diff options
Diffstat (limited to 'NorthstarDLL/clientchathooks.cpp')
-rw-r--r-- | NorthstarDLL/clientchathooks.cpp | 70 |
1 files changed, 28 insertions, 42 deletions
diff --git a/NorthstarDLL/clientchathooks.cpp b/NorthstarDLL/clientchathooks.cpp index 74418c06..fc7c1f19 100644 --- a/NorthstarDLL/clientchathooks.cpp +++ b/NorthstarDLL/clientchathooks.cpp @@ -1,29 +1,20 @@ #include "pch.h" -#include "clientchathooks.h" -#include <rapidjson/document.h> #include "squirrel.h" #include "serverchathooks.h" #include "localchatwriter.h" -typedef void(__fastcall* CHudChat__AddGameLineType)(void* self, const char* message, int fromPlayerId, bool isteam, bool isdead); -CHudChat__AddGameLineType CHudChat__AddGameLine; +#include <rapidjson/document.h> -struct ChatTags -{ - bool whisper; - bool team; - bool dead; -}; +AUTOHOOK_INIT() -static void CHudChat__AddGameLineHook(void* self, const char* message, int inboxId, bool isTeam, bool isDead) +AUTOHOOK(CHudChat__AddGameLine, client.dll + 0x22E580, +void,, (void* self, const char* message, int inboxId, bool isTeam, bool isDead)) { // This hook is called for each HUD, but we only want our logic to run once. if (self != *CHudChat::allHuds) - { return; - } - if (g_ClientSquirrelManager->setupfunc("CHudChat_ProcessMessageStartThread") != SQRESULT_ERROR) + if (g_pSquirrel<ScriptContext::CLIENT>->setupfunc("CHudChat_ProcessMessageStartThread") != SQRESULT_ERROR) { int senderId = inboxId & CUSTOM_MESSAGE_INDEX_MASK; bool isAnonymous = senderId == 0; @@ -38,58 +29,53 @@ static void CHudChat__AddGameLineHook(void* self, const char* message, int inbox payload = message + 1; } - g_ClientSquirrelManager->pusharg((int)senderId - 1); - g_ClientSquirrelManager->pusharg(payload); - g_ClientSquirrelManager->pusharg(isTeam); - g_ClientSquirrelManager->pusharg(isDead); - g_ClientSquirrelManager->pusharg(type); - g_ClientSquirrelManager->call(5); + g_pSquirrel<ScriptContext::CLIENT>->pushinteger(g_pSquirrel<ScriptContext::CLIENT>->sqvm, (int)senderId - 1); + g_pSquirrel<ScriptContext::CLIENT>->pushstring(g_pSquirrel<ScriptContext::CLIENT>->sqvm, payload); + g_pSquirrel<ScriptContext::CLIENT>->pushbool(g_pSquirrel<ScriptContext::CLIENT>->sqvm, isTeam); + g_pSquirrel<ScriptContext::CLIENT>->pushbool(g_pSquirrel<ScriptContext::CLIENT>->sqvm, isDead); + g_pSquirrel<ScriptContext::CLIENT>->pushinteger(g_pSquirrel<ScriptContext::CLIENT>->sqvm, type); + g_pSquirrel<ScriptContext::CLIENT>->call(g_pSquirrel<ScriptContext::CLIENT>->sqvm, 5); } else - { for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next) - { CHudChat__AddGameLine(hud, message, inboxId, isTeam, isDead); - } - } } // void NSChatWrite( int context, string str ) -static SQRESULT SQ_ChatWrite(void* sqvm) +SQRESULT SQ_ChatWrite(HSquirrelVM* sqvm) { - int context = ClientSq_getinteger(sqvm, 1); - const char* str = ClientSq_getstring(sqvm, 2); + int context = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); LocalChatWriter((LocalChatWriter::Context)context).Write(str); - return SQRESULT_NOTNULL; + return SQRESULT_NULL; } // void NSChatWriteRaw( int context, string str ) -static SQRESULT SQ_ChatWriteRaw(void* sqvm) +SQRESULT SQ_ChatWriteRaw(HSquirrelVM* sqvm) { - int context = ClientSq_getinteger(sqvm, 1); - const char* str = ClientSq_getstring(sqvm, 2); + int context = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); LocalChatWriter((LocalChatWriter::Context)context).InsertText(str); - return SQRESULT_NOTNULL; + return SQRESULT_NULL; } // void NSChatWriteLine( int context, string str ) -static SQRESULT SQ_ChatWriteLine(void* sqvm) +SQRESULT SQ_ChatWriteLine(HSquirrelVM* sqvm) { - int context = ClientSq_getinteger(sqvm, 1); - const char* str = ClientSq_getstring(sqvm, 2); + int context = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); LocalChatWriter((LocalChatWriter::Context)context).WriteLine(str); - return SQRESULT_NOTNULL; + return SQRESULT_NULL; } -void InitialiseClientChatHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientChatHooks, ClientSquirrel, (CModule module)) { - HookEnabler hook; - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x22E580, &CHudChat__AddGameLineHook, reinterpret_cast<LPVOID*>(&CHudChat__AddGameLine)); + AUTOHOOK_DISPATCH() - g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWrite", "int context, string text", "", SQ_ChatWrite); - g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWriteRaw", "int context, string text", "", SQ_ChatWriteRaw); - g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWriteLine", "int context, string text", "", SQ_ChatWriteLine); + g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration("void", "NSChatWrite", "int context, string text", "", SQ_ChatWrite); + g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration("void", "NSChatWriteRaw", "int context, string text", "", SQ_ChatWriteRaw); + g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration("void", "NSChatWriteLine", "int context, string text", "", SQ_ChatWriteLine); } |