diff options
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r-- | NorthstarDedicatedTest/clientchathooks.cpp | 24 | ||||
-rw-r--r-- | NorthstarDedicatedTest/miscserverscript.cpp | 12 | ||||
-rw-r--r-- | NorthstarDedicatedTest/plugins.cpp | 56 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptmainmenupromos.cpp | 30 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptmodmenu.cpp | 42 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptserverbrowser.cpp | 123 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/serverchathooks.cpp | 28 | ||||
-rw-r--r-- | NorthstarDedicatedTest/squirrel.cpp | 98 | ||||
-rw-r--r-- | NorthstarDedicatedTest/squirrel.h | 151 |
10 files changed, 312 insertions, 256 deletions
diff --git a/NorthstarDedicatedTest/clientchathooks.cpp b/NorthstarDedicatedTest/clientchathooks.cpp index bdd0e8c2..80d8a295 100644 --- a/NorthstarDedicatedTest/clientchathooks.cpp +++ b/NorthstarDedicatedTest/clientchathooks.cpp @@ -38,12 +38,12 @@ static void CHudChat__AddGameLineHook(void* self, const char* message, int inbox payload = message + 1; } - g_pClientSquirrel->pusharg((int)senderId - 1); - g_pClientSquirrel->pusharg(payload); - g_pClientSquirrel->pusharg(isTeam); - g_pClientSquirrel->pusharg(isDead); - g_pClientSquirrel->pusharg(type); - g_pClientSquirrel->call(5); + g_pClientSquirrel->pushinteger(g_pClientSquirrel->sqvm2, (int) senderId - 1); + g_pClientSquirrel->pushstring(g_pClientSquirrel->sqvm2, payload); + g_pClientSquirrel->pushbool(g_pClientSquirrel->sqvm2, isTeam); + g_pClientSquirrel->pushbool(g_pClientSquirrel->sqvm2, isDead); + g_pClientSquirrel->pushinteger(g_pClientSquirrel->sqvm2, type); + g_pClientSquirrel->call(g_pClientSquirrel->sqvm2, 5); } else { @@ -57,8 +57,8 @@ static void CHudChat__AddGameLineHook(void* self, const char* message, int inbox // void NSChatWrite( int context, string str ) static SQRESULT SQ_ChatWrite(void* sqvm) { - int context = g_pClientSquirrel->sq_getinteger(sqvm, 1); - const char* str = g_pClientSquirrel->sq_getstring(sqvm, 2); + int context = g_pClientSquirrel->getinteger(g_pClientSquirrel->sqvm2, 1); + const char* str = g_pClientSquirrel->getstring(g_pClientSquirrel->sqvm2, 2); LocalChatWriter((LocalChatWriter::Context)context).Write(str); return SQRESULT_NOTNULL; @@ -67,8 +67,8 @@ static SQRESULT SQ_ChatWrite(void* sqvm) // void NSChatWriteRaw( int context, string str ) static SQRESULT SQ_ChatWriteRaw(void* sqvm) { - int context = g_pClientSquirrel->sq_getinteger(sqvm, 1); - const char* str = g_pClientSquirrel->sq_getstring(sqvm, 2); + int context = g_pClientSquirrel->getinteger(g_pClientSquirrel->sqvm2, 1); + const char* str = g_pClientSquirrel->getstring(g_pClientSquirrel->sqvm2, 2); LocalChatWriter((LocalChatWriter::Context)context).InsertText(str); return SQRESULT_NOTNULL; @@ -77,8 +77,8 @@ static SQRESULT SQ_ChatWriteRaw(void* sqvm) // void NSChatWriteLine( int context, string str ) static SQRESULT SQ_ChatWriteLine(void* sqvm) { - int context = g_pClientSquirrel->sq_getinteger(sqvm, 1); - const char* str = g_pClientSquirrel->sq_getstring(sqvm, 2); + int context = g_pClientSquirrel->getinteger(g_pClientSquirrel->sqvm2, 1); + const char* str = g_pClientSquirrel->getstring(g_pClientSquirrel->sqvm2, 2); LocalChatWriter((LocalChatWriter::Context)context).WriteLine(str); return SQRESULT_NOTNULL; diff --git a/NorthstarDedicatedTest/miscserverscript.cpp b/NorthstarDedicatedTest/miscserverscript.cpp index 26c18d81..9e8d26ff 100644 --- a/NorthstarDedicatedTest/miscserverscript.cpp +++ b/NorthstarDedicatedTest/miscserverscript.cpp @@ -21,12 +21,12 @@ void* GetPlayerByIndex(int playerIndex) // void function NSEarlyWritePlayerIndexPersistenceForLeave( int playerIndex ) SQRESULT SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm) { - int playerIndex = g_pServerSquirrel->sq_getinteger(sqvm, 1); + int playerIndex = g_pServerSquirrel->getinteger(sqvm, 1); void* player = GetPlayerByIndex(playerIndex); if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player)) { - g_pServerSquirrel->sq_raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); + g_pServerSquirrel->raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); return SQRESULT_ERROR; } @@ -38,22 +38,22 @@ SQRESULT SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm) // bool function NSIsWritingPlayerPersistence() SQRESULT SQ_IsWritingPlayerPersistence(void* sqvm) { - g_pServerSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bSavingPersistentData); + g_pServerSquirrel->pushbool(sqvm, g_MasterServerManager->m_bSavingPersistentData); return SQRESULT_NOTNULL; } // bool function NSIsPlayerIndexLocalPlayer( int playerIndex ) SQRESULT SQ_IsPlayerIndexLocalPlayer(void* sqvm) { - int playerIndex = g_pServerSquirrel->sq_getinteger(sqvm, 1); + int playerIndex = g_pServerSquirrel->getinteger(sqvm, 1); void* player = GetPlayerByIndex(playerIndex); if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player)) { - g_pServerSquirrel->sq_raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); + g_pServerSquirrel->raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); return SQRESULT_ERROR; } - g_pServerSquirrel->sq_pushbool(sqvm, !strcmp(R2::g_LocalPlayerUserID, (char*)player + 0xF500)); + g_pServerSquirrel->pushbool(sqvm, !strcmp(R2::g_LocalPlayerUserID, (char*)player + 0xF500)); return SQRESULT_NOTNULL; } diff --git a/NorthstarDedicatedTest/plugins.cpp b/NorthstarDedicatedTest/plugins.cpp index 9f0c062f..157ac416 100644 --- a/NorthstarDedicatedTest/plugins.cpp +++ b/NorthstarDedicatedTest/plugins.cpp @@ -113,12 +113,12 @@ void initGameState() SQRESULT SQ_UpdateGameStateUI(void* sqvm) { AcquireSRWLockExclusive(&gameStateLock); - gameState.map = g_pClientSquirrel->sq_getstring(sqvm, 1); - gameState.mapDisplayName = g_pClientSquirrel->sq_getstring(sqvm, 2); - gameState.playlist = g_pClientSquirrel->sq_getstring(sqvm, 3); - gameState.playlistDisplayName = g_pClientSquirrel->sq_getstring(sqvm, 4); - gameState.connected = g_pClientSquirrel->sq_getbool(sqvm, 5); - gameState.loading = g_pClientSquirrel->sq_getbool(sqvm, 6); + gameState.map = g_pUISquirrel->getstring(sqvm, 1); + gameState.mapDisplayName = g_pUISquirrel->getstring(sqvm, 2); + gameState.playlist = g_pUISquirrel->getstring(sqvm, 3); + gameState.playlistDisplayName = g_pUISquirrel->getstring(sqvm, 4); + gameState.connected = g_pUISquirrel->getbool(sqvm, 5); + gameState.loading = g_pUISquirrel->getbool(sqvm, 6); ReleaseSRWLockExclusive(&gameStateLock); return SQRESULT_NOTNULL; } @@ -128,13 +128,13 @@ SQRESULT SQ_UpdateGameStateClient(void* sqvm) { AcquireSRWLockExclusive(&gameStateLock); AcquireSRWLockExclusive(&serverInfoLock); - gameState.players = g_pClientSquirrel->sq_getinteger(sqvm, 1); - serverInfo.maxPlayers = g_pClientSquirrel->sq_getinteger(sqvm, 2); - gameState.ourScore = g_pClientSquirrel->sq_getinteger(sqvm, 3); - gameState.secondHighestScore = g_pClientSquirrel->sq_getinteger(sqvm, 4); - gameState.highestScore = g_pClientSquirrel->sq_getinteger(sqvm, 5); - serverInfo.roundBased = g_pClientSquirrel->sq_getbool(sqvm, 6); - serverInfo.scoreLimit = g_pClientSquirrel->sq_getbool(sqvm, 7); + gameState.players = g_pClientSquirrel->getinteger(sqvm, 1); + serverInfo.maxPlayers = g_pClientSquirrel->getinteger(sqvm, 2); + gameState.ourScore = g_pClientSquirrel->getinteger(sqvm, 3); + gameState.secondHighestScore = g_pClientSquirrel->getinteger(sqvm, 4); + gameState.highestScore = g_pClientSquirrel->getinteger(sqvm, 5); + serverInfo.roundBased = g_pClientSquirrel->getbool(sqvm, 6); + serverInfo.scoreLimit = g_pClientSquirrel->getbool(sqvm, 7); ReleaseSRWLockExclusive(&gameStateLock); ReleaseSRWLockExclusive(&serverInfoLock); return SQRESULT_NOTNULL; @@ -146,15 +146,15 @@ SQRESULT SQ_UpdateServerInfo(void* sqvm) { AcquireSRWLockExclusive(&gameStateLock); AcquireSRWLockExclusive(&serverInfoLock); - serverInfo.id = g_pClientSquirrel->sq_getstring(sqvm, 1); - serverInfo.name = g_pClientSquirrel->sq_getstring(sqvm, 2); - serverInfo.password = g_pClientSquirrel->sq_getstring(sqvm, 3); - gameState.players = g_pClientSquirrel->sq_getinteger(sqvm, 4); - serverInfo.maxPlayers = g_pClientSquirrel->sq_getinteger(sqvm, 5); - gameState.map = g_pClientSquirrel->sq_getstring(sqvm, 6); - gameState.mapDisplayName = g_pClientSquirrel->sq_getstring(sqvm, 7); - gameState.playlist = g_pClientSquirrel->sq_getstring(sqvm, 8); - gameState.playlistDisplayName = g_pClientSquirrel->sq_getstring(sqvm, 9); + serverInfo.id = g_pUISquirrel->getstring(sqvm, 1); + serverInfo.name = g_pUISquirrel->getstring(sqvm, 2); + serverInfo.password = g_pUISquirrel->getstring(sqvm, 3); + gameState.players = g_pUISquirrel->getinteger(sqvm, 4); + serverInfo.maxPlayers = g_pUISquirrel->getinteger(sqvm, 5); + gameState.map = g_pUISquirrel->getstring(sqvm, 6); + gameState.mapDisplayName = g_pUISquirrel->getstring(sqvm, 7); + gameState.playlist = g_pUISquirrel->getstring(sqvm, 8); + gameState.playlistDisplayName = g_pUISquirrel->getstring(sqvm, 9); ReleaseSRWLockExclusive(&gameStateLock); ReleaseSRWLockExclusive(&serverInfoLock); return SQRESULT_NOTNULL; @@ -164,10 +164,10 @@ SQRESULT SQ_UpdateServerInfo(void* sqvm) SQRESULT SQ_UpdateServerInfoBetweenRounds(void* sqvm) { AcquireSRWLockExclusive(&serverInfoLock); - serverInfo.id = g_pClientSquirrel->sq_getstring(sqvm, 1); - serverInfo.name = g_pClientSquirrel->sq_getstring(sqvm, 2); - serverInfo.password = g_pClientSquirrel->sq_getstring(sqvm, 3); - serverInfo.maxPlayers = g_pClientSquirrel->sq_getinteger(sqvm, 4); + serverInfo.id = g_pClientSquirrel->getstring(sqvm, 1); + serverInfo.name = g_pClientSquirrel->getstring(sqvm, 2); + serverInfo.password = g_pClientSquirrel->getstring(sqvm, 3); + serverInfo.maxPlayers = g_pClientSquirrel->getinteger(sqvm, 4); ReleaseSRWLockExclusive(&serverInfoLock); return SQRESULT_NOTNULL; } @@ -176,7 +176,7 @@ SQRESULT SQ_UpdateServerInfoBetweenRounds(void* sqvm) SQRESULT SQ_UpdateTimeInfo(void* sqvm) { AcquireSRWLockExclusive(&serverInfoLock); - serverInfo.endTime = ceil(g_pClientSquirrel->sq_getfloat(sqvm, 1)); + serverInfo.endTime = ceil(g_pClientSquirrel->getfloat(sqvm, 1)); ReleaseSRWLockExclusive(&serverInfoLock); return SQRESULT_NOTNULL; } @@ -185,7 +185,7 @@ SQRESULT SQ_UpdateTimeInfo(void* sqvm) SQRESULT SQ_SetConnected(void* sqvm) { AcquireSRWLockExclusive(&gameStateLock); - gameState.loading = g_pClientSquirrel->sq_getbool(sqvm, 1); + gameState.loading = g_pUISquirrel->getbool(sqvm, 1); ReleaseSRWLockExclusive(&gameStateLock); return SQRESULT_NOTNULL; } diff --git a/NorthstarDedicatedTest/scriptmainmenupromos.cpp b/NorthstarDedicatedTest/scriptmainmenupromos.cpp index 0a49f491..71afc832 100644 --- a/NorthstarDedicatedTest/scriptmainmenupromos.cpp +++ b/NorthstarDedicatedTest/scriptmainmenupromos.cpp @@ -35,7 +35,7 @@ SQRESULT SQ_RequestCustomMainMenuPromos(void* sqvm) // bool function NSHasCustomMainMenuPromoData() SQRESULT SQ_HasCustomMainMenuPromoData(void* sqvm) { - g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bHasMainMenuPromoData); + g_pUISquirrel->pushbool(sqvm, g_MasterServerManager->m_bHasMainMenuPromoData); return SQRESULT_NOTNULL; } @@ -45,83 +45,83 @@ SQRESULT SQ_GetCustomMainMenuPromoData(void* sqvm) if (!g_MasterServerManager->m_bHasMainMenuPromoData) return SQRESULT_NULL; - switch (g_pClientSquirrel->sq_getinteger(sqvm, 1)) + switch (g_pUISquirrel->getinteger(sqvm, 1)) { case eMainMenuPromoDataProperty::newInfoTitle1: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle1.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle1.c_str()); break; } case eMainMenuPromoDataProperty::newInfoTitle2: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle2.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle2.c_str()); break; } case eMainMenuPromoDataProperty::newInfoTitle3: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle3.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle3.c_str()); break; } case eMainMenuPromoDataProperty::largeButtonTitle: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonTitle.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonTitle.c_str()); break; } case eMainMenuPromoDataProperty::largeButtonText: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonText.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonText.c_str()); break; } case eMainMenuPromoDataProperty::largeButtonUrl: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonUrl.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonUrl.c_str()); break; } case eMainMenuPromoDataProperty::largeButtonImageIndex: { - g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonImageIndex); + g_pUISquirrel->pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonImageIndex); break; } case eMainMenuPromoDataProperty::smallButton1Title: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1Title.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1Title.c_str()); break; } case eMainMenuPromoDataProperty::smallButton1Url: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1Url.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1Url.c_str()); break; } case eMainMenuPromoDataProperty::smallButton1ImageIndex: { - g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1ImageIndex); + g_pUISquirrel->pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1ImageIndex); break; } case eMainMenuPromoDataProperty::smallButton2Title: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2Title.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2Title.c_str()); break; } case eMainMenuPromoDataProperty::smallButton2Url: { - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2Url.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2Url.c_str()); break; } case eMainMenuPromoDataProperty::smallButton2ImageIndex: { - g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2ImageIndex); + g_pUISquirrel->pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2ImageIndex); break; } } diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp index df25cd1e..9d55e2be 100644 --- a/NorthstarDedicatedTest/scriptmodmenu.cpp +++ b/NorthstarDedicatedTest/scriptmodmenu.cpp @@ -7,12 +7,12 @@ // array<string> function NSGetModNames() SQRESULT SQ_GetModNames(void* sqvm) { - g_pClientSquirrel->sq_newarray(sqvm, 0); + g_pUISquirrel->newarray(sqvm, 0); for (Mod& mod : g_pModManager->m_loadedMods) { - g_pClientSquirrel->sq_pushstring(sqvm, mod.Name.c_str(), -1); - g_pClientSquirrel->sq_arrayappend(sqvm, -2); + g_pUISquirrel->pushstring(sqvm, mod.Name.c_str()); + g_pUISquirrel->arrayappend(sqvm, -2); } return SQRESULT_NOTNULL; @@ -21,14 +21,14 @@ SQRESULT SQ_GetModNames(void* sqvm) // bool function NSIsModEnabled(string modName) SQRESULT SQ_IsModEnabled(void* sqvm) { - const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); + const SQChar* modName = g_pUISquirrel->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_pClientSquirrel->sq_pushbool(sqvm, mod.Enabled); + g_pUISquirrel->pushbool(sqvm, mod.Enabled); return SQRESULT_NOTNULL; } } @@ -39,8 +39,8 @@ SQRESULT SQ_IsModEnabled(void* sqvm) // void function NSSetModEnabled(string modName, bool enabled) SQRESULT SQ_SetModEnabled(void* sqvm) { - const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); - const SQBool enabled = g_pClientSquirrel->sq_getbool(sqvm, 2); + const SQChar* modName = g_pUISquirrel->getstring(sqvm, 1); + const SQBool enabled = g_pUISquirrel->getbool(sqvm, 2); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_loadedMods) @@ -58,14 +58,14 @@ SQRESULT SQ_SetModEnabled(void* sqvm) // string function NSGetModDescriptionByModName(string modName) SQRESULT SQ_GetModDescription(void* sqvm) { - const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); + const SQChar* modName = g_pUISquirrel->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_pClientSquirrel->sq_pushstring(sqvm, mod.Description.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, mod.Description.c_str()); return SQRESULT_NOTNULL; } } @@ -76,14 +76,14 @@ SQRESULT SQ_GetModDescription(void* sqvm) // string function NSGetModVersionByModName(string modName) SQRESULT SQ_GetModVersion(void* sqvm) { - const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); + const SQChar* modName = g_pUISquirrel->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_pClientSquirrel->sq_pushstring(sqvm, mod.Version.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, mod.Version.c_str()); return SQRESULT_NOTNULL; } } @@ -94,14 +94,14 @@ SQRESULT SQ_GetModVersion(void* sqvm) // string function NSGetModDownloadLinkByModName(string modName) SQRESULT SQ_GetModDownloadLink(void* sqvm) { - const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); + const SQChar* modName = g_pUISquirrel->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_pClientSquirrel->sq_pushstring(sqvm, mod.DownloadLink.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, mod.DownloadLink.c_str()); return SQRESULT_NOTNULL; } } @@ -112,14 +112,14 @@ SQRESULT SQ_GetModDownloadLink(void* sqvm) // int function NSGetModLoadPriority(string modName) SQRESULT SQ_GetModLoadPriority(void* sqvm) { - const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); + const SQChar* modName = g_pUISquirrel->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_pClientSquirrel->sq_pushinteger(sqvm, mod.LoadPriority); + g_pUISquirrel->pushinteger(sqvm, mod.LoadPriority); return SQRESULT_NOTNULL; } } @@ -130,14 +130,14 @@ SQRESULT SQ_GetModLoadPriority(void* sqvm) // bool function NSIsModRequiredOnClient(string modName) SQRESULT SQ_IsModRequiredOnClient(void* sqvm) { - const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); + const SQChar* modName = g_pUISquirrel->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_pClientSquirrel->sq_pushbool(sqvm, mod.RequiredOnClient); + g_pUISquirrel->pushbool(sqvm, mod.RequiredOnClient); return SQRESULT_NOTNULL; } } @@ -148,8 +148,8 @@ SQRESULT SQ_IsModRequiredOnClient(void* sqvm) // array<string> function NSGetModConvarsByModName(string modName) SQRESULT SQ_GetModConvars(void* sqvm) { - const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); - g_pClientSquirrel->sq_newarray(sqvm, 0); + const SQChar* modName = g_pUISquirrel->getstring(sqvm, 1); + g_pUISquirrel->newarray(sqvm, 0); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_loadedMods) @@ -158,8 +158,8 @@ SQRESULT SQ_GetModConvars(void* sqvm) { for (ModConVar* cvar : mod.ConVars) { - g_pClientSquirrel->sq_pushstring(sqvm, cvar->Name.c_str(), -1); - g_pClientSquirrel->sq_arrayappend(sqvm, -2); + g_pUISquirrel->pushstring(sqvm, cvar->Name.c_str()); + g_pUISquirrel->arrayappend(sqvm, -2); } return SQRESULT_NOTNULL; diff --git a/NorthstarDedicatedTest/scriptserverbrowser.cpp b/NorthstarDedicatedTest/scriptserverbrowser.cpp index 86db4308..307af330 100644 --- a/NorthstarDedicatedTest/scriptserverbrowser.cpp +++ b/NorthstarDedicatedTest/scriptserverbrowser.cpp @@ -11,7 +11,7 @@ // bool function NSIsMasterServerAuthenticated() SQRESULT SQ_IsMasterServerAuthenticated(void* sqvm) { - g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bOriginAuthWithMasterServerDone); + g_pUISquirrel->pushbool(sqvm, g_MasterServerManager->m_bOriginAuthWithMasterServerDone); return SQRESULT_NOTNULL; } @@ -25,33 +25,33 @@ SQRESULT SQ_RequestServerList(void* sqvm) // bool function NSIsRequestingServerList() SQRESULT SQ_IsRequestingServerList(void* sqvm) { - g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bScriptRequestingServerList); + g_pUISquirrel->pushbool(sqvm, g_MasterServerManager->m_bScriptRequestingServerList); return SQRESULT_NOTNULL; } // bool function NSMasterServerConnectionSuccessful() SQRESULT SQ_MasterServerConnectionSuccessful(void* sqvm) { - g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bSuccessfullyConnected); + g_pUISquirrel->pushbool(sqvm, g_MasterServerManager->m_bSuccessfullyConnected); return SQRESULT_NOTNULL; } // int function NSGetServerCount() SQRESULT SQ_GetServerCount(void* sqvm) { - g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers.size()); + g_pUISquirrel->pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers.size()); return SQRESULT_NOTNULL; } // string function NSGetServerName( int serverIndex ) SQRESULT SQ_GetServerName(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get name of server index {} when only {} servers are available", serverIndex, @@ -60,19 +60,19 @@ SQRESULT SQ_GetServerName(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].name, -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].name); return SQRESULT_NOTNULL; } // string function NSGetServerDescription( int serverIndex ) SQRESULT SQ_GetServerDescription(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get description of server index {} when only {} servers are available", serverIndex, @@ -81,19 +81,19 @@ SQRESULT SQ_GetServerDescription(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].description.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].description.c_str()); return SQRESULT_NOTNULL; } // string function NSGetServerMap( int serverIndex ) SQRESULT SQ_GetServerMap(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get map of server index {} when only {} servers are available", serverIndex, @@ -102,19 +102,19 @@ SQRESULT SQ_GetServerMap(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].map, -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].map); return SQRESULT_NOTNULL; } // string function NSGetServerPlaylist( int serverIndex ) SQRESULT SQ_GetServerPlaylist(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get playlist of server index {} when only {} servers are available", serverIndex, @@ -123,19 +123,19 @@ SQRESULT SQ_GetServerPlaylist(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].playlist, -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].playlist); return SQRESULT_NOTNULL; } // int function NSGetServerPlayerCount( int serverIndex ) SQRESULT SQ_GetServerPlayerCount(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get playercount of server index {} when only {} servers are available", serverIndex, @@ -144,19 +144,19 @@ SQRESULT SQ_GetServerPlayerCount(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].playerCount); + g_pUISquirrel->pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].playerCount); return SQRESULT_NOTNULL; } // int function NSGetServerMaxPlayerCount( int serverIndex ) SQRESULT SQ_GetServerMaxPlayerCount(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get max playercount of server index {} when only {} servers are available", serverIndex, @@ -165,19 +165,19 @@ SQRESULT SQ_GetServerMaxPlayerCount(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].maxPlayers); + g_pUISquirrel->pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].maxPlayers); return SQRESULT_NOTNULL; } // string function NSGetServerID( int serverIndex ) SQRESULT SQ_GetServerID(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get id of server index {} when only {} servers are available", serverIndex, @@ -186,19 +186,19 @@ SQRESULT SQ_GetServerID(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].id, -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].id); return SQRESULT_NOTNULL; } // bool function NSServerRequiresPassword( int serverIndex ) SQRESULT SQ_ServerRequiresPassword(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get hasPassword of server index {} when only {} servers are available", serverIndex, @@ -207,19 +207,19 @@ SQRESULT SQ_ServerRequiresPassword(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiresPassword); + g_pUISquirrel->pushbool(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiresPassword); return SQRESULT_NOTNULL; } // int function NSGetServerRequiredModsCount( int serverIndex ) SQRESULT SQ_GetServerRequiredModsCount(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get required mods count of server index {} when only {} servers are available", serverIndex, @@ -228,20 +228,20 @@ SQRESULT SQ_GetServerRequiredModsCount(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()); + g_pUISquirrel->pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()); return SQRESULT_NOTNULL; } // string function NSGetServerRequiredModName( int serverIndex, int modIndex ) SQRESULT SQ_GetServerRequiredModName(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); - SQInteger modIndex = g_pClientSquirrel->sq_getinteger(sqvm, 2); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); + SQInteger modIndex = g_pUISquirrel->getinteger(sqvm, 2); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get hasPassword of server index {} when only {} servers are available", serverIndex, @@ -252,8 +252,8 @@ SQRESULT SQ_GetServerRequiredModName(void* sqvm) if (modIndex >= g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get required mod name of mod index {} when only {} mod are available", modIndex, @@ -262,20 +262,20 @@ SQRESULT SQ_GetServerRequiredModName(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Name.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Name.c_str()); return SQRESULT_NOTNULL; } // string function NSGetServerRequiredModVersion( int serverIndex, int modIndex ) SQRESULT SQ_GetServerRequiredModVersion(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); - SQInteger modIndex = g_pClientSquirrel->sq_getinteger(sqvm, 2); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); + SQInteger modIndex = g_pUISquirrel->getinteger(sqvm, 2); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get required mod version of server index {} when only {} servers are available", serverIndex, @@ -286,8 +286,8 @@ SQRESULT SQ_GetServerRequiredModVersion(void* sqvm) if (modIndex >= g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to get required mod version of mod index {} when only {} mod are available", modIndex, @@ -296,7 +296,7 @@ SQRESULT SQ_GetServerRequiredModVersion(void* sqvm) return SQRESULT_ERROR; } - g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Version.c_str(), -1); + g_pUISquirrel->pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Version.c_str()); return SQRESULT_NOTNULL; } @@ -312,13 +312,13 @@ SQRESULT SQ_ClearRecievedServerList(void* sqvm) // void function NSTryAuthWithServer( int serverIndex, string password = "" ) SQRESULT SQ_TryAuthWithServer(void* sqvm) { - SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); - const SQChar* password = g_pClientSquirrel->sq_getstring(sqvm, 2); + SQInteger serverIndex = g_pUISquirrel->getinteger(sqvm, 1); + const SQChar* password = g_pUISquirrel->getstring(sqvm, 2); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_pClientSquirrel->sq_raiseerror( - sqvm, + g_pUISquirrel->raiseerror( + sqvm, fmt::format( "Tried to auth with server index {} when only {} servers are available", serverIndex, @@ -345,14 +345,14 @@ SQRESULT SQ_TryAuthWithServer(void* sqvm) // bool function NSIsAuthenticatingWithServer() SQRESULT SQ_IsAuthComplete(void* sqvm) { - g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bScriptAuthenticatingWithGameServer); + g_pUISquirrel->pushbool(sqvm, g_MasterServerManager->m_bScriptAuthenticatingWithGameServer); return SQRESULT_NOTNULL; } // bool function NSWasAuthSuccessful() SQRESULT SQ_WasAuthSuccessful(void* sqvm) { - g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bSuccessfullyAuthenticatedWithGameServer); + g_pUISquirrel->pushbool(sqvm, g_MasterServerManager->m_bSuccessfullyAuthenticatedWithGameServer); return SQRESULT_NOTNULL; } @@ -361,7 +361,8 @@ SQRESULT SQ_ConnectToAuthedServer(void* sqvm) { if (!g_MasterServerManager->m_bHasPendingConnectionInfo) { - g_pClientSquirrel->sq_raiseerror(sqvm, fmt::format("Tried to connect to authed server before any pending connection info was available").c_str()); + g_pUISquirrel->raiseerror( + sqvm, fmt::format("Tried to connect to authed server before any pending connection info was available").c_str()); return SQRESULT_ERROR; } diff --git a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp index 51e42335..c2c87da1 100644 --- a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp +++ b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp @@ -10,8 +10,8 @@ void ConCommand_ns_script_servertoclientstringcommand(const CCommand& arg) if (g_pClientSquirrel->sqvm && g_pClientSquirrel->setupfunc("NSClientCodeCallback_RecievedServerToClientStringCommand") != SQRESULT_ERROR) { - g_pClientSquirrel->pusharg(arg.ArgS()); - g_pClientSquirrel->call(1); // todo: doesn't throw or log errors from within this, probably not great behaviour + g_pClientSquirrel->pushstring(g_pClientSquirrel->sqvm2, arg.ArgS()); + g_pClientSquirrel->call(g_pClientSquirrel->sqvm2, 1); // todo: doesn't throw or log errors from within this, probably not great behaviour } } diff --git a/NorthstarDedicatedTest/serverchathooks.cpp b/NorthstarDedicatedTest/serverchathooks.cpp index 472727c4..b2fd7111 100644 --- a/NorthstarDedicatedTest/serverchathooks.cpp +++ b/NorthstarDedicatedTest/serverchathooks.cpp @@ -79,10 +79,10 @@ static void CServerGameDLL__OnReceivedSayTextMessageHook(CServerGameDLL* self, u if (g_pServerSquirrel->setupfunc("CServerGameDLL_ProcessMessageStartThread") != SQRESULT_ERROR) { - g_pServerSquirrel->pusharg((int)senderPlayerId - 1); - g_pServerSquirrel->pusharg(text); - g_pServerSquirrel->pusharg(isTeam); - g_pServerSquirrel->call(3); + g_pServerSquirrel->pushinteger(g_pServerSquirrel->sqvm2, (int)senderPlayerId - 1); + g_pServerSquirrel->pushstring(g_pServerSquirrel->sqvm2, text); + g_pServerSquirrel->pushbool(g_pServerSquirrel->sqvm2, isTeam); + g_pServerSquirrel->call(g_pServerSquirrel->sqvm2, 3); } else CServerGameDLL__OnReceivedSayTextMessageHookBase(self, senderPlayerId, text, isTeam); @@ -143,9 +143,9 @@ void ChatBroadcastMessage(int fromPlayerIndex, int toPlayerIndex, const char* te // void function NSSendMessage( int playerIndex, string text, bool isTeam ) SQRESULT SQ_SendMessage(void* sqvm) { - int playerIndex = g_pServerSquirrel->sq_getinteger(sqvm, 1); - const char* text = g_pServerSquirrel->sq_getstring(sqvm, 2); - bool isTeam = g_pServerSquirrel->sq_getbool(sqvm, 3); + int playerIndex = g_pServerSquirrel->getinteger(sqvm, 1); + const char* text = g_pServerSquirrel->getstring(sqvm, 2); + bool isTeam = g_pServerSquirrel->getbool(sqvm, 3); ChatSendMessage(playerIndex, text, isTeam); @@ -155,16 +155,16 @@ SQRESULT SQ_SendMessage(void* sqvm) // void function NSBroadcastMessage( int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType ) SQRESULT SQ_BroadcastMessage(void* sqvm) { - int fromPlayerIndex = g_pServerSquirrel->sq_getinteger(sqvm, 1); - int toPlayerIndex = g_pServerSquirrel->sq_getinteger(sqvm, 2); - const char* text = g_pServerSquirrel->sq_getstring(sqvm, 3); - bool isTeam = g_pServerSquirrel->sq_getbool(sqvm, 4); - bool isDead = g_pServerSquirrel->sq_getbool(sqvm, 5); - int messageType = g_pServerSquirrel->sq_getinteger(sqvm, 6); + int fromPlayerIndex = g_pServerSquirrel->getinteger(sqvm, 1); + int toPlayerIndex = g_pServerSquirrel->getinteger(sqvm, 2); + const char* text = g_pServerSquirrel->getstring(sqvm, 3); + bool isTeam = g_pServerSquirrel->getbool(sqvm, 4); + bool isDead = g_pServerSquirrel->getbool(sqvm, 5); + int messageType = g_pServerSquirrel->getinteger(sqvm, 6); if (messageType < 1) { - g_pServerSquirrel->sq_raiseerror(sqvm, fmt::format("Invalid message type {}", messageType).c_str()); + g_pServerSquirrel->raiseerror(sqvm, fmt::format("Invalid message type {}", messageType).c_str()); return SQRESULT_ERROR; } diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index a64095a8..bc474713 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -260,40 +260,40 @@ ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, [](HMODULE baseAd g_pClientSquirrel->RegisterSquirrelFunc = (RegisterSquirrelFuncType)((char*)baseAddress + 0x108E0); g_pUISquirrel->RegisterSquirrelFunc = (RegisterSquirrelFuncType)((char*)baseAddress + 0x108E0); - g_pClientSquirrel->sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); - g_pUISquirrel->sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); - g_pClientSquirrel->sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5860); - g_pUISquirrel->sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5860); - - g_pClientSquirrel->sq_call = (sq_callType)((char*)baseAddress + 0x8650); - g_pUISquirrel->sq_call = (sq_callType)((char*)baseAddress + 0x8650); - - g_pClientSquirrel->sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); - g_pUISquirrel->sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); - g_pClientSquirrel->sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); - g_pUISquirrel->sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); - - g_pClientSquirrel->sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); - g_pUISquirrel->sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); - g_pClientSquirrel->sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); - g_pUISquirrel->sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); - g_pClientSquirrel->sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); - g_pUISquirrel->sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); - g_pClientSquirrel->sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); - g_pUISquirrel->sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); - g_pClientSquirrel->sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8470); - g_pUISquirrel->sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8470); - - g_pClientSquirrel->sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60C0); - g_pUISquirrel->sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60C0); - g_pClientSquirrel->sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60E0); - g_pUISquirrel->sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60E0); - g_pClientSquirrel->sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x6100); - g_pUISquirrel->sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x6100); - g_pClientSquirrel->sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6130); - g_pUISquirrel->sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6130); - g_pClientSquirrel->sq_get = (sq_getType)((char*)baseAddress + 0x7C30); - g_pUISquirrel->sq_get = (sq_getType)((char*)baseAddress + 0x7C30); + g_pClientSquirrel->__sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); + g_pUISquirrel->__sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); + g_pClientSquirrel->__sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5860); + g_pUISquirrel->__sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5860); + + g_pClientSquirrel->__sq_call = (sq_callType)((char*)baseAddress + 0x8650); + g_pUISquirrel->__sq_call = (sq_callType)((char*)baseAddress + 0x8650); + + g_pClientSquirrel->__sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); + g_pUISquirrel->__sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); + g_pClientSquirrel->__sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); + g_pUISquirrel->__sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); + + g_pClientSquirrel->__sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); + g_pUISquirrel->__sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); + g_pClientSquirrel->__sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); + g_pUISquirrel->__sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); + g_pClientSquirrel->__sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); + g_pUISquirrel->__sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); + g_pClientSquirrel->__sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); + g_pUISquirrel->__sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); + g_pClientSquirrel->__sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8470); + g_pUISquirrel->__sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8470); + + g_pClientSquirrel->__sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60C0); + g_pUISquirrel->__sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60C0); + g_pClientSquirrel->__sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60E0); + g_pUISquirrel->__sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60E0); + g_pClientSquirrel->__sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x6100); + g_pUISquirrel->__sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x6100); + g_pClientSquirrel->__sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6130); + g_pUISquirrel->__sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6130); + g_pClientSquirrel->__sq_get = (sq_getType)((char*)baseAddress + 0x7C30); + g_pUISquirrel->__sq_get = (sq_getType)((char*)baseAddress + 0x7C30); // uiscript_reset concommand: don't loop forever if compilation fails NSMem::NOP((uintptr_t)baseAddress + 0x3C6E4C, 6); @@ -326,24 +326,24 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, [](HMODULE baseAd g_pServerSquirrel->RegisterSquirrelFunc = (RegisterSquirrelFuncType)((char*)baseAddress + 0x1DD10); - g_pServerSquirrel->sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); - g_pServerSquirrel->sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5840); - g_pServerSquirrel->sq_call = (sq_callType)((char*)baseAddress + 0x8620); + g_pServerSquirrel->__sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); + g_pServerSquirrel->__sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5840); + g_pServerSquirrel->__sq_call = (sq_callType)((char*)baseAddress + 0x8620); - g_pServerSquirrel->sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); - g_pServerSquirrel->sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); + g_pServerSquirrel->__sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); + g_pServerSquirrel->__sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); - g_pServerSquirrel->sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); - g_pServerSquirrel->sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); - g_pServerSquirrel->sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); - g_pServerSquirrel->sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); - g_pServerSquirrel->sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8440); + g_pServerSquirrel->__sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); + g_pServerSquirrel->__sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); + g_pServerSquirrel->__sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); + g_pServerSquirrel->__sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); + g_pServerSquirrel->__sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8440); - g_pServerSquirrel->sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60A0); - g_pServerSquirrel->sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60C0); - g_pServerSquirrel->sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x60E0); - g_pServerSquirrel->sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6110); - g_pServerSquirrel->sq_get = (sq_getType)((char*)baseAddress + 0x7C00); + g_pServerSquirrel->__sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60A0); + g_pServerSquirrel->__sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60C0); + g_pServerSquirrel->__sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x60E0); + g_pServerSquirrel->__sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6110); + g_pServerSquirrel->__sq_get = (sq_getType)((char*)baseAddress + 0x7C00); HookEnabler hook; ENABLER_CREATEHOOK( diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h index cb46ac87..c654a599 100644 --- a/NorthstarDedicatedTest/squirrel.h +++ b/NorthstarDedicatedTest/squirrel.h @@ -100,25 +100,28 @@ template <ScriptContext context> class SquirrelManager public: void* sqvm; void* sqvm2; + #pragma region SQVM funcs RegisterSquirrelFuncType RegisterSquirrelFunc; - sq_compilebufferType sq_compilebuffer; - sq_callType sq_call; - sq_newarrayType sq_newarray; - sq_arrayappendType sq_arrayappend; - sq_pushroottableType sq_pushroottable; - sq_pushstringType sq_pushstring; - sq_pushintegerType sq_pushinteger; - sq_pushfloatType sq_pushfloat; - sq_pushboolType sq_pushbool; - sq_raiseerrorType sq_raiseerror; - - sq_getstringType sq_getstring; - sq_getintegerType sq_getinteger; - sq_getfloatType sq_getfloat; - sq_getboolType sq_getbool; - sq_getType sq_get; + sq_compilebufferType __sq_compilebuffer; + sq_callType __sq_call; + sq_raiseerrorType __sq_raiseerror; + + sq_newarrayType __sq_newarray; + sq_arrayappendType __sq_arrayappend; + + sq_pushroottableType __sq_pushroottable; + sq_pushstringType __sq_pushstring; + sq_pushintegerType __sq_pushinteger; + sq_pushfloatType __sq_pushfloat; + sq_pushboolType __sq_pushbool; + + sq_getstringType __sq_getstring; + sq_getintegerType __sq_getinteger; + sq_getfloatType __sq_getfloat; + sq_getboolType __sq_getbool; + sq_getType __sq_get; #pragma endregion public: @@ -154,74 +157,126 @@ template <ScriptContext context> class SquirrelManager std::string strCode(code); CompileBufferState bufferState = CompileBufferState(strCode); - SQRESULT compileResult = sq_compilebuffer(sqvm2, &bufferState, "console", -1, context); + SQRESULT compileResult = compilebuffer(&bufferState, "console"); spdlog::info("sq_compilebuffer returned {}", compileResult); - if (compileResult >= 0) + if (compileResult != SQRESULT_ERROR) { - sq_pushroottable(sqvm2); - SQRESULT callResult = sq_call(sqvm2, 1, false, false); + pushroottable(sqvm2); + SQRESULT callResult = call(sqvm2, 1); spdlog::info("sq_call returned {}", callResult); } } - int setupfunc(const char* funcname) + void AddFuncRegistration(std::string returnType, std::string name, std::string argTypes, std::string helpText, SQFunction func) { - sq_pushroottable(sqvm2); - sq_pushstring(sqvm2, funcname, -1); + SQFuncRegistration* reg = new SQFuncRegistration; + + reg->squirrelFuncName = new char[name.size() + 1]; + strcpy((char*)reg->squirrelFuncName, name.c_str()); + reg->cppFuncName = reg->squirrelFuncName; + + reg->helpText = new char[helpText.size() + 1]; + strcpy((char*)reg->helpText, helpText.c_str()); + + reg->returnValueType = new char[returnType.size() + 1]; + strcpy((char*)reg->returnValueType, returnType.c_str()); - int result = sq_get(sqvm2, -2); + reg->argTypes = new char[argTypes.size() + 1]; + strcpy((char*)reg->argTypes, argTypes.c_str()); + + reg->funcPtr = func; + + m_funcRegistrations.push_back(reg); + } + + SQRESULT setupfunc(const SQChar* funcname) + { + pushroottable(sqvm2); + pushstring(sqvm2, funcname, -1); + + SQRESULT result = get(sqvm2, -2); if (result != SQRESULT_ERROR) - sq_pushroottable(sqvm2); + pushroottable(sqvm2); return result; } - void pusharg(int arg) + #pragma region SQVM func wrappers + SQRESULT compilebuffer(CompileBufferState* bufferState, const SQChar* bufferName = "unnamedbuffer") { - sq_pushinteger(sqvm2, arg); + return __sq_compilebuffer(sqvm2, bufferState, bufferName, -1, context); } - void pusharg(const char* arg) + SQRESULT call(void* sqvm, const SQInteger args) { - sq_pushstring(sqvm2, arg, -1); + return __sq_call(sqvm, args + 1, false, false); } - void pusharg(float arg) + SQInteger raiseerror(void* sqvm, const const SQChar* sError) { - sq_pushfloat(sqvm2, arg); + return __sq_raiseerror(sqvm, sError); } - void pusharg(bool arg) + void newarray(void* sqvm, const SQInteger stackpos = 0) { - sq_pushbool(sqvm2, arg); + __sq_newarray(sqvm, stackpos); } - int call(int args) + SQRESULT arrayappend(void* sqvm, const SQInteger stackpos) { - return sq_call(sqvm2, args + 1, false, false); + return __sq_arrayappend(sqvm, stackpos); } - void AddFuncRegistration(std::string returnType, std::string name, std::string argTypes, std::string helpText, SQFunction func) + void pushroottable(void* sqvm) { - SQFuncRegistration* reg = new SQFuncRegistration; + __sq_pushroottable(sqvm); + } - reg->squirrelFuncName = new char[name.size() + 1]; - strcpy((char*)reg->squirrelFuncName, name.c_str()); - reg->cppFuncName = reg->squirrelFuncName; + void pushstring(void* sqvm, const SQChar* sVal, int length = -1) + { + __sq_pushstring(sqvm, sVal, length); + } - reg->helpText = new char[helpText.size() + 1]; - strcpy((char*)reg->helpText, helpText.c_str()); + void pushinteger(void* sqvm, const SQInteger iVal) + { + __sq_pushinteger(sqvm, iVal); + } - reg->returnValueType = new char[returnType.size() + 1]; - strcpy((char*)reg->returnValueType, returnType.c_str()); + void pushfloat(void* sqvm, const SQFloat flVal) + { + __sq_pushfloat(sqvm, flVal); + } - reg->argTypes = new char[argTypes.size() + 1]; - strcpy((char*)reg->argTypes, argTypes.c_str()); + void pushbool(void* sqvm, const SQBool bVal) + { + __sq_pushbool(sqvm, bVal); + } - reg->funcPtr = func; + const SQChar* getstring(void* sqvm, const SQInteger stackpos) + { + return __sq_getstring(sqvm, stackpos); + } - m_funcRegistrations.push_back(reg); + SQInteger getinteger(void* sqvm, const SQInteger stackpos) + { + return __sq_getinteger(sqvm, stackpos); + } + + SQFloat getfloat(void* sqvm, const SQInteger stackpos) + { + return __sq_getfloat(sqvm, stackpos); } + + SQBool getbool(void* sqvm, const SQInteger stackpos) + { + return __sq_getbool(sqvm, stackpos); + } + + SQRESULT get(void* sqvm, const SQInteger stackpos) + { + return __sq_get(sqvm, stackpos); + } + #pragma endregion }; extern SquirrelManager<ScriptContext::CLIENT>* g_pClientSquirrel; |