System: Store game hash as well as serial

This commit is contained in:
Stenzek
2023-05-15 23:38:37 +10:00
parent 7681551544
commit 9aa6c24620
20 changed files with 243 additions and 211 deletions

View File

@ -296,7 +296,6 @@ static Command s_command = Command::None;
static Command s_command_second_response = Command::None;
static DriveState s_drive_state = DriveState::Idle;
static DiscRegion s_disc_region = DiscRegion::Other;
static bool s_ps1_disc = false;
static StatusRegister s_status = {};
static SecondaryStatusRegister s_secondary_status = {};
@ -666,7 +665,7 @@ DiscRegion CDROM::GetDiscRegion()
bool CDROM::IsMediaPS1Disc()
{
return s_ps1_disc;
return (s_disc_region != DiscRegion::NonPS1);
}
bool CDROM::IsMediaAudioCD()
@ -715,35 +714,21 @@ bool CDROM::CanReadMedia()
return (s_drive_state != DriveState::ShellOpening && m_reader.HasMedia());
}
void CDROM::InsertMedia(std::unique_ptr<CDImage> media)
void CDROM::InsertMedia(std::unique_ptr<CDImage> media, DiscRegion region)
{
if (CanReadMedia())
RemoveMedia(true);
// check if it's a valid PS1 disc
std::string exe_name;
std::vector<u8> exe_buffer;
s_ps1_disc = System::ReadExecutableFromImage(media.get(), &exe_name, &exe_buffer);
Log_InfoPrintf("Inserting new media, disc region: %s, console region: %s",
Settings::GetDiscRegionName(region), Settings::GetConsoleRegionName(System::GetRegion()));
if (s_ps1_disc)
{
// set the region from the system area of the disc
s_disc_region = System::GetRegionForImage(media.get());
Log_InfoPrintf("Inserting new media, disc region: %s, console region: %s",
Settings::GetDiscRegionName(s_disc_region), Settings::GetConsoleRegionName(System::GetRegion()));
}
else
{
s_disc_region = DiscRegion::Other;
Log_InfoPrint("Inserting new media, non-PS1 disc");
}
s_disc_region = region;
m_reader.SetMedia(std::move(media));
SetHoldPosition(0, true);
// motor automatically spins up
if (s_drive_state != DriveState::ShellOpening)
StartMotor();
m_reader.SetMedia(std::move(media));
SetHoldPosition(0, true);
}
std::unique_ptr<CDImage> CDROM::RemoveMedia(bool for_disc_swap)
@ -764,8 +749,7 @@ std::unique_ptr<CDImage> CDROM::RemoveMedia(bool for_disc_swap)
s_secondary_status.motor_on = false;
s_secondary_status.shell_open = true;
s_secondary_status.ClearActiveBits();
s_disc_region = DiscRegion::Other;
s_ps1_disc = false;
s_disc_region = DiscRegion::NonPS1;
// If the drive was doing anything, we need to abort the command.
ClearDriveState();
@ -2683,7 +2667,7 @@ void CDROM::DoIDRead()
static constexpr u32 REGION_STRING_LENGTH = 4;
static constexpr std::array<std::array<u8, REGION_STRING_LENGTH>, static_cast<size_t>(DiscRegion::Count)>
region_strings = {{{'S', 'C', 'E', 'I'}, {'S', 'C', 'E', 'A'}, {'S', 'C', 'E', 'E'}, {0, 0, 0, 0}}};
region_strings = {{{'S', 'C', 'E', 'I'}, {'S', 'C', 'E', 'A'}, {'S', 'C', 'E', 'E'}, {0, 0, 0, 0}, {0, 0, 0, 0}}};
s_async_response_fifo.PushRange(region_strings[static_cast<u8>(s_disc_region)].data(), REGION_STRING_LENGTH);
SetAsyncInterrupt((flags_byte != 0) ? Interrupt::Error : Interrupt::Complete);

View File

