Update CGameConfig members to use std::string instead of fixed-size char arrays (#1495)
This commit is contained in:
parent
8f73e5e5a1
commit
d01c72f79b
@ -225,7 +225,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
|||||||
{
|
{
|
||||||
bShouldBeReadingDefault = true;
|
bShouldBeReadingDefault = true;
|
||||||
m_ParseState = PSTATE_GAMEDEFS;
|
m_ParseState = PSTATE_GAMEDEFS;
|
||||||
strncopy(m_Game, name, sizeof(m_Game));
|
m_Game = name;
|
||||||
} else {
|
} else {
|
||||||
m_IgnoreLevel++;
|
m_IgnoreLevel++;
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
|||||||
{
|
{
|
||||||
m_ParseState = PSTATE_GAMEDEFS_KEYS;
|
m_ParseState = PSTATE_GAMEDEFS_KEYS;
|
||||||
}
|
}
|
||||||
else if ((strcmp(name, "#supported") == 0) && (strcmp(m_Game, "#default") == 0))
|
else if ((strcmp(name, "#supported") == 0) && (m_Game == "#default"))
|
||||||
{
|
{
|
||||||
m_ParseState = PSTATE_GAMEDEFS_SUPPORTED;
|
m_ParseState = PSTATE_GAMEDEFS_SUPPORTED;
|
||||||
/* Ignore this section unless we get a game. */
|
/* Ignore this section unless we get a game. */
|
||||||
@ -280,23 +280,23 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
|||||||
}
|
}
|
||||||
case PSTATE_GAMEDEFS_KEYS:
|
case PSTATE_GAMEDEFS_KEYS:
|
||||||
{
|
{
|
||||||
strncopy(m_Key, name, sizeof(m_Key));
|
m_Key = name;
|
||||||
m_ParseState = PSTATE_GAMEDEFS_KEYS_PLATFORM;
|
m_ParseState = PSTATE_GAMEDEFS_KEYS_PLATFORM;
|
||||||
matched_platform = false;
|
matched_platform = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PSTATE_GAMEDEFS_OFFSETS:
|
case PSTATE_GAMEDEFS_OFFSETS:
|
||||||
{
|
{
|
||||||
m_Prop[0] = '\0';
|
m_Prop.clear();
|
||||||
m_Class[0] = '\0';
|
m_Class.clear();
|
||||||
strncopy(m_offset, name, sizeof(m_offset));
|
m_offset = name;
|
||||||
m_ParseState = PSTATE_GAMEDEFS_OFFSETS_OFFSET;
|
m_ParseState = PSTATE_GAMEDEFS_OFFSETS_OFFSET;
|
||||||
matched_platform = false;
|
matched_platform = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PSTATE_GAMEDEFS_SIGNATURES:
|
case PSTATE_GAMEDEFS_SIGNATURES:
|
||||||
{
|
{
|
||||||
strncopy(m_offset, name, sizeof(m_offset));
|
m_offset = name;
|
||||||
s_TempSig.Reset();
|
s_TempSig.Reset();
|
||||||
m_ParseState = PSTATE_GAMEDEFS_SIGNATURES_SIG;
|
m_ParseState = PSTATE_GAMEDEFS_SIGNATURES_SIG;
|
||||||
matched_platform = false;
|
matched_platform = false;
|
||||||
@ -338,7 +338,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
|||||||
if (error[0] != '\0')
|
if (error[0] != '\0')
|
||||||
{
|
{
|
||||||
m_IgnoreLevel = 1;
|
m_IgnoreLevel = 1;
|
||||||
logger->LogError("[SM] Error while parsing CRC section for \"%s\" (%s):", m_Game, m_CurFile);
|
logger->LogError("[SM] Error while parsing CRC section for \"%s\" (%s):", m_Game.c_str(), m_CurFile);
|
||||||
logger->LogError("[SM] %s", error);
|
logger->LogError("[SM] %s", error);
|
||||||
} else {
|
} else {
|
||||||
m_ParseState = PSTATE_GAMEDEFS_CRC_BINARY;
|
m_ParseState = PSTATE_GAMEDEFS_CRC_BINARY;
|
||||||
@ -353,12 +353,12 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
|||||||
}
|
}
|
||||||
case PSTATE_GAMEDEFS_ADDRESSES:
|
case PSTATE_GAMEDEFS_ADDRESSES:
|
||||||
{
|
{
|
||||||
m_Address[0] = '\0';
|
m_Address.clear();
|
||||||
m_AddressSignature[0] = '\0';
|
m_AddressSignature.clear();
|
||||||
m_AddressReadCount = 0;
|
m_AddressReadCount = 0;
|
||||||
m_AddressLastIsOffset = false;
|
m_AddressLastIsOffset = false;
|
||||||
|
|
||||||
strncopy(m_Address, name, sizeof(m_Address));
|
m_Address = name;
|
||||||
m_ParseState = PSTATE_GAMEDEFS_ADDRESSES_ADDRESS;
|
m_ParseState = PSTATE_GAMEDEFS_ADDRESSES_ADDRESS;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -374,7 +374,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
|||||||
if (strcmp(name, "linux") != 0 && strcmp(name, "windows") != 0 && strcmp(name, "mac") != 0 &&
|
if (strcmp(name, "linux") != 0 && strcmp(name, "windows") != 0 && strcmp(name, "mac") != 0 &&
|
||||||
strcmp(name, "linux64") != 0 && strcmp(name, "windows64") != 0 && strcmp(name, "mac64") != 0)
|
strcmp(name, "linux64") != 0 && strcmp(name, "windows64") != 0 && strcmp(name, "mac64") != 0)
|
||||||
{
|
{
|
||||||
logger->LogError("[SM] Error while parsing Address section for \"%s\" (%s):", m_Address, m_CurFile);
|
logger->LogError("[SM] Error while parsing Address section for \"%s\" (%s):", m_Address.c_str(), m_CurFile);
|
||||||
logger->LogError("[SM] Unrecognized platform \"%s\"", name);
|
logger->LogError("[SM] Unrecognized platform \"%s\"", name);
|
||||||
}
|
}
|
||||||
m_IgnoreLevel = 1;
|
m_IgnoreLevel = 1;
|
||||||
@ -411,11 +411,11 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
|||||||
{
|
{
|
||||||
if (strcmp(key, "class") == 0)
|
if (strcmp(key, "class") == 0)
|
||||||
{
|
{
|
||||||
strncopy(m_Class, value, sizeof(m_Class));
|
m_Class = value;
|
||||||
} else if (strcmp(key, "prop") == 0) {
|
} else if (strcmp(key, "prop") == 0) {
|
||||||
strncopy(m_Prop, value, sizeof(m_Prop));
|
m_Prop = value;
|
||||||
} else if (IsPlatformCompatible(key, &matched_platform)) {
|
} else if (IsPlatformCompatible(key, &matched_platform)) {
|
||||||
m_Offsets.replace(m_offset, static_cast<int>(strtol(value, NULL, 0)));
|
m_Offsets.replace(m_offset.c_str(), static_cast<int>(strtol(value, NULL, 0)));
|
||||||
}
|
}
|
||||||
} else if (m_ParseState == PSTATE_GAMEDEFS_KEYS) {
|
} else if (m_ParseState == PSTATE_GAMEDEFS_KEYS) {
|
||||||
std::string vstr(value);
|
std::string vstr(value);
|
||||||
@ -425,7 +425,7 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
|||||||
if (IsPlatformCompatible(key, &matched_platform))
|
if (IsPlatformCompatible(key, &matched_platform))
|
||||||
{
|
{
|
||||||
std::string vstr(value);
|
std::string vstr(value);
|
||||||
m_Keys.replace(m_Key, std::move(vstr));
|
m_Keys.replace(m_Key.c_str(), std::move(vstr));
|
||||||
}
|
}
|
||||||
} else if (m_ParseState == PSTATE_GAMEDEFS_SUPPORTED) {
|
} else if (m_ParseState == PSTATE_GAMEDEFS_SUPPORTED) {
|
||||||
if (strcmp(key, "game") == 0)
|
if (strcmp(key, "game") == 0)
|
||||||
@ -476,7 +476,7 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
|||||||
int limit = sizeof(m_AddressRead)/sizeof(m_AddressRead[0]);
|
int limit = sizeof(m_AddressRead)/sizeof(m_AddressRead[0]);
|
||||||
if (m_AddressLastIsOffset)
|
if (m_AddressLastIsOffset)
|
||||||
{
|
{
|
||||||
logger->LogError("[SM] Error parsing Address \"%s\", 'offset' entry must be the last entry (gameconf \"%s\")", m_Address, m_CurFile);
|
logger->LogError("[SM] Error parsing Address \"%s\", 'offset' entry must be the last entry (gameconf \"%s\")", m_Address.c_str(), m_CurFile);
|
||||||
}
|
}
|
||||||
else if (m_AddressReadCount < limit)
|
else if (m_AddressReadCount < limit)
|
||||||
{
|
{
|
||||||
@ -489,10 +489,10 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger->LogError("[SM] Error parsing Address \"%s\", does not support more than %d read offsets (gameconf \"%s\")", m_Address, limit, m_CurFile);
|
logger->LogError("[SM] Error parsing Address \"%s\", does not support more than %d read offsets (gameconf \"%s\")", m_Address.c_str(), limit, m_CurFile);
|
||||||
}
|
}
|
||||||
} else if (strcmp(key, "signature") == 0) {
|
} else if (strcmp(key, "signature") == 0) {
|
||||||
strncopy(m_AddressSignature, value, sizeof(m_AddressSignature));
|
m_AddressSignature = value;
|
||||||
}
|
}
|
||||||
} else if (m_ParseState == PSTATE_GAMEDEFS_CUSTOM) {
|
} else if (m_ParseState == PSTATE_GAMEDEFS_CUSTOM) {
|
||||||
return m_CustomHandler->ReadSMC_KeyValue(states, key, value);
|
return m_CustomHandler->ReadSMC_KeyValue(states, key, value);
|
||||||
@ -548,25 +548,24 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
|
|||||||
case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
|
case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
|
||||||
{
|
{
|
||||||
/* Parse the offset... */
|
/* Parse the offset... */
|
||||||
if (m_Class[0] != '\0'
|
if (!m_Class.empty() && !m_Prop.empty())
|
||||||
&& m_Prop[0] != '\0')
|
|
||||||
{
|
{
|
||||||
SendProp *pProp = gamehelpers->FindInSendTable(m_Class, m_Prop);
|
SendProp *pProp = gamehelpers->FindInSendTable(m_Class.c_str(), m_Prop.c_str());
|
||||||
if (pProp)
|
if (pProp)
|
||||||
{
|
{
|
||||||
int val = gamehelpers->GetSendPropOffset(pProp);
|
int val = gamehelpers->GetSendPropOffset(pProp);
|
||||||
m_Offsets.replace(m_offset, val);
|
m_Offsets.replace(m_offset.c_str(), val);
|
||||||
m_Props.replace(m_offset, pProp);
|
m_Props.replace(m_offset.c_str(), pProp);
|
||||||
} else {
|
} else {
|
||||||
/* Check if it's a non-default game and no offsets exist */
|
/* Check if it's a non-default game and no offsets exist */
|
||||||
if (((strcmp(m_Game, "*") != 0) && strcmp(m_Game, "#default") != 0)
|
if ((m_Game != "*" && m_Game != "#default")
|
||||||
&& (!m_Offsets.retrieve(m_offset)))
|
&& (!m_Offsets.retrieve(m_offset.c_str())))
|
||||||
{
|
{
|
||||||
logger->LogError("[SM] Unable to find property %s.%s (file \"%s\") (mod \"%s\")",
|
logger->LogError("[SM] Unable to find property %s.%s (file \"%s\") (mod \"%s\")",
|
||||||
m_Class,
|
m_Class.c_str(),
|
||||||
m_Prop,
|
m_Prop.c_str(),
|
||||||
m_CurFile,
|
m_CurFile,
|
||||||
m_Game);
|
m_Game.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -674,7 +673,7 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Sigs.replace(m_offset, final_addr);
|
m_Sigs.replace(m_offset.c_str(), final_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ParseState = PSTATE_GAMEDEFS_SIGNATURES;
|
m_ParseState = PSTATE_GAMEDEFS_SIGNATURES;
|
||||||
@ -690,10 +689,10 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
|
|||||||
{
|
{
|
||||||
m_ParseState = PSTATE_GAMEDEFS_ADDRESSES;
|
m_ParseState = PSTATE_GAMEDEFS_ADDRESSES;
|
||||||
|
|
||||||
if (m_Address[0] != '\0' && m_AddressSignature[0] != '\0')
|
if (!m_Address.empty() && !m_AddressSignature.empty())
|
||||||
{
|
{
|
||||||
AddressConf addrConf(m_AddressSignature, sizeof(m_AddressSignature), m_AddressReadCount, m_AddressRead, m_AddressLastIsOffset);
|
AddressConf addrConf(std::move(m_AddressSignature), m_AddressReadCount, m_AddressRead, m_AddressLastIsOffset);
|
||||||
m_Addresses.replace(m_Address, addrConf);
|
m_Addresses.replace(m_Address.c_str(), addrConf);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1041,7 +1040,7 @@ bool CGameConfig::GetAddress(const char *key, void **retaddr)
|
|||||||
AddressConf &addrConf = r->value;
|
AddressConf &addrConf = r->value;
|
||||||
|
|
||||||
void *addr;
|
void *addr;
|
||||||
if (!GetMemSig(addrConf.signatureName, &addr))
|
if (!GetMemSig(addrConf.signatureName.c_str(), &addr))
|
||||||
{
|
{
|
||||||
*retaddr = NULL;
|
*retaddr = NULL;
|
||||||
return false;
|
return false;
|
||||||
@ -1074,11 +1073,11 @@ static inline unsigned minOf(unsigned a, unsigned b)
|
|||||||
return a <= b ? a : b;
|
return a <= b ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGameConfig::AddressConf::AddressConf(char *sigName, unsigned sigLength, unsigned readCount, int *read, bool lastIsOffset)
|
CGameConfig::AddressConf::AddressConf(std::string&& sigName, unsigned readCount, int *read, bool lastIsOffset)
|
||||||
{
|
{
|
||||||
unsigned readLimit = minOf(readCount, sizeof(this->read) / sizeof(this->read[0]));
|
unsigned readLimit = minOf(readCount, sizeof(this->read) / sizeof(this->read[0]));
|
||||||
|
|
||||||
strncopy(signatureName, sigName, sizeof(signatureName) / sizeof(signatureName[0]));
|
this->signatureName = std::move(sigName);
|
||||||
this->readCount = readLimit;
|
this->readCount = readLimit;
|
||||||
memcpy(&this->read[0], read, sizeof(this->read[0])*readLimit);
|
memcpy(&this->read[0], read, sizeof(this->read[0])*readLimit);
|
||||||
|
|
||||||
|
@ -86,11 +86,11 @@ private:
|
|||||||
/* Parse states */
|
/* Parse states */
|
||||||
int m_ParseState;
|
int m_ParseState;
|
||||||
unsigned int m_IgnoreLevel;
|
unsigned int m_IgnoreLevel;
|
||||||
char m_Class[64];
|
std::string m_Class;
|
||||||
char m_Prop[64];
|
std::string m_Prop;
|
||||||
char m_offset[64];
|
std::string m_offset;
|
||||||
char m_Game[256];
|
std::string m_Game;
|
||||||
char m_Key[64];
|
std::string m_Key;
|
||||||
bool bShouldBeReadingDefault;
|
bool bShouldBeReadingDefault;
|
||||||
bool had_game;
|
bool had_game;
|
||||||
bool matched_game;
|
bool matched_game;
|
||||||
@ -105,18 +105,18 @@ private:
|
|||||||
/* Support for reading Addresses */
|
/* Support for reading Addresses */
|
||||||
struct AddressConf
|
struct AddressConf
|
||||||
{
|
{
|
||||||
char signatureName[64];
|
std::string signatureName;
|
||||||
int readCount;
|
int readCount;
|
||||||
int read[8];
|
int read[8];
|
||||||
bool lastIsOffset;
|
bool lastIsOffset;
|
||||||
|
|
||||||
AddressConf(char *sigName, unsigned sigLength, unsigned readCount, int *read, bool lastIsOffset);
|
AddressConf(std::string&& sigName, unsigned readCount, int *read, bool lastIsOffset);
|
||||||
|
|
||||||
AddressConf() {}
|
AddressConf() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
char m_Address[64];
|
std::string m_Address;
|
||||||
char m_AddressSignature[64];
|
std::string m_AddressSignature;
|
||||||
int m_AddressReadCount;
|
int m_AddressReadCount;
|
||||||
int m_AddressRead[8];
|
int m_AddressRead[8];
|
||||||
bool m_AddressLastIsOffset;
|
bool m_AddressLastIsOffset;
|
||||||
|
Loading…
Reference in New Issue
Block a user