diff options
author | Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> | 2023-12-27 00:32:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 01:32:01 +0100 |
commit | f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287 (patch) | |
tree | 90f2c6a4885dbd181799e2325cf33588697674e1 /primedev/scripts/client/clientchathooks.cpp | |
parent | bb8ed59f6891b1196c5f5bbe7346cd171c8215fa (diff) | |
download | NorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.tar.gz NorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.zip |
Folder restructuring from primedev (#624)v1.21.2-rc3v1.21.2
Copies of over the primedev folder structure for easier cherry-picking of further changes
Co-authored-by: F1F7Y <filip.bartos07@proton.me>
Diffstat (limited to 'primedev/scripts/client/clientchathooks.cpp')
-rw-r--r-- | primedev/scripts/client/clientchathooks.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/primedev/scripts/client/clientchathooks.cpp b/primedev/scripts/client/clientchathooks.cpp new file mode 100644 index 00000000..e084f47e --- /dev/null +++ b/primedev/scripts/client/clientchathooks.cpp @@ -0,0 +1,72 @@ +#include "squirrel/squirrel.h" +#include "util/utils.h" + +#include "server/serverchathooks.h" +#include "client/localchatwriter.h" + +#include <rapidjson/document.h> + +AUTOHOOK_INIT() + +// clang-format off +AUTOHOOK(CHudChat__AddGameLine, client.dll + 0x22E580, +void, __fastcall, (void* self, const char* message, int inboxId, bool isTeam, bool isDead)) +// clang-format on +{ + // This hook is called for each HUD, but we only want our logic to run once. + if (self != *CHudChat::allHuds) + return; + + int senderId = inboxId & CUSTOM_MESSAGE_INDEX_MASK; + bool isAnonymous = senderId == 0; + bool isCustom = isAnonymous || (inboxId & CUSTOM_MESSAGE_INDEX_BIT); + + // Type is set to 0 for non-custom messages, custom messages have a type encoded as the first byte + int type = 0; + const char* payload = message; + if (isCustom) + { + type = message[0]; + payload = message + 1; + } + + RemoveAsciiControlSequences(const_cast<char*>(message), true); + + SQRESULT result = g_pSquirrel<ScriptContext::CLIENT>->Call( + "CHudChat_ProcessMessageStartThread", static_cast<int>(senderId) - 1, payload, isTeam, isDead, type); + if (result == SQRESULT_ERROR) + for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next) + CHudChat__AddGameLine(hud, message, inboxId, isTeam, isDead); +} + +ADD_SQFUNC("void", NSChatWrite, "int context, string text", "", ScriptContext::CLIENT) +{ + int chatContext = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); + + LocalChatWriter((LocalChatWriter::Context)chatContext).Write(str); + return SQRESULT_NULL; +} + +ADD_SQFUNC("void", NSChatWriteRaw, "int context, string text", "", ScriptContext::CLIENT) +{ + int chatContext = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); + + LocalChatWriter((LocalChatWriter::Context)chatContext).InsertText(str); + return SQRESULT_NULL; +} + +ADD_SQFUNC("void", NSChatWriteLine, "int context, string text", "", ScriptContext::CLIENT) +{ + int chatContext = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); + + LocalChatWriter((LocalChatWriter::Context)chatContext).WriteLine(str); + return SQRESULT_NULL; +} + +ON_DLL_LOAD_CLIENT("client.dll", ClientChatHooks, (CModule module)) +{ + AUTOHOOK_DISPATCH() +} |