diff --git a/r5dev/game/client/vscript_client.cpp b/r5dev/game/client/vscript_client.cpp index c7ce1955..8c76136b 100644 --- a/r5dev/game/client/vscript_client.cpp +++ b/r5dev/game/client/vscript_client.cpp @@ -27,7 +27,7 @@ namespace VScriptCode //----------------------------------------------------------------------------- // Purpose: refreshes the server list //----------------------------------------------------------------------------- - SQRESULT RefreshServerCount(HSQUIRRELVM v) + SQRESULT RefreshServerList(HSQUIRRELVM v) { string serverMessage; // Refresh list. size_t iCount = g_pServerListManager->RefreshServerList(serverMessage); @@ -389,27 +389,27 @@ void Script_RegisterUIFunctions(CSquirrelVM* s) Script_RegisterCommonAbstractions(s); Script_RegisterCoreClientFunctions(s); - s->RegisterFunction("RefreshServerList", "Script_RefreshServerList", "Refreshes the public server list and returns the count", "int", "", &VScriptCode::Client::RefreshServerCount); - s->RegisterFunction("GetServerCount", "Script_GetServerCount", "Gets the number of public servers", "int", "", &VScriptCode::Client::GetServerCount); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, RefreshServerList, "Refreshes the public server list and returns the count", "int", ""); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerCount, "Gets the number of public servers", "int", ""); // Functions for retrieving server browser data - s->RegisterFunction("GetHiddenServerName", "Script_GetHiddenServerName", "Gets hidden server name by token", "string", "string", &VScriptCode::Client::GetHiddenServerName); - s->RegisterFunction("GetServerName", "Script_GetServerName", "Gets the name of the server at the specified index of the server list", "string", "int", &VScriptCode::Client::GetServerName); - s->RegisterFunction("GetServerDescription", "Script_GetServerDescription", "Gets the description of the server at the specified index of the server list", "string", "int", &VScriptCode::Client::GetServerDescription); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetHiddenServerName, "Gets hidden server name by token", "string", "string"); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerName, "Gets the name of the server at the specified index of the server list", "string", "int"); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerDescription, "Gets the description of the server at the specified index of the server list", "string", "int"); - s->RegisterFunction("GetServerMap", "Script_GetServerMap", "Gets the map of the server at the specified index of the server list", "string", "int", &VScriptCode::Client::GetServerMap); - s->RegisterFunction("GetServerPlaylist", "Script_GetServerPlaylist", "Gets the playlist of the server at the specified index of the server list", "string", "int", &VScriptCode::Client::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::Client::GetServerCurrentPlayers); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerMap, "Gets the map of the server at the specified index of the server list", "string", "int"); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerPlaylist, "Gets the playlist of the server at the specified index of the server list", "string", "int"); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerCurrentPlayers, "Gets the current player count of the server at the specified index of the server list", "int", "int"); - s->RegisterFunction("GetServerMaxPlayers", "Script_GetServerMaxPlayers", "Gets the max player count of the server at the specified index of the server list", "int", "int", &VScriptCode::Client::GetServerMaxPlayers); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerMaxPlayers, "Gets the max player count of the server at the specified index of the server list", "int", "int"); // Misc main menu functions - s->RegisterFunction("GetPromoData", "Script_GetPromoData", "Gets promo data for specified slot type", "string", "int", &VScriptCode::Client::GetPromoData); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetPromoData, "Gets promo data for specified slot type", "string", "int"); // Functions for connecting to servers - s->RegisterFunction("ConnectToServer", "Script_ConnectToServer", "Joins server by ip address and encryption key", "void", "string, string", &VScriptCode::Client::ConnectToServer); - s->RegisterFunction("ConnectToListedServer", "Script_ConnectToListedServer", "Joins listed server by index", "void", "int", &VScriptCode::Client::ConnectToListedServer); - s->RegisterFunction("ConnectToHiddenServer", "Script_ConnectToHiddenServer", "Joins hidden server by token", "void", "string", &VScriptCode::Client::ConnectToHiddenServer); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToServer, "Joins server by ip address and encryption key", "void", "string, string"); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToListedServer, "Joins listed server by index", "void", "int"); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToHiddenServer, "Joins hidden server by token", "void", "string"); } //--------------------------------------------------------------------------------- @@ -418,5 +418,5 @@ void Script_RegisterUIFunctions(CSquirrelVM* s) //--------------------------------------------------------------------------------- void Script_RegisterCoreClientFunctions(CSquirrelVM* s) { - s->RegisterFunction("IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VScriptCode::Client::IsClientDLL); + DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, IsClientDLL, "Returns whether this build is client only", "bool", ""); } diff --git a/r5dev/game/client/vscript_client.h b/r5dev/game/client/vscript_client.h index 4009126e..a2066ba4 100644 --- a/r5dev/game/client/vscript_client.h +++ b/r5dev/game/client/vscript_client.h @@ -5,7 +5,7 @@ namespace VScriptCode { namespace Client { - SQRESULT RefreshServerCount(HSQUIRRELVM v); + SQRESULT RefreshServerList(HSQUIRRELVM v); SQRESULT GetServerCount(HSQUIRRELVM v); SQRESULT GetHiddenServerName(HSQUIRRELVM v); @@ -32,4 +32,9 @@ void Script_RegisterClientFunctions(CSquirrelVM* s); void Script_RegisterUIFunctions(CSquirrelVM* s); void Script_RegisterCoreClientFunctions(CSquirrelVM* s); +#define DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, functionName, helpString, \ + returnType, parameters) \ + s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \ + helpString, returnType, parameters, VScriptCode::Client::##functionName); \ + #endif // VSCRIPT_CLIENT_H diff --git a/r5dev/game/server/vscript_server.cpp b/r5dev/game/server/vscript_server.cpp index 219133fe..0b390dc9 100644 --- a/r5dev/game/server/vscript_server.cpp +++ b/r5dev/game/server/vscript_server.cpp @@ -206,11 +206,11 @@ void Script_RegisterServerFunctions(CSquirrelVM* s) //--------------------------------------------------------------------------------- void Script_RegisterCoreServerFunctions(CSquirrelVM* s) { - s->RegisterFunction("IsServerActive", "Script_IsServerActive", "Returns whether the server is active", "bool", "", &VScriptCode::Server::IsServerActive); - s->RegisterFunction("IsDedicated", "Script_IsDedicated", "Returns whether this is a dedicated server", "bool", "", &VScriptCode::Server::IsDedicated); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, IsServerActive, "Returns whether the server is active", "bool", ""); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, IsDedicated, "Returns whether this is a dedicated server", "bool", ""); - s->RegisterFunction("CreateServer", "Script_CreateServer", "Starts server with the specified settings", "void", "string, string, string, string, int", &VScriptCode::Server::CreateServer); - s->RegisterFunction("DestroyServer", "Script_DestroyServer", "Shuts the local host game down", "void", "", &VScriptCode::Server::DestroyServer); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, CreateServer, "Starts server with the specified settings", "void", "string, string, string, string, int"); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, DestroyServer, "Shuts the local host game down", "void", ""); } //--------------------------------------------------------------------------------- @@ -219,14 +219,14 @@ void Script_RegisterCoreServerFunctions(CSquirrelVM* s) //--------------------------------------------------------------------------------- void Script_RegisterAdminPanelFunctions(CSquirrelVM* s) { - 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); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, GetNumHumanPlayers, "Gets the number of human players on the server", "int", ""); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, GetNumFakeClients, "Gets the number of bot players on the server", "int", ""); - s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string", &VScriptCode::Server::KickPlayerByName); - s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string", &VScriptCode::Server::KickPlayerById); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, KickPlayerByName, "Kicks a player from the server by name", "void", "string"); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, KickPlayerById, "Kicks a player from the server by handle or nucleus id", "void", "string"); - s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::Server::BanPlayerByName); - s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string", &VScriptCode::Server::BanPlayerById); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, BanPlayerByName, "Bans a player from the server by name", "void", "string"); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, BanPlayerById, "Bans a player from the server by handle or nucleus id", "void", "string"); - s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string", &VScriptCode::Server::UnbanPlayer); + DEFINE_SERVER_SCRIPTFUNC_NAMED(s, UnbanPlayer, "Unbans a player from the server by nucleus id or ip address", "void", "string"); } diff --git a/r5dev/game/server/vscript_server.h b/r5dev/game/server/vscript_server.h index ed82598d..fc22dc32 100644 --- a/r5dev/game/server/vscript_server.h +++ b/r5dev/game/server/vscript_server.h @@ -26,4 +26,9 @@ void Script_RegisterServerFunctions(CSquirrelVM* s); void Script_RegisterCoreServerFunctions(CSquirrelVM* s); void Script_RegisterAdminPanelFunctions(CSquirrelVM* s); +#define DEFINE_SERVER_SCRIPTFUNC_NAMED(s, functionName, helpString, \ + returnType, parameters) \ + s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \ + helpString, returnType, parameters, VScriptCode::Server::##functionName); \ + #endif // VSCRIPT_SERVER_H diff --git a/r5dev/game/shared/vscript_shared.cpp b/r5dev/game/shared/vscript_shared.cpp index 25c9b167..5c639d04 100644 --- a/r5dev/game/shared/vscript_shared.cpp +++ b/r5dev/game/shared/vscript_shared.cpp @@ -26,6 +26,15 @@ namespace VScriptCode { namespace Shared { + //----------------------------------------------------------------------------- + // Purpose: generic stub for unsupported functions + //----------------------------------------------------------------------------- + SQRESULT StubUnsupported(HSQUIRRELVM v) + { + v_SQVM_RaiseError(v, "This function is not supported on this builds.\n"); + return SQ_ERROR; + } + //----------------------------------------------------------------------------- // Purpose: expose SDK version to the VScript API //----------------------------------------------------------------------------- @@ -83,8 +92,8 @@ namespace VScriptCode //--------------------------------------------------------------------------------- void Script_RegisterCommonAbstractions(CSquirrelVM* s) { - s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::Shared::GetSDKVersion); + DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetSDKVersion, "Gets the SDK version as a string", "string", ""); - 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); + 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 >", ""); } diff --git a/r5dev/game/shared/vscript_shared.h b/r5dev/game/shared/vscript_shared.h index fd579a22..a15eea0b 100644 --- a/r5dev/game/shared/vscript_shared.h +++ b/r5dev/game/shared/vscript_shared.h @@ -16,6 +16,7 @@ namespace VScriptCode { namespace Shared { + SQRESULT StubUnsupported(HSQUIRRELVM v); SQRESULT GetSDKVersion(HSQUIRRELVM v); SQRESULT GetAvailableMaps(HSQUIRRELVM v); SQRESULT GetAvailablePlaylists(HSQUIRRELVM v); @@ -24,6 +25,16 @@ namespace VScriptCode void Script_RegisterCommonAbstractions(CSquirrelVM* s); +#define DEFINE_SCRIPTFUNC_STUBBED(s, functionName, returnType) \ + s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \ + "Stub function; not supported on this build.", #returnType, "", \ + &VScriptCode::Shared::StubUnsupported); \ + +#define DEFINE_SHARED_SCRIPTFUNC_NAMED(s, functionName, helpString, \ + returnType, parameters) \ + s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \ + helpString, returnType, parameters, VScriptCode::Shared::##functionName);\ + /////////////////////////////////////////////////////////////////////////////// class VScriptShared : public IDetour {