Skip to content

Commit c30def4

Browse files
committed
Beta 2.3.3.0
2 parents 94d2fe9 + 4f09dba commit c30def4

File tree

13 files changed

+462
-198
lines changed

13 files changed

+462
-198
lines changed

xivModdingFramework/Cache/XivDependencyGraph.cs

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
using xivModdingFramework.Models.DataContainers;
1818
using xivModdingFramework.Models.FileTypes;
1919
using xivModdingFramework.Mods;
20+
using xivModdingFramework.Mods.DataContainers;
21+
using xivModdingFramework.Mods.FileTypes;
2022
using xivModdingFramework.Resources;
23+
using xivModdingFramework.SqPack.DataContainers;
2124
using xivModdingFramework.SqPack.FileTypes;
2225
using xivModdingFramework.Variants.FileTypes;
2326
using static xivModdingFramework.Cache.XivCache;
@@ -492,14 +495,25 @@ public override int GetHashCode()
492495
/// Gets all the model files in this dependency chain.
493496
/// </summary>
494497
/// <returns></returns>
495-
public async Task<List<string>> GetModelFiles()
498+
public async Task<List<string>> GetModelFiles(IndexFile index = null, ModList modlist = null)
496499
{
497500
// Some chains have no meta entries, and jump straight to models.
498501
// Try to resolve Meta files first.
499502
if (Info.PrimaryType == XivItemType.equipment || Info.PrimaryType == XivItemType.accessory)
500503
{
501504
var _eqp = new Eqp(XivCache.GameInfo.GameDirectory);
502-
var races = await _eqp.GetAvailableRacialModels(Info.PrimaryId, Info.Slot, false, true);
505+
506+
List<XivRace> races = null;
507+
if (index != null)
508+
{
509+
var metadata = await ItemMetadata.GetFromCachedIndex(this, index);
510+
races = metadata.EqdpEntries.Where(x => x.Value.bit1).Select(x => x.Key).ToList();
511+
}
512+
else
513+
{
514+
races = await _eqp.GetAvailableRacialModels(Info.PrimaryId, Info.Slot, false, true);
515+
}
516+
503517
var models = new List<string>();
504518
foreach(var race in races)
505519
{
@@ -523,8 +537,13 @@ public async Task<List<string>> GetModelFiles()
523537
if (Info.PrimaryType == XivItemType.human && Info.SecondaryType != XivItemType.hair && Info.SecondaryId / 100 >= 1)
524538
{
525539
// For human types, if their model is missing, the version 00xx is used instead.
526-
var index = new Index(XivCache.GameInfo.GameDirectory);
527-
if(!(await index.FileExists(modelPath)))
540+
if(index == null)
541+
{
542+
var _index = new Index(XivCache.GameInfo.GameDirectory);
543+
index = await _index.GetIndexFile(IOUtil.GetDataFileFromPath(modelPath), false, true);
544+
}
545+
546+
if(!(index.FileExists(modelPath)))
528547
{
529548
var replacementNumber = (Info.SecondaryId % 100);
530549
var alteredRoot = new XivDependencyRoot(Info.PrimaryType, Info.PrimaryId, Info.SecondaryType, replacementNumber, Info.Slot);
@@ -546,8 +565,9 @@ public async Task<List<string>> GetModelFiles()
546565
/// Subsets of this data may be accessed with XivDependencyGraph::GetChildFiles(internalFilePath).
547566
/// </summary>
548567
/// <returns></returns>
549-
public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
568+
public async Task<List<string>> GetMaterialFiles(int materialVariant = -1, IndexFile index = null, ModList modlist = null)
550569
{
570+
var useCache = index == null;
551571

552572
var materials = new HashSet<string>();
553573
if (Info.PrimaryType == XivItemType.human && Info.SecondaryType == XivItemType.body)
@@ -560,8 +580,13 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
560580
var path= $"chara/human/c{primary}/obj/body/b{body}/material/v0001/mt_c{primary}b{body}_a.mtrl";
561581

562582
// Just validate it exists and call it a day.
563-
var index = new Index(XivCache.GameInfo.GameDirectory);
564-
var exists = await index.FileExists(path);
583+
if (index == null)
584+
{
585+
var _index = new Index(XivCache.GameInfo.GameDirectory);
586+
index = await _index.GetIndexFile(IOUtil.GetDataFileFromPath(path), false, true);
587+
}
588+
589+
var exists = index.FileExists(path);
565590
if(exists)
566591
{
567592
materials.Add(path);
@@ -582,7 +607,7 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
582607
}
583608
else
584609
{
585-
var models = await GetModelFiles();
610+
var models = await GetModelFiles(index, modlist);
586611
if (models != null && models.Count > 0)
587612
{
588613
var dataFile = IOUtil.GetDataFileFromPath(models[0]);
@@ -598,7 +623,15 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
598623

599624
foreach (var model in models)
600625
{
601-
var mdlMats = await XivCache.GetChildFiles(model);
626+
List<string> mdlMats = null;
627+
if (useCache)
628+
{
629+
mdlMats = await XivCache.GetChildFiles(model);
630+
} else
631+
{
632+
mdlMats = await _mdl.GetReferencedMaterialPaths(model, -1, false, false, index, modlist);
633+
}
634+
602635
if (materialVariant <= 0)
603636
{
604637
foreach (var mat in mdlMats)
@@ -638,11 +671,15 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
638671
}
639672

640673
// Here we get to get a little fancy.
641-
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
642-
var modList = _modding.GetModList();
674+
if (modlist == null)
675+
{
676+
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
677+
modlist = _modding.GetModList();
678+
}
679+
643680
var rootFolder = Info.GetRootFolder();
644681
var variantRep = "v" + materialVariant.ToString().PadLeft(4, '0');
645-
foreach (var mod in modList.Mods)
682+
foreach (var mod in modlist.Mods)
646683
{
647684
if (!mod.enabled) continue;
648685

@@ -673,15 +710,25 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
673710
/// Subsets of this data may be accessed with XivDependencyGraph::GetChildFiles(internalFilePath).
674711
/// </summary>
675712
/// <returns></returns>
676-
public async Task<List<string>> GetTextureFiles(int materialVariant = -1)
713+
public async Task<List<string>> GetTextureFiles(int materialVariant = -1, IndexFile index = null, ModList modlist = null)
677714
{
678-
var materials = await GetMaterialFiles(materialVariant);
715+
var materials = await GetMaterialFiles(materialVariant, index, modlist);
679716
var textures = new HashSet<string>();
680717
if (materials != null && materials.Count > 0)
681718
{
682719
foreach (var mat in materials)
683720
{
684-
var mtrlTexs = await XivCache.GetChildFiles(mat);
721+
List<string> mtrlTexs = null;
722+
if (index == null)
723+
{
724+
mtrlTexs = await XivCache.GetChildFiles(mat);
725+
} else
726+
{
727+
var dataFile = IOUtil.GetDataFileFromPath(mat);
728+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory, dataFile, XivCache.GameInfo.GameLanguage);
729+
mtrlTexs = await _mtrl.GetTexturePathsFromMtrlPath(mat, false, false, index, modlist);
730+
}
731+
685732
foreach (var tex in mtrlTexs)
686733
{
687734
textures.Add(tex);

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 16 additions & 6 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;
@@ -293,10 +295,10 @@ public async Task<XivMtrl> GetMtrlData(string mtrlFile, int materialSet = -1, in
293295
/// </summary>
294296
/// <param name="mtrlPath"></param>
295297
/// <returns></returns>
296-
public async Task<List<string>> GetTexturePathsFromMtrlPath(string mtrlPath, bool includeDummies = false, bool forceOriginal = false)
298+
public async Task<List<string>> GetTexturePathsFromMtrlPath(string mtrlPath, bool includeDummies = false, bool forceOriginal = false, IndexFile index = null, ModList modlist = null)
297299
{
298300
var dat = new Dat(_gameDirectory);
299-
var mtrlData = await dat.GetType2Data(mtrlPath, forceOriginal);
301+
var mtrlData = await dat.GetType2Data(mtrlPath, forceOriginal, index, modlist);
300302
var uniqueTextures = new HashSet<string>();
301303
var texRegex = new Regex(".*\\.tex$");
302304

@@ -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: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
using System.Text.RegularExpressions;
5757
using xivModdingFramework.Materials.DataContainers;
5858
using xivModdingFramework.Cache;
59+
using xivModdingFramework.SqPack.DataContainers;
60+
using xivModdingFramework.Mods.DataContainers;
5961

6062
namespace xivModdingFramework.Models.FileTypes
6163
{
@@ -407,30 +409,36 @@ public async Task<XivMdl> GetRawMdlData(IItemModel item, XivRace race, string su
407409

408410
/// <summary>
409411
/// Retrieves the raw XivMdl file at a given internal file path.
412+
///
413+
/// If it an explicit offset is provided, it will be used over path or mod offset resolution.
410414
/// </summary>
411415
/// <returns>An XivMdl structure containing all mdl data.</returns>
412-
public async Task<XivMdl> GetRawMdlData(string mdlPath, bool getOriginal = false)
416+
public async Task<XivMdl> GetRawMdlData(string mdlPath, bool getOriginal = false, long offset = 0)
413417
{
414418

415-
var index = new Index(_gameDirectory);
416419
var dat = new Dat(_gameDirectory);
417420
var modding = new Modding(_gameDirectory);
418421
var mod = await modding.TryGetModEntry(mdlPath);
419422
var modded = mod != null && mod.enabled;
420423
var getShapeData = true;
421424

422425

423-
long offset = await index.GetDataOffset(mdlPath);
424-
425-
if (getOriginal)
426+
if (offset == 0)
426427
{
427-
if (modded)
428+
var index = new Index(_gameDirectory);
429+
offset = await index.GetDataOffset(mdlPath);
430+
431+
if (getOriginal)
428432
{
429-
offset = mod.data.originalOffset;
430-
modded = false;
433+
if (modded)
434+
{
435+
offset = mod.data.originalOffset;
436+
modded = false;
437+
}
431438
}
432439
}
433440

441+
434442
if (offset == 0)
435443
{
436444
return null;
@@ -1685,18 +1693,24 @@ public async Task<XivMdl> GetRawMdlData(string mdlPath, bool getOriginal = false
16851693
/// <param name="mdlPath"></param>
16861694
/// <param name="getOriginal"></param>
16871695
/// <returns></returns>
1688-
public async Task<List<string>> GetReferencedMaterialPaths(string mdlPath, int materialVariant = -1, bool getOriginal = false, bool includeSkin = true)
1696+
public async Task<List<string>> GetReferencedMaterialPaths(string mdlPath, int materialVariant = -1, bool getOriginal = false, bool includeSkin = true, IndexFile index = null, ModList modlist = null)
16891697
{
16901698
// Language is irrelevant here.
16911699
var dataFile = IOUtil.GetDataFileFromPath(mdlPath);
16921700
var _mtrl = new Mtrl(_gameDirectory, dataFile, XivLanguage.None);
16931701
var _imc = new Imc(_gameDirectory);
1694-
var _index = new Index(_gameDirectory);
1702+
if (index == null)
1703+
{
1704+
var _index = new Index(_gameDirectory);
1705+
var _modding = new Modding(_gameDirectory);
1706+
index = await _index.GetIndexFile(dataFile, false, true);
1707+
modlist = await _modding.GetModListAsync();
1708+
}
16951709

16961710
var materials = new List<string>();
16971711

16981712
// Read the raw Material names from the file.
1699-
var materialNames = await GetReferencedMaterialNames(mdlPath, getOriginal);
1713+
var materialNames = await GetReferencedMaterialNames(mdlPath, getOriginal, index, modlist);
17001714
if(materialNames.Count == 0)
17011715
{
17021716
return materials;
@@ -1723,7 +1737,7 @@ public async Task<List<string>> GetReferencedMaterialPaths(string mdlPath, int m
17231737
// We need to get the IMC info for this MDL so that we can pull every possible Material Variant.
17241738
try
17251739
{
1726-
var info = await _imc.GetFullImcInfo(imcPath);
1740+
var info = await _imc.GetFullImcInfo(imcPath, index, modlist);
17271741
var slotRegex = new Regex("_([a-z]{3}).mdl$");
17281742
var slot = "";
17291743
var m = slotRegex.Match(mdlPath);
@@ -1796,19 +1810,30 @@ public async Task<List<string>> GetReferencedMaterialPaths(string mdlPath, int m
17961810
/// <param name="mdlPath"></param>
17971811
/// <param name="getOriginal"></param>
17981812
/// <returns></returns>
1799-
public async Task<List<string>> GetReferencedMaterialNames(string mdlPath, bool getOriginal = false)
1813+
public async Task<List<string>> GetReferencedMaterialNames(string mdlPath, bool getOriginal = false, IndexFile index = null, ModList modlist = null)
18001814
{
18011815
var materials = new List<string>();
1802-
var index = new Index(_gameDirectory);
18031816
var dat = new Dat(_gameDirectory);
18041817
var modding = new Modding(_gameDirectory);
1805-
var mod = await modding.TryGetModEntry(mdlPath);
1806-
var offset = await index.GetDataOffset(mdlPath);
18071818

1808-
var modded = mod != null && mod.enabled;
1819+
1820+
if (index == null)
1821+
{
1822+
var _index = new Index(_gameDirectory);
1823+
index = await _index.GetIndexFile(IOUtil.GetDataFileFromPath(mdlPath), false, true);
1824+
1825+
}
1826+
1827+
var offset = index.Get8xDataOffset(mdlPath);
18091828
if (getOriginal)
18101829
{
1811-
if (modded)
1830+
if(modlist == null)
1831+
{
1832+
modlist = await modding.GetModListAsync();
1833+
}
1834+
1835+
var mod = modlist.Mods.FirstOrDefault(x => x.fullPath == mdlPath);
1836+
if(mod != null)
18121837
{
18131838
offset = mod.data.originalOffset;
18141839
}

0 commit comments

Comments
 (0)