From b80d330ac865aa97177825d09c7b1edc09114d11 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Sun, 4 Sep 2022 22:47:02 +0200 Subject: Get rid of context file This is basically 77a1195d77034c00959dfd030e2eb7a57d58a88d from refactor PR redone on top of main --- NorthstarDLL/NorthstarDLL.vcxproj | 2 -- NorthstarDLL/NorthstarDLL.vcxproj.filters | 6 ------ NorthstarDLL/context.cpp | 14 -------------- NorthstarDLL/context.h | 11 ----------- NorthstarDLL/logging.h | 1 - NorthstarDLL/modmanager.h | 4 +--- NorthstarDLL/sourceinterface.cpp | 4 ---- NorthstarDLL/squirrel.cpp | 26 ++++++++++++++++++++++++++ NorthstarDLL/squirrel.h | 11 +++++++++++ 9 files changed, 38 insertions(+), 41 deletions(-) delete mode 100644 NorthstarDLL/context.cpp delete mode 100644 NorthstarDLL/context.h diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index 19444e8d..70200fa6 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -128,7 +128,6 @@ - @@ -581,7 +580,6 @@ - diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index ebbe4fa4..0a224c80 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -168,9 +168,6 @@ Header Files\Shared - - Header Files\Shared - Header Files\Shared @@ -1550,9 +1547,6 @@ Source Files\Shared - - Source Files\Shared - Source Files\Shared diff --git a/NorthstarDLL/context.cpp b/NorthstarDLL/context.cpp deleted file mode 100644 index 19ee85a3..00000000 --- a/NorthstarDLL/context.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "pch.h" -#include "context.h" - -const char* GetContextName(ScriptContext context) -{ - if (context == ScriptContext::CLIENT) - return "CLIENT"; - else if (context == ScriptContext::SERVER) - return "SERVER"; - else if (context == ScriptContext::UI) - return "UI"; - - return ""; -} diff --git a/NorthstarDLL/context.h b/NorthstarDLL/context.h deleted file mode 100644 index d872f738..00000000 --- a/NorthstarDLL/context.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -enum class ScriptContext : int -{ - SERVER, - CLIENT, - UI, - NONE -}; - -const char* GetContextName(ScriptContext context); diff --git a/NorthstarDLL/logging.h b/NorthstarDLL/logging.h index 59537e01..dc21e6d9 100644 --- a/NorthstarDLL/logging.h +++ b/NorthstarDLL/logging.h @@ -1,5 +1,4 @@ #pragma once -#include "context.h" void CreateLogFiles(); void InitialiseLogging(); diff --git a/NorthstarDLL/modmanager.h b/NorthstarDLL/modmanager.h index 83cc0e40..815946ad 100644 --- a/NorthstarDLL/modmanager.h +++ b/NorthstarDLL/modmanager.h @@ -5,6 +5,7 @@ #include #include "rapidjson/document.h" #include "memalloc.h" +#include "squirrel.h" namespace fs = std::filesystem; @@ -24,9 +25,6 @@ struct ModConVar struct ModScriptCallback { public: - // would've liked to make it possible to hook arbitrary codecallbacks, but couldn't find a function that calls some ui ones - // std::string HookedCodeCallback; - ScriptContext Context; // called before the codecallback is executed diff --git a/NorthstarDLL/sourceinterface.cpp b/NorthstarDLL/sourceinterface.cpp index 56020e5e..4ef241ea 100644 --- a/NorthstarDLL/sourceinterface.cpp +++ b/NorthstarDLL/sourceinterface.cpp @@ -2,11 +2,7 @@ #include "sourceinterface.h" #include "hooks.h" #include "hookutils.h" - #include "sourceconsole.h" -#include "context.h" -#include "convar.h" -#include // really wanted to do a modular callback system here but honestly couldn't be bothered so hardcoding stuff for now: todo later diff --git a/NorthstarDLL/squirrel.cpp b/NorthstarDLL/squirrel.cpp index 2fa957fb..b52d266f 100644 --- a/NorthstarDLL/squirrel.cpp +++ b/NorthstarDLL/squirrel.cpp @@ -107,6 +107,32 @@ SquirrelManager* g_ClientSquirrelManager; SquirrelManager* g_ServerSquirrelManager; SquirrelManager* g_UISquirrelManager; +template SquirrelManager* GetSquirrelManager() +{ + switch (context) + { + case ScriptContext::CLIENT: + return g_ClientSquirrelManager; + case ScriptContext::SERVER: + return g_ServerSquirrelManager; + case ScriptContext::UI: + return g_UISquirrelManager; + } +} + +const char* GetContextName(ScriptContext context) +{ + switch (context) + { + case ScriptContext::CLIENT: + return "CLIENT"; + case ScriptContext::SERVER: + return "SERVER"; + case ScriptContext::UI: + return "UI"; + } +} + SQInteger NSTestFunc(void* sqvm) { return 1; diff --git a/NorthstarDLL/squirrel.h b/NorthstarDLL/squirrel.h index e465ddc6..ab982736 100644 --- a/NorthstarDLL/squirrel.h +++ b/NorthstarDLL/squirrel.h @@ -544,6 +544,16 @@ struct SQArray } \ } +enum class ScriptContext : int +{ + SERVER, + CLIENT, + UI, + NONE +}; + +const char* GetContextName(ScriptContext context); + // core sqvm funcs typedef SQRESULT (*sq_compilebufferType)(void* sqvm, CompileBufferState* compileBuffer, const char* file, int a1, ScriptContext a2); extern sq_compilebufferType ClientSq_compilebuffer; @@ -811,3 +821,4 @@ template class SquirrelManager extern SquirrelManager* g_ClientSquirrelManager; extern SquirrelManager* g_ServerSquirrelManager; extern SquirrelManager* g_UISquirrelManager; +template SquirrelManager* GetSquirrelManager(); -- cgit v1.2.3