diff options
Diffstat (limited to 'NorthstarDedicatedTest/squirrel.cpp')
-rw-r--r-- | NorthstarDedicatedTest/squirrel.cpp | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index 66bf755c..e78b26f2 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -12,22 +12,30 @@ SQPrintType UISQPrint; SQPrintType ServerSQPrint; template<Context context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...); +typedef void* (*CreateNewVMType)(void* a1, Context contextArg); +CreateNewVMType ClientCreateNewVM; // only need a client one since ui doesn't have its own func for this +CreateNewVMType ServerCreateNewVM; +void* CreateNewVMHook(void* a1, Context contextArg); // inits SquirrelManager<CLIENT>* g_ClientSquirrelManager; SquirrelManager<SERVER>* g_ServerSquirrelManager; +SquirrelManager<UI>* g_UISquirrelManager; void InitialiseClientSquirrel(HMODULE baseAddress) { - g_ClientSquirrelManager = new SquirrelManager<CLIENT>(); - HookEnabler hook; - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12B00, &SQPrintHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientSQPrint)); + + // client inits + g_ClientSquirrelManager = new SquirrelManager<CLIENT>(); + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12B00, &SQPrintHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientSQPrint)); // client print function // ui inits - // currently these are mostly incomplete + g_UISquirrelManager = new SquirrelManager<UI>(); + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12BA0, &SQPrintHook<UI>, reinterpret_cast<LPVOID*>(&UISQPrint)); // ui print function - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12BA0, &SQPrintHook<UI>, reinterpret_cast<LPVOID*>(&UISQPrint)); + // hooks for both client and ui, since they share some functions + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26130, &CreateNewVMHook, reinterpret_cast<LPVOID*>(&ClientCreateNewVM)); // client createnewvm function } void InitialiseServerSquirrel(HMODULE baseAddress) @@ -35,7 +43,8 @@ void InitialiseServerSquirrel(HMODULE baseAddress) g_ServerSquirrelManager = new SquirrelManager<SERVER>(); HookEnabler hook; - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1FE90, &SQPrintHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerSQPrint)); + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1FE90, &SQPrintHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerSQPrint)); // server print function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x260E0, &CreateNewVMHook, reinterpret_cast<LPVOID*>(&ServerCreateNewVM)); // server createnewvm function } // hooks @@ -52,16 +61,42 @@ template<Context context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...) if (buf[charsWritten - 1] == '\n') buf[charsWritten - 1] == '\0'; - Log(context, buf, ""); + spdlog::info("[{} SCRIPT] {}", GetContextName(context), buf); } va_end(va); return 0; } +void* CreateNewVMHook(void* a1, Context context) +{ + std::cout << "CreateNewVM " << GetContextName(context) << std::endl; + + if (context == CLIENT) + { + void* sqvm = ClientCreateNewVM(a1, context); + g_ClientSquirrelManager->sqvm = sqvm; + + return sqvm; + } + else if (context == UI) + { + void* sqvm = ClientCreateNewVM(a1, context); + g_UISquirrelManager->sqvm = sqvm; + + return sqvm; + } + else if (context == SERVER) + { + void* sqvm = ServerCreateNewVM(a1, context); + g_ServerSquirrelManager->sqvm = sqvm; + + return sqvm; + } +} // manager -template<Context context> SquirrelManager<context>::SquirrelManager() +template<Context context> SquirrelManager<context>::SquirrelManager() : sqvm(nullptr) { }
\ No newline at end of file |