r5sdk/r5dev/pluginsdk/pluginsdk.cpp
Kawe Mazidjatari 6f441292d0 CModule construction optimization
Moved construction logic to separate method, and call that from constructor instead. When willing to change the entire context on the same object, you can now just call 'InitFromXXXX()'. Previously, a whole new object would be generated and copied into ours, and then deleted again.
2023-07-10 13:54:00 +02:00

71 lines
2.6 KiB
C++

//=============================================================================//
//
// Purpose: plugin sdk that makes plugins run!
//
//-----------------------------------------------------------------------------
//
//=============================================================================//
#include "core/stdafx.h"
#include "ifactory.h"
#include "pluginsystem/ipluginsystem.h"
#include "pluginsdk.h"
//---------------------------------------------------------------------------------
// Purpose: constructor
// Input : pszSelfModule -
//---------------------------------------------------------------------------------
CPluginSDK::CPluginSDK(const char* pszSelfModule) : m_FactoryInstance(nullptr), m_PluginSystem(nullptr)
{
m_SelfModule.InitFromName(pszSelfModule);
// !TODO: Use PEB!
m_GameModule.InitFromName("r5apex.exe");
}
//---------------------------------------------------------------------------------
// Purpose: destructor
//---------------------------------------------------------------------------------
CPluginSDK::~CPluginSDK()
{
}
//---------------------------------------------------------------------------------
// Purpose: properly initialize the plugin sdk
//---------------------------------------------------------------------------------
bool CPluginSDK::InitSDK()
{
auto getFactorySystemFn = m_SDKModule.GetExportedSymbol("GetFactorySystem").RCast<void*(*)()>();
Assert(getFactorySystemFn, "Could not find GetFactorySystem export from gamesdk.dll");
if (!getFactorySystemFn)
return false;
m_FactoryInstance = reinterpret_cast<IFactory*>(getFactorySystemFn());
Assert(getFactorySystemFn, "m_FactoryInstace was nullptr.");
if (!m_FactoryInstance)
return false;
// Let's make sure the factory version matches, else we unload.
bool isFactoryVersionOk = strcmp(m_FactoryInstance->GetFactoryFullName("VFactorySystem"), FACTORY_INTERFACE_VERSION) == 0;
Assert(isFactoryVersionOk, "Version mismatch between IFactory and CFactory.");
if (!isFactoryVersionOk)
return false;
// Let's make sure the SDK version matches with the PluginSystem, else we unload
bool isPluginVersionOk = strcmp(m_FactoryInstance->GetFactoryFullName("VPluginSystem"), INTERFACEVERSION_PLUGINSYSTEM) == 0;
Assert(isPluginVersionOk, "Version mismatch between CPluginSDK and CPluginSystem.");
if (!isPluginVersionOk)
return false;
m_PluginSystem = m_FactoryInstance->GetFactoryPtr(INTERFACEVERSION_PLUGINSYSTEM, false).RCast<IPluginSystem*>();
Assert(m_PluginSystem, "m_PluginSystem was nullptr.");
if (!m_PluginSystem)
return false;
return true;
}
CPluginSDK* g_pPluginSDK = nullptr;