Skip to content

Commit 2fc18c5

Browse files
committed
Update 2.3.2.6
2 parents ff2b1c4 + 1235f17 commit 2fc18c5

File tree

12 files changed

+246
-148
lines changed

12 files changed

+246
-148
lines changed

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
using xivModdingFramework.Items.Enums;
3030
using xivModdingFramework.Items.Interfaces;
3131
using xivModdingFramework.Materials.DataContainers;
32+
using xivModdingFramework.Mods.DataContainers;
3233
using xivModdingFramework.Resources;
34+
using xivModdingFramework.SqPack.DataContainers;
3335
using xivModdingFramework.SqPack.FileTypes;
3436
using xivModdingFramework.Textures.DataContainers;
3537
using xivModdingFramework.Textures.Enums;
@@ -697,15 +699,15 @@ public void SaveColorSetExtraData(IItem item, XivMtrl xivMtrl, DirectoryInfo sav
697699
/// <param name="item">The item whos mtrl is being imported</param>
698700
/// <param name="source">The source/application that is writing to the dat.</param>
699701
/// <returns>The new offset</returns>
700-
public async Task<long> ImportMtrl(XivMtrl xivMtrl, IItem item, string source)
702+
public async Task<long> ImportMtrl(XivMtrl xivMtrl, IItem item, string source, IndexFile cachedIndexFile = null, ModList cachedModList = null)
701703
{
702704
try
703705
{
704706
var mtrlBytes = CreateMtrlFile(xivMtrl, item);
705707
var dat = new Dat(_gameDirectory);
706708

707709
// Create the actual raw MTRL first. - Files should always be created top down.
708-
long offset = await dat.ImportType2Data(mtrlBytes.ToArray(), xivMtrl.MTRLPath, source, item);
710+
long offset = await dat.ImportType2Data(mtrlBytes.ToArray(), xivMtrl.MTRLPath, source, item, cachedIndexFile, cachedModList);
709711

710712
// The MTRL file is now ready to go, but we need to validate the texture paths and create them if needed.
711713
var mapInfoList = xivMtrl.GetAllMapInfos(false);
@@ -714,7 +716,15 @@ public async Task<long> ImportMtrl(XivMtrl xivMtrl, IItem item, string source)
714716
foreach (var mapInfo in mapInfoList)
715717
{
716718
var path = mapInfo.Path;
717-
var exists = await _index.FileExists(mapInfo.Path, IOUtil.GetDataFileFromPath(path));
719+
bool exists = false;
720+
if (cachedIndexFile != null)
721+
{
722+
exists = cachedIndexFile.FileExists(mapInfo.Path);
723+
}
724+
else
725+
{
726+
exists = await _index.FileExists(mapInfo.Path, IOUtil.GetDataFileFromPath(path));
727+
}
718728

719729
if(exists)
720730
{
@@ -732,7 +742,7 @@ public async Task<long> ImportMtrl(XivMtrl xivMtrl, IItem item, string source)
732742

733743
var di = Tex.GetDefaultTexturePath(mapInfo.Usage);
734744

735-
var newOffset = await _tex.ImportTex(xivTex.TextureTypeAndPath.Path, di.FullName, item, source);
745+
var newOffset = await _tex.ImportTex(xivTex.TextureTypeAndPath.Path, di.FullName, item, source, cachedIndexFile, cachedModList);
736746

737747
}
738748

xivModdingFramework/Models/DataContainers/EquipmentParameter.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public static List<string> SlotsAsList()
169169
/// </summary>
170170
public enum EquipmentParameterFlag
171171
{
172+
// Default flag set is 0x 3F E0 00 70 60 3F 00
173+
172174
// For FULL GEAR PIECES, they're always marked as TRUE = Show
173175
// For PARTIAL GEAR PIECES, they're marked as TRUE = HIDE
174176

@@ -197,7 +199,7 @@ public enum EquipmentParameterFlag
197199
LegHideKneePads = 17, // atr_lpd
198200
LegHideShortBoot = 18, // atr_leg
199201
LegHideHalfBoot = 19, // atr_leg
200-
Bit20 = 20,
202+
LegBootUnknown = 20,
201203
LegShowFoot = 21,
202204
Bit22 = 22,
203205
Bit23 = 23,
@@ -243,8 +245,8 @@ public enum EquipmentParameterFlag
243245
HeadUnknownHelmet2 = 55, // Usually set on for helmets, in place of 48/49
244246

245247
// Byte 7 - Shadowbringers Race Settings
246-
EnableShbFlags = 56,
247-
ShbShowHead = 57,
248+
HeadShowHrothgarHat = 56,
249+
HeadShowVieraHat = 57,
248250
Bit58 = 58,
249251
Bit59 = 59,
250252
Bit60 = 60,

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,30 +407,36 @@ public async Task<XivMdl> GetRawMdlData(IItemModel item, XivRace race, string su
407407

408408
/// <summary>
409409
/// Retrieves the raw XivMdl file at a given internal file path.
410+
///
411+
/// If it an explicit offset is provided, it will be used over path or mod offset resolution.
410412
/// </summary>
411413
/// <returns>An XivMdl structure containing all mdl data.</returns>
412-
public async Task<XivMdl> GetRawMdlData(string mdlPath, bool getOriginal = false)
414+
public async Task<XivMdl> GetRawMdlData(string mdlPath, bool getOriginal = false, long offset = 0)
413415
{
414416

415-
var index = new Index(_gameDirectory);
416417
var dat = new Dat(_gameDirectory);
417418
var modding = new Modding(_gameDirectory);
418419
var mod = await modding.TryGetModEntry(mdlPath);
419420
var modded = mod != null && mod.enabled;
420421
var getShapeData = true;
421422

422423

423-
long offset = await index.GetDataOffset(mdlPath);
424-
425-
if (getOriginal)
424+
if (offset == 0)
426425
{
427-
if (modded)
426+
var index = new Index(_gameDirectory);
427+
offset = await index.GetDataOffset(mdlPath);
428+
429+
if (getOriginal)
428430
{
429-
offset = mod.data.originalOffset;
430-
modded = false;
431+
if (modded)
432+
{
433+
offset = mod.data.originalOffset;
434+
modded = false;
435+
}
431436
}
432437
}
433438

439+
434440
if (offset == 0)
435441
{
436442
return null;

xivModdingFramework/Mods/FileTypes/ItemMetadata.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static async Task<ItemMetadata> GetMetadata(string internalFilePath)
144144
/// </summary>
145145
/// <param name="root"></param>
146146
/// <returns></returns>
147-
public static async Task<ItemMetadata> GetMetadata(XivDependencyRoot root)
147+
public static async Task<ItemMetadata> GetMetadata(XivDependencyRoot root, bool forceDefault = false)
148148
{
149149
if(root == null)
150150
{
@@ -164,11 +164,11 @@ public static async Task<ItemMetadata> GetMetadata(XivDependencyRoot root)
164164

165165
// Run it through the binary deserializer and we're good.
166166
//return await Deserialize(data);
167-
return await CreateFromRaw(root);
167+
return await CreateFromRaw(root, forceDefault);
168168
} else
169169
{
170170
// This is the fun part where we get to pull the Metadata from all the disparate files around the FFXIV File System.
171-
return await CreateFromRaw(root);
171+
return await CreateFromRaw(root, forceDefault);
172172
}
173173
}
174174

@@ -211,17 +211,15 @@ private static async Task<ItemMetadata> CreateFromRaw(XivDependencyRoot root, bo
211211
/// </summary>
212212
/// <param name="meta"></param>
213213
/// <returns></returns>
214-
public static async Task SaveMetadata(ItemMetadata meta, string source)
214+
public static async Task SaveMetadata(ItemMetadata meta, string source, IndexFile index = null, ModList modlist = null)
215215
{
216216
var _dat = new Dat(XivCache.GameInfo.GameDirectory);
217217
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
218218

219219
var path = meta.Root.Info.GetRootFile();
220220
var item = meta.Root.GetFirstItem();
221221

222-
var entry = await _modding.TryGetModEntry(path);
223-
224-
await _dat.ImportType2Data(await Serialize(meta), path, source, item);
222+
await _dat.ImportType2Data(await Serialize(meta), path, source, item, index, modlist);
225223
}
226224

227225
/// <summary>
@@ -231,7 +229,7 @@ public static async Task SaveMetadata(ItemMetadata meta, string source)
231229
/// <param name="index"></param>
232230
/// <param name="modlist"></param>
233231
/// <returns></returns>
234-
internal static async Task ApplyMetadataBatched(List<ItemMetadata> data, IndexFile index, ModList modlist)
232+
internal static async Task ApplyMetadataBatched(List<ItemMetadata> data, IndexFile index, ModList modlist, bool save = true)
235233
{
236234
var _eqp = new Eqp(XivCache.GameInfo.GameDirectory);
237235
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
@@ -306,8 +304,11 @@ internal static async Task ApplyMetadataBatched(List<ItemMetadata> data, IndexFi
306304
}
307305
}
308306

309-
await _index.SaveIndexFile(index);
310-
await _modding.SaveModListAsync(modlist);
307+
if (save)
308+
{
309+
await _index.SaveIndexFile(index);
310+
await _modding.SaveModListAsync(modlist);
311+
}
311312
}
312313

313314
/// <summary>

xivModdingFramework/Mods/FileTypes/TTMP.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,18 @@ public string GetVersion(DirectoryInfo modPackDirectory)
433433
/// <param name="gameDirectory">The game directory</param>
434434
/// <param name="modListDirectory">The mod list directory</param>
435435
/// <param name="progress">The progress of the import</param>
436+
/// <param name="RootConversions">Roots to convert during import, if any conversions are required.</param>
436437
/// <returns>The number of total mods imported</returns>
437438
public async Task<(int ImportCount, int ErrorCount, string Errors, float Duration)> ImportModPackAsync(DirectoryInfo modPackDirectory, List<ModsJson> modsJson,
438-
DirectoryInfo gameDirectory, DirectoryInfo modListDirectory, IProgress<(int current, int total, string message)> progress)
439+
DirectoryInfo gameDirectory, DirectoryInfo modListDirectory, IProgress<(int current, int total, string message)> progress, Dictionary<XivDependencyRoot, XivDependencyRoot> RootConversions = null)
439440
{
440441
if (modsJson == null || modsJson.Count == 0) return (0, 0, "", 0);
441442

443+
if(RootConversions == null)
444+
{
445+
RootConversions = new Dictionary<XivDependencyRoot, XivDependencyRoot>();
446+
}
447+
442448
var startTime = DateTime.Now.Ticks;
443449

444450
var dat = new Dat(gameDirectory);
@@ -553,15 +559,9 @@ await Task.Run(async () =>
553559
mod= modsByFile[modJson.FullPath];
554560
}
555561

556-
uint offset = 0;
557-
558-
if(mod != null && mod.data.modSize >= size)
559-
{
560-
offset = await dat.WriteToDat(data, df, mod.data.modOffset);
561-
} else
562-
{
563-
offset = await dat.WriteToDat(data, df);
564-
}
562+
// Always write data to end of file during modpack imports in case we need
563+
// to roll back the import.
564+
uint offset = await dat.WriteToDat(data, df);
565565
DatOffsets.Add(modJson.FullPath, offset);
566566

567567
var dataType = BitConverter.ToInt32(data, 4);

xivModdingFramework/Mods/Modding.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,16 @@ public async Task<int> PurgeInvalidEmptyBlocks()
569569
/// Deletes a mod from the modlist
570570
/// </summary>
571571
/// <param name="modItemPath">The mod item path of the mod to delete</param>
572-
public async Task DeleteMod(string modItemPath, bool allowInternal = false)
572+
public async Task DeleteMod(string modItemPath, bool allowInternal = false, IndexFile index = null, ModList modList = null)
573573
{
574-
var modList = GetModList();
574+
var doSave = false;
575+
var _index = new Index(_gameDirectory);
576+
if (modList == null)
577+
{
578+
doSave = true;
579+
modList = GetModList();
580+
index = await _index.GetIndexFile(IOUtil.GetDataFileFromPath(modItemPath));
581+
}
575582

576583
var modToRemove = (from mod in modList.Mods
577584
where mod.fullPath.Equals(modItemPath)
@@ -585,19 +592,14 @@ where mod.fullPath.Equals(modItemPath)
585592
throw new Exception("Cannot delete internal data without explicit toggle.");
586593
}
587594

588-
if (modToRemove.IsCustomFile())
589-
{
590-
var index = new Index(_gameDirectory);
591-
await index.DeleteFileDescriptor(modItemPath, XivDataFiles.GetXivDataFile(modToRemove.datFile));
592-
}
593-
if (modToRemove.enabled)
594-
{
595-
await ToggleModStatus(modItemPath, false);
596-
}
597-
595+
await ToggleModUnsafe(false, modToRemove, allowInternal, true, index, modList);
598596
modList.Mods.Remove(modToRemove);
599597

600-
SaveModList(modList);
598+
if (doSave)
599+
{
600+
await _index.SaveIndexFile(index);
601+
await SaveModListAsync(modList);
602+
}
601603
}
602604

603605
/// <summary>

0 commit comments

Comments
 (0)