Merge pull request #282 from Arkshine/gamedata-type-desc
Modify game config parser to support more offset data and reflect changes
This commit is contained in:
@ -51,6 +51,8 @@ struct TempSigInfo
|
||||
|
||||
} TempSig;
|
||||
|
||||
TypeDescription TempType;
|
||||
|
||||
static char ParseEngine[32];
|
||||
|
||||
static bool DoesGameMatch(const char *value)
|
||||
@ -63,13 +65,10 @@ static bool DoesEngineMatch(const char* value)
|
||||
return strcmp(ParseEngine, value) == 0;
|
||||
}
|
||||
|
||||
CGameConfig::CGameConfig(const char *path)
|
||||
CGameConfig::CGameConfig(const char *path) : m_FoundOffset(false), m_CustomLevel(0), m_CustomHandler(nullptr)
|
||||
{
|
||||
strncopy(m_File, path, sizeof(m_File));
|
||||
strncopy(ParseEngine, IS_DEDICATED_SERVER() ? "engine_ds" : "engine_ls", sizeof(ParseEngine));
|
||||
|
||||
m_CustomLevel = 0;
|
||||
m_CustomHandler = nullptr;
|
||||
}
|
||||
|
||||
CGameConfig::~CGameConfig()
|
||||
@ -181,9 +180,11 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
case PSTATE_GAMEDEFS_OFFSETS:
|
||||
{
|
||||
strncopy(m_Offset, name, sizeof(m_Offset));
|
||||
TempType.reset();
|
||||
|
||||
m_ParseState = PSTATE_GAMEDEFS_OFFSETS_OFFSET;
|
||||
m_MatchedPlatform = false;
|
||||
m_FoundOffset = false;
|
||||
break;
|
||||
}
|
||||
case PSTATE_GAMEDEFS_SIGNATURES:
|
||||
@ -251,26 +252,89 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
||||
{
|
||||
case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
|
||||
{
|
||||
if (g_LibSys.IsPlatformCompatible(key, &m_MatchedPlatform))
|
||||
if (!strcmp(key, "type"))
|
||||
{
|
||||
if (m_Class[0])
|
||||
{
|
||||
auto ic = m_OffsetsByClass.findForAdd(m_Class);
|
||||
auto type = FieldType::FIELD_NONE;
|
||||
|
||||
if (ic.found())
|
||||
{
|
||||
ic->value->list.replace(m_Offset, atoi(value));
|
||||
}
|
||||
else if (m_OffsetsByClass.add(ic, m_Class))
|
||||
{
|
||||
ic->value = new OffsetClass;
|
||||
ic->value->list.insert(m_Offset, atoi(value));
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!strcmp(value, "stringint"))
|
||||
{
|
||||
m_Offsets.replace(m_Offset, atoi(value));
|
||||
type = FieldType::FIELD_STRINGINT;
|
||||
}
|
||||
else if (!strcmp(value, "stringptr"))
|
||||
{
|
||||
type = FieldType::FIELD_STRINGPTR;
|
||||
}
|
||||
else if (!strcmp(value, "string"))
|
||||
{
|
||||
type = FieldType::FIELD_STRING;
|
||||
}
|
||||
else if (!strcmp(value, "classptr"))
|
||||
{
|
||||
type = FieldType::FIELD_CLASSPTR;
|
||||
}
|
||||
else if (!strcmp(value, "class"))
|
||||
{
|
||||
type = FieldType::FIELD_CLASS;
|
||||
}
|
||||
else if (!strcmp(value, "ehandle"))
|
||||
{
|
||||
type = FieldType::FIELD_EHANDLE;
|
||||
}
|
||||
else if (!strcmp(value, "edict"))
|
||||
{
|
||||
type = FieldType::FIELD_EDICT;
|
||||
}
|
||||
else if (!strcmp(value, "entvars"))
|
||||
{
|
||||
type = FieldType::FIELD_ENTVARS;
|
||||
}
|
||||
else if (!strcmp(value, "vector"))
|
||||
{
|
||||
type = FieldType::FIELD_VECTOR;
|
||||
}
|
||||
else if (!strcmp(value, "pointer"))
|
||||
{
|
||||
type = FieldType::FIELD_POINTER;
|
||||
}
|
||||
else if (!strcmp(value, "integer"))
|
||||
{
|
||||
type = FieldType::FIELD_INTEGER;
|
||||
}
|
||||
else if (!strcmp(value, "function"))
|
||||
{
|
||||
type = FieldType::FIELD_FUNCTION;
|
||||
}
|
||||
else if (!strcmp(value, "boolean"))
|
||||
{
|
||||
type = FieldType::FIELD_BOOLEAN;
|
||||
}
|
||||
else if (!strcmp(value, "short"))
|
||||
{
|
||||
type = FieldType::FIELD_SHORT;
|
||||
}
|
||||
else if (!strcmp(value, "character"))
|
||||
{
|
||||
type = FieldType::FIELD_CHARACTER;
|
||||
}
|
||||
else if (!strcmp(value, "float"))
|
||||
{
|
||||
type = FieldType::FIELD_FLOAT;
|
||||
}
|
||||
|
||||
TempType.fieldType = type;
|
||||
}
|
||||
else if (!strcmp(key, "size"))
|
||||
{
|
||||
TempType.fieldSize = ke::Max<int>(0, atoi(value));
|
||||
}
|
||||
else if (!strcmp(key, "unsigned"))
|
||||
{
|
||||
TempType.fieldUnsigned = !!atoi(value);
|
||||
}
|
||||
else if (g_LibSys.IsPlatformCompatible(key, &m_MatchedPlatform))
|
||||
{
|
||||
m_FoundOffset = true;
|
||||
TempType.fieldOffset = atoi(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -414,6 +478,28 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
|
||||
}
|
||||
case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
|
||||
{
|
||||
if (m_FoundOffset)
|
||||
{
|
||||
if (m_Class[0])
|
||||
{
|
||||
auto ic = m_OffsetsByClass.findForAdd(m_Class);
|
||||
|
||||
if (ic.found())
|
||||
{
|
||||
ic->value->list.replace(m_Offset, TempType);
|
||||
}
|
||||
else if (m_OffsetsByClass.add(ic, m_Class))
|
||||
{
|
||||
ic->value = new OffsetClass;
|
||||
ic->value->list.insert(m_Offset, TempType);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Offsets.replace(m_Offset, TempType);
|
||||
}
|
||||
}
|
||||
|
||||
m_ParseState = PSTATE_GAMEDEFS_OFFSETS;
|
||||
break;
|
||||
}
|
||||
@ -672,12 +758,12 @@ bool CGameConfig::EnterFile(const char *file, char *error, size_t maxlength)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameConfig::GetOffset(const char *key, int *value)
|
||||
bool CGameConfig::GetOffset(const char *key, TypeDescription *value)
|
||||
{
|
||||
return m_Offsets.retrieve(key, value);
|
||||
}
|
||||
|
||||
bool CGameConfig::GetOffsetByClass(const char *classname, const char *key, int *value)
|
||||
bool CGameConfig::GetOffsetByClass(const char *classname, const char *key, TypeDescription *value)
|
||||
{
|
||||
auto r = m_OffsetsByClass.find(classname);
|
||||
|
||||
|
@ -45,8 +45,8 @@ class CGameConfig
|
||||
public: // IGameConfig
|
||||
|
||||
const char* GetKeyValue(const char *key);
|
||||
bool GetOffset(const char *key, int *value);
|
||||
bool GetOffsetByClass(const char *classname, const char *key, int *value);
|
||||
bool GetOffset(const char *key, TypeDescription *value);
|
||||
bool GetOffsetByClass(const char *classname, const char *key, TypeDescription *value);
|
||||
bool GetMemSig(const char *key, void **addr);
|
||||
bool GetAddress(const char *key, void **addr);
|
||||
|
||||
@ -61,15 +61,16 @@ class CGameConfig
|
||||
|
||||
struct OffsetClass
|
||||
{
|
||||
StringHashMap<int> list;
|
||||
StringHashMap<TypeDescription> list;
|
||||
};
|
||||
|
||||
typedef StringHashMap<ke::AutoPtr<OffsetClass>> OffsetClassMap;
|
||||
typedef StringHashMap<TypeDescription> OffsetMap;
|
||||
|
||||
char m_File[PLATFORM_MAX_PATH];
|
||||
char m_CurrentPath[PLATFORM_MAX_PATH];
|
||||
|
||||
StringHashMap<int> m_Offsets;
|
||||
OffsetMap m_Offsets;
|
||||
OffsetClassMap m_OffsetsByClass;
|
||||
StringHashMap<ke::AString> m_Keys;
|
||||
StringHashMap<void*> m_Sigs;
|
||||
@ -81,6 +82,7 @@ class CGameConfig
|
||||
char m_Offset[64];
|
||||
char m_Game[256];
|
||||
|
||||
bool m_FoundOffset;
|
||||
bool m_MatchedClasses;
|
||||
bool m_ShouldBeReadingDefault;
|
||||
bool m_HadGame;
|
||||
|
@ -54,7 +54,7 @@ static cell AMX_NATIVE_CALL GameConfGetOffset(AMX *amx, cell *params)
|
||||
}
|
||||
|
||||
int length;
|
||||
int value;
|
||||
TypeDescription value;
|
||||
|
||||
const char *key = get_amxstring(amx, params[2], 0, length);
|
||||
|
||||
@ -63,7 +63,7 @@ static cell AMX_NATIVE_CALL GameConfGetOffset(AMX *amx, cell *params)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return value;
|
||||
return value.fieldOffset;
|
||||
}
|
||||
|
||||
// native GameConfGetClassOffset(GameConfig:handle, const classname[], const key[]);
|
||||
@ -78,7 +78,7 @@ static cell AMX_NATIVE_CALL GameConfGetClassOffset(AMX *amx, cell *params)
|
||||
}
|
||||
|
||||
int length;
|
||||
int value;
|
||||
TypeDescription value;
|
||||
|
||||
const char *classname = get_amxstring(amx, params[2], 0, length);
|
||||
const char *key = get_amxstring(amx, params[3], 1, length);
|
||||
@ -88,7 +88,7 @@ static cell AMX_NATIVE_CALL GameConfGetClassOffset(AMX *amx, cell *params)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return value;
|
||||
return value.fieldOffset;
|
||||
}
|
||||
|
||||
// native bool:GameConfGetKeyValue(GameConfig:handle, const key[], buffer[], maxlen);
|
||||
|
Reference in New Issue
Block a user