NdsForge.NET 1.0.1
Read, validate, edit, compare, and build Nintendo DS and DSi images from .NET
Loading...
Searching...
No Matches
NdsHeaderEdit.cs
1using System.Text;
2
3namespace NdsForge;
4
6public sealed class NdsHeaderEdit
7{
9 private readonly NdsHeader _source;
12 internal NdsHeaderEdit(NdsHeader source)
13 {
14 _source = source;
15 Title = source.Title;
16 GameCode = source.GameCode;
17 MakerCode = source.MakerCode;
18 Version = source.Version;
19 RegionCode = source.RegionCode;
20 AutoStart = source.AutoStart;
24 }
25
27 public string Title { get; set; }
28
30 public string GameCode { get; set; }
31
33 public string MakerCode { get; set; }
34
36 public byte Version { get; set; }
37
39 public byte RegionCode { get; set; }
40
42 public byte AutoStart { get; set; }
43
45 public uint NormalCardControl { get; set; }
46
48 public uint SecureCardControl { get; set; }
49
51 public ushort SecureTransferTimeout { get; set; }
52
54 internal bool HasChanges =>
55 Title != _source.Title ||
56 GameCode != _source.GameCode ||
57 MakerCode != _source.MakerCode ||
58 Version != _source.Version ||
59 RegionCode != _source.RegionCode ||
60 AutoStart != _source.AutoStart ||
61 NormalCardControl != _source.NormalCardControl ||
62 SecureCardControl != _source.SecureCardControl ||
63 SecureTransferTimeout != _source.SecureTransferTimeout;
64
67 internal void Apply(Span<byte> header)
68 {
69 WriteAscii(header.Slice(0x00, 12), Title, 0, 12, nameof(Title));
70 WriteAscii(header.Slice(0x0C, 4), GameCode, 4, 4, nameof(GameCode));
71 WriteAscii(header.Slice(0x10, 2), MakerCode, 2, 2, nameof(MakerCode));
72 header[0x1D] = RegionCode;
73 header[0x1E] = Version;
74 header[0x1F] = AutoStart;
75 NdsBinary.WriteUInt32(header, 0x60, NormalCardControl);
76 NdsBinary.WriteUInt32(header, 0x64, SecureCardControl);
77 NdsBinary.WriteUInt16(header, 0x6E, SecureTransferTimeout);
78 }
79
86 private static void WriteAscii(
87 Span<byte> destination,
88 string value,
89 int minimumLength,
90 int maximumLength,
91 string propertyName)
92 {
93 ArgumentNullException.ThrowIfNull(value);
94 if (value.Length < minimumLength || value.Length > maximumLength ||
95 value.Any(static character => character is < ' ' or > '~'))
96 {
97 throw new InvalidDataException(
98 $"{propertyName} must contain {minimumLength} through {maximumLength} printable ASCII characters.");
99 }
100
101 destination.Clear();
102 Encoding.ASCII.GetBytes(value, destination);
103 }
104}
string MakerCode
Controls the exact two-character printable-ASCII publisher code stored at header offset 0x10.
uint SecureCardControl
Gets or sets secure card-control timing and flags.
ushort SecureTransferTimeout
Controls the raw 16-bit timeout applied to secure-area cartridge transfers.
string Title
Controls the padded 12-byte printable-ASCII application label; shorter values receive zero padding.
string GameCode
Controls the exact four-character printable-ASCII product code used for title identity and region con...
uint NormalCardControl
Gets or sets normal card-control timing and flags.
byte AutoStart
Controls the complete boot-policy byte and preserves responsibility for reserved bits with the caller...
byte RegionCode
Controls the raw region byte whose defined bits depend on the image's DS or DSi unit code.
byte Version
Controls the publisher-defined one-byte software revision without changing any format version.
Projects the common cartridge header into typed fields while retaining every byte needed for lossless...
Definition NdsHeader.cs:5
ushort SecureTransferTimeout
Preserves the cartridge-transfer timeout value used while accessing the secure area.
Definition NdsHeader.cs:125
uint NormalCardControl
Preserves the raw ROM-control timing word used for ordinary cartridge transfers.
Definition NdsHeader.cs:113
byte AutoStart
Preserves the boot-control byte at offset 0x1F, including reserved bits for lossless rewriting.
Definition NdsHeader.cs:83
byte RegionCode
Preserves the header's region byte, whose defined interpretation depends on DS versus DSi mode.
Definition NdsHeader.cs:77
string Title
Decodes the padded 12-byte ASCII label shown by low-level cartridge inspection tools.
Definition NdsHeader.cs:53
byte Version
Exposes the publisher-controlled one-byte software revision rather than the banner or format version.
Definition NdsHeader.cs:80
uint SecureCardControl
Preserves the raw ROM-control timing word used during secure-area cartridge transfers.
Definition NdsHeader.cs:116
string GameCode
Decodes the four-byte product code used for title identity, region suffixes, and encryption derivatio...
Definition NdsHeader.cs:56
string MakerCode
Decodes the two-byte publisher identifier; Nintendo-authored retail images commonly use 01.
Definition NdsHeader.cs:59