From a0f0b7926603b4112029c674e8a0753375e06d62 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 19 Jul 2023 18:52:00 +0200 Subject: [PATCH] Add callback for registering script constants, and added 'LISTEN_SERVER' All listen server code should be compiled out of the scripts using 'LISTEN_SERVER'. The constant must have a non-null value. --- r5dev/core/init.cpp | 42 ++++++++++++------- r5dev/game/shared/vscript_shared.cpp | 18 +++++--- r5dev/game/shared/vscript_shared.h | 1 + .../languages/squirrel_re/vsquirrel.cpp | 8 ++++ .../vscript/languages/squirrel_re/vsquirrel.h | 2 + 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 9c7448e1..6b33fd9c 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -149,6 +149,31 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// +#ifdef DEDICATED +// These command line parameters disable a bunch of things in the engine that +// the dedicated server does not need, therefore, reducing a lot of overhead. +void InitCommandLineParameters() +{ + CommandLine()->AppendParm("-collate", ""); + CommandLine()->AppendParm("-multiple", ""); + CommandLine()->AppendParm("-noorigin", ""); + CommandLine()->AppendParm("-nodiscord", ""); + CommandLine()->AppendParm("-noshaderapi", ""); + CommandLine()->AppendParm("-nobakedparticles", ""); + CommandLine()->AppendParm("-novid", ""); + CommandLine()->AppendParm("-nomenuvid", ""); + CommandLine()->AppendParm("-nosound", ""); + CommandLine()->AppendParm("-nomouse", ""); + CommandLine()->AppendParm("-nojoy", ""); + CommandLine()->AppendParm("-nosendtable", ""); +} +#endif // DEDICATED + +void ScriptConstantRegistrationCallback(CSquirrelVM* s) +{ + Script_RegisterListenServerConstants(s); +} + void Systems_Init() { DevMsg(eDLL_T::NONE, "+-------------------------------------------------------------+\n"); @@ -197,23 +222,12 @@ void Systems_Init() ConVar_StaticInit(); #ifdef DEDICATED - // These command line parameters disable a bunch of things in the engine that - // the dedicated server does not need, therefore, reducing a lot of overhead. - CommandLine()->AppendParm("-collate", ""); - CommandLine()->AppendParm("-multiple", ""); - CommandLine()->AppendParm("-noorigin", ""); - CommandLine()->AppendParm("-nodiscord", ""); - CommandLine()->AppendParm("-noshaderapi", ""); - CommandLine()->AppendParm("-nobakedparticles", ""); - CommandLine()->AppendParm("-novid", ""); - CommandLine()->AppendParm("-nomenuvid", ""); - CommandLine()->AppendParm("-nosound", ""); - CommandLine()->AppendParm("-nomouse", ""); - CommandLine()->AppendParm("-nojoy", ""); - CommandLine()->AppendParm("-nosendtable", ""); + InitCommandLineParameters(); #endif // DEDICATED // Script context registration callbacks. + ScriptConstantRegister_Callback = ScriptConstantRegistrationCallback; + #ifndef CLIENT_DLL ServerScriptRegister_Callback = Script_RegisterServerFunctions; CoreServerScriptRegister_Callback = Script_RegisterCoreServerFunctions; diff --git a/r5dev/game/shared/vscript_shared.cpp b/r5dev/game/shared/vscript_shared.cpp index d8a1a77e..493169cb 100644 --- a/r5dev/game/shared/vscript_shared.cpp +++ b/r5dev/game/shared/vscript_shared.cpp @@ -13,14 +13,10 @@ #include "core/stdafx.h" #include "vpc/keyvalues.h" -#include "engine/server/server.h" +#include "engine/client/cl_main.h" #include "engine/cmodel_bsp.h" -#include "engine/host_state.h" -#include "networksystem/pylon.h" -#include "networksystem/bansystem.h" -#include "networksystem/listmanager.h" -#include "vscript_shared.h" #include "vscript/languages/squirrel_re/include/sqvm.h" +#include "vscript_shared.h" namespace VScriptCode { @@ -88,3 +84,13 @@ void Script_RegisterCommonAbstractions(CSquirrelVM* s) DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailableMaps, "Gets an array of all available maps", "array< string >", ""); DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailablePlaylists, "Gets an array of all available playlists", "array< string >", ""); } + +//--------------------------------------------------------------------------------- +// Purpose: listen server constants (!!! only call on builds containing a listen server !!!) +// Input : *s - +//--------------------------------------------------------------------------------- +void Script_RegisterListenServerConstants(CSquirrelVM* s) +{ + const SQBool hasListenServer = !IsClientDLL(); + s->RegisterConstant("LISTEN_SERVER", hasListenServer); +} diff --git a/r5dev/game/shared/vscript_shared.h b/r5dev/game/shared/vscript_shared.h index 3a3b8e77..ba0224fe 100644 --- a/r5dev/game/shared/vscript_shared.h +++ b/r5dev/game/shared/vscript_shared.h @@ -23,6 +23,7 @@ namespace VScriptCode } void Script_RegisterCommonAbstractions(CSquirrelVM* s); +void Script_RegisterListenServerConstants(CSquirrelVM* s); #define DEFINE_SHARED_SCRIPTFUNC_NAMED(s, functionName, helpString, \ returnType, parameters) \ diff --git a/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp b/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp index 990141f2..69b7fb70 100644 --- a/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp +++ b/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp @@ -17,6 +17,9 @@ void(*UiScriptRegister_Callback)(CSquirrelVM* s) = nullptr; void(*CoreServerScriptRegister_Callback)(CSquirrelVM* s) = nullptr; void(*AdminPanelScriptRegister_Callback)(CSquirrelVM* s) = nullptr; +// Registering constants in scripts. +void(*ScriptConstantRegister_Callback)(CSquirrelVM* s) = nullptr; + //--------------------------------------------------------------------------------- // Purpose: Initialises a Squirrel VM instance // Output : True on success, false on failure @@ -75,6 +78,11 @@ SQBool CSquirrelVM::DestroySignalEntryListHead(CSquirrelVM* s, HSQUIRRELVM v, SQ { SQBool result = v_CSquirrelVM_DestroySignalEntryListHead(s, v, f); s->RegisterConstant("DEVELOPER", developer->GetInt()); + + // Must have one. + Assert(ScriptConstantRegister_Callback); + ScriptConstantRegister_Callback(s); + return result; } diff --git a/r5dev/vscript/languages/squirrel_re/vsquirrel.h b/r5dev/vscript/languages/squirrel_re/vsquirrel.h index 94fe8d8b..7198b64c 100644 --- a/r5dev/vscript/languages/squirrel_re/vsquirrel.h +++ b/r5dev/vscript/languages/squirrel_re/vsquirrel.h @@ -50,6 +50,8 @@ extern void(*UiScriptRegister_Callback)(CSquirrelVM* s); extern void(*CoreServerScriptRegister_Callback)(CSquirrelVM* s); extern void(*AdminPanelScriptRegister_Callback)(CSquirrelVM* s); +extern void(*ScriptConstantRegister_Callback)(CSquirrelVM* s); + inline CMemory p_CSquirrelVM_Init; inline bool(*v_CSquirrelVM_Init)(CSquirrelVM* s, SQCONTEXT context, SQFloat curtime);