Ensure ROMId is safe

This commit is contained in:
OV2 2023-03-14 12:26:44 +01:00
parent 7a268ef91c
commit b7f56efccc
2 changed files with 19 additions and 0 deletions

View File

@ -2424,6 +2424,7 @@ void CMemory::InitROM (void)
//// Show ROM information
ROMId[4] = 0;
strcpy(ROMId, SafeString(ROMId).c_str());
sprintf(String, "\"%s\" [%s] %s, %s, %s, %s, SRAM:%s, ID:%s, CRC32:%08X",
ROMName, isChecksumOK ? "checksum ok" : ((Multi.cartType == 4) ? "no checksum" : "bad checksum"),
@ -3500,6 +3501,23 @@ void CMemory::ApplyROMFixes (void)
Timings.RenderPos = 32;
}
std::string CMemory::SafeString(std::string s, bool allow_jis /*=false*/)
{
std::string safe;
for (int i = 0; i < s.length(); i++)
{
if (s[i] >= 32 && s[i] < 127) // ASCII
safe += s[i];
else
if (allow_jis && ROMRegion == 0 && ((uint8)s[i] >= 0xa0 && (uint8)s[i] < 0xe0)) // JIS X 201 - Katakana
safe += s[i];
else
safe += '_';
}
return safe;
}
// BPS % UPS % IPS
// number decoding used for both BPS and UPS

View File

@ -170,6 +170,7 @@ struct CMemory
bool8 match_nc (const char *);
bool8 match_id (const char *);
void ApplyROMFixes (void);
std::string SafeString(std::string s, bool allow_jis = false);
void CheckForAnyPatch (const char *, bool8, int32 &);
void MakeRomInfoText (char *);