From f4da2de99a920d7a44c6571cb13196d5b7069af3 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 23 Apr 2019 23:18:27 +0200 Subject: [PATCH] Set accepted EULA version to max value (#4728) * Set accepted EULA version to max value CFG: write the max value of 0x7F7F to the default cfg savegame and auto update on init CECD: Actually read the EULA version from CFG --- src/core/hle/service/cecd/cecd.cpp | 9 ++++++--- src/core/hle/service/cfg/cfg.cpp | 27 ++++++++++++++++++++++++++- src/core/hle/service/cfg/cfg.h | 17 +++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/core/hle/service/cecd/cecd.cpp b/src/core/hle/service/cecd/cecd.cpp index 85f3e50ce..281f48026 100644 --- a/src/core/hle/service/cecd/cecd.cpp +++ b/src/core/hle/service/cecd/cecd.cpp @@ -21,6 +21,7 @@ #include "core/hle/service/cecd/cecd_ndm.h" #include "core/hle/service/cecd/cecd_s.h" #include "core/hle/service/cecd/cecd_u.h" +#include "core/hle/service/cfg/cfg.h" #include "fmt/format.h" namespace Service::CECD { @@ -612,10 +613,12 @@ void Module::Interface::ReadData(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); std::vector buffer; switch (info_type) { - case CecSystemInfoType::EulaVersion: // TODO: Read config Eula version - buffer = {0xFF, 0xFF}; - dest_buffer.Write(buffer.data(), 0, buffer.size()); + case CecSystemInfoType::EulaVersion: { + auto cfg = Service::CFG::GetModule(cecd->system); + Service::CFG::EULAVersion version = cfg->GetEULAVersion(); + dest_buffer.Write(&version, 0, sizeof(version)); break; + } case CecSystemInfoType::Eula: buffer = {0x01}; // Eula agreed dest_buffer.Write(buffer.data(), 0, buffer.size()); diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index dba000257..df6fd2e76 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -89,6 +89,7 @@ struct ConsoleCountryInfo { static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes"); } // namespace +static const EULAVersion MAX_EULA_VERSION = {0x7F, 0x7F}; static const ConsoleModelInfo CONSOLE_MODEL = {NINTENDO_3DS_XL, {0, 0, 0}}; static const u8 CONSOLE_LANGUAGE = LANGUAGE_EN; static const UsernameBlock CONSOLE_USERNAME_BLOCK = {u"CITRA", 0, 0}; @@ -505,7 +506,8 @@ ResultCode Module::FormatConfig() { return res; // 0x000D0000 - Accepted EULA version - res = CreateConfigInfoBlk(EULAVersionBlockID, 0x4, 0xE, zero_buffer); + u32_le data = MAX_EULA_VERSION.minor + (MAX_EULA_VERSION.major << 8); + res = CreateConfigInfoBlk(EULAVersionBlockID, sizeof(data), 0xE, &data); if (!res.IsSuccess()) return res; @@ -564,6 +566,15 @@ ResultCode Module::LoadConfigNANDSaveFile() { Module::Module() { LoadConfigNANDSaveFile(); + // Check the config savegame EULA Version and update it to 0x7F7F if necessary + // so users will never get a promt to accept EULA + EULAVersion version = GetEULAVersion(); + if (version.major != MAX_EULA_VERSION.major || version.minor != MAX_EULA_VERSION.minor) { + LOG_INFO(Service_CFG, "Updating accepted EULA version to {}.{}", MAX_EULA_VERSION.major, + MAX_EULA_VERSION.minor); + SetEULAVersion(Service::CFG::MAX_EULA_VERSION); + UpdateConfigNANDSavegame(); + } } Module::~Module() = default; @@ -718,6 +729,20 @@ u64 Module::GetConsoleUniqueId() { return console_id_le; } +EULAVersion Module::GetEULAVersion() { + u32_le data; + GetConfigInfoBlock(EULAVersionBlockID, sizeof(data), 0xE, &data); + EULAVersion version; + version.minor = data & 0xFF; + version.major = (data >> 8) & 0xFF; + return version; +} + +void Module::SetEULAVersion(const EULAVersion& version) { + u32_le data = version.minor + (version.major << 8); + SetConfigInfoBlock(EULAVersionBlockID, sizeof(data), 0xE, &data); +} + std::shared_ptr GetModule(Core::System& system) { auto cfg = system.ServiceManager().GetService("cfg:u"); if (!cfg) diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index af63c6f91..6886d513b 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h @@ -47,6 +47,11 @@ enum SystemLanguage { enum SoundOutputMode { SOUND_MONO = 0, SOUND_STEREO = 1, SOUND_SURROUND = 2 }; +struct EULAVersion { + u8 minor; + u8 major; +}; + /// Block header in the config savedata file struct SaveConfigBlockEntry { u32 block_id; ///< The id of the current block @@ -398,6 +403,18 @@ public: */ u64 GetConsoleUniqueId(); + /** + * Sets the accepted EULA version in the config savegame. + * @param version the version to set + */ + void SetEULAVersion(const EULAVersion& version); + + /** + * Gets the accepted EULA version from config savegame. + * @returns the EULA version + */ + EULAVersion GetEULAVersion(); + /** * Writes the config savegame memory buffer to the config savegame file in the filesystem * @returns ResultCode indicating the result of the operation, 0 on success