aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
authorMaya <malte.hoermeyer@web.de>2022-07-09 00:17:05 +0200
committerGitHub <noreply@github.com>2022-07-09 00:17:05 +0200
commit9f8190486e04c66483dc8cd0ca9fd92fc732789a (patch)
treecd65b6d8a74e02ce35cce30e9be706428ac246a6 /NorthstarDedicatedTest
parent5995a7462da970ee2102a0dd0047ebbcef519dd0 (diff)
downloadNorthstarLauncher-9f8190486e04c66483dc8cd0ca9fd92fc732789a.tar.gz
NorthstarLauncher-9f8190486e04c66483dc8cd0ca9fd92fc732789a.zip
Add StringToAsset function to squirrel (#216)
* Add StringToAsset function to squirrel also added better values for return type enum because otherwise asset can't be returned without casting * Formatting * Switched to a template for the stringToAsset function also renamed files but have to do it in 2 commits because git ignores file case * Rename step 2 * change to lowercase in include * changed to lowercase in include inside dllmain
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj2
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters6
-rw-r--r--NorthstarDedicatedTest/dllmain.cpp3
-rw-r--r--NorthstarDedicatedTest/scriptutility.cpp29
-rw-r--r--NorthstarDedicatedTest/scriptutility.h4
-rw-r--r--NorthstarDedicatedTest/squirrel.cpp29
-rw-r--r--NorthstarDedicatedTest/squirrel.h25
7 files changed, 96 insertions, 2 deletions
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
index ea9ccbb3..ff6ca2ea 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
@@ -121,6 +121,7 @@
<ClInclude Include="ns_version.h" />
<ClInclude Include="plugins.h" />
<ClInclude Include="plugin_abi.h" />
+ <ClInclude Include="scriptutility.h" />
<ClInclude Include="serverchathooks.h" />
<ClInclude Include="clientauthhooks.h" />
<ClInclude Include="color.h" />
@@ -616,6 +617,7 @@
<ClCompile Include="scriptmodmenu.cpp" />
<ClCompile Include="scriptserverbrowser.cpp" />
<ClCompile Include="scriptsrson.cpp" />
+ <ClCompile Include="scriptutility.cpp" />
<ClCompile Include="serverauthentication.cpp" />
<ClCompile Include="miscserverscript.cpp" />
<ClCompile Include="serverchathooks.cpp" />
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
index 576b9004..0e48f4a0 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
@@ -1515,6 +1515,9 @@
<ClInclude Include="NSMem.h">
<Filter>Header Files\Shared\ExploitFixes</Filter>
</ClInclude>
+ <ClInclude Include="scriptutility.h">
+ <Filter>Header Files\Shared</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@@ -1682,6 +1685,9 @@
<ClCompile Include="clientruihooks.cpp">
<Filter>Source Files\Client</Filter>
</ClCompile>
+ <ClCompile Include="scriptutility.cpp">
+ <Filter>Source Files\Shared</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<MASM Include="audio_asm.asm">
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index 04cb883b..d64cc34f 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -45,6 +45,7 @@
#include <string.h>
#include "version.h"
#include "pch.h"
+#include "scriptutility.h"
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
@@ -255,6 +256,7 @@ bool InitialiseNorthstar()
AddDllLoadCallbackForClient("client.dll", InitialiseClientVideoOverrides);
AddDllLoadCallbackForClient("engine.dll", InitialiseEngineClientRUIHooks);
AddDllLoadCallbackForClient("engine.dll", InitialiseDebugOverlay);
+ AddDllLoadCallbackForClient("client.dll", InitialiseClientSquirrelUtilityFunctions);
// audio hooks
AddDllLoadCallbackForClient("client.dll", InitialiseMilesAudioHooks);
}
@@ -267,6 +269,7 @@ bool InitialiseNorthstar()
AddDllLoadCallback("server.dll", InitialiseMiscServerScriptCommand);
AddDllLoadCallback("server.dll", InitialiseMiscServerFixes);
AddDllLoadCallback("server.dll", InitialiseBuildAINFileHooks);
+ AddDllLoadCallback("server.dll", InitialiseServerSquirrelUtilityFunctions);
AddDllLoadCallback("engine.dll", InitialisePlaylistHooks);
diff --git a/NorthstarDedicatedTest/scriptutility.cpp b/NorthstarDedicatedTest/scriptutility.cpp
new file mode 100644
index 00000000..98c6f3a3
--- /dev/null
+++ b/NorthstarDedicatedTest/scriptutility.cpp
@@ -0,0 +1,29 @@
+#include "pch.h"
+#include "scriptutility.h"
+#include "squirrel.h"
+
+template <ScriptContext context> SQRESULT SQ_StringToAsset(void* sqvm)
+{
+ if (context == ScriptContext::SERVER)
+ {
+ const char* asset = ServerSq_getstring(sqvm, 1);
+ ServerSq_pushAsset(sqvm, asset, -1);
+ }
+ else
+ {
+ const char* asset = ClientSq_getstring(sqvm, 1);
+ ClientSq_pushAsset(sqvm, asset, -1);
+ }
+ return SQRESULT_NOTNULL;
+}
+
+void InitialiseClientSquirrelUtilityFunctions(HMODULE baseAddress)
+{
+ g_ClientSquirrelManager->AddFuncRegistration("asset", "StringToAsset", "string assetName", "", SQ_StringToAsset<ScriptContext::CLIENT>);
+ g_UISquirrelManager->AddFuncRegistration("asset", "StringToAsset", "string assetName", "", SQ_StringToAsset<ScriptContext::UI>);
+}
+
+void InitialiseServerSquirrelUtilityFunctions(HMODULE baseAddress)
+{
+ g_ServerSquirrelManager->AddFuncRegistration("asset", "StringToAsset", "string assetName", "", SQ_StringToAsset<ScriptContext::SERVER>);
+} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/scriptutility.h b/NorthstarDedicatedTest/scriptutility.h
new file mode 100644
index 00000000..2b58ebfb
--- /dev/null
+++ b/NorthstarDedicatedTest/scriptutility.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void InitialiseClientSquirrelUtilityFunctions(HMODULE baseAddress);
+void InitialiseServerSquirrelUtilityFunctions(HMODULE baseAddress); \ No newline at end of file
diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp
index b1c5b4a8..d0d54a3a 100644
--- a/NorthstarDedicatedTest/squirrel.cpp
+++ b/NorthstarDedicatedTest/squirrel.cpp
@@ -72,6 +72,9 @@ sq_pushboolType ServerSq_pushbool;
sq_pusherrorType ClientSq_pusherror;
sq_pusherrorType ServerSq_pusherror;
+sq_pushAssetType ClientSq_pushAsset;
+sq_pushAssetType ServerSq_pushAsset;
+
// sq stack get funcs
sq_getstringType ClientSq_getstring;
sq_getstringType ServerSq_getstring;
@@ -136,6 +139,7 @@ void InitialiseClientSquirrel(HMODULE baseAddress)
ClientSq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800);
ClientSq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710);
ClientSq_pusherror = (sq_pusherrorType)((char*)baseAddress + 0x8470);
+ ClientSq_pushAsset = (sq_pushAssetType)((char*)baseAddress + 0x3560);
ClientSq_getstring = (sq_getstringType)((char*)baseAddress + 0x60C0);
ClientSq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60E0);
@@ -190,6 +194,7 @@ void InitialiseServerSquirrel(HMODULE baseAddress)
ServerSq_pushfloat = (sq_pushfloatType)((char*)baseAddress + 0x3800);
ServerSq_pushbool = (sq_pushboolType)((char*)baseAddress + 0x3710);
ServerSq_pusherror = (sq_pusherrorType)((char*)baseAddress + 0x8440);
+ ServerSq_pushAsset = (sq_pushAssetType)((char*)baseAddress + 0x3560);
ServerSq_getstring = (sq_getstringType)((char*)baseAddress + 0x60A0);
ServerSq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60C0);
@@ -485,4 +490,28 @@ template <ScriptContext context> int64_t RegisterSquirrelFuncHook(void* sqvm, SQ
return ServerRegisterSquirrelFunc(sqvm, funcReg, unknown);
else
return ClientRegisterSquirrelFunc(sqvm, funcReg, unknown);
+}
+
+SQReturnTypeEnum GetReturnTypeEnumFromString(const char* returnTypeString)
+{
+
+ static std::map<std::string, SQReturnTypeEnum> sqEnumStrMap = {
+ {"bool", SqReturnBoolean},
+ {"float", SqReturnFloat},
+ {"vector", SqReturnVector},
+ {"int", SqReturnInteger},
+ {"entity", SqReturnEntity},
+ {"string", SqReturnString},
+ {"array", SqReturnArrays},
+ {"asset", SqReturnAsset},
+ {"table", SqReturnTable}};
+
+ if (sqEnumStrMap.count(returnTypeString))
+ {
+ return sqEnumStrMap[returnTypeString];
+ }
+ else
+ {
+ return SqReturnDefault; // previous default value
+ }
} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h
index d6dfcc57..cbdf0c8c 100644
--- a/NorthstarDedicatedTest/squirrel.h
+++ b/NorthstarDedicatedTest/squirrel.h
@@ -18,6 +18,20 @@ const SQRESULT SQRESULT_NOTNULL = 1;
typedef SQInteger (*SQFunction)(void* sqvm);
+enum SQReturnTypeEnum
+{
+ SqReturnFloat = 0x1,
+ SqReturnVector = 0x3,
+ SqReturnInteger = 0x5,
+ SqReturnBoolean = 0x6,
+ SqReturnEntity = 0xD,
+ SqReturnString = 0x21,
+ SqReturnDefault = 0x20,
+ SqReturnArrays = 0x25,
+ SqReturnAsset = 0x28,
+ SqReturnTable = 0x26,
+};
+
struct CompileBufferState
{
const SQChar* buffer;
@@ -43,7 +57,7 @@ struct SQFuncRegistration
__int32 devLevel;
const char* shortNameMaybe;
__int32 unknown2;
- __int32 returnTypeEnum;
+ SQReturnTypeEnum returnTypeEnum;
__int32* externalBufferPointer;
__int64 externalBufferSize;
__int64 unknown3;
@@ -53,10 +67,12 @@ struct SQFuncRegistration
SQFuncRegistration()
{
memset(this, 0, sizeof(SQFuncRegistration));
- this->returnTypeEnum = 32;
+ this->returnTypeEnum = SqReturnDefault;
}
};
+SQReturnTypeEnum GetReturnTypeEnumFromString(const char* returnTypeString);
+
// core sqvm funcs
typedef SQRESULT (*sq_compilebufferType)(void* sqvm, CompileBufferState* compileBuffer, const char* file, int a1, ScriptContext a2);
extern sq_compilebufferType ClientSq_compilebuffer;
@@ -105,6 +121,10 @@ typedef SQInteger (*sq_pusherrorType)(void* sqvm, const SQChar* error);
extern sq_pusherrorType ClientSq_pusherror;
extern sq_pusherrorType ServerSq_pusherror;
+typedef SQRESULT (*sq_pushAssetType)(void* sqvm, const SQChar* assetName, SQInteger nameLength);
+extern sq_pushAssetType ServerSq_pushAsset;
+extern sq_pushAssetType ClientSq_pushAsset;
+
// sq stack get funcs
typedef const SQChar* (*sq_getstringType)(void* sqvm, SQInteger stackpos);
extern sq_getstringType ClientSq_getstring;
@@ -277,6 +297,7 @@ template <ScriptContext context> class SquirrelManager
reg->returnTypeString = new char[returnType.size() + 1];
strcpy((char*)reg->returnTypeString, returnType.c_str());
+ reg->returnTypeEnum = GetReturnTypeEnumFromString(returnType.c_str());
reg->argTypes = new char[argTypes.size() + 1];
strcpy((char*)reg->argTypes, argTypes.c_str());