add get/set playername, add on say2 filter callback
This commit is contained in:
@@ -13,6 +13,31 @@ Host_Say_t original_Host_Say = NULL;
|
||||
StartupServer_t origin_StartServer = NULL;
|
||||
GameFrame_t origin_GameFrame = NULL;
|
||||
CCSWeaponBase_Spawn_t origin_CCSWeaponBase_Spawn = NULL;
|
||||
UTIL_SayText2Filter_t origin_UTIL_SayText2Filter = NULL;
|
||||
void __fastcall hook_UTIL_SayText2Filter(
|
||||
IRecipientFilter& filter, CCSPlayerController* pEntity,
|
||||
uint64_t eMessageType, const char* messeageName, const char* param1,
|
||||
const char* param2, const char* param3, const char* param4) {
|
||||
const auto entIndex =
|
||||
PlayerSlot_to_EntityIndex(filter.GetRecipientIndex(0).Get());
|
||||
/*
|
||||
LOG("UTIL_SayText2Filter: %s\n", messeageName);
|
||||
LOG("entIndex: %d\n", entIndex);
|
||||
|
||||
LOG("param1: %s\n", param1);
|
||||
LOG("param2: %s\n", param2);
|
||||
|
||||
LOG("param3: %s\n", param3);
|
||||
LOG("param4: %s\n", param4);
|
||||
LOG("eMessageType: %d\n", eMessageType);
|
||||
*/
|
||||
const auto isHandle = ScriptCallBacks::luCall_onSayText2Filter(
|
||||
entIndex, eMessageType, messeageName, param1, param2, param3, param4);
|
||||
if (isHandle == false) {
|
||||
origin_UTIL_SayText2Filter(filter, pEntity, eMessageType, messeageName,
|
||||
param1, param2, param3, param4);
|
||||
}
|
||||
}
|
||||
// https://github.com/Source2ZE/CS2Fixes/blob/main/src/commands.cpp#L494
|
||||
void __fastcall hook_CCSWeaponBase_Spawn(CBaseEntity* pThis, void* a2) {
|
||||
const char* pszClassName = pThis->m_pEntity()->m_designerName;
|
||||
@@ -250,6 +275,13 @@ auto initMinHook() -> bool {
|
||||
LOG("MH_CreateHook origin_CCSWeaponBase_Spawn\n");
|
||||
break;
|
||||
}
|
||||
if (MH_CreateHook((LPVOID)Offset::FnUTIL_SayText2FilterPtr,
|
||||
&hook_UTIL_SayText2Filter,
|
||||
reinterpret_cast<LPVOID*>(
|
||||
&origin_UTIL_SayText2Filter)) != MH_OK) {
|
||||
LOG("MH_CreateHook origin_UTIL_SayText2Filter\n");
|
||||
break;
|
||||
}
|
||||
// <20><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>
|
||||
if (MH_EnableHook(MH_ALL_HOOKS) != MH_OK) {
|
||||
LOG("MH_EnableHook \n");
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
#pragma once
|
||||
#include "head.h"
|
||||
|
||||
typedef bool(__fastcall* FireEventServerSide_t)(CGameEventManager*, IGameEvent*, bool);
|
||||
class IRecipientFilter;
|
||||
typedef bool(__fastcall* FireEventServerSide_t)(CGameEventManager*, IGameEvent*,
|
||||
bool);
|
||||
typedef void(__fastcall* Host_Say_t)(void*, void*, bool, int, const char*);
|
||||
typedef void(__fastcall* OnClientConnect_t)(void*, CPlayerSlot, const char*, uint64_t, const char*, const char*, bool);
|
||||
typedef void(__fastcall* OnClientDisconnect_t)(void*, CPlayerSlot, int, const char*, uint64_t, const char*);
|
||||
typedef void(__fastcall* StartupServer_t)(void*, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*);
|
||||
typedef void(__fastcall* OnClientConnect_t)(void*, CPlayerSlot, const char*,
|
||||
uint64_t, const char*, const char*,
|
||||
bool);
|
||||
typedef void(__fastcall* OnClientDisconnect_t)(void*, CPlayerSlot, int,
|
||||
const char*, uint64_t,
|
||||
const char*);
|
||||
typedef void(__fastcall* StartupServer_t)(void*,
|
||||
const GameSessionConfiguration_t&,
|
||||
ISource2WorldSession*, const char*);
|
||||
typedef void(__fastcall* GameFrame_t)(void*, bool, bool, bool);
|
||||
typedef void(__fastcall* UTIL_SayText2Filter_t)(IRecipientFilter&,
|
||||
CCSPlayerController*, uint64_t,
|
||||
const char*, const char*,
|
||||
const char*, const char*,
|
||||
const char*);
|
||||
|
||||
namespace hooks {
|
||||
extern Host_Say_t original_Host_Say;
|
||||
auto init() -> bool;
|
||||
auto unload() -> void;
|
||||
}
|
||||
extern Host_Say_t original_Host_Say;
|
||||
auto init() -> bool;
|
||||
auto unload() -> void;
|
||||
} // namespace hooks
|
||||
|
||||
@@ -8,6 +8,8 @@ uint64_t CCSGameRulesInterFacePtr;
|
||||
uint64_t Host_SayPtr;
|
||||
uint64_t Module_tier0;
|
||||
uint64_t MaxPlayerNumsPtr;
|
||||
uint64_t FnUTIL_SayText2FilterPtr;
|
||||
PlayerChangeName_t FnPlayerChangeName;
|
||||
HashFunction_t FnServerHashFunction;
|
||||
StateChanged_t FnStateChanged;
|
||||
NetworkStateChanged_t FnNetworkStateChanged;
|
||||
@@ -67,6 +69,7 @@ auto Init() -> bool {
|
||||
server.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
|
||||
server.FindPattern(pattern_NetworkStateChanged).Get(FnNetworkStateChanged);
|
||||
server.FindPattern(pattern_FnStateChangedPtr).Get(FnStateChanged);
|
||||
server.FindPattern(pattern_PlayerChangeName).Get(FnPlayerChangeName);
|
||||
|
||||
server.FindPattern(pattern_CGameEventManager)
|
||||
.ToAbsolute(3, 0)
|
||||
@@ -74,16 +77,19 @@ auto Init() -> bool {
|
||||
server.FindPattern(pattern_CreateCCSGameRulesInterFacePtr)
|
||||
.ToAbsolute(3, 0)
|
||||
.Get(CCSGameRulesInterFacePtr);
|
||||
server.FindPattern(pattern_FnRespawnPlayerInDeathMatch).Get(FnRespawnPlayerInDeathMatch);
|
||||
server.FindPattern(pattern_FnRespawnPlayerInDeathMatch)
|
||||
.Get(FnRespawnPlayerInDeathMatch);
|
||||
server.FindPattern(pattern_FnEntityRemove).Get(FnEntityRemove);
|
||||
server.FindPattern(pattern_FnGiveNamedItemPtr).Get(FnGiveNamedItem);
|
||||
server.FindPattern(pattern_fnHost_SayPtr).Get(Host_SayPtr);
|
||||
//server.FindPattern(pattern_ServerHashFunctionPtr).Get(FnServerHashFunction);
|
||||
// server.FindPattern(pattern_ServerHashFunctionPtr).Get(FnServerHashFunction);
|
||||
server.FindPattern(pattern_UTIL_ClientPrintAll).Get(FnUTIL_ClientPrintAll);
|
||||
server.FindPattern(pattern_FnClientPrint).Get(FnClientPrint);
|
||||
|
||||
server.FindPattern(pattern_FnUTIL_SayTextFilter).Get(FnUTIL_SayTextFilter);
|
||||
server.FindPattern(pattern_CCSWeaponBase_Spawn).Get(FnCCSWeaponBase_Spawn);
|
||||
server.FindPattern(pattern_FnUTIL_SayText2FilterPtr)
|
||||
.Get(FnUTIL_SayText2FilterPtr);
|
||||
|
||||
InterFaces::SchemaSystem = reinterpret_cast<CSchemaSystem*>(
|
||||
schemasystem.FindInterface("SchemaSystem_001").Get());
|
||||
@@ -91,8 +97,8 @@ auto Init() -> bool {
|
||||
// engine.FindInterface("GameEventSystemServerV001").Get());
|
||||
InterFaces::ILocalize = reinterpret_cast<CLocalize*>(
|
||||
localize.FindInterface("Localize_001").Get());
|
||||
InterFaces::IVEngineCvar = reinterpret_cast<ICvar*>(
|
||||
tier0.FindInterface("VEngineCvar007").Get());
|
||||
InterFaces::IVEngineCvar =
|
||||
reinterpret_cast<ICvar*>(tier0.FindInterface("VEngineCvar007").Get());
|
||||
|
||||
InterFaces::GameResourceServiceServer =
|
||||
reinterpret_cast<CGameResourceService*>(
|
||||
@@ -106,7 +112,6 @@ auto Init() -> bool {
|
||||
server.FindInterface("Source2GameClients001").Get());
|
||||
InterFaces::ISource2ServerInterFace = reinterpret_cast<ISource2Server*>(
|
||||
server.FindInterface("Source2Server001").Get());
|
||||
|
||||
if (InterFaces::ISource2ServerInterFace) {
|
||||
InterFaces::GameEventManager =
|
||||
(IGameEventManager2*)(CALL_VIRTUAL(
|
||||
@@ -124,13 +129,16 @@ auto Init() -> bool {
|
||||
LOG("[huoji]FireEventServerSidePtr : %llx \n", FireEventServerSidePtr);
|
||||
LOG("[huoji]Host_SayPtr : %llx \n", Host_SayPtr);
|
||||
LOG("[huoji]FnNetworkStateChanged : %llx \n", FnNetworkStateChanged);
|
||||
//LOG("[huoji]FnServerHashFunction : %llx \n", FnServerHashFunction);
|
||||
// LOG("[huoji]FnServerHashFunction : %llx \n", FnServerHashFunction);
|
||||
LOG("[huoji]FnStateChanged : %llx \n", FnStateChanged);
|
||||
LOG("[huoji]FnRespawnPlayerInDeathMatch : %llx \n", FnRespawnPlayerInDeathMatch);
|
||||
LOG("[huoji]FnRespawnPlayerInDeathMatch : %llx \n",
|
||||
FnRespawnPlayerInDeathMatch);
|
||||
LOG("[huoji]FnGiveNamedItem : %llx \n", FnGiveNamedItem);
|
||||
LOG("[huoji]FnClientPrint : %llx \n", FnClientPrint);
|
||||
LOG("[huoji]FnUTIL_ClientPrintAll : %llx \n", FnUTIL_ClientPrintAll);
|
||||
LOG("[huoji]FnCCSWeaponBase_Spawn : %llx \n", FnCCSWeaponBase_Spawn);
|
||||
LOG("[huoji]FnPlayerChangeName : %llx \n", FnPlayerChangeName);
|
||||
LOG("[huoji]FnUTIL_SayText2FilterPtr : %llx \n", FnUTIL_SayText2FilterPtr);
|
||||
|
||||
LOG("[huoji]MaxGlobals : %d \n", global::MaxPlayers);
|
||||
|
||||
@@ -147,8 +155,7 @@ auto Init() -> bool {
|
||||
InterFaces::IVEngineServer);
|
||||
LOG("[huoji]InterFaces::ISource2ServerInterFace : %llx \n",
|
||||
InterFaces::ISource2ServerInterFace);
|
||||
LOG("[huoji]InterFaces::IVEngineCvar : %llx \n",
|
||||
InterFaces::IVEngineCvar);
|
||||
LOG("[huoji]InterFaces::IVEngineCvar : %llx \n", InterFaces::IVEngineCvar);
|
||||
LOG("[huoji] CGameEntitySystem::GetInstance : %llx \n",
|
||||
CGameEntitySystem::GetInstance());
|
||||
LOG("init offset success !\n");
|
||||
@@ -157,7 +164,9 @@ auto Init() -> bool {
|
||||
0, NULL);
|
||||
// LOG("FnServerHashFunction: %llx \n", FnServerHashFunction("here",
|
||||
// sizeof("here") - 1, 0x31415926));
|
||||
return FnCCSWeaponBase_Spawn && FnEntityRemove && FnRespawnPlayerInDeathMatch && FnGiveNamedItem && Host_SayPtr && InterFaces::IVEngineServer &&
|
||||
return FnPlayerChangeName && FnCCSWeaponBase_Spawn && FnEntityRemove &&
|
||||
FnRespawnPlayerInDeathMatch && FnGiveNamedItem && Host_SayPtr &&
|
||||
InterFaces::IVEngineServer &&
|
||||
InterFaces::GameResourceServiceServer &&
|
||||
InterFaces::IServerGameClient && InterFaces::GameEventManager &&
|
||||
InterFaces::SchemaSystem && FireEventServerSidePtr &&
|
||||
|
||||
@@ -23,9 +23,15 @@ typedef void*(__fastcall* EntityRemove_t)(CGameEntitySystem*, void*, void*,
|
||||
uint64_t);
|
||||
typedef void*(__fastcall* UTIL_SayTextFilter_t)(IRecipientFilter&, const char*,
|
||||
CCSPlayerController*, uint64_t);
|
||||
typedef void(__fastcall* UTIL_ClientPrintAll_t)(int msg_dest, const char* msg_name, const char* param1, const char* param2, const char* param3, const char* param4);
|
||||
typedef void(__fastcall* ClientPrint_t)(CCSPlayerController* player, int msg_dest, const char* msg_name, const char* param1, const char* param2, const char* param3, const char* param4);
|
||||
typedef void(__fastcall* UTIL_ClientPrintAll_t)(
|
||||
int msg_dest, const char* msg_name, const char* param1, const char* param2,
|
||||
const char* param3, const char* param4);
|
||||
typedef void(__fastcall* ClientPrint_t)(CCSPlayerController* player,
|
||||
int msg_dest, const char* msg_name,
|
||||
const char* param1, const char* param2,
|
||||
const char* param3, const char* param4);
|
||||
typedef void(__fastcall* CCSWeaponBase_Spawn_t)(CBaseEntity*, void*);
|
||||
typedef void(__fastcall* PlayerChangeName_t)(CBaseEntity*, char*);
|
||||
class CSchemaSystem;
|
||||
class CGameResourceService;
|
||||
class CLocalize;
|
||||
@@ -44,7 +50,15 @@ extern ISource2Server* ISource2ServerInterFace;
|
||||
extern CCSGameRules* CCSGameRulesInterFace;
|
||||
extern ICvar* IVEngineCvar;
|
||||
}; // namespace InterFaces
|
||||
static const auto pattern_VscriptPath = THE_GAME_SIG("BE 01 ?? ?? ?? 2B D6 74 ?? 3B D6");
|
||||
static const auto pattern_FnUTIL_SayText2FilterPtr = THE_GAME_SIG(
|
||||
"48 89 5C 24 ?? 55 56 57 48 8D 6C 24 ?? 48 81 EC ?? ?? ?? ?? 41 0F B6 F8");
|
||||
static const auto pattern_PlayerChangeName = THE_GAME_SIG(
|
||||
"4C 8B DC 55 56 41 54 49 8D ?? ?? ?? ?? ?? 48 ?? ?? ?? ?? ?? ?? 48 8B F1 "
|
||||
"41 ?? ?? ?? ?? ?? 8B 89 ?? ?? ?? ?? 4C 8B D2 41 3B CC 0F ?? ?? ?? ?? ?? "
|
||||
"4C ?? ?? ?? ?? ?? ?? 4D 85 C0 0F ?? ?? ?? ?? ?? 83 ?? ?? 0F ?? ?? ?? ?? "
|
||||
"?? 8B C1 25 ?? ?? ?? ??");
|
||||
static const auto pattern_VscriptPath =
|
||||
THE_GAME_SIG("BE 01 ?? ?? ?? 2B D6 74 ?? 3B D6");
|
||||
static const auto pattern_CGameEventManager = THE_GAME_SIG(
|
||||
"48 ?? ?? ?? ?? ?? ?? 48 89 ?? ?? ?? 48 89 01 48 8B D9 48 ?? ?? ?? ?? ?? "
|
||||
"?? 48 89 ?? ?? E8 ?? ?? ?? ?? 48 ?? ?? ?? ?? ?? ??");
|
||||
@@ -79,7 +93,9 @@ static const auto pattern_CreateCCSGameRulesInterFacePtr = THE_GAME_SIG(
|
||||
"?? ?? 4C 8D ?? ?? ?? 49 8B ?? ?? 49 8B ?? ?? 49 8B ?? ?? 49 8B E3 41 5F "
|
||||
"41 5E 5F C3");
|
||||
static const auto pattern_FnRespawnPlayer = THE_GAME_SIG(
|
||||
"48 89 ?? ?? ?? 48 89 ?? ?? ?? 56 48 ?? ?? ?? ?? ?? ?? 48 8B DA 48 8B E9 48 85 D2 0F ?? ?? ?? ?? ?? 48 8B 02 48 8B CA FF ?? ?? ?? ?? ?? 84 C0 0F ?? ?? ?? ?? ?? 83 BB ?? ?? ?? ?? ?? 0F ?? ?? ?? ?? ??");
|
||||
"48 89 ?? ?? ?? 48 89 ?? ?? ?? 56 48 ?? ?? ?? ?? ?? ?? 48 8B DA 48 8B E9 "
|
||||
"48 85 D2 0F ?? ?? ?? ?? ?? 48 8B 02 48 8B CA FF ?? ?? ?? ?? ?? 84 C0 0F "
|
||||
"?? ?? ?? ?? ?? 83 BB ?? ?? ?? ?? ?? 0F ?? ?? ?? ?? ??");
|
||||
static const auto pattern_FnRespawnPlayerInDeathMatch = THE_GAME_SIG(
|
||||
"48 89 ?? ?? ?? 57 48 ?? ?? ?? 48 8D ?? ?? ?? 48 8B F9 E8 ?? ?? ?? ?? 83 "
|
||||
"?? ?? 74 ?? 48 ?? ?? ?? ?? ?? ?? 48 8B CF 48 8B 10 48 8B ?? ?? ?? ?? ?? "
|
||||
@@ -92,15 +108,20 @@ static const auto pattern_FnEntityRemove = THE_GAME_SIG(
|
||||
static const auto pattern_FnUTIL_SayTextFilter = THE_GAME_SIG(
|
||||
"48 89 5C 24 ?? 55 56 57 48 8D 6C 24 ?? 48 81 EC ?? ?? ?? ?? 49 8B D8");
|
||||
static const auto pattern_UTIL_ClientPrintAll = THE_GAME_SIG(
|
||||
"48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 81 EC 70 01 ?? ?? 8B E9");
|
||||
static const auto pattern_FnClientPrint = THE_GAME_SIG(
|
||||
"48 85 C9 0F 84 ?? ?? ?? ?? 48 8B C4 48 89 58 18");
|
||||
static const auto pattern_CCSWeaponBase_Spawn = THE_GAME_SIG("48 89 5C 24 08 48 89 6C 24 18 48 89 74 24 20 57 48 83 EC 30 48 8B DA 48 8B E9 E8 ?? ?? ?? ??");
|
||||
"48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 81 EC 70 01 ?? ?? 8B "
|
||||
"E9");
|
||||
static const auto pattern_FnClientPrint =
|
||||
THE_GAME_SIG("48 85 C9 0F 84 ?? ?? ?? ?? 48 8B C4 48 89 58 18");
|
||||
static const auto pattern_CCSWeaponBase_Spawn = THE_GAME_SIG(
|
||||
"48 89 5C 24 08 48 89 6C 24 18 48 89 74 24 20 57 48 83 EC 30 48 8B DA 48 "
|
||||
"8B E9 E8 ?? ?? ?? ??");
|
||||
extern uint64_t GameResourceServicePtr;
|
||||
extern uint64_t FireEventServerSidePtr;
|
||||
extern uint64_t Module_tier0;
|
||||
extern uint64_t Host_SayPtr;
|
||||
extern uint64_t MaxPlayerNumsPtr;
|
||||
extern uint64_t FnUTIL_SayText2FilterPtr;
|
||||
|
||||
extern HashFunction_t FnServerHashFunction;
|
||||
extern StateChanged_t FnStateChanged;
|
||||
extern NetworkStateChanged_t FnNetworkStateChanged;
|
||||
@@ -111,6 +132,7 @@ extern UTIL_SayTextFilter_t FnUTIL_SayTextFilter;
|
||||
extern UTIL_ClientPrintAll_t FnUTIL_ClientPrintAll;
|
||||
extern ClientPrint_t FnClientPrint;
|
||||
extern CCSWeaponBase_Spawn_t FnCCSWeaponBase_Spawn;
|
||||
extern PlayerChangeName_t FnPlayerChangeName;
|
||||
extern bool InitOffsetSuccess;
|
||||
auto Init() -> bool;
|
||||
}; // namespace Offset
|
||||
|
||||
@@ -54,7 +54,7 @@ auto ExcutePlayerAction(int playerIndex,
|
||||
function(playerController);
|
||||
} while (false);
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ҫ<EFBFBD>Լ<EFBFBD>push<73><68>stack<63><6B>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ҫ<EFBFBD>Լ<EFBFBD>push<73><68>stack<63><6B>
|
||||
auto luaApi_ListenToGameEvent(lua_State* luaVm) -> int {
|
||||
const auto eventName = lua_tostring(luaVm, 1);
|
||||
do {
|
||||
@@ -73,7 +73,7 @@ auto luaApi_ListenToGameEvent(lua_State* luaVm) -> int {
|
||||
LOG("luaApi_ListenToGameEvent unknown event name: %s\n", eventName);
|
||||
break;
|
||||
}
|
||||
// <20><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>ӵ<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>ӵ<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>
|
||||
std::unique_lock lock(ScriptCallBacks::mutex_callbackList);
|
||||
ScriptCallBacks::callbackList[luaVm][callbackType] =
|
||||
luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||
@@ -82,7 +82,7 @@ auto luaApi_ListenToGameEvent(lua_State* luaVm) -> int {
|
||||
eventName);
|
||||
} while (false);
|
||||
|
||||
lua_pop(luaVm, 2); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ
|
||||
lua_pop(luaVm, 2); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int {
|
||||
@@ -593,7 +593,8 @@ auto luaApi_SendToPlayerChat(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
const auto hudType = lua_tointeger(luaVm, 2);
|
||||
const auto message = lua_tostring(luaVm, 3);
|
||||
if (hudType >= static_cast<int>(_HubType::kMax) || hudType < static_cast<int>(_HubType::kNotify)) {
|
||||
if (hudType >= static_cast<int>(_HubType::kMax) ||
|
||||
hudType < static_cast<int>(_HubType::kNotify)) {
|
||||
lua_pop(luaVm, 3);
|
||||
return 0;
|
||||
}
|
||||
@@ -608,7 +609,8 @@ auto luaApi_SentToAllPlayerChat(lua_State* luaVm) -> int {
|
||||
// param: playerIndex:int, message:string
|
||||
const auto message = lua_tostring(luaVm, 1);
|
||||
const auto hudType = lua_tointeger(luaVm, 2);
|
||||
if (hudType >= static_cast<int>(_HubType::kMax) || hudType < static_cast<int>(_HubType::kNotify)) {
|
||||
if (hudType >= static_cast<int>(_HubType::kMax) ||
|
||||
hudType < static_cast<int>(_HubType::kNotify)) {
|
||||
lua_pop(luaVm, 3);
|
||||
return 0;
|
||||
}
|
||||
@@ -719,11 +721,52 @@ auto luaApi_RunClientCommand(lua_State* luaVm) -> int {
|
||||
const auto command = lua_tostring(luaVm, 2);
|
||||
|
||||
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
|
||||
Offset::InterFaces::IVEngineServer->ClientCommand(EntityIndex_to_PlayerSlot(playerIndex), command);
|
||||
Offset::InterFaces::IVEngineServer->ClientCommand(
|
||||
EntityIndex_to_PlayerSlot(playerIndex), command);
|
||||
});
|
||||
lua_pop(luaVm, 2);
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_SetPlayerName(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
const auto playerName = lua_tostring(luaVm, 2);
|
||||
|
||||
if (playerName != nullptr) {
|
||||
ExcutePlayerAction(
|
||||
playerIndex, [&](CCSPlayerController* playerController) {
|
||||
Offset::FnPlayerChangeName(playerController->m_hPawn().Get(),
|
||||
(char*)playerName);
|
||||
});
|
||||
}
|
||||
lua_pop(luaVm, 2);
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_SetPlayerNameSlient(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
const auto playerName = lua_tostring(luaVm, 2);
|
||||
|
||||
if (playerName != nullptr) {
|
||||
ExcutePlayerAction(
|
||||
playerIndex, [&](CCSPlayerController* playerController) {
|
||||
const auto playerNameAddress =
|
||||
&playerController->m_iszPlayerName();
|
||||
const auto playerNameLength = min(strlen(playerName) + 1, 127);
|
||||
memcpy(playerNameAddress, playerName, playerNameLength);
|
||||
});
|
||||
}
|
||||
lua_pop(luaVm, 2);
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_GetPlayerName(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
std::string playerName;
|
||||
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
|
||||
playerName = &playerController->m_iszPlayerName();
|
||||
});
|
||||
lua_pop(luaVm, 1);
|
||||
lua_pushstring(luaVm, playerName.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto luaApi_GetPlayerSteamId(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
std::string steamid;
|
||||
@@ -907,8 +950,7 @@ auto luaApi_GetConVarString(lua_State* luaVm) -> int {
|
||||
auto luaApi_GetConVarInt(lua_State* luaVm) -> int {
|
||||
// param: convarObject:int
|
||||
const auto inputData = lua_tointeger(luaVm, 1);
|
||||
if (inputData)
|
||||
{
|
||||
if (inputData) {
|
||||
ConVarHandle theConvarHandle{};
|
||||
theConvarHandle.Set(inputData);
|
||||
int value = -1;
|
||||
@@ -984,6 +1026,10 @@ auto initFunciton(lua_State* luaVm) -> void {
|
||||
lua_register(luaVm, "luaApi_GetConVarInt", luaApi_GetConVarInt);
|
||||
lua_register(luaVm, "luaApi_GetPlayerSteamId", luaApi_GetPlayerSteamId);
|
||||
lua_register(luaVm, "luaApi_RunClientCommand", luaApi_RunClientCommand);
|
||||
lua_register(luaVm, "luaApi_SetPlayerName", luaApi_SetPlayerName);
|
||||
lua_register(luaVm, "luaApi_GetPlayerName", luaApi_GetPlayerName);
|
||||
lua_register(luaVm, "luaApi_SetPlayerNameSlient",
|
||||
luaApi_SetPlayerNameSlient);
|
||||
|
||||
// lua_register(luaVm, "luaApi_TeleportPlayer", luaApi_TeleportPlayer);
|
||||
|
||||
@@ -999,7 +1045,7 @@ auto initFunciton(lua_State* luaVm) -> void {
|
||||
.addData("weaponIndex", &_luaApi_WeaponInfo::weaponIndex)
|
||||
.endClass()
|
||||
.addFunction("luaApi_GetPlayerWeaponInfo", &luaApi_GetPlayerWeaponInfo);
|
||||
// <20>Ҳ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>
|
||||
// <20>Ҳ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>
|
||||
luabridge::getGlobalNamespace(luaVm)
|
||||
.beginClass<_luaApi_WeaponInfo>("WeaponInfo")
|
||||
.addConstructor<void (*)(void)>()
|
||||
|
||||
@@ -16,6 +16,8 @@ std::unordered_map<uint32_t, _CallbackNames> callbackNameWithEnumMap{
|
||||
{hash_32_fnv1a_const("player_hurt"), _CallbackNames::kOnPlayerHurt},
|
||||
{hash_32_fnv1a_const("player_team"), _CallbackNames::kOnPlayerTeamChange},
|
||||
{hash_32_fnv1a_const("http_request"), _CallbackNames::kOnHttpRequest},
|
||||
{hash_32_fnv1a_const("say_text_to_filter"),
|
||||
_CallbackNames::kOnSayText2Filter},
|
||||
|
||||
};
|
||||
auto CallBackNameToEnum(const char* name) -> _CallbackNames {
|
||||
@@ -255,4 +257,33 @@ auto luaCall_onHttpRequest(std::string url, std::string metaData,
|
||||
}
|
||||
});
|
||||
}
|
||||
auto luCall_onSayText2Filter(int player, uint64_t eMessageType,
|
||||
const char* messeageName, const char* param1,
|
||||
const char* param2, const char* param3,
|
||||
const char* param4) -> bool {
|
||||
bool result = false;
|
||||
ExcuteCallbackInAllLuaVm(_CallbackNames::kOnSayText2Filter,
|
||||
[&](lua_State* luaVm, int refIndex) -> void {
|
||||
lua_rawgeti(luaVm, LUA_REGISTRYINDEX,
|
||||
refIndex);
|
||||
if (lua_isfunction(luaVm, -1)) {
|
||||
lua_pushinteger(luaVm, player);
|
||||
lua_pushinteger(luaVm, eMessageType);
|
||||
lua_pushstring(luaVm, messeageName);
|
||||
lua_pushstring(luaVm, param1);
|
||||
lua_pushstring(luaVm, param2);
|
||||
lua_pushstring(luaVm, param3);
|
||||
lua_pushstring(luaVm, param4);
|
||||
if (lua_pcall(luaVm, 7, 1, 0) != LUA_OK) {
|
||||
LOG("Error calling Lua callback: %s\n",
|
||||
lua_tostring(luaVm, -1));
|
||||
lua_pop(luaVm, 1);
|
||||
}
|
||||
if (lua_isboolean(luaVm, -1)) {
|
||||
result = lua_toboolean(luaVm, -1);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
} // namespace ScriptCallBacks
|
||||
|
||||
@@ -13,7 +13,8 @@ enum class _CallbackNames {
|
||||
kOnRoundEnd,
|
||||
kOnPlayerHurt,
|
||||
kOnPlayerTeamChange,
|
||||
kOnHttpRequest
|
||||
kOnHttpRequest,
|
||||
kOnSayText2Filter
|
||||
};
|
||||
extern std::unordered_map<lua_State*, std::unordered_map<_CallbackNames, int>>
|
||||
callbackList;
|
||||
@@ -40,4 +41,8 @@ auto luaCall_onPlayerTeamChange(int userid, int team, int oldteam,
|
||||
-> bool;
|
||||
auto luaCall_onHttpRequest(std::string url, std::string metaData,
|
||||
std::string respon, int statusCode) -> void;
|
||||
auto luCall_onSayText2Filter(int player, uint64_t eMessageType,
|
||||
const char* messeageName, const char* param1,
|
||||
const char* param2, const char* param3,
|
||||
const char* param4) -> bool;
|
||||
} // namespace ScriptCallBacks
|
||||
|
||||
Reference in New Issue
Block a user