@ -25,7 +25,7 @@ bool IsMediaPS1Disc();
bool IsMediaAudioCD();
bool DoesMediaRegionMatchConsole();
void InsertMedia(std::unique_ptr<CDImage> media);
void InsertMedia(std::unique_ptr<CDImage> media, DiscRegion region);
std::unique_ptr<CDImage> RemoveMedia(bool for_disc_swap);
bool PrecacheMedia();

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "game_database.h"
@ -35,7 +35,6 @@ enum : u32
};
static Entry* GetMutableEntry(const std::string_view& serial);
static const Entry* GetEntryForId(const std::string_view& code);
static bool LoadFromCache();
static bool SaveToCache();
@ -111,6 +110,9 @@ void GameDatabase::Unload()
const GameDatabase::Entry* GameDatabase::GetEntryForId(const std::string_view& code)
{
if (code.empty())
return nullptr;
EnsureLoaded();
auto iter = UnorderedStringMapFind(s_code_lookup, code);
@ -144,7 +146,8 @@ std::string GameDatabase::GetSerialForPath(const char* path)
const GameDatabase::Entry* GameDatabase::GetEntryForDisc(CDImage* image)
{
std::string id(System::GetGameIdFromImage(image, false));
std::string id;
System::GetGameDetailsFromImage(image, &id, nullptr);
if (!id.empty())
{
const Entry* entry = GetEntryForId(id);
@ -152,15 +155,7 @@ const GameDatabase::Entry* GameDatabase::GetEntryForDisc(CDImage* image)
return entry;
}
std::string hash_id(System::GetGameHashIdFromImage(image));
if (!hash_id.empty())
{
const Entry* entry = GetEntryForId(hash_id);
if (entry)
return entry;
}
Log_WarningPrintf("No entry found for disc (exe code: '%s', hash code: '%s')", id.c_str(), hash_id.c_str());
Log_WarningPrintf("No entry found for disc '%s'", id.c_str());
return nullptr;
}
@ -498,7 +493,7 @@ void GameDatabase::Entry::ApplySettings(Settings& settings, bool display_osd_mes
"Controller in port %u (%s) is not supported for %s.\nSupported controllers: "
"%s\nPlease configure a supported controller from the list above."),
i + 1u, Host::TranslateString("ControllerType", Settings::GetControllerTypeDisplayName(ctype)).GetCharArray(),
System::GetRunningTitle().c_str(), supported_controller_string.GetCharArray());
System::GetGameTitle().c_str(), supported_controller_string.GetCharArray());
}
}
}

View File

@ -88,6 +88,7 @@ void EnsureLoaded();
void Unload();
const Entry* GetEntryForDisc(CDImage* image);
const Entry* GetEntryForId(const std::string_view& code);
const Entry* GetEntryForSerial(const std::string_view& serial);
std::string GetSerialForDisc(CDImage* image);
std::string GetSerialForPath(const char* path);

View File

