diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-10-19 02:18:24 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-10-19 02:18:24 +0100 |
commit | ed7e4fed4ddedaf9d4c181052ca552a0914d57bb (patch) | |
tree | 0d451e40d82b0513c4f2acd42ea750638b1d4c88 /NorthstarDedicatedTest/miscserverscript.cpp | |
parent | 9b8a6d155a7a2cf1bfb4e8d98980bfb0b6e94d92 (diff) | |
download | NorthstarLauncher-ed7e4fed4ddedaf9d4c181052ca552a0914d57bb.tar.gz NorthstarLauncher-ed7e4fed4ddedaf9d4c181052ca552a0914d57bb.zip |
add masterserver mod list support and fix some squirrel issues
Diffstat (limited to 'NorthstarDedicatedTest/miscserverscript.cpp')
-rw-r--r-- | NorthstarDedicatedTest/miscserverscript.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/miscserverscript.cpp b/NorthstarDedicatedTest/miscserverscript.cpp new file mode 100644 index 00000000..dd4c7101 --- /dev/null +++ b/NorthstarDedicatedTest/miscserverscript.cpp @@ -0,0 +1,65 @@ +#include "pch.h" +#include "miscserverscript.h" +#include "squirrel.h" +#include "masterserver.h" +#include "serverauthentication.h" +#include "gameutils.h" + +// annoying helper function because i can't figure out getting players or entities from sqvm rn +// wish i didn't have to do it like this, but here we are +void* GetPlayerByIndex(int playerIndex) +{ + const int PLAYER_ARRAY_OFFSET = 0x12A53F90; + const int PLAYER_SIZE = 0x2D728; + + void* playerArrayBase = (char*)GetModuleHandleA("engine.dll") + PLAYER_ARRAY_OFFSET; + void* player = (char*)playerArrayBase + (playerIndex * PLAYER_SIZE); + + return player; +} + +// void function NSEarlyWritePlayerIndexPersistenceForLeave( int playerIndex ) +SQInteger SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm) +{ + int playerIndex = ServerSq_getinteger(sqvm, 1); + void* player = GetPlayerByIndex(playerIndex); + + if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player)) + { + ServerSq_pusherror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); + return -1; + } + + g_ServerAuthenticationManager->m_additionalPlayerData[player].needPersistenceWriteOnLeave = false; + g_ServerAuthenticationManager->WritePersistentData(player); + return 0; +} + +// bool function NSIsWritingPlayerPersistence() +SQInteger SQ_IsWritingPlayerPersistence(void* sqvm) +{ + ServerSq_pushbool(sqvm, g_MasterServerManager->m_savingPersistentData); + return 1; +} + +// bool function NSIsPlayerIndexLocalPlayer( int playerIndex ) +SQInteger SQ_IsPlayerIndexLocalPlayer(void* sqvm) +{ + int playerIndex = ServerSq_getinteger(sqvm, 1); + void* player = GetPlayerByIndex(playerIndex); + if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player)) + { + ServerSq_pusherror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); + return -1; + } + + ServerSq_pushbool(sqvm, !strcmp(g_LocalPlayerUserID, (char*)player + 0xF500)); + return 1; +} + +void InitialiseMiscServerScriptCommand(HMODULE baseAddress) +{ + g_ServerSquirrelManager->AddFuncRegistration("void", "NSEarlyWritePlayerIndexPersistenceForLeave", "int playerIndex", "", SQ_EarlyWritePlayerIndexPersistenceForLeave); + g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence); + g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsPlayerIndexLocalPlayer", "int playerIndex", "", SQ_IsPlayerIndexLocalPlayer); +}
\ No newline at end of file |