aboutsummaryrefslogtreecommitdiff
path: root/primedev/squirrel
diff options
context:
space:
mode:
authoruniboi <64006268+uniboi@users.noreply.github.com>2024-02-04 02:14:46 +0100
committerGitHub <noreply@github.com>2024-02-04 02:14:46 +0100
commitedf013952ca2d110f190dc8cd16e5529846656e4 (patch)
treeca219c17665810d94f2cb23b27f58fa9c82f3a62 /primedev/squirrel
parent6ad955ae0aab8b79910cb4a12777419a78a42a90 (diff)
downloadNorthstarLauncher-edf013952ca2d110f190dc8cd16e5529846656e4.tar.gz
NorthstarLauncher-edf013952ca2d110f190dc8cd16e5529846656e4.zip
Replaces the current plugin api with source interfaces. - backwards compatible - no more json in binaries (wtf) - does not rely on structs from third party libraries (wtf) - actually initializes variables - no more basically unused classes The launcher exposes almost everything required by plugins in interfaces that allow for backwards compatibility. The only thing that's passed to a plugin directly is the northstar dll HWND and a struct of data that's different for each plugin.
Diffstat (limited to 'primedev/squirrel')
-rw-r--r--primedev/squirrel/squirrel.cpp106
-rw-r--r--primedev/squirrel/squirrel.h8
-rw-r--r--primedev/squirrel/squirrelclasstypes.h10
3 files changed, 11 insertions, 113 deletions
diff --git a/primedev/squirrel/squirrel.cpp b/primedev/squirrel/squirrel.cpp
index affedebb..70dedcb8 100644
--- a/primedev/squirrel/squirrel.cpp
+++ b/primedev/squirrel/squirrel.cpp
@@ -6,8 +6,8 @@
#include "dedicated/dedicated.h"
#include "engine/r2engine.h"
#include "core/tier0.h"
-#include "plugins/plugin_abi.h"
#include "plugins/plugins.h"
+#include "plugins/pluginmanager.h"
#include "ns_version.h"
#include "core/vanilla.h"
@@ -157,79 +157,6 @@ const char* SQTypeNameFromID(int type)
return "";
}
-template <ScriptContext context> void SquirrelManager<context>::GenerateSquirrelFunctionsStruct(SquirrelFunctions* s)
-{
- s->RegisterSquirrelFunc = RegisterSquirrelFunc;
- s->__sq_defconst = __sq_defconst;
-
- s->__sq_compilebuffer = __sq_compilebuffer;
- s->__sq_call = __sq_call;
- s->__sq_raiseerror = __sq_raiseerror;
- s->__sq_compilefile = __sq_compilefile;
-
- s->__sq_newarray = __sq_newarray;
- s->__sq_arrayappend = __sq_arrayappend;
-
- s->__sq_newtable = __sq_newtable;
- s->__sq_newslot = __sq_newslot;
-
- s->__sq_pushroottable = __sq_pushroottable;
- s->__sq_pushstring = __sq_pushstring;
- s->__sq_pushinteger = __sq_pushinteger;
- s->__sq_pushfloat = __sq_pushfloat;
- s->__sq_pushbool = __sq_pushbool;
- s->__sq_pushasset = __sq_pushasset;
- s->__sq_pushvector = __sq_pushvector;
- s->__sq_pushobject = __sq_pushobject;
-
- s->__sq_getstring = __sq_getstring;
- s->__sq_getinteger = __sq_getinteger;
- s->__sq_getfloat = __sq_getfloat;
- s->__sq_getbool = __sq_getbool;
- s->__sq_get = __sq_get;
- s->__sq_getasset = __sq_getasset;
- s->__sq_getuserdata = __sq_getuserdata;
- s->__sq_getvector = __sq_getvector;
- s->__sq_getthisentity = __sq_getthisentity;
- s->__sq_getobject = __sq_getobject;
-
- s->__sq_stackinfos = __sq_stackinfos;
-
- s->__sq_createuserdata = __sq_createuserdata;
- s->__sq_setuserdatatypeid = __sq_setuserdatatypeid;
- s->__sq_getfunction = __sq_getfunction;
-
- s->__sq_schedule_call_external = AsyncCall_External;
-
- s->__sq_getentityfrominstance = __sq_getentityfrominstance;
- s->__sq_GetEntityConstant_CBaseEntity = __sq_GetEntityConstant_CBaseEntity;
-
- s->__sq_pushnewstructinstance = __sq_pushnewstructinstance;
- s->__sq_sealstructslot = __sq_sealstructslot;
-}
-
-// Allows for generating squirrelmessages from plugins.
-void AsyncCall_External(ScriptContext context, const char* func_name, SquirrelMessage_External_Pop function, void* userdata)
-{
- SquirrelMessage message {};
- message.functionName = func_name;
- message.isExternal = true;
- message.externalFunc = function;
- message.userdata = userdata;
- switch (context)
- {
- case ScriptContext::CLIENT:
- g_pSquirrel<ScriptContext::CLIENT>->messageBuffer->push(message);
- break;
- case ScriptContext::SERVER:
- g_pSquirrel<ScriptContext::SERVER>->messageBuffer->push(message);
- break;
- case ScriptContext::UI:
- g_pSquirrel<ScriptContext::UI>->messageBuffer->push(message);
- break;
- }
-}
-
// needed to define implementations for squirrelmanager outside of squirrel.h without compiler errors
template class SquirrelManager<ScriptContext::SERVER>;
template class SquirrelManager<ScriptContext::CLIENT>;
@@ -264,11 +191,11 @@ template <ScriptContext context> void SquirrelManager<context>::VMCreated(CSquir
defconst(m_pSQVM, pair.first.c_str(), bWasFound);
}
- auto loadedPlugins = &g_pPluginManager->m_vLoadedPlugins;
+ std::vector<Plugin> loadedPlugins = g_pPluginManager->GetLoadedPlugins();
for (const auto& pluginName : g_pModManager->m_PluginDependencyConstants)
{
- auto f = [&](Plugin plugin) -> bool { return plugin.dependencyName == pluginName; };
- defconst(m_pSQVM, pluginName.c_str(), std::find_if(loadedPlugins->begin(), loadedPlugins->end(), f) != loadedPlugins->end());
+ auto f = [&](Plugin plugin) -> bool { return plugin.GetDependencyName() == pluginName; };
+ defconst(m_pSQVM, pluginName.c_str(), std::find_if(loadedPlugins.begin(), loadedPlugins.end(), f) != loadedPlugins.end());
}
defconst(m_pSQVM, "MAX_FOLDER_SIZE", GetMaxSaveFolderSize() / 1024);
@@ -284,7 +211,7 @@ template <ScriptContext context> void SquirrelManager<context>::VMCreated(CSquir
defconst(m_pSQVM, "VANILLA", g_pVanillaCompatibility->GetVanillaCompatibility());
g_pSquirrel<context>->messageBuffer = new SquirrelMessageBuffer();
- g_pPluginManager->InformSQVMCreated(context, newSqvm);
+ g_pPluginManager->InformSqvmCreated(newSqvm);
}
template <ScriptContext context> void SquirrelManager<context>::VMDestroyed()
@@ -312,7 +239,7 @@ template <ScriptContext context> void SquirrelManager<context>::VMDestroyed()
}
}
- g_pPluginManager->InformSQVMDestroyed(context);
+ g_pPluginManager->InformSqvmDestroying(m_pSQVM);
// Discard the previous vm and delete the message buffer.
m_pSQVM = nullptr;
@@ -661,17 +588,10 @@ template <ScriptContext context> void SquirrelManager<context>::ProcessMessageBu
size_t argsAmount = message.args.size();
- if (message.isExternal && message.externalFunc != NULL)
+ for (auto& v : message.args)
{
- argsAmount = message.externalFunc(m_pSQVM->sqvm, message.userdata);
- }
- else
- {
- for (auto& v : message.args)
- {
- // Execute lambda to push arg to stack
- v();
- }
+ // Execute lambda to push arg to stack
+ v();
}
_call(m_pSQVM->sqvm, (SQInteger)argsAmount);
@@ -839,10 +759,6 @@ ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (CModule module))
g_pSquirrel<ScriptContext::CLIENT>->__sq_getfunction = module.Offset(0x6CB0).RCast<sq_getfunctionType>();
g_pSquirrel<ScriptContext::UI>->__sq_getfunction = g_pSquirrel<ScriptContext::CLIENT>->__sq_getfunction;
-
- SquirrelFunctions s = {};
- g_pSquirrel<ScriptContext::CLIENT>->GenerateSquirrelFunctionsStruct(&s);
- g_pPluginManager->InformSQVMLoad(ScriptContext::CLIENT, &s);
}
ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (CModule module))
@@ -921,10 +837,6 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (CModule module))
FCVAR_GAMEDLL | FCVAR_GAMEDLL_FOR_REMOTE_CLIENTS | FCVAR_CHEAT);
StubUnsafeSQFuncs<ScriptContext::SERVER>();
-
- SquirrelFunctions s = {};
- g_pSquirrel<ScriptContext::SERVER>->GenerateSquirrelFunctionsStruct(&s);
- g_pPluginManager->InformSQVMLoad(ScriptContext::SERVER, &s);
}
void InitialiseSquirrelManagers()
diff --git a/primedev/squirrel/squirrel.h b/primedev/squirrel/squirrel.h
index 17f4186d..0c1f24d3 100644
--- a/primedev/squirrel/squirrel.h
+++ b/primedev/squirrel/squirrel.h
@@ -3,7 +3,6 @@
#include "squirrelclasstypes.h"
#include "squirrelautobind.h"
#include "core/math/vector.h"
-#include "plugins/plugin_abi.h"
#include "mods/modmanager.h"
/*
@@ -51,8 +50,6 @@ const char* GetContextName_Short(ScriptContext context);
eSQReturnType SQReturnTypeFromString(const char* pReturnType);
const char* SQTypeNameFromID(const int iTypeId);
-void AsyncCall_External(ScriptContext context, const char* func_name, SquirrelMessage_External_Pop function, void* userdata);
-
ScriptContext ScriptContextFromString(std::string string);
namespace NS::log
@@ -417,7 +414,6 @@ public:
SQRESULT setupfunc(const SQChar* funcname);
void AddFuncOverride(std::string name, SQFunction func);
void ProcessMessageBuffer();
- void GenerateSquirrelFunctionsStruct(SquirrelFunctions* s);
};
template <ScriptContext context> SquirrelManager<context>* g_pSquirrel;
@@ -483,7 +479,7 @@ requires is_iterable<T>
inline VoidFunction SQMessageBufferPushArg(T& arg) {
FunctionVector localv = {};
localv.push_back([]{g_pSquirrel<context>->newarray(g_pSquirrel<context>->m_pSQVM->sqvm, 0);});
-
+
for (const auto& item : arg) {
localv.push_back(SQMessageBufferPushArg<context>(item));
localv.push_back([]{g_pSquirrel<context>->arrayappend(g_pSquirrel<context>->m_pSQVM->sqvm, -2);});
@@ -497,7 +493,7 @@ requires is_map<T>
inline VoidFunction SQMessageBufferPushArg(T& map) {
FunctionVector localv = {};
localv.push_back([]{g_pSquirrel<context>->newtable(g_pSquirrel<context>->m_pSQVM->sqvm);});
-
+
for (const auto& item : map) {
localv.push_back(SQMessageBufferPushArg<context>(item.first));
localv.push_back(SQMessageBufferPushArg<context>(item.second));
diff --git a/primedev/squirrel/squirrelclasstypes.h b/primedev/squirrel/squirrelclasstypes.h
index cd777551..91c3c468 100644
--- a/primedev/squirrel/squirrelclasstypes.h
+++ b/primedev/squirrel/squirrelclasstypes.h
@@ -116,18 +116,11 @@ concept is_iterable = requires(std::ranges::range_value_t<T> x)
// clang-format on
-typedef int (*SquirrelMessage_External_Pop)(HSquirrelVM* sqvm, void* userdata);
-typedef void (*sq_schedule_call_externalType)(
- ScriptContext context, const char* funcname, SquirrelMessage_External_Pop function, void* userdata);
-
class SquirrelMessage
{
public:
std::string functionName;
FunctionVector args;
- bool isExternal = false;
- void* userdata = NULL;
- SquirrelMessage_External_Pop externalFunc = NULL;
};
class SquirrelMessageBuffer
@@ -243,6 +236,3 @@ typedef SQRESULT (*sq_pushnewstructinstanceType)(HSquirrelVM* sqvm, int fieldCou
typedef SQRESULT (*sq_sealstructslotType)(HSquirrelVM* sqvm, int slotIndex);
#pragma endregion
-
-// These "external" versions of the types are for plugins
-typedef int64_t (*RegisterSquirrelFuncType_External)(ScriptContext context, SQFuncRegistration* funcReg, char unknown);