Skip to content

Commit dfe6c72

Browse files
committed
Big oopsie
1 parent d11850d commit dfe6c72

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

ColDefReader.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System.Buffers.Binary;
12
using System.Collections.Immutable;
3+
using System.Runtime.CompilerServices;
24
using System.Runtime.InteropServices;
5+
using System.Runtime.InteropServices.Marshalling;
36
using System.Security.Cryptography;
47
using Lumina;
58
using Lumina.Data.Files.Excel;
@@ -76,8 +79,21 @@ [.. files.Where(pair => pair.Item2.Header.Variant == ExcelVariant.Subrows).Selec
7679

7780
public ExcelColumnDefinition[] this[string sheetName] => Sheets[sheetName];
7881

79-
public uint GetColumnsHash(string sheetName) =>
80-
Crc32.Get(MemoryMarshal.AsBytes(Sheets[sheetName].AsSpan()));
82+
public uint GetColumnsHash(string sheetName)
83+
{
84+
var data = MemoryMarshal.Cast<ExcelColumnDefinition, ushort>(Sheets[sheetName].AsSpan());
85+
86+
// Column hashes are based on the file data, so we need to ensure the endianness matches
87+
if (BitConverter.IsLittleEndian)
88+
{
89+
var temp = data.ToArray();
90+
foreach (ref var el in temp.AsSpan())
91+
el = BinaryPrimitives.ReverseEndianness(el);
92+
data = temp.AsSpan();
93+
}
94+
95+
return Crc32.Get(MemoryMarshal.Cast<ushort, byte>(data));
96+
}
8197

8298
public void WriteTo(TextWriter writer)
8399
{

0 commit comments

Comments
 (0)