mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Adapt new master server features to SQVM
* Adapted current/max players to SQVM. * Improved exception handling in SQVM.
This commit is contained in:
parent
3efd7ece3b
commit
6b48d42609
@ -58,7 +58,7 @@ namespace VSquirrel
|
||||
return SQ_OK;
|
||||
|
||||
sq_newarray(v, 0);
|
||||
for (auto& it : g_vAllMaps)
|
||||
for (const string& it : g_vAllMaps)
|
||||
{
|
||||
sq_pushstring(v, it.c_str(), -1);
|
||||
sq_arrayappend(v, -2);
|
||||
@ -76,7 +76,7 @@ namespace VSquirrel
|
||||
return SQ_OK;
|
||||
|
||||
sq_newarray(v, 0);
|
||||
for (auto& it : g_vAllPlaylists)
|
||||
for (const string& it : g_vAllPlaylists)
|
||||
{
|
||||
sq_pushstring(v, it.c_str(), -1);
|
||||
sq_arrayappend(v, -2);
|
||||
@ -129,22 +129,53 @@ namespace VSquirrel
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetServerName(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger iServerIndex = sq_getinteger(v, 1);
|
||||
string svServerName = g_pBrowser->m_vServerList[iServerIndex].m_svHostName;
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
if (iServer >= static_cast<SQInteger>(g_pBrowser->m_vServerList.size()))
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n",
|
||||
static_cast<SQInteger>(g_pBrowser->m_vServerList.size()));
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
string svServerName = g_pBrowser->m_vServerList[iServer].m_svHostName;
|
||||
sq_pushstring(v, svServerName.c_str(), -1);
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get server's current description from serverlist index
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetServerDescription(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
if (iServer >= static_cast<SQInteger>(g_pBrowser->m_vServerList.size()))
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n",
|
||||
static_cast<SQInteger>(g_pBrowser->m_vServerList.size()));
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
string svServerDescription = g_pBrowser->m_vServerList[iServer].m_svDescription;
|
||||
sq_pushstring(v, svServerDescription.c_str(), -1);
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get server's current playlist via serverlist index
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetServerPlaylist(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger iServerIndex = sq_getinteger(v, 1);
|
||||
string svServerPlaylist = g_pBrowser->m_vServerList[iServerIndex].m_svPlaylist;
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
if (iServer >= static_cast<SQInteger>(g_pBrowser->m_vServerList.size()))
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n",
|
||||
static_cast<SQInteger>(g_pBrowser->m_vServerList.size()));
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
string svServerPlaylist = g_pBrowser->m_vServerList[iServer].m_svPlaylist;
|
||||
sq_pushstring(v, svServerPlaylist.c_str(), -1);
|
||||
|
||||
return SQ_OK;
|
||||
@ -155,14 +186,56 @@ namespace VSquirrel
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetServerMap(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger iServerIndex = sq_getinteger(v, 1);
|
||||
string svServerMapName = g_pBrowser->m_vServerList[iServerIndex].m_svMapName;
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
if (iServer >= static_cast<SQInteger>(g_pBrowser->m_vServerList.size()))
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n",
|
||||
static_cast<SQInteger>(g_pBrowser->m_vServerList.size()));
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
string svServerMapName = g_pBrowser->m_vServerList[iServer].m_svMapName;
|
||||
sq_pushstring(v, svServerMapName.c_str(), -1);
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get server's current player count via serverlist index
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetServerCurrentPlayers(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
if (iServer >= static_cast<SQInteger>(g_pBrowser->m_vServerList.size()))
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n",
|
||||
static_cast<SQInteger>(g_pBrowser->m_vServerList.size()));
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
sq_pushinteger(v, strtol(g_pBrowser->m_vServerList[iServer].m_svPlayerCount.c_str(), NULL, NULL));
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get server's current player count via serverlist index
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetServerMaxPlayers(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
if (iServer >= static_cast<SQInteger>(g_pBrowser->m_vServerList.size()))
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n",
|
||||
static_cast<SQInteger>(g_pBrowser->m_vServerList.size()));
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
sq_pushinteger(v, strtol(g_pBrowser->m_vServerList[iServer].m_svMaxPlayers.c_str(), NULL, NULL));
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get current server count from pylon
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -242,12 +315,18 @@ namespace VSquirrel
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT SetEncKeyAndConnect(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger iServerIndex = sq_getinteger(v, 1);
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
if (iServer >= static_cast<SQInteger>(g_pBrowser->m_vServerList.size()))
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n",
|
||||
static_cast<SQInteger>(g_pBrowser->m_vServerList.size()));
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
// !TODO: Create glue class instead.
|
||||
g_pBrowser->ConnectToServer(g_pBrowser->m_vServerList[iServerIndex].m_svIpAddress,
|
||||
g_pBrowser->m_vServerList[iServerIndex].m_svGamePort,
|
||||
g_pBrowser->m_vServerList[iServerIndex].m_svEncryptionKey);
|
||||
g_pBrowser->ConnectToServer(g_pBrowser->m_vServerList[iServer].m_svIpAddress,
|
||||
g_pBrowser->m_vServerList[iServer].m_svGamePort,
|
||||
g_pBrowser->m_vServerList[iServer].m_svEncryptionKey);
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
@ -258,17 +337,19 @@ namespace VSquirrel
|
||||
SQRESULT CreateServerFromMenu(HSQUIRRELVM v)
|
||||
{
|
||||
string svServerName = sq_getstring(v, 1);
|
||||
string svServerMapName = sq_getstring(v, 2);
|
||||
string svServerPlaylist = sq_getstring(v, 3);
|
||||
EServerVisibility eServerVisibility = static_cast<EServerVisibility>(sq_getinteger(v, 4));
|
||||
string svServerDescription = sq_getstring(v, 2);
|
||||
string svServerMapName = sq_getstring(v, 3);
|
||||
string svServerPlaylist = sq_getstring(v, 4);
|
||||
EServerVisibility eServerVisibility = static_cast<EServerVisibility>(sq_getinteger(v, 5));
|
||||
|
||||
if (svServerName.empty() || svServerMapName.empty() || svServerPlaylist.empty())
|
||||
return SQ_OK;
|
||||
|
||||
// Adjust browser settings.
|
||||
g_pBrowser->m_Server.m_svPlaylist = svServerPlaylist;
|
||||
g_pBrowser->m_Server.m_svMapName = svServerMapName;
|
||||
g_pBrowser->m_Server.m_svHostName = svServerName;
|
||||
g_pBrowser->m_Server.m_svDescription = svServerDescription;
|
||||
g_pBrowser->m_Server.m_svMapName = svServerMapName;
|
||||
g_pBrowser->m_Server.m_svPlaylist = svServerPlaylist;
|
||||
g_pBrowser->eServerVisibility = eServerVisibility;
|
||||
|
||||
// Launch server.
|
||||
|
@ -38,8 +38,11 @@ namespace VSquirrel
|
||||
namespace UI
|
||||
{
|
||||
SQRESULT GetServerName(HSQUIRRELVM v);
|
||||
SQRESULT GetServerDescription(HSQUIRRELVM v);
|
||||
SQRESULT GetServerPlaylist(HSQUIRRELVM v);
|
||||
SQRESULT GetServerMap(HSQUIRRELVM v);
|
||||
SQRESULT GetServerCurrentPlayers(HSQUIRRELVM v);
|
||||
SQRESULT GetServerMaxPlayers(HSQUIRRELVM v);
|
||||
SQRESULT GetServerCount(HSQUIRRELVM v);
|
||||
SQRESULT GetPromoData(HSQUIRRELVM v);
|
||||
SQRESULT SetEncKeyAndConnect(HSQUIRRELVM v);
|
||||
|
@ -82,8 +82,11 @@ void Script_RegisterUIFunctions(CSquirrelVM* pSquirrelVM)
|
||||
|
||||
// Functions for retrieving server browser data
|
||||
Script_RegisterFunction(pSquirrelVM, "GetServerName", "Script_GetServerName", "Gets the name of the server at the specified index of the server list", "string", "int", &VSquirrel::UI::GetServerName);
|
||||
Script_RegisterFunction(pSquirrelVM, "GetServerDescription", "Script_GetServerDescription", "Gets the description of the server at the specified index of the server list", "string", "int", &VSquirrel::UI::GetServerDescription);
|
||||
Script_RegisterFunction(pSquirrelVM, "GetServerPlaylist", "Script_GetServerPlaylist", "Gets the playlist of the server at the specified index of the server list", "string", "int", &VSquirrel::UI::GetServerPlaylist);
|
||||
Script_RegisterFunction(pSquirrelVM, "GetServerMap", "Script_GetServerMap", "Gets the map of the server at the specified index of the server list", "string", "int", &VSquirrel::UI::GetServerMap);
|
||||
Script_RegisterFunction(pSquirrelVM, "GetServerCurrentPlayers", "Script_GetServerCurrentPlayers", "Gets the current player count of the server at the specified index of the server list", "int", "int", &VSquirrel::UI::GetServerCurrentPlayers);
|
||||
Script_RegisterFunction(pSquirrelVM, "GetServerMaxPlayers", "Script_GetServerMaxPlayers", "Gets the max player count of the server at the specified index of the server list", "int", "int", &VSquirrel::UI::GetServerMaxPlayers);
|
||||
Script_RegisterFunction(pSquirrelVM, "GetServerCount", "Script_GetServerCount", "Gets the number of public servers", "int", "", &VSquirrel::UI::GetServerCount);
|
||||
|
||||
// Misc main menu functions
|
||||
@ -91,7 +94,7 @@ void Script_RegisterUIFunctions(CSquirrelVM* pSquirrelVM)
|
||||
Script_RegisterFunction(pSquirrelVM, "GetPromoData", "Script_GetPromoData", "Gets promo data for specified slot type", "string", "int", &VSquirrel::UI::GetPromoData);
|
||||
|
||||
// Functions for connecting to servers
|
||||
Script_RegisterFunction(pSquirrelVM, "CreateServer", "Script_CreateServer", "Start server with the specified settings", "void", "string, string, string, int", &VSquirrel::UI::CreateServerFromMenu);
|
||||
Script_RegisterFunction(pSquirrelVM, "CreateServer", "Script_CreateServer", "Start server with the specified settings", "void", "string, string, string, string, int", &VSquirrel::UI::CreateServerFromMenu);
|
||||
Script_RegisterFunction(pSquirrelVM, "SetEncKeyAndConnect", "Script_SetEncKeyAndConnect", "Set the encryption key to that of the specified server and connects to it", "void", "int", &VSquirrel::UI::SetEncKeyAndConnect);
|
||||
Script_RegisterFunction(pSquirrelVM, "JoinPrivateServerFromMenu", "Script_JoinPrivateServerFromMenu", "Joins private server by token", "void", "string", &VSquirrel::UI::JoinPrivateServerFromMenu);
|
||||
Script_RegisterFunction(pSquirrelVM, "GetPrivateServerMessage", "Script_GetPrivateServerMessage", "Gets private server join status message", "string", "string", &VSquirrel::UI::GetPrivateServerMessage);
|
||||
|
@ -57,6 +57,12 @@ inline auto v_SQVM_CompileError = p_SQVM_CompileError.RCast<void (*)(HSQUIRRELVM
|
||||
inline CMemory p_SQVM_LogicError;
|
||||
inline auto v_SQVM_LogicError = p_SQVM_LogicError.RCast<void (*)(SQBool bPrompt)>();
|
||||
|
||||
inline CMemory p_SQVM_ScriptError;
|
||||
inline auto v_SQVM_ScriptError = p_SQVM_ScriptError.RCast<SQInteger (*)(const SQChar* pszFormat, ...)>();
|
||||
|
||||
inline CMemory p_SQVM_RaiseError;
|
||||
inline auto v_SQVM_RaiseError = p_SQVM_RaiseError.RCast<SQInteger(*)(HSQUIRRELVM v, const SQChar* pszFormat, ...)>();
|
||||
|
||||
SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...);
|
||||
SQRESULT SQVM_WarningFunc(HSQUIRRELVM v, SQInteger a2, SQInteger a3, SQInteger* nStringSize, SQChar** ppString);
|
||||
void SQVM_CompileError(HSQUIRRELVM v, const SQChar* pszError, const SQChar* pszFile, SQUnsignedInteger nLine, SQInteger nColumn);
|
||||
@ -78,6 +84,8 @@ class HSQVM : public IDetour
|
||||
spdlog::debug("| FUN: SQVM_WarningCmd : {:#18x} |\n", p_SQVM_WarningCmd.GetPtr());
|
||||
spdlog::debug("| FUN: SQVM_CompileError : {:#18x} |\n", p_SQVM_CompileError.GetPtr());
|
||||
spdlog::debug("| FUN: SQVM_LogicError : {:#18x} |\n", p_SQVM_LogicError.GetPtr());
|
||||
spdlog::debug("| FUN: SQVM_ScriptError : {:#18x} |\n", p_SQVM_ScriptError.GetPtr());
|
||||
spdlog::debug("| FUN: SQVM_RaiseError : {:#18x} |\n", p_SQVM_RaiseError.GetPtr());
|
||||
spdlog::debug("+----------------------------------------------------------------+\n");
|
||||
}
|
||||
virtual void GetFun(void) const
|
||||
@ -93,13 +101,17 @@ class HSQVM : public IDetour
|
||||
#endif
|
||||
p_SQVM_WarningCmd = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x30\x33\xDB\x48\x8D\x44\x24\x00\x4C\x8D\x4C\x24\x00"), "xxxxxxxxxxxx?xxxx?");
|
||||
p_SQVM_CompileError = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x41\x56\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\xD9\x4C\x8B\xF2"), "xxxx?xxxx?xxxx?xxxx?xxxxx????xxxxxx");
|
||||
p_SQVM_ScriptError = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\xE9\x00\x00\x00\x00\xF7\xD2"), "x????xx").FollowNearCallSelf();
|
||||
p_SQVM_RaiseError = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x54\x24\x00\x4C\x89\x44\x24\x00\x4C\x89\x4C\x24\x00\x53\x56\x57\x48\x83\xEC\x40"), "xxxx?xxxx?xxxx?xxxxxxx");
|
||||
|
||||
v_SQVM_PrintFunc = p_SQVM_PrintFunc.RCast<SQRESULT(*)(HSQUIRRELVM, SQChar*, ...)>(); /*48 8B C4 48 89 50 10 4C 89 40 18 4C 89 48 20 53 56 57 48 81 EC 30 08 00 00 48 8B DA 48 8D 70 18 48 8B F9 E8 ?? ?? ?? FF 48 89 74 24 28 48 8D 54 24 30 33*/
|
||||
v_SQVM_WarningFunc = p_SQVM_WarningFunc.RCast<SQRESULT(*)(HSQUIRRELVM, SQInteger, SQInteger, SQInteger*, SQChar**)>(); /*4C 89 4C 24 20 44 89 44 24 18 89 54 24 10 53 55 56 57 41 54 41 55 41 56 41 57 48 83 EC ?? 48 8B*/
|
||||
v_SQVM_GetErrorLine = p_SQVM_GetErrorLine.RCast<size_t(*)(const SQChar*, SQInteger, SQChar*, SQInteger)>(); /*48 8B C4 55 56 48 8D A8 ?? ?? ?? ?? 48 81 EC ?? ?? ?? ?? 83 65 90 FC*/
|
||||
v_SQVM_WarningCmd = p_SQVM_WarningCmd.RCast<SQRESULT(*)(HSQUIRRELVM, SQInteger)>(); /*40 53 48 83 EC 30 33 DB 48 8D 44 24 ?? 4C 8D 4C 24 ??*/
|
||||
v_SQVM_CompileError = p_SQVM_CompileError.RCast<void (*)(HSQUIRRELVM, const SQChar*, const SQChar*, SQUnsignedInteger, SQInteger)>(); /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 41 56 48 81 EC ? ? ? ? 48 8B D9 4C 8B F2*/
|
||||
v_SQVM_LogicError = p_SQVM_LogicError.RCast<void (*)(SQBool)>(); /*48 83 EC 38 F2 0F 10 05 ? ? ? ?*/
|
||||
v_SQVM_CompileError = p_SQVM_CompileError.RCast<void (*)(HSQUIRRELVM, const SQChar*, const SQChar*, SQUnsignedInteger, SQInteger)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 41 56 48 81 EC ?? ?? ?? ?? 48 8B D9 4C 8B F2*/
|
||||
v_SQVM_LogicError = p_SQVM_LogicError.RCast<void (*)(SQBool)>(); /*48 83 EC 38 F2 0F 10 05 ?? ?? ?? ??*/
|
||||
v_SQVM_ScriptError = p_SQVM_ScriptError.RCast<SQInteger(*)(const SQChar*, ...)>(); /*E9 ?? ?? ?? ?? F7 D2*/
|
||||
v_SQVM_RaiseError = p_SQVM_RaiseError.RCast<SQInteger(*)(HSQUIRRELVM, const SQChar*, ...)>(); /*E8 ?? ?? ?? ?? 32 C0 EB 3C*/
|
||||
}
|
||||
virtual void GetVar(void) const { }
|
||||
virtual void GetCon(void) const { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user