diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-05-09 16:42:33 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-05-09 16:42:33 +0100 |
commit | 5a58dd1c05e943d6b440bea5b4a6ae80ce16841e (patch) | |
tree | 9ea18142c2e2885b990671c04db4786aa05f86f3 /NorthstarDedicatedTest | |
parent | 77a1195d77034c00959dfd030e2eb7a57d58a88d (diff) | |
download | NorthstarLauncher-5a58dd1c05e943d6b440bea5b4a6ae80ce16841e.tar.gz NorthstarLauncher-5a58dd1c05e943d6b440bea5b4a6ae80ce16841e.zip |
refactor some squirrel stuff and ingame compilation error message
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r-- | NorthstarDedicatedTest/clientchathooks.cpp | 32 | ||||
-rw-r--r-- | NorthstarDedicatedTest/masterserver.cpp | 33 | ||||
-rw-r--r-- | NorthstarDedicatedTest/misccommands.cpp | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/miscserverscript.cpp | 18 | ||||
-rw-r--r-- | NorthstarDedicatedTest/plugins.cpp | 72 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptmainmenupromos.cpp | 36 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptmodmenu.cpp | 62 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptserverbrowser.cpp | 142 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp | 8 | ||||
-rw-r--r-- | NorthstarDedicatedTest/serverchathooks.cpp | 34 | ||||
-rw-r--r-- | NorthstarDedicatedTest/sourceinterface.cpp | 18 | ||||
-rw-r--r-- | NorthstarDedicatedTest/squirrel.cpp | 526 | ||||
-rw-r--r-- | NorthstarDedicatedTest/squirrel.h | 17 |
13 files changed, 453 insertions, 547 deletions
diff --git a/NorthstarDedicatedTest/clientchathooks.cpp b/NorthstarDedicatedTest/clientchathooks.cpp index b6cf56ac..d666072e 100644 --- a/NorthstarDedicatedTest/clientchathooks.cpp +++ b/NorthstarDedicatedTest/clientchathooks.cpp @@ -24,7 +24,7 @@ static void CHudChat__AddGameLineHook(void* self, const char* message, int inbox return; } - if (g_ClientSquirrelManager->setupfunc("CHudChat_ProcessMessageStartThread") != SQRESULT_ERROR) + if (g_pClientSquirrel->setupfunc("CHudChat_ProcessMessageStartThread") != SQRESULT_ERROR) { int senderId = inboxId & CUSTOM_MESSAGE_INDEX_MASK; bool isAnonymous = senderId == 0; @@ -39,12 +39,12 @@ static void CHudChat__AddGameLineHook(void* self, const char* message, int inbox payload = message + 1; } - g_ClientSquirrelManager->pusharg((int)senderId - 1); - g_ClientSquirrelManager->pusharg(payload); - g_ClientSquirrelManager->pusharg(isTeam); - g_ClientSquirrelManager->pusharg(isDead); - g_ClientSquirrelManager->pusharg(type); - g_ClientSquirrelManager->call(5); + 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); } else { @@ -58,8 +58,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_ClientSquirrelManager->sq_getinteger(sqvm, 1); - const char* str = g_ClientSquirrelManager->sq_getstring(sqvm, 2); + int context = g_pClientSquirrel->sq_getinteger(sqvm, 1); + const char* str = g_pClientSquirrel->sq_getstring(sqvm, 2); LocalChatWriter((LocalChatWriter::Context)context).Write(str); return SQRESULT_NOTNULL; @@ -68,8 +68,8 @@ static SQRESULT SQ_ChatWrite(void* sqvm) // void NSChatWriteRaw( int context, string str ) static SQRESULT SQ_ChatWriteRaw(void* sqvm) { - int context = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); - const char* str = g_ClientSquirrelManager->sq_getstring(sqvm, 2); + int context = g_pClientSquirrel->sq_getinteger(sqvm, 1); + const char* str = g_pClientSquirrel->sq_getstring(sqvm, 2); LocalChatWriter((LocalChatWriter::Context)context).InsertText(str); return SQRESULT_NOTNULL; @@ -78,8 +78,8 @@ static SQRESULT SQ_ChatWriteRaw(void* sqvm) // void NSChatWriteLine( int context, string str ) static SQRESULT SQ_ChatWriteLine(void* sqvm) { - int context = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); - const char* str = g_ClientSquirrelManager->sq_getstring(sqvm, 2); + int context = g_pClientSquirrel->sq_getinteger(sqvm, 1); + const char* str = g_pClientSquirrel->sq_getstring(sqvm, 2); LocalChatWriter((LocalChatWriter::Context)context).WriteLine(str); return SQRESULT_NOTNULL; @@ -90,7 +90,7 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientChatHooks, ClientSquirrel, (HMOD HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x22E580, &CHudChat__AddGameLineHook, reinterpret_cast<LPVOID*>(&CHudChat__AddGameLine)); - g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWrite", "int context, string text", "", SQ_ChatWrite); - g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWriteRaw", "int context, string text", "", SQ_ChatWriteRaw); - g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWriteLine", "int context, string text", "", SQ_ChatWriteLine); + g_pClientSquirrel->AddFuncRegistration("void", "NSChatWrite", "int context, string text", "", SQ_ChatWrite); + g_pClientSquirrel->AddFuncRegistration("void", "NSChatWriteRaw", "int context, string text", "", SQ_ChatWriteRaw); + g_pClientSquirrel->AddFuncRegistration("void", "NSChatWriteLine", "int context, string text", "", SQ_ChatWriteLine); }) diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index 287b9e99..9c78c71a 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -113,39 +113,6 @@ void UpdateServerInfoFromUnicodeToUTF8() g_MasterServerManager->m_sUnicodeServerDesc = unescape_unicode(Cvar_ns_server_desc->GetString()); } -const char* HttplibErrorToString(httplib::Error error) -{ - switch (error) - { - case httplib::Error::Success: - return "httplib::Error::Success"; - case httplib::Error::Unknown: - return "httplib::Error::Unknown"; - case httplib::Error::Connection: - return "httplib::Error::Connection"; - case httplib::Error::BindIPAddress: - return "httplib::Error::BindIPAddress"; - case httplib::Error::Read: - return "httplib::Error::Read"; - case httplib::Error::Write: - return "httplib::Error::Write"; - case httplib::Error::ExceedRedirectCount: - return "httplib::Error::ExceedRedirectCount"; - case httplib::Error::Canceled: - return "httplib::Error::Canceled"; - case httplib::Error::SSLConnection: - return "httplib::Error::SSLConnection"; - case httplib::Error::SSLLoadingCerts: - return "httplib::Error::SSLLoadingCerts"; - case httplib::Error::SSLServerVerification: - return "httplib::Error::SSLServerVerification"; - case httplib::Error::UnsupportedMultipartBoundaryChars: - return "httplib::Error::UnsupportedMultipartBoundaryChars"; - } - - return ""; -} - RemoteServerInfo::RemoteServerInfo( const char* newId, const char* newName, diff --git a/NorthstarDedicatedTest/misccommands.cpp b/NorthstarDedicatedTest/misccommands.cpp index 0c7de684..00a32c48 100644 --- a/NorthstarDedicatedTest/misccommands.cpp +++ b/NorthstarDedicatedTest/misccommands.cpp @@ -46,7 +46,7 @@ void AddMiscConCommands() Cbuf_Execute(); // weird way of checking, but check if client script vm is initialised, mainly just to allow players to cancel this - if (g_ClientSquirrelManager->sqvm) + if (g_pClientSquirrel->sqvm) { g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = true; diff --git a/NorthstarDedicatedTest/miscserverscript.cpp b/NorthstarDedicatedTest/miscserverscript.cpp index 3c32ad1c..5d346b2a 100644 --- a/NorthstarDedicatedTest/miscserverscript.cpp +++ b/NorthstarDedicatedTest/miscserverscript.cpp @@ -22,12 +22,12 @@ void* GetPlayerByIndex(int playerIndex) // void function NSEarlyWritePlayerIndexPersistenceForLeave( int playerIndex ) SQRESULT SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm) { - int playerIndex = g_ServerSquirrelManager->sq_getinteger(sqvm, 1); + int playerIndex = g_pServerSquirrel->sq_getinteger(sqvm, 1); void* player = GetPlayerByIndex(playerIndex); if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player)) { - g_ServerSquirrelManager->sq_raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); + g_pServerSquirrel->sq_raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); return SQRESULT_ERROR; } @@ -39,29 +39,29 @@ SQRESULT SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm) // bool function NSIsWritingPlayerPersistence() SQRESULT SQ_IsWritingPlayerPersistence(void* sqvm) { - g_ServerSquirrelManager->sq_pushbool(sqvm, g_MasterServerManager->m_bSavingPersistentData); + g_pServerSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bSavingPersistentData); return SQRESULT_NOTNULL; } // bool function NSIsPlayerIndexLocalPlayer( int playerIndex ) SQRESULT SQ_IsPlayerIndexLocalPlayer(void* sqvm) { - int playerIndex = g_ServerSquirrelManager->sq_getinteger(sqvm, 1); + int playerIndex = g_pServerSquirrel->sq_getinteger(sqvm, 1); void* player = GetPlayerByIndex(playerIndex); if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player)) { - g_ServerSquirrelManager->sq_raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); + g_pServerSquirrel->sq_raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); return SQRESULT_ERROR; } - g_ServerSquirrelManager->sq_pushbool(sqvm, !strcmp(g_LocalPlayerUserID, (char*)player + 0xF500)); + g_pServerSquirrel->sq_pushbool(sqvm, !strcmp(g_LocalPlayerUserID, (char*)player + 0xF500)); return SQRESULT_NOTNULL; } ON_DLL_LOAD_RELIESON("server.dll", MiscServerScriptCommands, ServerSquirrel, (HMODULE baseAddress) { - g_ServerSquirrelManager->AddFuncRegistration( + g_pServerSquirrel->AddFuncRegistration( "void", "NSEarlyWritePlayerIndexPersistenceForLeave", "int playerIndex", "", SQ_EarlyWritePlayerIndexPersistenceForLeave); - g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence); - g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsPlayerIndexLocalPlayer", "int playerIndex", "", SQ_IsPlayerIndexLocalPlayer); + g_pServerSquirrel->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence); + g_pServerSquirrel->AddFuncRegistration("bool", "NSIsPlayerIndexLocalPlayer", "int playerIndex", "", SQ_IsPlayerIndexLocalPlayer); })
\ No newline at end of file diff --git a/NorthstarDedicatedTest/plugins.cpp b/NorthstarDedicatedTest/plugins.cpp index b77b4ef4..ae651d09 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_ClientSquirrelManager->sq_getstring(sqvm, 1); - gameState.mapDisplayName = g_ClientSquirrelManager->sq_getstring(sqvm, 2); - gameState.playlist = g_ClientSquirrelManager->sq_getstring(sqvm, 3); - gameState.playlistDisplayName = g_ClientSquirrelManager->sq_getstring(sqvm, 4); - gameState.connected = g_ClientSquirrelManager->sq_getbool(sqvm, 5); - gameState.loading = g_ClientSquirrelManager->sq_getbool(sqvm, 6); + 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); ReleaseSRWLockExclusive(&gameStateLock); return SQRESULT_NOTNULL; } @@ -128,13 +128,13 @@ SQRESULT SQ_UpdateGameStateClient(void* sqvm) { AcquireSRWLockExclusive(&gameStateLock); AcquireSRWLockExclusive(&serverInfoLock); - gameState.players = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); - serverInfo.maxPlayers = g_ClientSquirrelManager->sq_getinteger(sqvm, 2); - gameState.ourScore = g_ClientSquirrelManager->sq_getinteger(sqvm, 3); - gameState.secondHighestScore = g_ClientSquirrelManager->sq_getinteger(sqvm, 4); - gameState.highestScore = g_ClientSquirrelManager->sq_getinteger(sqvm, 5); - serverInfo.roundBased = g_ClientSquirrelManager->sq_getbool(sqvm, 6); - serverInfo.scoreLimit = g_ClientSquirrelManager->sq_getbool(sqvm, 7); + 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); ReleaseSRWLockExclusive(&gameStateLock); ReleaseSRWLockExclusive(&serverInfoLock); return SQRESULT_NOTNULL; @@ -146,15 +146,15 @@ SQRESULT SQ_UpdateServerInfo(void* sqvm) { AcquireSRWLockExclusive(&gameStateLock); AcquireSRWLockExclusive(&serverInfoLock); - serverInfo.id = g_ClientSquirrelManager->sq_getstring(sqvm, 1); - serverInfo.name = g_ClientSquirrelManager->sq_getstring(sqvm, 2); - serverInfo.password = g_ClientSquirrelManager->sq_getstring(sqvm, 3); - gameState.players = g_ClientSquirrelManager->sq_getinteger(sqvm, 4); - serverInfo.maxPlayers = g_ClientSquirrelManager->sq_getinteger(sqvm, 5); - gameState.map = g_ClientSquirrelManager->sq_getstring(sqvm, 6); - gameState.mapDisplayName = g_ClientSquirrelManager->sq_getstring(sqvm, 7); - gameState.playlist = g_ClientSquirrelManager->sq_getstring(sqvm, 8); - gameState.playlistDisplayName = g_ClientSquirrelManager->sq_getstring(sqvm, 9); + 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); 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_ClientSquirrelManager->sq_getstring(sqvm, 1); - serverInfo.name = g_ClientSquirrelManager->sq_getstring(sqvm, 2); - serverInfo.password = g_ClientSquirrelManager->sq_getstring(sqvm, 3); - serverInfo.maxPlayers = g_ClientSquirrelManager->sq_getinteger(sqvm, 4); + 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); 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_ClientSquirrelManager->sq_getfloat(sqvm, 1)); + serverInfo.endTime = ceil(g_pClientSquirrel->sq_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_ClientSquirrelManager->sq_getbool(sqvm, 1); + gameState.loading = g_pClientSquirrel->sq_getbool(sqvm, 1); ReleaseSRWLockExclusive(&gameStateLock); return SQRESULT_NOTNULL; } @@ -390,21 +390,21 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", PluginCommands, ClientSquirrel, (HMODU // i swear there's a way to make this not have be run in 2 contexts but i can't figure it out // some funcs i need are just not available in UI or CLIENT - if (g_UISquirrelManager && g_ClientSquirrelManager) + if (g_pUISquirrel && g_pClientSquirrel) { - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "void", "NSUpdateGameStateUI", "string gamemode, string gamemodeName, string map, string mapName, bool connected, bool loading", "", SQ_UpdateGameStateUI); - g_ClientSquirrelManager->AddFuncRegistration( + g_pClientSquirrel->AddFuncRegistration( "void", "NSUpdateGameStateClient", "int playerCount, int maxPlayers, int outScore, int secondHighestScore, int highestScore, bool roundBased, int scoreLimit", "", SQ_UpdateGameStateClient); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "void", "NSUpdateServerInfo", "string id, string name, string password, int players, int maxPlayers, string map, string mapDisplayName, string playlist, " @@ -412,10 +412,10 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", PluginCommands, ClientSquirrel, (HMODU "playlistDisplayName", "", SQ_UpdateServerInfo); - g_ClientSquirrelManager->AddFuncRegistration( + g_pClientSquirrel->AddFuncRegistration( "void", "NSUpdateServerInfoReload", "int maxPlayers", "", SQ_UpdateServerInfoBetweenRounds); - g_ClientSquirrelManager->AddFuncRegistration("void", "NSUpdateTimeInfo", "float timeInFuture", "", SQ_UpdateTimeInfo); - g_UISquirrelManager->AddFuncRegistration("void", "NSSetLoading", "bool loading", "", SQ_SetConnected); - g_UISquirrelManager->AddFuncRegistration("void", "NSUpdateListenServer", "", "", SQ_UpdateListenServer); + g_pClientSquirrel->AddFuncRegistration("void", "NSUpdateTimeInfo", "float timeInFuture", "", SQ_UpdateTimeInfo); + g_pUISquirrel->AddFuncRegistration("void", "NSSetLoading", "bool loading", "", SQ_SetConnected); + g_pUISquirrel->AddFuncRegistration("void", "NSUpdateListenServer", "", "", SQ_UpdateListenServer); } }) diff --git a/NorthstarDedicatedTest/scriptmainmenupromos.cpp b/NorthstarDedicatedTest/scriptmainmenupromos.cpp index 745fe01b..cb398251 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_ClientSquirrelManager->sq_pushbool(sqvm, g_MasterServerManager->m_bHasMainMenuPromoData); + g_pClientSquirrel->sq_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_ClientSquirrelManager->sq_getinteger(sqvm, 1)) + switch (g_pClientSquirrel->sq_getinteger(sqvm, 1)) { case eMainMenuPromoDataProperty::newInfoTitle1: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle1.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle1.c_str(), -1); break; } case eMainMenuPromoDataProperty::newInfoTitle2: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle2.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle2.c_str(), -1); break; } case eMainMenuPromoDataProperty::newInfoTitle3: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle3.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.newInfoTitle3.c_str(), -1); break; } case eMainMenuPromoDataProperty::largeButtonTitle: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonTitle.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonTitle.c_str(), -1); break; } case eMainMenuPromoDataProperty::largeButtonText: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonText.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonText.c_str(), -1); break; } case eMainMenuPromoDataProperty::largeButtonUrl: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonUrl.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonUrl.c_str(), -1); break; } case eMainMenuPromoDataProperty::largeButtonImageIndex: { - g_ClientSquirrelManager->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonImageIndex); + g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.largeButtonImageIndex); break; } case eMainMenuPromoDataProperty::smallButton1Title: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1Title.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1Title.c_str(), -1); break; } case eMainMenuPromoDataProperty::smallButton1Url: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1Url.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1Url.c_str(), -1); break; } case eMainMenuPromoDataProperty::smallButton1ImageIndex: { - g_ClientSquirrelManager->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1ImageIndex); + g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton1ImageIndex); break; } case eMainMenuPromoDataProperty::smallButton2Title: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2Title.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2Title.c_str(), -1); break; } case eMainMenuPromoDataProperty::smallButton2Url: { - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2Url.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2Url.c_str(), -1); break; } case eMainMenuPromoDataProperty::smallButton2ImageIndex: { - g_ClientSquirrelManager->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2ImageIndex); + g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_sMainMenuPromoData.smallButton2ImageIndex); break; } } @@ -131,7 +131,7 @@ SQRESULT SQ_GetCustomMainMenuPromoData(void* sqvm) ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptMainMenuPrograms, ClientSquirrel, (HMODULE baseAddress) { - g_UISquirrelManager->AddFuncRegistration("void", "NSRequestCustomMainMenuPromos", "", "", SQ_RequestCustomMainMenuPromos); - g_UISquirrelManager->AddFuncRegistration("bool", "NSHasCustomMainMenuPromoData", "", "", SQ_HasCustomMainMenuPromoData); - g_UISquirrelManager->AddFuncRegistration("var", "NSGetCustomMainMenuPromoData", "int promoDataKey", "", SQ_GetCustomMainMenuPromoData); + g_pUISquirrel->AddFuncRegistration("void", "NSRequestCustomMainMenuPromos", "", "", SQ_RequestCustomMainMenuPromos); + g_pUISquirrel->AddFuncRegistration("bool", "NSHasCustomMainMenuPromoData", "", "", SQ_HasCustomMainMenuPromoData); + g_pUISquirrel->AddFuncRegistration("var", "NSGetCustomMainMenuPromoData", "int promoDataKey", "", SQ_GetCustomMainMenuPromoData); })
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp index c31f24cf..e27634f2 100644 --- a/NorthstarDedicatedTest/scriptmodmenu.cpp +++ b/NorthstarDedicatedTest/scriptmodmenu.cpp @@ -7,12 +7,12 @@ // array<string> function NSGetModNames() SQRESULT SQ_GetModNames(void* sqvm) { - g_ClientSquirrelManager->sq_newarray(sqvm, 0); + g_pClientSquirrel->sq_newarray(sqvm, 0); for (Mod& mod : g_ModManager->m_loadedMods) { - g_ClientSquirrelManager->sq_pushstring(sqvm, mod.Name.c_str(), -1); - g_ClientSquirrelManager->sq_arrayappend(sqvm, -2); + g_pClientSquirrel->sq_pushstring(sqvm, mod.Name.c_str(), -1); + g_pClientSquirrel->sq_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_ClientSquirrelManager->sq_getstring(sqvm, 1); + const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_ClientSquirrelManager->sq_pushbool(sqvm, mod.Enabled); + g_pClientSquirrel->sq_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_ClientSquirrelManager->sq_getstring(sqvm, 1); - const SQBool enabled = g_ClientSquirrelManager->sq_getbool(sqvm, 2); + const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); + const SQBool enabled = g_pClientSquirrel->sq_getbool(sqvm, 2); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_ModManager->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_ClientSquirrelManager->sq_getstring(sqvm, 1); + const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_ClientSquirrelManager->sq_pushstring(sqvm, mod.Description.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, mod.Description.c_str(), -1); 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_ClientSquirrelManager->sq_getstring(sqvm, 1); + const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_ClientSquirrelManager->sq_pushstring(sqvm, mod.Version.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, mod.Version.c_str(), -1); 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_ClientSquirrelManager->sq_getstring(sqvm, 1); + const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_ClientSquirrelManager->sq_pushstring(sqvm, mod.DownloadLink.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, mod.DownloadLink.c_str(), -1); 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_ClientSquirrelManager->sq_getstring(sqvm, 1); + const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_ClientSquirrelManager->sq_pushinteger(sqvm, mod.LoadPriority); + g_pClientSquirrel->sq_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_ClientSquirrelManager->sq_getstring(sqvm, 1); + const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { - g_ClientSquirrelManager->sq_pushbool(sqvm, mod.RequiredOnClient); + g_pClientSquirrel->sq_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_ClientSquirrelManager->sq_getstring(sqvm, 1); - g_ClientSquirrelManager->sq_newarray(sqvm, 0); + const SQChar* modName = g_pClientSquirrel->sq_getstring(sqvm, 1); + g_pClientSquirrel->sq_newarray(sqvm, 0); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_ModManager->m_loadedMods) @@ -158,8 +158,8 @@ SQRESULT SQ_GetModConvars(void* sqvm) { for (ModConVar* cvar : mod.ConVars) { - g_ClientSquirrelManager->sq_pushstring(sqvm, cvar->Name.c_str(), -1); - g_ClientSquirrelManager->sq_arrayappend(sqvm, -2); + g_pClientSquirrel->sq_pushstring(sqvm, cvar->Name.c_str(), -1); + g_pClientSquirrel->sq_arrayappend(sqvm, -2); } return SQRESULT_NOTNULL; @@ -178,27 +178,27 @@ SQRESULT SQ_ReloadMods(void* sqvm) ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptModMenu, ClientSquirrel, (HMODULE baseAddress) { - g_UISquirrelManager->AddFuncRegistration("array<string>", "NSGetModNames", "", "Returns the names of all loaded mods", SQ_GetModNames); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration("array<string>", "NSGetModNames", "", "Returns the names of all loaded mods", SQ_GetModNames); + g_pUISquirrel->AddFuncRegistration( "bool", "NSIsModEnabled", "string modName", "Returns whether a given mod is enabled", SQ_IsModEnabled); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "void", "NSSetModEnabled", "string modName, bool enabled", "Sets whether a given mod is enabled", SQ_SetModEnabled); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "string", "NSGetModDescriptionByModName", "string modName", "Returns a given mod's description", SQ_GetModDescription); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "string", "NSGetModVersionByModName", "string modName", "Returns a given mod's version", SQ_GetModVersion); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "string", "NSGetModDownloadLinkByModName", "string modName", "Returns a given mod's download link", SQ_GetModDownloadLink); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "bool", "NSIsModRequiredOnClient", "string modName", "Returns whether a given mod is required on connecting clients", SQ_IsModRequiredOnClient); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "int", "NSGetModLoadPriority", "string modName", "Returns a given mod's load priority", SQ_GetModLoadPriority); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "array<string>", "NSGetModConvarsByModName", "string modName", "Returns the names of all a given mod's cvars", SQ_GetModConvars); - g_UISquirrelManager->AddFuncRegistration("void", "NSReloadMods", "", "Reloads mods", SQ_ReloadMods); + g_pUISquirrel->AddFuncRegistration("void", "NSReloadMods", "", "Reloads mods", SQ_ReloadMods); })
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptserverbrowser.cpp b/NorthstarDedicatedTest/scriptserverbrowser.cpp index f2d53347..4f2b9bd0 100644 --- a/NorthstarDedicatedTest/scriptserverbrowser.cpp +++ b/NorthstarDedicatedTest/scriptserverbrowser.cpp @@ -11,7 +11,7 @@ // bool function NSIsMasterServerAuthenticated() SQRESULT SQ_IsMasterServerAuthenticated(void* sqvm) { - g_ClientSquirrelManager->sq_pushbool(sqvm, g_MasterServerManager->m_bOriginAuthWithMasterServerDone); + g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bOriginAuthWithMasterServerDone); return SQRESULT_NOTNULL; } @@ -25,32 +25,32 @@ SQRESULT SQ_RequestServerList(void* sqvm) // bool function NSIsRequestingServerList() SQRESULT SQ_IsRequestingServerList(void* sqvm) { - g_ClientSquirrelManager->sq_pushbool(sqvm, g_MasterServerManager->m_bScriptRequestingServerList); + g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bScriptRequestingServerList); return SQRESULT_NOTNULL; } // bool function NSMasterServerConnectionSuccessful() SQRESULT SQ_MasterServerConnectionSuccessful(void* sqvm) { - g_ClientSquirrelManager->sq_pushbool(sqvm, g_MasterServerManager->m_bSuccessfullyConnected); + g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bSuccessfullyConnected); return SQRESULT_NOTNULL; } // int function NSGetServerCount() SQRESULT SQ_GetServerCount(void* sqvm) { - g_ClientSquirrelManager->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers.size()); + g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers.size()); return SQRESULT_NOTNULL; } // string function NSGetServerName( int serverIndex ) SQRESULT SQ_GetServerName(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get name of server index {} when only {} servers are available", @@ -60,18 +60,18 @@ SQRESULT SQ_GetServerName(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].name, -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].name, -1); return SQRESULT_NOTNULL; } // string function NSGetServerDescription( int serverIndex ) SQRESULT SQ_GetServerDescription(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get description of server index {} when only {} servers are available", @@ -81,18 +81,18 @@ SQRESULT SQ_GetServerDescription(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].description.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].description.c_str(), -1); return SQRESULT_NOTNULL; } // string function NSGetServerMap( int serverIndex ) SQRESULT SQ_GetServerMap(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get map of server index {} when only {} servers are available", @@ -102,18 +102,18 @@ SQRESULT SQ_GetServerMap(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].map, -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].map, -1); return SQRESULT_NOTNULL; } // string function NSGetServerPlaylist( int serverIndex ) SQRESULT SQ_GetServerPlaylist(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get playlist of server index {} when only {} servers are available", @@ -123,18 +123,18 @@ SQRESULT SQ_GetServerPlaylist(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].playlist, -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].playlist, -1); return SQRESULT_NOTNULL; } // int function NSGetServerPlayerCount( int serverIndex ) SQRESULT SQ_GetServerPlayerCount(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get playercount of server index {} when only {} servers are available", @@ -144,18 +144,18 @@ SQRESULT SQ_GetServerPlayerCount(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].playerCount); + g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].playerCount); return SQRESULT_NOTNULL; } // int function NSGetServerMaxPlayerCount( int serverIndex ) SQRESULT SQ_GetServerMaxPlayerCount(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get max playercount of server index {} when only {} servers are available", @@ -165,18 +165,18 @@ SQRESULT SQ_GetServerMaxPlayerCount(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].maxPlayers); + g_pClientSquirrel->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].maxPlayers); return SQRESULT_NOTNULL; } // string function NSGetServerID( int serverIndex ) SQRESULT SQ_GetServerID(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get id of server index {} when only {} servers are available", @@ -186,18 +186,18 @@ SQRESULT SQ_GetServerID(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].id, -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].id, -1); return SQRESULT_NOTNULL; } // bool function NSServerRequiresPassword( int serverIndex ) SQRESULT SQ_ServerRequiresPassword(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get hasPassword of server index {} when only {} servers are available", @@ -207,18 +207,18 @@ SQRESULT SQ_ServerRequiresPassword(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushbool(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiresPassword); + g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiresPassword); return SQRESULT_NOTNULL; } // int function NSGetServerRequiredModsCount( int serverIndex ) SQRESULT SQ_GetServerRequiredModsCount(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get required mods count of server index {} when only {} servers are available", @@ -228,19 +228,19 @@ SQRESULT SQ_GetServerRequiredModsCount(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushinteger(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()); + g_pClientSquirrel->sq_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_ClientSquirrelManager->sq_getinteger(sqvm, 1); - SQInteger modIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 2); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger modIndex = g_pClientSquirrel->sq_getinteger(sqvm, 2); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get hasPassword of server index {} when only {} servers are available", @@ -252,7 +252,7 @@ SQRESULT SQ_GetServerRequiredModName(void* sqvm) if (modIndex >= g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get required mod name of mod index {} when only {} mod are available", @@ -262,19 +262,19 @@ SQRESULT SQ_GetServerRequiredModName(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Name.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Name.c_str(), -1); return SQRESULT_NOTNULL; } // string function NSGetServerRequiredModVersion( int serverIndex, int modIndex ) SQRESULT SQ_GetServerRequiredModVersion(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); - SQInteger modIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 2); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + SQInteger modIndex = g_pClientSquirrel->sq_getinteger(sqvm, 2); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get required mod version of server index {} when only {} servers are available", @@ -286,7 +286,7 @@ SQRESULT SQ_GetServerRequiredModVersion(void* sqvm) if (modIndex >= g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to get required mod version of mod index {} when only {} mod are available", @@ -296,7 +296,7 @@ SQRESULT SQ_GetServerRequiredModVersion(void* sqvm) return SQRESULT_ERROR; } - g_ClientSquirrelManager->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Version.c_str(), -1); + g_pClientSquirrel->sq_pushstring(sqvm, g_MasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Version.c_str(), -1); return SQRESULT_NOTNULL; } @@ -312,12 +312,12 @@ SQRESULT SQ_ClearRecievedServerList(void* sqvm) // void function NSTryAuthWithServer( int serverIndex, string password = "" ) SQRESULT SQ_TryAuthWithServer(void* sqvm) { - SQInteger serverIndex = g_ClientSquirrelManager->sq_getinteger(sqvm, 1); - const SQChar* password = g_ClientSquirrelManager->sq_getstring(sqvm, 2); + SQInteger serverIndex = g_pClientSquirrel->sq_getinteger(sqvm, 1); + const SQChar* password = g_pClientSquirrel->sq_getstring(sqvm, 2); if (serverIndex >= g_MasterServerManager->m_vRemoteServers.size()) { - g_ClientSquirrelManager->sq_raiseerror( + g_pClientSquirrel->sq_raiseerror( sqvm, fmt::format( "Tried to auth with server index {} when only {} servers are available", @@ -345,14 +345,14 @@ SQRESULT SQ_TryAuthWithServer(void* sqvm) // bool function NSIsAuthenticatingWithServer() SQRESULT SQ_IsAuthComplete(void* sqvm) { - g_ClientSquirrelManager->sq_pushbool(sqvm, g_MasterServerManager->m_bScriptAuthenticatingWithGameServer); + g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bScriptAuthenticatingWithGameServer); return SQRESULT_NOTNULL; } // bool function NSWasAuthSuccessful() SQRESULT SQ_WasAuthSuccessful(void* sqvm) { - g_ClientSquirrelManager->sq_pushbool(sqvm, g_MasterServerManager->m_bSuccessfullyAuthenticatedWithGameServer); + g_pClientSquirrel->sq_pushbool(sqvm, g_MasterServerManager->m_bSuccessfullyAuthenticatedWithGameServer); return SQRESULT_NOTNULL; } @@ -361,7 +361,7 @@ SQRESULT SQ_ConnectToAuthedServer(void* sqvm) { if (!g_MasterServerManager->m_bHasPendingConnectionInfo) { - g_ClientSquirrelManager->sq_raiseerror(sqvm, fmt::format("Tried to connect to authed server before any pending connection info was available").c_str()); + g_pClientSquirrel->sq_raiseerror(sqvm, fmt::format("Tried to connect to authed server before any pending connection info was available").c_str()); return SQRESULT_ERROR; } @@ -410,33 +410,33 @@ SQRESULT SQ_CompleteAuthWithLocalServer(void* sqvm) ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptServerBrowser, ClientSquirrel, (HMODULE baseAddress) { - g_UISquirrelManager->AddFuncRegistration("bool", "NSIsMasterServerAuthenticated", "", "", SQ_IsMasterServerAuthenticated); - g_UISquirrelManager->AddFuncRegistration("void", "NSRequestServerList", "", "", SQ_RequestServerList); - g_UISquirrelManager->AddFuncRegistration("bool", "NSIsRequestingServerList", "", "", SQ_IsRequestingServerList); - g_UISquirrelManager->AddFuncRegistration("bool", "NSMasterServerConnectionSuccessful", "", "", SQ_MasterServerConnectionSuccessful); - g_UISquirrelManager->AddFuncRegistration("int", "NSGetServerCount", "", "", SQ_GetServerCount); - g_UISquirrelManager->AddFuncRegistration("void", "NSClearRecievedServerList", "", "", SQ_ClearRecievedServerList); - - g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerName", "int serverIndex", "", SQ_GetServerName); - g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerDescription", "int serverIndex", "", SQ_GetServerDescription); - g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerMap", "int serverIndex", "", SQ_GetServerMap); - g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerPlaylist", "int serverIndex", "", SQ_GetServerPlaylist); - g_UISquirrelManager->AddFuncRegistration("int", "NSGetServerPlayerCount", "int serverIndex", "", SQ_GetServerPlayerCount); - g_UISquirrelManager->AddFuncRegistration("int", "NSGetServerMaxPlayerCount", "int serverIndex", "", SQ_GetServerMaxPlayerCount); - g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerID", "int serverIndex", "", SQ_GetServerID); - g_UISquirrelManager->AddFuncRegistration("bool", "NSServerRequiresPassword", "int serverIndex", "", SQ_ServerRequiresPassword); - g_UISquirrelManager->AddFuncRegistration("int", "NSGetServerRequiredModsCount", "int serverIndex", "", SQ_GetServerRequiredModsCount); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration("bool", "NSIsMasterServerAuthenticated", "", "", SQ_IsMasterServerAuthenticated); + g_pUISquirrel->AddFuncRegistration("void", "NSRequestServerList", "", "", SQ_RequestServerList); + g_pUISquirrel->AddFuncRegistration("bool", "NSIsRequestingServerList", "", "", SQ_IsRequestingServerList); + g_pUISquirrel->AddFuncRegistration("bool", "NSMasterServerConnectionSuccessful", "", "", SQ_MasterServerConnectionSuccessful); + g_pUISquirrel->AddFuncRegistration("int", "NSGetServerCount", "", "", SQ_GetServerCount); + g_pUISquirrel->AddFuncRegistration("void", "NSClearRecievedServerList", "", "", SQ_ClearRecievedServerList); + + g_pUISquirrel->AddFuncRegistration("string", "NSGetServerName", "int serverIndex", "", SQ_GetServerName); + g_pUISquirrel->AddFuncRegistration("string", "NSGetServerDescription", "int serverIndex", "", SQ_GetServerDescription); + g_pUISquirrel->AddFuncRegistration("string", "NSGetServerMap", "int serverIndex", "", SQ_GetServerMap); + g_pUISquirrel->AddFuncRegistration("string", "NSGetServerPlaylist", "int serverIndex", "", SQ_GetServerPlaylist); + g_pUISquirrel->AddFuncRegistration("int", "NSGetServerPlayerCount", "int serverIndex", "", SQ_GetServerPlayerCount); + g_pUISquirrel->AddFuncRegistration("int", "NSGetServerMaxPlayerCount", "int serverIndex", "", SQ_GetServerMaxPlayerCount); + g_pUISquirrel->AddFuncRegistration("string", "NSGetServerID", "int serverIndex", "", SQ_GetServerID); + g_pUISquirrel->AddFuncRegistration("bool", "NSServerRequiresPassword", "int serverIndex", "", SQ_ServerRequiresPassword); + g_pUISquirrel->AddFuncRegistration("int", "NSGetServerRequiredModsCount", "int serverIndex", "", SQ_GetServerRequiredModsCount); + g_pUISquirrel->AddFuncRegistration( "string", "NSGetServerRequiredModName", "int serverIndex, int modIndex", "", SQ_GetServerRequiredModName); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "string", "NSGetServerRequiredModVersion", "int serverIndex, int modIndex", "", SQ_GetServerRequiredModVersion); - g_UISquirrelManager->AddFuncRegistration( + g_pUISquirrel->AddFuncRegistration( "void", "NSTryAuthWithServer", "int serverIndex, string password = \"\"", "", SQ_TryAuthWithServer); - g_UISquirrelManager->AddFuncRegistration("bool", "NSIsAuthenticatingWithServer", "", "", SQ_IsAuthComplete); - g_UISquirrelManager->AddFuncRegistration("bool", "NSWasAuthSuccessful", "", "", SQ_WasAuthSuccessful); - g_UISquirrelManager->AddFuncRegistration("void", "NSConnectToAuthedServer", "", "", SQ_ConnectToAuthedServer); + g_pUISquirrel->AddFuncRegistration("bool", "NSIsAuthenticatingWithServer", "", "", SQ_IsAuthComplete); + g_pUISquirrel->AddFuncRegistration("bool", "NSWasAuthSuccessful", "", "", SQ_WasAuthSuccessful); + g_pUISquirrel->AddFuncRegistration("void", "NSConnectToAuthedServer", "", "", SQ_ConnectToAuthedServer); - g_UISquirrelManager->AddFuncRegistration("void", "NSTryAuthWithLocalServer", "", "", SQ_TryAuthWithLocalServer); - g_UISquirrelManager->AddFuncRegistration("void", "NSCompleteAuthWithLocalServer", "", "", SQ_CompleteAuthWithLocalServer); + g_pUISquirrel->AddFuncRegistration("void", "NSTryAuthWithLocalServer", "", "", SQ_TryAuthWithLocalServer); + g_pUISquirrel->AddFuncRegistration("void", "NSCompleteAuthWithLocalServer", "", "", SQ_CompleteAuthWithLocalServer); })
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp index b73932ed..79dde3e4 100644 --- a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp +++ b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp @@ -7,11 +7,11 @@ void ConCommand_ns_script_servertoclientstringcommand(const CCommand& arg) { - if (g_ClientSquirrelManager->sqvm && - g_ClientSquirrelManager->setupfunc("NSClientCodeCallback_RecievedServerToClientStringCommand") != SQRESULT_ERROR) + if (g_pClientSquirrel->sqvm && + g_pClientSquirrel->setupfunc("NSClientCodeCallback_RecievedServerToClientStringCommand") != SQRESULT_ERROR) { - g_ClientSquirrelManager->pusharg(arg.ArgS()); - g_ClientSquirrelManager->call(1); // todo: doesn't throw or log errors from within this, probably not great behaviour + g_pClientSquirrel->pusharg(arg.ArgS()); + g_pClientSquirrel->call(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 98f1bdc1..c16b7a4b 100644 --- a/NorthstarDedicatedTest/serverchathooks.cpp +++ b/NorthstarDedicatedTest/serverchathooks.cpp @@ -77,12 +77,12 @@ static void CServerGameDLL__OnReceivedSayTextMessageHook(CServerGameDLL* self, u return; } - if (g_ServerSquirrelManager->setupfunc("CServerGameDLL_ProcessMessageStartThread") != SQRESULT_ERROR) + if (g_pServerSquirrel->setupfunc("CServerGameDLL_ProcessMessageStartThread") != SQRESULT_ERROR) { - g_ServerSquirrelManager->pusharg((int)senderPlayerId - 1); - g_ServerSquirrelManager->pusharg(text); - g_ServerSquirrelManager->pusharg(isTeam); - g_ServerSquirrelManager->call(3); + g_pServerSquirrel->pusharg((int)senderPlayerId - 1); + g_pServerSquirrel->pusharg(text); + g_pServerSquirrel->pusharg(isTeam); + g_pServerSquirrel->call(3); } else CServerGameDLL__OnReceivedSayTextMessageHookBase(self, senderPlayerId, text, isTeam); @@ -142,9 +142,9 @@ void ChatBroadcastMessage(int fromPlayerIndex, int toPlayerIndex, const char* te SQRESULT SQ_SendMessage(void* sqvm) { - int playerIndex = g_ServerSquirrelManager->sq_getinteger(sqvm, 1); - const char* text = g_ServerSquirrelManager->sq_getstring(sqvm, 2); - bool isTeam = g_ServerSquirrelManager->sq_getbool(sqvm, 3); + 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); ChatSendMessage(playerIndex, text, isTeam); @@ -153,16 +153,16 @@ SQRESULT SQ_SendMessage(void* sqvm) SQRESULT SQ_BroadcastMessage(void* sqvm) { - int fromPlayerIndex = g_ServerSquirrelManager->sq_getinteger(sqvm, 1); - int toPlayerIndex = g_ServerSquirrelManager->sq_getinteger(sqvm, 2); - const char* text = g_ServerSquirrelManager->sq_getstring(sqvm, 3); - bool isTeam = g_ServerSquirrelManager->sq_getbool(sqvm, 4); - bool isDead = g_ServerSquirrelManager->sq_getbool(sqvm, 5); - int messageType = g_ServerSquirrelManager->sq_getinteger(sqvm, 6); + 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); if (messageType < 1) { - g_ServerSquirrelManager->sq_raiseerror(sqvm, fmt::format("Invalid message type {}", messageType).c_str()); + g_pServerSquirrel->sq_raiseerror(sqvm, fmt::format("Invalid message type {}", messageType).c_str()); return SQRESULT_ERROR; } @@ -200,8 +200,8 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerChatHooks, ServerSquirrel, (HMODULE bas reinterpret_cast<LPVOID*>(&CServerGameDLL__OnReceivedSayTextMessageHookBase)); // Chat sending functions - g_ServerSquirrelManager->AddFuncRegistration("void", "NSSendMessage", "int playerIndex, string text, bool isTeam", "", SQ_SendMessage); - g_ServerSquirrelManager->AddFuncRegistration( + g_pServerSquirrel->AddFuncRegistration("void", "NSSendMessage", "int playerIndex, string text, bool isTeam", "", SQ_SendMessage); + g_pServerSquirrel->AddFuncRegistration( "void", "NSBroadcastMessage", "int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType", diff --git a/NorthstarDedicatedTest/sourceinterface.cpp b/NorthstarDedicatedTest/sourceinterface.cpp index 73e93849..e80a067d 100644 --- a/NorthstarDedicatedTest/sourceinterface.cpp +++ b/NorthstarDedicatedTest/sourceinterface.cpp @@ -6,10 +6,10 @@ // really wanted to do a modular callback system here but honestly couldn't be bothered so hardcoding stuff for now: todo later -CreateInterfaceFn clientCreateInterfaceOriginal; +CreateInterfaceFn ClientCreateInterfaceOriginal; void* ClientCreateInterfaceHook(const char* pName, int* pReturnCode) { - void* ret = clientCreateInterfaceOriginal(pName, pReturnCode); + void* ret = ClientCreateInterfaceOriginal(pName, pReturnCode); spdlog::info("CreateInterface CLIENT {}", pName); if (!strcmp(pName, "GameClientExports001")) @@ -18,19 +18,19 @@ void* ClientCreateInterfaceHook(const char* pName, int* pReturnCode) return ret; } -CreateInterfaceFn serverCreateInterfaceOriginal; +CreateInterfaceFn ServerCreateInterfaceOriginal; void* ServerCreateInterfaceHook(const char* pName, int* pReturnCode) { - void* ret = serverCreateInterfaceOriginal(pName, pReturnCode); + void* ret = ServerCreateInterfaceOriginal(pName, pReturnCode); spdlog::info("CreateInterface SERVER {}", pName); return ret; } -CreateInterfaceFn engineCreateInterfaceOriginal; +CreateInterfaceFn EngineCreateInterfaceOriginal; void* EngineCreateInterfaceHook(const char* pName, int* pReturnCode) { - void* ret = engineCreateInterfaceOriginal(pName, pReturnCode); + void* ret = EngineCreateInterfaceOriginal(pName, pReturnCode); spdlog::info("CreateInterface ENGINE {}", pName); return ret; @@ -43,7 +43,7 @@ ON_DLL_LOAD("client.dll", ClientInterface, (HMODULE baseAddress) hook, GetProcAddress(baseAddress, "CreateInterface"), &ClientCreateInterfaceHook, - reinterpret_cast<LPVOID*>(&clientCreateInterfaceOriginal)); + reinterpret_cast<LPVOID*>(&ClientCreateInterfaceOriginal)); }) ON_DLL_LOAD("server.dll", ServerInterface, (HMODULE baseAddress) @@ -53,7 +53,7 @@ ON_DLL_LOAD("server.dll", ServerInterface, (HMODULE baseAddress) hook, GetProcAddress(baseAddress, "CreateInterface"), &ServerCreateInterfaceHook, - reinterpret_cast<LPVOID*>(&serverCreateInterfaceOriginal)); + reinterpret_cast<LPVOID*>(&ServerCreateInterfaceOriginal)); }) ON_DLL_LOAD("engine.dll", EngineInterface, (HMODULE baseAddress) @@ -63,5 +63,5 @@ ON_DLL_LOAD("engine.dll", EngineInterface, (HMODULE baseAddress) hook, GetProcAddress(baseAddress, "CreateInterface"), &EngineCreateInterfaceHook, - reinterpret_cast<LPVOID*>(&engineCreateInterfaceOriginal)); + reinterpret_cast<LPVOID*>(&EngineCreateInterfaceOriginal)); })
\ No newline at end of file diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index 1772bdb8..7851192b 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -2,58 +2,28 @@ #include "squirrel.h" #include "hooks.h" #include "hookutils.h" -#include "sigscanning.h" #include "concommand.h" #include "modmanager.h" -#include <iostream> - -// hook forward declarations -typedef SQInteger (*SQPrintType)(void* sqvm, char* fmt, ...); -SQPrintType ClientSQPrint; -SQPrintType UISQPrint; -SQPrintType ServerSQPrint; -template <ScriptContext context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...); - -typedef void* (*CreateNewVMType)(void* a1, ScriptContext contextArg); -CreateNewVMType ClientCreateNewVM; // only need a client one since ui doesn't have its own func for this -CreateNewVMType ServerCreateNewVM; -template <ScriptContext context> void* CreateNewVMHook(void* a1, ScriptContext contextArg); - -typedef void (*DestroyVMType)(void* a1, void* sqvm); -DestroyVMType ClientDestroyVM; // only need a client one since ui doesn't have its own func for this -DestroyVMType ServerDestroyVM; -template <ScriptContext context> void DestroyVMHook(void* a1, void* sqvm); - -typedef void (*ScriptCompileError)(void* sqvm, const char* error, const char* file, int line, int column); -ScriptCompileError ClientSQCompileError; // only need a client one since ui doesn't have its own func for this -ScriptCompileError ServerSQCompileError; -template <ScriptContext context> void ScriptCompileErrorHook(void* sqvm, const char* error, const char* file, int line, int column); - -typedef char (*CallScriptInitCallbackType)(void* sqvm, const char* callback); -CallScriptInitCallbackType ClientCallScriptInitCallback; -CallScriptInitCallbackType ServerCallScriptInitCallback; -template <ScriptContext context> char CallScriptInitCallbackHook(void* sqvm, const char* callback); +#include "gameutils.h" RegisterSquirrelFuncType ClientRegisterSquirrelFunc; RegisterSquirrelFuncType ServerRegisterSquirrelFunc; -template <ScriptContext context> void ExecuteCodeCommand(const CCommand& args); - // inits -SquirrelManager<ScriptContext::CLIENT>* g_ClientSquirrelManager; -SquirrelManager<ScriptContext::SERVER>* g_ServerSquirrelManager; -SquirrelManager<ScriptContext::UI>* g_UISquirrelManager; +SquirrelManager<ScriptContext::CLIENT>* g_pClientSquirrel; +SquirrelManager<ScriptContext::SERVER>* g_pServerSquirrel; +SquirrelManager<ScriptContext::UI>* g_pUISquirrel; template <ScriptContext context> SquirrelManager<context>* GetSquirrelManager() { switch (context) { case ScriptContext::CLIENT: - return g_ClientSquirrelManager; + return g_pClientSquirrel; case ScriptContext::SERVER: - return g_ServerSquirrelManager; + return g_pServerSquirrel; case ScriptContext::UI: - return g_UISquirrelManager; + return g_pUISquirrel; } } @@ -70,149 +40,11 @@ const char* GetContextName(ScriptContext context) } } -ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (HMODULE baseAddress) -{ - HookEnabler hook; - - // client inits - g_ClientSquirrelManager = new SquirrelManager<ScriptContext::CLIENT>(); - - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x12B00, - &SQPrintHook<ScriptContext::CLIENT>, - reinterpret_cast<LPVOID*>(&ClientSQPrint)); // client print function - RegisterConCommand( - "script_client", ExecuteCodeCommand<ScriptContext::CLIENT>, "Executes script code on the client vm", FCVAR_CLIENTDLL); - - // ui inits - g_UISquirrelManager = new SquirrelManager<ScriptContext::UI>(); - - ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x12BA0, &SQPrintHook<ScriptContext::UI>, reinterpret_cast<LPVOID*>(&UISQPrint)); // ui print function - RegisterConCommand("script_ui", ExecuteCodeCommand<ScriptContext::UI>, "Executes script code on the ui vm", FCVAR_CLIENTDLL); - - ClientRegisterSquirrelFunc = (RegisterSquirrelFuncType)((char*)baseAddress + 0x108E0); - - g_ClientSquirrelManager->sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); - g_UISquirrelManager->sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); - g_ClientSquirrelManager->sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5860); - g_UISquirrelManager->sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5860); - - g_ClientSquirrelManager->sq_call = (sq_callType)((char*)baseAddress + 0x8650); - g_UISquirrelManager->sq_call = (sq_callType)((char*)baseAddress + 0x8650); - - g_ClientSquirrelManager->sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); - g_UISquirrelManager->sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); - g_ClientSquirrelManager->sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); - g_UISquirrelManager->sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); - - g_ClientSquirrelManager->sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); - g_UISquirrelManager->sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); - g_ClientSquirrelManager->sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); - g_UISquirrelManager->sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); - g_ClientSquirrelManager->sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); - g_UISquirrelManager->sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); - g_ClientSquirrelManager->sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); - g_UISquirrelManager->sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); - g_ClientSquirrelManager->sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8470); - g_UISquirrelManager->sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8470); - - g_ClientSquirrelManager->sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60C0); - g_UISquirrelManager->sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60C0); - g_ClientSquirrelManager->sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60E0); - g_UISquirrelManager->sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60E0); - g_ClientSquirrelManager->sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x6100); - g_UISquirrelManager->sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x6100); - g_ClientSquirrelManager->sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6130); - g_UISquirrelManager->sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6130); - g_ClientSquirrelManager->sq_get = (sq_getType)((char*)baseAddress + 0x7C30); - g_UISquirrelManager->sq_get = (sq_getType)((char*)baseAddress + 0x7C30); - - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x26130, - &CreateNewVMHook<ScriptContext::CLIENT>, - reinterpret_cast<LPVOID*>(&ClientCreateNewVM)); // client createnewvm function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x26E70, - &DestroyVMHook<ScriptContext::CLIENT>, - reinterpret_cast<LPVOID*>(&ClientDestroyVM)); // client destroyvm function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x79A50, - &ScriptCompileErrorHook<ScriptContext::CLIENT>, - reinterpret_cast<LPVOID*>(&ClientSQCompileError)); // client compileerror function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x10190, - &CallScriptInitCallbackHook<ScriptContext::CLIENT>, - reinterpret_cast<LPVOID*>(&ClientCallScriptInitCallback)); // client callscriptinitcallback function -}) - -ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (HMODULE baseAddress) -{ - g_ServerSquirrelManager = new SquirrelManager<ScriptContext::SERVER>(); - - ServerRegisterSquirrelFunc = (RegisterSquirrelFuncType)((char*)baseAddress + 0x1DD10); - - g_ServerSquirrelManager->sq_compilebuffer = (sq_compilebufferType)((char*)baseAddress + 0x3110); - g_ServerSquirrelManager->sq_pushroottable = (sq_pushroottableType)((char*)baseAddress + 0x5840); - g_ServerSquirrelManager->sq_call = (sq_callType)((char*)baseAddress + 0x8620); - - g_ServerSquirrelManager->sq_newarray = (sq_newarrayType)((char*)baseAddress + 0x39F0); - g_ServerSquirrelManager->sq_arrayappend = (sq_arrayappendType)((char*)baseAddress + 0x3C70); - - g_ServerSquirrelManager->sq_pushstring = (sq_pushstringType)((char*)baseAddress + 0x3440); - g_ServerSquirrelManager->sq_pushinteger = (sq_pushintegerType)((char*)baseAddress + 0x36A0); - g_ServerSquirrelManager->sq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800); - g_ServerSquirrelManager->sq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710); - g_ServerSquirrelManager->sq_raiseerror = (sq_raiseerrorType)((char*)baseAddress + 0x8440); - - g_ServerSquirrelManager->sq_getstring = (sq_getstringType)((char*)baseAddress + 0x60A0); - g_ServerSquirrelManager->sq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60C0); - g_ServerSquirrelManager->sq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x60E0); - g_ServerSquirrelManager->sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6110); - g_ServerSquirrelManager->sq_get = (sq_getType)((char*)baseAddress + 0x7C00); - - HookEnabler hook; - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x1FE90, - &SQPrintHook<ScriptContext::SERVER>, - reinterpret_cast<LPVOID*>(&ServerSQPrint)); // server print function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x260E0, - &CreateNewVMHook<ScriptContext::SERVER>, - reinterpret_cast<LPVOID*>(&ServerCreateNewVM)); // server createnewvm function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x26E20, - &DestroyVMHook<ScriptContext::SERVER>, - reinterpret_cast<LPVOID*>(&ServerDestroyVM)); // server destroyvm function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x799E0, - &ScriptCompileErrorHook<ScriptContext::SERVER>, - reinterpret_cast<LPVOID*>(&ServerSQCompileError)); // server compileerror function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x1D5C0, - &CallScriptInitCallbackHook<ScriptContext::SERVER>, - reinterpret_cast<LPVOID*>(&ServerCallScriptInitCallback)); // server callscriptinitcallback function - - // cheat and clientcmd_can_execute allows clients to execute this, but since it's unsafe we only allow it when cheats are enabled - // for script_client and script_ui, we don't use cheats, so clients can execute them on themselves all they want - RegisterConCommand( - "script", - ExecuteCodeCommand<ScriptContext::SERVER>, - "Executes script code on the server vm", - FCVAR_GAMEDLL | FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_CHEAT); -}) - // hooks +typedef SQInteger (*SQPrintType)(void* sqvm, char* fmt, ...); +SQPrintType ClientSQPrint; +SQPrintType UISQPrint; +SQPrintType ServerSQPrint; template <ScriptContext context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...) { va_list va; @@ -233,6 +65,9 @@ template <ScriptContext context> SQInteger SQPrintHook(void* sqvm, char* fmt, .. return 0; } +typedef void* (*CreateNewVMType)(void* a1, ScriptContext contextArg); +CreateNewVMType ClientCreateNewVM; +CreateNewVMType ServerCreateNewVM; template <ScriptContext context> void* CreateNewVMHook(void* a1, ScriptContext realContext) { void* sqvm; @@ -242,31 +77,34 @@ template <ScriptContext context> void* CreateNewVMHook(void* a1, ScriptContext r sqvm = ClientCreateNewVM(a1, realContext); if (realContext == ScriptContext::UI) - g_UISquirrelManager->VMCreated(sqvm); + g_pUISquirrel->VMCreated(sqvm); else - g_ClientSquirrelManager->VMCreated(sqvm); + g_pClientSquirrel->VMCreated(sqvm); } else if (context == ScriptContext::SERVER) { sqvm = ServerCreateNewVM(a1, context); - g_ServerSquirrelManager->VMCreated(sqvm); + g_pServerSquirrel->VMCreated(sqvm); } spdlog::info("CreateNewVM {} {}", GetContextName(realContext), sqvm); return sqvm; } +typedef void (*DestroyVMType)(void* a1, void* sqvm); +DestroyVMType ClientDestroyVM; +DestroyVMType ServerDestroyVM; template <ScriptContext context> void DestroyVMHook(void* a1, void* sqvm) { ScriptContext realContext = context; // ui and client use the same function so we use this for prints if (context == ScriptContext::CLIENT) { - if (g_ClientSquirrelManager->sqvm == sqvm) - g_ClientSquirrelManager->VMDestroyed(); - else if (g_UISquirrelManager->sqvm == sqvm) + if (g_pClientSquirrel->sqvm == sqvm) + g_pClientSquirrel->VMDestroyed(); + else if (g_pUISquirrel->sqvm == sqvm) { - g_UISquirrelManager->VMDestroyed(); + g_pUISquirrel->VMDestroyed(); realContext = ScriptContext::UI; } @@ -274,148 +112,108 @@ template <ScriptContext context> void DestroyVMHook(void* a1, void* sqvm) } else if (context == ScriptContext::SERVER) { - g_ServerSquirrelManager->VMDestroyed(); + g_pServerSquirrel->VMDestroyed(); ServerDestroyVM(a1, sqvm); } spdlog::info("DestroyVM {} {}", GetContextName(realContext), sqvm); } +typedef void (*ScriptCompileError)(void* sqvm, const char* error, const char* file, int line, int column); +ScriptCompileError ClientSQCompileError; +ScriptCompileError ServerSQCompileError; template <ScriptContext context> void ScriptCompileErrorHook(void* sqvm, const char* error, const char* file, int line, int column) { ScriptContext realContext = context; // ui and client use the same function so we use this for prints - if (context == ScriptContext::CLIENT && sqvm == g_UISquirrelManager->sqvm) + if (context == ScriptContext::CLIENT && sqvm == g_pUISquirrel->sqvm2) realContext = ScriptContext::UI; spdlog::error("{} SCRIPT COMPILE ERROR {}", GetContextName(realContext), error); spdlog::error("{} line [{}] column [{}]", file, line, column); - // dont call the original since it kills game - // in the future it'd be nice to do an actual error with UICodeCallback_ErrorDialog here, but only if we're compiling level scripts - // compilestring and stuff shouldn't tho - // though, that also has potential to be REALLY bad if we're compiling ui scripts lol + // use disconnect to display an error message for the compile error, but only if we aren't compiling from console, or from compilestring() + // TODO: compilestring can actually define a custom buffer name as the second arg, we don't currently have a way of checking this + // ideally we'd just check if the sqvm was fully initialised here, somehow + if (strcmp(file, "console") && strcmp(file, "unnamedbuffer")) + { + Cbuf_AddText( + Cbuf_GetCurrentPlayer(), + fmt::format("disconnect \"Encountered {} script compilation error, see console for details.\"", GetContextName(realContext)) + .c_str(), + cmd_source_t::kCommandSrcCode); + + // TODO: for ui script, we need to prevent the infinite compilation error loop the game will get into on uiscript_reset if there is a compilation error + } + + // dont call the original function since it kills game lol } -template <ScriptContext context> char CallScriptInitCallbackHook(void* sqvm, const char* callback) +typedef bool (*CallScriptInitCallbackType)(void* sqvm, const char* callback); +CallScriptInitCallbackType ClientCallScriptInitCallback; +CallScriptInitCallbackType ServerCallScriptInitCallback; +template <ScriptContext context> bool CallScriptInitCallbackHook(void* sqvm, const char* callback) { - char ret; + CallScriptInitCallbackType callScriptInitCallback; + ScriptContext realContext = context; + bool shouldCallCustomCallbacks = true; if (context == ScriptContext::CLIENT) { - ScriptContext realContext = context; // ui and client use the same function so we use this for prints - bool shouldCallCustomCallbacks = false; + callScriptInitCallback = ClientCallScriptInitCallback; - // since we don't hook arbitrary callbacks yet, make sure we're only doing callbacks on inits if (!strcmp(callback, "UICodeCallback_UIInit")) - { realContext = ScriptContext::UI; - shouldCallCustomCallbacks = true; - } - else if (!strcmp(callback, "ClientCodeCallback_MapSpawn")) - shouldCallCustomCallbacks = true; - - // run before callbacks - // todo: we need to verify if RunOn is valid for current state before calling callbacks - if (shouldCallCustomCallbacks) - { - for (Mod mod : g_ModManager->m_loadedMods) - { - if (!mod.Enabled) - continue; - - for (ModScript script : mod.Scripts) - { - for (ModScriptCallback modCallback : script.Callbacks) - { - if (modCallback.Context == realContext && modCallback.BeforeCallback.length()) - { - spdlog::info( - "Running custom {} script callback \"{}\"", GetContextName(realContext), modCallback.BeforeCallback); - ClientCallScriptInitCallback(sqvm, modCallback.BeforeCallback.c_str()); - } - } - } - } - } - - spdlog::info("{} CodeCallback {} called", GetContextName(realContext), callback); - if (!shouldCallCustomCallbacks) - spdlog::info("Not executing custom callbacks for CodeCallback {}", callback); - ret = ClientCallScriptInitCallback(sqvm, callback); - - // run after callbacks - if (shouldCallCustomCallbacks) - { - for (Mod mod : g_ModManager->m_loadedMods) - { - if (!mod.Enabled) - continue; - - for (ModScript script : mod.Scripts) - { - for (ModScriptCallback modCallback : script.Callbacks) - { - if (modCallback.Context == realContext && modCallback.AfterCallback.length()) - { - spdlog::info( - "Running custom {} script callback \"{}\"", GetContextName(realContext), modCallback.AfterCallback); - ClientCallScriptInitCallback(sqvm, modCallback.AfterCallback.c_str()); - } - } - } - } - } + else if (strcmp(callback, "ClientCodeCallback_MapSpawn")) + shouldCallCustomCallbacks = false; } else if (context == ScriptContext::SERVER) { - // since we don't hook arbitrary callbacks yet, make sure we're only doing callbacks on inits - bool shouldCallCustomCallbacks = !strcmp(callback, "CodeCallback_MapSpawn"); + callScriptInitCallback = ServerCallScriptInitCallback; + shouldCallCustomCallbacks = !strcmp(callback, "CodeCallback_MapSpawn"); + } - // run before callbacks - // todo: we need to verify if RunOn is valid for current state before calling callbacks - if (shouldCallCustomCallbacks) + if (shouldCallCustomCallbacks) + { + for (Mod mod : g_ModManager->m_loadedMods) { - for (Mod mod : g_ModManager->m_loadedMods) - { - if (!mod.Enabled) - continue; + if (!mod.Enabled) + continue; - for (ModScript script : mod.Scripts) + for (ModScript script : mod.Scripts) + { + for (ModScriptCallback modCallback : script.Callbacks) { - for (ModScriptCallback modCallback : script.Callbacks) + if (modCallback.Context == realContext && modCallback.BeforeCallback.length()) { - if (modCallback.Context == ScriptContext::SERVER && modCallback.BeforeCallback.length()) - { - spdlog::info("Running custom {} script callback \"{}\"", GetContextName(context), modCallback.BeforeCallback); - ServerCallScriptInitCallback(sqvm, modCallback.BeforeCallback.c_str()); - } + spdlog::info("Running custom {} script callback \"{}\"", GetContextName(realContext), modCallback.BeforeCallback); + callScriptInitCallback(sqvm, modCallback.BeforeCallback.c_str()); } } } } + } - spdlog::info("{} CodeCallback {} called", GetContextName(context), callback); - if (!shouldCallCustomCallbacks) - spdlog::info("Not executing custom callbacks for CodeCallback {}", callback); - ret = ServerCallScriptInitCallback(sqvm, callback); + spdlog::info("{} CodeCallback {} called", GetContextName(realContext), callback); + if (!shouldCallCustomCallbacks) + spdlog::info("Not executing custom callbacks for CodeCallback {}", callback); + bool ret = callScriptInitCallback(sqvm, callback); - // run after callbacks - if (shouldCallCustomCallbacks) + // run after callbacks + if (shouldCallCustomCallbacks) + { + for (Mod mod : g_ModManager->m_loadedMods) { - for (Mod mod : g_ModManager->m_loadedMods) - { - if (!mod.Enabled) - continue; + if (!mod.Enabled) + continue; - for (ModScript script : mod.Scripts) + for (ModScript script : mod.Scripts) + { + for (ModScriptCallback modCallback : script.Callbacks) { - for (ModScriptCallback modCallback : script.Callbacks) + if (modCallback.Context == realContext && modCallback.AfterCallback.length()) { - if (modCallback.Context == ScriptContext::SERVER && modCallback.AfterCallback.length()) - { - spdlog::info("Running custom {} script callback \"{}\"", GetContextName(context), modCallback.AfterCallback); - ServerCallScriptInitCallback(sqvm, modCallback.AfterCallback.c_str()); - } + spdlog::info("Running custom {} script callback \"{}\"", GetContextName(realContext), modCallback.AfterCallback); + callScriptInitCallback(sqvm, modCallback.AfterCallback.c_str()); } } } @@ -428,9 +226,155 @@ template <ScriptContext context> char CallScriptInitCallbackHook(void* sqvm, con template <ScriptContext context> void ExecuteCodeCommand(const CCommand& args) { if (context == ScriptContext::CLIENT) - g_ClientSquirrelManager->ExecuteCode(args.ArgS()); + g_pClientSquirrel->ExecuteCode(args.ArgS()); else if (context == ScriptContext::UI) - g_UISquirrelManager->ExecuteCode(args.ArgS()); + g_pUISquirrel->ExecuteCode(args.ArgS()); else if (context == ScriptContext::SERVER) - g_ServerSquirrelManager->ExecuteCode(args.ArgS()); -}
\ No newline at end of file + g_pServerSquirrel->ExecuteCode(args.ArgS()); +} + +ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (HMODULE baseAddress) +{ + HookEnabler hook; + + // client inits + g_pClientSquirrel = new SquirrelManager<ScriptContext::CLIENT>; + + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x12B00, + &SQPrintHook<ScriptContext::CLIENT>, + reinterpret_cast<LPVOID*>(&ClientSQPrint)); // client print function + RegisterConCommand( + "script_client", ExecuteCodeCommand<ScriptContext::CLIENT>, "Executes script code on the client vm", FCVAR_CLIENTDLL); + + // ui inits + g_pUISquirrel = new SquirrelManager<ScriptContext::UI>; + + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x12BA0, + &SQPrintHook<ScriptContext::UI>, + reinterpret_cast<LPVOID*>(&UISQPrint)); // ui print function + RegisterConCommand("script_ui", ExecuteCodeCommand<ScriptContext::UI>, "Executes script code on the ui vm", FCVAR_CLIENTDLL); + + 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); + + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x26130, + &CreateNewVMHook<ScriptContext::CLIENT>, + reinterpret_cast<LPVOID*>(&ClientCreateNewVM)); // client createnewvm function + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x26E70, + &DestroyVMHook<ScriptContext::CLIENT>, + reinterpret_cast<LPVOID*>(&ClientDestroyVM)); // client destroyvm function + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x79A50, + &ScriptCompileErrorHook<ScriptContext::CLIENT>, + reinterpret_cast<LPVOID*>(&ClientSQCompileError)); // client compileerror function + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x10190, + &CallScriptInitCallbackHook<ScriptContext::CLIENT>, + reinterpret_cast<LPVOID*>(&ClientCallScriptInitCallback)); // client callscriptinitcallback function +}) + +ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (HMODULE baseAddress) +{ + g_pServerSquirrel = new SquirrelManager<ScriptContext::SERVER>; + + 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_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_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( + hook, + (char*)baseAddress + 0x1FE90, + &SQPrintHook<ScriptContext::SERVER>, + reinterpret_cast<LPVOID*>(&ServerSQPrint)); // server print function + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x260E0, + &CreateNewVMHook<ScriptContext::SERVER>, + reinterpret_cast<LPVOID*>(&ServerCreateNewVM)); // server createnewvm function + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x26E20, + &DestroyVMHook<ScriptContext::SERVER>, + reinterpret_cast<LPVOID*>(&ServerDestroyVM)); // server destroyvm function + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x799E0, + &ScriptCompileErrorHook<ScriptContext::SERVER>, + reinterpret_cast<LPVOID*>(&ServerSQCompileError)); // server compileerror function + ENABLER_CREATEHOOK( + hook, + (char*)baseAddress + 0x1D5C0, + &CallScriptInitCallbackHook<ScriptContext::SERVER>, + reinterpret_cast<LPVOID*>(&ServerCallScriptInitCallback)); // server callscriptinitcallback function + + // cheat and clientcmd_can_execute allows clients to execute this, but since it's unsafe we only allow it when cheats are enabled + // for script_client and script_ui, we don't use cheats, so clients can execute them on themselves all they want + RegisterConCommand( + "script", + ExecuteCodeCommand<ScriptContext::SERVER>, + "Executes script code on the server vm", + FCVAR_GAMEDLL | FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_CHEAT); +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h index 4dc3240c..6f4e4f9e 100644 --- a/NorthstarDedicatedTest/squirrel.h +++ b/NorthstarDedicatedTest/squirrel.h @@ -5,7 +5,6 @@ typedef float SQFloat; typedef long SQInteger; typedef unsigned long SQUnsignedInteger; typedef char SQChar; - typedef SQUnsignedInteger SQBool; enum SQRESULT : SQInteger @@ -70,8 +69,6 @@ const char* GetContextName(ScriptContext context); // core sqvm funcs typedef int64_t (*RegisterSquirrelFuncType)(void* sqvm, SQFuncRegistration* funcReg, char unknown); -extern RegisterSquirrelFuncType ClientRegisterSquirrelFunc; -extern RegisterSquirrelFuncType ServerRegisterSquirrelFunc; typedef SQRESULT (*sq_compilebufferType)(void* sqvm, CompileBufferState* compileBuffer, const char* file, int a1, ScriptContext a2); typedef SQRESULT (*sq_callType)(void* sqvm, SQInteger s1, SQBool a2, SQBool a3); @@ -104,6 +101,8 @@ template <ScriptContext context> class SquirrelManager void* sqvm; void* sqvm2; #pragma region SQVM funcs + RegisterSquirrelFuncType RegisterSquirrelFunc; + sq_compilebufferType sq_compilebuffer; sq_callType sq_call; sq_newarrayType sq_newarray; @@ -133,11 +132,7 @@ template <ScriptContext context> class SquirrelManager for (SQFuncRegistration* funcReg : m_funcRegistrations) { spdlog::info("Registering {} function {}", GetContextName(context), funcReg->squirrelFuncName); - - if (context == ScriptContext::CLIENT || context == ScriptContext::UI) - ClientRegisterSquirrelFunc(sqvm, funcReg, 1); - else - ServerRegisterSquirrelFunc(sqvm, funcReg, 1); + RegisterSquirrelFunc(sqvm, funcReg, 1); } } @@ -229,7 +224,7 @@ template <ScriptContext context> class SquirrelManager } }; -extern SquirrelManager<ScriptContext::CLIENT>* g_ClientSquirrelManager; -extern SquirrelManager<ScriptContext::SERVER>* g_ServerSquirrelManager; -extern SquirrelManager<ScriptContext::UI>* g_UISquirrelManager; +extern SquirrelManager<ScriptContext::CLIENT>* g_pClientSquirrel; +extern SquirrelManager<ScriptContext::SERVER>* g_pServerSquirrel; +extern SquirrelManager<ScriptContext::UI>* g_pUISquirrel; template <ScriptContext context> SquirrelManager<context>* GetSquirrelManager();
\ No newline at end of file |