2022-08-21 00:59:55 +02:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
{
|
2023-07-10 13:54:00 +02:00
|
|
|
m_SelfModule.InitFromName(pszSelfModule);
|
2023-08-22 01:11:49 +02:00
|
|
|
m_GameModule.InitFromBase(CModule::GetProcessEnvironmentBlock()->ImageBaseAddress);
|
2022-08-21 00:59:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: destructor
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
CPluginSDK::~CPluginSDK()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: properly initialize the plugin sdk
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
bool CPluginSDK::InitSDK()
|
|
|
|
{
|
2023-08-22 01:11:49 +02:00
|
|
|
InstantiateInterfaceFn factorySystem = m_SDKModule.GetExportedSymbol("GetFactorySystem").RCast<InstantiateInterfaceFn>();
|
|
|
|
if (!factorySystem)
|
|
|
|
{
|
|
|
|
Assert(factorySystem, "factorySystem == NULL; symbol renamed???");
|
2022-08-21 00:59:55 +02:00
|
|
|
return false;
|
2023-08-22 01:11:49 +02:00
|
|
|
}
|
2022-08-21 00:59:55 +02:00
|
|
|
|
2023-08-22 01:11:49 +02:00
|
|
|
m_FactoryInstance = (IFactorySystem*)factorySystem();
|
2022-08-21 00:59:55 +02:00
|
|
|
|
|
|
|
// Let's make sure the factory version matches, else we unload.
|
2023-08-22 01:11:49 +02:00
|
|
|
bool isFactoryVersionOk = strcmp(m_FactoryInstance->GetVersion(), FACTORY_INTERFACE_VERSION) == 0;
|
2022-08-21 00:59:55 +02:00
|
|
|
if (!isFactoryVersionOk)
|
2023-08-22 01:11:49 +02:00
|
|
|
{
|
|
|
|
Assert(isFactoryVersionOk, "Version mismatch!");
|
2022-08-21 00:59:55 +02:00
|
|
|
return false;
|
2023-08-22 01:11:49 +02:00
|
|
|
}
|
2022-08-21 00:59:55 +02:00
|
|
|
|
2023-08-22 01:11:49 +02:00
|
|
|
// Unload if
|
|
|
|
m_PluginSystem = (IPluginSystem*)m_FactoryInstance->GetFactory(INTERFACEVERSION_PLUGINSYSTEM);
|
2022-08-21 00:59:55 +02:00
|
|
|
if (!m_PluginSystem)
|
2023-08-22 01:11:49 +02:00
|
|
|
{
|
|
|
|
Assert(m_PluginSystem, "CPluginSDK::m_PluginSystem == NULL");
|
2022-08-21 00:59:55 +02:00
|
|
|
return false;
|
2023-08-22 01:11:49 +02:00
|
|
|
}
|
2022-08-21 00:59:55 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginSDK* g_pPluginSDK = nullptr;
|