VMManager: Support picking between en and non-en title

This commit is contained in:
TellowKrinkle 2023-10-15 19:27:07 -05:00 committed by TellowKrinkle
parent 4ed9ade4fc
commit b28c11cb54
7 changed files with 28 additions and 11 deletions

View File

@ -2992,7 +2992,7 @@ void Achievements::RAIntegration::RACallbackRebuildMenu()
void Achievements::RAIntegration::RACallbackEstimateTitle(char* buf)
{
std::string title(fmt::format("{0} ({1}) [{2:08X}]", VMManager::GetTitle(), VMManager::GetDiscSerial(), VMManager::GetDiscCRC()));
std::string title(fmt::format("{0} ({1}) [{2:08X}]", VMManager::GetTitle(false), VMManager::GetDiscSerial(), VMManager::GetDiscCRC()));
StringUtil::Strlcpy(buf, title, 256);
}

View File

@ -810,7 +810,7 @@ static std::string GSGetBaseFilename()
std::string filename;
// append the game serial and title
if (std::string name(VMManager::GetTitle()); !name.empty())
if (std::string name(VMManager::GetTitle(true)); !name.empty())
{
Path::SanitizeFileName(&name);
if (name.length() > 219)

View File

@ -515,7 +515,7 @@ bool FullscreenUI::Initialize()
if (VMManager::HasValidVM())
{
UpdateGameDetails(VMManager::GetDiscPath(), VMManager::GetDiscSerial(), VMManager::GetTitle(), VMManager::GetDiscCRC(),
UpdateGameDetails(VMManager::GetDiscPath(), VMManager::GetDiscSerial(), VMManager::GetTitle(true), VMManager::GetDiscCRC(),
VMManager::GetCurrentCRC());
}
else

View File

@ -438,7 +438,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{
if (!VMManager::HasValidVM())
goto error;
const std::string gameName = VMManager::GetTitle();
const std::string gameName = VMManager::GetTitle(false);
const u32 size = gameName.size() + 1;
if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size))
goto error;

View File

@ -82,7 +82,7 @@ bool InputRecording::create(const std::string& fileName, const bool fromSaveStat
m_file.setEmulatorVersion();
m_file.setAuthor(authorName);
m_file.setGameName(VMManager::GetTitle());
m_file.setGameName(VMManager::GetTitle(false));
m_file.writeHeader();
initializeState();
InputRec::log("Started new input recording");
@ -133,9 +133,9 @@ bool InputRecording::play(const std::string& filename)
initializeState();
InputRec::log("Replaying input recording");
m_file.logRecordingMetadata();
if (VMManager::GetTitle() != m_file.getGameName())
if (VMManager::GetTitle(false) != m_file.getGameName())
{
InputRec::consoleLog(fmt::format("Input recording was possibly constructed for a different game. Expected: {}, Actual: {}", m_file.getGameName(), VMManager::GetTitle()));
InputRec::consoleLog(fmt::format("Input recording was possibly constructed for a different game. Expected: {}, Actual: {}", m_file.getGameName(), VMManager::GetTitle(false)));
}
return true;
}

View File

@ -163,6 +163,8 @@ static std::string s_disc_serial;
static std::string s_disc_elf;
static std::string s_disc_version;
static std::string s_title;
static std::string s_title_en_search;
static std::string s_title_en_replace;
static u32 s_disc_crc;
static u32 s_current_crc;
static u32 s_elf_entry_point = 0xFFFFFFFFu;
@ -302,10 +304,17 @@ std::string VMManager::GetDiscELF()
return s_disc_elf;
}
std::string VMManager::GetTitle()
std::string VMManager::GetTitle(bool prefer_en)
{
std::unique_lock lock(s_info_mutex);
return s_title;
std::string out = s_title;
if (!s_title_en_search.empty())
{
size_t pos = out.find(s_title_en_search);
if (pos != out.npos)
out.replace(pos, s_title_en_search.size(), s_title_en_replace);
}
return out;
}
u32 VMManager::GetDiscCRC()
@ -850,11 +859,19 @@ void VMManager::UpdateDiscDetails(bool booting)
SaveSessionTime(old_serial);
s_title_en_search.clear();
s_title_en_replace.clear();
std::string custom_title = GameList::GetCustomTitleForPath(CDVDsys_GetFile(CDVDsys_GetSourceType()));
if (serial_is_valid)
{
if (const GameDatabaseSchema::GameEntry* game = GameDatabase::findGame(s_disc_serial))
{
if (!game->name_en.empty())
{
s_title_en_search = game->name;
s_title_en_replace = game->name_en;
}
std::string game_title = custom_title.empty() ? game->name : std::move(custom_title);
// Append the ELF override if we're using it with a disc.
@ -985,7 +1002,7 @@ void VMManager::ReportGameChangeToHost()
{
const std::string& disc_path = CDVDsys_GetFile(CDVDsys_GetSourceType());
const u32 crc_to_report = HasBootedELF() ? s_current_crc : 0;
FullscreenUI::GameChanged(disc_path, s_disc_serial, s_title, s_disc_crc, crc_to_report);
FullscreenUI::GameChanged(disc_path, s_disc_serial, GetTitle(true), s_disc_crc, crc_to_report);
Host::OnGameChanged(s_title, s_elf_override, disc_path, s_disc_serial, s_disc_crc, crc_to_report);
}

View File

@ -79,7 +79,7 @@ namespace VMManager
std::string GetDiscELF();
/// Returns the name of the disc/executable currently running.
std::string GetTitle();
std::string GetTitle(bool prefer_en);
/// Returns the CRC for the main ELF of the disc currently running.
u32 GetDiscCRC();