aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/miscserverscript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDLL/miscserverscript.cpp')
-rw-r--r--NorthstarDLL/miscserverscript.cpp63
1 files changed, 26 insertions, 37 deletions
diff --git a/NorthstarDLL/miscserverscript.cpp b/NorthstarDLL/miscserverscript.cpp
index e6ddd58b..7ae8047f 100644
--- a/NorthstarDLL/miscserverscript.cpp
+++ b/NorthstarDLL/miscserverscript.cpp
@@ -1,76 +1,65 @@
#include "pch.h"
-#include "miscserverscript.h"
#include "squirrel.h"
#include "masterserver.h"
#include "serverauthentication.h"
-#include "gameutils.h"
#include "dedicated.h"
+#include "r2client.h"
+#include "r2server.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;
-}
+#include <filesystem>
// void function NSEarlyWritePlayerIndexPersistenceForLeave( int playerIndex )
-SQRESULT SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm)
+SQRESULT SQ_EarlyWritePlayerIndexPersistenceForLeave(HSquirrelVM* sqvm)
{
- int playerIndex = ServerSq_getinteger(sqvm, 1);
- void* player = GetPlayerByIndex(playerIndex);
+ int playerIndex = g_pSquirrel<ScriptContext::SERVER>->getinteger(sqvm, 1);
+ R2::CBaseClient* player = &R2::g_pClientArray[playerIndex];
- if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player))
+ if (!g_pServerAuthentication->m_PlayerAuthenticationData.count(player))
{
- ServerSq_pusherror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str());
+ g_pSquirrel<ScriptContext::SERVER>->raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str());
return SQRESULT_ERROR;
}
- g_ServerAuthenticationManager->m_additionalPlayerData[player].needPersistenceWriteOnLeave = false;
- g_ServerAuthenticationManager->WritePersistentData(player);
+ g_pServerAuthentication->m_PlayerAuthenticationData[player].needPersistenceWriteOnLeave = false;
+ g_pServerAuthentication->WritePersistentData(player);
return SQRESULT_NULL;
}
// bool function NSIsWritingPlayerPersistence()
-SQRESULT SQ_IsWritingPlayerPersistence(void* sqvm)
+SQRESULT SQ_IsWritingPlayerPersistence(HSquirrelVM* sqvm)
{
- ServerSq_pushbool(sqvm, g_MasterServerManager->m_bSavingPersistentData);
+ g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, g_pMasterServerManager->m_bSavingPersistentData);
return SQRESULT_NOTNULL;
}
// bool function NSIsPlayerIndexLocalPlayer( int playerIndex )
-SQRESULT SQ_IsPlayerIndexLocalPlayer(void* sqvm)
+SQRESULT SQ_IsPlayerIndexLocalPlayer(HSquirrelVM* sqvm)
{
- int playerIndex = ServerSq_getinteger(sqvm, 1);
- void* player = GetPlayerByIndex(playerIndex);
- if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player))
+ int playerIndex = g_pSquirrel<ScriptContext::SERVER>->getinteger(sqvm, 1);
+ R2::CBaseClient* player = &R2::g_pClientArray[playerIndex];
+ if (!g_pServerAuthentication->m_PlayerAuthenticationData.count(player))
{
- ServerSq_pusherror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str());
+ g_pSquirrel<ScriptContext::SERVER>->raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str());
return SQRESULT_ERROR;
}
- ServerSq_pushbool(sqvm, !strcmp(g_LocalPlayerUserID, (char*)player + 0xF500));
+ g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, !strcmp(R2::g_pLocalPlayerUserID, player->m_UID));
return SQRESULT_NOTNULL;
}
// bool function NSIsDedicated()
-
-SQRESULT SQ_IsDedicated(void* sqvm)
+SQRESULT SQ_IsDedicated(HSquirrelVM* sqvm)
{
- ServerSq_pushbool(sqvm, IsDedicatedServer());
+ g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, IsDedicatedServer());
return SQRESULT_NOTNULL;
}
-void InitialiseMiscServerScriptCommand(HMODULE baseAddress)
+ON_DLL_LOAD_RELIESON("server.dll", MiscServerScriptCommands, ServerSquirrel, (CModule module))
{
- g_ServerSquirrelManager->AddFuncRegistration(
+ g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration(
"void", "NSEarlyWritePlayerIndexPersistenceForLeave", "int playerIndex", "", SQ_EarlyWritePlayerIndexPersistenceForLeave);
- g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence);
- g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsPlayerIndexLocalPlayer", "int playerIndex", "", SQ_IsPlayerIndexLocalPlayer);
- g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsDedicated", "", "", SQ_IsDedicated);
+ g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence);
+ g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration(
+ "bool", "NSIsPlayerIndexLocalPlayer", "int playerIndex", "", SQ_IsPlayerIndexLocalPlayer);
+ g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration("bool", "NSIsDedicated", "", "", SQ_IsDedicated);
}