Skip to content

Commit 3bd19cf

Browse files
committed
- Added additional safety checks when applying Metadata files.
1 parent 2b51301 commit 3bd19cf

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

xivModdingFramework/Mods/FileTypes/ItemMetadata.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Net.NetworkInformation;
56
using System.Runtime.CompilerServices;
67
using System.Security.Cryptography;
78
using System.Text;
@@ -88,6 +89,31 @@ public ItemMetadata(XivDependencyRoot root)
8889
Root = root;
8990
}
9091

92+
/// <summary>
93+
/// Validates this metadata file to ensure it is being written to the correct location.
94+
/// </summary>
95+
public void Validate(string path)
96+
{
97+
const string prefix = "INVALID METADATA ERROR: ";
98+
if (Root == null)
99+
{
100+
throw new InvalidDataException(prefix + "Internal Root is NULL.");
101+
}
102+
103+
if(Root.Info.GetRootFile() != path)
104+
{
105+
throw new InvalidDataException(prefix + "Internal file path not match destination file path.");
106+
}
107+
108+
foreach(var entry in EstEntries)
109+
{
110+
if(entry.Value.SetId != Root.Info.PrimaryId && entry.Value.SetId != Root.Info.SecondaryId)
111+
{
112+
throw new InvalidDataException(prefix + "Extra Skeleton Table entries do not match internal set number.");
113+
}
114+
}
115+
}
116+
91117
/// <summary>
92118
/// Gets the metadata file for an IItem entry
93119
/// </summary>

xivModdingFramework/Mods/Modding.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ public async Task<bool> ToggleModUnsafe(bool enable, Mod mod, bool includeIntern
379379
var data = await dat.GetType2Data(mod.fullPath, false);
380380
var meta = await ItemMetadata.Deserialize(data);
381381

382+
meta.Validate(mod.fullPath);
383+
382384
// And write that metadata to the actual constituent files.
383385
await ItemMetadata.ApplyMetadata(meta);
384386
}

xivModdingFramework/SqPack/FileTypes/Dat.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,10 +1863,13 @@ where entry.fullPath.Equals(modEntry.fullPath)
18631863
var ext = Path.GetExtension(internalFilePath);
18641864
if(ext == ".meta")
18651865
{
1866+
18661867
// Retreive the uncompressed meta entry we just wrote.
18671868
var data = await GetType2Data(offset, dataFile);
18681869
var meta = await ItemMetadata.Deserialize(data);
18691870

1871+
meta.Validate(internalFilePath);
1872+
18701873
// And write that metadata to the actual constituent files.
18711874
await ItemMetadata.ApplyMetadata(meta);
18721875
}

0 commit comments

Comments
 (0)