7
7
using System . Text . RegularExpressions ;
8
8
using System . Threading . Tasks ;
9
9
using xivModdingFramework . Cache ;
10
+ using xivModdingFramework . General . Enums ;
10
11
using xivModdingFramework . Helpers ;
11
12
using xivModdingFramework . Items . Enums ;
12
13
using xivModdingFramework . Materials . FileTypes ;
@@ -30,7 +31,7 @@ public static class RootCloner
30
31
/// <param name="Destination">Destination root to copy to.</param>
31
32
/// <param name="ApplicationSource">Application to list as the source for the resulting mod entries.</param>
32
33
/// <returns></returns>
33
- public static async Task CloneRoot ( XivDependencyRoot Source , XivDependencyRoot Destination , string ApplicationSource , int singleVariant = - 1 , IProgress < string > ProgressReporter = null )
34
+ public static async Task CloneRoot ( XivDependencyRoot Source , XivDependencyRoot Destination , string ApplicationSource , int singleVariant = - 1 , string saveDirectory = null , IProgress < string > ProgressReporter = null )
34
35
{
35
36
36
37
if ( ProgressReporter != null )
@@ -408,8 +409,8 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
408
409
modlist = await _modding . GetModListAsync ( ) ;
409
410
410
411
411
-
412
- var modPack = new ModPack ( ) { author = "System" , name = "Item Copy - " + srcItem . Name + " -> " + iName , url = "" , version = "1.0" } ;
412
+ var modPack = new ModPack ( ) { author = "System" , name = "Item Copy - " + srcItem . Name + " to " + iName , url = "" , version = "1.0" } ;
413
+ List < Mod > mods = new List < Mod > ( ) ;
413
414
foreach ( var mod in modlist . Mods )
414
415
{
415
416
if ( allFiles . Contains ( mod . fullPath ) )
@@ -419,6 +420,8 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
419
420
mod . category = iCat ;
420
421
mod . source = ApplicationSource ;
421
422
mod . modPack = modPack ;
423
+
424
+ mods . Add ( mod ) ;
422
425
}
423
426
}
424
427
@@ -427,6 +430,43 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
427
430
428
431
_modding . SaveModList ( modlist ) ;
429
432
433
+ if ( saveDirectory != null )
434
+ {
435
+
436
+ ProgressReporter . Report ( "Creating TTMP File..." ) ;
437
+ var desc = "Item Converter Modpack - " + srcItem . Name + " -> " + iName + "\n Created at: " + DateTime . Now . ToString ( ) ;
438
+ // Time to save the modlist to file.
439
+ var dir = new DirectoryInfo ( saveDirectory ) ;
440
+ var _ttmp = new TTMP ( dir , ApplicationSource ) ;
441
+ var smpd = new SimpleModPackData ( )
442
+ {
443
+ Author = modPack . author ,
444
+ Description = desc ,
445
+ Url = modPack . url ,
446
+ Version = new Version ( 1 , 0 , 0 ) ,
447
+ Name = modPack . name ,
448
+ SimpleModDataList = new List < SimpleModData > ( )
449
+ } ;
450
+
451
+ foreach ( var mod in mods )
452
+ {
453
+ var size = await _dat . GetCompressedFileSize ( mod . data . modOffset , df ) ;
454
+ var smd = new SimpleModData ( )
455
+ {
456
+ Name = iName ,
457
+ FullPath = mod . fullPath ,
458
+ DatFile = df . GetDataFileName ( ) ,
459
+ Category = iCat ,
460
+ IsDefault = false ,
461
+ ModSize = size ,
462
+ ModOffset = mod . data . modOffset
463
+ } ;
464
+ smpd . SimpleModDataList . Add ( smd ) ;
465
+ }
466
+
467
+ await _ttmp . CreateSimpleModPack ( smpd , XivCache . GameInfo . GameDirectory , null , true ) ;
468
+ }
469
+
430
470
if ( ProgressReporter != null )
431
471
{
432
472
ProgressReporter . Report ( "Root copy complete." ) ;
@@ -463,25 +503,19 @@ private static string UpdateFolder(XivDependencyRoot Source, XivDependencyRoot D
463
503
{
464
504
if ( Destination . Info . PrimaryType == XivItemType . human && Destination . Info . SecondaryType == XivItemType . hair && Path . GetExtension ( path ) == ".mtrl" )
465
505
{
466
- // Hair material paths are actually hard-coded into the game, so there's some wild stuff that has to go on here.
467
- if ( Destination . Info . SecondaryId > 115 && Destination . Info . SecondaryId <= 200 )
468
- {
469
- // Hairs between 115 and 200 have forced material path sharing enabled.
470
- var digit3 = Destination . Info . SecondaryId / 100 ;
471
- var race = digit3 % 2 == 0 ? 101 : 201 ;
506
+ var hairRoot = Mtrl . GetHairMaterialRoot ( Destination . Info ) ;
472
507
473
- // Force the race code to the appropriate one.
474
- var raceReplace = new Regex ( "/c[0-9]{4}" ) ;
475
- path = raceReplace . Replace ( path , "/c" + race . ToString ( ) . PadLeft ( 4 , '0' ) ) ;
508
+ // Force the race code to the appropriate one.
509
+ var raceReplace = new Regex ( "/c[0-9]{4}" ) ;
510
+ path = raceReplace . Replace ( path , "/c" + hairRoot . PrimaryId . ToString ( ) . PadLeft ( 4 , '0' ) ) ;
476
511
477
- var hairReplace = new Regex ( "/h[0-9]{4}" ) ;
478
- path = hairReplace . Replace ( path , "/h" + Destination . Info . SecondaryId . ToString ( ) . PadLeft ( 4 , '0' ) ) ;
512
+ var hairReplace = new Regex ( "/h[0-9]{4}" ) ;
513
+ path = hairReplace . Replace ( path , "/h" + hairRoot . SecondaryId . ToString ( ) . PadLeft ( 4 , '0' ) ) ;
479
514
480
- // Hairs between 115 and 200 have forced material path sharing enabled.
481
- path = Path . GetDirectoryName ( path ) ;
482
- path = path . Replace ( '\\ ' , '/' ) ;
483
- return path ;
484
- }
515
+ // Hairs between 115 and 200 have forced material path sharing enabled.
516
+ path = Path . GetDirectoryName ( path ) ;
517
+ path = path . Replace ( '\\ ' , '/' ) ;
518
+ return path ;
485
519
}
486
520
487
521
// So first off, just copy anything from the old root folder to the new one.
@@ -511,28 +545,21 @@ private static string UpdateFileName(XivDependencyRoot Source, XivDependencyRoot
511
545
512
546
if ( Destination . Info . PrimaryType == XivItemType . human && Destination . Info . SecondaryType == XivItemType . hair && Path . GetExtension ( path ) == ".mtrl" )
513
547
{
514
- // Hair material paths are actually hard-coded into the game, so there's some wild stuff that has to go on here.
515
- if ( Destination . Info . SecondaryId > 115 && Destination . Info . SecondaryId <= 200 )
516
- {
517
- // Hairs between 115 and 200 have forced material path sharing enabled.
518
- var digit3 = Destination . Info . SecondaryId / 100 ;
519
- var race = digit3 % 2 == 0 ? 101 : 201 ;
548
+ var hairRoot = Mtrl . GetHairMaterialRoot ( Destination . Info ) ;
520
549
521
- // Force the race code to the appropriate one.
522
- var raceReplace = new Regex ( "^mt_c[0-9]{4}h[0-9]{4}" ) ;
523
- file = raceReplace . Replace ( file , "mt_c" + race . ToString ( ) . PadLeft ( 4 , '0' ) + "h" + Destination . Info . SecondaryId . ToString ( ) . PadLeft ( 4 , '0' ) ) ;
550
+ // Force replace the root information to the correct one for this target hair .
551
+ var raceReplace = new Regex ( "^mt_c[0-9]{4}h[0-9]{4}" ) ;
552
+ file = raceReplace . Replace ( file , "mt_c" + hairRoot . PrimaryId . ToString ( ) . PadLeft ( 4 , '0' ) + "h" + hairRoot . SecondaryId . ToString ( ) . PadLeft ( 4 , '0' ) ) ;
524
553
525
- // So for these, the first half of the filename is hard-coded locked (the c#### part)
526
- // We have to get gimmicky and play around with the suffixing.
527
- var initialPartRex = new Regex ( "^(mt_c[0-9]{4}h[0-9]{4})(?:_c[0-9]{4})?(.+)$" ) ;
528
- var m = initialPartRex . Match ( file ) ;
554
+ // Jam in a suffix into the MTRL to make it unique/non-colliding.
555
+ var initialPartRex = new Regex ( "^(mt_c[0-9]{4}h[0-9]{4})(?:_c[0-9]{4})?(.+)$" ) ;
556
+ var m = initialPartRex . Match ( file ) ;
529
557
530
- // ???
531
- if ( ! m . Success ) return file ;
558
+ // ???
559
+ if ( ! m . Success ) return file ;
532
560
533
- file = m . Groups [ 1 ] . Value + "_c" + Destination . Info . PrimaryId . ToString ( ) . PadLeft ( 4 , '0' ) + m . Groups [ 2 ] . Value ;
534
- return file ;
535
- }
561
+ file = m . Groups [ 1 ] . Value + "_c" + Destination . Info . PrimaryId . ToString ( ) . PadLeft ( 4 , '0' ) + m . Groups [ 2 ] . Value ;
562
+ return file ;
536
563
}
537
564
538
565
var rex = new Regex ( "[a-z][0-9]{4}([a-z][0-9]{4})" ) ;
0 commit comments