Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
add console chat api
Browse files Browse the repository at this point in the history
  • Loading branch information
huoji120 committed Oct 18, 2023
1 parent b53f445 commit 254d0e1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
26 changes: 16 additions & 10 deletions csgo2/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CCSPlayerPawn*>(
event->GetPlayerPawn(userIdNameParams));
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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<CCSPlayerPawn*>(
event->GetPlayerPawn(userIdNameParams));
const auto attackerPawn = reinterpret_cast<CCSPlayerPawn*>(
Expand All @@ -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<int>(_ChatType::kConsole), message);
}
auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool {
auto [procesChatSuccess, chatType, chatCtx] =
Expand All @@ -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<int>(chatType),
chatCtx);
}
auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
const char* pszNetworkID, const char* pszAddress,
Expand Down
1 change: 1 addition & 0 deletions csgo2/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions csgo2/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions csgo2/script_apis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(_HubType::kMax) || hudType < static_cast<int>(_HubType::kNotify)) {
lua_pop(luaVm, 3);
return 0;
}
Expand All @@ -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<int>(_HubType::kMax) || hudType < static_cast<int>(_HubType::kNotify)) {
lua_pop(luaVm, 3);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions csgo2/sdk_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(hubtype), buf, nullptr, nullptr, nullptr, nullptr);
}
auto SendConsoleChat(_HubType hubtype, const char* msg, ...) -> void
{
Expand All @@ -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<int>(hubtype), buf, nullptr, nullptr, nullptr, nullptr);
}
}; // namespace SdkTools
4 changes: 2 additions & 2 deletions csgo2/sdk_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 254d0e1

Please sign in to comment.