diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2023-01-13 14:28:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 15:28:09 +0100 |
commit | 063260ca0b1f633cf120d79796fe7aa3329c1e26 (patch) | |
tree | 1bcc5516729168db6be4981b07115d30a8821da2 /NorthstarDLL/engine/hoststate.cpp | |
parent | 8bddf5bfe83b52165c589b2dd5e544831a55231d (diff) | |
download | NorthstarLauncher-1.12.0-rc5.tar.gz NorthstarLauncher-1.12.0-rc5.zip |
Execute cfgs before server startup for gamemode being run (#398)v1.12.0-rc5v1.12.0-rc4v1.12.0
* run cfg to initialise gamemode on startup
* remove ; characters from mp_gamemode
* exec using _Cmd_Exec_f to avoid issues with semicolons in gamemode names
allowing additional commands to be run
* run from cfg/server/ rather than cfg/
* fixup formatting
Diffstat (limited to 'NorthstarDLL/engine/hoststate.cpp')
-rw-r--r-- | NorthstarDLL/engine/hoststate.cpp | 44 |
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)>(); } |