add console chat api
This commit is contained in:
@@ -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));
|
||||
@@ -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<CCSPlayerPawn*>(
|
||||
event->GetPlayerPawn(userIdNameParams));
|
||||
const auto attackerPawn = reinterpret_cast<CCSPlayerPawn*>(
|
||||
@@ -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] =
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user