Skip to content

Commit c32f062

Browse files
feat: Add method to check version in the overlay API
1 parent d359a51 commit c32f062

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/D2SSharp/Model/D2SaveOverlay.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ public struct HeaderLayout
2020
[FieldOffset(12)] public uint Checksum;
2121

2222
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+
}
2336
}
2437

2538
/// <summary>

0 commit comments

Comments
 (0)