aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/plugins
diff options
context:
space:
mode:
authorcat_or_not <41955154+catornot@users.noreply.github.com>2023-11-05 20:21:50 -0500
committerGitHub <noreply@github.com>2023-11-06 02:21:50 +0100
commitbb822b7638d5ae9bc4499ff76edc74f3741e6518 (patch)
tree558886bd28dc53d1004e235be1c1543c5ec2fd9f /NorthstarDLL/plugins
parent583bae6e1a7e35eec2c5cb4383bc0089f6ee6781 (diff)
downloadNorthstarLauncher-bb822b7638d5ae9bc4499ff76edc74f3741e6518.tar.gz
NorthstarLauncher-bb822b7638d5ae9bc4499ff76edc74f3741e6518.zip
- nuked presence logic ( moved to the discord rpc plugin ) - more exposed sq functions - exposed dll addresses - `g_pCVar` is exposed - added "userdata" to plugin's async call - added runframe to plugins
Diffstat (limited to 'NorthstarDLL/plugins')
-rw-r--r--NorthstarDLL/plugins/plugin_abi.h89
-rw-r--r--NorthstarDLL/plugins/pluginbackend.cpp53
-rw-r--r--NorthstarDLL/plugins/pluginbackend.h4
-rw-r--r--NorthstarDLL/plugins/plugins.cpp16
-rw-r--r--NorthstarDLL/plugins/plugins.h8
5 files changed, 60 insertions, 110 deletions
diff --git a/NorthstarDLL/plugins/plugin_abi.h b/NorthstarDLL/plugins/plugin_abi.h
index c9fa9d25..16b26a1c 100644
--- a/NorthstarDLL/plugins/plugin_abi.h
+++ b/NorthstarDLL/plugins/plugin_abi.h
@@ -1,16 +1,7 @@
#pragma once
-#include <string>
#include "squirrel/squirrelclasstypes.h"
-#define ABI_VERSION 2
-
-enum GameState
-{
- LOADING = 0,
- MAINMENU = 1,
- LOBBY = 2,
- INGAME = 3
-};
+#define ABI_VERSION 3
enum PluginLoadDLL
{
@@ -33,6 +24,7 @@ struct SquirrelFunctions
sq_compilebufferType __sq_compilebuffer;
sq_callType __sq_call;
sq_raiseerrorType __sq_raiseerror;
+ sq_compilefileType __sq_compilefile;
sq_newarrayType __sq_newarray;
sq_arrayappendType __sq_arrayappend;
@@ -48,10 +40,6 @@ struct SquirrelFunctions
sq_pushassetType __sq_pushasset;
sq_pushvectorType __sq_pushvector;
sq_pushobjectType __sq_pushobject;
- sq_getthisentityType __sq_getthisentity;
- sq_getobjectType __sq_getobject;
-
- sq_stackinfosType __sq_stackinfos;
sq_getstringType __sq_getstring;
sq_getintegerType __sq_getinteger;
@@ -61,14 +49,22 @@ struct SquirrelFunctions
sq_getassetType __sq_getasset;
sq_getuserdataType __sq_getuserdata;
sq_getvectorType __sq_getvector;
+ sq_getthisentityType __sq_getthisentity;
+ sq_getobjectType __sq_getobject;
+
+ sq_stackinfosType __sq_stackinfos;
sq_createuserdataType __sq_createuserdata;
sq_setuserdatatypeidType __sq_setuserdatatypeid;
sq_getfunctionType __sq_getfunction;
sq_schedule_call_externalType __sq_schedule_call_external;
+
sq_getentityfrominstanceType __sq_getentityfrominstance;
sq_GetEntityConstantType __sq_GetEntityConstant_CBaseEntity;
+
+ sq_pushnewstructinstanceType __sq_pushnewstructinstance;
+ sq_sealstructslotType __sq_sealstructslot;
};
struct MessageSource
@@ -89,9 +85,28 @@ struct LogMsg
int pluginHandle;
};
-typedef void (*loggerfunc_t)(LogMsg* msg);
-typedef void (*PLUGIN_RELAY_INVITE_TYPE)(const char* invite);
-typedef void* (*CreateObjectFunc)(ObjectType type);
+extern "C"
+{
+ typedef void (*loggerfunc_t)(LogMsg* msg);
+ typedef void (*PLUGIN_RELAY_INVITE_TYPE)(const char* invite);
+ typedef void* (*CreateObjectFunc)(ObjectType type);
+
+ typedef void (*PluginFnCommandCallback_t)(void* command);
+ typedef void (*PluginConCommandConstructorType)(
+ void* newCommand, const char* name, PluginFnCommandCallback_t callback, const char* helpString, int flags, void* parent);
+ typedef void (*PluginConVarRegisterType)(
+ void* pConVar,
+ const char* pszName,
+ const char* pszDefaultValue,
+ int nFlags,
+ const char* pszHelpString,
+ bool bMin,
+ float fMin,
+ bool bMax,
+ float fMax,
+ void* pCallback);
+ typedef void (*PluginConVarMallocType)(void* pConVarMaloc, int a2, int a3);
+}
struct PluginNorthstarData
{
@@ -109,37 +124,12 @@ struct PluginInitFuncs
struct PluginEngineData
{
- void* ConCommandConstructor;
- void* conVarMalloc;
- void* conVarRegister;
+ PluginConCommandConstructorType ConCommandConstructor;
+ PluginConVarMallocType conVarMalloc;
+ PluginConVarRegisterType conVarRegister;
void* ConVar_Vtable;
void* IConVar_Vtable;
-};
-
-struct PluginGameStatePresence
-{
- const char* id;
- const char* name;
- const char* description;
- const char* password;
-
- bool isServer;
- bool isLocal;
- GameState state;
-
- const char* map;
- const char* mapDisplayname;
- const char* playlist;
- const char* playlistDisplayname;
-
- int currentPlayers;
- int maxPlayers;
-
- int ownScore;
- int otherHighestScore; // NOTE: The highest score OR the second highest score if we have the highest
- int maxScore;
-
- int timestampEnd;
+ void* g_pCVar;
};
/// <summary> Async communication within the plugin system
@@ -157,8 +147,5 @@ typedef void (*PLUGIN_INIT_SQVM_TYPE)(SquirrelFunctions* funcs);
typedef void (*PLUGIN_INFORM_SQVM_CREATED_TYPE)(ScriptContext context, CSquirrelVM* sqvm);
typedef void (*PLUGIN_INFORM_SQVM_DESTROYED_TYPE)(ScriptContext context);
-// Async Communication types
-
-// Northstar -> Plugin
-typedef void (*PLUGIN_PUSH_PRESENCE_TYPE)(PluginGameStatePresence* data);
-typedef void (*PLUGIN_INFORM_DLL_LOAD_TYPE)(PluginLoadDLL dll, void* data);
+typedef void (*PLUGIN_INFORM_DLL_LOAD_TYPE)(const char* dll, PluginEngineData* data, void* dllPtr);
+typedef void (*PLUGIN_RUNFRAME)();
diff --git a/NorthstarDLL/plugins/pluginbackend.cpp b/NorthstarDLL/plugins/pluginbackend.cpp
index f9766235..850394ac 100644
--- a/NorthstarDLL/plugins/pluginbackend.cpp
+++ b/NorthstarDLL/plugins/pluginbackend.cpp
@@ -7,6 +7,8 @@
#include "core/convar/concommand.h"
+#include <filesystem>
+
#define EXPORT extern "C" __declspec(dllexport)
AUTOHOOK_INIT()
@@ -36,52 +38,13 @@ void PluginCommunicationHandler::PushRequest(PluginDataRequestType type, PluginR
requestQueue.push(PluginDataRequest {type, func});
}
-void PluginCommunicationHandler::GeneratePresenceObjects()
+void InformPluginsDLLLoad(fs::path dllPath, void* address)
{
- PluginGameStatePresence presence {};
-
- presence.id = g_pGameStatePresence->id.c_str();
- presence.name = g_pGameStatePresence->name.c_str();
- presence.description = g_pGameStatePresence->description.c_str();
- presence.password = g_pGameStatePresence->password.c_str();
-
- presence.isServer = g_pGameStatePresence->isServer;
- presence.isLocal = g_pGameStatePresence->isLocal;
-
- if (g_pGameStatePresence->isLoading)
- presence.state = GameState::LOADING;
- else if (g_pGameStatePresence->uiMap == "")
- presence.state = GameState::MAINMENU;
- else if (g_pGameStatePresence->map == "mp_lobby" && g_pGameStatePresence->isLocal && g_pGameStatePresence->isLobby)
- presence.state = GameState::LOBBY;
- else
- presence.state = GameState::INGAME;
+ std::string dllName = dllPath.filename().string();
- presence.map = g_pGameStatePresence->map.c_str();
- presence.mapDisplayname = g_pGameStatePresence->mapDisplayname.c_str();
- presence.playlist = g_pGameStatePresence->playlist.c_str();
- presence.playlistDisplayname = g_pGameStatePresence->playlistDisplayname.c_str();
+ void* data = NULL;
+ if (strncmp(dllName.c_str(), "engine.dll", 10) == 0)
+ data = &g_pPluginCommunicationhandler->m_sEngineData;
- presence.currentPlayers = g_pGameStatePresence->currentPlayers;
- presence.maxPlayers = g_pGameStatePresence->maxPlayers;
- presence.ownScore = g_pGameStatePresence->ownScore;
- presence.otherHighestScore = g_pGameStatePresence->otherHighestScore;
- presence.maxScore = g_pGameStatePresence->maxScore;
- presence.timestampEnd = g_pGameStatePresence->timestampEnd;
- g_pPluginManager->PushPresence(&presence);
-}
-
-ON_DLL_LOAD_RELIESON("engine.dll", PluginBackendEngine, ConCommand, (CModule module))
-{
- g_pPluginManager->InformDLLLoad(PluginLoadDLL::ENGINE, &g_pPluginCommunicationhandler->m_sEngineData);
-}
-
-ON_DLL_LOAD_RELIESON("client.dll", PluginBackendClient, ConCommand, (CModule module))
-{
- g_pPluginManager->InformDLLLoad(PluginLoadDLL::CLIENT, nullptr);
-}
-
-ON_DLL_LOAD_RELIESON("server.dll", PluginBackendServer, ConCommand, (CModule module))
-{
- g_pPluginManager->InformDLLLoad(PluginLoadDLL::SERVER, nullptr);
+ g_pPluginManager->InformDLLLoad(dllName.c_str(), data, address);
}
diff --git a/NorthstarDLL/plugins/pluginbackend.h b/NorthstarDLL/plugins/pluginbackend.h
index bcbccbd8..fc66a597 100644
--- a/NorthstarDLL/plugins/pluginbackend.h
+++ b/NorthstarDLL/plugins/pluginbackend.h
@@ -1,6 +1,5 @@
#pragma once
#include "plugin_abi.h"
-#include "shared/gamepresence.h"
#include <queue>
#include <mutex>
@@ -30,8 +29,6 @@ class PluginCommunicationHandler
void RunFrame();
void PushRequest(PluginDataRequestType type, PluginRespondDataCallable func);
- void GeneratePresenceObjects();
-
public:
std::queue<PluginDataRequest> requestQueue = {};
std::mutex requestMutex;
@@ -39,4 +36,5 @@ class PluginCommunicationHandler
PluginEngineData m_sEngineData {};
};
+void InformPluginsDLLLoad(fs::path dllPath, void* address);
extern PluginCommunicationHandler* g_pPluginCommunicationhandler;
diff --git a/NorthstarDLL/plugins/plugins.cpp b/NorthstarDLL/plugins/plugins.cpp
index 18610e2e..121512e5 100644
--- a/NorthstarDLL/plugins/plugins.cpp
+++ b/NorthstarDLL/plugins/plugins.cpp
@@ -174,10 +174,10 @@ std::optional<Plugin> PluginManager::LoadPlugin(fs::path path, PluginInitFuncs*
plugin.inform_sqvm_created = (PLUGIN_INFORM_SQVM_CREATED_TYPE)GetProcAddress(pluginLib, "PLUGIN_INFORM_SQVM_CREATED");
plugin.inform_sqvm_destroyed = (PLUGIN_INFORM_SQVM_DESTROYED_TYPE)GetProcAddress(pluginLib, "PLUGIN_INFORM_SQVM_DESTROYED");
- plugin.push_presence = (PLUGIN_PUSH_PRESENCE_TYPE)GetProcAddress(pluginLib, "PLUGIN_RECEIVE_PRESENCE");
-
plugin.inform_dll_load = (PLUGIN_INFORM_DLL_LOAD_TYPE)GetProcAddress(pluginLib, "PLUGIN_INFORM_DLL_LOAD");
+ plugin.run_frame = (PLUGIN_RUNFRAME)GetProcAddress(pluginLib, "PLUGIN_RUNFRAME");
+
plugin.handle = m_vLoadedPlugins.size();
plugin.logger = std::make_shared<ColoredLogger>(plugin.displayName.c_str(), NS::Colors::PLUGIN);
RegisterLogger(plugin.logger);
@@ -298,24 +298,24 @@ void PluginManager::InformSQVMDestroyed(ScriptContext context)
}
}
-void PluginManager::PushPresence(PluginGameStatePresence* data)
+void PluginManager::InformDLLLoad(const char* dll, void* data, void* dllPtr)
{
for (auto plugin : m_vLoadedPlugins)
{
- if (plugin.push_presence != NULL)
+ if (plugin.inform_dll_load != NULL)
{
- plugin.push_presence(data);
+ plugin.inform_dll_load(dll, (PluginEngineData*)data, dllPtr);
}
}
}
-void PluginManager::InformDLLLoad(PluginLoadDLL dll, void* data)
+void PluginManager::RunFrame()
{
for (auto plugin : m_vLoadedPlugins)
{
- if (plugin.inform_dll_load != NULL)
+ if (plugin.run_frame != NULL)
{
- plugin.inform_dll_load(dll, data);
+ plugin.run_frame();
}
}
}
diff --git a/NorthstarDLL/plugins/plugins.h b/NorthstarDLL/plugins/plugins.h
index ffa277d0..d91b2811 100644
--- a/NorthstarDLL/plugins/plugins.h
+++ b/NorthstarDLL/plugins/plugins.h
@@ -30,8 +30,9 @@ class Plugin
PLUGIN_INFORM_SQVM_CREATED_TYPE inform_sqvm_created;
PLUGIN_INFORM_SQVM_DESTROYED_TYPE inform_sqvm_destroyed;
- PLUGIN_PUSH_PRESENCE_TYPE push_presence;
PLUGIN_INFORM_DLL_LOAD_TYPE inform_dll_load;
+
+ PLUGIN_RUNFRAME run_frame;
};
class PluginManager
@@ -46,9 +47,10 @@ class PluginManager
void InformSQVMLoad(ScriptContext context, SquirrelFunctions* s);
void InformSQVMCreated(ScriptContext context, CSquirrelVM* sqvm);
void InformSQVMDestroyed(ScriptContext context);
- void PushPresence(PluginGameStatePresence* data);
- void InformDLLLoad(PluginLoadDLL dll, void* data);
+ void InformDLLLoad(const char* dll, void* data, void* dllPtr);
+
+ void RunFrame();
private:
std::string pluginPath;