NdsForge.NET 1.0.1
Read, validate, edit, compare, and build Nintendo DS and DSi images from .NET
Loading...
Searching...
No Matches
NdsKey1KeyTable.cs
1using System.Buffers.Binary;
2
3namespace NdsForge;
4
10public sealed class NdsKey1KeyTable
11{
13 public const int ByteLength = 0x1048;
14
16 private readonly uint[] _words;
17
20 public NdsKey1KeyTable(ReadOnlySpan<byte> data)
21 {
22 if (data.Length != ByteLength)
23 {
24 throw new ArgumentException($"A DS KEY1 table must contain exactly 0x{ByteLength:X} bytes.", nameof(data));
25 }
26
27 _words = new uint[ByteLength / sizeof(uint)];
28 for (int index = 0; index < _words.Length; index++)
29 {
30 _words[index] = BinaryPrimitives.ReadUInt32LittleEndian(data[(index * sizeof(uint))..]);
31 }
32 }
33
36 public byte[] Export()
37 {
38 var data = new byte[ByteLength];
39 for (int index = 0; index < _words.Length; index++)
40 {
41 BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(index * sizeof(uint)), _words[index]);
42 }
43
44 return data;
45 }
46
49 internal uint[] CreateWorkingWords() => (uint[])_words.Clone();
50}
byte[] Export()
Exports the seed schedule exactly as little-endian words for controlled persistence or interop.
const int ByteLength
Number of little-endian bytes in the complete KEY1 seed schedule.
NdsKey1KeyTable(ReadOnlySpan< byte > data)
Loads the complete native little-endian key schedule without assuming where it originated.