aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/engine/hoststate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDLL/engine/hoststate.cpp')
-rw-r--r--NorthstarDLL/engine/hoststate.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/NorthstarDLL/engine/hoststate.cpp b/NorthstarDLL/engine/hoststate.cpp
index d474b908..4900539b 100644
--- a/NorthstarDLL/engine/hoststate.cpp
+++ b/NorthstarDLL/engine/hoststate.cpp
@@ -20,9 +20,35 @@ namespace R2
} // namespace R2
ConVar* Cvar_hostport;
+std::string sLastMode;
+
+void (*_fastcall _Cmd_Exec_f)(const CCommand& arg, bool bOnlyIfExists, bool bUseWhitelists);
void ServerStartingOrChangingMap()
{
+ ConVar* Cvar_mp_gamemode = g_pCVar->FindVar("mp_gamemode");
+
+ // directly call _Cmd_Exec_f to avoid weirdness with ; being in mp_gamemode potentially
+ // if we ran exec {mp_gamemode} and mp_gamemode contained semicolons, this could be used to execute more commands
+ char* commandBuf[1040]; // assumedly this is the size of CCommand since we don't have an actual constructor
+ memset(commandBuf, 0, sizeof(commandBuf));
+ CCommand tempCommand = *(CCommand*)&commandBuf;
+ if (sLastMode.length() &&
+ CCommand__Tokenize(
+ tempCommand, fmt::format("exec server/cleanup_gamemode_{}", sLastMode).c_str(), R2::cmd_source_t::kCommandSrcCode))
+ _Cmd_Exec_f(tempCommand, false, false);
+
+ memset(commandBuf, 0, sizeof(commandBuf));
+ if (CCommand__Tokenize(
+ tempCommand,
+ fmt::format("exec server/setup_gamemode_{}", sLastMode = Cvar_mp_gamemode->GetString()).c_str(),
+ R2::cmd_source_t::kCommandSrcCode))
+ {
+ _Cmd_Exec_f(tempCommand, false, false);
+ }
+
+ Cbuf_Execute(); // exec everything right now
+
// net_data_block_enabled is required for sp, force it if we're on an sp map
// sucks for security but just how it be
if (!strncmp(g_pHostState->m_levelName, "sp_", 3))
@@ -119,6 +145,22 @@ void, __fastcall, (CHostState* self))
g_pServerAuthentication->StopPlayerAuthServer();
CHostState__State_GameShutdown(self);
+
+ // run gamemode cleanup cfg now instead of when we start next map
+ if (sLastMode.length())
+ {
+ char* commandBuf[1040]; // assumedly this is the size of CCommand since we don't have an actual constructor
+ memset(commandBuf, 0, sizeof(commandBuf));
+ CCommand tempCommand = *(CCommand*)&commandBuf;
+ if (CCommand__Tokenize(
+ tempCommand, fmt::format("exec server/cleanup_gamemode_{}", sLastMode).c_str(), R2::cmd_source_t::kCommandSrcCode))
+ {
+ _Cmd_Exec_f(tempCommand, false, false);
+ Cbuf_Execute();
+ }
+
+ sLastMode.clear();
+ }
}
// clang-format off
@@ -154,4 +196,6 @@ ON_DLL_LOAD_RELIESON("engine.dll", HostState, ConVar, (CModule module))
g_pHostState = module.Offset(0x7CF180).As<CHostState*>();
Cvar_hostport = module.Offset(0x13FA6070).As<ConVar*>();
+
+ _Cmd_Exec_f = module.Offset(0x1232C0).As<void (*__fastcall)(const CCommand&, bool, bool)>();
}