aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/logging.cpp
diff options
context:
space:
mode:
authorHappyDOGE <28511119+HappyDOGE@users.noreply.github.com>2022-01-29 12:21:41 +0300
committerHappyDOGE <28511119+HappyDOGE@users.noreply.github.com>2022-01-29 12:21:41 +0300
commit800b2a7dbd9c344873841e225407b3fcd6d29fe0 (patch)
treec6ca9b1842fd5ca4bcbd537a818249fe2a5f2b81 /NorthstarDedicatedTest/logging.cpp
parentb9c611229e87075bd64ac2b8b8e8a736723daeca (diff)
downloadNorthstarLauncher-800b2a7dbd9c344873841e225407b3fcd6d29fe0.tar.gz
NorthstarLauncher-800b2a7dbd9c344873841e225407b3fcd6d29fe0.zip
add TextMsg logging
Diffstat (limited to 'NorthstarDedicatedTest/logging.cpp')
-rw-r--r--NorthstarDedicatedTest/logging.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp
index 235bfe2e..9fc39cde 100644
--- a/NorthstarDedicatedTest/logging.cpp
+++ b/NorthstarDedicatedTest/logging.cpp
@@ -387,4 +387,63 @@ void InitialiseEngineSpewFuncHooks(HMODULE baseAddress)
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1A1530, CClientState_ProcessPrint_Hook, reinterpret_cast<LPVOID*>(&CClientState_ProcessPrint_Original));
Cvar_spewlog_enable = RegisterConVar("spewlog_enable", "1", FCVAR_NONE, "Enables/disables whether the engine spewfunc should be logged");
+}
+
+#include "bitbuf.h"
+
+ConVar* Cvar_cl_showtextmsg;
+
+typedef void(*TextMsg_Type)(__int64);
+TextMsg_Type TextMsg_Original;
+
+class ICenterPrint
+{
+public:
+ virtual void ctor() = 0;
+ virtual void Clear(void) = 0;
+ virtual void ColorPrint(int r, int g, int b, int a, wchar_t* text) = 0;
+ virtual void ColorPrint(int r, int g, int b, int a, char* text) = 0;
+ virtual void Print(wchar_t* text) = 0;
+ virtual void Print(char* text) = 0;
+ virtual void SetTextColor(int r, int g, int b, int a) = 0;
+};
+
+ICenterPrint* internalCenterPrint = NULL;
+
+void TextMsgHook(BFRead* msg)
+{
+ int msg_dest = msg->ReadByte();
+
+ char text[256];
+ msg->ReadString(text, sizeof(text));
+
+ if (!Cvar_cl_showtextmsg->m_nValue)
+ return;
+
+ switch (msg_dest) {
+ case 4: // HUD_PRINTCENTER
+ internalCenterPrint->Print(text);
+ break;
+ default:
+ spdlog::warn("Unimplemented TextMsg type {}! printing to console", msg_dest);
+ [[fallthrough]];
+ case 2: // HUD_PRINTCONSOLE
+ auto endpos = strlen(text);
+ if (text[endpos - 1] == '\n')
+ text[endpos - 1] = '\0'; // cut off repeated newline
+ spdlog::info(text);
+ break;
+ }
+}
+
+void InitialiseClientPrintHooks(HMODULE baseAddress)
+{
+ HookEnabler hook;
+
+ internalCenterPrint = (ICenterPrint*)((char*)baseAddress + 0x216E940);
+
+ // "TextMsg" usermessage
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x198710, TextMsgHook, reinterpret_cast<LPVOID*>(&TextMsg_Original));
+
+ Cvar_cl_showtextmsg = RegisterConVar("cl_showtextmsg", "1", FCVAR_NONE, "Enable/disable text messages printing on the screen.");
} \ No newline at end of file