17
17
using xivModdingFramework . Models . DataContainers ;
18
18
using xivModdingFramework . Models . FileTypes ;
19
19
using xivModdingFramework . Mods ;
20
+ using xivModdingFramework . Mods . DataContainers ;
21
+ using xivModdingFramework . Mods . FileTypes ;
20
22
using xivModdingFramework . Resources ;
23
+ using xivModdingFramework . SqPack . DataContainers ;
21
24
using xivModdingFramework . SqPack . FileTypes ;
22
25
using xivModdingFramework . Variants . FileTypes ;
23
26
using static xivModdingFramework . Cache . XivCache ;
@@ -492,14 +495,25 @@ public override int GetHashCode()
492
495
/// Gets all the model files in this dependency chain.
493
496
/// </summary>
494
497
/// <returns></returns>
495
- public async Task < List < string > > GetModelFiles ( )
498
+ public async Task < List < string > > GetModelFiles ( IndexFile index = null , ModList modlist = null )
496
499
{
497
500
// Some chains have no meta entries, and jump straight to models.
498
501
// Try to resolve Meta files first.
499
502
if ( Info . PrimaryType == XivItemType . equipment || Info . PrimaryType == XivItemType . accessory )
500
503
{
501
504
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
+
503
517
var models = new List < string > ( ) ;
504
518
foreach ( var race in races )
505
519
{
@@ -523,8 +537,13 @@ public async Task<List<string>> GetModelFiles()
523
537
if ( Info . PrimaryType == XivItemType . human && Info . SecondaryType != XivItemType . hair && Info . SecondaryId / 100 >= 1 )
524
538
{
525
539
// 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 ) ) )
528
547
{
529
548
var replacementNumber = ( Info . SecondaryId % 100 ) ;
530
549
var alteredRoot = new XivDependencyRoot ( Info . PrimaryType , Info . PrimaryId , Info . SecondaryType , replacementNumber , Info . Slot ) ;
@@ -546,8 +565,9 @@ public async Task<List<string>> GetModelFiles()
546
565
/// Subsets of this data may be accessed with XivDependencyGraph::GetChildFiles(internalFilePath).
547
566
/// </summary>
548
567
/// <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 )
550
569
{
570
+ var useCache = index == null ;
551
571
552
572
var materials = new HashSet < string > ( ) ;
553
573
if ( Info . PrimaryType == XivItemType . human && Info . SecondaryType == XivItemType . body )
@@ -560,8 +580,13 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
560
580
var path = $ "chara/human/c{ primary } /obj/body/b{ body } /material/v0001/mt_c{ primary } b{ body } _a.mtrl";
561
581
562
582
// 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 ) ;
565
590
if ( exists )
566
591
{
567
592
materials . Add ( path ) ;
@@ -582,7 +607,7 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
582
607
}
583
608
else
584
609
{
585
- var models = await GetModelFiles ( ) ;
610
+ var models = await GetModelFiles ( index , modlist ) ;
586
611
if ( models != null && models . Count > 0 )
587
612
{
588
613
var dataFile = IOUtil . GetDataFileFromPath ( models [ 0 ] ) ;
@@ -598,7 +623,15 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
598
623
599
624
foreach ( var model in models )
600
625
{
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
+
602
635
if ( materialVariant <= 0 )
603
636
{
604
637
foreach ( var mat in mdlMats )
@@ -638,11 +671,15 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
638
671
}
639
672
640
673
// 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
+
643
680
var rootFolder = Info . GetRootFolder ( ) ;
644
681
var variantRep = "v" + materialVariant . ToString ( ) . PadLeft ( 4 , '0' ) ;
645
- foreach ( var mod in modList . Mods )
682
+ foreach ( var mod in modlist . Mods )
646
683
{
647
684
if ( ! mod . enabled ) continue ;
648
685
@@ -673,15 +710,25 @@ public async Task<List<string>> GetMaterialFiles(int materialVariant = -1)
673
710
/// Subsets of this data may be accessed with XivDependencyGraph::GetChildFiles(internalFilePath).
674
711
/// </summary>
675
712
/// <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 )
677
714
{
678
- var materials = await GetMaterialFiles ( materialVariant ) ;
715
+ var materials = await GetMaterialFiles ( materialVariant , index , modlist ) ;
679
716
var textures = new HashSet < string > ( ) ;
680
717
if ( materials != null && materials . Count > 0 )
681
718
{
682
719
foreach ( var mat in materials )
683
720
{
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
+
685
732
foreach ( var tex in mtrlTexs )
686
733
{
687
734
textures . Add ( tex ) ;
0 commit comments