aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/clientchathooks.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-08-24 00:32:31 +0100
committerGeckoEidechse <gecko.eidechse+git@pm.me>2022-08-25 21:32:55 +0200
commit46bed8d09f32360377350d71816a76abdfbf2c7c (patch)
tree7feedae4910dbfe0e53d26ea1e00c4616d2c1850 /NorthstarDLL/clientchathooks.cpp
parenta97f1f07bb5aa31629cd87023e09669eb4bf1fe9 (diff)
downloadNorthstarLauncher-46bed8d09f32360377350d71816a76abdfbf2c7c.tar.gz
NorthstarLauncher-46bed8d09f32360377350d71816a76abdfbf2c7c.zip
Adjust folder structure (#242)v1.9.5-rc1v1.9.5
* Adjust folder structure * change launcher directory name
Diffstat (limited to 'NorthstarDLL/clientchathooks.cpp')
-rw-r--r--NorthstarDLL/clientchathooks.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/NorthstarDLL/clientchathooks.cpp b/NorthstarDLL/clientchathooks.cpp
new file mode 100644
index 00000000..74418c06
--- /dev/null
+++ b/NorthstarDLL/clientchathooks.cpp
@@ -0,0 +1,95 @@
+#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;
+
+struct ChatTags
+{
+ bool whisper;
+ bool team;
+ bool dead;
+};
+
+static void CHudChat__AddGameLineHook(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)
+ {
+ 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_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);
+ }
+ 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 = ClientSq_getinteger(sqvm, 1);
+ const char* str = ClientSq_getstring(sqvm, 2);
+
+ LocalChatWriter((LocalChatWriter::Context)context).Write(str);
+ return SQRESULT_NOTNULL;
+}
+
+// void NSChatWriteRaw( int context, string str )
+static SQRESULT SQ_ChatWriteRaw(void* sqvm)
+{
+ int context = ClientSq_getinteger(sqvm, 1);
+ const char* str = ClientSq_getstring(sqvm, 2);
+
+ LocalChatWriter((LocalChatWriter::Context)context).InsertText(str);
+ return SQRESULT_NOTNULL;
+}
+
+// void NSChatWriteLine( int context, string str )
+static SQRESULT SQ_ChatWriteLine(void* sqvm)
+{
+ int context = ClientSq_getinteger(sqvm, 1);
+ const char* str = ClientSq_getstring(sqvm, 2);
+
+ LocalChatWriter((LocalChatWriter::Context)context).WriteLine(str);
+ return SQRESULT_NOTNULL;
+}
+
+void InitialiseClientChatHooks(HMODULE baseAddress)
+{
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x22E580, &CHudChat__AddGameLineHook, reinterpret_cast<LPVOID*>(&CHudChat__AddGameLine));
+
+ 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);
+}