Working Game IDs for Elf/Dol files

This commit is contained in:
cbartondock
2021-01-21 10:47:07 -05:00
parent ebf3b5faf4
commit 83c127784b
5 changed files with 32 additions and 6 deletions

View File

@ -4,11 +4,14 @@
#include "Core/ConfigManager.h"
#include <algorithm>
#include <cinttypes>
#include <climits>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <string_view>
#include <variant>
#include <fmt/format.h>
@ -653,6 +656,11 @@ void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd, DiscIO::Plat
}
}
void SConfig::SetRunningGameMetadata(const std::string& game_id)
{
SetRunningGameMetadata(game_id, "", 0, 0, DiscIO::Region::Unknown);
}
void SConfig::SetRunningGameMetadata(const std::string& game_id, const std::string& gametdb_id,
u64 title_id, u16 revision, DiscIO::Region region)
{
@ -770,6 +778,15 @@ bool SConfig::IsUSBDeviceWhitelisted(const std::pair<u16, u16> vid_pid) const
return m_usb_passthrough_devices.find(vid_pid) != m_usb_passthrough_devices.end();
}
// Static method to make a simple game ID for elf/dol files
std::string SConfig::MakeGameID(std::string_view file_name)
{
size_t lastdot = file_name.find_last_of(".");
if (lastdot == std::string::npos)
return "ID-" + std::string(file_name);
return "ID-" + std::string(file_name.substr(0, lastdot));
}
// The reason we need this function is because some memory card code
// expects to get a non-NTSC-K region even if we're emulating an NTSC-K Wii.
DiscIO::Region SConfig::ToGameCubeRegion(DiscIO::Region region)
@ -840,6 +857,13 @@ struct SetGameMetadata
// Strip the .elf/.dol file extension and directories before the name
SplitPath(executable.path, nullptr, &config->m_debugger_game_id, nullptr);
// Set DOL/ELF game ID appropriately
std::string executable_path = executable.path;
constexpr char BACKSLASH = '\\';
constexpr char FORWARDSLASH = '/';
std::replace(executable_path.begin(), executable_path.end(), BACKSLASH, FORWARDSLASH);
config->SetRunningGameMetadata(SConfig::MakeGameID(PathToFileName(executable_path)));
Host_TitleChanged();
return true;