From c191fe5348481aac0bce5fac6d6ca292ff76919c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 26 Feb 2017 19:23:12 +0100 Subject: [PATCH] IOS/ES: Update running game info on title change This allows Dolphin to stay up-to-date about what title is currently running, which fixes savestates, screenshots, etc. after an ES_Launch. Same limitation as with MIOS: currently, GameINIs are not reloaded, because it's a pain with the current config system. It'll happen when the new config system is done, and this commit makes it much easier to do! --- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 3 -- Source/Core/Core/IOS/ES/ES.cpp | 58 +++++++++++++++++++++++---- Source/Core/Core/IOS/ES/Formats.cpp | 5 +++ Source/Core/Core/IOS/ES/Formats.h | 1 + 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index 26b44593ad..fa60ba4ab4 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -406,9 +406,6 @@ bool CBoot::EmulatedBS2_Wii() DEBUG_LOG(BOOT, "Run iAppLoaderClose"); RunFunction(iAppLoaderClose); - // Load patches and run startup patches - PatchEngine::LoadPatches(); - IOS::HLE::ES_DIVerify(tmd, DVDInterface::GetVolume().GetTicket()); // return diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index abd458cc22..28a46422de 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -20,17 +20,22 @@ #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" #include "Common/NandPaths.h" +#include "Core/Boot/Boot.h" #include "Core/Boot/Boot_DOL.h" #include "Core/ConfigManager.h" +#include "Core/HLE/HLE.h" #include "Core/HW/DVDInterface.h" #include "Core/HW/Memmap.h" #include "Core/IOS/ES/ES.h" #include "Core/IOS/ES/Formats.h" +#include "Core/PatchEngine.h" +#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PowerPC.h" #include "Core/WiiRoot.h" #include "Core/ec_wii.h" #include "DiscIO/NANDContentLoader.h" #include "DiscIO/Volume.h" +#include "VideoCommon/HiresTextures.h" namespace IOS { @@ -44,10 +49,12 @@ 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; bool active = false; + bool first_change = true; }; // Shared across all ES instances. @@ -138,6 +145,46 @@ void TitleContext::Update(const IOS::ES::TMDReader& tmd_, const IOS::ES::TicketR ticket = ticket_; tmd = tmd_; active = true; + + // Interesting title changes (channel or disc game launch) always happen after an IOS reload. + if (first_change) + { + UpdateRunningGame(); + first_change = false; + } +} + +void TitleContext::UpdateRunningGame() const +{ + // This one does not always make sense for Wii titles, so let's reset it back to a sane value. + SConfig::GetInstance().m_strName = ""; + if (IOS::ES::IsTitleType(tmd.GetTitleId(), IOS::ES::TitleType::Game) || + IOS::ES::IsTitleType(tmd.GetTitleId(), IOS::ES::TitleType::GameWithChannel)) + { + 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(); } void ES::LoadWAD(const std::string& _rContentFile) @@ -1425,13 +1472,10 @@ IPCCommandResult ES::GetOwnedTitleCount(const IOCtlVRequest& request) const DiscIO::CNANDContentLoader& ES::AccessContentDevice(u64 title_id) { - // for WADs, the passed title id and the stored title id match; along with s_content_file being - // set - // to the - // actual WAD file name. We cannot simply get a NAND Loader for the title id in those cases, since - // the WAD - // need not be installed in the NAND, but it could be opened directly from a WAD file anywhere on - // disk. + // for WADs, the passed title id and the stored title id match; along with s_content_file + // being set to the actual WAD file name. We cannot simply get a NAND Loader for the title id + // in those cases, since the WAD need not be installed in the NAND, but it could be opened + // directly from a WAD file anywhere on disk. if (s_title_context.active && s_title_context.tmd.GetTitleId() == title_id && !s_content_file.empty()) { diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 9efc47c846..96a81004e5 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -126,6 +126,11 @@ u16 TMDReader::GetTitleVersion() const return Common::swap16(m_bytes.data() + offsetof(TMDHeader, title_version)); } +u16 TMDReader::GetGroupId() const +{ + return Common::swap16(m_bytes.data() + offsetof(TMDHeader, group_id)); +} + u16 TMDReader::GetNumContents() const { return Common::swap16(m_bytes.data() + offsetof(TMDHeader, num_contents)); diff --git a/Source/Core/Core/IOS/ES/Formats.h b/Source/Core/Core/IOS/ES/Formats.h index 1dea544cc8..de31b78d0b 100644 --- a/Source/Core/Core/IOS/ES/Formats.h +++ b/Source/Core/Core/IOS/ES/Formats.h @@ -137,6 +137,7 @@ public: DiscIO::Region GetRegion() const; u64 GetTitleId() const; u16 GetTitleVersion() const; + u16 GetGroupId() const; u16 GetNumContents() const; bool GetContent(u16 index, Content* content) const;