Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins v3 #472

Merged
merged 38 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d4b26c9
bump version
catornot May 14, 2023
eae6476
prototyping RunFrame for plugins
catornot May 14, 2023
374c961
add ptr to dlls to InformDLLLoad
catornot Jun 9, 2023
2f7a6a5
expose g_pCVar to plugins
catornot Jun 9, 2023
fa8c47f
improve async call for plugins
catornot Jun 10, 2023
fdccb6b
fmt
catornot Jun 10, 2023
0c3b4be
nuke presence for plugins
catornot Jun 12, 2023
447e18e
update sq functions and async call
catornot Jun 14, 2023
63fd065
completely nuke presence for plugins
catornot Jun 15, 2023
668466b
small changes to header files
catornot Jun 15, 2023
2054898
fix abi error not logging itself
catornot Jun 15, 2023
d0e0c63
actually push all the sq functions
catornot Jun 15, 2023
ca12e10
oops
catornot Jun 15, 2023
b694846
actually call RunFrame
catornot Jun 16, 2023
30a5de5
Merge branch 'R2Northstar:main' into pluginsv3
catornot Jun 18, 2023
91754a5
stuff idk trying to merge main
catornot Jun 25, 2023
d92fc1e
fix compile err
catornot Jun 25, 2023
6578331
merge main
catornot Jul 25, 2023
1d73e33
remove useless string include in plugin_abi.h
catornot Jul 25, 2023
3080cfd
Merge branch 'main' into pluginsv3
catornot Jul 28, 2023
d62934a
Merge branch 'main' into pluginsv3
catornot Aug 2, 2023
8eb6d96
remove PLUGINS.ipch
catornot Aug 2, 2023
b292371
inform plugins of all loaded dlls
catornot Aug 3, 2023
760a466
also call in LoadLibraryW
catornot Aug 4, 2023
caab7c8
Merge branch 'main' into pluginsv3
catornot Sep 8, 2023
611242a
extern C some functions in plugin_abi.h
catornot Sep 12, 2023
f9a965b
fix
catornot Sep 12, 2023
f3fbd2f
remove trailing comment
catornot Sep 19, 2023
090c974
remove HOSTSTATE.ipch
catornot Sep 19, 2023
08cd635
Merge branch 'main' into pluginsv3
catornot Sep 19, 2023
a6a2d6d
Merge branch 'main' into pluginsv3
GeckoEidechse Oct 10, 2023
04f8230
merge main
catornot Oct 16, 2023
6195047
add type information to PluginEngineData
catornot Oct 21, 2023
6f091ed
change static_cast to reinterpret_cast for previous commit
catornot Oct 21, 2023
4c4cb1b
add const back to some Plugin typedefs
catornot Oct 21, 2023
92e1497
Merge branch 'main' into pluginsv3
GeckoEidechse Nov 2, 2023
8fbb263
Merge branch 'main' into pluginsv3
GeckoEidechse Nov 5, 2023
5e99766
Merge branch 'main' into pluginsv3
GeckoEidechse Nov 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added HOSTSTATE.ipch
catornot marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
2 changes: 0 additions & 2 deletions NorthstarDLL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ add_library(NorthstarDLL SHARED
"shared/exploit_fixes/exploitfixes_utf8parser.cpp"
"shared/exploit_fixes/ns_limits.cpp"
"shared/exploit_fixes/ns_limits.h"
"shared/gamepresence.cpp"
"shared/gamepresence.h"
"shared/keyvalues.cpp"
"shared/keyvalues.h"
"shared/maxplayers.cpp"
Expand Down
1 change: 1 addition & 0 deletions NorthstarDLL/core/convar/convar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ON_DLL_LOAD("engine.dll", ConVar, (CModule module))
g_pPluginCommunicationhandler->m_sEngineData.conVarRegister = (void*)conVarRegister;
g_pPluginCommunicationhandler->m_sEngineData.ConVar_Vtable = (void*)g_pConVar_Vtable;
g_pPluginCommunicationhandler->m_sEngineData.IConVar_Vtable = (void*)g_pIConVar_Vtable;
g_pPluginCommunicationhandler->m_sEngineData.g_pCVar = (void*)R2::g_pCVar;
}

//-----------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions NorthstarDLL/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "plugins/plugins.h"
#include "util/version.h"
#include "squirrel/squirrel.h"
#include "shared/gamepresence.h"
#include "server/serverpresence.h"

#include "rapidjson/document.h"
Expand Down Expand Up @@ -58,7 +57,6 @@ bool InitialiseNorthstar()

g_pServerPresence = new ServerPresenceManager();

