aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/engine
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2023-01-13 14:28:09 +0000
committerGitHub <noreply@github.com>2023-01-13 15:28:09 +0100
commit063260ca0b1f633cf120d79796fe7aa3329c1e26 (patch)
tree1bcc5516729168db6be4981b07115d30a8821da2 /NorthstarDLL/engine
parent8bddf5bfe83b52165c589b2dd5e544831a55231d (diff)
downloadNorthstarLauncher-063260ca0b1f633cf120d79796fe7aa3329c1e26.tar.gz
NorthstarLauncher-063260ca0b1f633cf120d79796fe7aa3329c1e26.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')
-rw-r--r--NorthstarDLL/engine/hoststate.cpp44
-rw-r--r--NorthstarDLL/engine/r2engine.cpp4
-rw-r--r--NorthstarDLL/engine/r2engine.h2
3 files changed, 50 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)>();
}
diff --git a/NorthstarDLL/engine/r2engine.cpp b/NorthstarDLL/engine/r2engine.cpp
index 11233a2d..22884a73 100644
--- a/NorthstarDLL/engine/r2engine.cpp
+++ b/NorthstarDLL/engine/r2engine.cpp
@@ -10,6 +10,8 @@ namespace R2
Cbuf_AddTextType Cbuf_AddText;
Cbuf_ExecuteType Cbuf_Execute;
+ bool (*CCommand__Tokenize)(CCommand& self, const char* pCommandString, R2::cmd_source_t commandSource);
+
CEngine* g_pEngine;
void (*CBaseClient__Disconnect)(void* self, uint32_t unknownButAlways1, const char* reason, ...);
@@ -27,6 +29,8 @@ ON_DLL_LOAD("engine.dll", R2Engine, (CModule module))
Cbuf_AddText = module.Offset(0x1203B0).As<Cbuf_AddTextType>();
Cbuf_Execute = module.Offset(0x1204B0).As<Cbuf_ExecuteType>();
+ CCommand__Tokenize = module.Offset(0x418380).As<bool (*)(CCommand&, const char*, R2::cmd_source_t)>();
+
g_pEngine = module.Offset(0x7D70C8).Deref().As<CEngine*>();
CBaseClient__Disconnect = module.Offset(0x1012C0).As<void (*)(void*, uint32_t, const char*, ...)>();
diff --git a/NorthstarDLL/engine/r2engine.h b/NorthstarDLL/engine/r2engine.h
index a7ed62a3..bc242201 100644
--- a/NorthstarDLL/engine/r2engine.h
+++ b/NorthstarDLL/engine/r2engine.h
@@ -59,6 +59,8 @@ namespace R2
typedef void (*Cbuf_ExecuteType)();
extern Cbuf_ExecuteType Cbuf_Execute;
+ extern bool (*CCommand__Tokenize)(CCommand& self, const char* pCommandString, R2::cmd_source_t commandSource);
+
// CEngine
enum EngineQuitState