aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/clientchathooks.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-05-27 01:13:14 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-05-27 01:13:14 +0100
commit0de847bb4832c201233c87fa37867b9d89f0e8c8 (patch)
treef05add722b788d32aae40663e7748234452a3443 /NorthstarDLL/clientchathooks.cpp
parent2171d95e1221442081bade7929c05b82ca0f2a08 (diff)
downloadNorthstarLauncher-0de847bb4832c201233c87fa37867b9d89f0e8c8.tar.gz
NorthstarLauncher-0de847bb4832c201233c87fa37867b9d89f0e8c8.zip
rename project folder (:tf: commit log)
Diffstat (limited to 'NorthstarDLL/clientchathooks.cpp')
-rw-r--r--NorthstarDLL/clientchathooks.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/NorthstarDLL/clientchathooks.cpp b/NorthstarDLL/clientchathooks.cpp
new file mode 100644
index 00000000..f778c6ee
--- /dev/null
+++ b/NorthstarDLL/clientchathooks.cpp
@@ -0,0 +1,87 @@
+#include "pch.h"
+#include "squirrel.h"
+#include "serverchathooks.h"
+#include "localchatwriter.h"
+
+#include <rapidjson/document.h>
+
+AUTOHOOK_INIT()
+
+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_pClientSquirrel->setupfunc("CHudChat_ProcessMessageStartThread") != SQRESULT_ERROR)
+ {
+ 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;
+ }
+
+ g_pClientSquirrel->pushinteger(g_pClientSquirrel->sqvm2, (int) senderId - 1);
+ g_pClientSquirrel->pushstring(g_pClientSquirrel->sqvm2, payload);
+ g_pClientSquirrel->pushbool(g_pClientSquirrel->sqvm2, isTeam);
+ g_pClientSquirrel->pushbool(g_pClientSquirrel->sqvm2, isDead);
+ g_pClientSquirrel->pushinteger(g_pClientSquirrel->sqvm2, type);
+ g_pClientSquirrel->call(g_pClientSquirrel->sqvm2, 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)
+{
+ int context = g_pClientSquirrel->getinteger(g_pClientSquirrel->sqvm2, 1);
+ const char* str = g_pClientSquirrel->getstring(g_pClientSquirrel->sqvm2, 2);
+
+ LocalChatWriter((LocalChatWriter::Context)context).Write(str);
+ return SQRESULT_NOTNULL;
+}
+
+// void NSChatWriteRaw( int context, string str )
+static SQRESULT SQ_ChatWriteRaw(void* sqvm)
+{
+ int context = g_pClientSquirrel->getinteger(g_pClientSquirrel->sqvm2, 1);
+ const char* str = g_pClientSquirrel->getstring(g_pClientSquirrel->sqvm2, 2);
+
+ LocalChatWriter((LocalChatWriter::Context)context).InsertText(str);
+ return SQRESULT_NOTNULL;
+}
+
+// void NSChatWriteLine( int context, string str )
+static SQRESULT SQ_ChatWriteLine(void* sqvm)
+{
+ int context = g_pClientSquirrel->getinteger(g_pClientSquirrel->sqvm2, 1);
+ const char* str = g_pClientSquirrel->getstring(g_pClientSquirrel->sqvm2, 2);
+
+ LocalChatWriter((LocalChatWriter::Context)context).WriteLine(str);
+ return SQRESULT_NOTNULL;
+}
+
+ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientChatHooks, ClientSquirrel, [](HMODULE baseAddress)
+{
+ AUTOHOOK_DISPATCH()
+
+ g_pClientSquirrel->AddFuncRegistration("void", "NSChatWrite", "int context, string text", "", SQ_ChatWrite);
+ g_pClientSquirrel->AddFuncRegistration("void", "NSChatWriteRaw", "int context, string text", "", SQ_ChatWriteRaw);
+ g_pClientSquirrel->AddFuncRegistration("void", "NSChatWriteLine", "int context, string text", "", SQ_ChatWriteLine);
+})