@ -788,10 +788,11 @@ const char* Settings::GetConsoleRegionDisplayName(ConsoleRegion region)
return s_console_region_display_names[static_cast<int>(region)];
}
static std::array<const char*, 4> s_disc_region_names = {{"NTSC-J", "NTSC-U", "PAL", "Other"}};
static std::array<const char*, 4> s_disc_region_display_names = {
static std::array<const char*, 5> s_disc_region_names = {{"NTSC-J", "NTSC-U", "PAL", "Other", "Non-PS1"}};
static std::array<const char*, 5> s_disc_region_display_names = {
{TRANSLATABLE("DiscRegion", "NTSC-J (Japan)"), TRANSLATABLE("DiscRegion", "NTSC-U/C (US, Canada)"),
TRANSLATABLE("DiscRegion", "PAL (Europe, Australia)"), TRANSLATABLE("DiscRegion", "Other")}};
TRANSLATABLE("DiscRegion", "PAL (Europe, Australia)"), TRANSLATABLE("DiscRegion", "Other"),
TRANSLATABLE("DiscRegion", "Non-PS1")}};
std::optional<DiscRegion> Settings::ParseDiscRegionName(const char* str)
{

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "system.h"
@ -91,7 +91,6 @@ static bool LoadMemoryState(const MemorySaveState& mss);
static bool LoadEXE(const char* filename);
static std::string GetExecutableNameForImage(ISOReader& iso, bool strip_subdirectories);
static bool ReadExecutableFromImage(ISOReader& iso, std::string* out_executable_name,
std::vector<u8>* out_executable_data);
@ -128,6 +127,7 @@ static void SetTimerResolutionIncreased(bool enabled);
} // namespace System
static constexpr const float PERFORMANCE_COUNTER_UPDATE_INTERVAL = 1.0f;
static constexpr const char FALLBACK_EXE_NAME[] = "PSX.EXE";
static std::unique_ptr<INISettingsInterface> s_game_settings_interface;
static std::unique_ptr<INISettingsInterface> s_input_settings_interface;
@ -147,6 +147,7 @@ static BIOS::Hash s_bios_hash = {};
static std::string s_running_game_path;
static std::string s_running_game_serial;
static std::string s_running_game_title;
static System::GameHash s_running_game_hash;
static bool s_running_unknown_game;
static float s_throttle_frequency = 60.0f;
@ -315,20 +316,25 @@ void System::IncrementInternalFrameNumber()
s_internal_frame_number++;
}
const std::string& System::GetRunningPath()
const std::string& System::GetDiscPath()
{
return s_running_game_path;
}
const std::string& System::GetRunningSerial()
const std::string& System::GetGameSerial()
{
return s_running_game_serial;
}
const std::string& System::GetRunningTitle()
const std::string& System::GetGameTitle()
{
return s_running_game_title;
}
System::GameHash System::GetGameHash()
{
return s_running_game_hash;
}
bool System::IsRunningUnknownGame()
{
return s_running_unknown_game;
@ -447,6 +453,7 @@ ConsoleRegion System::GetConsoleRegionForDiscRegion(DiscRegion region)
case DiscRegion::NTSC_U:
case DiscRegion::Other:
case DiscRegion::NonPS1:
default:
return ConsoleRegion::NTSC_U;
@ -455,70 +462,86 @@ ConsoleRegion System::GetConsoleRegionForDiscRegion(DiscRegion region)
}
}
std::string System::GetGameSerialForPath(const char* image_path, bool fallback_to_hash)
std::string System::GetGameHashId(GameHash hash)
{
std::unique_ptr<CDImage> cdi = CDImage::Open(image_path, false, nullptr);
if (!cdi)
return {};
return GetGameIdFromImage(cdi.get(), fallback_to_hash);
return StringUtil::StdStringFromFormat("HASH-%" PRIX64, hash);
}
std::string System::GetGameIdFromImage(CDImage* cdi, bool fallback_to_hash)
{
std::string code(GetExecutableNameForImage(cdi));
if (!code.empty())
{
// SCES_123.45 -> SCES-12345
for (std::string::size_type pos = 0; pos < code.size();)
{
if (code[pos] == '.')
{
code.erase(pos, 1);
continue;
}
if (code[pos] == '_')
code[pos] = '-';
else
code[pos] = static_cast<char>(std::toupper(code[pos]));
pos++;
}
return code;
}
if (!fallback_to_hash)
return {};
return GetGameHashIdFromImage(cdi);
}
std::string System::GetGameHashIdFromImage(CDImage* cdi)
bool System::GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash* out_hash)
{
ISOReader iso;
if (!iso.Open(cdi, 1))
return {};
{
if (out_id)
out_id->clear();
if (out_hash)
*out_hash = 0;
return false;
}
std::string id;
std::string exe_name;
std::vector<u8> exe_buffer;
if (!ReadExecutableFromImage(cdi, &exe_name, &exe_buffer))
return {};
if (!ReadExecutableFromImage(iso, &exe_name, &exe_buffer))
{
if (out_id)
out_id->clear();
if (out_hash)
*out_hash = 0;
return false;
}
// Always compute the hash.
const u32 track_1_length = cdi->GetTrackLength(1);
XXH64_state_t* state = XXH64_createState();
XXH64_reset(state, 0x4242D00C);
XXH64_update(state, exe_name.c_str(), exe_name.size());
XXH64_update(state, exe_buffer.data(), exe_buffer.size());
XXH64_update(state, &iso.GetPVD(), sizeof(ISOReader::ISOPrimaryVolumeDescriptor));
XXH64_update(state, &track_1_length, sizeof(track_1_length));
const u64 hash = XXH64_digest(state);
const GameHash hash = XXH64_digest(state);
XXH64_freeState(state);
Log_DevPrintf("Hash for '%s' - %" PRIX64, exe_name.c_str(), hash);
Log_InfoPrintf("Hash for '%s' - %" PRIX64, exe_name.c_str(), hash);
return StringUtil::StdStringFromFormat("HASH-%" PRIX64, hash);
if (exe_name != FALLBACK_EXE_NAME)
{
// Strip off any subdirectories.
const std::string::size_type slash = exe_name.rfind('\\');
if (slash != std::string::npos)
id = std::string_view(exe_name).substr(slash + 1);
else
id = exe_name;
// SCES_123.45 -> SCES-12345
for (std::string::size_type pos = 0; pos < id.size();)
{
if (id[pos] == '.')
{
id.erase(pos, 1);
continue;
}
if (id[pos] == '_')
id[pos] = '-';
else
id[pos] = static_cast<char>(std::toupper(id[pos]));
pos++;
}
}
if (out_id)
{
if (id.empty())
*out_id = GetGameHashId(hash);
else
*out_id = std::move(id);
}
if (out_hash)
*out_hash = hash;
return true;
}
std::string System::GetExecutableNameForImage(ISOReader& iso, bool strip_subdirectories)
@ -526,7 +549,7 @@ std::string System::GetExecutableNameForImage(ISOReader& iso, bool strip_subdire
// Read SYSTEM.CNF
std::vector<u8> system_cnf_data;
if (!iso.ReadFile("SYSTEM.CNF", &system_cnf_data))
return {};
return FALLBACK_EXE_NAME;
// Parse lines
std::vector<std::pair<std::string, std::string>> lines;
@ -568,7 +591,10 @@ std::string System::GetExecutableNameForImage(ISOReader& iso, bool strip_subdire
auto iter = std::find_if(lines.begin(), lines.end(),
[](const auto& it) { return StringUtil::Strcasecmp(it.first.c_str(), "boot") == 0; });
if (iter == lines.end())
return {};
{
// Fallback to PSX.EXE
return FALLBACK_EXE_NAME;
}
std::string code = iter->second;
std::string::size_type pos;
@ -608,49 +634,17 @@ std::string System::GetExecutableNameForImage(ISOReader& iso, bool strip_subdire
return code;
}
std::string System::GetExecutableNameForImage(CDImage* cdi)
std::string System::GetExecutableNameForImage(CDImage* cdi, bool strip_subdirectories)
{
ISOReader iso;
if (!iso.Open(cdi, 1))
return {};
return GetExecutableNameForImage(iso, true);
}
bool System::ReadExecutableFromImage(ISOReader& iso, std::string* out_executable_name,
std::vector<u8>* out_executable_data)
{
bool result = false;
std::string executable_path(GetExecutableNameForImage(iso, false));
Log_DevPrintf("Executable path: '%s'", executable_path.c_str());
if (!executable_path.empty())
{
result = iso.ReadFile(executable_path.c_str(), out_executable_data);
if (!result)
Log_ErrorPrintf("Failed to read executable '%s' from disc", executable_path.c_str());
}
if (!result)
{
// fallback to PSX.EXE
executable_path = "PSX.EXE";
result = iso.ReadFile(executable_path.c_str(), out_executable_data);
if (!result)
Log_ErrorPrint("Failed to read fallback PSX.EXE from disc");
}
if (!result)
return false;
if (out_executable_name)
*out_executable_name = std::move(executable_path);
return true;
return GetExecutableNameForImage(iso, strip_subdirectories);
}
bool System::ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name,
std::vector<u8>* out_executable_data)
std::vector<u8>* out_executable_data)
{
ISOReader iso;
if (!iso.Open(cdi, 1))
@ -659,6 +653,25 @@ bool System::ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_n
return ReadExecutableFromImage(iso, out_executable_name, out_executable_data);
}
bool System::ReadExecutableFromImage(ISOReader& iso, std::string* out_executable_name, std::vector<u8>* out_executable_data)
{
const std::string executable_path = GetExecutableNameForImage(iso, false);
Log_DevPrintf("Executable path: '%s'", executable_path.c_str());
if (!executable_path.empty() && out_executable_data)
{
if (!iso.ReadFile(executable_path.c_str(), out_executable_data))
{
Log_ErrorPrintf("Failed to read executable '%s' from disc", executable_path.c_str());
return false;
}
}
if (out_executable_name)
*out_executable_name = std::move(executable_path);
return true;
}
DiscRegion System::GetRegionForSerial(std::string_view serial)
{
std::string prefix;
@ -705,15 +718,25 @@ DiscRegion System::GetRegionFromSystemArea(CDImage* cdi)
DiscRegion System::GetRegionForImage(CDImage* cdi)
{
DiscRegion system_area_region = GetRegionFromSystemArea(cdi);
const DiscRegion system_area_region = GetRegionFromSystemArea(cdi);
if (system_area_region != DiscRegion::Other)
return system_area_region;
std::string serial = GetGameIdFromImage(cdi, false);
if (serial.empty())
return DiscRegion::Other;
ISOReader iso;
if (!iso.Open(cdi, 1))
return DiscRegion::NonPS1;
return GetRegionForSerial(serial);
// The executable must exist, because this just returns PSX.EXE if it doesn't.
const std::string exename = GetExecutableNameForImage(iso, false);
if (exename.empty() || !iso.FileExists(exename.c_str()))
return DiscRegion::NonPS1;
// Strip off any subdirectories.
const std::string::size_type slash = exename.rfind('\\');
if (slash != std::string::npos)
return GetRegionForSerial(std::string_view(exename).substr(slash + 1));
else
return GetRegionForSerial(exename);
}
DiscRegion System::GetRegionForExe(const char* path)
@ -1115,7 +1138,8 @@ bool System::BootSystem(SystemBootParameters parameters)
// Load CD image up and detect region.
Common::Error error;
std::unique_ptr<CDImage> media;
std::unique_ptr<CDImage> disc;
DiscRegion disc_region = DiscRegion::NonPS1;
std::string exe_boot;
std::string psf_boot;
if (!parameters.filename.empty())
@ -1139,8 +1163,8 @@ bool System::BootSystem(SystemBootParameters parameters)
else
{
Log_InfoPrintf("Loading CD image '%s'...", parameters.filename.c_str());
media = CDImage::Open(parameters.filename.c_str(), g_settings.cdrom_load_image_patches, &error);
if (!media)
disc = CDImage::Open(parameters.filename.c_str(), g_settings.cdrom_load_image_patches, &error);
if (!disc)
{
Host::ReportErrorAsync("Error", fmt::format("Failed to load CD image '{}': {}",
Path::GetFileName(parameters.filename), error.GetCodeAndMessage()));
@ -1151,7 +1175,7 @@ bool System::BootSystem(SystemBootParameters parameters)
if (s_region == ConsoleRegion::Auto)
{
const DiscRegion disc_region = GetRegionForImage(media.get());
disc_region = GetRegionForImage(disc.get());
if (disc_region != DiscRegion::Other)
{
s_region = GetConsoleRegionForDiscRegion(disc_region);
@ -1178,7 +1202,7 @@ bool System::BootSystem(SystemBootParameters parameters)
Log_InfoPrintf("Console Region: %s", Settings::GetConsoleRegionDisplayName(s_region));
// Switch subimage.
if (media && parameters.media_playlist_index != 0 && !media->SwitchSubImage(parameters.media_playlist_index, &error))
if (disc && parameters.media_playlist_index != 0 && !disc->SwitchSubImage(parameters.media_playlist_index, &error))
{
Host::ReportFormattedErrorAsync("Error", "Failed to switch to subimage %u in '%s': %s",
parameters.media_playlist_index, parameters.filename.c_str(),
@ -1189,7 +1213,7 @@ bool System::BootSystem(SystemBootParameters parameters)
}
// Update running game, this will apply settings as well.
UpdateRunningGame(media ? media->GetFileName().c_str() : parameters.filename.c_str(), media.get(), true);
UpdateRunningGame(disc ? disc->GetFileName().c_str() : parameters.filename.c_str(), disc.get(), true);
if (!parameters.override_exe.empty())
{
@ -1207,7 +1231,7 @@ bool System::BootSystem(SystemBootParameters parameters)
}
// Check for SBI.
if (!CheckForSBIFile(media.get()))
if (!CheckForSBIFile(disc.get()))
{
s_state = State::Shutdown;
ClearRunningGame();
@ -1274,8 +1298,8 @@ bool System::BootSystem(SystemBootParameters parameters)
}
// Insert CD, and apply fastboot patch if enabled.
if (media)
CDROM::InsertMedia(std::move(media));
if (disc)
CDROM::InsertMedia(std::move(disc), disc_region);
if (CDROM::HasMedia() && (parameters.override_fast_boot.has_value() ? parameters.override_fast_boot.value() :
g_settings.bios_patch_fast_boot))
{
@ -1513,6 +1537,7 @@ void System::ClearRunningGame()
s_running_game_serial.clear();
s_running_game_path.clear();
s_running_game_title.clear();
s_running_game_hash = 0;
s_running_unknown_game = false;
s_cheat_list.reset();
s_state = State::Shutdown;
@ -1967,7 +1992,8 @@ bool System::DoLoadState(ByteStream* state, bool force_software_renderer, bool u
CDROM::Reset();
if (media)
{
CDROM::InsertMedia(std::move(media));
const DiscRegion region = GetRegionForImage(media.get());
CDROM::InsertMedia(std::move(media), region);
if (g_settings.cdrom_load_image_to_ram)
CDROM::PrecacheMedia();
}
@ -2997,8 +3023,9 @@ bool System::InsertMedia(const char* path)
return false;
}
const DiscRegion region = GetRegionForImage(image.get());
UpdateRunningGame(path, image.get(), false);
CDROM::InsertMedia(std::move(image));
CDROM::InsertMedia(std::move(image), region);
Log_InfoPrintf("Inserted media from %s (%s, %s)", s_running_game_path.c_str(), s_running_game_serial.c_str(),
s_running_game_title.c_str());
if (g_settings.cdrom_load_image_to_ram)
@ -3031,6 +3058,7 @@ void System::UpdateRunningGame(const char* path, CDImage* image, bool booting)
s_running_game_path.clear();
s_running_game_serial.clear();
s_running_game_title.clear();
s_running_game_hash = 0;
s_running_unknown_game = true;
if (path && std::strlen(path) > 0)
@ -3044,7 +3072,10 @@ void System::UpdateRunningGame(const char* path, CDImage* image, bool booting)
}
else if (image)
{
const GameDatabase::Entry* entry = GameDatabase::GetEntryForDisc(image);
std::string id;
GetGameDetailsFromImage(image, &id, &s_running_game_hash);
const GameDatabase::Entry* entry = GameDatabase::GetEntryForId(id);
if (entry)
{
s_running_game_serial = entry->serial;
@ -3053,9 +3084,8 @@ void System::UpdateRunningGame(const char* path, CDImage* image, bool booting)
}
else
{
const std::string display_name(FileSystem::GetDisplayNameFromPath(path));
s_running_game_serial = GetGameIdFromImage(image, true);
s_running_game_title = Path::GetFileTitle(display_name);
s_running_game_serial = std::move(id);
s_running_game_title = Path::GetFileTitle(FileSystem::GetDisplayNameFromPath(path));
}
if (image->HasSubImages() && g_settings.memory_card_use_playlist_title)
@ -3182,14 +3212,17 @@ bool System::SwitchMediaSubImage(u32 index)
Host::AddFormattedOSDMessage(10.0f,
Host::TranslateString("OSDMessage", "Failed to switch to subimage %u in '%s': %s."),
index + 1u, image->GetFileName().c_str(), error.GetCodeAndMessage().GetCharArray());
CDROM::InsertMedia(std::move(image));
const DiscRegion region = GetRegionForImage(image.get());
CDROM::InsertMedia(std::move(image), region);
return false;
}
Host::AddFormattedOSDMessage(20.0f, Host::TranslateString("OSDMessage", "Switched to sub-image %s (%u) in '%s'."),
image->GetSubImageMetadata(index, "title").c_str(), index + 1u,
image->GetMetadata("title").c_str());
CDROM::InsertMedia(std::move(image));
const DiscRegion region = GetRegionForImage(image.get());
CDROM::InsertMedia(std::move(image), region);
ClearMemorySaveStates();
return true;
@ -3840,7 +3873,7 @@ bool System::StartDumpingAudio(const char* filename)
std::string auto_filename;
if (!filename)
{
const auto& serial = System::GetRunningSerial();
const auto& serial = System::GetGameSerial();
if (serial.empty())
{
auto_filename = Path::Combine(
@ -3885,7 +3918,7 @@ bool System::SaveScreenshot(const char* filename /* = nullptr */, bool full_reso
std::string auto_filename;
if (!filename)
{
const auto& code = System::GetRunningSerial();
const auto& code = System::GetGameSerial();
const char* extension = "png";
if (code.empty())
{
@ -4079,7 +4112,7 @@ std::string System::GetCheatFileName()
{
std::string ret;
const std::string& title = System::GetRunningTitle();
const std::string& title = System::GetGameTitle();
if (!title.empty())
ret = Path::Combine(EmuFolders::Cheats, fmt::format("{}.cht", title.c_str()));

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#pragma once
@ -88,6 +88,8 @@ enum class State
Paused
};
using GameHash = u64;
extern TickCount g_ticks_per_second;
/// Returns true if the filename is a PlayStation executable we can inject.
@ -105,12 +107,12 @@ bool IsSaveStateFilename(const std::string_view& path);
/// Returns the preferred console type for a disc.
ConsoleRegion GetConsoleRegionForDiscRegion(DiscRegion region);
std::string GetExecutableNameForImage(CDImage* cdi);
std::string GetExecutableNameForImage(CDImage* cdi, bool strip_subdirectories);
bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std::vector<u8>* out_executable_data);
std::string GetGameHashIdFromImage(CDImage* cdi);
std::string GetGameIdFromImage(CDImage* cdi, bool fallback_to_hash);
std::string GetGameSerialForPath(const char* image_path, bool fallback_to_hash);
bool IsValidGameImage(CDImage* cdi);
std::string GetGameHashId(GameHash hash);
bool GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash* out_hash);
DiscRegion GetRegionForSerial(std::string_view serial);
DiscRegion GetRegionFromSystemArea(CDImage* cdi);
DiscRegion GetRegionForImage(CDImage* cdi);
@ -177,11 +179,12 @@ u32 GetInternalFrameNumber();
void FrameDone();
void IncrementInternalFrameNumber();
const std::string& GetRunningPath();
const std::string& GetRunningSerial();
const std::string& GetRunningTitle();
const std::string& GetDiscPath();
const std::string& GetGameSerial();
const std::string& GetGameTitle();
GameHash GetGameHash();
bool IsRunningUnknownGame();
const BIOS::ImageInfo* GetBIOSImageInfo();
const BIOS::Hash& GetBIOSHash();

View File

@ -37,6 +37,7 @@ enum class DiscRegion : u8
NTSC_U, // SCEA
PAL, // SCEE
Other,
NonPS1,
Count
};