Skip to content

Commit 91d4f81

Browse files
committed
TexTypePathList is now programatically generated rather than being a hardcoded list, and no longer based on texture names/suffixes. AVFX textures moved out of the XivMTRL as they're not actually part of MTRL files. (TT adds them back in for item listings on its own.)
1 parent 82056b7 commit 91d4f81

File tree

4 files changed

+101
-31
lines changed

4 files changed

+101
-31
lines changed

xivModdingFramework/Helpers/IOUtil.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
using System;
1718
using System.Collections.Generic;
1819
using System.IO;
1920
using System.IO.Compression;
2021
using System.Linq;
2122
using System.Runtime.InteropServices;
23+
using System.Text.RegularExpressions;
2224
using System.Threading.Tasks;
2325
using xivModdingFramework.General.Enums;
2426
using xivModdingFramework.Items.Interfaces;
@@ -140,5 +142,30 @@ public static void ReplaceBytesAt(List<byte> original, byte[] toInject, int inde
140142
original[index + i] = toInject[i];
141143
};
142144
}
145+
146+
147+
148+
/// <summary>
149+
/// Resolves what XivDataFile a file lives in based upon its internal FFXIV directory path.
150+
/// </summary>
151+
/// <param name="path"></param>
152+
/// <returns></returns>
153+
public static XivDataFile GetDataFileFromPath(string path)
154+
{
155+
var files = Enum.GetValues(typeof(XivDataFile));
156+
foreach (var f in files)
157+
{
158+
var file = (XivDataFile)f;
159+
var prefix = file.GetFolderKey();
160+
161+
var match = Regex.Match(path, "^" + prefix);
162+
if (match.Success)
163+
{
164+
return file;
165+
}
166+
}
167+
168+
throw new Exception("Could not resolve data file - Invalid internal FFXIV path.");
169+
}
143170
}
144171
}

xivModdingFramework/Materials/DataContainers/XivMtrl.cs

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Linq;
2222
using System.Resources;
2323
using System.Text.RegularExpressions;
24+
using xivModdingFramework.General.Enums;
2425
using xivModdingFramework.Materials.FileTypes;
2526
using xivModdingFramework.Textures.DataContainers;
2627
using xivModdingFramework.Textures.Enums;
@@ -259,9 +260,22 @@ public ushort TextureDescriptorCount
259260
public List<TextureDescriptorStruct> TextureDescriptorList { get; set; }
260261

261262
/// <summary>
262-
/// A list of TexTypePath for the mtrl <see cref="TexTypePath"/>
263+
/// The TexTools expected list of textures in the item, including colorset 'texture'.
263264
/// </summary>
264-
public List<TexTypePath> TextureTypePathList { get; set; }
265+
public List<TexTypePath> TextureTypePathList
266+
{
267+
get
268+
{
269+
return GetTextureTypePathList();
270+
}
271+
}
272+
273+
/// <summary>
274+
/// Whether or not this Material's Variant has VFX associated with it.
275+
/// Used to indicate if TexTools should retrieve the VFX textures
276+
/// for the Texture Listing.
277+
/// </summary>
278+
public bool hasVfx { get; set; }
265279

266280
/// <summary>
267281
/// The internal MTRL path
@@ -559,6 +573,14 @@ public void SetMapInfo(XivTexType MapType, MapInfo info)
559573
// Detokenize paths
560574
info.path = DetokenizePath(info.path, info.Usage);
561575

576+
// Ensure .tex or .atex ending for sanity.
577+
var match = Regex.Match(info.path, "\\.a?tex$");
578+
if(!match.Success)
579+
{
580+
info.path = info.path += ".tex";
581+
}
582+
583+
562584

563585

564586
var raw = new TextureDescriptorStruct();
@@ -659,6 +681,54 @@ public List<MapInfo> GetAllMapInfos(bool tokenize = true)
659681
return ret;
660682
}
661683

