Skip to content

Commit c89761e

Browse files
committed
- Fix for writing file additions to incorrect hashes.
1 parent ff2b1c4 commit c89761e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

xivModdingFramework/SqPack/DataContainers/IndexFile.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Security.Cryptography;
88
using System.Text;
9+
using xivModdingFramework.Exd.FileTypes;
910
using xivModdingFramework.General.Enums;
1011
using xivModdingFramework.Helpers;
1112

@@ -154,8 +155,10 @@ private void ReadIndex1File(BinaryReader stream)
154155
{
155156
Index1Entries.Add(entry.FolderPathHash, new Dictionary<uint, FileIndexEntry>());
156157
}
157-
Index1Entries[entry.FolderPathHash].Add(entry.FileNameHash, entry);
158-
}
158+
if (!Index1Entries[entry.FolderPathHash].ContainsKey(entry.FileNameHash))
159+
{
160+
Index1Entries[entry.FolderPathHash].Add(entry.FileNameHash, entry);
161+
}
159162
} else if(segmentId == 1 || segmentId == 2)
160163
{
161164
// Segment 4 is regenerated when writing, so we don't need to store it.
@@ -208,12 +211,16 @@ private void ReadIndex2File(BinaryReader stream)
208211

209212
var bytes = stream.ReadBytes(8);
210213
entry.SetBytes(bytes);
211-
Index2Entries.Add(entry.FullPathHash, entry);
214+
215+
if (!Index2Entries.ContainsKey(entry.FullPathHash))
216+
{
217+
Index2Entries.Add(entry.FullPathHash, entry);
218+
}
212219
}
213220
}
214221
else if (segmentId == 1 || segmentId == 2 || segmentId == 3)
215222
{
216-
Index2ExtraSegments.Add(stream.ReadBytes(segmentSize));
223+
Index2ExtraSegments.Add(stream.ReadBytes(segmentSize));
217224
}
218225
}
219226

@@ -253,6 +260,10 @@ private void WriteIndex1File(BinaryWriter stream)
253260
}
254261

255262
folderListing[folderKey].FileCount++;
263+
if (entry.FileNameHash != fileKey || entry.FolderPathHash != folderKey)
264+
{
265+
throw new Exception("Attempted to save Index file with invalid structure.");
266+
}
256267
fileListing.Add(entry);
257268

258269
currentFileOffset += 16;
@@ -668,7 +679,7 @@ public uint SetDataOffset(string filePath, uint newRawOffsetWithDatNumEmbed)
668679
if (newRawOffsetWithDatNumEmbed != 0)
669680
{
670681
var entry = new FileIndexEntry(newRawOffsetWithDatNumEmbed, fileHash, folderHash);
671-
Index1Entries[folderHash].Add(newRawOffsetWithDatNumEmbed, entry);
682+
Index1Entries[folderHash].Add(fileHash, entry);
672683
}
673684
} else
674685
{

0 commit comments

Comments
 (0)