summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/DiscExtractor.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2023-06-12 15:37:02 -0400
committerGitHub <noreply@github.com>2023-06-12 15:37:02 -0400
commitc8559a79332aa81e4060389d82cd8df885147972 (patch)
treeb552b47737cf7285bfda32ec6f6993caaede80e2 /Source/Core/DiscIO/DiscExtractor.cpp
parent635bce2e7bfcf0268c1a223a1b42fa7fd3721a1e (diff)
parentee19ff66b4284c4849a4bec446fb5f9077f6c7d6 (diff)
Merge pull request #11863 from Minty-Meeo/nkit-extract
Remove NKit data when extracting a GCN/Wii disc volume
Diffstat (limited to 'Source/Core/DiscIO/DiscExtractor.cpp')
-rw-r--r--Source/Core/DiscIO/DiscExtractor.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/Source/Core/DiscIO/DiscExtractor.cpp b/Source/Core/DiscIO/DiscExtractor.cpp
index 229e2a59cc..f3754153e9 100644
--- a/Source/Core/DiscIO/DiscExtractor.cpp
+++ b/Source/Core/DiscIO/DiscExtractor.cpp
@@ -4,6 +4,9 @@
#include "DiscIO/DiscExtractor.h"
#include <algorithm>
+#include <array>
+#include <cstddef>
+#include <cstring>
#include <functional>
#include <optional>
#include <string>
@@ -137,8 +140,25 @@ bool ExportWiiUnencryptedHeader(const Volume& volume, const std::string& export_
if (volume.GetVolumeType() != Platform::WiiDisc)
return false;
- return ExportData(volume, PARTITION_NONE, WII_NONPARTITION_DISCHEADER_ADDRESS,
- WII_NONPARTITION_DISCHEADER_SIZE, export_filename);
+ File::IOFile f(export_filename, "wb");
+ if (!f)
+ return false;
+
+ std::array<u8, WII_NONPARTITION_DISCHEADER_SIZE> buffer;
+
+ if (!volume.Read(WII_NONPARTITION_DISCHEADER_ADDRESS, buffer.size(), buffer.data(),
+ PARTITION_NONE))
+ {
+ return false;
+ }
+ // NKitv1 unconditionally sets and unsets some flags when converting between Wii ISO and Wii NKit.
+ // This is because the NKit format decrypts the disc partitions and removes the h3 hash table.
+ // https://wiibrew.org/wiki/Wii_disc#Header
+ if (volume.IsNKit())
+ std::memset(buffer.data() + 0x60, 0, 2);
+ if (!f.WriteBytes(buffer.data(), buffer.size()))
+ return false;
+ return true;
}
bool ExportWiiRegionData(const Volume& volume, const std::string& export_filename)
@@ -212,7 +232,20 @@ bool ExportHeader(const Volume& volume, const Partition& partition,
if (!IsDisc(volume.GetVolumeType()))
return false;
- return ExportData(volume, partition, DISCHEADER_ADDRESS, DISCHEADER_SIZE, export_filename);
+ File::IOFile f(export_filename, "wb");
+ if (!f)
+ return false;
+
+ std::array<u8, DISCHEADER_SIZE> buffer;
+
+ if (!volume.Read(DISCHEADER_ADDRESS, buffer.size(), buffer.data(), partition))
+ return false;
+ // Erase NKitv1 data
+ if (volume.IsNKit())
+ std::memset(buffer.data() + 0x200, 0, 0x1C);
+ if (!f.WriteBytes(buffer.data(), buffer.size()))
+ return false;
+ return true;
}
bool ExportBI2Data(const Volume& volume, const Partition& partition,