2022-01-18 01:21:24 +01:00
|
|
|
//===========================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: A higher level link library for general use in the game and SDK.
|
|
|
|
//
|
|
|
|
//===========================================================================//
|
2022-01-17 03:28:16 +01:00
|
|
|
|
2022-01-18 01:21:24 +01:00
|
|
|
#include "core/stdafx.h"
|
|
|
|
#include "vpc/interfaces.h"
|
2022-01-17 03:28:16 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-04-09 00:59:42 +02:00
|
|
|
// Purpose: add a factory to the factories vector
|
2022-04-16 13:02:14 +02:00
|
|
|
// Input : svFactoryName -
|
|
|
|
// pFactory -
|
2022-04-09 00:59:42 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void CFactory::AddFactory(const string& svFactoryName, void* pFactory)
|
|
|
|
{
|
|
|
|
int nVersionIndex = GetVersionIndex(svFactoryName);
|
|
|
|
FactoryInfo factoryInfo = FactoryInfo(svFactoryName, svFactoryName.substr(0, nVersionIndex),
|
|
|
|
svFactoryName.substr(nVersionIndex), reinterpret_cast<uintptr_t>(pFactory));
|
|
|
|
|
|
|
|
m_vFactories.push_back(factoryInfo); // Push factory info back into the vector.
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: add a factory to the factories vector
|
2022-04-16 13:02:14 +02:00
|
|
|
// Input : factoryInfo -
|
2022-04-09 00:59:42 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void CFactory::AddFactory(FactoryInfo factoryInfo)
|
|
|
|
{
|
|
|
|
m_vFactories.push_back(factoryInfo); // Push factory info back into the vector.
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: get the version index from interface name
|
|
|
|
// Input : svInterfaceName -
|
|
|
|
// Output : index of version in input interface string
|
2022-01-17 03:28:16 +01:00
|
|
|
//---------------------------------------------------------------------------------
|
2022-04-09 00:59:42 +02:00
|
|
|
int CFactory::GetVersionIndex(const string& svInterfaceName) const
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2022-04-09 00:59:42 +02:00
|
|
|
int nVersionIndex = 0;
|
|
|
|
for (int i = 0; i < svInterfaceName.length(); i++) // Loop through each charater to find the start of interface version.
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2022-04-09 00:59:42 +02:00
|
|
|
if (std::isdigit(svInterfaceName[i]))
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2022-04-09 00:59:42 +02:00
|
|
|
nVersionIndex = i;
|
|
|
|
break;
|
2022-01-17 03:28:16 +01:00
|
|
|
}
|
2022-04-09 00:59:42 +02:00
|
|
|
}
|
|
|
|
return nVersionIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: get all factory registered in the global s_pInterfacesRegs
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void CFactory::GetFactoriesFromRegister(void)
|
|
|
|
{
|
|
|
|
for (InterfaceGlobals_t* it = s_pInterfacesRegs.GetValue<InterfaceGlobals_t*>();
|
|
|
|
it; it = it->m_pNextInterfacePtr) // Loop till we go out of scope.
|
|
|
|
{
|
|
|
|
string svInterfaceName = it->m_pInterfaceName; // Get copy of the name.
|
|
|
|
int nVersionIndex = GetVersionIndex(svInterfaceName);
|
2022-01-17 03:28:16 +01:00
|
|
|
|
|
|
|
// Push back the interface.
|
2022-04-09 00:59:42 +02:00
|
|
|
AddFactory(FactoryInfo(svInterfaceName, svInterfaceName.substr(0, nVersionIndex),
|
|
|
|
svInterfaceName.substr(nVersionIndex), reinterpret_cast<uintptr_t>(it->m_pInterfacePtr())));
|
2022-01-17 03:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-04-09 00:59:42 +02:00
|
|
|
// Purpose: get factory pointer with factoryname input from factories vector
|
|
|
|
// Input : svFactoryName -
|
|
|
|
// bVersionLess -
|
2022-04-16 13:02:14 +02:00
|
|
|
// Output : CMemory
|
2022-01-17 03:28:16 +01:00
|
|
|
//---------------------------------------------------------------------------------
|
2022-04-10 19:59:34 +02:00
|
|
|
CMemory CFactory::GetFactoryPtr(const string& svFactoryName, bool bVersionLess) const
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2022-04-09 00:59:42 +02:00
|
|
|
for (auto& it : m_vFactories) // Loop through the whole vector.
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2022-04-09 00:59:42 +02:00
|
|
|
if (bVersionLess)
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2022-04-09 00:59:42 +02:00
|
|
|
if (it.m_szFactoryName == svFactoryName)
|
|
|
|
return it.m_pFactoryPtr;
|
2022-01-17 03:28:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-09 00:59:42 +02:00
|
|
|
if (it.m_szFactoryFullName == svFactoryName)
|
|
|
|
return it.m_pFactoryPtr;
|
2022-01-17 03:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-10 19:59:34 +02:00
|
|
|
return CMemory();
|
2022-01-17 03:28:16 +01:00
|
|
|
}
|
|
|
|
|
2022-04-09 00:59:42 +02:00
|
|
|
CFactory* g_pFactory = new CFactory();
|