From ced1614cacab2adda6997091a8a3eebf6cf3334a Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 9 Mar 2017 09:47:43 +0100 Subject: [PATCH 1/3] Unify the way of setting game ID, title ID, revision The existing code from ConfigManager, ES and MIOS is merged into a new set of functions called SetRunningGameMetadata. --- Source/Core/Core/BootManager.cpp | 3 +- Source/Core/Core/ConfigManager.cpp | 108 ++++++++++++------ Source/Core/Core/ConfigManager.h | 24 +++- .../Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp | 2 +- Source/Core/Core/IOS/ES/ES.cpp | 49 +------- Source/Core/Core/IOS/ES/Formats.cpp | 6 + Source/Core/Core/IOS/ES/Formats.h | 1 + Source/Core/Core/IOS/MIOS.cpp | 12 +- Source/Core/Core/Movie.cpp | 2 +- Source/Core/Core/WiiRoot.cpp | 12 +- Source/Core/DolphinWX/Cheats/CheatsWindow.cpp | 2 +- .../Core/DolphinWX/Debugger/DebuggerPanel.cpp | 2 +- .../VideoBackends/D3D/GeometryShaderCache.cpp | 2 +- .../VideoBackends/D3D/PixelShaderCache.cpp | 2 +- .../VideoBackends/D3D/VertexShaderCache.cpp | 2 +- Source/Core/VideoBackends/D3D12/D3DState.cpp | 2 +- .../Core/VideoBackends/D3D12/ShaderCache.cpp | 2 +- .../VideoBackends/OGL/ProgramShaderCache.cpp | 2 +- .../Core/VideoBackends/Vulkan/ObjectCache.cpp | 2 +- Source/Core/VideoCommon/HiresTextures.cpp | 4 +- Source/Core/VideoCommon/TextureCacheBase.cpp | 2 +- 21 files changed, 126 insertions(+), 117 deletions(-) diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index 217566be80..ea9e68b079 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -415,8 +415,7 @@ void Stop() void RestoreConfig() { SConfig::GetInstance().LoadSettingsFromSysconf(); - SConfig::GetInstance().m_strGameID = "00000000"; - SConfig::GetInstance().m_title_id = 0; + SConfig::GetInstance().ResetRunningGameMetadata(); config_cache.RestoreConfig(&SConfig::GetInstance()); } diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 23d72da278..7c30c41c1f 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -21,11 +21,16 @@ #include "Core/Boot/Boot.h" #include "Core/Boot/Boot_DOL.h" #include "Core/ConfigManager.h" -#include "Core/Core.h" // for bWii +#include "Core/Core.h" #include "Core/FifoPlayer/FifoDataFile.h" +#include "Core/HLE/HLE.h" #include "Core/HW/SI/SI.h" +#include "Core/IOS/ES/Formats.h" #include "Core/IOS/USB/Bluetooth/BTBase.h" +#include "Core/PatchEngine.h" +#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PowerPC.h" +#include "VideoCommon/HiresTextures.h" #include "DiscIO/Enums.h" #include "DiscIO/NANDContentLoader.h" @@ -726,6 +731,67 @@ void SConfig::LoadSettingsFromSysconf() bPAL60 = sysconf.GetData("IPL.E60") != 0; } +void SConfig::ResetRunningGameMetadata() +{ + SetRunningGameMetadata("00000000", 0, 0); +} + +void SConfig::SetRunningGameMetadata(const DiscIO::IVolume& volume) +{ + u64 title_id = 0; + volume.GetTitleID(&title_id); + SetRunningGameMetadata(volume.GetGameID(), title_id, volume.GetRevision()); +} + +void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd) +{ + const u64 title_id = tmd.GetTitleId(); + std::string game_id; + + if (IOS::ES::IsDiscTitle(title_id)) + { + const u32 title_identifier = Common::swap32(static_cast(title_id)); + const u16 group_id = Common::swap16(tmd.GetGroupId()); + + char ascii_game_id[6]; + std::memcpy(ascii_game_id, &title_identifier, sizeof(title_identifier)); + std::memcpy(ascii_game_id + sizeof(title_identifier), &group_id, sizeof(group_id)); + + game_id = ascii_game_id; + } + else + { + game_id = StringFromFormat("%016" PRIX64, title_id); + } + + SetRunningGameMetadata(game_id, title_id, tmd.GetTitleVersion()); +} + +void SConfig::SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision) +{ + const bool was_changed = m_game_id != game_id || m_title_id != title_id || m_revision != revision; + m_game_id = game_id; + m_title_id = title_id; + m_revision = revision; + + if (was_changed) + { + NOTICE_LOG(BOOT, "Game ID set to %s", game_id.c_str()); + + if (Core::IsRunning()) + { + // TODO: have a callback mechanism for title changes? + g_symbolDB.Clear(); + CBoot::LoadMapFromFilename(); + HLE::Clear(); + HLE::PatchFunctions(); + PatchEngine::Shutdown(); + PatchEngine::LoadPatches(); + HiresTexture::Update(); + } + } +} + void SConfig::LoadDefaults() { bEnableDebugging = false; @@ -783,9 +849,7 @@ void SConfig::LoadDefaults() bJITSystemRegistersOff = false; bJITBranchOff = false; - m_strGameID = "00000000"; - m_title_id = 0; - m_revision = 0; + ResetRunningGameMetadata(); } bool SConfig::IsUSBDeviceWhitelisted(const std::pair vid_pid) const @@ -870,9 +934,7 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2) m_strFilename.c_str()); return false; } - m_strGameID = pVolume->GetGameID(); - pVolume->GetTitleID(&m_title_id); - m_revision = pVolume->GetRevision(); + SetRunningGameMetadata(*pVolume); // Check if we have a Wii disc bWii = pVolume->GetVolumeType() == DiscIO::Platform::WII_DISC; @@ -916,11 +978,11 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2) } else if (DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename).IsValid()) { - std::unique_ptr pVolume(DiscIO::CreateVolumeFromFilename(m_strFilename)); - const DiscIO::CNANDContentLoader& ContentLoader = + const DiscIO::CNANDContentLoader& content_loader = DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename); + const IOS::ES::TMDReader& tmd = content_loader.GetTMD(); - if (ContentLoader.GetContentByIndex(ContentLoader.GetTMD().GetBootIndex()) == nullptr) + if (content_loader.GetContentByIndex(tmd.GetBootIndex()) == nullptr) { // WAD is valid yet cannot be booted. Install instead. u64 installed = DiscIO::CNANDContentManager::Access().Install_WiiWAD(m_strFilename); @@ -929,33 +991,11 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2) return false; // do not boot } - SetRegion(ContentLoader.GetTMD().GetRegion(), &set_region_dir); + SetRegion(tmd.GetRegion(), &set_region_dir); + SetRunningGameMetadata(tmd); bWii = true; m_BootType = BOOT_WII_NAND; - - if (pVolume) - { - m_strGameID = pVolume->GetGameID(); - pVolume->GetTitleID(&m_title_id); - } - else - { - // null pVolume means that we are loading from nand folder (Most Likely Wii Menu) - // if this is the second boot we would be using the Name and id of the last title - m_strGameID.clear(); - m_title_id = 0; - } - - // Use the TitleIDhex for name and/or game ID if launching - // from nand folder or if it is not ascii characters - // (specifically sysmenu could potentially apply to other things) - std::string titleidstr = StringFromFormat("%016" PRIx64, m_title_id); - - if (m_strGameID.empty()) - { - m_strGameID = titleidstr; - } } else { diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 9d70841cd7..efa3ca8d72 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -19,6 +19,14 @@ namespace DiscIO { enum class Language; enum class Region; +class IVolume; +} +namespace IOS +{ +namespace ES +{ +class TMDReader; +} } // DSP Backend Types @@ -209,17 +217,20 @@ struct SConfig : NonCopyable std::string m_strDefaultISO; std::string m_strDVDRoot; std::string m_strApploader; - std::string m_strGameID; - u64 m_title_id; std::string m_strWiiSDCardPath; - u16 m_revision; std::string m_perfDir; + const std::string& GetGameID() const { return m_game_id; } + u64 GetTitleID() const { return m_title_id; } + u16 GetRevision() const { return m_revision; } + void ResetRunningGameMetadata(); + void SetRunningGameMetadata(const DiscIO::IVolume& volume); + void SetRunningGameMetadata(const IOS::ES::TMDReader& tmd); + void LoadDefaults(); static const char* GetDirectoryForRegion(DiscIO::Region region); bool AutoSetup(EBootBS2 _BootBS2); - const std::string& GetGameID() const { return m_strGameID; } void CheckMemcardPath(std::string& memcardPath, const std::string& gameRegion, bool isSlotA); DiscIO::Language GetCurrentLanguage(bool wii) const; @@ -373,7 +384,12 @@ private: void LoadUSBPassthroughSettings(IniFile& ini); void LoadSysconfSettings(IniFile& ini); + void SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision); bool SetRegion(DiscIO::Region region, std::string* directory_name); static SConfig* m_Instance; + + std::string m_game_id; + u64 m_title_id; + u16 m_revision; }; diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp index 86fa60db5a..69654a4cbf 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp @@ -156,7 +156,7 @@ void CEXIMemoryCard::SetupGciFolder(u16 sizeMb) { DiscIO::Region region = SConfig::GetInstance().m_region; - std::string game_id = SConfig::GetInstance().m_strGameID; + const std::string& game_id = SConfig::GetInstance().GetGameID(); u32 CurrentGameId = 0; if (game_id.length() >= 4 && game_id != "00000000" && game_id != TITLEID_SYSMENU_STRING) CurrentGameId = BE32((u8*)game_id.c_str()); diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index 63ff222397..7e0f13d338 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -24,17 +24,12 @@ #include "Common/MsgHandler.h" #include "Common/NandPaths.h" #include "Common/Swap.h" -#include "Core/Boot/Boot.h" #include "Core/ConfigManager.h" -#include "Core/HLE/HLE.h" #include "Core/HW/Memmap.h" #include "Core/IOS/ES/Formats.h" -#include "Core/PatchEngine.h" -#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/ec_wii.h" #include "DiscIO/NANDContentLoader.h" #include "DiscIO/Volume.h" -#include "VideoCommon/HiresTextures.h" namespace IOS { @@ -48,7 +43,6 @@ struct TitleContext void DoState(PointerWrap& p); void Update(const DiscIO::CNANDContentLoader& content_loader); void Update(const IOS::ES::TMDReader& tmd_, const IOS::ES::TicketReader& ticket_); - void UpdateRunningGame() const; IOS::ES::TicketReader ticket; IOS::ES::TMDReader tmd; @@ -86,12 +80,6 @@ constexpr const u8* s_key_table[11] = { s_key_empty, // Unknown }; -static bool IsDiscTitle(u64 title_id) -{ - return IsTitleType(title_id, IOS::ES::TitleType::Game) || - IsTitleType(title_id, IOS::ES::TitleType::GameWithChannel); -} - ES::ES(u32 device_id, const std::string& device_name) : Device(device_id, device_name) { } @@ -145,43 +133,11 @@ void TitleContext::Update(const IOS::ES::TMDReader& tmd_, const IOS::ES::TicketR // Interesting title changes (channel or disc game launch) always happen after an IOS reload. if (first_change) { - UpdateRunningGame(); + SConfig::GetInstance().SetRunningGameMetadata(tmd); first_change = false; } } -void TitleContext::UpdateRunningGame() const -{ - if (IsDiscTitle(tmd.GetTitleId())) - { - const u32 title_identifier = Common::swap32(static_cast(tmd.GetTitleId())); - const u16 group_id = Common::swap16(tmd.GetGroupId()); - - char ascii_game_id[6]; - std::memcpy(ascii_game_id, &title_identifier, sizeof(title_identifier)); - std::memcpy(ascii_game_id + sizeof(title_identifier), &group_id, sizeof(group_id)); - - SConfig::GetInstance().m_strGameID = ascii_game_id; - } - else - { - SConfig::GetInstance().m_strGameID = StringFromFormat("%016" PRIX64, tmd.GetTitleId()); - } - - SConfig::GetInstance().m_title_id = tmd.GetTitleId(); - - // TODO: have a callback mechanism for title changes? - g_symbolDB.Clear(); - CBoot::LoadMapFromFilename(); - ::HLE::Clear(); - ::HLE::PatchFunctions(); - PatchEngine::Shutdown(); - PatchEngine::LoadPatches(); - HiresTexture::Update(); - - NOTICE_LOG(IOS_ES, "Active title: %016" PRIx64, tmd.GetTitleId()); -} - void ES::LoadWAD(const std::string& _rContentFile) { s_content_file = _rContentFile; @@ -1040,7 +996,8 @@ IPCCommandResult ES::GetTitles(const IOCtlVRequest& request) static bool ShouldReturnFakeViewsForIOSes(u64 title_id) { const bool ios = IsTitleType(title_id, IOS::ES::TitleType::System) && title_id != TITLEID_SYSMENU; - const bool disc_title = s_title_context.active && IsDiscTitle(s_title_context.tmd.GetTitleId()); + const bool disc_title = + s_title_context.active && IOS::ES::IsDiscTitle(s_title_context.tmd.GetTitleId()); return ios && SConfig::GetInstance().m_BootType == SConfig::BOOT_ISO && disc_title; } diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 7e5541d723..e8ecffb6d5 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -26,6 +26,12 @@ bool IsTitleType(u64 title_id, TitleType title_type) return static_cast(title_id >> 32) == static_cast(title_type); } +bool IsDiscTitle(u64 title_id) +{ + return IsTitleType(title_id, TitleType::Game) || + IsTitleType(title_id, TitleType::GameWithChannel); +} + bool Content::IsShared() const { return (type & 0x8000) != 0; diff --git a/Source/Core/Core/IOS/ES/Formats.h b/Source/Core/Core/IOS/ES/Formats.h index de31b78d0b..11466bce7c 100644 --- a/Source/Core/Core/IOS/ES/Formats.h +++ b/Source/Core/Core/IOS/ES/Formats.h @@ -30,6 +30,7 @@ enum class TitleType : u32 }; bool IsTitleType(u64 title_id, TitleType title_type); +bool IsDiscTitle(u64 title_id); #pragma pack(push, 4) struct TMDHeader diff --git a/Source/Core/Core/IOS/MIOS.cpp b/Source/Core/Core/IOS/MIOS.cpp index 0d6289a31c..a7e51f51fe 100644 --- a/Source/Core/Core/IOS/MIOS.cpp +++ b/Source/Core/Core/IOS/MIOS.cpp @@ -12,7 +12,6 @@ #include "Common/MsgHandler.h" #include "Common/NandPaths.h" #include "Common/Swap.h" -#include "Core/Boot/Boot.h" #include "Core/Boot/ElfReader.h" #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -124,17 +123,8 @@ static void ReinitHardware() static void UpdateRunningGame() { DVDThread::WaitUntilIdle(); - const DiscIO::IVolume& volume = DVDInterface::GetVolume(); SConfig::GetInstance().m_BootType = SConfig::BOOT_MIOS; - SConfig::GetInstance().m_strGameID = volume.GetGameID(); - SConfig::GetInstance().m_revision = volume.GetRevision(); - - g_symbolDB.Clear(); - CBoot::LoadMapFromFilename(); - ::HLE::Clear(); - ::HLE::PatchFunctions(); - - NOTICE_LOG(IOS, "Running game: %s", SConfig::GetInstance().m_strGameID.c_str()); + SConfig::GetInstance().SetRunningGameMetadata(DVDInterface::GetVolume()); } constexpr u32 ADDRESS_INIT_SEMAPHORE = 0x30f8; diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 0f34fa0b31..c16f360945 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -1477,7 +1477,7 @@ void GetSettings() s_bNetPlay = NetPlay::IsNetPlayRunning(); if (SConfig::GetInstance().bWii) { - u64 title_id = SConfig::GetInstance().m_title_id; + u64 title_id = SConfig::GetInstance().GetTitleID(); s_bClearSave = !File::Exists(Common::GetTitleDataPath(title_id, Common::FROM_SESSION_ROOT) + "banner.bin"); s_language = SConfig::GetInstance().m_wii_language; diff --git a/Source/Core/Core/WiiRoot.cpp b/Source/Core/Core/WiiRoot.cpp index c2cddfee18..6ff2deb6bf 100644 --- a/Source/Core/Core/WiiRoot.cpp +++ b/Source/Core/Core/WiiRoot.cpp @@ -27,9 +27,9 @@ static std::string s_temp_wii_root; static void InitializeDeterministicWiiSaves() { std::string save_path = - Common::GetTitleDataPath(SConfig::GetInstance().m_title_id, Common::FROM_SESSION_ROOT); + Common::GetTitleDataPath(SConfig::GetInstance().GetTitleID(), Common::FROM_SESSION_ROOT); std::string user_save_path = - Common::GetTitleDataPath(SConfig::GetInstance().m_title_id, Common::FROM_CONFIGURED_ROOT); + Common::GetTitleDataPath(SConfig::GetInstance().GetTitleID(), Common::FROM_CONFIGURED_ROOT); if (Movie::IsRecordingInput()) { if (NetPlay::IsNetPlayRunning() && !SConfig::GetInstance().bCopyWiiSaveNetplay) @@ -93,13 +93,13 @@ void ShutdownWiiRoot() if (!s_temp_wii_root.empty()) { std::string save_path = - Common::GetTitleDataPath(SConfig::GetInstance().m_title_id, Common::FROM_SESSION_ROOT); + Common::GetTitleDataPath(SConfig::GetInstance().GetTitleID(), Common::FROM_SESSION_ROOT); std::string user_save_path = - Common::GetTitleDataPath(SConfig::GetInstance().m_title_id, Common::FROM_CONFIGURED_ROOT); + Common::GetTitleDataPath(SConfig::GetInstance().GetTitleID(), Common::FROM_CONFIGURED_ROOT); std::string user_backup_path = File::GetUserPath(D_BACKUP_IDX) + - StringFromFormat("%08x/%08x/", static_cast(SConfig::GetInstance().m_title_id >> 32), - static_cast(SConfig::GetInstance().m_title_id)); + StringFromFormat("%08x/%08x/", static_cast(SConfig::GetInstance().GetTitleID() >> 32), + static_cast(SConfig::GetInstance().GetTitleID())); if (File::Exists(save_path + "banner.bin") && SConfig::GetInstance().bEnableMemcardSdWriting) { // Backup the existing save just in case it's still needed. diff --git a/Source/Core/DolphinWX/Cheats/CheatsWindow.cpp b/Source/Core/DolphinWX/Cheats/CheatsWindow.cpp index c8d26fb736..27983cc23f 100644 --- a/Source/Core/DolphinWX/Cheats/CheatsWindow.cpp +++ b/Source/Core/DolphinWX/Cheats/CheatsWindow.cpp @@ -177,7 +177,7 @@ void wxCheatsWindow::UpdateGUI() m_gameini_default = parameters.LoadDefaultGameIni(); m_gameini_local = parameters.LoadLocalGameIni(); m_game_id = parameters.GetGameID(); - m_game_revision = parameters.m_revision; + m_game_revision = parameters.GetRevision(); m_gameini_local_path = File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini"; Load_ARCodes(); Load_GeckoCodes(); diff --git a/Source/Core/DolphinWX/Debugger/DebuggerPanel.cpp b/Source/Core/DolphinWX/Debugger/DebuggerPanel.cpp index 01d2cf19ba..a5284ea145 100644 --- a/Source/Core/DolphinWX/Debugger/DebuggerPanel.cpp +++ b/Source/Core/DolphinWX/Debugger/DebuggerPanel.cpp @@ -232,7 +232,7 @@ void GFXDebuggerPanel::OnPauseAtNextFrameButton(wxCommandEvent& event) void GFXDebuggerPanel::OnDumpButton(wxCommandEvent& event) { std::string dump_path = - File::GetUserPath(D_DUMP_IDX) + "Debug/" + SConfig::GetInstance().m_strGameID + "/"; + File::GetUserPath(D_DUMP_IDX) + "Debug/" + SConfig::GetInstance().GetGameID() + "/"; if (!File::CreateFullPath(dump_path)) return; diff --git a/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp b/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp index 2114a23d99..6dbd3d3dde 100644 --- a/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp @@ -164,7 +164,7 @@ void GeometryShaderCache::Init() std::string cache_filename = StringFromFormat("%sdx11-%s-gs.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), - SConfig::GetInstance().m_strGameID.c_str()); + SConfig::GetInstance().GetGameID().c_str()); GeometryShaderCacheInserter inserter; g_gs_disk_cache.OpenAndRead(cache_filename, inserter); } diff --git a/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp b/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp index a1090fa2f2..289e9a32f9 100644 --- a/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp @@ -504,7 +504,7 @@ void PixelShaderCache::Init() std::string cache_filename = StringFromFormat("%sdx11-%s-ps.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), - SConfig::GetInstance().m_strGameID.c_str()); + SConfig::GetInstance().GetGameID().c_str()); PixelShaderCacheInserter inserter; g_ps_disk_cache.OpenAndRead(cache_filename, inserter); } diff --git a/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp b/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp index 1dc26c09fc..1ca0982e6f 100644 --- a/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp @@ -165,7 +165,7 @@ void VertexShaderCache::Init() std::string cache_filename = StringFromFormat("%sdx11-%s-vs.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), - SConfig::GetInstance().m_strGameID.c_str()); + SConfig::GetInstance().GetGameID().c_str()); VertexShaderCacheInserter inserter; g_vs_disk_cache.OpenAndRead(cache_filename, inserter); } diff --git a/Source/Core/VideoBackends/D3D12/D3DState.cpp b/Source/Core/VideoBackends/D3D12/D3DState.cpp index 6b0f0dd807..7b16194e78 100644 --- a/Source/Core/VideoBackends/D3D12/D3DState.cpp +++ b/Source/Core/VideoBackends/D3D12/D3DState.cpp @@ -143,7 +143,7 @@ void StateCache::Init() std::string cache_filename = StringFromFormat("%sdx12-%s-pso.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), - SConfig::GetInstance().m_strGameID.c_str()); + SConfig::GetInstance().GetGameID().c_str()); PipelineStateCacheInserter inserter; s_pso_disk_cache.OpenAndRead(cache_filename, inserter); diff --git a/Source/Core/VideoBackends/D3D12/ShaderCache.cpp b/Source/Core/VideoBackends/D3D12/ShaderCache.cpp index 5e94040f18..db060a2fb9 100644 --- a/Source/Core/VideoBackends/D3D12/ShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D12/ShaderCache.cpp @@ -77,7 +77,7 @@ void ShaderCache::Init() if (!File::Exists(shader_cache_path)) File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX)); - std::string title_game_id = SConfig::GetInstance().m_strGameID.c_str(); + const std::string& title_game_id = SConfig::GetInstance().GetGameID(); std::string gs_cache_filename = StringFromFormat("%sdx11-%s-gs.cache", shader_cache_path.c_str(), title_game_id.c_str()); diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index cbd5feac21..ef91b01f02 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -437,7 +437,7 @@ void ProgramShaderCache::Init() std::string cache_filename = StringFromFormat("%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), - SConfig::GetInstance().m_strGameID.c_str()); + SConfig::GetInstance().GetGameID().c_str()); ProgramShaderCacheInserter inserter; g_program_disk_cache.OpenAndRead(cache_filename, inserter); diff --git a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp index 94d9178aa9..9c903b0065 100644 --- a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp +++ b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp @@ -327,7 +327,7 @@ std::pair ObjectCache::GetPipelineWithCacheResult(const Pipeli std::string ObjectCache::GetDiskCacheFileName(const char* type) { return StringFromFormat("%svulkan-%s-%s.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), - SConfig::GetInstance().m_strGameID.c_str(), type); + SConfig::GetInstance().GetGameID().c_str(), type); } class PipelineCacheReadCallback : public LinearDiskCacheReader diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index e18931db9c..f503932681 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -87,7 +87,7 @@ void HiresTexture::Update() s_textureCache.clear(); } - const std::string& game_id = SConfig::GetInstance().m_strGameID; + const std::string& game_id = SConfig::GetInstance().GetGameID(); const std::string texture_directory = GetTextureDirectory(game_id); std::vector extensions{ ".png", ".bmp", ".tga", ".dds", @@ -226,7 +226,7 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size, g_ActiveConfig.iSafeTextureCache_ColorSamples) : 0; - name = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_strGameID.c_str(), + name = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().GetGameID().c_str(), (u32)(tex_hash ^ tlut_hash), (u16)format); if (s_textureMap.find(name) != s_textureMap.end()) { diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 0ad86e82c5..b1dbee5407 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -437,7 +437,7 @@ TextureCacheBase::DoPartialTextureUpdates(TCacheEntryBase* entry_to_update, u8* void TextureCacheBase::DumpTexture(TCacheEntryBase* entry, std::string basename, unsigned int level) { - std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().m_strGameID; + std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().GetGameID(); // make sure that the directory exists if (!File::Exists(szDir) || !File::IsDirectory(szDir)) From e04245a10ef8fd93097c2e38072c00137d56313f Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 9 Mar 2017 18:07:20 +0100 Subject: [PATCH 2/3] ConfigManager: Hack for getting the right revision on ES_Launch --- Source/Core/Core/ConfigManager.cpp | 35 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 7c30c41c1f..93f5ffa438 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -24,6 +24,8 @@ #include "Core/Core.h" #include "Core/FifoPlayer/FifoDataFile.h" #include "Core/HLE/HLE.h" +#include "Core/HW/DVDInterface.h" +#include "Core/HW/DVDThread.h" #include "Core/HW/SI/SI.h" #include "Core/IOS/ES/Formats.h" #include "Core/IOS/USB/Bluetooth/BTBase.h" @@ -745,26 +747,27 @@ void SConfig::SetRunningGameMetadata(const DiscIO::IVolume& volume) void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd) { - const u64 title_id = tmd.GetTitleId(); - std::string game_id; + const u64 tmd_title_id = tmd.GetTitleId(); - if (IOS::ES::IsDiscTitle(title_id)) + // If we're launching a disc game, we want to read the revision from + // the disc header instead of the TMD. They can differ. + // (IOS HLE ES calls us with a TMDReader rather than a volume when launching + // a disc game, because ES has no reason to be accessing the disc directly.) + if (DVDInterface::VolumeIsValid()) { - const u32 title_identifier = Common::swap32(static_cast(title_id)); - const u16 group_id = Common::swap16(tmd.GetGroupId()); - - char ascii_game_id[6]; - std::memcpy(ascii_game_id, &title_identifier, sizeof(title_identifier)); - std::memcpy(ascii_game_id + sizeof(title_identifier), &group_id, sizeof(group_id)); - - game_id = ascii_game_id; - } - else - { - game_id = StringFromFormat("%016" PRIX64, title_id); + DVDThread::WaitUntilIdle(); + const DiscIO::IVolume& volume = DVDInterface::GetVolume(); + u64 volume_title_id; + if (volume.GetTitleID(&volume_title_id) && volume_title_id == tmd_title_id) + { + SetRunningGameMetadata(volume.GetGameID(), volume_title_id, volume.GetRevision()); + return; + } } - SetRunningGameMetadata(game_id, title_id, tmd.GetTitleVersion()); + // If not launching a disc game, just read everything from the TMD. + SetRunningGameMetadata(StringFromFormat("%016" PRIX64, tmd_title_id), tmd_title_id, + tmd.GetTitleVersion()); } void SConfig::SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision) From ab616145c2d90e5397c89b006775b533c8e845b7 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 9 Mar 2017 18:47:40 +0100 Subject: [PATCH 3/3] Get the right game ID for SSBB's Masterpiece partitions --- Source/Core/DiscIO/VolumeWiiCrypted.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index ad9cd917d5..541331bcc7 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -161,7 +161,7 @@ std::string CVolumeWiiCrypted::GetGameID() const char ID[6]; - if (!Read(0, 6, (u8*)ID, false)) + if (!Read(0, 6, (u8*)ID, true)) return std::string(); return DecodeString(ID); @@ -179,7 +179,7 @@ Region CVolumeWiiCrypted::GetRegion() const Country CVolumeWiiCrypted::GetCountry() const { u8 country_byte; - if (!m_pReader->Read(3, 1, &country_byte)) + if (!ReadSwapped(3, &country_byte, true)) return Country::COUNTRY_UNKNOWN; const Region region = GetRegion(); @@ -209,7 +209,7 @@ std::string CVolumeWiiCrypted::GetMakerID() const char makerID[2]; - if (!Read(0x4, 0x2, (u8*)&makerID, false)) + if (!Read(0x4, 0x2, (u8*)&makerID, true)) return std::string(); return DecodeString(makerID); @@ -221,7 +221,7 @@ u16 CVolumeWiiCrypted::GetRevision() const return 0; u8 revision; - if (!m_pReader->Read(7, 1, &revision)) + if (!ReadSwapped(7, &revision, true)) return 0; return revision; @@ -230,7 +230,7 @@ u16 CVolumeWiiCrypted::GetRevision() const std::string CVolumeWiiCrypted::GetInternalName() const { char name_buffer[0x60]; - if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name_buffer, false)) + if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name_buffer, true)) return DecodeString(name_buffer); return ""; @@ -291,7 +291,7 @@ Platform CVolumeWiiCrypted::GetVolumeType() const u8 CVolumeWiiCrypted::GetDiscNumber() const { u8 disc_number; - m_pReader->Read(6, 1, &disc_number); + ReadSwapped(6, &disc_number, true); return disc_number; }