Skip to content

Commit b46f08a

Browse files
committed
fix WDC2 strings after ordering
1 parent 027715b commit b46f08a

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

WDBXEditor/Reader/FileTypes/WDC2.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,12 @@ public override void ReadHeader(ref BinaryReader dbReader, string signature)
380380
InternalRecordSize = (uint)CopyTable.First().Value.Length;
381381

382382
if (CopyTableSize > 0)
383-
CopyTable = CopyTable.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
384-
383+
{
384+
var sort = CopyTable.Select((x, i) => new { CT = x, Off = recordOffsets[i] }).OrderBy(x => x.CT.Key);
385+
recordOffsets = sort.Select(x => x.Off).ToList();
386+
CopyTable = sort.ToDictionary(x => x.CT.Key, x => x.CT.Value);
387+
}
388+
385389
return CopyTable;
386390
}
387391

@@ -549,7 +553,7 @@ public override void WriteData(BinaryWriter bw, DBEntry entry)
549553
rowData.Dequeue();
550554

551555
bitStream.SeekNextOffset(); // each row starts at a 0 bit position
552-
556+
553557
long bitOffset = bitStream.Offset; // used for offset map calcs
554558

555559
for (int fieldIndex = 0; fieldIndex < FieldCount; fieldIndex++)
@@ -682,9 +686,9 @@ public override void WriteData(BinaryWriter bw, DBEntry entry)
682686
RecordDataOffset = (int)bw.BaseStream.Position;
683687

684688
// write string offsets
685-
if(stringLookup.Count > 0)
689+
if (stringLookup.Count > 0)
686690
{
687-
foreach(var lk in stringLookup)
691+
foreach (var lk in stringLookup)
688692
{
689693
bitStream.Seek(lk.Key.Item1, lk.Key.Item2);
690694
bitStream.WriteInt32((int)(lk.Value + bitStream.Length - lk.Key.Item1 - (lk.Key.Item2 >> 3)));
@@ -790,6 +794,7 @@ public override void WriteData(BinaryWriter bw, DBEntry entry)
790794
public override void Clear()
791795
{
792796
recordOffsets.Clear();
797+
columnOffsets.Clear();
793798
}
794799
}
795800
}

0 commit comments

Comments
 (0)