From fe8a23e0d9d5c214e470e9bf1b76aa4cf19fc2d8 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:32:37 +0300 Subject: [PATCH] Add CFG::GetConfigInfoBlk8 implementation --- include/services/cfg.hpp | 3 ++ src/core/services/cfg.cpp | 83 +++++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/include/services/cfg.hpp b/include/services/cfg.hpp index 3ab0426a..28327574 100644 --- a/include/services/cfg.hpp +++ b/include/services/cfg.hpp @@ -15,6 +15,7 @@ class CFGService { // Service functions void getConfigInfoBlk2(u32 messagePointer); + void getConfigInfoBlk8(u32 messagePointer); void getCountryCodeID(u32 messagePointer); void getLocalFriendCodeSeed(u32 messagePointer); void getRegionCanadaUSA(u32 messagePointer); @@ -23,6 +24,8 @@ class CFGService { void secureInfoGetByte101(u32 messagePointer); void secureInfoGetRegion(u32 messagePointer); + void getConfigInfo(u32 output, u32 blockID, u32 size, u32 permissionMask); + public: enum class Type { U, // cfg:u diff --git a/src/core/services/cfg.cpp b/src/core/services/cfg.cpp index 23c6e262..5a916ef0 100644 --- a/src/core/services/cfg.cpp +++ b/src/core/services/cfg.cpp @@ -11,6 +11,7 @@ namespace CFGCommands { enum : u32 { GetConfigInfoBlk2 = 0x00010082, + GetConfigInfoBlk8 = 0x04010082, SecureInfoGetRegion = 0x00020000, GenHashConsoleUnique = 0x00030040, GetRegionCanadaUSA = 0x00040000, @@ -61,77 +62,91 @@ void CFGService::getConfigInfoBlk2(u32 messagePointer) { u32 output = mem.read32(messagePointer + 16); // Pointer to write the output data to log("CFG::GetConfigInfoBlk2 (size = %X, block ID = %X, output pointer = %08X\n", size, blockID, output); + + getConfigInfo(output, blockID, size, 0x2); + mem.write32(messagePointer, IPC::responseHeader(0x1, 1, 2)); + mem.write32(messagePointer + 4, Result::Success); +} + +void CFGService::getConfigInfoBlk8(u32 messagePointer) { + u32 size = mem.read32(messagePointer + 4); + u32 blockID = mem.read32(messagePointer + 8); + u32 output = mem.read32(messagePointer + 16); // Pointer to write the output data to + log("CFG::GetConfigInfoBlk8 (size = %X, block ID = %X, output pointer = %08X\n", size, blockID, output); + + getConfigInfo(output, blockID, size, 0x8); + mem.write32(messagePointer, IPC::responseHeader(0x401, 1, 2)); + mem.write32(messagePointer + 4, Result::Success); +} + +void CFGService::getConfigInfo(u32 output, u32 blockID, u32 size, u32 permissionMask) { // TODO: Make this not bad - if (size == 1 && blockID == 0x70001) { // Sound output mode + if (size == 1 && blockID == 0x70001) { // Sound output mode mem.write8(output, static_cast(DSPService::SoundOutputMode::Stereo)); - } else if (size == 1 && blockID == 0xA0002){ // System language + } else if (size == 1 && blockID == 0xA0002) { // System language mem.write8(output, static_cast(LanguageCodes::English)); - } else if (size == 4 && blockID == 0xB0000) { // Country info - mem.write8(output, 0); // Unknown - mem.write8(output + 1, 0); // Unknown - mem.write8(output + 2, 2); // Province (Temporarily stubbed to Washington DC like Citra) - mem.write8(output + 3, static_cast(country)); // Country code + } else if (size == 4 && blockID == 0xB0000) { // Country info + mem.write8(output, 0); // Unknown + mem.write8(output + 1, 0); // Unknown + mem.write8(output + 2, 2); // Province (Temporarily stubbed to Washington DC like Citra) + mem.write8(output + 3, static_cast(country)); // Country code } else if (size == 0x20 && blockID == 0x50005) { // "Stereo Camera settings" // Implementing this properly fixes NaN uniforms in some games. Values taken from 3dmoo & Citra static constexpr std::array STEREO_CAMERA_SETTINGS = { - 62.0f, 289.0f, 76.80000305175781f, 46.08000183105469f, - 10.0f, 5.0f, 55.58000183105469f, 21.56999969482422f + 62.0f, 289.0f, 76.80000305175781f, 46.08000183105469f, 10.0f, 5.0f, 55.58000183105469f, 21.56999969482422f, }; for (int i = 0; i < 8; i++) { mem.write32(output + i * 4, Helpers::bit_cast(STEREO_CAMERA_SETTINGS[i])); } - } else if (size == 0x1C && blockID == 0xA0000) { // Username + } else if (size == 0x1C && blockID == 0xA0000) { // Username writeStringU16(output, u"Pander"); - } else if (size == 0xC0 && blockID == 0xC0000) { // Parental restrictions info - for (int i = 0; i < 0xC0; i++) - mem.write8(output + i, 0); - } else if (size == 4 && blockID == 0xD0000) { // Agreed EULA version (first 2 bytes) and latest EULA version (next 2 bytes) + } else if (size == 0xC0 && blockID == 0xC0000) { // Parental restrictions info + for (int i = 0; i < 0xC0; i++) mem.write8(output + i, 0); + } else if (size == 4 && blockID == 0xD0000) { // Agreed EULA version (first 2 bytes) and latest EULA version (next 2 bytes) log("Read EULA info\n"); - mem.write16(output, 0x0202); // Agreed EULA version = 2.2 (Random number. TODO: Check) - mem.write16(output + 2, 0x0202); // Latest EULA version = 2.2 - } else if (size == 0x800 && blockID == 0xB0001) { // UTF-16 name for our country in every language at 0x80 byte intervals + mem.write16(output, 0x0202); // Agreed EULA version = 2.2 (Random number. TODO: Check) + mem.write16(output + 2, 0x0202); // Latest EULA version = 2.2 + } else if (size == 0x800 && blockID == 0xB0001) { // UTF-16 name for our country in every language at 0x80 byte intervals constexpr size_t languageCount = 16; - constexpr size_t nameSize = 0x80; // Max size of each name in bytes - std::u16string name = u"PandaLand (Home of PandaSemi LLC) (aka Pandistan)"; // Note: This + the null terminator needs to fit in 0x80 bytes + constexpr size_t nameSize = 0x80; // Max size of each name in bytes + std::u16string name = u"PandaLand (Home of PandaSemi LLC) (aka Pandistan)"; // Note: This + the null terminator needs to fit in 0x80 bytes for (int i = 0; i < languageCount; i++) { u32 pointer = output + i * nameSize; writeStringU16(pointer, name); } - } else if (size == 0x800 && blockID == 0xB0002) { // UTF-16 name for our state in every language at 0x80 byte intervals + } else if (size == 0x800 && blockID == 0xB0002) { // UTF-16 name for our state in every language at 0x80 byte intervals constexpr size_t languageCount = 16; - constexpr size_t nameSize = 0x80; // Max size of each name in bytes - std::u16string name = u"Pandington"; // Note: This + the null terminator needs to fit in 0x80 bytes + constexpr size_t nameSize = 0x80; // Max size of each name in bytes + std::u16string name = u"Pandington"; // Note: This + the null terminator needs to fit in 0x80 bytes for (int i = 0; i < languageCount; i++) { u32 pointer = output + i * nameSize; writeStringU16(pointer, name); } - } else if (size == 4 && blockID == 0xB0003) { // Coordinates (latidude and longtitude) as s16 - mem.write16(output, 0); // Latitude - mem.write16(output + 2, 0); // Longtitude - } else if (size == 2 && blockID == 0xA0001) { // Birthday - mem.write8(output, 5); // Month (May) - mem.write8(output + 1, 5); // Day (Fifth) - } else if (size == 8 && blockID == 0x30001) { // User time offset + } else if (size == 4 && blockID == 0xB0003) { // Coordinates (latidude and longtitude) as s16 + mem.write16(output, 0); // Latitude + mem.write16(output + 2, 0); // Longtitude + } else if (size == 2 && blockID == 0xA0001) { // Birthday + mem.write8(output, 5); // Month (May) + mem.write8(output + 1, 5); // Day (Fifth) + } else if (size == 8 && blockID == 0x30001) { // User time offset printf("Read from user time offset field in NAND. TODO: What is this\n"); mem.write64(output, 0); - } else if (size == 20 && blockID == 0xC0001) { // COPPACS restriction data, used by games when they detect a USA/Canada region for market restriction stuff + } else if (size == 20 && blockID == 0xC0001) { // COPPACS restriction data, used by games when they detect a USA/Canada region for market + // restriction stuff for (u32 i = 0; i < size; i += 4) { mem.write32(output + i, 0); } } else if (size == 4 && blockID == 0x170000) { // Miiverse access key mem.write32(output, 0); } else if (size == 8 && blockID == 0x00090000) { - mem.write64(output, 0); // Some sort of key used with nwm::UDS::InitializeWithVersion + mem.write64(output, 0); // Some sort of key used with nwm::UDS::InitializeWithVersion } else { Helpers::panic("Unhandled GetConfigInfoBlk2 configuration. Size = %d, block = %X", size, blockID); } - - mem.write32(messagePointer, IPC::responseHeader(0x1, 1, 2)); - mem.write32(messagePointer + 4, Result::Success); } void CFGService::secureInfoGetRegion(u32 messagePointer) {