diff options
Diffstat (limited to 'NorthstarDedicatedTest/squirrel.cpp')
-rw-r--r-- | NorthstarDedicatedTest/squirrel.cpp | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index 48136f97..2b0ba172 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -13,27 +13,27 @@ typedef SQInteger(*SQPrintType)(void* sqvm, char* fmt, ...); SQPrintType ClientSQPrint; SQPrintType UISQPrint; SQPrintType ServerSQPrint; -template<Context context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...); +template<ScriptContex context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...); -typedef void*(*CreateNewVMType)(void* a1, Context contextArg); +typedef void*(*CreateNewVMType)(void* a1, ScriptContex contextArg); CreateNewVMType ClientCreateNewVM; // only need a client one since ui doesn't have its own func for this CreateNewVMType ServerCreateNewVM; -template<Context context> void* CreateNewVMHook(void* a1, Context contextArg); +template<ScriptContex context> void* CreateNewVMHook(void* a1, ScriptContex contextArg); typedef void(*DestroyVMType)(void* a1, void* sqvm); DestroyVMType ClientDestroyVM; // only need a client one since ui doesn't have its own func for this DestroyVMType ServerDestroyVM; -template<Context context> void DestroyVMHook(void* a1, void* sqvm); +template<ScriptContex context> void DestroyVMHook(void* a1, void* sqvm); typedef void(*ScriptCompileError)(void* sqvm, const char* error, const char* file, int line, int column); ScriptCompileError ClientSQCompileError; // only need a client one since ui doesn't have its own func for this ScriptCompileError ServerSQCompileError; -template<Context context> void ScriptCompileErrorHook(void* sqvm, const char* error, const char* file, int line, int column); +template<ScriptContex context> void ScriptCompileErrorHook(void* sqvm, const char* error, const char* file, int line, int column); typedef char(*CallScriptInitCallbackType)(void* sqvm, const char* callback); CallScriptInitCallbackType ClientCallScriptInitCallback; CallScriptInitCallbackType ServerCallScriptInitCallback; -template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char* callback); +template<ScriptContex context> char CallScriptInitCallbackHook(void* sqvm, const char* callback); // core sqvm funcs sq_compilebufferType ClientSq_compilebuffer; @@ -88,12 +88,12 @@ sq_getboolType ClientSq_getbool; sq_getboolType ServerSq_getbool; -template<Context context> void ExecuteCodeCommand(const CCommand& args); +template<ScriptContex context> void ExecuteCodeCommand(const CCommand& args); // inits -SquirrelManager<CLIENT>* g_ClientSquirrelManager; -SquirrelManager<SERVER>* g_ServerSquirrelManager; -SquirrelManager<UI>* g_UISquirrelManager; +SquirrelManager<ScriptContex::CLIENT>* g_ClientSquirrelManager; +SquirrelManager<ScriptContex::SERVER>* g_ServerSquirrelManager; +SquirrelManager<ScriptContex::UI>* g_UISquirrelManager; SQInteger NSTestFunc(void* sqvm) { @@ -108,16 +108,16 @@ void InitialiseClientSquirrel(HMODULE baseAddress) HookEnabler hook; // client inits - g_ClientSquirrelManager = new SquirrelManager<CLIENT>(); + g_ClientSquirrelManager = new SquirrelManager<ScriptContex::CLIENT>(); - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12B00, &SQPrintHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientSQPrint)); // client print function - RegisterConCommand("script_client", ExecuteCodeCommand<CLIENT>, "Executes script code on the client vm", FCVAR_CLIENTDLL); + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12B00, &SQPrintHook<ScriptContex::CLIENT>, reinterpret_cast<LPVOID*>(&ClientSQPrint)); // client print function + RegisterConCommand("script_client", ExecuteCodeCommand<ScriptContex::CLIENT>, "Executes script code on the client vm", FCVAR_CLIENTDLL); // ui inits - g_UISquirrelManager = new SquirrelManager<UI>(); + g_UISquirrelManager = new SquirrelManager<ScriptContex::UI>(); - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12BA0, &SQPrintHook<UI>, reinterpret_cast<LPVOID*>(&UISQPrint)); // ui print function - RegisterConCommand("script_ui", ExecuteCodeCommand<UI>, "Executes script code on the ui vm", FCVAR_CLIENTDLL); + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12BA0, &SQPrintHook<ScriptContex::UI>, reinterpret_cast<LPVOID*>(&UISQPrint)); // ui print function + RegisterConCommand("script_ui", ExecuteCodeCommand<ScriptContex::UI>, "Executes script code on the ui vm", FCVAR_CLIENTDLL); // inits for both client and ui, since they share some functions ClientSq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); @@ -139,15 +139,15 @@ void InitialiseClientSquirrel(HMODULE baseAddress) ClientSq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x6100); ClientSq_getbool = (sq_getboolType)((char*)baseAddress + 0x6130); - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26130, &CreateNewVMHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientCreateNewVM)); // client createnewvm function - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26E70, &DestroyVMHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientDestroyVM)); // client destroyvm function - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x79A50, &ScriptCompileErrorHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientSQCompileError)); // client compileerror function - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x10190, &CallScriptInitCallbackHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientCallScriptInitCallback)); // client callscriptinitcallback function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26130, &CreateNewVMHook<ScriptContex::CLIENT>, reinterpret_cast<LPVOID*>(&ClientCreateNewVM)); // client createnewvm function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26E70, &DestroyVMHook<ScriptContex::CLIENT>, reinterpret_cast<LPVOID*>(&ClientDestroyVM)); // client destroyvm function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x79A50, &ScriptCompileErrorHook<ScriptContex::CLIENT>, reinterpret_cast<LPVOID*>(&ClientSQCompileError)); // client compileerror function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x10190, &CallScriptInitCallbackHook<ScriptContex::CLIENT>, reinterpret_cast<LPVOID*>(&ClientCallScriptInitCallback)); // client callscriptinitcallback function } void InitialiseServerSquirrel(HMODULE baseAddress) { - g_ServerSquirrelManager = new SquirrelManager<SERVER>(); + g_ServerSquirrelManager = new SquirrelManager<ScriptContex::SERVER>(); HookEnabler hook; @@ -170,19 +170,19 @@ void InitialiseServerSquirrel(HMODULE baseAddress) ServerSq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x60E0); ServerSq_getbool = (sq_getboolType)((char*)baseAddress + 0x6110); - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1FE90, &SQPrintHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerSQPrint)); // server print function - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x260E0, &CreateNewVMHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerCreateNewVM)); // server createnewvm function - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26E20, &DestroyVMHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerDestroyVM)); // server destroyvm function - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x799E0, &ScriptCompileErrorHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerSQCompileError)); // server compileerror function - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1D5C0, &CallScriptInitCallbackHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerCallScriptInitCallback)); // server callscriptinitcallback function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1FE90, &SQPrintHook<ScriptContex::SERVER>, reinterpret_cast<LPVOID*>(&ServerSQPrint)); // server print function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x260E0, &CreateNewVMHook<ScriptContex::SERVER>, reinterpret_cast<LPVOID*>(&ServerCreateNewVM)); // server createnewvm function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26E20, &DestroyVMHook<ScriptContex::SERVER>, reinterpret_cast<LPVOID*>(&ServerDestroyVM)); // server destroyvm function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x799E0, &ScriptCompileErrorHook<ScriptContex::SERVER>, reinterpret_cast<LPVOID*>(&ServerSQCompileError)); // server compileerror function + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1D5C0, &CallScriptInitCallbackHook<ScriptContex::SERVER>, reinterpret_cast<LPVOID*>(&ServerCallScriptInitCallback)); // server callscriptinitcallback function // cheat and clientcmd_can_execute allows clients to execute this, but since it's unsafe we only allow it when cheats are enabled // for script_client and script_ui, we don't use cheats, so clients can execute them on themselves all they want - RegisterConCommand("script", ExecuteCodeCommand<SERVER>, "Executes script code on the server vm", FCVAR_GAMEDLL | FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_CHEAT); + RegisterConCommand("script", ExecuteCodeCommand<ScriptContex::SERVER>, "Executes script code on the server vm", FCVAR_GAMEDLL | FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_CHEAT); } // hooks -template<Context context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...) +template<ScriptContex context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...) { va_list va; va_start(va, fmt); @@ -202,20 +202,20 @@ template<Context context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...) return 0; } -template<Context context> void* CreateNewVMHook(void* a1, Context realContext) +template<ScriptContex context> void* CreateNewVMHook(void* a1, ScriptContex realContext) { void* sqvm; - if (context == CLIENT) + if (context == ScriptContex::CLIENT) { sqvm = ClientCreateNewVM(a1, realContext); - if (realContext == UI) + if (realContext == ScriptContex::UI) g_UISquirrelManager->VMCreated(sqvm); else g_ClientSquirrelManager->VMCreated(sqvm); } - else if (context == SERVER) + else if (context == ScriptContex::SERVER) { sqvm = ServerCreateNewVM(a1, context); g_ServerSquirrelManager->VMCreated(sqvm); @@ -225,23 +225,23 @@ template<Context context> void* CreateNewVMHook(void* a1, Context realContext) return sqvm; } -template<Context context> void DestroyVMHook(void* a1, void* sqvm) +template<ScriptContex context> void DestroyVMHook(void* a1, void* sqvm) { - Context realContext = context; // ui and client use the same function so we use this for prints + ScriptContex realContext = context; // ui and client use the same function so we use this for prints - if (context == CLIENT) + if (context == ScriptContex::CLIENT) { if (g_ClientSquirrelManager->sqvm == sqvm) g_ClientSquirrelManager->VMDestroyed(); else if (g_UISquirrelManager->sqvm == sqvm) { g_UISquirrelManager->VMDestroyed(); - realContext = UI; + realContext = ScriptContex::UI; } ClientDestroyVM(a1, sqvm); } - else if (context == SERVER) + else if (context == ScriptContex::SERVER) { g_ServerSquirrelManager->VMDestroyed(); ServerDestroyVM(a1, sqvm); @@ -250,11 +250,11 @@ template<Context context> void DestroyVMHook(void* a1, void* sqvm) spdlog::info("DestroyVM {} {}", GetContextName(realContext), sqvm); } -template<Context context> void ScriptCompileErrorHook(void* sqvm, const char* error, const char* file, int line, int column) +template<ScriptContex context> void ScriptCompileErrorHook(void* sqvm, const char* error, const char* file, int line, int column) { - Context realContext = context; // ui and client use the same function so we use this for prints - if (context == CLIENT && sqvm == g_UISquirrelManager->sqvm) - realContext = UI; + ScriptContex realContext = context; // ui and client use the same function so we use this for prints + if (context == ScriptContex::CLIENT && sqvm == g_UISquirrelManager->sqvm) + realContext = ScriptContex::UI; spdlog::error("{} SCRIPT COMPILE ERROR {}", GetContextName(realContext), error); spdlog::error("{} line [{}] column [{}]", file, line, column); @@ -265,19 +265,19 @@ template<Context context> void ScriptCompileErrorHook(void* sqvm, const char* er // though, that also has potential to be REALLY bad if we're compiling ui scripts lol } -template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char* callback) +template<ScriptContex context> char CallScriptInitCallbackHook(void* sqvm, const char* callback) { char ret; - if (context == CLIENT) + if (context == ScriptContex::CLIENT) { - Context realContext = context; // ui and client use the same function so we use this for prints + ScriptContex realContext = context; // ui and client use the same function so we use this for prints bool shouldCallCustomCallbacks = false; // since we don't hook arbitrary callbacks yet, make sure we're only doing callbacks on inits if (!strcmp(callback, "UICodeCallback_UIInit")) { - realContext = UI; + realContext = ScriptContex::UI; shouldCallCustomCallbacks = true; } else if (!strcmp(callback, "ClientCodeCallback_MapSpawn")) @@ -333,7 +333,7 @@ template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char } } } - else if (context == SERVER) + else if (context == ScriptContex::SERVER) { // since we don't hook arbitrary callbacks yet, make sure we're only doing callbacks on inits bool shouldCallCustomCallbacks = !strcmp(callback, "CodeCallback_MapSpawn"); @@ -351,7 +351,7 @@ template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char { for (ModScriptCallback modCallback : script.Callbacks) { - if (modCallback.Context == SERVER && modCallback.BeforeCallback.length()) + if (modCallback.Context == ScriptContex::SERVER && modCallback.BeforeCallback.length()) { spdlog::info("Running custom {} script callback \"{}\"", GetContextName(context), modCallback.BeforeCallback); ServerCallScriptInitCallback(sqvm, modCallback.BeforeCallback.c_str()); @@ -378,7 +378,7 @@ template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char { for (ModScriptCallback modCallback : script.Callbacks) { - if (modCallback.Context == SERVER && modCallback.AfterCallback.length()) + if (modCallback.Context == ScriptContex::SERVER && modCallback.AfterCallback.length()) { spdlog::info("Running custom {} script callback \"{}\"", GetContextName(context), modCallback.AfterCallback); ServerCallScriptInitCallback(sqvm, modCallback.AfterCallback.c_str()); @@ -392,12 +392,12 @@ template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char return ret; } -template<Context context> void ExecuteCodeCommand(const CCommand& args) +template<ScriptContex context> void ExecuteCodeCommand(const CCommand& args) { - if (context == CLIENT) + if (context == ScriptContex::CLIENT) g_ClientSquirrelManager->ExecuteCode(args.ArgS()); - else if (context == UI) + else if (context == ScriptContex::UI) g_UISquirrelManager->ExecuteCode(args.ArgS()); - else if (context == SERVER) + else if (context == ScriptContex::SERVER) g_ServerSquirrelManager->ExecuteCode(args.ArgS()); }
\ No newline at end of file |