2022-08-20 01:59:36 +02:00
|
|
|
#pragma once
|
2022-08-20 12:42:19 +02:00
|
|
|
#include "ipluginsystem.h"
|
2022-08-20 01:59:36 +02:00
|
|
|
|
2023-07-16 12:04:34 +02:00
|
|
|
#define PLUGIN_INSTALL_DIR "bin\\x64_retail\\plugins"
|
|
|
|
|
2022-12-12 17:16:39 +01:00
|
|
|
class CModAppSystemGroup;
|
2023-04-23 22:28:16 +01:00
|
|
|
class CServer;
|
|
|
|
class CClient;
|
|
|
|
struct user_creds_s;
|
2022-08-20 12:42:19 +02:00
|
|
|
|
2022-12-12 17:16:39 +01:00
|
|
|
template<typename T>
|
|
|
|
class CPluginCallbackList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CPluginCallbackList() : m_vCallbacks() {}
|
|
|
|
CPluginCallbackList(const vector<T>& cbs) : m_vCallbacks(cbs) {}
|
|
|
|
|
|
|
|
vector<T>& GetCallbacks() { return m_vCallbacks; }
|
|
|
|
|
|
|
|
operator bool()
|
|
|
|
{
|
|
|
|
return !this->m_vCallbacks.empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<T>& operator!()
|
|
|
|
{
|
|
|
|
return this->m_vCallbacks;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginCallbackList<T>& operator+=(const T& rhs)
|
|
|
|
{
|
|
|
|
if (rhs)
|
|
|
|
this->m_vCallbacks.push_back(rhs);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginCallbackList<T>& operator+=(const vector<T>& rhs)
|
|
|
|
{
|
|
|
|
for (auto it : rhs)
|
|
|
|
{
|
|
|
|
if (it)
|
|
|
|
this->m_vCallbacks.push_back(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginCallbackList<T>& operator-=(const T& rhs)
|
|
|
|
{
|
|
|
|
if (rhs) {
|
|
|
|
auto it = std::find(m_vCallbacks.begin(), m_vCallbacks.end(), rhs);
|
|
|
|
if (it != m_vCallbacks.end())
|
|
|
|
m_vCallbacks.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginCallbackList<T>& operator-=(const vector<T>& rhs)
|
|
|
|
{
|
|
|
|
for (auto itc : rhs)
|
|
|
|
{
|
|
|
|
if (itc) {
|
|
|
|
auto it = std::find(m_vCallbacks.begin(), m_vCallbacks.end(), itc);
|
|
|
|
if (it != m_vCallbacks.end())
|
|
|
|
m_vCallbacks.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector<T> m_vCallbacks;
|
|
|
|
};
|
|
|
|
|
2022-08-20 12:42:19 +02:00
|
|
|
class CPluginSystem : IPluginSystem
|
2022-08-20 01:59:36 +02:00
|
|
|
{
|
|
|
|
public:
|
2022-08-20 12:42:19 +02:00
|
|
|
struct PluginInstance_t
|
2022-08-20 01:59:36 +02:00
|
|
|
{
|
2022-08-20 12:42:19 +02:00
|
|
|
PluginInstance_t(string svPluginName, string svPluginFullPath) : m_svPluginName(svPluginName), m_svPluginFullPath(svPluginFullPath), m_svDescription(std::string()), m_bIsLoaded(false) {};
|
2022-08-20 01:59:36 +02:00
|
|
|
|
|
|
|
// Might wanna make a status code system.
|
2023-05-08 19:28:16 +01:00
|
|
|
typedef bool(*OnLoad)(const char*, const char*);
|
2022-08-21 00:59:55 +02:00
|
|
|
typedef void(*OnUnload)();
|
2022-08-20 01:59:36 +02:00
|
|
|
|
|
|
|
CModule m_hModule;
|
|
|
|
string m_svPluginName;
|
|
|
|
string m_svPluginFullPath;
|
|
|
|
string m_svDescription;
|
|
|
|
bool m_bIsLoaded; // [ PIXIE ]: I don't like this and it's bad.
|
2022-09-09 19:47:31 +02:00
|
|
|
// I will make a module manager later which will grab all modules from the process and adds each module / removes module that passes through DLLMain.
|
2022-08-20 01:59:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void PluginSystem_Init();
|
2022-08-20 12:42:19 +02:00
|
|
|
bool ReloadPluginInstance(PluginInstance_t& pluginInst);
|
|
|
|
bool LoadPluginInstance(PluginInstance_t& pluginInst);
|
|
|
|
bool UnloadPluginInstance(PluginInstance_t& pluginInst);
|
2022-12-12 17:16:39 +01:00
|
|
|
void AddPluginCallback(PluginHelpWithAnything_t* help);
|
|
|
|
void RemovePluginCallback(PluginHelpWithAnything_t* help);
|
2022-08-20 12:42:19 +02:00
|
|
|
|
|
|
|
vector<PluginInstance_t>& GetPluginInstances();
|
|
|
|
|
|
|
|
virtual void* HelpWithAnything(PluginHelpWithAnything_t* help);
|
2022-08-20 01:59:36 +02:00
|
|
|
|
2022-12-12 17:16:39 +01:00
|
|
|
#define CREATE_PLUGIN_CALLBACK(typeName, type, funcName, varName) public: using typeName = type; CPluginCallbackList<typeName>& funcName() { return varName; } private: CPluginCallbackList<typeName> varName;
|
|
|
|
|
|
|
|
CREATE_PLUGIN_CALLBACK(CreateFn, bool(*)(CModAppSystemGroup*), GetCreateCallbacks, createCallbacks);
|
2023-04-23 22:28:16 +01:00
|
|
|
CREATE_PLUGIN_CALLBACK(ConnectClientFn, bool(*)(CServer*, CClient*, user_creds_s*), GetConnectClientCallbacks, connectClientCallbacks);
|
2022-12-12 17:16:39 +01:00
|
|
|
|
|
|
|
#undef CREATE_PLUGIN_CALLBACK
|
|
|
|
|
2022-08-20 01:59:36 +02:00
|
|
|
private:
|
2022-08-20 12:42:19 +02:00
|
|
|
vector<PluginInstance_t> pluginInstances;
|
2022-08-20 01:59:36 +02:00
|
|
|
};
|
2022-08-20 11:42:22 +02:00
|
|
|
extern CPluginSystem* g_pPluginSystem;
|
2022-12-12 17:16:39 +01:00
|
|
|
|
|
|
|
// Monitor this and performance profile this if fps drops are detected.
|
|
|
|
#define CALL_PLUGIN_CALLBACKS(callback, ...) \
|
|
|
|
for (auto& cb : !callback) \
|
|
|
|
cb(__VA_ARGS__)
|