Skip to content

Commit 57ed263

Browse files
committed
- Made Mtrl Path resolution smarter with regards to skin materials.
1 parent b2fcbd4 commit 57ed263

File tree

1 file changed

+19
-2
lines changed
  • xivModdingFramework/Materials/FileTypes

1 file changed

+19
-2
lines changed

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ private async Task<List<TexTypePath>> GetTexNames(IEnumerable<string> texPathLis
996996
private static readonly Regex _weaponMatch = new Regex("(w[0-9]{4})");
997997
private static readonly Regex _tailMatch = new Regex("(t[0-9]{4})");
998998
private static readonly Regex _raceMatch = new Regex("(c[0-9]{4})");
999+
private static readonly Regex _bodyRegex = new Regex("(b[0-9]{4})");
9991000
private static readonly Regex _skinRegex = new Regex("^/mt_c([0-9]{4})b([0-9]{4})_.+\\.mtrl$");
10001001
/// <summary>
10011002
/// Resolves the MTRL path for a given MDL path.
@@ -1020,11 +1021,27 @@ public string GetMtrlPath(string mdlPath, string mtrlName, int mtrlVariant = 1)
10201021
var mdlMatch = _raceMatch.Match(mdlPath);
10211022
var mtrlMatch = _raceMatch.Match(mtrlName);
10221023

1024+
10231025
// Both Items have racial model information in their path, and the races DON'T match.
10241026
if (mdlMatch.Success && mtrlMatch.Success && mdlMatch.Groups[1].Value != mtrlMatch.Groups[1].Value)
10251027
{
1026-
// In this case, we actually replace the race in the Material the race from the MODEL, which has priority.
1027-
mtrlName = mtrlName.Replace(mtrlMatch.Groups[1].Value, mdlMatch.Groups[1].Value);
1028+
1029+
// Need to find the racial skin for this race.
1030+
var baseRace = XivRaces.GetXivRace(mdlMatch.Groups[1].Value.Substring(1));
1031+
var skinRace = XivRaceTree.GetSkinRace(baseRace);
1032+
var skinRaceString = "c" + XivRaces.GetRaceCode(skinRace);
1033+
1034+
// In this case, we actually replace both with the racial skin material based on the Model, which has priority.
1035+
mtrlName = mtrlName.Replace(mtrlMatch.Groups[1].Value, skinRaceString);
1036+
mdlPath = mdlPath.Replace(mdlMatch.Groups[1].Value, skinRaceString);
1037+
1038+
// If we actually shifted races, reset the body identifier.
1039+
// This shouldn't really ever happen, but safety check.
1040+
if(baseRace != skinRace)
1041+
{
1042+
mtrlName = _bodyRegex.Replace(mtrlName, "b0001");
1043+
mdlPath = _bodyRegex.Replace(mdlPath, "b0001");
1044+
}
10281045
}
10291046

10301047

0 commit comments

Comments
 (0)