Skip to content

Commit c4b767e

Browse files
committed
Beta v2.3.3.9b
2 parents def976d + c409871 commit c4b767e

File tree

3 files changed

+66
-24
lines changed

3 files changed

+66
-24
lines changed

xivModdingFramework/Mods/FileTypes/ItemMetadata.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public void Validate(string path)
122122
/// </summary>
123123
/// <param name="item"></param>
124124
/// <returns></returns>
125-
public static async Task<ItemMetadata> GetMetadata(IItem item)
125+
public static async Task<ItemMetadata> GetMetadata(IItem item, bool forceDefault = false)
126126
{
127-
return await GetMetadata(item.GetRoot());
127+
return await GetMetadata(item.GetRoot(), forceDefault);
128128
}
129129

130130
/// <summary>
@@ -133,10 +133,10 @@ public static async Task<ItemMetadata> GetMetadata(IItem item)
133133
/// </summary>
134134
/// <param name="internalFilePath"></param>
135135
/// <returns></returns>
136-
public static async Task<ItemMetadata> GetMetadata(string internalFilePath)
136+
public static async Task<ItemMetadata> GetMetadata(string internalFilePath, bool forceDefault = false )
137137
{
138138
var root = await XivCache.GetFirstRoot(internalFilePath);
139-
return await GetMetadata(root);
139+
return await GetMetadata(root, forceDefault);
140140
}
141141

142142
/// <summary>
@@ -151,14 +151,17 @@ public static async Task<ItemMetadata> GetMetadata(XivDependencyRoot root, bool
151151
return null;
152152
}
153153

154-
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
155-
var _dat = new Dat(XivCache.GameInfo.GameDirectory);
154+
Mod mod = null;
156155
var filePath = root.Info.GetRootFile();
157-
158-
var mod = await _modding.TryGetModEntry(filePath);
156+
if (!forceDefault)
157+
{
158+
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
159+
mod = await _modding.TryGetModEntry(filePath);
160+
}
159161

