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)
|
|
|
|
{
|
2022-06-18 17:52:32 +02:00
|
|
|
size_t nVersionIndex = GetVersionIndex(svFactoryName);
|
2023-04-08 17:45:21 +02:00
|
|
|
FactoryInfo_t factoryInfo(reinterpret_cast<uintptr_t>(pFactory), svFactoryName,
|
|
|
|
svFactoryName.substr(0, nVersionIndex), svFactoryName.substr(nVersionIndex));
|
2022-04-09 00:59:42 +02:00
|
|
|
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------
|
2022-08-20 12:42:19 +02:00
|
|
|
void CFactory::AddFactory(FactoryInfo_t factoryInfo)
|
2022-04-09 00:59:42 +02:00
|
|
|
{
|
|
|
|
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-06-18 17:52:32 +02:00
|
|
|
size_t CFactory::GetVersionIndex(const string& svInterfaceName) const
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2022-06-18 17:52:32 +02:00
|
|
|
size_t nVersionIndex = 0;
|
2022-08-21 00:59:55 +02:00
|
|
|
for (size_t i = 0; i < svInterfaceName.length(); i++) // Loop through each character 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.
|
2022-06-18 17:52:32 +02:00
|
|
|
size_t nVersionIndex = GetVersionIndex(svInterfaceName);
|
2022-01-17 03:28:16 +01:00
|
|
|
|
|
|
|
// Push back the interface.
|
2023-04-08 17:45:21 +02:00
|
|
|
AddFactory(FactoryInfo_t(reinterpret_cast<uintptr_t>(it->m_pInterfacePtr()), svInterfaceName,
|
|
|
|
svInterfaceName.substr(0, nVersionIndex), svInterfaceName.substr(nVersionIndex)));
|
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-08-20 12:42:19 +02:00
|
|
|
for (const FactoryInfo_t& 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-08-21 00:59:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: get full factory string from versionless string
|
|
|
|
// Input : svFactoryName -
|
|
|
|
// Output : const char*
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
const char* CFactory::GetFactoryFullName(const string& svFactoryName) const
|
|
|
|
{
|
|
|
|
for (const FactoryInfo_t& it : m_vFactories)
|
|
|
|
{
|
|
|
|
if (it.m_szFactoryName == svFactoryName)
|
|
|
|
return it.m_szFactoryFullName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2022-08-21 01:02:07 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: expose factory system to other dlls
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-08-21 00:59:55 +02:00
|
|
|
extern "C" __declspec(dllexport) void* GetFactorySystem()
|
|
|
|
{
|
|
|
|
return g_pFactory;
|
|
|
|
}
|
|
|
|
|
2022-04-09 00:59:42 +02:00
|
|
|
CFactory* g_pFactory = new CFactory();
|