diff options
-rw-r--r-- | NorthstarDLL/NorthstarDLL.vcxproj | 2 | ||||
-rw-r--r-- | NorthstarDLL/NorthstarDLL.vcxproj.filters | 5 | ||||
-rw-r--r-- | NorthstarDLL/clientchathooks.cpp | 31 | ||||
-rw-r--r-- | NorthstarDLL/miscserverscript.cpp | 35 | ||||
-rw-r--r-- | NorthstarDLL/scriptdatatables.cpp | 68 | ||||
-rw-r--r-- | NorthstarDLL/scriptjson.cpp | 41 | ||||
-rw-r--r-- | NorthstarDLL/scriptmainmenupromos.cpp | 20 | ||||
-rw-r--r-- | NorthstarDLL/scriptmodmenu.cpp | 100 | ||||
-rw-r--r-- | NorthstarDLL/scriptserverbrowser.cpp | 209 | ||||
-rw-r--r-- | NorthstarDLL/scriptutility.cpp | 21 | ||||
-rw-r--r-- | NorthstarDLL/serverchathooks.cpp | 21 | ||||
-rw-r--r-- | NorthstarDLL/squirrel.h | 21 | ||||
-rw-r--r-- | NorthstarDLL/squirrelautobind.cpp | 21 | ||||
-rw-r--r-- | NorthstarDLL/squirrelautobind.h | 76 |
14 files changed, 297 insertions, 374 deletions
diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index 894de139..9d66b854 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -558,6 +558,7 @@ <ClInclude Include="sourceinterface.h" />
<ClInclude Include="squirrel.h" />
<ClInclude Include="exploitfixes_utf8parser.cpp" />
+ <ClInclude Include="squirrelautobind.h" />
<ClInclude Include="tier0.h" />
<ClInclude Include="vector.h" />
<ClInclude Include="version.h" />
@@ -637,6 +638,7 @@ <ClCompile Include="sourceinterface.cpp" />
<ClCompile Include="squirrel.cpp" />
<ClCompile Include="exploitfixes.cpp" />
+ <ClCompile Include="squirrelautobind.cpp" />
<ClCompile Include="tier0.cpp" />
<ClCompile Include="version.cpp" />
</ItemGroup>
diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index b34f1c71..9241bb90 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -1488,6 +1488,8 @@ <ClInclude Include="vector.h">
<Filter>Header Files\Math</Filter>
</ClInclude>
+ <ClInclude Include="squirrelautobind.h">
+ <Filter>Header Files\Squirrel</Filter>
<ClInclude Include="keyvalues.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -1700,6 +1702,9 @@ <ClCompile Include="scriptdatatables.cpp">
<Filter>Source Files\Scripted</Filter>
</ClCompile>
+ <ClCompile Include="squirrelautobind.cpp">
+ <Filter>Source Files\Squirrel</Filter>
+ </ClCompile>
<ClCompile Include="kb_act.cpp">
<Filter>Source Files\Mods\Compiled Assets</Filter>
</ClCompile>
diff --git a/NorthstarDLL/clientchathooks.cpp b/NorthstarDLL/clientchathooks.cpp index a7a42689..3346ea2e 100644 --- a/NorthstarDLL/clientchathooks.cpp +++ b/NorthstarDLL/clientchathooks.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "squirrel.h" + #include "serverchathooks.h" #include "localchatwriter.h" @@ -43,41 +44,29 @@ void, __fastcall, (void* self, const char* message, int inboxId, bool isTeam, bo CHudChat__AddGameLine(hud, message, inboxId, isTeam, isDead); } -// void NSChatWrite( int context, string str ) -SQRESULT SQ_ChatWrite(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSChatWrite, "int context, string text", "", ScriptContext::CLIENT) { - int context = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + int chatContext = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); - LocalChatWriter((LocalChatWriter::Context)context).Write(str); + LocalChatWriter((LocalChatWriter::Context)chatContext).Write(str); return SQRESULT_NULL; } -// void NSChatWriteRaw( int context, string str ) -SQRESULT SQ_ChatWriteRaw(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSChatWriteRaw, "int context, string text", "", ScriptContext::CLIENT) { - int context = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + int chatContext = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); - LocalChatWriter((LocalChatWriter::Context)context).InsertText(str); + LocalChatWriter((LocalChatWriter::Context)chatContext).InsertText(str); return SQRESULT_NULL; } -// void NSChatWriteLine( int context, string str ) -SQRESULT SQ_ChatWriteLine(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSChatWriteLine, "int context, string text", "", ScriptContext::CLIENT) { - int context = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); + int chatContext = g_pSquirrel<ScriptContext::CLIENT>->getinteger(sqvm, 1); const char* str = g_pSquirrel<ScriptContext::CLIENT>->getstring(sqvm, 2); - LocalChatWriter((LocalChatWriter::Context)context).WriteLine(str); + LocalChatWriter((LocalChatWriter::Context)chatContext).WriteLine(str); return SQRESULT_NULL; } - -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientChatHooks, ClientSquirrel, (CModule module)) -{ - AUTOHOOK_DISPATCH() - - g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration("void", "NSChatWrite", "int context, string text", "", SQ_ChatWrite); - g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration("void", "NSChatWriteRaw", "int context, string text", "", SQ_ChatWriteRaw); - g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration("void", "NSChatWriteLine", "int context, string text", "", SQ_ChatWriteLine); -} diff --git a/NorthstarDLL/miscserverscript.cpp b/NorthstarDLL/miscserverscript.cpp index 758323ef..a8e7264b 100644 --- a/NorthstarDLL/miscserverscript.cpp +++ b/NorthstarDLL/miscserverscript.cpp @@ -8,22 +8,21 @@ #include <filesystem> -// void function NSEarlyWritePlayerPersistenceForLeave( entity player ) -SQRESULT SQ_EarlyWritePlayerPersistenceForLeave(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSEarlyWritePlayerPersistenceForLeave, "entity player", "", ScriptContext::SERVER) { - const R2::CBasePlayer* pPlayer = g_pSquirrel<ScriptContext::SERVER>->getentity<R2::CBasePlayer>(sqvm, 1); + const R2::CBasePlayer* pPlayer = g_pSquirrel<context>->getentity<R2::CBasePlayer>(sqvm, 1); if (!pPlayer) { spdlog::warn("NSEarlyWritePlayerPersistenceForLeave got null player"); - g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, false); + g_pSquirrel<context>->pushbool(sqvm, false); return SQRESULT_NOTNULL; } R2::CBaseClient* pClient = &R2::g_pClientArray[pPlayer->m_nPlayerIndex - 1]; if (g_pServerAuthentication->m_PlayerAuthenticationData.find(pClient) == g_pServerAuthentication->m_PlayerAuthenticationData.end()) { - g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, false); + g_pSquirrel<context>->pushbool(sqvm, false); return SQRESULT_NOTNULL; } @@ -32,42 +31,30 @@ SQRESULT SQ_EarlyWritePlayerPersistenceForLeave(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// bool function NSIsWritingPlayerPersistence() -SQRESULT SQ_IsWritingPlayerPersistence(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSIsWritingPlayerPersistence, "", "", ScriptContext::SERVER) { - g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, g_pMasterServerManager->m_bSavingPersistentData); + g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bSavingPersistentData); return SQRESULT_NOTNULL; } -// bool function NSIsPlayerLocalPlayer( entity player ) -SQRESULT SQ_IsPlayerLocalPlayer(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSIsPlayerLocalPlayer, "entity player", "", ScriptContext::SERVER) { const R2::CBasePlayer* pPlayer = g_pSquirrel<ScriptContext::SERVER>->getentity<R2::CBasePlayer>(sqvm, 1); if (!pPlayer) { spdlog::warn("NSIsPlayerLocalPlayer got null player"); - g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, false); + g_pSquirrel<context>->pushbool(sqvm, false); return SQRESULT_NOTNULL; } R2::CBaseClient* pClient = &R2::g_pClientArray[pPlayer->m_nPlayerIndex - 1]; - g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, !strcmp(R2::g_pLocalPlayerUserID, pClient->m_UID)); + g_pSquirrel<context>->pushbool(sqvm, !strcmp(R2::g_pLocalPlayerUserID, pClient->m_UID)); return SQRESULT_NOTNULL; } -// bool function NSIsDedicated() -SQRESULT SQ_IsDedicated(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSIsDedicated, "", "", ScriptContext::SERVER) { - g_pSquirrel<ScriptContext::SERVER>->pushbool(sqvm, IsDedicatedServer()); + g_pSquirrel<context>->pushbool(sqvm, IsDedicatedServer()); return SQRESULT_NOTNULL; } - -ON_DLL_LOAD_RELIESON("server.dll", MiscServerScriptCommands, ServerSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( - "void", "NSEarlyWritePlayerPersistenceForLeave", "entity player", "", SQ_EarlyWritePlayerPersistenceForLeave); - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence); - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration("bool", "NSIsPlayerLocalPlayer", "entity player", "", SQ_IsPlayerLocalPlayer); - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration("bool", "NSIsDedicated", "", "", SQ_IsDedicated); -} diff --git a/NorthstarDLL/scriptdatatables.cpp b/NorthstarDLL/scriptdatatables.cpp index fc2be943..dfa45737 100644 --- a/NorthstarDLL/scriptdatatables.cpp +++ b/NorthstarDLL/scriptdatatables.cpp @@ -97,7 +97,7 @@ Vector3 StringToVector(char* pString) } // var function GetDataTable( asset path ) -template <ScriptContext context> SQRESULT SQ_GetDatatable(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTable, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { const char* pAssetName; g_pSquirrel<context>->getasset(sqvm, 2, &pAssetName); @@ -271,8 +271,8 @@ template <ScriptContext context> SQRESULT SQ_GetDatatable(HSquirrelVM* sqvm) } } -// int function GetDataTableRowCount( var datatable, string columnName ) -template <ScriptContext context> SQRESULT SQ_GetDataTableColumnByName(HSquirrelVM* sqvm) +// int function GetDataTableColumnByName( var datatable, string columnName ) +REPLACE_SQFUNC(GetDataTableColumnByName, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -299,7 +299,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableColumnByName(HSquirrelV } // int function GetDataTableRowCount( var datatable ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowCount(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowCount, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -314,7 +314,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowCount(HSquirrelVM* s } // string function GetDataTableString( var datatable, int row, int col ) -template <ScriptContext context> SQRESULT SQ_GetDataTableString(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableString, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -341,7 +341,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableString(HSquirrelVM* sqv } // asset function GetDataTableAsset( var datatable, int row, int col ) -template <ScriptContext context> SQRESULT SQ_GetDataTableAsset(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableAsset, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -368,7 +368,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableAsset(HSquirrelVM* sqvm } // int function GetDataTableInt( var datatable, int row, int col ) -template <ScriptContext context> SQRESULT SQ_GetDataTableInt(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableInt, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -395,7 +395,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableInt(HSquirrelVM* sqvm) } // float function GetDataTableFloat( var datatable, int row, int col ) -template <ScriptContext context> SQRESULT SQ_GetDataTableFloat(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableFloat, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -422,7 +422,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableFloat(HSquirrelVM* sqvm } // bool function GetDataTableBool( var datatable, int row, int col ) -template <ScriptContext context> SQRESULT SQ_GetDataTableBool(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableBool, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -449,7 +449,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableBool(HSquirrelVM* sqvm) } // vector function GetDataTableVector( var datatable, int row, int col ) -template <ScriptContext context> SQRESULT SQ_GetDataTableVector(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableVector, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -476,7 +476,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableVector(HSquirrelVM* sqv } // int function GetDataTableRowMatchingStringValue( var datatable, int col, string value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingStringValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowMatchingStringValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -502,7 +502,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingStringValue( } // int function GetDataTableRowMatchingAssetValue( var datatable, int col, asset value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingAssetValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableMatchingAssetValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -529,7 +529,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingAssetValue(H } // int function GetDataTableRowMatchingFloatValue( var datatable, int col, float value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingFloatValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowMatchingFloatValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -555,7 +555,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingFloatValue(H } // int function GetDataTableRowMatchingIntValue( var datatable, int col, int value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingIntValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowMatchingIntValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -581,7 +581,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingIntValue(HSq } // int function GetDataTableRowMatchingVectorValue( var datatable, int col, vector value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingVectorValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowMatchingVectorValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -608,7 +608,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowMatchingVectorValue( } // int function GetDataTableRowGreaterThanOrEqualToIntValue( var datatable, int col, int value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowGreaterThanOrEqualToIntValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowGreaterThanOrEqualToIntValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -635,7 +635,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowGreaterThanOrEqualTo } // int function GetDataTableRowLessThanOrEqualToIntValue( var datatable, int col, int value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowLessThanOrEqualToIntValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowLessThanOrEqualToIntValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -661,7 +661,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowLessThanOrEqualToInt } // int function GetDataTableRowGreaterThanOrEqualToFloatValue( var datatable, int col, float value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowGreaterThanOrEqualToFloatValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowGreaterThanOrEqualToFloatValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -687,7 +687,7 @@ template <ScriptContext context> SQRESULT SQ_GetDataTableRowGreaterThanOrEqualTo } // int function GetDataTableRowLessThanOrEqualToFloatValue( var datatable, int col, float value ) -template <ScriptContext context> SQRESULT SQ_GetDataTableRowLessThanOrEqualToFloatValue(HSquirrelVM* sqvm) +REPLACE_SQFUNC(GetDataTableRowLessThanOrEqualToFloatValue, (ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)) { CSVData** pData; uint64_t typeId; @@ -886,43 +886,13 @@ void ConCommand_dump_datatables(const CCommand& args) DumpDatatable(datatable); } -template <ScriptContext context> void RegisterDataTableFunctions() -{ - g_pSquirrel<context>->AddFuncOverride("GetDataTable", SQ_GetDatatable<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableColumnByName", SQ_GetDataTableColumnByName<context>); - g_pSquirrel<context>->AddFuncOverride("GetDatatableRowCount", SQ_GetDataTableRowCount<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableString", SQ_GetDataTableString<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableInt", SQ_GetDataTableInt<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableFloat", SQ_GetDataTableFloat<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableBool", SQ_GetDataTableBool<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableAsset", SQ_GetDataTableAsset<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableVector", SQ_GetDataTableVector<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableRowMatchingStringValue", SQ_GetDataTableRowMatchingStringValue<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableRowMatchingAssetValue", SQ_GetDataTableRowMatchingAssetValue<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableRowMatchingFloatValue", SQ_GetDataTableRowMatchingFloatValue<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableRowMatchingIntValue", SQ_GetDataTableRowMatchingIntValue<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableRowMatchingVectorValue", SQ_GetDataTableRowMatchingVectorValue<context>); - g_pSquirrel<context>->AddFuncOverride( - "GetDataTableRowLessThanOrEqualToFloatValue", SQ_GetDataTableRowLessThanOrEqualToFloatValue<context>); - g_pSquirrel<context>->AddFuncOverride( - "GetDataTableRowGreaterThanOrEqualToFloatValue", SQ_GetDataTableRowGreaterThanOrEqualToFloatValue<context>); - g_pSquirrel<context>->AddFuncOverride("GetDataTableRowLessThanOrEqualToIntValue", SQ_GetDataTableRowLessThanOrEqualToIntValue<context>); - g_pSquirrel<context>->AddFuncOverride( - "GetDataTableRowGreaterThanOrEqualToFloatValue", SQ_GetDataTableRowGreaterThanOrEqualToIntValue<context>); -} - ON_DLL_LOAD_RELIESON("server.dll", ServerScriptDatatables, ServerSquirrel, (CModule module)) { - RegisterDataTableFunctions<ScriptContext::SERVER>(); - SQ_GetDatatableInternal<ScriptContext::SERVER> = module.Offset(0x1250f0).As<Datatable* (*)(HSquirrelVM*)>(); } ON_DLL_LOAD_RELIESON("client.dll", ClientScriptDatatables, ClientSquirrel, (CModule module)) { - RegisterDataTableFunctions<ScriptContext::CLIENT>(); - RegisterDataTableFunctions<ScriptContext::UI>(); - SQ_GetDatatableInternal<ScriptContext::CLIENT> = module.Offset(0x1C9070).As<Datatable* (*)(HSquirrelVM*)>(); SQ_GetDatatableInternal<ScriptContext::UI> = SQ_GetDatatableInternal<ScriptContext::CLIENT>; } diff --git a/NorthstarDLL/scriptjson.cpp b/NorthstarDLL/scriptjson.cpp index a9767615..8efad7b4 100644 --- a/NorthstarDLL/scriptjson.cpp +++ b/NorthstarDLL/scriptjson.cpp @@ -208,8 +208,12 @@ template <ScriptContext context> void EncodeJSONArray( } } -// table function DecodeJSON( string json, bool fatalParseErrors = false ) -template <ScriptContext context> SQRESULT SQ_DecodeJSON(HSquirrelVM* sqvm) +ADD_SQFUNC( + "table", + DecodeJSON, + "string json, bool fatalParseErrors = false", + "converts a json string to a squirrel table", + ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER) { const char* pJson = g_pSquirrel<context>->getstring(sqvm, 1); const bool bFatalParseErrors = g_pSquirrel<context>->getbool(sqvm, 2); @@ -236,8 +240,12 @@ template <ScriptContext context> SQRESULT SQ_DecodeJSON(HSquirrelVM* sqvm) DecodeJsonTable<context>(sqvm, (rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>*)&doc); } -// string function EncodeJSON( table data ) -template <ScriptContext context> SQRESULT SQ_EncodeJSON(HSquirrelVM* sqvm) +ADD_SQFUNC( + "string", + EncodeJSON, + "table data", + "converts a squirrel table to a json string", + ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER) { rapidjson_document doc; doc.SetObject(); @@ -255,28 +263,3 @@ template <ScriptContext context> SQRESULT SQ_EncodeJSON(HSquirrelVM* sqvm) g_pSquirrel<context>->pushstring(sqvm, pJsonString, -1); return SQRESULT_NOTNULL; } - -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientScriptJSON, ClientSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration( - "table", - "DecodeJSON", - "string json, bool fatalParseErrors = false", - "converts a json string to a squirrel table", - SQ_DecodeJSON<ScriptContext::CLIENT>); - g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration( - "string", "EncodeJSON", "table data", "converts a squirrel table to a json string", SQ_EncodeJSON<ScriptContext::CLIENT>); - - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "table", "DecodeJSON", "string json", "converts a json string to a squirrel table", SQ_DecodeJSON<ScriptContext::UI>); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "string", "EncodeJSON", "table data", "converts a squirrel table to a json string", SQ_EncodeJSON<ScriptContext::UI>); -} - -ON_DLL_LOAD_RELIESON("server.dll", ServerScriptJSON, ServerSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( - "table", "DecodeJSON", "string json", "converts a json string to a squirrel table", SQ_DecodeJSON<ScriptContext::SERVER>); - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( - "string", "EncodeJSON", "table data", "converts a squirrel table to a json string", SQ_EncodeJSON<ScriptContext::SERVER>); -} diff --git a/NorthstarDLL/scriptmainmenupromos.cpp b/NorthstarDLL/scriptmainmenupromos.cpp index a1277235..5f7a09c1 100644 --- a/NorthstarDLL/scriptmainmenupromos.cpp +++ b/NorthstarDLL/scriptmainmenupromos.cpp @@ -22,23 +22,19 @@ enum eMainMenuPromoDataProperty smallButton2Url, smallButton2ImageIndex }; - -// void function NSRequestCustomMainMenuPromos() -SQRESULT SQ_RequestCustomMainMenuPromos(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSRequestCustomMainMenuPromos, "", "", ScriptContext::UI) { g_pMasterServerManager->RequestMainMenuPromos(); return SQRESULT_NULL; } -// bool function NSHasCustomMainMenuPromoData() -SQRESULT SQ_HasCustomMainMenuPromoData(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSHasCustomMainMenuPromoData, "", "", ScriptContext::UI) { g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, g_pMasterServerManager->m_bHasMainMenuPromoData); return SQRESULT_NOTNULL; } -// var function NSGetCustomMainMenuPromoData( int promoDataKey ) -SQRESULT SQ_GetCustomMainMenuPromoData(HSquirrelVM* sqvm) +ADD_SQFUNC("var", NSGetCustomMainMenuPromoData, "int promoDataKey", "", ScriptContext::UI) { if (!g_pMasterServerManager->m_bHasMainMenuPromoData) return SQRESULT_NULL; @@ -125,12 +121,4 @@ SQRESULT SQ_GetCustomMainMenuPromoData(HSquirrelVM* sqvm) } return SQRESULT_NOTNULL; -} - -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptMainMenuPromos, ClientSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("void", "NSRequestCustomMainMenuPromos", "", "", SQ_RequestCustomMainMenuPromos); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("bool", "NSHasCustomMainMenuPromoData", "", "", SQ_HasCustomMainMenuPromoData); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "var", "NSGetCustomMainMenuPromoData", "int promoDataKey", "", SQ_GetCustomMainMenuPromoData); -} +}
\ No newline at end of file diff --git a/NorthstarDLL/scriptmodmenu.cpp b/NorthstarDLL/scriptmodmenu.cpp index d2f35285..df5dc101 100644 --- a/NorthstarDLL/scriptmodmenu.cpp +++ b/NorthstarDLL/scriptmodmenu.cpp @@ -2,31 +2,29 @@ #include "modmanager.h" #include "squirrel.h" -// array<string> function NSGetModNames() -SQRESULT SQ_GetModNames(HSquirrelVM* sqvm) +ADD_SQFUNC("array<string>", NSGetModNames, "", "", ScriptContext::UI) { - g_pSquirrel<ScriptContext::UI>->newarray(sqvm, 0); + g_pSquirrel<context>->newarray(sqvm, 0); for (Mod& mod : g_pModManager->m_LoadedMods) { - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, mod.Name.c_str()); - g_pSquirrel<ScriptContext::UI>->arrayappend(sqvm, -2); + g_pSquirrel<context>->pushstring(sqvm, mod.Name.c_str()); + g_pSquirrel<context>->arrayappend(sqvm, -2); } return SQRESULT_NOTNULL; } -// bool function NSIsModEnabled(string modName) -SQRESULT SQ_IsModEnabled(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSIsModEnabled, "string modName", "", ScriptContext::UI) { - const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1); + const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_LoadedMods) { if (!mod.Name.compare(modName)) { - g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, mod.m_bEnabled); + g_pSquirrel<context>->pushbool(sqvm, mod.m_bEnabled); return SQRESULT_NOTNULL; } } @@ -34,11 +32,10 @@ SQRESULT SQ_IsModEnabled(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// void function NSSetModEnabled(string modName, bool enabled) -SQRESULT SQ_SetModEnabled(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSSetModEnabled, "string modName, bool enabled", "", ScriptContext::UI) { - const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1); - const SQBool enabled = g_pSquirrel<ScriptContext::UI>->getbool(sqvm, 2); + const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1); + const SQBool enabled = g_pSquirrel<context>->getbool(sqvm, 2); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_LoadedMods) @@ -53,17 +50,16 @@ SQRESULT SQ_SetModEnabled(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// string function NSGetModDescriptionByModName(string modName) -SQRESULT SQ_GetModDescription(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetModDescriptionByModName, "string modName", "", ScriptContext::UI) { - const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1); + const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_LoadedMods) { if (!mod.Name.compare(modName)) { - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, mod.Description.c_str()); + g_pSquirrel<context>->pushstring(sqvm, mod.Description.c_str()); return SQRESULT_NOTNULL; } } @@ -71,17 +67,16 @@ SQRESULT SQ_GetModDescription(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// string function NSGetModVersionByModName(string modName) -SQRESULT SQ_GetModVersion(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetModVersionByModName, "string modName", "", ScriptContext::UI) { - const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1); + const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_LoadedMods) { if (!mod.Name.compare(modName)) { - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, mod.Version.c_str()); + g_pSquirrel<context>->pushstring(sqvm, mod.Version.c_str()); return SQRESULT_NOTNULL; } } @@ -89,17 +84,16 @@ SQRESULT SQ_GetModVersion(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// string function NSGetModDownloadLinkByModName(string modName) -SQRESULT SQ_GetModDownloadLink(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetModDownloadLinkByModName, "string modName", "", ScriptContext::UI) { - const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1); + const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_LoadedMods) { if (!mod.Name.compare(modName)) { - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, mod.DownloadLink.c_str()); + g_pSquirrel<context>->pushstring(sqvm, mod.DownloadLink.c_str()); return SQRESULT_NOTNULL; } } @@ -107,17 +101,16 @@ SQRESULT SQ_GetModDownloadLink(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// int function NSGetModLoadPriority(string modName) -SQRESULT SQ_GetModLoadPriority(HSquirrelVM* sqvm) +ADD_SQFUNC("int", NSGetModLoadPriority, "string modName", "", ScriptContext::UI) { - const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1); + const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_LoadedMods) { if (!mod.Name.compare(modName)) { - g_pSquirrel<ScriptContext::UI>->pushinteger(sqvm, mod.LoadPriority); + g_pSquirrel<context>->pushinteger(sqvm, mod.LoadPriority); return SQRESULT_NOTNULL; } } @@ -125,17 +118,16 @@ SQRESULT SQ_GetModLoadPriority(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// bool function NSIsModRequiredOnClient(string modName) -SQRESULT SQ_IsModRequiredOnClient(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSIsModRequiredOnClient, "string modName", "", ScriptContext::UI) { - const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1); + const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_LoadedMods) { if (!mod.Name.compare(modName)) { - g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, mod.RequiredOnClient); + g_pSquirrel<context>->pushbool(sqvm, mod.RequiredOnClient); return SQRESULT_NOTNULL; } } @@ -143,11 +135,10 @@ SQRESULT SQ_IsModRequiredOnClient(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// array<string> function NSGetModConvarsByModName(string modName) -SQRESULT SQ_GetModConvars(HSquirrelVM* sqvm) +ADD_SQFUNC("array<string>", NSGetModConvarsByModName, "string modName", "", ScriptContext::UI) { - const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1); - g_pSquirrel<ScriptContext::UI>->newarray(sqvm, 0); + const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1); + g_pSquirrel<context>->newarray(sqvm, 0); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->m_LoadedMods) @@ -156,8 +147,8 @@ SQRESULT SQ_GetModConvars(HSquirrelVM* sqvm) { for (ModConVar* cvar : mod.ConVars) { - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, cvar->Name.c_str()); - g_pSquirrel<ScriptContext::UI>->arrayappend(sqvm, -2); + g_pSquirrel<context>->pushstring(sqvm, cvar->Name.c_str()); + g_pSquirrel<context>->arrayappend(sqvm, -2); } return SQRESULT_NOTNULL; @@ -167,37 +158,8 @@ SQRESULT SQ_GetModConvars(HSquirrelVM* sqvm) return SQRESULT_NOTNULL; // return empty array } -// void function NSReloadMods() -SQRESULT SQ_ReloadMods(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSReloadMods, "", "", ScriptContext::UI) { g_pModManager->LoadMods(); return SQRESULT_NULL; } - -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptModMenu, ClientSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "array<string>", "NSGetModNames", "", "Returns the names of all loaded mods", SQ_GetModNames); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "bool", "NSIsModEnabled", "string modName", "Returns whether a given mod is enabled", SQ_IsModEnabled); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "void", "NSSetModEnabled", "string modName, bool enabled", "Sets whether a given mod is enabled", SQ_SetModEnabled); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "string", "NSGetModDescriptionByModName", "string modName", "Returns a given mod's description", SQ_GetModDescription); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "string", "NSGetModVersionByModName", "string modName", "Returns a given mod's version", SQ_GetModVersion); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "string", "NSGetModDownloadLinkByModName", "string modName", "Returns a given mod's download link", SQ_GetModDownloadLink); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "bool", - "NSIsModRequiredOnClient", - "string modName", - "Returns whether a given mod is required on connecting clients", - SQ_IsModRequiredOnClient); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "int", "NSGetModLoadPriority", "string modName", "Returns a given mod's load priority", SQ_GetModLoadPriority); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "array<string>", "NSGetModConvarsByModName", "string modName", "Returns the names of all a given mod's cvars", SQ_GetModConvars); - - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("void", "NSReloadMods", "", "Reloads mods", SQ_ReloadMods); -} diff --git a/NorthstarDLL/scriptserverbrowser.cpp b/NorthstarDLL/scriptserverbrowser.cpp index 5b2cf75f..e6066954 100644 --- a/NorthstarDLL/scriptserverbrowser.cpp +++ b/NorthstarDLL/scriptserverbrowser.cpp @@ -7,49 +7,43 @@ // functions for viewing server browser -// bool function NSIsMasterServerAuthenticated() -SQRESULT SQ_IsMasterServerAuthenticated(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSIsMasterServerAuthenticated, "", "", ScriptContext::UI) { - g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerDone); + g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerDone); return SQRESULT_NOTNULL; } -// void function NSRequestServerList() -SQRESULT SQ_RequestServerList(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSRequestServerList, "", "", ScriptContext::UI) { g_pMasterServerManager->RequestServerList(); return SQRESULT_NULL; } -// bool function NSIsRequestingServerList() -SQRESULT SQ_IsRequestingServerList(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSIsRequestingServerList, "", "", ScriptContext::UI) { - g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, g_pMasterServerManager->m_bScriptRequestingServerList); + g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bScriptRequestingServerList); return SQRESULT_NOTNULL; } -// bool function NSMasterServerConnectionSuccessful() -SQRESULT SQ_MasterServerConnectionSuccessful(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSMasterServerConnectionSuccessful, "", "", ScriptContext::UI) { - g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, g_pMasterServerManager->m_bSuccessfullyConnected); + g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bSuccessfullyConnected); return SQRESULT_NOTNULL; } -// int function NSGetServerCount() -SQRESULT SQ_GetServerCount(HSquirrelVM* sqvm) +ADD_SQFUNC("int", NSGetServerCount, "", "", ScriptContext::UI) { - g_pSquirrel<ScriptContext::UI>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers.size()); + g_pSquirrel<context>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers.size()); return SQRESULT_NOTNULL; } -// string function NSGetServerName( int serverIndex ) -SQRESULT SQ_GetServerName(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetServerName, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get name of server index {} when only {} servers are available", @@ -59,18 +53,17 @@ SQRESULT SQ_GetServerName(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].name); + g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].name); return SQRESULT_NOTNULL; } -// string function NSGetServerDescription( int serverIndex ) -SQRESULT SQ_GetServerDescription(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetServerDescription, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get description of server index {} when only {} servers are available", @@ -80,18 +73,17 @@ SQRESULT SQ_GetServerDescription(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].description.c_str()); + g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].description.c_str()); return SQRESULT_NOTNULL; } -// string function NSGetServerMap( int serverIndex ) -SQRESULT SQ_GetServerMap(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetServerMap, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get map of server index {} when only {} servers are available", @@ -101,18 +93,17 @@ SQRESULT SQ_GetServerMap(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].map); + g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].map); return SQRESULT_NOTNULL; } -// string function NSGetServerPlaylist( int serverIndex ) -SQRESULT SQ_GetServerPlaylist(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetServerPlaylist, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get playlist of server index {} when only {} servers are available", @@ -122,18 +113,17 @@ SQRESULT SQ_GetServerPlaylist(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].playlist); + g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].playlist); return SQRESULT_NOTNULL; } -// int function NSGetServerPlayerCount( int serverIndex ) -SQRESULT SQ_GetServerPlayerCount(HSquirrelVM* sqvm) +ADD_SQFUNC("int", NSGetServerPlayerCount, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get playercount of server index {} when only {} servers are available", @@ -143,18 +133,17 @@ SQRESULT SQ_GetServerPlayerCount(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].playerCount); + g_pSquirrel<context>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].playerCount); return SQRESULT_NOTNULL; } -// int function NSGetServerMaxPlayerCount( int serverIndex ) -SQRESULT SQ_GetServerMaxPlayerCount(HSquirrelVM* sqvm) +ADD_SQFUNC("int", NSGetServerMaxPlayerCount, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get max playercount of server index {} when only {} servers are available", @@ -164,18 +153,17 @@ SQRESULT SQ_GetServerMaxPlayerCount(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].maxPlayers); + g_pSquirrel<context>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].maxPlayers); return SQRESULT_NOTNULL; } -// string function NSGetServerID( int serverIndex ) -SQRESULT SQ_GetServerID(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetServerID, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get id of server index {} when only {} servers are available", @@ -185,18 +173,17 @@ SQRESULT SQ_GetServerID(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].id); + g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].id); return SQRESULT_NOTNULL; } -// bool function NSServerRequiresPassword( int serverIndex ) -SQRESULT SQ_ServerRequiresPassword(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSServerRequiresPassword, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get hasPassword of server index {} when only {} servers are available", @@ -206,18 +193,17 @@ SQRESULT SQ_ServerRequiresPassword(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].requiresPassword); + g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].requiresPassword); return SQRESULT_NOTNULL; } -// int function NSGetServerRequiredModsCount( int serverIndex ) -SQRESULT SQ_GetServerRequiredModsCount(HSquirrelVM* sqvm) +ADD_SQFUNC("int", NSGetServerRequiredModsCount, "int serverIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get required mods count of server index {} when only {} servers are available", @@ -227,19 +213,18 @@ SQRESULT SQ_GetServerRequiredModsCount(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()); + g_pSquirrel<context>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()); return SQRESULT_NOTNULL; } -// string function NSGetServerRequiredModName( int serverIndex, int modIndex ) -SQRESULT SQ_GetServerRequiredModName(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetServerRequiredModName, "int serverIndex, int modIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); - SQInteger modIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 2); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); + SQInteger modIndex = g_pSquirrel<context>->getinteger(sqvm, 2); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get hasPassword of server index {} when only {} servers are available", @@ -251,7 +236,7 @@ SQRESULT SQ_GetServerRequiredModName(HSquirrelVM* sqvm) if (modIndex >= g_pMasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get required mod name of mod index {} when only {} mod are available", @@ -261,20 +246,18 @@ SQRESULT SQ_GetServerRequiredModName(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushstring( - sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Name.c_str()); + g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Name.c_str()); return SQRESULT_NOTNULL; } -// string function NSGetServerRequiredModVersion( int serverIndex, int modIndex ) -SQRESULT SQ_GetServerRequiredModVersion(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetServerRequiredModVersion, "int serverIndex, int modIndex", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); - SQInteger modIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 2); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); + SQInteger modIndex = g_pSquirrel<context>->getinteger(sqvm, 2); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get required mod version of server index {} when only {} servers are available", @@ -286,7 +269,7 @@ SQRESULT SQ_GetServerRequiredModVersion(HSquirrelVM* sqvm) if (modIndex >= g_pMasterServerManager->m_vRemoteServers[serverIndex].requiredMods.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to get required mod version of mod index {} when only {} mod are available", @@ -296,13 +279,11 @@ SQRESULT SQ_GetServerRequiredModVersion(HSquirrelVM* sqvm) return SQRESULT_ERROR; } - g_pSquirrel<ScriptContext::UI>->pushstring( - sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Version.c_str()); + g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].requiredMods[modIndex].Version.c_str()); return SQRESULT_NOTNULL; } -// void function NSClearRecievedServerList() -SQRESULT SQ_ClearRecievedServerList(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSClearRecievedServerList, "", "", ScriptContext::UI) { g_pMasterServerManager->ClearServerList(); return SQRESULT_NULL; @@ -310,15 +291,14 @@ SQRESULT SQ_ClearRecievedServerList(HSquirrelVM* sqvm) // functions for authenticating with servers -// void function NSTryAuthWithServer( int serverIndex, string password = "" ) -SQRESULT SQ_TryAuthWithServer(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSTryAuthWithServer, "int serverIndex, string password = ''", "", ScriptContext::UI) { - SQInteger serverIndex = g_pSquirrel<ScriptContext::UI>->getinteger(sqvm, 1); - const SQChar* password = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 2); + SQInteger serverIndex = g_pSquirrel<context>->getinteger(sqvm, 1); + const SQChar* password = g_pSquirrel<context>->getstring(sqvm, 2); if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format( "Tried to auth with server index {} when only {} servers are available", @@ -343,26 +323,23 @@ SQRESULT SQ_TryAuthWithServer(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// bool function NSIsAuthenticatingWithServer() -SQRESULT SQ_IsAuthComplete(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSIsAuthenticatingWithServer, "", "", ScriptContext::UI) { - g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, g_pMasterServerManager->m_bScriptAuthenticatingWithGameServer); + g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bScriptAuthenticatingWithGameServer); return SQRESULT_NOTNULL; } -// bool function NSWasAuthSuccessful() -SQRESULT SQ_WasAuthSuccessful(HSquirrelVM* sqvm) +ADD_SQFUNC("bool", NSWasAuthSuccessful, "", "", ScriptContext::UI) { - g_pSquirrel<ScriptContext::UI>->pushbool(sqvm, g_pMasterServerManager->m_bSuccessfullyAuthenticatedWithGameServer); + g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bSuccessfullyAuthenticatedWithGameServer); return SQRESULT_NOTNULL; } -// void function NSConnectToAuthedServer() -SQRESULT SQ_ConnectToAuthedServer(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSConnectToAuthedServer, "", "", ScriptContext::UI) { if (!g_pMasterServerManager->m_bHasPendingConnectionInfo) { - g_pSquirrel<ScriptContext::UI>->raiseerror( + g_pSquirrel<context>->raiseerror( sqvm, fmt::format("Tried to connect to authed server before any pending connection info was available").c_str()); return SQRESULT_ERROR; } @@ -388,8 +365,7 @@ SQRESULT SQ_ConnectToAuthedServer(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// void function NSTryAuthWithLocalServer() -SQRESULT SQ_TryAuthWithLocalServer(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSTryAuthWithLocalServer, "", "", ScriptContext::UI) { // do auth request g_pMasterServerManager->AuthenticateWithOwnServer(R2::g_pLocalPlayerUserID, g_pMasterServerManager->m_sOwnClientAuthToken); @@ -397,8 +373,7 @@ SQRESULT SQ_TryAuthWithLocalServer(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// void function NSCompleteAuthWithLocalServer() -SQRESULT SQ_CompleteAuthWithLocalServer(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSCompleteAuthWithLocalServer, "", "", ScriptContext::UI) { // literally just set serverfilter // note: this assumes we have no authdata other than our own @@ -408,48 +383,8 @@ SQRESULT SQ_CompleteAuthWithLocalServer(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// string function NSGetAuthFailReason() -SQRESULT SQ_GetAuthFailReason(HSquirrelVM* sqvm) +ADD_SQFUNC("string", NSGetAuthFailReason, "", "", ScriptContext::UI) { - g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, g_pMasterServerManager->m_sAuthFailureReason.c_str(), -1); + g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_sAuthFailureReason.c_str(), -1); return SQRESULT_NOTNULL; } - -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptServerBrowser, ClientSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("bool", "NSIsMasterServerAuthenticated", "", "", SQ_IsMasterServerAuthenticated); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("void", "NSRequestServerList", "", "", SQ_RequestServerList); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("bool", "NSIsRequestingServerList", "", "", SQ_IsRequestingServerList); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "bool", "NSMasterServerConnectionSuccessful", "", "", SQ_MasterServerConnectionSuccessful); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("int", "NSGetServerCount", "", "", SQ_GetServerCount); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("void", "NSClearRecievedServerList", "", "", SQ_ClearRecievedServerList); - - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("string", "NSGetServerName", "int serverIndex", "", SQ_GetServerName); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("string", "NSGetServerDescription", "int serverIndex", "", SQ_GetServerDescription); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("string", "NSGetServerMap", "int serverIndex", "", SQ_GetServerMap); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("string", "NSGetServerPlaylist", "int serverIndex", "", SQ_GetServerPlaylist); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("int", "NSGetServerPlayerCount", "int serverIndex", "", SQ_GetServerPlayerCount); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "int", "NSGetServerMaxPlayerCount", "int serverIndex", "", SQ_GetServerMaxPlayerCount); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("string", "NSGetServerID", "int serverIndex", "", SQ_GetServerID); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "bool", "NSServerRequiresPassword", "int serverIndex", "", SQ_ServerRequiresPassword); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "int", "NSGetServerRequiredModsCount", "int serverIndex", "", SQ_GetServerRequiredModsCount); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "string", "NSGetServerRequiredModName", "int serverIndex, int modIndex", "", SQ_GetServerRequiredModName); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "string", "NSGetServerRequiredModVersion", "int serverIndex, int modIndex", "", SQ_GetServerRequiredModVersion); - - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "void", "NSTryAuthWithServer", "int serverIndex, string password = \"\"", "", SQ_TryAuthWithServer); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("bool", "NSIsAuthenticatingWithServer", "", "", SQ_IsAuthComplete); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("bool", "NSWasAuthSuccessful", "", "", SQ_WasAuthSuccessful); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("void", "NSConnectToAuthedServer", "", "", SQ_ConnectToAuthedServer); - - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("void", "NSTryAuthWithLocalServer", "", "", SQ_TryAuthWithLocalServer); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("void", "NSCompleteAuthWithLocalServer", "", "", SQ_CompleteAuthWithLocalServer); - - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("string", "NSGetAuthFailReason", "", "", SQ_GetAuthFailReason); -} diff --git a/NorthstarDLL/scriptutility.cpp b/NorthstarDLL/scriptutility.cpp index 7a1936cf..1ff8e4bb 100644 --- a/NorthstarDLL/scriptutility.cpp +++ b/NorthstarDLL/scriptutility.cpp @@ -2,22 +2,13 @@ #include "squirrel.h" // asset function StringToAsset( string assetName ) -template <ScriptContext context> SQRESULT SQ_StringToAsset(HSquirrelVM* sqvm) +ADD_SQFUNC( + "asset", + StringToAsset, + "string assetName", + "converts a given string to an asset", + ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER) { g_pSquirrel<context>->pushasset(sqvm, g_pSquirrel<context>->getstring(sqvm, 1), -1); return SQRESULT_NOTNULL; } - -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientSharedScriptUtility, ClientSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration( - "asset", "StringToAsset", "string assetName", "converts a given string to an asset", SQ_StringToAsset<ScriptContext::CLIENT>); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "asset", "StringToAsset", "string assetName", "converts a given string to an asset", SQ_StringToAsset<ScriptContext::UI>); -} - -ON_DLL_LOAD_RELIESON("server.dll", ServerSharedScriptUtility, ServerSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( - "asset", "StringToAsset", "string assetName", "converts a given string to an asset", SQ_StringToAsset<ScriptContext::SERVER>); -}
\ No newline at end of file diff --git a/NorthstarDLL/serverchathooks.cpp b/NorthstarDLL/serverchathooks.cpp index 31844c67..d97f1ebf 100644 --- a/NorthstarDLL/serverchathooks.cpp +++ b/NorthstarDLL/serverchathooks.cpp @@ -115,8 +115,7 @@ void ChatBroadcastMessage(int fromPlayerIndex, int toPlayerIndex, const char* te CRecipientFilter__Destruct(&filter); } -// void function NSSendMessage( int playerIndex, string text, bool isTeam ) -SQRESULT SQ_SendMessage(HSquirrelVM* sqvm) +ADD_SQFUNC("void", NSSendMessage, "int playerIndex, string text, bool isTeam", "", ScriptContext::SERVER) { int playerIndex = g_pSquirrel<ScriptContext::SERVER>->getinteger(sqvm, 1); const char* text = g_pSquirrel<ScriptContext::SERVER>->getstring(sqvm, 2); @@ -127,8 +126,12 @@ SQRESULT SQ_SendMessage(HSquirrelVM* sqvm) return SQRESULT_NULL; } -// void function NSBroadcastMessage( int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType ) -SQRESULT SQ_BroadcastMessage(HSquirrelVM* sqvm) +ADD_SQFUNC( + "void", + NSBroadcastMessage, + "int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType", + "", + ScriptContext::SERVER) { int fromPlayerIndex = g_pSquirrel<ScriptContext::SERVER>->getinteger(sqvm, 1); int toPlayerIndex = g_pSquirrel<ScriptContext::SERVER>->getinteger(sqvm, 2); @@ -170,14 +173,4 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerChatHooks, ServerSquirrel, (CModule mod MessageWriteByte = module.Offset(0x158A90).As<void(__fastcall*)(int)>(); MessageWriteString = module.Offset(0x158D00).As<void(__fastcall*)(const char*)>(); MessageWriteBool = module.Offset(0x158A00).As<void(__fastcall*)(bool)>(); - - // Chat sending functions - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( - "void", "NSSendMessage", "int playerIndex, string text, bool isTeam", "", SQ_SendMessage); - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( - "void", - "NSBroadcastMessage", - "int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType", - "", - SQ_BroadcastMessage); } diff --git a/NorthstarDLL/squirrel.h b/NorthstarDLL/squirrel.h index a157b1af..6142b157 100644 --- a/NorthstarDLL/squirrel.h +++ b/NorthstarDLL/squirrel.h @@ -1,6 +1,7 @@ #pragma once #include "squirreldatatypes.h" +#include "squirrelautobind.h" #include "vector.h" // stolen from ttf2sdk: sqvm types @@ -82,6 +83,26 @@ enum class ScriptContext : int UI, }; +static constexpr int operator&(ScriptContext first, ScriptContext second) +{ + return first == second; +} + +static constexpr int operator&(int first, ScriptContext second) +{ + return first & (1 << static_cast<int>(second)); +} + +static constexpr int operator|(ScriptContext first, ScriptContext second) +{ + return (1 << static_cast<int>(first)) + (1 << static_cast<int>(second)); +} + +static constexpr int operator|(int first, ScriptContext second) +{ + return first + (1 << static_cast<int>(second)); +} + const char* GetContextName(ScriptContext context); const char* GetContextName_Short(ScriptContext context); eSQReturnType SQReturnTypeFromString(const char* pReturnType); diff --git a/NorthstarDLL/squirrelautobind.cpp b/NorthstarDLL/squirrelautobind.cpp new file mode 100644 index 00000000..d5f42477 --- /dev/null +++ b/NorthstarDLL/squirrelautobind.cpp @@ -0,0 +1,21 @@ +#include "pch.h" +#include "squirrelautobind.h" + +SquirrelAutoBindContainer* g_pSqAutoBindContainer; + +ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrelAutoBind, ClientSquirrel, (CModule module)) +{ + spdlog::info("ClientSquirrelAutoBInd AutoBindFuncsVectorsize {}", g_pSqAutoBindContainer->clientSqAutoBindFuncs.size()); + for (auto& autoBindFunc : g_pSqAutoBindContainer->clientSqAutoBindFuncs) + { + autoBindFunc(); + } +} + +ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrelAutoBind, ServerSquirrel, (CModule module)) +{ + for (auto& autoBindFunc : g_pSqAutoBindContainer->serverSqAutoBindFuncs) + { + autoBindFunc(); + } +} diff --git a/NorthstarDLL/squirrelautobind.h b/NorthstarDLL/squirrelautobind.h new file mode 100644 index 00000000..865479a1 --- /dev/null +++ b/NorthstarDLL/squirrelautobind.h @@ -0,0 +1,76 @@ +#pragma once +#include <vector> + +typedef void (*SqAutoBindFunc)(); + +class SquirrelAutoBindContainer +{ + public: + std::vector<std::function<void()>> clientSqAutoBindFuncs; + std::vector<std::function<void()>> serverSqAutoBindFuncs; +}; + +extern SquirrelAutoBindContainer* g_pSqAutoBindContainer; + +class __squirrelautobind; + +#define ADD_SQFUNC(returnType, funcName, argTypes, helpText, runOnContext) \ + template <ScriptContext context> SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm); \ + namespace \ + { \ + __squirrelautobind CONCAT2(__squirrelautobind, __LINE__)( \ + []() \ + { \ + if constexpr (runOnContext & ScriptContext::UI) \ + g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( \ + returnType, __STR(funcName), argTypes, helpText, CONCAT2(Script_, funcName) < ScriptContext::UI >); \ + if constexpr (runOnContext & ScriptContext::CLIENT) \ + g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration( \ + returnType, __STR(funcName), argTypes, helpText, CONCAT2(Script_, funcName) < ScriptContext::CLIENT >); \ + }, \ + []() \ + { \ + if constexpr (runOnContext & ScriptContext::SERVER) \ + g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( \ + returnType, __STR(funcName), argTypes, helpText, CONCAT2(Script_, funcName) < ScriptContext::SERVER >); \ + }); \ + } \ + template <ScriptContext context> SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm) + +#define REPLACE_SQFUNC(funcName, runOnContext) \ + template <ScriptContext context> SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm); \ + namespace \ + { \ + __squirrelautobind CONCAT2(__squirrelautobind, __LINE__)( \ + []() \ + { \ + if constexpr (runOnContext & ScriptContext::UI) \ + g_pSquirrel<ScriptContext::UI>->AddFuncOverride(__STR(funcName), CONCAT2(Script_, funcName) < ScriptContext::UI >); \ + if constexpr (runOnContext & ScriptContext::CLIENT) \ + g_pSquirrel<ScriptContext::CLIENT>->AddFuncOverride( \ + __STR(funcName), CONCAT2(Script_, funcName) < ScriptContext::CLIENT >); \ + }, \ + []() \ + { \ + if constexpr (runOnContext & ScriptContext::SERVER) \ + g_pSquirrel<ScriptContext::SERVER>->AddFuncOverride( \ + __STR(funcName), CONCAT2(Script_, funcName) < ScriptContext::SERVER >); \ + }); \ + } \ + template <ScriptContext context> SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm) + +class __squirrelautobind +{ + public: + __squirrelautobind() = delete; + + __squirrelautobind(std::function<void()> clientAutoBindFunc, std::function<void()> serverAutoBindFunc) + { + // Bit hacky but we can't initialise this normally since this gets run automatically on load + if (g_pSqAutoBindContainer == nullptr) + g_pSqAutoBindContainer = new SquirrelAutoBindContainer(); + + g_pSqAutoBindContainer->clientSqAutoBindFuncs.push_back(clientAutoBindFunc); + g_pSqAutoBindContainer->serverSqAutoBindFuncs.push_back(serverAutoBindFunc); + } +}; |