We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d359a51 commit c32f062Copy full SHA for c32f062
1 file changed
src/D2SSharp/Model/D2SaveOverlay.cs
@@ -20,6 +20,19 @@ public struct HeaderLayout
20
[FieldOffset(12)] public uint Checksum;
21
22
internal readonly bool IsValid => Magic == D2Save.Magic;
23
+
24
+ /// <summary>
25
+ /// Returns the save file version from raw bytes without allocating.
26
+ /// </summary>
27
+ /// <param name="data">The save file data (minimum 8 bytes).</param>
28
+ /// <returns>The save file version.</returns>
29
+ public static uint GetVersion(ReadOnlySpan<byte> data)
30
+ {
31
+ ref readonly var header = ref MemoryMarshal.AsRef<HeaderLayout>(data);
32
+ if (!header.IsValid)
33
+ throw new InvalidDataException($"Invalid save file magic: 0x{header.Magic:X8}, expected 0x{D2Save.Magic:X8}");
34
+ return header.Version;
35
+ }
36
}
37
38
/// <summary>
0 commit comments