g_pGameStatePresence = new GameStatePresence();
g_pPluginManager = new PluginManager();
g_pPluginManager->LoadPlugins();

Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/engine/hoststate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void, __fastcall, (CHostState* self, double flCurrentTime, float flFrameTime))
if (g_pSquirrel<ScriptContext::SERVER>->m_pSQVM != nullptr && g_pSquirrel<ScriptContext::SERVER>->m_pSQVM->sqvm != nullptr)
g_pSquirrel<ScriptContext::SERVER>->ProcessMessageBuffer();

g_pGameStatePresence->RunFrame();
g_pPluginManager->RunFrame();
}

ON_DLL_LOAD_RELIESON("engine.dll", HostState, ConVar, (CModule module))
Expand Down
58 changes: 14 additions & 44 deletions NorthstarDLL/plugins/plugin_abi.h
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down Expand Up @@ -114,32 +110,7 @@ struct PluginEngineData
void* 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;
catornot marked this conversation as resolved.
Show resolved Hide resolved
catornot marked this conversation as resolved.
Show resolved Hide resolved
};

/// <summary> Async communication within the plugin system
Expand All @@ -157,8 +128,7 @@ 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
typedef void (*PLUGIN_INFORM_DLL_LOAD_TYPE)(PluginLoadDLL dll, void* data, void* dllPtr);
typedef void (*PLUGIN_RUNFRAME)();

// Northstar -> Plugin
typedef void (*PLUGIN_PUSH_PRESENCE_TYPE)(PluginGameStatePresence* data);
typedef void (*PLUGIN_INFORM_DLL_LOAD_TYPE)(PluginLoadDLL dll, void* data);
// Async Communication types
catornot marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 4 additions & 38 deletions NorthstarDLL/plugins/pluginbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,52 +42,18 @@ void PluginCommunicationHandler::PushRequest(PluginDataRequestType type, PluginR
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);
g_pPluginManager->InformDLLLoad(
catornot marked this conversation as resolved.
Show resolved Hide resolved
PluginLoadDLL::ENGINE, &g_pPluginCommunicationhandler->m_sEngineData, reinterpret_cast<void*>(module.m_nAddress));
}

ON_DLL_LOAD_RELIESON("client.dll", PluginBackendClient, ConCommand, (CModule module))
{
g_pPluginManager->InformDLLLoad(PluginLoadDLL::CLIENT, nullptr);
g_pPluginManager->InformDLLLoad(PluginLoadDLL::CLIENT, nullptr, reinterpret_cast<void*>(module.m_nAddress));
}

ON_DLL_LOAD_RELIESON("server.dll", PluginBackendServer, ConCommand, (CModule module))
{
g_pPluginManager->InformDLLLoad(PluginLoadDLL::SERVER, nullptr);
g_pPluginManager->InformDLLLoad(PluginLoadDLL::SERVER, nullptr, reinterpret_cast<void*>(module.m_nAddress));
}
3 changes: 0 additions & 3 deletions NorthstarDLL/plugins/pluginbackend.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "plugin_abi.h"
#include "shared/gamepresence.h"

#include <queue>
#include <mutex>
Expand Down Expand Up @@ -30,8 +29,6 @@ class PluginCommunicationHandler
void RunFrame();
void PushRequest(PluginDataRequestType type, PluginRespondDataCallable func);

void GeneratePresenceObjects();

public:
std::queue<PluginDataRequest> requestQueue;
std::mutex requestMutex;
Expand Down
18 changes: 9 additions & 9 deletions NorthstarDLL/plugins/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ std::optional<Plugin> PluginManager::LoadPlugin(fs::path path, PluginInitFuncs*
if (strcmp(manifestJSON["api_version"].GetString(), std::to_string(ABI_VERSION).c_str()))
{
NS::log::PLUGINSYS->error(
"'{}' has an incompatible API version number '{}' in its manifest. Current ABI version is '{}'", pathstring, ABI_VERSION);
"'{}' has an incompatible API version number in its manifest. Current ABI version is '{}'", pathstring, ABI_VERSION);
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
return std::nullopt;
}
// Passed all checks, going to actually load it now
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -300,24 +300,24 @@ void PluginManager::InformSQVMDestroyed(ScriptContext context)
}
}

void PluginManager::PushPresence(PluginGameStatePresence* data)
void PluginManager::InformDLLLoad(PluginLoadDLL 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, 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();
}
}
}
8 changes: 5 additions & 3 deletions NorthstarDLL/plugins/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(PluginLoadDLL dll, void* data, void* dllPtr);

void RunFrame();

private:
std::string pluginPath;
Expand Down
79 changes: 0 additions & 79 deletions NorthstarDLL/shared/gamepresence.cpp
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Loading