add console chat api

This commit is contained in:
Huoji's
2023-10-19 03:16:12 +08:00
parent b53f4457e6
commit 254d0e1cd5
6 changed files with 34 additions and 21 deletions

View File

@@ -2,12 +2,12 @@
namespace events { namespace events {
auto OnPlayerTeamChangeEevent(IGameEvent* event) -> void { auto OnPlayerTeamChangeEevent(IGameEvent* event) -> void {
GameEventKeySymbol_t userIdNameParams{ "userid" }; GameEventKeySymbol_t userIdNameParams{"userid"};
GameEventKeySymbol_t teamNameParams{ "team" }; GameEventKeySymbol_t teamNameParams{"team"};
GameEventKeySymbol_t oldteamNameParams{ "oldteam" }; GameEventKeySymbol_t oldteamNameParams{"oldteam"};
GameEventKeySymbol_t disconnectNameParams{ "disconnect"}; GameEventKeySymbol_t disconnectNameParams{"disconnect"};
GameEventKeySymbol_t silentNameParams{ "silent" }; GameEventKeySymbol_t silentNameParams{"silent"};
GameEventKeySymbol_t isbotParams{ "isbot"}; GameEventKeySymbol_t isbotParams{"isbot"};
const auto PlayerPawn = reinterpret_cast<CCSPlayerPawn*>( const auto PlayerPawn = reinterpret_cast<CCSPlayerPawn*>(
event->GetPlayerPawn(userIdNameParams)); event->GetPlayerPawn(userIdNameParams));
@@ -27,7 +27,8 @@ auto OnPlayerTeamChangeEevent(IGameEvent* event) -> void {
auto disconnect = event->GetBool(disconnectNameParams); auto disconnect = event->GetBool(disconnectNameParams);
auto slient = event->GetBool(silentNameParams); auto slient = event->GetBool(silentNameParams);
auto isBot = event->GetBool(isbotParams); 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); event->SetBool(silentNameParams, true);
} }
} }
@@ -115,7 +116,7 @@ auto OnPlayerDeathEvent(IGameEvent* event) -> void {
GameEventKeySymbol_t userIdNameParams{"userid"}; GameEventKeySymbol_t userIdNameParams{"userid"};
GameEventKeySymbol_t attackerNameParams{"attacker"}; GameEventKeySymbol_t attackerNameParams{"attacker"};
GameEventKeySymbol_t headshotNameParams{"headshot"}; GameEventKeySymbol_t headshotNameParams{"headshot"};
const auto victimPawn = reinterpret_cast<CCSPlayerPawn*>( const auto victimPawn = reinterpret_cast<CCSPlayerPawn*>(
event->GetPlayerPawn(userIdNameParams)); event->GetPlayerPawn(userIdNameParams));
const auto attackerPawn = reinterpret_cast<CCSPlayerPawn*>( const auto attackerPawn = reinterpret_cast<CCSPlayerPawn*>(
@@ -137,7 +138,11 @@ auto OnPlayerDeathEvent(IGameEvent* event) -> void {
const auto attackerIndex = attacker->GetRefEHandle().GetEntryIndex(); const auto attackerIndex = attacker->GetRefEHandle().GetEntryIndex();
ScriptCallBacks::luaCall_onPlayerDeath(victimIndex, attackerIndex, ScriptCallBacks::luaCall_onPlayerDeath(victimIndex, attackerIndex,
isHeadShot); 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 OnPlayerChat(CCSPlayerController* player, std::string message) -> bool {
auto [procesChatSuccess, chatType, chatCtx] = auto [procesChatSuccess, chatType, chatCtx] =
@@ -146,7 +151,8 @@ auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool {
return false; return false;
} }
return ScriptCallBacks::luaCall_onPlayerSpeak( 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, auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
const char* pszNetworkID, const char* pszAddress, const char* pszNetworkID, const char* pszAddress,

View File

@@ -4,6 +4,7 @@ class CCSPlayerController;
namespace events { namespace events {
auto OnPlayerDeathEvent(IGameEvent* event) -> void; auto OnPlayerDeathEvent(IGameEvent* event) -> void;
auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool; auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool;
auto OnConsoleChat(std::string message) -> bool;
auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid, auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
const char* pszNetworkID, const char* pszAddress, const char* pszNetworkID, const char* pszAddress,
bool bFakePlayer) -> void; bool bFakePlayer) -> void;

View File

@@ -36,8 +36,7 @@ void __fastcall hook_CCSWeaponBase_Spawn(CBaseEntity* pThis, void* a2) {
for (const auto& weapon : GameWeapons::WeaponMap) { for (const auto& weapon : GameWeapons::WeaponMap) {
const auto& key = weapon.first; const auto& key = weapon.first;
const auto& [fullWeaponName, weaponItemDefIndex] = weapon.second; const auto& [fullWeaponName, weaponItemDefIndex] = weapon.second;
if (fullWeaponName.find(weaponName) == if (fullWeaponName.find(weaponName) == std::string::npos) {
std::string::npos) {
continue; continue;
} }
lookupWeaponSimpleName = key; lookupWeaponSimpleName = key;
@@ -50,7 +49,8 @@ void __fastcall hook_CCSWeaponBase_Spawn(CBaseEntity* pThis, void* a2) {
const auto [fullWeaponName, weaponiItemDefIndex] = const auto [fullWeaponName, weaponiItemDefIndex] =
GameWeapons::WeaponMap.at(lookupWeaponSimpleName); 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_iItemDefinitionIndex(),
pWeapon->m_AttributeManager()->m_Item()->m_bInitialized()); 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; char* pos = nullptr;
bool blockMsg = false; bool blockMsg = false;
do { do {
if (theArgs == nullptr || theEntity == nullptr) { if (theArgs == nullptr) {
break; break;
} }
const auto message = std::string(theArgs->GetCommandString()); 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) { if (events::OnPlayerChat(theEntity, message) == true) {
blockMsg = true; blockMsg = true;
break; break;

View File

@@ -593,7 +593,7 @@ auto luaApi_SendToPlayerChat(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
const auto hudType = lua_tointeger(luaVm, 2); const auto hudType = lua_tointeger(luaVm, 2);
const auto message = lua_tostring(luaVm, 3); 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); lua_pop(luaVm, 3);
return 0; return 0;
} }
@@ -608,7 +608,7 @@ auto luaApi_SentToAllPlayerChat(lua_State* luaVm) -> int {
// param: playerIndex:int, message:string // param: playerIndex:int, message:string
const auto message = lua_tostring(luaVm, 1); const auto message = lua_tostring(luaVm, 1);
const auto hudType = lua_tointeger(luaVm, 2); 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); lua_pop(luaVm, 3);
return 0; return 0;
} }

View File

@@ -38,7 +38,7 @@ auto SentChatToClient(CCSPlayerController* player, _HubType hubtype, const char*
va_end(args); 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 auto SendConsoleChat(_HubType hubtype, const char* msg, ...) -> void
{ {
@@ -50,6 +50,6 @@ auto SendConsoleChat(_HubType hubtype, const char* msg, ...) -> void
va_end(args); 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 }; // namespace SdkTools

View File

@@ -8,8 +8,8 @@ inline int EntityIndex_to_PlayerSlot(int EntityIndex) {
#define HUD_PRINTCONSOLE 2 #define HUD_PRINTCONSOLE 2
#define HUD_PRINTTALK 3 #define HUD_PRINTTALK 3
#define HUD_PRINTCENTER 4 #define HUD_PRINTCENTER 4
enum _ChatType { kTeam, kAll }; enum class _ChatType { kTeam, kAll, kConsole };
enum _HubType { kNotify = 1, kConsole, kTalk, kCenter, kMax }; enum class _HubType { kNotify = 1, kConsole, kTalk, kCenter, kMax };
namespace SdkTools { namespace SdkTools {
auto ProcessChatString(const std::string& input) auto ProcessChatString(const std::string& input)