mirror of
https://github.com/patchzyy/wiicompiled
synced 2026-09-11 01:23:15 -04:00
Treat empty MKW save as missing rather than corrupt (#168)
* treat empty mkw save as missing first-run format zero-fills rksys.dat before any real save; a quit before the first save left an all-zero file that read back as corrupt and trapped the user in a delete/recreate loop. read opens now treat an all-zero rksys.dat as absent (a real save always begins with the RKSD0006 header), so the game recreates it from scratch. also ignore native build output. * shorten * I dont really want to change this to be honest. * extra safety --------- Co-authored-by: patchzyy <64382339+patchzyy@users.noreply.github.com>
This commit is contained in:
@@ -93,6 +93,9 @@ extern "C" int32_t NANDOpen_HLE(uint32_t pathPtr, uint32_t fileInfoPtr, uint32_t
|
||||
|
||||
const std::filesystem::path hostPath = TranslateNandPath(path);
|
||||
|
||||
if (const auto result = NandCheckSystemSaveRead("NANDOpen", hostPath, mode))
|
||||
return *result;
|
||||
|
||||
// Existing-file write opens go through a shadow copy seeded from the original, so a
|
||||
// crash between NANDWrite and NANDClose cannot leave a torn file (the game patches
|
||||
// sub-ranges, e.g. ghost saves at a non-zero offset). New files still create in place.
|
||||
|
||||
@@ -411,6 +411,8 @@ extern "C" int32_t NANDSafeOpen_HLE(uint32_t pathPtr, uint32_t fileInfoPtr, uint
|
||||
if (mode == 1) {
|
||||
// Read-only safe open reads the original in place; the library builds no scratch
|
||||
// copy for this case.
|
||||
if (const auto result = NandCheckSystemSaveRead("NANDSafeOpen", hostPath, mode))
|
||||
return *result;
|
||||
FILE* file = NandFopen(hostPath, "rb");
|
||||
if (!file && IsFaceLibResourcePath(path) && SeedFaceLibResource(hostPath)) {
|
||||
file = NandFopen(hostPath, "rb");
|
||||
|
||||
@@ -411,6 +411,26 @@ bool IsFaceLibResourcePath(const char* path) {
|
||||
return std::strcmp(path, "/shared2/menu/FaceLib/RFL_Res.dat") == 0;
|
||||
}
|
||||
|
||||
std::optional<int32_t> NandCheckSystemSaveRead(const char* who,
|
||||
const std::filesystem::path& hostPath, int mode, bool ios) {
|
||||
const auto action = RuntimeNandSave::CheckRead(hostPath, mode);
|
||||
if (action == RuntimeNandSave::ReadAction::Proceed) return std::nullopt;
|
||||
if (action == RuntimeNandSave::ReadAction::Missing) {
|
||||
LogNandWarning(who, "treating empty or zero-filled system save '%s' as missing",
|
||||
HostPathText(hostPath).c_str());
|
||||
return ios ? ISFS_ENOENT : NAND_RESULT_NOEXISTS;
|
||||
}
|
||||
if (action == RuntimeNandSave::ReadAction::RecoveryNeeded) {
|
||||
LogNandError(who, "system save '%s' is missing or blank but its .nandsafe.tmp contains data; "
|
||||
"back up both files before attempting recovery",
|
||||
HostPathText(hostPath).c_str());
|
||||
} else {
|
||||
LogNandError(who, "could not inspect system save '%s' or its write shadow; leaving data untouched",
|
||||
HostPathText(hostPath).c_str());
|
||||
}
|
||||
return ios ? ISFS_EIO : NAND_RESULT_UNKNOWN;
|
||||
}
|
||||
|
||||
// Create directories recursively
|
||||
bool CreateDirectoryPath(const std::filesystem::path& path) {
|
||||
if (path.empty()) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "hle/runtime_parse_helpers.h"
|
||||
#include "memory.h"
|
||||
#include "nand_path.h"
|
||||
#include "nand_save_probe.h"
|
||||
#include "hle/net/network.h"
|
||||
#include "recomp_mod_loader.h"
|
||||
#include "runtime_config.h"
|
||||
@@ -26,6 +27,7 @@
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
@@ -56,6 +58,11 @@ constexpr uint32_t kNandTitleIdLo = 0x524D4350; // "RMCP" fallback
|
||||
void LogNandError(const char* func, const char* fmt, ...);
|
||||
void LogNandWarning(const char* func, const char* fmt, ...);
|
||||
|
||||
// An empty optional means continue opening normally; otherwise return the
|
||||
// supplied NAND/IOS error without exposing a failed scan as a missing save.
|
||||
std::optional<int32_t> NandCheckSystemSaveRead(const char* who,
|
||||
const std::filesystem::path& hostPath, int mode, bool ios = false);
|
||||
|
||||
// ============================================================================
|
||||
// File Descriptor Management
|
||||
// ============================================================================
|
||||
|
||||
@@ -391,6 +391,9 @@ extern "C" int32_t NAND_IOS_Open_HLE(uint32_t pathPtr, uint32_t mode) {
|
||||
|
||||
// It's a NAND file path
|
||||
const std::filesystem::path hostPath = TranslateNandPath(path);
|
||||
|
||||
if (const auto result = NandCheckSystemSaveRead("IOS_Open", hostPath, mode, true))
|
||||
return *result;
|
||||
|
||||
// Seed FaceLib resources before the existence check so every open mode can
|
||||
// still find them on a fresh managed NAND.
|
||||
|
||||
Reference in New Issue
Block a user