aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/squirrel.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-08 15:33:31 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-08 15:33:31 +0100
commit4c4d605d10109e02708984755405bbe0947ef5c4 (patch)
tree1d5ffe7909b24b6c79fd444b420741e85f6c2b57 /NorthstarDedicatedTest/squirrel.cpp
parent8dfb8e866119f653802609b24165b0458149c4cc (diff)
downloadNorthstarLauncher-4c4d605d10109e02708984755405bbe0947ef5c4.tar.gz
NorthstarLauncher-4c4d605d10109e02708984755405bbe0947ef5c4.zip
initial commit
Diffstat (limited to 'NorthstarDedicatedTest/squirrel.cpp')
-rw-r--r--NorthstarDedicatedTest/squirrel.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp
new file mode 100644
index 00000000..66bf755c
--- /dev/null
+++ b/NorthstarDedicatedTest/squirrel.cpp
@@ -0,0 +1,67 @@
+#include "pch.h"
+#include "squirrel.h"
+#include "hooks.h"
+#include "hookutils.h"
+#include "sigscanning.h"
+#include <iostream>
+
+// hook forward declarations
+typedef SQInteger(*SQPrintType)(void* sqvm, char* fmt, ...);
+SQPrintType ClientSQPrint;
+SQPrintType UISQPrint;
+SQPrintType ServerSQPrint;
+template<Context context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...);
+
+
+// inits
+SquirrelManager<CLIENT>* g_ClientSquirrelManager;
+SquirrelManager<SERVER>* g_ServerSquirrelManager;
+
+void InitialiseClientSquirrel(HMODULE baseAddress)
+{
+ g_ClientSquirrelManager = new SquirrelManager<CLIENT>();
+
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12B00, &SQPrintHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientSQPrint));
+
+ // ui inits
+ // currently these are mostly incomplete
+
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12BA0, &SQPrintHook<UI>, reinterpret_cast<LPVOID*>(&UISQPrint));
+}
+
+void InitialiseServerSquirrel(HMODULE baseAddress)
+{
+ g_ServerSquirrelManager = new SquirrelManager<SERVER>();
+
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1FE90, &SQPrintHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerSQPrint));
+}
+
+// hooks
+template<Context context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...)
+{
+ va_list va;
+ va_start(va, fmt);
+
+ SQChar buf[1024];
+ int charsWritten = vsnprintf_s(buf, _TRUNCATE, fmt, va);
+
+ if (charsWritten > 0)
+ {
+ if (buf[charsWritten - 1] == '\n')
+ buf[charsWritten - 1] == '\0';
+
+ Log(context, buf, "");
+ }
+
+ va_end(va);
+ return 0;
+}
+
+
+// manager
+template<Context context> SquirrelManager<context>::SquirrelManager()
+{
+
+} \ No newline at end of file