Skip to content

Commit 1ecbd3a

Browse files
committed
More sanity checks, and always recompile metadata files after ffxiv patches.
1 parent bd9a4bf commit 1ecbd3a

File tree

2 files changed

+28
-2
lines changed
  • xivModdingFramework

2 files changed

+28
-2
lines changed

xivModdingFramework/SqPack/FileTypes/Dat.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ public async Task<byte[]> GetType2Data(string internalPath, bool forceOriginal)
442442
/// <returns>Byte array containing the decompressed type 2 data.</returns>
443443
public async Task<byte[]> GetType2Data(long offset, XivDataFile dataFile)
444444
{
445+
if (offset <= 0)
446+
{
447+
throw new InvalidDataException("Cannot get file data without valid offset.");
448+
}
449+
450+
445451
var type2Bytes = new List<byte>();
446452

447453
// This formula is used to obtain the dat number in which the offset is located
@@ -770,6 +776,10 @@ public async Task<byte[]> CreateType2Data(byte[] dataToCreate)
770776
/// <returns>A tuple containing the mesh count, material count, and decompressed data</returns>
771777
public async Task<(int MeshCount, int MaterialCount, byte[] Data)> GetType3Data(long offset, XivDataFile dataFile)
772778
{
779+
if (offset <= 0)
780+
{
781+
throw new InvalidDataException("Cannot get file data without valid offset.");
782+
}
773783

774784
// This formula is used to obtain the dat number in which the offset is located
775785
var datNum = (int) ((offset / 8) & 0x0F) / 2;
@@ -934,6 +944,11 @@ public async Task<XivTex> GetType4Data(string internalPath, bool forceOriginal)
934944

935945
public async Task<int> GetCompressedFileSize(long offset, XivDataFile dataFile)
936946
{
947+
if (offset <= 0)
948+
{
949+
throw new InvalidDataException("Cannot get file size data without valid offset.");
950+
}
951+
937952

938953
var xivTex = new XivTex();
939954

@@ -1079,6 +1094,11 @@ public async Task<int> GetCompressedFileSize(long offset, XivDataFile dataFile)
10791094
/// <returns>An XivTex containing all the type 4 texture data</returns>
10801095
public async Task<XivTex> GetType4Data(long offset, XivDataFile dataFile)
10811096
{
1097+
if (offset <= 0)
1098+
{
1099+
throw new InvalidDataException("Cannot get file size data without valid offset.");
1100+
}
1101+
10821102
var xivTex = new XivTex();
10831103

10841104
var decompressedData = new List<byte>();

xivModdingFramework/Variants/FileTypes/Imc.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,17 @@ public async Task SaveFullImcInfo(FullImcInfo info, IItemModel item)
486486

487487
public async Task SaveFullImcInfo(FullImcInfo info, string path, string itemName = null, string category = null, string source = null)
488488
{
489+
if (info == null || info.TypeIdentifier != ImcType.Set && info.TypeIdentifier != ImcType.NonSet)
490+
{
491+
throw new InvalidDataException("Cannot save invalid IMC file.");
492+
}
493+
489494
var index = new Index(_gameDirectory);
490495
var dat = new Dat(_gameDirectory);
491496

492497
var data = new List<byte>();
493498

499+
494500
// 4 Header bytes.
495501
data.AddRange(BitConverter.GetBytes((short) info.SubsetCount));
496502
data.AddRange(BitConverter.GetBytes((short) info.TypeIdentifier));
@@ -607,9 +613,9 @@ public class FullImcInfo
607613
/// Get the number of subsets.
608614
/// -NOT- the same as number of material variants.
609615
/// </summary>
610-
public int SubsetCount { get
616+
public short SubsetCount { get
611617
{
612-
return SubsetList.Count;
618+
return (short)SubsetList.Count;
613619
}
614620
set {
615621
throw new NotSupportedException("Attempted to directly set SubsetCount.");

0 commit comments

Comments
 (0)