Consolidate SDKTools ent factory lookup (r=asherkin).

This commit is contained in:
Nicholas Hastings 2013-11-05 20:32:37 -05:00
parent c13a0a2e7a
commit 056f64ad40

View File

@ -502,6 +502,63 @@ void _ignore_invalid_parameter(
} }
#endif #endif
CEntityFactoryDictionary *GetEntityFactoryDictionary()
{
static CEntityFactoryDictionary *dict = NULL;
#if SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_SDK2013
dict = (CEntityFactoryDictionary *) servertools->GetEntityFactoryDictionary();
#else
if (dict == NULL)
{
void *addr;
if (g_pGameConf->GetMemSig("EntityFactoryFinder", (void **) &addr) && addr)
{
int offset;
if (!g_pGameConf->GetOffset("EntityFactoryOffset", &offset) || !offset)
{
return NULL;
}
dict = *reinterpret_cast<CEntityFactoryDictionary **>((intptr_t) addr + offset);
}
}
if (dict == NULL)
{
ICallWrapper *pWrapper = NULL;
PassInfo retData;
retData.flags = PASSFLAG_BYVAL;
retData.size = sizeof(void *);
retData.type = PassType_Basic;
void *addr;
if (g_pGameConf->GetMemSig("EntityFactory", &addr) && addr != NULL)
{
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0);
}
if (pWrapper)
{
void *returnData = NULL;
pWrapper->Execute(NULL, &returnData);
pWrapper->Destroy();
if (returnData == NULL)
{
return NULL;
}
dict = (CEntityFactoryDictionary *) returnData;
}
}
#endif
return dict;
}
CON_COMMAND(sm_dump_classes, "Dumps the class list as a text file") CON_COMMAND(sm_dump_classes, "Dumps the class list as a text file")
{ {
#if SOURCE_ENGINE <= SE_DARKMESSIAH #if SOURCE_ENGINE <= SE_DARKMESSIAH
@ -521,39 +578,10 @@ CON_COMMAND(sm_dump_classes, "Dumps the class list as a text file")
return; return;
} }
CEntityFactoryDictionary *dict = NULL; CEntityFactoryDictionary *dict = GetEntityFactoryDictionary();
#if SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_SDK2013
dict = (CEntityFactoryDictionary *)servertools->GetEntityFactoryDictionary();
#else
ICallWrapper *pWrapper = NULL;
if (!pWrapper)
{
PassInfo retData;
retData.flags = PASSFLAG_BYVAL;
retData.size = sizeof(void *);
retData.type = PassType_Basic;
void *addr;
if (!g_pGameConf->GetMemSig("EntityFactory", &addr) || addr == NULL)
{
META_CONPRINT("Failed to locate function\n");
return;
}
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0);
}
pWrapper->Execute(NULL, &dict);
pWrapper->Destroy();
#endif
if (dict == NULL) if (dict == NULL)
{ {
META_CONPRINT("Failed to locate function\n");
return; return;
} }
@ -714,53 +742,7 @@ CON_COMMAND(sm_dump_datamaps, "Dumps the data map list as a text file")
return; return;
} }
static CEntityFactoryDictionary *dict = NULL; CEntityFactoryDictionary *dict = GetEntityFactoryDictionary();
if (dict == NULL)
{
void *addr;
if (g_pGameConf->GetMemSig("EntityFactoryFinder", (void **)&addr) && addr)
{
int offset;
if (!g_pGameConf->GetOffset("EntityFactoryOffset", &offset) || !offset)
{
return;
}
dict = *reinterpret_cast<CEntityFactoryDictionary **>((intptr_t)addr + offset);
}
}
if (dict == NULL)
{
ICallWrapper *pWrapper = NULL;
PassInfo retData;
retData.flags = PASSFLAG_BYVAL;
retData.size = sizeof(void *);
retData.type = PassType_Basic;
void *addr;
if (g_pGameConf->GetMemSig("EntityFactory", &addr) && addr != NULL)
{
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0);
}
if (pWrapper)
{
void *returnData = NULL;
pWrapper->Execute(NULL, &returnData);
pWrapper->Destroy();
if (returnData == NULL)
{
return;
}
dict = ( CEntityFactoryDictionary * )returnData;
}
}
if ( dict == NULL ) if ( dict == NULL )
{ {
META_CONPRINT("Failed to locate function\n"); META_CONPRINT("Failed to locate function\n");