160162
if(mod != null && mod.enabled)
161163
{
164+
var _dat = new Dat(XivCache.GameInfo.GameDirectory);
162165
// We have modded metadata stored in the .meta file in the DAT we can use.
163166
var data = await _dat.GetType2Data(filePath, false);
164167

xivModdingFramework/Mods/FileTypes/TTMP.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ await Task.Run(async () =>
859859
if (!indexFiles.ContainsKey(XivDataFile._04_Chara))
860860
{
861861
indexFiles.Add(XivDataFile._04_Chara, await _index.GetIndexFile(XivDataFile._04_Chara));
862+
metadataEntries.Add(XivDataFile._04_Chara, new List<ItemMetadata>());
862863
}
863864
// Expand the racial scaling files
864865
await CMP.ApplyRgspFile(file, indexFiles[XivDataFile._04_Chara], modList);

xivModdingFramework/Mods/Modding.cs

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,6 @@ public async Task<bool> ToggleModUnsafe(bool enable, Mod mod, bool includeIntern
399399
if (cachedIndex != null)
400400
{
401401
cachedIndex.SetDataOffset(mod.fullPath, 0);
402-
403-
// This is a metadata entry being deleted, we'll need to restore the metadata entries back to default.
404-
if (mod.fullPath.EndsWith(".meta"))
405-
{
406-
var root = await XivCache.GetFirstRoot(mod.fullPath);
407-
await ItemMetadata.RestoreDefaultMetadata(root, cachedIndex, cachedModlist);
408-
}
409-
410-
if (mod.fullPath.EndsWith(".rgsp"))
411-
{
412-
await CMP.RestoreDefaultScaling(mod.fullPath, cachedIndex, cachedModlist);
413-
}
414402
}
415403
else
416404
{
@@ -450,7 +438,7 @@ public async Task ToggleAllMods(bool enable, IProgress<(int current, int total,
450438

451439
public async Task ToggleMods(bool enable, IEnumerable<string> filePaths, IProgress<(int current, int total, string message)> progress = null)
452440
{
453-
var index = new Index(_gameDirectory);
441+
var _index = new Index(_gameDirectory);
454442

455443
var modList = await GetModListAsync();
456444

@@ -487,7 +475,7 @@ public async Task ToggleMods(bool enable, IEnumerable<string> filePaths, IProgre
487475
var df = IOUtil.GetDataFileFromPath(modEntry.fullPath);
488476
if (!indexFiles.ContainsKey(df))
489477
{
490-
indexFiles.Add(df, await index.GetIndexFile(df));
478+
indexFiles.Add(df, await _index.GetIndexFile(df));
491479
}
492480

493481

@@ -506,7 +494,7 @@ public async Task ToggleMods(bool enable, IEnumerable<string> filePaths, IProgre
506494
modList.Mods.Remove(modEntry);
507495
}
508496
}
509-
else
497+
else if(enable)
510498
{
511499
progress?.Report((0, 0, "Expanding Metadata Entries..."));
512500

@@ -541,11 +529,42 @@ public async Task ToggleMods(bool enable, IEnumerable<string> filePaths, IProgre
541529
{
542530
await CMP.ApplyRgspFile(mod.fullPath, indexFiles[XivDataFile._04_Chara], modList);
543531
}
532+
} else
533+
{
534+
progress?.Report((0, 0, "Restoring Metadata Entries..."));
535+
var metadataEntries = mods.Where(x => x.fullPath.EndsWith(".meta")).ToList();
536+
var _dat = new Dat(XivCache.GameInfo.GameDirectory);
537+
538+
Dictionary<XivDataFile, List<ItemMetadata>> metadata = new Dictionary<XivDataFile, List<ItemMetadata>>();
539+
foreach (var mod in metadataEntries)
540+
{
541+
var root = await XivCache.GetFirstRoot(mod.fullPath);
542+
var df = IOUtil.GetDataFileFromPath(mod.fullPath);
543+
var meta = await ItemMetadata.GetMetadata(root, true);
544+
if (!metadata.ContainsKey(df))
545+
{
546+
metadata.Add(df, new List<ItemMetadata>());
547+
}
548+
metadata[df].Add(meta);
549+
}
550+
551+
foreach (var dkv in metadata)
552+
{
553+
var df = dkv.Key;
554+
await ItemMetadata.ApplyMetadataBatched(dkv.Value, indexFiles[df], modList);
555+
}
556+
557+
var rgspEntries = mods.Where(x => x.fullPath.EndsWith(".rgsp")).ToList();
558+
foreach (var mod in rgspEntries)
559+
{
560+
await CMP.RestoreDefaultScaling(mod.fullPath, indexFiles[XivDataFile._04_Chara], modList);
561+
}
562+
544563
}
545564

546565
foreach (var kv in indexFiles)
547566
{
548-
await index.SaveIndexFile(kv.Value);
567+
await _index.SaveIndexFile(kv.Value);
549568
}
550569

551570
SaveModList(modList);
@@ -614,6 +633,20 @@ where mod.fullPath.Equals(modItemPath)
614633
}
615634

616635
await ToggleModUnsafe(false, modToRemove, allowInternal, true, index, modList);
636+
637+
638+
// This is a metadata entry being deleted, we'll need to restore the metadata entries back to default.
639+
if (modToRemove.fullPath.EndsWith(".meta"))
640+
{
641+
var root = await XivCache.GetFirstRoot(modToRemove.fullPath);
642+
await ItemMetadata.RestoreDefaultMetadata(root, index, modList);
643+
}
644+
645+
if (modToRemove.fullPath.EndsWith(".rgsp"))
646+
{
647+
await CMP.RestoreDefaultScaling(modToRemove.fullPath, index, modList);
648+
}
649+
617650
modList.Mods.Remove(modToRemove);
618651

619652
if (doSave)
@@ -706,6 +739,11 @@ public async Task CleanUpModlist(IProgress<(int Current, int Total, string Messa
706739
mod.name = cmpName;
707740
mod.category = "Racial Scaling";
708741
}
742+
else if (mod.fullPath.StartsWith("ui/"))
743+
{
744+
mod.name = Path.GetFileName(mod.fullPath);
745+
mod.category = "UI";
746+
}
709747
else
710748
{
711749
mod.name = Path.GetFileName(mod.fullPath);

0 commit comments

Comments
 (0)