aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/plugins/pluginbackend.cpp
diff options
context:
space:
mode:
authorEmma Miler <emma.pi@protonmail.com>2023-04-11 20:49:16 +0200
committerGitHub <noreply@github.com>2023-04-11 20:49:16 +0200
commit450d0b1ed437cf37b4309af952af8904f3f07768 (patch)
tree3f0fd39b5663b5c3f4b9e76c70cc4987f22d66c7 /NorthstarDLL/plugins/pluginbackend.cpp
parent72da1da5b4c04ccc1154853a308cab6459c60b79 (diff)
downloadNorthstarLauncher-450d0b1ed437cf37b4309af952af8904f3f07768.tar.gz
NorthstarLauncher-450d0b1ed437cf37b4309af952af8904f3f07768.zip
Plugin system v2 (#343)
* Some work * Rewrite gamestate presence * Add plugin system logger * Format changes * Format chjange * Fix gamestate stuff * some callback stuff * move around invite stuff * move invite to funcs * fix presence server data * Actually call InformSQVMCreated * bruh * Fix TODO's * Formatting * Fix filters * Add InformDLLLoads * Fix plugin handle always being 0 * Formatting * Fix merge issues * Formatting * Mods can add files compiled at SQVM init * Some Small Fixes * Add changes from review * Fix load failure * Add new squirrel functions * actually call InformSQVMDestroyed * add CreateObject function * answers to complaints * remove snake cases from GameStatePresence --------- Co-authored-by: cat_or_not <41955154+catornot@users.noreply.github.com>
Diffstat (limited to 'NorthstarDLL/plugins/pluginbackend.cpp')
-rw-r--r--NorthstarDLL/plugins/pluginbackend.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/NorthstarDLL/plugins/pluginbackend.cpp b/NorthstarDLL/plugins/pluginbackend.cpp
new file mode 100644
index 00000000..b442d702
--- /dev/null
+++ b/NorthstarDLL/plugins/pluginbackend.cpp
@@ -0,0 +1,94 @@
+#include "pch.h"
+#include "pluginbackend.h"
+#include "plugin_abi.h"
+#include "server/serverpresence.h"
+#include "masterserver/masterserver.h"
+#include "squirrel/squirrel.h"
+#include "plugins.h"
+
+#include "core/convar/concommand.h"
+
+#define EXPORT extern "C" __declspec(dllexport)
+
+AUTOHOOK_INIT()
+
+PluginCommunicationHandler* g_pPluginCommunicationhandler;
+
+static PluginDataRequest storedRequest {PluginDataRequestType::END, (PluginRespondDataCallable) nullptr};
+
+void init_plugincommunicationhandler()
+{
+ g_pPluginCommunicationhandler = new PluginCommunicationHandler;
+ g_pPluginCommunicationhandler->requestQueue = {};
+}
+
+void PluginCommunicationHandler::RunFrame()
+{
+ std::lock_guard<std::mutex> lock(requestMutex);
+ if (!requestQueue.empty())
+ {
+ storedRequest = requestQueue.front();
+ switch (storedRequest.type)
+ {
+ default:
+ spdlog::error("{} was called with invalid request type '{}'", __FUNCTION__, static_cast<int>(storedRequest.type));
+ }
+ requestQueue.pop();
+ }
+}
+
+void PluginCommunicationHandler::PushRequest(PluginDataRequestType type, PluginRespondDataCallable func)
+{
+ std::lock_guard<std::mutex> lock(requestMutex);
+ requestQueue.push(PluginDataRequest {type, func});
+}
+
+void PluginCommunicationHandler::GeneratePresenceObjects()
+{
+ 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;
+
+ 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();
+
+ 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);
+}