mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Removed all extraneous copies by adding the class 'InterfaceReg' which will construct a new interface, and link it to the engine's static register. The Source Engine macro 'EXPOSE_INTERFACE_FN' will help utilizing this. The game module from the plugin is not obtained through the process environment block, so the executable is no longer sensitive to names.
66 lines
2.1 KiB
C++
66 lines
2.1 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);
|
|
m_GameModule.InitFromBase(CModule::GetProcessEnvironmentBlock()->ImageBaseAddress);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: destructor
|
|
//---------------------------------------------------------------------------------
|
|
CPluginSDK::~CPluginSDK()
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: properly initialize the plugin sdk
|
|
//---------------------------------------------------------------------------------
|
|
bool CPluginSDK::InitSDK()
|
|
{
|
|
InstantiateInterfaceFn factorySystem = m_SDKModule.GetExportedSymbol("GetFactorySystem").RCast<InstantiateInterfaceFn>();
|
|
if (!factorySystem)
|
|
{
|
|
Assert(factorySystem, "factorySystem == NULL; symbol renamed???");
|
|
return false;
|
|
}
|
|
|
|
m_FactoryInstance = (IFactorySystem*)factorySystem();
|
|
|
|
// Let's make sure the factory version matches, else we unload.
|
|
bool isFactoryVersionOk = strcmp(m_FactoryInstance->GetVersion(), FACTORY_INTERFACE_VERSION) == 0;
|
|
if (!isFactoryVersionOk)
|
|
{
|
|
Assert(isFactoryVersionOk, "Version mismatch!");
|
|
return false;
|
|
}
|
|
|
|
// Unload if
|
|
m_PluginSystem = (IPluginSystem*)m_FactoryInstance->GetFactory(INTERFACEVERSION_PLUGINSYSTEM);
|
|
if (!m_PluginSystem)
|
|
{
|
|
Assert(m_PluginSystem, "CPluginSDK::m_PluginSystem == NULL");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
CPluginSDK* g_pPluginSDK = nullptr; |