From 30bbea3f4e13fa6d4c38e67f6d9d6c626cad149b Mon Sep 17 00:00:00 2001 From: NarcolepticK Date: Sun, 12 Aug 2018 03:26:45 -0400 Subject: [PATCH] service/cecd: Add initial files to archive after it is formatted --- src/core/hle/service/cecd/cecd.cpp | 65 +++++++++++++++++++++++++++++- src/core/hle/service/cecd/cecd.h | 1 - 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/cecd/cecd.cpp b/src/core/hle/service/cecd/cecd.cpp index eb4aaca66..5d4dd8f8b 100644 --- a/src/core/hle/service/cecd/cecd.cpp +++ b/src/core/hle/service/cecd/cecd.cpp @@ -298,7 +298,7 @@ void Module::Interface::GetSystemInfo(Kernel::HLERequestContext& ctx) { dest_buffer.Write(buffer.data(), 0, buffer.size()); break; default: - LOG_ERROR(Service_CECD, "Unknown system info type {}", static_cast(info_type)); + LOG_ERROR(Service_CECD, "Unknown system info type={}", static_cast(info_type)); } rb.Push(RESULT_SUCCESS); @@ -454,10 +454,18 @@ void Module::Interface::OpenAndRead(Kernel::HLERequestContext& ctx) { LOG_ERROR(Service_CECD, "Failed to open file: {}", path.AsString()); if (path_type == CecDataPathType::CEC_PATH_MBOX_INFO) { + const FileSys::Path root_dir_path( + cecd->GetCecDataPathTypeAsString(CecDataPathType::CEC_PATH_ROOT_DIR, + ncch_program_id) + .data()); const FileSys::Path mbox_path( cecd->GetCecDataPathTypeAsString(CecDataPathType::CEC_PATH_MBOX_DIR, ncch_program_id) .data()); + + /// Just in case the root dir /CEC doesn't exist, we try to create it first + Service::FS::CreateDirectoryFromArchive(cecd->cecd_system_save_data_archive, + root_dir_path); Service::FS::CreateDirectoryFromArchive(cecd->cecd_system_save_data_archive, mbox_path); } @@ -565,6 +573,61 @@ Module::Module() { // Open it again to get a valid archive now that the folder exists archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); + + /// Now that the archive is formatted, we need to create the root CEC directory, + /// eventlog.dat, and CEC/MBoxList____ + const FileSys::Path root_dir_path( + GetCecDataPathTypeAsString(CecDataPathType::CEC_PATH_ROOT_DIR, 0).data()); + Service::FS::CreateDirectoryFromArchive(*archive_result, root_dir_path); + + FileSys::Mode mode; + mode.write_flag.Assign(1); + mode.create_flag.Assign(1); + + /// eventlog.dat resides in the root of the archive beside the CEC directory + /// Initially created, at offset 0x0, are bytes 0x01 0x41 0x12, followed by + /// zeroes until offset 0x1000, where it changes to 0xDD until the end of file + /// at offset 0x30d53 + FileSys::Path eventlog_path("/eventlog.dat"); + + auto eventlog_result = + Service::FS::OpenFileFromArchive(*archive_result, eventlog_path, mode); + + constexpr u32 eventlog_size = 0x30d54; + auto eventlog = eventlog_result.Unwrap(); + std::vector eventlog_buffer(eventlog_size); + + std::memset(&eventlog_buffer[0], 0, 0x1000); + eventlog_buffer[0] = 0x01; + eventlog_buffer[1] = 0x41; + eventlog_buffer[2] = 0x12; + std::memset(&eventlog_buffer[0x1000], 0xDD, eventlog_size - 0x1000); + + eventlog->backend->Write(0, eventlog_size, true, eventlog_buffer.data()).Unwrap(); + eventlog->backend->Close(); + + /// MBoxList____ resides within the root CEC/ directory. + /// Initially created, at offset 0x0, are bytes 0x68 0x68 0x00 0x00 0x01, with 0x6868 'hh', + /// being the magic number. The rest of the file is filled with zeroes, until the end of + /// file at offset 0x18b + FileSys::Path mboxlist_path( + GetCecDataPathTypeAsString(CecDataPathType::CEC_PATH_MBOX_LIST, 0).data()); + + auto mboxlist_result = + Service::FS::OpenFileFromArchive(*archive_result, mboxlist_path, mode); + + constexpr u32 mboxlist_size = 0x18c; + auto mboxlist = mboxlist_result.Unwrap(); + std::vector mboxlist_buffer(mboxlist_size); + + std::memset(&mboxlist_buffer[0], 0, mboxlist_size); + mboxlist_buffer[0] = 0x68; + mboxlist_buffer[1] = 0x68; + /// mboxlist_buffer[2-3] are already zeroed + mboxlist_buffer[4] = 0x01; + + mboxlist->backend->Write(0, mboxlist_size, true, mboxlist_buffer.data()).Unwrap(); + mboxlist->backend->Close(); } ASSERT_MSG(archive_result.Succeeded(), "Could not open the CECD SystemSaveData archive!"); diff --git a/src/core/hle/service/cecd/cecd.h b/src/core/hle/service/cecd/cecd.h index 95c977da6..37e6df0d1 100644 --- a/src/core/hle/service/cecd/cecd.h +++ b/src/core/hle/service/cecd/cecd.h @@ -46,7 +46,6 @@ public: * CecDataPathType possible missing values; need to figure out placement * * data:/CEC/TMP - * utBox__ * data:/CEC/test */ enum class CecDataPathType : u32 {