bool UTIL_FindDataMapInfo(datamap_t *pMap, const char *name, sm_datatable_info_t *pDataTable) { while (pMap) { for (int i = 0; i < pMap->dataNumFields; ++i) { if (pMap->dataDesc[i].fieldName == NULL) { continue; } if (strcmp(name, pMap->dataDesc[i].fieldName) == 0) { pDataTable->prop = &(pMap->dataDesc[i]); pDataTable->actual_offset = GetTypeDescOffs(pDataTable->prop); return true; } if (pMap->dataDesc[i].td == NULL || !UTIL_FindDataMapInfo(pMap->dataDesc[i].td, name, pDataTable)) { continue; } pDataTable->actual_offset += GetTypeDescOffs(&(pMap->dataDesc[i])); return true; } pMap = pMap->baseMap; } return false; }
const char *EntityOutputManager::GetEntityClassname(CBaseEntity *pEntity) { static int offset = -1; if (offset == -1) { datamap_t *pMap = gamehelpers->GetDataMap(pEntity); typedescription_t *pDesc = gamehelpers->FindInDataMap(pMap, "m_iClassname"); offset = GetTypeDescOffs(pDesc); } return *(const char **)(((unsigned char *)pEntity) + offset); }
const char *CHalfLife2::GetEntityClassname(CBaseEntity *pEntity) { static int offset = -1; if (offset == -1) { datamap_t *pMap = GetDataMap(pEntity); typedescription_t *pDesc = FindInDataMap(pMap, "m_iClassname"); offset = GetTypeDescOffs(pDesc); } return *(const char **)(((unsigned char *)pEntity) + offset); }
void *FindOutputPointerByName(CBaseEntity *pEntity, const char *outputname) { datamap_t *pMap = gamehelpers->GetDataMap(pEntity); while (pMap) { for (int i=0; i<pMap->dataNumFields; i++) { if (pMap->dataDesc[i].flags & FTYPEDESC_OUTPUT) { if (strcmp(pMap->dataDesc[i].externalName,outputname) == 0) { return reinterpret_cast<void *>((unsigned char*)pEntity + GetTypeDescOffs(&pMap->dataDesc[i])); } } } pMap = pMap->baseMap; } return NULL; }
// Iterate the datamap of pCaller and look for output pointers with the same address as pOutput const char *EntityOutputManager::FindOutputName(void *pOutput, CBaseEntity *pCaller) { datamap_t *pMap = gamehelpers->GetDataMap(pCaller); while (pMap) { for (int i=0; i<pMap->dataNumFields; i++) { if (pMap->dataDesc[i].flags & FTYPEDESC_OUTPUT) { if ((char *)pCaller + GetTypeDescOffs(&pMap->dataDesc[i]) == pOutput) { return pMap->dataDesc[i].externalName; } } } pMap = pMap->baseMap; } return NULL; }