aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/host.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-05-11 14:11:37 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-05-11 14:11:37 +0100
commit862a115b08017e02b45a786e59feb436d1de278f (patch)
treed45b4920da15a12f1395b4c05cf4babec84e632e /NorthstarDedicatedTest/host.cpp
parent2dba51a6a281573ea40cc52c80d10155387d4720 (diff)
downloadNorthstarLauncher-862a115b08017e02b45a786e59feb436d1de278f.tar.gz
NorthstarLauncher-862a115b08017e02b45a786e59feb436d1de278f.zip
move hoststate to its own file and add host_init hooks
Diffstat (limited to 'NorthstarDedicatedTest/host.cpp')
-rw-r--r--NorthstarDedicatedTest/host.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/host.cpp b/NorthstarDedicatedTest/host.cpp
new file mode 100644
index 00000000..9217c128
--- /dev/null
+++ b/NorthstarDedicatedTest/host.cpp
@@ -0,0 +1,55 @@
+#include "pch.h"
+#include "host.h"
+#include "convar.h"
+#include "modmanager.h"
+#include "gameutils.h"
+
+typedef void (*Host_InitType)(bool bDedicated);
+Host_InitType Host_Init;
+void Host_InitHook(bool bDedicated)
+{
+ Host_Init(bDedicated);
+
+ // get all mod convars
+ std::vector<std::string> vModConvarNames;
+ for (auto& mod : g_ModManager->m_loadedMods)
+ for (auto& cvar : mod.ConVars)
+ vModConvarNames.push_back(cvar->Name);
+
+ // strip hidden and devonly cvar flags
+ int iCvarsAltered = 0;
+ for (auto& pair : g_pCVar->DumpToMap())
+ {
+ // don't remove from mod cvars
+ if (std::find(vModConvarNames.begin(), vModConvarNames.end(), pair.second->m_pszName) != vModConvarNames.end())
+ continue;
+
+ // strip flags
+ int flags = pair.second->GetFlags();
+ if (flags & FCVAR_DEVELOPMENTONLY)
+ {
+ flags &= ~FCVAR_DEVELOPMENTONLY;
+ iCvarsAltered++;
+ }
+
+ if (flags & FCVAR_HIDDEN)
+ {
+ flags &= ~FCVAR_HIDDEN;
+ iCvarsAltered++;
+ }
+
+ pair.second->m_nFlags = flags;
+ }
+
+ spdlog::info("Removed {} hidden/devonly cvar flags", iCvarsAltered);
+
+ // run client autoexec if on client
+ if (!bDedicated)
+ Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_client", cmd_source_t::kCommandSrcCode);
+}
+
+ON_DLL_LOAD("engine.dll", Host_Init, [](HMODULE baseAddress)
+{
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x155EA0, &Host_InitHook, reinterpret_cast<LPVOID*>(&Host_Init));
+}) \ No newline at end of file