684+
/// <summary>
685+
/// Get the 'TexTypePath' List that TT expects to populate the texture listing.
686+
/// Generated via using GetAllMapInfos to scan based on actual MTRL settings,
687+
/// Rather than file names.
688+
/// </summary>
689+
/// <returns></returns>
690+
public List<TexTypePath> GetTextureTypePathList()
691+
{
692+
var ret = new List<TexTypePath>();
693+
var maps = GetAllMapInfos(false);
694+
TexTypePath ttp;
695+
foreach (var map in maps)
696+
{
697+
ttp = new TexTypePath() { DataFile = GetDataFile(), Path = map.path, Type = map.Usage};
698+
699+
var fName = Path.GetFileNameWithoutExtension(map.path);
700+
if (fName != "") {
701+
var name = map.Usage.ToString() + ": " + fName;
702+
ttp.Name = name;
703+
}
704+
705+
ret.Add(ttp);
706+
}
707+
708+
709+
// Include the colorset as its own texture if we have one.
710+
if (ColorSetCount > 0 && ColorSetData.Count > 0)
711+
{
712+
ttp = new TexTypePath
713+
{
714+
Path = MTRLPath,
715+
Type = XivTexType.ColorSet,
716+
DataFile = GetDataFile()
717+
};
718+
ret.Add(ttp);
719+
}
720+
721+
return ret;
722+
}
723+
724+
/// <summary>
725+
/// Retrieves the Data File this MTRL resides in based on the path of the MTRL file.
726+
/// </summary>
727+
/// <returns></returns>
728+
public XivDataFile GetDataFile()
729+
{
730+
return Helpers.IOUtil.GetDataFileFromPath(MTRLPath);
731+
}
662732

663733
/// <summary>
664734
/// Retreives the base texture directory this material references.

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,8 @@ public async Task<XivMtrl> GetMtrlData(IItemModel itemModel, XivRace race, char
222222
}
223223

224224
var mtrlData = await GetMtrlData(mtrlOffset, mtrlStringPath, dxVersion);
225+
mtrlData.hasVfx = true;
225226

226-
if (mtrlPath.HasVfx)
227-
{
228-
var atex = new ATex(_gameDirectory, DataFile);
229-
try
230-
{
231-
mtrlData.TextureTypePathList.AddRange(await atex.GetAtexPaths(itemModel));
232-
}
233-
catch
234-
{
235-
return mtrlData;
236-
}
237-
}
238227

239228
return mtrlData;
240229
}
@@ -338,7 +327,6 @@ await Task.Run((Func<Task>)(async () =>
338327
MapCount = br.ReadByte(),
339328
ColorSetCount = br.ReadByte(),
340329
UnknownDataSize = br.ReadByte(),
341-
TextureTypePathList = new List<TexTypePath>(),
342330
MTRLPath = mtrlPath
343331
};
344332

@@ -428,9 +416,6 @@ await Task.Run((Func<Task>)(async () =>
428416
count++;
429417
}
430418

431-
// add the textures to the TextureTypePathList
432-
xivMtrl.TextureTypePathList.AddRange(await GetTexNames(xivMtrl.TexturePathList, DataFile));
433-
434419
// get the map path strings
435420
xivMtrl.MapPathList = new List<string>(xivMtrl.MapCount);
436421
for (var i = 0; i < xivMtrl.MapCount; i++)
@@ -449,18 +434,6 @@ await Task.Run((Func<Task>)(async () =>
449434
count++;
450435
}
451436

452-
// If the mtrl file contains a color set, add it to the TextureTypePathList
453-
if (xivMtrl.ColorSetDataSize > 0)
454-
{
455-
var ttp = new TexTypePath
456-
{
457-
Path = mtrlPath,
458-
Type = XivTexType.ColorSet,
459-
DataFile = DataFile
460-
};
461-
xivMtrl.TextureTypePathList.Add(ttp);
462-
}
463-
464437
var shaderPathSize = xivMtrl.MaterialDataSize - xivMtrl.TexturePathsDataSize;
465438

466439
xivMtrl.Shader = Encoding.UTF8.GetString(br.ReadBytes(shaderPathSize)).Replace("\0", "");

xivModdingFramework/Textures/FileTypes/ATex.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task<List<TexTypePath>> GetAtexPaths(IItemModel itemModel)
8181
var ttp = new TexTypePath
8282
{
8383
DataFile = _dataFile,
84-
Name = Path.GetFileNameWithoutExtension(atexPath),
84+
Name = "VFX: " + Path.GetFileNameWithoutExtension(atexPath),
8585
Path = atexPath
8686
};
8787

0 commit comments

Comments
 (0)