From af5d9f693a0bd0408a33b8212dd835000f6f3f4c Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 6 Jun 2018 14:30:53 +0200 Subject: [PATCH] Set 0x0000002C to NDEV 2.1 when running a debug-signed Wii disc This fixes the The Last Story prototype that GerbilSoft was testing, because the apploader is a bit more lenient with the max size of DOL sections when it detects that you're using a devkit console. --- Source/Core/Core/Boot/Boot.cpp | 3 ++- Source/Core/Core/Boot/Boot.h | 3 ++- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 13 ++++++++----- Source/Core/Core/Boot/Boot_WiiWAD.cpp | 14 +++++++++++--- Source/Core/Core/IOS/ES/Formats.cpp | 11 +++++++---- Source/Core/Core/IOS/ES/Formats.h | 3 +++ 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index a30b5c3100..84f1ced546 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -43,6 +43,7 @@ #include "Core/IOS/ES/ES.h" #include "Core/IOS/FS/FileSystem.h" #include "Core/IOS/IOS.h" +#include "Core/IOS/IOSC.h" #include "Core/IOS/Uids.h" #include "Core/PatchEngine.h" #include "Core/PowerPC/PPCAnalyst.h" @@ -370,7 +371,7 @@ bool CBoot::BootUp(std::unique_ptr boot) // Because there is no TMD to get the requested system (IOS) version from, // we default to IOS58, which is the version used by the Homebrew Channel. - SetupWiiMemory(); + SetupWiiMemory(IOS::HLE::IOSC::ConsoleType::Retail); IOS::HLE::GetIOS()->BootIOS(Titles::IOS(58)); } else diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index 24e1c7ffd1..589b9b2056 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -13,6 +13,7 @@ #include #include "Common/CommonTypes.h" +#include "Core/IOS/IOSC.h" #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" #include "DiscIO/Volume.h" @@ -116,7 +117,7 @@ private: static bool Load_BS2(const std::string& boot_rom_filename); static void SetupGCMemory(); - static bool SetupWiiMemory(); + static bool SetupWiiMemory(IOS::HLE::IOSC::ConsoleType console_type); }; class BootExecutableReader diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index aa61807fa7..395d9b9930 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -25,6 +25,7 @@ #include "Core/IOS/ES/Formats.h" #include "Core/IOS/FS/FileSystem.h" #include "Core/IOS/IOS.h" +#include "Core/IOS/IOSC.h" #include "Core/IOS/Uids.h" #include "Core/PowerPC/MMU.h" #include "Core/PowerPC/PowerPC.h" @@ -214,7 +215,7 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::Volume& volume) return RunApploader(/*is_wii*/ false, volume); } -bool CBoot::SetupWiiMemory() +bool CBoot::SetupWiiMemory(IOS::HLE::IOSC::ConsoleType console_type) { static const std::map region_settings = { {DiscIO::Region::NTSC_J, {"JPN", "NTSC", "JP", "LJ"}}, @@ -294,9 +295,10 @@ bool CBoot::SetupWiiMemory() Memory::Write_U32(0x0D15EA5E, 0x00000020); // Another magic word Memory::Write_U32(0x00000001, 0x00000024); // Unknown Memory::Write_U32(Memory::REALRAM_SIZE, 0x00000028); // MEM1 size 24MB - Memory::Write_U32(0x00000023, 0x0000002c); // Production Board Model - Memory::Write_U32(0x00000000, 0x00000030); // Init - Memory::Write_U32(0x817FEC60, 0x00000034); // Init + u32 board_model = console_type == IOS::HLE::IOSC::ConsoleType::RVT ? 0x10000021 : 0x00000023; + Memory::Write_U32(board_model, 0x0000002c); // Board Model + Memory::Write_U32(0x00000000, 0x00000030); // Init + Memory::Write_U32(0x817FEC60, 0x00000034); // Init // 38, 3C should get start, size of FST through apploader Memory::Write_U32(0x8008f7b8, 0x000000e4); // Thread Init Memory::Write_U32(Memory::REALRAM_SIZE, 0x000000f0); // "Simulated memory size" (debug mode?) @@ -381,7 +383,8 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume& volume) Memory::Write_U32(0, 0x3194); Memory::Write_U32(static_cast(data_partition.offset >> 2), 0x3198); - if (!SetupWiiMemory() || !IOS::HLE::GetIOS()->BootIOS(tmd.GetIOSId())) + const auto console_type = volume.GetTicket(data_partition).GetConsoleType(); + if (!SetupWiiMemory(console_type) || !IOS::HLE::GetIOS()->BootIOS(tmd.GetIOSId())) return false; DVDRead(volume, 0x00000000, 0x00000000, 0x20, DiscIO::PARTITION_NONE); // Game Code diff --git a/Source/Core/Core/Boot/Boot_WiiWAD.cpp b/Source/Core/Core/Boot/Boot_WiiWAD.cpp index c34ce98209..8c0fed08dd 100644 --- a/Source/Core/Core/Boot/Boot_WiiWAD.cpp +++ b/Source/Core/Core/Boot/Boot_WiiWAD.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/CommonTypes.h" @@ -12,6 +13,7 @@ #include "Core/IOS/ES/ES.h" #include "Core/IOS/ES/Formats.h" #include "Core/IOS/IOS.h" +#include "Core/IOS/IOSC.h" #include "Core/WiiUtils.h" #include "DiscIO/WiiWad.h" @@ -21,9 +23,15 @@ bool CBoot::BootNANDTitle(const u64 title_id) state->type = 0x04; // TYPE_NANDBOOT }); - auto* ios = IOS::HLE::GetIOS(); - SetupWiiMemory(); - return ios->GetES()->LaunchTitle(title_id); + auto es = IOS::HLE::GetIOS()->GetES(); + const IOS::ES::TicketReader ticket = es->FindSignedTicket(title_id); + auto console_type = IOS::HLE::IOSC::ConsoleType::Retail; + if (ticket.IsValid()) + console_type = ticket.GetConsoleType(); + else + ERROR_LOG(BOOT, "No ticket was found for %016" PRIx64, title_id); + SetupWiiMemory(console_type); + return es->LaunchTitle(title_id); } bool CBoot::Boot_WiiWAD(const DiscIO::WiiWAD& wad) diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 9c4ad4f0cb..b2990f0d40 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -443,10 +443,13 @@ std::array TicketReader::GetTitleKey(const HLE::IOSC& iosc) const std::array TicketReader::GetTitleKey() const { - const bool is_rvt = (GetIssuer() == "Root-CA00000002-XS00000006"); - const HLE::IOSC::ConsoleType console_type = - is_rvt ? HLE::IOSC::ConsoleType::RVT : HLE::IOSC::ConsoleType::Retail; - return GetTitleKey(HLE::IOSC{console_type}); + return GetTitleKey(HLE::IOSC{GetConsoleType()}); +} + +HLE::IOSC::ConsoleType TicketReader::GetConsoleType() const +{ + const bool is_rvt = GetIssuer() == "Root-CA00000002-XS00000006"; + return is_rvt ? HLE::IOSC::ConsoleType::RVT : HLE::IOSC::ConsoleType::Retail; } void TicketReader::DeleteTicket(u64 ticket_id_to_delete) diff --git a/Source/Core/Core/IOS/ES/Formats.h b/Source/Core/Core/IOS/ES/Formats.h index 6afbf3407a..4a13d425cf 100644 --- a/Source/Core/Core/IOS/ES/Formats.h +++ b/Source/Core/Core/IOS/ES/Formats.h @@ -242,6 +242,9 @@ public: // and constructs a temporary IOSC instance. std::array GetTitleKey() const; + // Infers the console type (retail or devkit) based on the certificate issuer. + HLE::IOSC::ConsoleType GetConsoleType() const; + // Deletes a ticket with the given ticket ID from the internal buffer. void DeleteTicket(u64 ticket_id);