diff --git a/csgo2/events.cpp b/csgo2/events.cpp index 9a4ef6f..10b921a 100644 --- a/csgo2/events.cpp +++ b/csgo2/events.cpp @@ -2,12 +2,12 @@ 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"}; + 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)); @@ -27,7 +27,8 @@ auto OnPlayerTeamChangeEevent(IGameEvent* event) -> void { 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) { + if (ScriptCallBacks::luaCall_onPlayerTeamChange( + playerIndex, team, oldTeam, disconnect, slient, isBot) == true) { event->SetBool(silentNameParams, true); } } @@ -115,7 +116,7 @@ auto OnPlayerDeathEvent(IGameEvent* event) -> void { GameEventKeySymbol_t userIdNameParams{"userid"}; GameEventKeySymbol_t attackerNameParams{"attacker"}; GameEventKeySymbol_t headshotNameParams{"headshot"}; - + const auto victimPawn = reinterpret_cast( event->GetPlayerPawn(userIdNameParams)); const auto attackerPawn = reinterpret_cast( @@ -137,7 +138,11 @@ auto OnPlayerDeathEvent(IGameEvent* event) -> void { const auto attackerIndex = attacker->GetRefEHandle().GetEntryIndex(); ScriptCallBacks::luaCall_onPlayerDeath(victimIndex, attackerIndex, isHeadShot); - //printf("player[%p] %s kill[%p] %llu\n", attacker, &attacker->m_iszPlayerName(), victim, &victim->m_steamID()); + // printf("player[%p] %s kill[%p] %llu\n", attacker, + // &attacker->m_iszPlayerName(), victim, &victim->m_steamID()); +} +auto OnConsoleChat(std::string message) -> bool { + return ScriptCallBacks::luaCall_onPlayerSpeak(-1, static_cast(_ChatType::kConsole), message); } auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool { auto [procesChatSuccess, chatType, chatCtx] = @@ -146,7 +151,8 @@ auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool { return false; } return ScriptCallBacks::luaCall_onPlayerSpeak( - player->GetRefEHandle().GetEntryIndex(), chatType, chatCtx); + player->GetRefEHandle().GetEntryIndex(), static_cast(chatType), + chatCtx); } auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid, const char* pszNetworkID, const char* pszAddress, diff --git a/csgo2/events.h b/csgo2/events.h index 9d4f01e..d0eae3f 100644 --- a/csgo2/events.h +++ b/csgo2/events.h @@ -4,6 +4,7 @@ class CCSPlayerController; namespace events { auto OnPlayerDeathEvent(IGameEvent* event) -> void; auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool; +auto OnConsoleChat(std::string message) -> bool; auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid, const char* pszNetworkID, const char* pszAddress, bool bFakePlayer) -> void; diff --git a/csgo2/hooks.cpp b/csgo2/hooks.cpp index aca486b..fa89dc7 100644 --- a/csgo2/hooks.cpp +++ b/csgo2/hooks.cpp @@ -36,8 +36,7 @@ void __fastcall hook_CCSWeaponBase_Spawn(CBaseEntity* pThis, void* a2) { for (const auto& weapon : GameWeapons::WeaponMap) { const auto& key = weapon.first; const auto& [fullWeaponName, weaponItemDefIndex] = weapon.second; - if (fullWeaponName.find(weaponName) == - std::string::npos) { + if (fullWeaponName.find(weaponName) == std::string::npos) { continue; } lookupWeaponSimpleName = key; @@ -50,7 +49,8 @@ void __fastcall hook_CCSWeaponBase_Spawn(CBaseEntity* pThis, void* a2) { const auto [fullWeaponName, weaponiItemDefIndex] = GameWeapons::WeaponMap.at(lookupWeaponSimpleName); - LOG("Fixing a %s with index = %d and initialized = %d\n", fullWeaponName.c_str(), + 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()); @@ -139,11 +139,17 @@ void __fastcall hook_Host_Say(void* pEntity, void* args, bool teamonly, char* pos = nullptr; bool blockMsg = false; do { - if (theArgs == nullptr || theEntity == nullptr) { + if (theArgs == nullptr) { break; } const auto message = std::string(theArgs->GetCommandString()); - + if (theEntity == nullptr) { + if (events::OnConsoleChat(message) == true) { + blockMsg = true; + break; + } + break; + } if (events::OnPlayerChat(theEntity, message) == true) { blockMsg = true; break; diff --git a/csgo2/script_apis.cpp b/csgo2/script_apis.cpp index 0d5b878..dd1bcb9 100644 --- a/csgo2/script_apis.cpp +++ b/csgo2/script_apis.cpp @@ -593,7 +593,7 @@ 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 >= _HubType::kMax || hudType < _HubType::kNotify) { + if (hudType >= static_cast(_HubType::kMax) || hudType < static_cast(_HubType::kNotify)) { lua_pop(luaVm, 3); return 0; } @@ -608,7 +608,7 @@ 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 >= _HubType::kMax || hudType < _HubType::kNotify) { + if (hudType >= static_cast(_HubType::kMax) || hudType < static_cast(_HubType::kNotify)) { lua_pop(luaVm, 3); return 0; } diff --git a/csgo2/sdk_tools.cpp b/csgo2/sdk_tools.cpp index 8207867..4f5108c 100644 --- a/csgo2/sdk_tools.cpp +++ b/csgo2/sdk_tools.cpp @@ -38,7 +38,7 @@ auto SentChatToClient(CCSPlayerController* player, _HubType hubtype, const char* va_end(args); - Offset::FnClientPrint(player, hubtype, buf, nullptr, nullptr, nullptr, nullptr); + Offset::FnClientPrint(player, static_cast(hubtype), buf, nullptr, nullptr, nullptr, nullptr); } auto SendConsoleChat(_HubType hubtype, const char* msg, ...) -> void { @@ -50,6 +50,6 @@ auto SendConsoleChat(_HubType hubtype, const char* msg, ...) -> void va_end(args); - Offset::FnUTIL_ClientPrintAll(hubtype, buf, nullptr, nullptr, nullptr, nullptr); + Offset::FnUTIL_ClientPrintAll(static_cast(hubtype), buf, nullptr, nullptr, nullptr, nullptr); } }; // namespace SdkTools diff --git a/csgo2/sdk_tools.h b/csgo2/sdk_tools.h index 86894fd..0c95519 100644 --- a/csgo2/sdk_tools.h +++ b/csgo2/sdk_tools.h @@ -8,8 +8,8 @@ inline int EntityIndex_to_PlayerSlot(int EntityIndex) { #define HUD_PRINTCONSOLE 2 #define HUD_PRINTTALK 3 #define HUD_PRINTCENTER 4 -enum _ChatType { kTeam, kAll }; -enum _HubType { kNotify = 1, kConsole, kTalk, kCenter, kMax }; +enum class _ChatType { kTeam, kAll, kConsole }; +enum class _HubType { kNotify = 1, kConsole, kTalk, kCenter, kMax }; namespace SdkTools { auto ProcessChatString(const std::string& input)