Skip to content

Commit

Permalink
VMManager: Support picking between en and non-en title
Browse files Browse the repository at this point in the history
  • Loading branch information
TellowKrinkle committed Oct 16, 2023
1 parent 79be028 commit 1793d8d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pcsx2/Achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/Common/GSRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/ImGui/FullscreenUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/PINE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions pcsx2/Recording/InputRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down
21 changes: 19 additions & 2 deletions pcsx2/VMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/VMManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1793d8d

Please sign in to comment.