From e33b566f88339de72d59a6dedc05d9680b4e1361 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 18 Jul 2023 00:17:49 +0200 Subject: [PATCH] Split server and client into separate libs Work in progress; does not compile! Moved script registration function to static gamedll libs instead, and used a pointer callback approach for calling them to avoid duplicate symbols during linkage. --- r5dev/core/CMakeLists.txt | 31 ++++- r5dev/game/CMakeLists.txt | 54 +++++++-- r5dev/game/shared/r1/weapon_bolt.h | 2 + r5dev/game/shared/shared_classnames.h | 6 +- r5dev/game/shared/vscript_shared.cpp | 114 ++++++++++++++++-- r5dev/game/shared/vscript_shared.h | 30 +++-- .../languages/squirrel_re/vsquirrel.cpp | 17 ++- .../vscript/languages/squirrel_re/vsquirrel.h | 4 + r5dev/vscript/vscript.cpp | 92 -------------- r5dev/vscript/vscript.h | 4 - 10 files changed, 215 insertions(+), 139 deletions(-) diff --git a/r5dev/core/CMakeLists.txt b/r5dev/core/CMakeLists.txt index 21871024..06d0847f 100644 --- a/r5dev/core/CMakeLists.txt +++ b/r5dev/core/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required( VERSION 3.16 ) + macro( add_sdk_project PROJECT_NAME ) add_module( "shared_lib" ${PROJECT_NAME} "vpc" ${FOLDER_CONTEXT} TRUE TRUE ) @@ -79,7 +80,6 @@ target_link_libraries( ${PROJECT_NAME} PRIVATE "localize" "vscript" - "game" ) if( NOT ${PROJECT_NAME} STREQUAL "dedicated" ) @@ -99,29 +99,48 @@ target_link_libraries( ${PROJECT_NAME} PRIVATE "engine" "d3d11.lib" ) + else() target_link_libraries( ${PROJECT_NAME} PRIVATE - "engine_ds" "materialsystem_nodx" # Needs the No-DirectX version for patching. + "engine_ds" ) endif() +# Determine the compiler definitions and link libraries per project. if( ${PROJECT_NAME} STREQUAL "gamesdk" ) end_sources() + +target_link_libraries( ${PROJECT_NAME} PRIVATE + "server_static" + "client_static" +) target_compile_definitions( ${PROJECT_NAME} PRIVATE "GAMESDK" ) + elseif( ${PROJECT_NAME} STREQUAL "dedicated" ) end_sources() -target_compile_definitions( ${PROJECT_NAME} PRIVATE - "DEDICATED" - "MATERIALSYSTEM_NODX" # Needs the No-DirectX version for patching. + +target_link_libraries( ${PROJECT_NAME} PRIVATE + "server_static" ) +target_compile_definitions( ${PROJECT_NAME} PRIVATE + "MATERIALSYSTEM_NODX" + "SERVER_DLL" + "DEDICATED" +) + elseif( ${PROJECT_NAME} STREQUAL "client" ) end_sources( "${BUILD_OUTPUT_DIR}/bin/x64_retail/" ) + +target_link_libraries( ${PROJECT_NAME} PRIVATE + "client_static" +) target_compile_definitions( ${PROJECT_NAME} PRIVATE "CLIENT_DLL" ) + endif() target_link_options( ${PROJECT_NAME} PRIVATE @@ -161,4 +180,4 @@ endmacro() add_sdk_project( "gamesdk" ) add_sdk_project( "dedicated" ) -#add_sdk_project( "client" ) +add_sdk_project( "client" ) diff --git a/r5dev/game/CMakeLists.txt b/r5dev/game/CMakeLists.txt index c620400e..8722dde6 100644 --- a/r5dev/game/CMakeLists.txt +++ b/r5dev/game/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required( VERSION 3.16 ) -add_module( "lib" "game" "vpc" ${FOLDER_CONTEXT} TRUE TRUE ) + +macro( add_game_project PROJECT_NAME ) +add_module( "lib" ${PROJECT_NAME} "vpc" ${FOLDER_CONTEXT} TRUE TRUE ) start_sources() @@ -33,6 +35,7 @@ add_sources( SOURCE_GROUP "Shared/Weapon" "shared/r1/weapon_bolt.h" ) +if( NOT ${PROJECT_NAME} STREQUAL "client_static" ) add_sources( SOURCE_GROUP "Server" "server/ai_network.cpp" "server/ai_network.h" @@ -63,6 +66,15 @@ add_sources( SOURCE_GROUP "Server" "server/playerlocaldata.h" ) +add_sources( SOURCE_GROUP "Public" + "${ENGINE_SOURCE_DIR}/public/iserverentity.h" + "${ENGINE_SOURCE_DIR}/public/iservernetworkable.h" + "${ENGINE_SOURCE_DIR}/public/iserverunknown.h" +) + +endif() + +if( NOT ${PROJECT_NAME} STREQUAL "server_static" ) add_sources( SOURCE_GROUP "Client" "client/c_baseentity.cpp" "client/c_baseentity.h" @@ -80,16 +92,6 @@ add_sources( SOURCE_GROUP "Client" ) add_sources( SOURCE_GROUP "Public" - "${ENGINE_SOURCE_DIR}/public/basehandle.h" - "${ENGINE_SOURCE_DIR}/public/edict.h" - "${ENGINE_SOURCE_DIR}/public/eiface.h" - "${ENGINE_SOURCE_DIR}/public/globalvars_base.h" - "${ENGINE_SOURCE_DIR}/public/ihandleentity.h" - - "${ENGINE_SOURCE_DIR}/public/iserverentity.h" - "${ENGINE_SOURCE_DIR}/public/iservernetworkable.h" - "${ENGINE_SOURCE_DIR}/public/iserverunknown.h" - "${ENGINE_SOURCE_DIR}/public/icliententity.h" "${ENGINE_SOURCE_DIR}/public/icliententitylist.h" "${ENGINE_SOURCE_DIR}/public/iclientnetworkable.h" @@ -97,14 +99,40 @@ add_sources( SOURCE_GROUP "Public" "${ENGINE_SOURCE_DIR}/public/iclientthinkable.h" "${ENGINE_SOURCE_DIR}/public/iclientunknown.h" - "${ENGINE_SOURCE_DIR}/public/game/shared/weapon_types.h" - "${ENGINE_SOURCE_DIR}/public/game/shared/in_buttons.h" "${ENGINE_SOURCE_DIR}/public/game/client/iinput.h" ) +endif() + +add_sources( SOURCE_GROUP "Public" + "${ENGINE_SOURCE_DIR}/public/basehandle.h" + "${ENGINE_SOURCE_DIR}/public/edict.h" + "${ENGINE_SOURCE_DIR}/public/eiface.h" + "${ENGINE_SOURCE_DIR}/public/globalvars_base.h" + "${ENGINE_SOURCE_DIR}/public/ihandleentity.h" + + "${ENGINE_SOURCE_DIR}/public/game/shared/weapon_types.h" + "${ENGINE_SOURCE_DIR}/public/game/shared/in_buttons.h" +) + end_sources() +if( ${PROJECT_NAME} STREQUAL "server_static" ) +target_compile_definitions( ${PROJECT_NAME} PRIVATE + "SERVER_DLL" +) +elseif( ${PROJECT_NAME} STREQUAL "client_static" ) +target_compile_definitions( ${PROJECT_NAME} PRIVATE + "CLIENT_DLL" +) +endif() + target_include_directories( ${PROJECT_NAME} PRIVATE "${ENGINE_SOURCE_DIR}/tier0/" "${ENGINE_SOURCE_DIR}/tier1/" ) + +endmacro() + +add_game_project( "server_static" ) +add_game_project( "client_static" ) diff --git a/r5dev/game/shared/r1/weapon_bolt.h b/r5dev/game/shared/r1/weapon_bolt.h index 080aa3c1..777d2c5d 100644 --- a/r5dev/game/shared/r1/weapon_bolt.h +++ b/r5dev/game/shared/r1/weapon_bolt.h @@ -1,5 +1,7 @@ #ifndef GAME_WEAPON_BOLT_H #define GAME_WEAPON_BOLT_H + +#include #ifndef CLIENT_DLL #include #include diff --git a/r5dev/game/shared/shared_classnames.h b/r5dev/game/shared/shared_classnames.h index 264ece3f..f584e1af 100644 --- a/r5dev/game/shared/shared_classnames.h +++ b/r5dev/game/shared/shared_classnames.h @@ -13,12 +13,12 @@ // Hacky macros to allow shared code to work without even worse macro-izing #if defined( CLIENT_DLL ) -/* // TODO: Uncomment if required for client. + // Uncomment if required for client. #define CBaseEntity C_BaseEntity #define CBaseCombatCharacter C_BaseCombatCharacter #define CBaseAnimating C_BaseAnimating -#define CBasePlayer C_BasePlayer -*/ +#define CPlayer C_Player + #endif diff --git a/r5dev/game/shared/vscript_shared.cpp b/r5dev/game/shared/vscript_shared.cpp index 4afdd7a2..4ae72687 100644 --- a/r5dev/game/shared/vscript_shared.cpp +++ b/r5dev/game/shared/vscript_shared.cpp @@ -6,7 +6,7 @@ // // Create functions here under the target VM namespace. If the function has to // be registered for 2 or more VM's, put them under the 'SHARED' namespace. -// Ifdef them out for 'DEDICATED' / 'CLIENT_DLL' if the target VM's do not +// Ifdef them out for 'SERVER_DLL' / 'CLIENT_DLL' if the target VM's do not // include 'SERVER' / 'CLIENT'. // //=============================================================================// @@ -22,9 +22,9 @@ #ifndef CLIENT_DLL #include "networksystem/bansystem.h" #endif // !CLIENT_DLL -#ifndef DEDICATED +#ifndef SERVER_DLL #include "networksystem/listmanager.h" -#endif // !DEDICATED +#endif // !SERVER_DLL #include "vscript_shared.h" #include "vscript/languages/squirrel_re/include/sqvm.h" @@ -193,7 +193,7 @@ namespace VScriptCode return SQ_OK; } -#ifndef DEDICATED + //----------------------------------------------------------------------------- // Purpose: checks whether this SDK build is a client dll //----------------------------------------------------------------------------- @@ -207,7 +207,6 @@ namespace VScriptCode sq_pushbool(v, bClientOnly); return SQ_OK; } -#endif // !DEDICATED } #ifndef CLIENT_DLL namespace SERVER @@ -240,7 +239,7 @@ namespace VScriptCode } } #endif // !CLIENT_DLL -#ifndef DEDICATED +#ifndef SERVER_DLL namespace CLIENT { } @@ -622,5 +621,104 @@ namespace VScriptCode return SQ_OK; } } -#endif // !DEDICATED -} \ No newline at end of file +#endif // !SERVER_DLL +} + +#ifndef CLIENT_DLL +//--------------------------------------------------------------------------------- +// Purpose: registers script functions in SERVER context +// Input : *s - +//--------------------------------------------------------------------------------- +void Script_RegisterServerFunctions(CSquirrelVM* s) +{ + s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native SERVER test function", "void", "", &VScriptCode::SHARED::SDKNativeTest); + s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion); + + s->RegisterFunction("GetNumHumanPlayers", "Script_GetNumHumanPlayers", "Gets the number of human players on the server", "int", "", &VScriptCode::SERVER::GetNumHumanPlayers); + s->RegisterFunction("GetNumFakeClients", "Script_GetNumFakeClients", "Gets the number of bot players on the server", "int", "", &VScriptCode::SERVER::GetNumFakeClients); + + s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps); + s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists); + + s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string, string", &VScriptCode::SHARED::KickPlayerByName); + s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string, string", &VScriptCode::SHARED::KickPlayerById); + + s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::SHARED::BanPlayerByName); + s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string, string", &VScriptCode::SHARED::BanPlayerById); + + s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string, string", &VScriptCode::SHARED::UnbanPlayer); + + s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame); + + s->RegisterFunction("IsDedicated", "Script_IsDedicated", "Returns whether this is a dedicated server", "bool", "", &VScriptCode::SERVER::IsDedicated); +} +#endif // !CLIENT_DLL + +#ifndef SERVER_DLL +//--------------------------------------------------------------------------------- +// Purpose: registers script functions in CLIENT context +// Input : *s - +//--------------------------------------------------------------------------------- +void Script_RegisterClientFunctions(CSquirrelVM* s) +{ + s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native CLIENT test function", "void", "", &VScriptCode::SHARED::SDKNativeTest); + s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion); + + s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps); + s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists); + + s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame); + s->RegisterFunction("IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VScriptCode::SHARED::IsClientDLL); +} + +//--------------------------------------------------------------------------------- +// Purpose: registers script functions in UI context +// Input : *s - +//--------------------------------------------------------------------------------- +void Script_RegisterUIFunctions(CSquirrelVM* s) +{ + s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native UI test function", "void", "", &VScriptCode::SHARED::SDKNativeTest); + s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion); + + s->RegisterFunction("RefreshServerList", "Script_RefreshServerList", "Refreshes the public server list and returns the count", "int", "", &VScriptCode::UI::RefreshServerCount); + + // Functions for retrieving server browser data + s->RegisterFunction("GetServerName", "Script_GetServerName", "Gets the name of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerName); + s->RegisterFunction("GetServerDescription", "Script_GetServerDescription", "Gets the description of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerDescription); + s->RegisterFunction("GetServerMap", "Script_GetServerMap", "Gets the map of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerMap); + s->RegisterFunction("GetServerPlaylist", "Script_GetServerPlaylist", "Gets the playlist of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerPlaylist); + s->RegisterFunction("GetServerCurrentPlayers", "Script_GetServerCurrentPlayers", "Gets the current player count of the server at the specified index of the server list", "int", "int", &VScriptCode::UI::GetServerCurrentPlayers); + s->RegisterFunction("GetServerMaxPlayers", "Script_GetServerMaxPlayers", "Gets the max player count of the server at the specified index of the server list", "int", "int", &VScriptCode::UI::GetServerMaxPlayers); + s->RegisterFunction("GetServerCount", "Script_GetServerCount", "Gets the number of public servers", "int", "", &VScriptCode::UI::GetServerCount); + + // Misc main menu functions + s->RegisterFunction("GetPromoData", "Script_GetPromoData", "Gets promo data for specified slot type", "string", "int", &VScriptCode::UI::GetPromoData); + + // Functions for creating servers + s->RegisterFunction("CreateServer", "Script_CreateServer", "Starts server with the specified settings", "void", "string, string, string, string, int", &VScriptCode::UI::CreateServer); + s->RegisterFunction("IsServerActive", "Script_IsServerActive", "Returns whether the server is active", "bool", "", &VScriptCode::SHARED::IsServerActive); + + // Functions for connecting to servers + s->RegisterFunction("ConnectToServer", "Script_ConnectToServer", "Joins server by ip address and encryption key", "void", "string, string", &VScriptCode::UI::ConnectToServer); + s->RegisterFunction("ConnectToListedServer", "Script_ConnectToListedServer", "Joins listed server by index", "void", "int", &VScriptCode::UI::ConnectToListedServer); + s->RegisterFunction("ConnectToHiddenServer", "Script_ConnectToHiddenServer", "Joins hidden server by token", "void", "string", &VScriptCode::UI::ConnectToHiddenServer); + + s->RegisterFunction("GetHiddenServerName", "Script_GetHiddenServerName", "Gets hidden server name by token", "string", "string", &VScriptCode::UI::GetHiddenServerName); + s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps); + s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists); + +#ifndef CLIENT_DLL // UI 'admin' functions controlling server code + s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string", &VScriptCode::SHARED::KickPlayerByName); + s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string", &VScriptCode::SHARED::KickPlayerById); + + s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::SHARED::BanPlayerByName); + s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string", &VScriptCode::SHARED::BanPlayerById); + + s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string", &VScriptCode::SHARED::UnbanPlayer); + + s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame); +#endif // !CLIENT_DLL + + s->RegisterFunction("IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VScriptCode::SHARED::IsClientDLL); +} +#endif diff --git a/r5dev/game/shared/vscript_shared.h b/r5dev/game/shared/vscript_shared.h index 1f90db3d..c9bc30f8 100644 --- a/r5dev/game/shared/vscript_shared.h +++ b/r5dev/game/shared/vscript_shared.h @@ -1,6 +1,7 @@ #ifndef VSCRIPT_SHARED_H #define VSCRIPT_SHARED_H #include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/vsquirrel.h" inline CMemory p_Script_Remote_BeginRegisteringFunctions; inline void*(*Script_Remote_BeginRegisteringFunctions)(void); @@ -11,9 +12,9 @@ inline void*(*RestoreRemoteChecksumsFromSaveGame)(void* a1, void* a2); #ifndef CLIENT_DLL inline uint32_t* g_nServerRemoteChecksum = nullptr; #endif // !CLIENT_DLL -#ifndef DEDICATED +#ifndef SERVER_DLL inline uint32_t* g_nClientRemoteChecksum = nullptr; -#endif // !DEDICATED +#endif // !SERVER_DLL namespace VScriptCode { @@ -24,9 +25,9 @@ namespace VScriptCode SQRESULT GetAvailableMaps(HSQUIRRELVM v); SQRESULT GetAvailablePlaylists(HSQUIRRELVM v); SQRESULT ShutdownHostGame(HSQUIRRELVM v); -#ifndef DEDICATED +#ifndef SERVER_DLL SQRESULT IsClientDLL(HSQUIRRELVM v); -#endif // !DEDICATED +#endif // !SERVER_DLL SQRESULT IsServerActive(HSQUIRRELVM v); #ifndef CLIENT_DLL SQRESULT KickPlayerByName(HSQUIRRELVM v); @@ -44,7 +45,7 @@ namespace VScriptCode SQRESULT IsDedicated(HSQUIRRELVM v); } #endif // !CLIENT_DLL -#ifndef DEDICATED +#ifndef SERVER_DLL namespace CLIENT { } @@ -65,9 +66,18 @@ namespace VScriptCode SQRESULT GetHiddenServerName(HSQUIRRELVM v); SQRESULT ConnectToServer(HSQUIRRELVM v); } -#endif // !DEDICATED +#endif // !SERVER_DLL } +#ifndef CLIENT_DLL +void Script_RegisterServerFunctions(CSquirrelVM* s); +#endif // !CLIENT_DLL + +#ifndef SERVER_DLL +void Script_RegisterClientFunctions(CSquirrelVM* s); +void Script_RegisterUIFunctions(CSquirrelVM* s); +#endif // !SERVER_DLL + /////////////////////////////////////////////////////////////////////////////// class VScriptShared : public IDetour { @@ -78,9 +88,9 @@ class VScriptShared : public IDetour #ifndef CLIENT_DLL LogVarAdr("g_nServerRemoteChecksum", reinterpret_cast(g_nServerRemoteChecksum)); #endif // !CLIENT_DLL -#ifndef DEDICATED +#ifndef SERVER_DLL LogVarAdr("g_nClientRemoteChecksum", reinterpret_cast(g_nClientRemoteChecksum)); -#endif // !DEDICATED +#endif // !SERVER_DLL } virtual void GetFun(void) const { @@ -95,9 +105,9 @@ class VScriptShared : public IDetour #ifndef CLIENT_DLL g_nServerRemoteChecksum = p_RestoreRemoteChecksumsFromSaveGame.Offset(0x1C0).FindPatternSelf("48 8D 15", CMemory::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); #endif // !CLIENT_DLL -#ifndef DEDICATED +#ifndef SERVER_DLL g_nClientRemoteChecksum = p_Script_Remote_BeginRegisteringFunctions.Offset(0x0).FindPatternSelf("89 05", CMemory::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x2, 0x6).RCast(); -#endif // !DEDICATED +#endif // !SERVER_DLL } virtual void GetCon(void) const { } virtual void Attach(void) const { } diff --git a/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp b/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp index b37f42fd..76d069ac 100644 --- a/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp +++ b/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp @@ -8,6 +8,11 @@ #include "pluginsystem/modsystem.h" #include "vsquirrel.h" +// Callbacks for registering abstracted script functions. +void(*ServerScriptRegister_Callback)(CSquirrelVM* s) = nullptr; +void(*ClientScriptRegister_Callback)(CSquirrelVM* s) = nullptr; +void(*UiScriptRegister_Callback)(CSquirrelVM* s) = nullptr; + //--------------------------------------------------------------------------------- // Purpose: Initialises a Squirrel VM instance // Output : True on success, false on failure @@ -27,17 +32,23 @@ SQBool CSquirrelVM::Init(CSquirrelVM* s, SQCONTEXT context, SQFloat curTime) #ifndef CLIENT_DLL case SQCONTEXT::SERVER: g_pServerScript = s; - Script_RegisterServerFunctions(s); + if (ServerScriptRegister_Callback) + ServerScriptRegister_Callback(s); + break; #endif #ifndef DEDICATED case SQCONTEXT::CLIENT: g_pClientScript = s; - Script_RegisterClientFunctions(s); + if (ClientScriptRegister_Callback) + ClientScriptRegister_Callback(s); + break; case SQCONTEXT::UI: g_pUIScript = s; - Script_RegisterUIFunctions(s); + if (UiScriptRegister_Callback) + UiScriptRegister_Callback(s); + break; #endif } diff --git a/r5dev/vscript/languages/squirrel_re/vsquirrel.h b/r5dev/vscript/languages/squirrel_re/vsquirrel.h index 627a0c25..2ef9c871 100644 --- a/r5dev/vscript/languages/squirrel_re/vsquirrel.h +++ b/r5dev/vscript/languages/squirrel_re/vsquirrel.h @@ -43,6 +43,10 @@ private: }; #pragma pack(pop) +extern void(*ServerScriptRegister_Callback)(CSquirrelVM* s); +extern void(*ClientScriptRegister_Callback)(CSquirrelVM* s); +extern void(*UiScriptRegister_Callback)(CSquirrelVM* s); + inline CMemory p_CSquirrelVM_Init; inline bool(*v_CSquirrelVM_Init)(CSquirrelVM* s, SQCONTEXT context, SQFloat curtime); diff --git a/r5dev/vscript/vscript.cpp b/r5dev/vscript/vscript.cpp index 7fc4d8fe..1a6e11ba 100644 --- a/r5dev/vscript/vscript.cpp +++ b/r5dev/vscript/vscript.cpp @@ -12,98 +12,6 @@ #include "game/shared/vscript_shared.h" #include "pluginsystem/modsystem.h" -//--------------------------------------------------------------------------------- -// Purpose: registers script functions in SERVER context -// Input : *s - -//--------------------------------------------------------------------------------- -void Script_RegisterServerFunctions(CSquirrelVM* s) -{ - s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native SERVER test function", "void", "", &VScriptCode::SHARED::SDKNativeTest); - s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion); - - s->RegisterFunction("GetNumHumanPlayers", "Script_GetNumHumanPlayers", "Gets the number of human players on the server", "int", "", &VScriptCode::SERVER::GetNumHumanPlayers); - s->RegisterFunction("GetNumFakeClients", "Script_GetNumFakeClients", "Gets the number of bot players on the server", "int", "", &VScriptCode::SERVER::GetNumFakeClients); - - s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps); - s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists); - - s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string, string", &VScriptCode::SHARED::KickPlayerByName); - s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string, string", &VScriptCode::SHARED::KickPlayerById); - - s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::SHARED::BanPlayerByName); - s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string, string", &VScriptCode::SHARED::BanPlayerById); - - s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string, string", &VScriptCode::SHARED::UnbanPlayer); - - s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame); - - s->RegisterFunction("IsDedicated", "Script_IsDedicated", "Returns whether this is a dedicated server", "bool", "", &VScriptCode::SERVER::IsDedicated); -} - -//--------------------------------------------------------------------------------- -// Purpose: registers script functions in CLIENT context -// Input : *s - -//--------------------------------------------------------------------------------- -void Script_RegisterClientFunctions(CSquirrelVM* s) -{ - s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native CLIENT test function", "void", "", &VScriptCode::SHARED::SDKNativeTest); - s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion); - - s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps); - s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists); - - s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame); - s->RegisterFunction("IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VScriptCode::SHARED::IsClientDLL); -} - -//--------------------------------------------------------------------------------- -// Purpose: registers script functions in UI context -// Input : *s - -//--------------------------------------------------------------------------------- -void Script_RegisterUIFunctions(CSquirrelVM* s) -{ - s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native UI test function", "void", "", &VScriptCode::SHARED::SDKNativeTest); - s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion); - - s->RegisterFunction("RefreshServerList", "Script_RefreshServerList", "Refreshes the public server list and returns the count", "int", "", &VScriptCode::UI::RefreshServerCount); - - // Functions for retrieving server browser data - s->RegisterFunction("GetServerName", "Script_GetServerName", "Gets the name of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerName); - s->RegisterFunction("GetServerDescription", "Script_GetServerDescription", "Gets the description of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerDescription); - s->RegisterFunction("GetServerMap", "Script_GetServerMap", "Gets the map of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerMap); - s->RegisterFunction("GetServerPlaylist", "Script_GetServerPlaylist", "Gets the playlist of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerPlaylist); - s->RegisterFunction("GetServerCurrentPlayers", "Script_GetServerCurrentPlayers", "Gets the current player count of the server at the specified index of the server list", "int", "int", &VScriptCode::UI::GetServerCurrentPlayers); - s->RegisterFunction("GetServerMaxPlayers", "Script_GetServerMaxPlayers", "Gets the max player count of the server at the specified index of the server list", "int", "int", &VScriptCode::UI::GetServerMaxPlayers); - s->RegisterFunction("GetServerCount", "Script_GetServerCount", "Gets the number of public servers", "int", "", &VScriptCode::UI::GetServerCount); - - // Misc main menu functions - s->RegisterFunction("GetPromoData", "Script_GetPromoData", "Gets promo data for specified slot type", "string", "int", &VScriptCode::UI::GetPromoData); - - // Functions for creating servers - s->RegisterFunction("CreateServer", "Script_CreateServer", "Starts server with the specified settings", "void", "string, string, string, string, int", &VScriptCode::UI::CreateServer); - s->RegisterFunction("IsServerActive", "Script_IsServerActive", "Returns whether the server is active", "bool", "", &VScriptCode::SHARED::IsServerActive); - - // Functions for connecting to servers - s->RegisterFunction("ConnectToServer", "Script_ConnectToServer", "Joins server by ip address and encryption key", "void", "string, string", &VScriptCode::UI::ConnectToServer); - s->RegisterFunction("ConnectToListedServer", "Script_ConnectToListedServer", "Joins listed server by index", "void", "int", &VScriptCode::UI::ConnectToListedServer); - s->RegisterFunction("ConnectToHiddenServer", "Script_ConnectToHiddenServer", "Joins hidden server by token", "void", "string", &VScriptCode::UI::ConnectToHiddenServer); - - s->RegisterFunction("GetHiddenServerName", "Script_GetHiddenServerName", "Gets hidden server name by token", "string", "string", &VScriptCode::UI::GetHiddenServerName); - s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps); - s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists); - - s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string", &VScriptCode::SHARED::KickPlayerByName); - s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string", &VScriptCode::SHARED::KickPlayerById); - - s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::SHARED::BanPlayerByName); - s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string", &VScriptCode::SHARED::BanPlayerById); - - s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string", &VScriptCode::SHARED::UnbanPlayer); - - s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame); - s->RegisterFunction("IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VScriptCode::SHARED::IsClientDLL); -} - //--------------------------------------------------------------------------------- // Purpose: Returns the script VM pointer by context // Input : context - diff --git a/r5dev/vscript/vscript.h b/r5dev/vscript/vscript.h index 3eb436fe..3861280c 100644 --- a/r5dev/vscript/vscript.h +++ b/r5dev/vscript/vscript.h @@ -34,10 +34,6 @@ inline SQBool(*v_Script_PrecompileClientScripts)(CSquirrelVM* vm); inline CMemory p_Script_SetClientCompiler; inline void(*v_Script_SetClientPrecompiler)(SQCONTEXT ctx, RSON::Node_t* rson); -void Script_RegisterServerFunctions(CSquirrelVM* s); -void Script_RegisterClientFunctions(CSquirrelVM* s); -void Script_RegisterUIFunctions(CSquirrelVM* s); - CSquirrelVM* Script_GetScriptHandle(const SQCONTEXT context); RSON::Node_t* Script_LoadScriptList(const SQChar* rsonfile); SQBool Script_LoadScriptFile(HSQUIRRELVM v, const SQChar* path, const SQChar* name, SQInteger flags);