System: Don't strip subdirectories when reading exe

Fixes getting hashes for cheevos in games such as Metal Gear Solid -
Integral.
This commit is contained in:
Connor McLaughlin 2021-03-02 01:37:25 +10:00
parent f6b8e2121b
commit c7a4efc395

View file

@ -420,7 +420,7 @@ std::string GetGameCodeForImage(CDImage* cdi)
return code; return code;
} }
static std::string GetExecutableNameForImage(CDImage* cdi, ISOReader& iso) static std::string GetExecutableNameForImage(CDImage* cdi, ISOReader& iso, bool strip_subdirectories)
{ {
// Read SYSTEM.CNF // Read SYSTEM.CNF
std::vector<u8> system_cnf_data; std::vector<u8> system_cnf_data;
@ -469,9 +469,12 @@ static std::string GetExecutableNameForImage(CDImage* cdi, ISOReader& iso)
if (iter == lines.end()) if (iter == lines.end())
return {}; return {};
// cdrom:\SCES_123.45;1
std::string code = iter->second; std::string code = iter->second;
std::string::size_type pos = code.rfind('\\'); std::string::size_type pos;
if (strip_subdirectories)
{
// cdrom:\SCES_123.45;1
pos = code.rfind('\\');
if (pos != std::string::npos) if (pos != std::string::npos)
{ {
code.erase(0, pos + 1); code.erase(0, pos + 1);
@ -483,6 +486,18 @@ static std::string GetExecutableNameForImage(CDImage* cdi, ISOReader& iso)
if (pos != std::string::npos) if (pos != std::string::npos)
code.erase(0, pos + 1); code.erase(0, pos + 1);
} }
}
else
{
if (code.compare(0, 6, "cdrom:") == 0)
code.erase(0, 6);
else
Log_WarningPrintf("Unknown prefix in executable path: '%s'", code.c_str());
// remove leading slashes
while (code[0] == '/' || code[0] == '\\')
code.erase(0, 1);
}
// strip off ; or version number // strip off ; or version number
pos = code.rfind(';'); pos = code.rfind(';');
@ -498,7 +513,7 @@ std::string GetExecutableNameForImage(CDImage* cdi)
if (!iso.Open(cdi, 1)) if (!iso.Open(cdi, 1))
return {}; return {};
return GetExecutableNameForImage(cdi, iso); return GetExecutableNameForImage(cdi, iso, true);
} }
bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std::vector<u8>* out_executable_data) bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std::vector<u8>* out_executable_data)
@ -509,19 +524,20 @@ bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std
bool result = false; bool result = false;
std::string executable_name(GetExecutableNameForImage(cdi, iso)); std::string executable_path(GetExecutableNameForImage(cdi, iso, false));
if (!executable_name.empty()) Log_DevPrintf("Executable path: '%s'", executable_path.c_str());
if (!executable_path.empty())
{ {
result = iso.ReadFile(executable_name.c_str(), out_executable_data); result = iso.ReadFile(executable_path.c_str(), out_executable_data);
if (!result) if (!result)
Log_ErrorPrintf("Failed to read executable '%s' from disc", executable_name.c_str()); Log_ErrorPrintf("Failed to read executable '%s' from disc", executable_path.c_str());
} }
if (!result) if (!result)
{ {
// fallback to PSX.EXE // fallback to PSX.EXE
executable_name = "PSX.EXE"; executable_path = "PSX.EXE";
result = iso.ReadFile(executable_name.c_str(), out_executable_data); result = iso.ReadFile(executable_path.c_str(), out_executable_data);
if (!result) if (!result)
Log_ErrorPrint("Failed to read fallback PSX.EXE from disc"); Log_ErrorPrint("Failed to read fallback PSX.EXE from disc");
} }
@ -530,7 +546,7 @@ bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std
return false; return false;
if (out_executable_name) if (out_executable_name)
*out_executable_name = std::move(executable_name); *out_executable_name = std::move(executable_path);
return true; return true;
} }
@ -1866,7 +1882,6 @@ void UpdateMultitaps()
} }
} }
bool DumpRAM(const char* filename) bool DumpRAM(const char* filename)
{ {
if (!IsValid()) if (!IsValid())