Skip to content

Commit a47e0a5

Browse files
committed
Add functions for checking and fixing incorrect type4 reported file sizes.
1 parent c8737e3 commit a47e0a5

File tree

1 file changed

+41
-0
lines changed
  • xivModdingFramework/SqPack/FileTypes

1 file changed

+41
-0
lines changed

xivModdingFramework/SqPack/FileTypes/Dat.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,47 @@ await Task.Run(async () =>
847847
return (meshCount, materialCount, byteList.ToArray());
848848
}
849849

850+
public async Task<uint> GetReportedType4UncompressedSize(XivDataFile df, long offsetWithDatNumber)
851+
{
852+
// This formula is used to obtain the dat number in which the offset is located
853+
var datNum = (int)((offsetWithDatNumber / 8) & 0x0F) / 2;
854+
855+
var offset = OffsetCorrection(datNum, offsetWithDatNumber);
856+
857+
var datPath = Path.Combine(_gameDirectory.FullName, $"{df.GetDataFileName()}{DatExtension}{datNum}");
858+
859+
return await Task.Run(async () =>
860+
{
861+
using (var br = new BinaryReader(File.OpenRead(datPath)))
862+
{
863+
br.BaseStream.Seek(offset+8, SeekOrigin.Begin);
864+
865+
var size = br.ReadUInt32();
866+
return size;
867+
}
868+
});
869+
}
870+
871+
public async Task UpdateType4UncompressedSize(XivDataFile df, long offsetWithDatNumber, uint correctedFileSize)
872+
{
873+
// This formula is used to obtain the dat number in which the offset is located
874+
var datNum = (int)((offsetWithDatNumber / 8) & 0x0F) / 2;
875+
876+
var offset = OffsetCorrection(datNum, offsetWithDatNumber);
877+
878+
var datPath = Path.Combine(_gameDirectory.FullName, $"{df.GetDataFileName()}{DatExtension}{datNum}");
879+
880+
await Task.Run(async () =>
881+
{
882+
using (var br = new BinaryWriter(File.OpenWrite(datPath)))
883+
{
884+
br.BaseStream.Seek(offset + 8, SeekOrigin.Begin);
885+
br.Write(correctedFileSize);
886+
}
887+
});
888+
}
889+
890+
850891
/// <summary>
851892
/// Gets the original or modded data for type 4 files based on the path specified.
852893
/// </summary>

0 commit comments

Comments
 (0)