diff --git a/SabreTools.Serialization/Wrappers/N3DS.cs b/SabreTools.Serialization/Wrappers/N3DS.cs index a355d236..692a8804 100644 --- a/SabreTools.Serialization/Wrappers/N3DS.cs +++ b/SabreTools.Serialization/Wrappers/N3DS.cs @@ -436,6 +436,38 @@ namespace SabreTools.Serialization.Wrappers return (partitionOffsetMU + exeFsOffsetMU) * MediaUnitSize; } + /// + /// Get the offset of a partition logo + /// + /// Offset to the logo of the partition, 0 on error + public uint GetLogoOffset(int index) + { + // No partitions means no size is available + if (PartitionsTable == null || Partitions == null) + return 0; + if (index < 0 || index >= Partitions.Length) + return 0; + + // Invalid partition table entry means no size is available + var entry = PartitionsTable[index]; + if (entry == null) + return 0; + + // Invalid partition means no size is available + var header = Partitions[index]; + if (header == null || header.MagicID != NCCHMagicNumber) + return 0; + + // If the offset is 0, return 0 + uint logoOffsetMU = header.LogoRegionOffsetInMediaUnits; + if (logoOffsetMU == 0) + return 0; + + // Return the adjusted offset + uint partitionOffsetMU = entry.Offset; + return (partitionOffsetMU + logoOffsetMU) * MediaUnitSize; + } + /// /// Get the offset of a partition /// @@ -462,6 +494,38 @@ namespace SabreTools.Serialization.Wrappers return partitionOffsetMU * MediaUnitSize; } + /// + /// Get the offset of a partition plain region + /// + /// Offset to the plain region of the partition, 0 on error + public uint GetPlainRegionOffset(int index) + { + // No partitions means no size is available + if (PartitionsTable == null || Partitions == null) + return 0; + if (index < 0 || index >= Partitions.Length) + return 0; + + // Invalid partition table entry means no size is available + var entry = PartitionsTable[index]; + if (entry == null) + return 0; + + // Invalid partition means no size is available + var header = Partitions[index]; + if (header == null || header.MagicID != NCCHMagicNumber) + return 0; + + // If the offset is 0, return 0 + uint prOffsetMU = header.PlainRegionOffsetInMediaUnits; + if (prOffsetMU == 0) + return 0; + + // Return the adjusted offset + uint partitionOffsetMU = entry.Offset; + return (partitionOffsetMU + prOffsetMU) * MediaUnitSize; + } + /// /// Get the offset of a partition RomFS ///