From 79bc2cf89d436f6ef2b845618f131fac8954bba7 Mon Sep 17 00:00:00 2001 From: Huoji's <1296564236@qq.com> Date: Wed, 11 Oct 2023 03:58:34 +0800 Subject: [PATCH] update sdk, fix weapon drop bug, update gamevent struct from hl2sdk --- .vscode/settings.json | 3 +- csgo2/events.cpp | 151 ++++++++++------------- csgo2/events.h | 1 + csgo2/hooks.cpp | 33 ++++-- csgo2/offset.cpp | 7 +- csgo2/script_apis.cpp | 2 + csgo2/script_callbacks.cpp | 27 +++++ csgo2/script_callbacks.h | 4 +- csgo2/sdk/gameevent/IGameEvent.h | 197 ++++++++++++++++++++++--------- csgo2/tools.cpp | 6 + csgo2/tools.h | 1 + 11 files changed, 271 insertions(+), 161 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ad52f84..3036db0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -88,6 +88,7 @@ "random": "cpp", "hash_map": "cpp", "hash_set": "cpp", - "filesystem": "cpp" + "filesystem": "cpp", + "regex": "cpp" } } diff --git a/csgo2/events.cpp b/csgo2/events.cpp index 208b725..9a4ef6f 100644 --- a/csgo2/events.cpp +++ b/csgo2/events.cpp @@ -1,57 +1,55 @@ #include "events.h" namespace events { +auto OnPlayerTeamChangeEevent(IGameEvent* event) -> void { + GameEventKeySymbol_t userIdNameParams{ "userid" }; + GameEventKeySymbol_t teamNameParams{ "team" }; + GameEventKeySymbol_t oldteamNameParams{ "oldteam" }; + GameEventKeySymbol_t disconnectNameParams{ "disconnect"}; + GameEventKeySymbol_t silentNameParams{ "silent" }; + GameEventKeySymbol_t isbotParams{ "isbot"}; + + const auto PlayerPawn = reinterpret_cast( + event->GetPlayerPawn(userIdNameParams)); + if (PlayerPawn == nullptr) { + return; + } + if (PlayerPawn->IsBasePlayerController() == false) { + return; + } + const auto Player = PlayerPawn->GetPlayerController(); + if (Player == nullptr) { + return; + } + const auto playerIndex = Player->GetRefEHandle().GetEntryIndex(); + auto team = event->GetInt(teamNameParams); + auto oldTeam = event->GetInt(oldteamNameParams); + auto disconnect = event->GetBool(disconnectNameParams); + auto slient = event->GetBool(silentNameParams); + auto isBot = event->GetBool(isbotParams); + if (ScriptCallBacks::luaCall_onPlayerTeamChange(playerIndex, team, oldTeam, disconnect, slient, isBot) == true) { + event->SetBool(silentNameParams, true); + } +} auto OnPlayerHurtEvent(IGameEvent* event) -> void { /* auto luaCall_onPlayerHurt(int userid, int attacker, int health, int armor, const char* weapon, int dmg_health, int dmg_armor, int hitgroup) -> void */ - UnkGameEventStruct_t userIdNameParams{"userid"}; - UnkGameEventStruct_t attackerNameParams{"attacker"}; - UnkGameEventStruct_t healthNameParams{0}; - UnkGameEventStruct_t armorNameParams{0}; - UnkGameEventStruct_t weaponNameParams{0}; - UnkGameEventStruct_t dmg_healthNameParams{0}; - UnkGameEventStruct_t dmg_armorNameParams{0}; - UnkGameEventStruct_t hitgroupNameParams{0}; - - static const auto healthStr = "health"; - static const auto armorStr = "armor"; - static const auto weaponStr = "weapon"; - static const auto dmg_healthStr = "dmg_health"; - static const auto dmg_armorStr = "dmg_armor"; - static const auto hitgroupStr = "hitgroup"; - - healthNameParams.m_Unk = Offset::FnServerHashFunction( - healthStr, sizeof healthStr, SERVER_HASH_FUCNTION_KEY); - healthNameParams.m_Key = healthStr; - - armorNameParams.m_Unk = Offset::FnServerHashFunction( - armorStr, sizeof armorStr, SERVER_HASH_FUCNTION_KEY); - armorNameParams.m_Key = armorStr; - - weaponNameParams.m_Unk = Offset::FnServerHashFunction( - weaponStr, sizeof weaponStr, SERVER_HASH_FUCNTION_KEY); - - weaponNameParams.m_Key = weaponStr; - - dmg_healthNameParams.m_Unk = Offset::FnServerHashFunction( - dmg_healthStr, sizeof dmg_healthStr, SERVER_HASH_FUCNTION_KEY); - dmg_healthNameParams.m_Key = dmg_healthStr; - - dmg_armorNameParams.m_Unk = Offset::FnServerHashFunction( - dmg_armorStr, sizeof dmg_armorStr, SERVER_HASH_FUCNTION_KEY); - dmg_armorNameParams.m_Key = dmg_armorStr; - - hitgroupNameParams.m_Unk = Offset::FnServerHashFunction( - hitgroupStr, sizeof hitgroupStr, SERVER_HASH_FUCNTION_KEY); - hitgroupNameParams.m_Key = hitgroupStr; + GameEventKeySymbol_t userIdNameParams{"userid"}; + GameEventKeySymbol_t attackerNameParams{"attacker"}; + GameEventKeySymbol_t healthNameParams{"health"}; + GameEventKeySymbol_t armorNameParams{"armor"}; + GameEventKeySymbol_t weaponNameParams{"weapon"}; + GameEventKeySymbol_t dmg_healthNameParams{"dmg_health"}; + GameEventKeySymbol_t dmg_armorNameParams{"dmg_armor"}; + GameEventKeySymbol_t hitgroupNameParams{"hitgroup"}; const auto victimPawn = reinterpret_cast( - event->GetPlayerPawn(&userIdNameParams)); + event->GetPlayerPawn(userIdNameParams)); const auto attackerPawn = reinterpret_cast( - event->GetPlayerPawn(&attackerNameParams)); + event->GetPlayerPawn(attackerNameParams)); if (victimPawn == nullptr || attackerPawn == nullptr) { return; } @@ -67,12 +65,12 @@ auto OnPlayerHurtEvent(IGameEvent* event) -> void { const auto victimIndex = victim->GetRefEHandle().GetEntryIndex(); const auto attackerIndex = attacker->GetRefEHandle().GetEntryIndex(); - auto health = event->GetInt(&healthNameParams); - auto armor = event->GetInt(&armorNameParams); - auto weapon = event->GetString(&weaponNameParams); - auto dmg_health = event->GetInt(&dmg_healthNameParams); - auto dmg_armor = event->GetInt(&dmg_armorNameParams); - auto hitgroup = event->GetInt(&hitgroupNameParams); + auto health = event->GetInt(healthNameParams); + auto armor = event->GetInt(armorNameParams); + auto weapon = event->GetString(weaponNameParams); + auto dmg_health = event->GetInt(dmg_healthNameParams); + auto dmg_armor = event->GetInt(dmg_armorNameParams); + auto hitgroup = event->GetInt(hitgroupNameParams); ScriptCallBacks::luaCall_onPlayerHurt(victimIndex, attackerIndex, health, armor, weapon, dmg_health, dmg_armor, hitgroup); @@ -84,45 +82,25 @@ auto OnRoundEndEvent(IGameEvent* event) -> void { "message" "string" // end round message */ - UnkGameEventStruct_t winnerNameParams{0}; - UnkGameEventStruct_t reasonNameParams{0}; - UnkGameEventStruct_t messageNameParams{0}; - - static const auto winnerStr = "winner"; - static const auto reasonStr = "reason"; - static const auto messageStr = "message"; - - winnerNameParams.m_Unk = Offset::FnServerHashFunction( - winnerStr, sizeof winnerStr, SERVER_HASH_FUCNTION_KEY); - winnerNameParams.m_Key = winnerStr; - - reasonNameParams.m_Unk = Offset::FnServerHashFunction( - reasonStr, sizeof reasonStr, SERVER_HASH_FUCNTION_KEY); - reasonNameParams.m_Key = reasonStr; - - messageNameParams.m_Unk = Offset::FnServerHashFunction( - messageStr, sizeof messageStr, SERVER_HASH_FUCNTION_KEY); - messageNameParams.m_Key = messageStr; + GameEventKeySymbol_t winnerNameParams{"winner"}; + GameEventKeySymbol_t reasonNameParams{"reason"}; + GameEventKeySymbol_t messageNameParams{"message"}; - const auto message = event->GetString(&messageNameParams); - const auto winner = event->GetInt(&winnerNameParams); - const auto reason = event->GetInt(&reasonNameParams); + const auto message = event->GetString(messageNameParams); + const auto winner = event->GetInt(winnerNameParams); + const auto reason = event->GetInt(reasonNameParams); ScriptCallBacks::luaCall_onRoundEnd(winner, reason, message); } auto OnRoundStartEvent(IGameEvent* event) -> void { - UnkGameEventStruct_t timelimitNameParams{0}; - static const auto timelimitStr = "timelimit"; - timelimitNameParams.m_Unk = Offset::FnServerHashFunction( - timelimitStr, sizeof timelimitStr, SERVER_HASH_FUCNTION_KEY); - timelimitNameParams.m_Key = timelimitStr; - const auto timelimit = event->GetInt(&timelimitNameParams); + GameEventKeySymbol_t timelimitNameParams{"timelimit"}; + const auto timelimit = event->GetInt(timelimitNameParams); ScriptCallBacks::luaCall_onRoundStart(timelimit); } auto OnPlayerSpawnEvent(IGameEvent* event) -> void { - UnkGameEventStruct_t userIdNameParams{"userid"}; + GameEventKeySymbol_t userIdNameParams{"userid"}; const auto playerPawn = reinterpret_cast( - event->GetPlayerPawn(&userIdNameParams)); + event->GetPlayerPawn(userIdNameParams)); if (playerPawn == nullptr) { return; } @@ -134,18 +112,15 @@ auto OnPlayerSpawnEvent(IGameEvent* event) -> void { ScriptCallBacks::luaCall_onPlayerSpawn(playerIndex); } auto OnPlayerDeathEvent(IGameEvent* event) -> void { - UnkGameEventStruct_t userIdNameParams{"userid"}; - UnkGameEventStruct_t attackerNameParams{"attacker"}; - UnkGameEventStruct_t headshotNameParams{0}; - static const auto headShotStr = "headshot"; - headshotNameParams.m_Unk = Offset::FnServerHashFunction( - headShotStr, sizeof headShotStr, SERVER_HASH_FUCNTION_KEY); - headshotNameParams.m_Key = headShotStr; + GameEventKeySymbol_t userIdNameParams{"userid"}; + GameEventKeySymbol_t attackerNameParams{"attacker"}; + GameEventKeySymbol_t headshotNameParams{"headshot"}; + const auto victimPawn = reinterpret_cast( - event->GetPlayerPawn(&userIdNameParams)); + event->GetPlayerPawn(userIdNameParams)); const auto attackerPawn = reinterpret_cast( - event->GetPlayerPawn(&attackerNameParams)); - const auto isHeadShot = event->GetBool(&headshotNameParams); + event->GetPlayerPawn(attackerNameParams)); + const auto isHeadShot = event->GetBool(headshotNameParams); if (victimPawn == nullptr || attackerPawn == nullptr) { return; } diff --git a/csgo2/events.h b/csgo2/events.h index a39ca12..9d4f01e 100644 --- a/csgo2/events.h +++ b/csgo2/events.h @@ -14,4 +14,5 @@ auto OnPlayerSpawnEvent(IGameEvent* event) -> void; auto OnRoundStartEvent(IGameEvent* event) -> void; auto OnRoundEndEvent(IGameEvent* event) -> void; auto OnPlayerHurtEvent(IGameEvent* event) -> void; +auto OnPlayerTeamChangeEevent(IGameEvent* event) -> void; } // namespace events diff --git a/csgo2/hooks.cpp b/csgo2/hooks.cpp index 5009ad8..df09479 100644 --- a/csgo2/hooks.cpp +++ b/csgo2/hooks.cpp @@ -13,7 +13,7 @@ Host_Say_t original_Host_Say = NULL; StartupServer_t origin_StartServer = NULL; GameFrame_t origin_GameFrame = NULL; CCSWeaponBase_Spawn_t origin_CCSWeaponBase_Spawn = NULL; - +// 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; @@ -31,14 +31,26 @@ void __fastcall hook_CCSWeaponBase_Spawn(CBaseEntity* pThis, void* a2) { pWeapon->m_AttributeManager()->m_Item()->m_bInitialized()) { break; } - if (GameWeapons::WeaponMap.find(pszClassName) == - GameWeapons::WeaponMap.end()) { + const auto weaponName = Tools::toLower(std::string(pszClassName)); + auto lookupWeaponSimpleName = std::string(); + for (const auto& weapon : GameWeapons::WeaponMap) { + const auto& key = weapon.first; + const auto& [fullWeaponName, weaponItemDefIndex] = weapon.second; + if (fullWeaponName.find(weaponName) == + std::string::npos) { + continue; + } + lookupWeaponSimpleName = key; + break; + } + if (lookupWeaponSimpleName.size() <= 1) { break; } + // lazy , fix me const auto [fullWeaponName, weaponiItemDefIndex] = - GameWeapons::WeaponMap.at(pszClassName); + GameWeapons::WeaponMap.at(lookupWeaponSimpleName); - LOG("Fixing a %s with index = %d and initialized = %d\n", pszClassName, + LOG("Fixing a %s with index = %d and initialized = %d\n", fullWeaponName.c_str(), pWeapon->m_AttributeManager()->m_Item()->m_iItemDefinitionIndex(), pWeapon->m_AttributeManager()->m_Item()->m_bInitialized()); @@ -60,8 +72,7 @@ void __fastcall hook_GameFrame(void* rcx, bool simulating, bool bFirstTick, if (simulating && global::HasTicked) { global::m_flUniversalTime += global::GlobalVars->curtime - global::m_flLastTickedTime; - } - else { + } else { global::m_flUniversalTime += global::GlobalVars->interval_per_tick; } @@ -75,7 +86,7 @@ void __fastcall hook_GameFrame(void* rcx, bool simulating, bool bFirstTick, GameTimer::ExcuteTimers(); GameTickRunTime::ExcuteTickFunctions(); } - + return origin_GameFrame(rcx, simulating, bFirstTick, bLastTick); } void __fastcall hook_StartServer(void* rcx, @@ -173,6 +184,7 @@ bool __fastcall hook_FireEventServerSide(CGameEventManager* rcx, static constexpr auto round_start = hash_32_fnv1a_const("round_start"); static constexpr auto round_end = hash_32_fnv1a_const("round_end"); static constexpr auto player_hurt = hash_32_fnv1a_const("player_hurt"); + static constexpr auto player_team = hash_32_fnv1a_const("player_team"); switch (hash_32_fnv1a_const(eventName)) { case player_death: @@ -190,6 +202,9 @@ bool __fastcall hook_FireEventServerSide(CGameEventManager* rcx, case player_hurt: events::OnPlayerHurtEvent(event); break; + case player_team: + events::OnPlayerTeamChangeEevent(event); + break; // V社bug,这不会有用 /* case player_chat: @@ -263,7 +278,7 @@ auto initVmtHook() -> bool { origin_StartServer && origin_GameFrame; } auto initConVarHooks() -> void { - // Offset::InterFaces::IVEngineCvar->RegisterConVar + // Offset::InterFaces::IVEngineCvar->RegisterConVar } auto init() -> bool { bool isSuccess = initMinHook() && initVmtHook(); diff --git a/csgo2/offset.cpp b/csgo2/offset.cpp index 73ee570..4a1f880 100644 --- a/csgo2/offset.cpp +++ b/csgo2/offset.cpp @@ -78,7 +78,7 @@ auto Init() -> bool { 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); @@ -124,7 +124,7 @@ 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]FnGiveNamedItem : %llx \n", FnGiveNamedItem); @@ -157,8 +157,7 @@ auto Init() -> bool { 0, NULL); // LOG("FnServerHashFunction: %llx \n", FnServerHashFunction("here", // sizeof("here") - 1, 0x31415926)); - return FnCCSWeaponBase_Spawn && FnEntityRemove && FnRespawnPlayerInDeathMatch && FnGiveNamedItem && - FnServerHashFunction && Host_SayPtr && InterFaces::IVEngineServer && + return FnCCSWeaponBase_Spawn && FnEntityRemove && FnRespawnPlayerInDeathMatch && FnGiveNamedItem && Host_SayPtr && InterFaces::IVEngineServer && InterFaces::GameResourceServiceServer && InterFaces::IServerGameClient && InterFaces::GameEventManager && InterFaces::SchemaSystem && FireEventServerSidePtr && diff --git a/csgo2/script_apis.cpp b/csgo2/script_apis.cpp index 10f8833..3275597 100644 --- a/csgo2/script_apis.cpp +++ b/csgo2/script_apis.cpp @@ -790,6 +790,7 @@ auto luaApi_HttpPost(lua_State* luaVm) -> int { lua_pushstring(luaVm, response.c_str()); return 2; } + auto initFunciton(lua_State* luaVm) -> void { lua_register(luaVm, "ListenToGameEvent", luaApi_ListenToGameEvent); lua_register(luaVm, "luaApi_SetPlayerCurrentWeaponAmmo", @@ -838,6 +839,7 @@ auto initFunciton(lua_State* luaVm) -> void { lua_register(luaVm, "luaApi_HttpGet", luaApi_HttpGet); lua_register(luaVm, "luaApi_HttpPost", luaApi_HttpPost); lua_register(luaVm, "luaApi_GetPlayerSteamId", luaApi_GetPlayerSteamId); + //lua_register(luaVm, "luaApi_TeleportPlayer", luaApi_TeleportPlayer); luabridge::getGlobalNamespace(luaVm) .beginClass<_luaApi_WeaponInfo>("WeaponInfo") diff --git a/csgo2/script_callbacks.cpp b/csgo2/script_callbacks.cpp index 6448273..8135715 100644 --- a/csgo2/script_callbacks.cpp +++ b/csgo2/script_callbacks.cpp @@ -14,6 +14,7 @@ std::unordered_map callbackNameWithEnumMap{ {hash_32_fnv1a_const("round_start"), _CallbackNames::kOnRoundStart}, {hash_32_fnv1a_const("round_end"), _CallbackNames::kOnRoundEnd}, {hash_32_fnv1a_const("player_hurt"), _CallbackNames::kOnPlayerHurt}, + {hash_32_fnv1a_const("player_team"), _CallbackNames::kOnPlayerTeamChange}, }; auto CallBackNameToEnum(const char* name) -> _CallbackNames { if (name == nullptr) { @@ -205,4 +206,30 @@ auto luaCall_onPlayerHurt(int userid, int attacker, int health, int armor, } }); } +auto luaCall_onPlayerTeamChange(int userid, int team, int oldteam, bool disconnect, bool slient, bool isBot) -> bool { + bool result = false; + ExcuteCallbackInAllLuaVm(_CallbackNames::kOnPlayerTeamChange, + [&](lua_State* luaVm, int refIndex) -> void { + lua_rawgeti(luaVm, LUA_REGISTRYINDEX, + refIndex); + if (lua_isfunction(luaVm, -1)) { + lua_pushinteger(luaVm, userid); + lua_pushinteger(luaVm, team); + lua_pushinteger(luaVm, oldteam); + lua_pushboolean(luaVm, disconnect); + lua_pushboolean(luaVm, slient); + lua_pushboolean(luaVm, isBot); + + if (lua_pcall(luaVm, 6, 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 diff --git a/csgo2/script_callbacks.h b/csgo2/script_callbacks.h index c3e3ba1..664cf17 100644 --- a/csgo2/script_callbacks.h +++ b/csgo2/script_callbacks.h @@ -11,7 +11,8 @@ enum class _CallbackNames { kOnPlayerSpawn, kOnRoundStart, kOnRoundEnd, - kOnPlayerHurt + kOnPlayerHurt, + kOnPlayerTeamChange }; extern std::unordered_map> callbackList; @@ -33,4 +34,5 @@ auto luaCall_onRoundEnd(int winnerTeam, int reason, const char* message) auto luaCall_onPlayerHurt(int userid, int attacker, int health, int armor, const char* weapon, int dmg_health, int dmg_armor, int hitgroup) -> void; +auto luaCall_onPlayerTeamChange(int userid, int team, int oldteam, bool disconnect, bool slient, bool isBot) -> bool; } // namespace ScriptCallBacks diff --git a/csgo2/sdk/gameevent/IGameEvent.h b/csgo2/sdk/gameevent/IGameEvent.h index 3579092..5d2c105 100644 --- a/csgo2/sdk/gameevent/IGameEvent.h +++ b/csgo2/sdk/gameevent/IGameEvent.h @@ -9,87 +9,168 @@ class CUtlString; class IToolGameEventAPI { virtual void unk001(void*) = 0; }; -struct UnkGameEventStruct_t { - UnkGameEventStruct_t(const char* keyName) { - m_Unk = 0; - m_Key = keyName; + +static auto MurmurHash2(const void* key, int len, uint32 seed) -> uint32_t +{ +#define LittleDWord( val ) ( val ) + + // 'm' and 'r' are mixing constants generated offline. + // They're not really 'magic', they just happen to work well. + + const uint32 m = 0x5bd1e995; + const int r = 24; + + // Initialize the hash to a 'random' value + + uint32 h = seed ^ len; + + // Mix 4 bytes at a time into the hash + + const unsigned char* data = (const unsigned char*)key; + + while (len >= 4) + { + uint32 k = LittleDWord(*(uint32*)data); + + k *= m; + k ^= k >> r; + k *= m; + + h *= m; + h ^= k; + + data += 4; + len -= 4; } - uint64_t m_Unk; - const char* m_Key; + // Handle the last few bytes of the input array + + switch (len) + { + case 3: h ^= data[2] << 16; + case 2: h ^= data[1] << 8; + case 1: h ^= data[0]; + h *= m; + }; + + // Do a few final mixes of the hash to ensure the last few + // bytes are well-incorporated. + + h ^= h >> 13; + h *= m; + h ^= h >> 15; + + return h; +} + +struct GameEventKeySymbol_t { + GameEventKeySymbol_t(const char* keyName) { + if (keyName != nullptr) { + m_nHashCode = MurmurHash2(keyName, strlen(keyName), 0x31415926); + m_pszKeyName = keyName; + } + } + + uint64_t m_nHashCode; + const char* m_pszKeyName; }; -class IGameEvent { +class IHandleEntity +{ + virtual void Schema_DynamicBinding(void**) = 0; +public: + virtual ~IHandleEntity() = 0; + virtual const CEntityHandle GetRefEHandle() const = 0; +}; +class IGameEvent{ public: - // 0 - virtual ~IGameEvent(){}; + virtual ~IGameEvent() {}; virtual const char* GetName() const = 0; // get event name virtual int GetID() const = 0; virtual bool IsReliable() const = 0; // if event handled reliable virtual bool IsLocal() const = 0; // if event is never networked - virtual bool IsEmpty( - const char* keyName = NULL) = 0; // check if data field exists + virtual bool IsEmpty(const GameEventKeySymbol_t + & keySymbol) = 0; // check if data field exists - // Data access index 6 - virtual bool GetBool(UnkGameEventStruct_t* keyName = NULL, + // Data access + virtual bool GetBool(const GameEventKeySymbol_t& keySymbol, bool defaultValue = false) = 0; - virtual int GetInt(UnkGameEventStruct_t* keyName = NULL, + virtual int GetInt(const GameEventKeySymbol_t& keySymbol, int defaultValue = 0) = 0; - virtual uint64_t GetUint64(UnkGameEventStruct_t* keyName = NULL, - uint64_t defaultValue = 0) = 0; - virtual float GetFloat(UnkGameEventStruct_t* keyName = NULL, + virtual uint64 GetUint64(const GameEventKeySymbol_t& keySymbol, + uint64 defaultValue = 0) = 0; + virtual float GetFloat(const GameEventKeySymbol_t& keySymbol, float defaultValue = 0.0f) = 0; - virtual const char* GetString(UnkGameEventStruct_t* keyName = NULL, + virtual const char* GetString(const GameEventKeySymbol_t& keySymbol, const char* defaultValue = "") = 0; - virtual void* GetPtr(const char* keyName = NULL, - void* defaultValue = NULL) = 0; - - /* These function prototypes and names are very speculative and might be - * incorrect */ - virtual CEntityHandle GetEHandle(UnkGameEventStruct_t* keyName, - CEntityHandle defaultValue) = 0; - virtual CEntityHandle GetStrictEHandle(UnkGameEventStruct_t* keyName, - CEntityHandle defaultValue) = 0; - virtual CEntityHandle GetEHandle2(UnkGameEventStruct_t* keyName, - CEntityHandle defaultValue) = 0; - - virtual CPlayerSlot* GetPlayerSlot( - UnkGameEventStruct_t* keyName = NULL) = 0; - virtual CBasePlayer* GetPlayer(UnkGameEventStruct_t* keyName = NULL) = 0; - - virtual void* GetPlayerPawn(UnkGameEventStruct_t* keyName = NULL) = 0; - virtual CEntityHandle GetPlayerControllerEHandle( - UnkGameEventStruct_t* keyName = NULL) = 0; - virtual CEntityHandle GetPlayerControllerEHandle2( - UnkGameEventStruct_t* keyName = NULL) = 0; - /* ============================================================ */ - - virtual void SetBool(const char* keyName, bool value) = 0; - virtual void SetInt(const char* keyName, int value) = 0; - virtual void SetUint64(const char* keyName, uint64_t value) = 0; - virtual void SetFloat(const char* keyName, float value) = 0; - virtual void SetString(const char* keyName, const char* value) = 0; - virtual void SetPtr(const char* keyName, void* value) = 0; - - /* These function prototypes and names are very speculative and might be - * incorrect */ - virtual void SetEHandleStrict(const char* keyName, - CEntityHandle handle) = 0; - virtual void SetEHandle(const char* keyName, CEntityHandle handle) = 0; + virtual void* GetPtr(const GameEventKeySymbol_t& keySymbol) = 0; + + virtual CEntityHandle GetEHandle( + const GameEventKeySymbol_t& keySymbol, + CEntityHandle defaultValue = CEntityHandle()) = 0; + + // Returns the entity instance, mostly used for _pawn keys, might return 0 + // if used on any other key (even on a controller). + virtual IHandleEntity* GetEntity( + const GameEventKeySymbol_t& keySymbol, + IHandleEntity* fallbackInstance = NULL) = 0; + virtual CEntityIndex GetEntityIndex( + const GameEventKeySymbol_t& keySymbol, + CEntityIndex defaultValue = CEntityIndex(-1)) = 0; + + virtual CPlayerSlot GetPlayerSlot( + const GameEventKeySymbol_t& keySymbol) = 0; + + virtual IHandleEntity* GetPlayerController( + const GameEventKeySymbol_t& keySymbol) = 0; + virtual IHandleEntity* GetPlayerPawn( + const GameEventKeySymbol_t& keySymbol) = 0; + + // Returns the EHandle for the _pawn entity. + virtual CEntityHandle GetPawnEHandle( + const GameEventKeySymbol_t& keySymbol) = 0; + // Returns the CEntityIndex for the _pawn entity. + virtual CEntityIndex GetPawnEntityIndex( + const GameEventKeySymbol_t& keySymbol) = 0; + + virtual void SetBool(const GameEventKeySymbol_t& keySymbol, bool value) = 0; + virtual void SetInt(const GameEventKeySymbol_t& keySymbol, int value) = 0; + virtual void SetUint64(const GameEventKeySymbol_t& keySymbol, + uint64 value) = 0; + virtual void SetFloat(const GameEventKeySymbol_t& keySymbol, + float value) = 0; + virtual void SetString(const GameEventKeySymbol_t& keySymbol, + const char* value) = 0; + virtual void SetPtr(const GameEventKeySymbol_t& keySymbol, void* value) = 0; + + virtual void SetEntity(const GameEventKeySymbol_t& keySymbol, + CEntityIndex value) = 0; + virtual void SetEntity(const GameEventKeySymbol_t& keySymbol, + IHandleEntity* value) = 0; // Also sets the _pawn key - virtual void SetPlayerSlot(const char* keyName, CPlayerSlot value) = 0; - virtual void SetPlayer(const char* keyName, CBasePlayer* value) = 0; - /* ============================================================ */ + virtual void SetPlayer(const GameEventKeySymbol_t& keySymbol, + CPlayerSlot value) = 0; + // Also sets the _pawn key (Expects pawn entity to be passed) + virtual void SetPlayer(const GameEventKeySymbol_t& keySymbol, + IHandleEntity* pawn) = 0; - virtual bool HasKey(const char* keyName) = 0; + // Expects pawn entity to be passed, will set the controller entity as a + // controllerKeyName and pawn entity as a pawnKeyName. + virtual void SetPlayerRaw(const GameEventKeySymbol_t& controllerKeySymbol, + const GameEventKeySymbol_t& pawnKeySymbol, + IHandleEntity* pawn) = 0; + + virtual bool HasKey(const GameEventKeySymbol_t& keySymbol) = 0; // Something script vm related virtual void unk001() = 0; - // virtual KeyValues* GetDataKeys() const = 0; + // Not based on keyvalues anymore as it seems like + virtual void* GetDataKeys() const = 0; }; + class IGameEventListener2 { public: virtual ~IGameEventListener2(void){}; diff --git a/csgo2/tools.cpp b/csgo2/tools.cpp index 588925f..a8b7d49 100644 --- a/csgo2/tools.cpp +++ b/csgo2/tools.cpp @@ -1,5 +1,11 @@ #include "tools.h" namespace Tools { +auto toLower(const std::string& str) -> std::string{ + std::string lowerStr = str; + std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), + [](unsigned char c) { return std::tolower(c); }); + return lowerStr; +} auto GetDirs(const std::string& path) -> std::pair, std::vector> { std::vector dirPaths; diff --git a/csgo2/tools.h b/csgo2/tools.h index 75d194c..6cf3377 100644 --- a/csgo2/tools.h +++ b/csgo2/tools.h @@ -6,4 +6,5 @@ auto GetExePath() -> std::string; auto GetFiles(const std::string& path, std::vector& files) -> void; auto GetDirs(const std::string& path) -> std::pair, std::vector>; +auto toLower(const std::string& str) -> std::string; }; // namespace Tools