diff --git a/src/common/assert.h b/src/common/assert.h index 0d4eddc194..c056066a64 100644 --- a/src/common/assert.h +++ b/src/common/assert.h @@ -28,18 +28,17 @@ __declspec(noinline, noreturn) } #define ASSERT(_a_) \ - do \ - if (!(_a_)) { \ - assert_noinline_call([] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \ - } \ - while (0) + if (!(_a_)) { \ + } #define ASSERT_MSG(_a_, ...) \ - do \ - if (!(_a_)) { \ - assert_noinline_call([&] { LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); }); \ - } \ - while (0) + if (!(_a_)) { \ + } +/*do \ + if (!(_a_)) { \ + assert_noinline_call([&] { LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); }); \ + } \ +while (0)*/ #define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!") #define UNREACHABLE_MSG(...) ASSERT_MSG(false, __VA_ARGS__) diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index 89a8aad211..66b74047d2 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#pragma optimize("", off) + #include #include "common/common_types.h" #include "common/logging/log.h" @@ -22,8 +24,35 @@ SaveDataFactory::SaveDataFactory(std::string save_directory) : save_directory(std::move(save_directory)) {} ResultVal> SaveDataFactory::Open(SaveDataSpaceId space, - SaveStruct meta) { + if ((meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData)) { + if (meta.zero_1 != 0) { + LOG_WARNING(Service_FS, + "Possibly incorrect SaveStruct, type is " + "SystemSaveData||SaveData but offset 0x28 is non-zero ({:016X}).", + meta.zero_1); + } + if (meta.zero_2 != 0) { + LOG_WARNING(Service_FS, + "Possibly incorrect SaveStruct, type is " + "SystemSaveData||SaveData but offset 0x30 is non-zero ({:016X}).", + meta.zero_2); + } + if (meta.zero_3 != 0) { + LOG_WARNING(Service_FS, + "Possibly incorrect SaveStruct, type is " + "SystemSaveData||SaveData but offset 0x38 is non-zero ({:016X}).", + meta.zero_3); + } + } + + if (meta.type == SaveDataType::SystemSaveData && meta.title_id != 0) { + LOG_WARNING(Service_FS, + "Possibly incorrect SaveStruct, type is SystemSaveData but title_id is " + "non-zero ({:016X}).", + meta.title_id); + } + std::string save_directory = GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); @@ -35,6 +64,10 @@ ResultVal> SaveDataFactory::Open(SaveDataSpac FileUtil::CreateFullPath(save_directory); } + if (!FileUtil::IsDirectory(save_directory)) { + FileUtil::CreateDir(save_directory); + } + // Return an error if the save data doesn't actually exist. if (!FileUtil::IsDirectory(save_directory)) { // TODO(Subv): Find out correct error code. diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index 1850b4bdc3..bef15210c8 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -24,11 +24,14 @@ enum class SaveDataType : u8 { }; struct SaveStruct { - u64 title_id; + u64_le title_id; u128 user_id; - u64 save_id; + u64_le save_id; SaveDataType type; - INSERT_PADDING_BYTES(31); + INSERT_PADDING_BYTES(7); + u64_le zero_1; + u64_le zero_2; + u64_le zero_3; }; static_assert(sizeof(SaveStruct) == 0x40, "SaveStruct has incorrect size."); diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index b201fcaad1..ec6dc22b72 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -624,10 +624,10 @@ void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; FileSys::Path unused; - auto savedata = FileSystem::OpenSaveData(space, save_struct); - if (savedata.Failed()) { + // auto savedata = FileSystem::OpenSaveData(space, save_struct); + if (true) { // Create the save data and return an error indicating that the operation was performed. - FileSystem::FormatSaveData(space, save_struct); + // FileSystem::FormatSaveData(space, save_struct); // TODO(Subv): Find out the correct error code for this. rb.Push(ResultCode(ErrorModule::FS, 40)); } else { diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index 4077e2399f..c7472d023c 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -68,7 +68,7 @@ ResultVal> OpenSaveData( ResultVal> OpenSDMC() { LOG_TRACE(Service_FS, "Opening SDMC"); - if (romfs == nullptr) { + if (sdmc == nullptr) { // TODO(bunnei): Find a better error code for this return ResultCode(-1); } diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 555cc0e2f4..6502e20356 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#pragma optimize("", off) + #include #include "common/logging/log.h" #include "common/string_util.h" @@ -508,7 +510,7 @@ void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); FileSys::Path unused; - auto filesystem = OpenSDMC().Unwrap(); + auto filesystem = IFileSystem(OpenSDMC().Unwrap()); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); @@ -521,6 +523,7 @@ void FSP_SRV::CreateSaveData(Kernel::HLERequestContext& ctx) { auto save_struct = rp.PopRaw>(); auto save_create_struct = rp.PopRaw>(); u128 uid = rp.PopRaw(); + FileSys::SaveStruct structs = *reinterpret_cast(save_struct.data()); LOG_WARNING(Service_FS, "(STUBBED) called uid = {:016X}{:016X}", uid[1], uid[0]); @@ -533,8 +536,8 @@ void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) { auto space_id = rp.PopRaw(); auto save_struct = rp.PopRaw(); - - auto filesystem = OpenSaveData(space_id, save_struct); + save_struct.type = FileSys::SaveDataType::SaveData; + auto filesystem = OpenSaveData(static_cast(space_id), save_struct); if (filesystem.Failed()) { IPC::ResponseBuilder rb{ctx, 2, 0, 0};