Skip to content

Commit 0c14a47

Browse files
committed
- Remove extraneous arguments when creating Mtrl class
- Added missing cache queue for item and model conversions - Minor shape data adjustments.
1 parent b4b4bef commit 0c14a47

File tree

7 files changed

+40
-35
lines changed

7 files changed

+40
-35
lines changed

xivModdingFramework/Cache/XivDependencyGraph.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ public async Task<List<string>> GetTextureFiles(int materialVariant = -1, IndexF
734734

735735
if (index.Get8xDataOffset(mat) != 0)
736736
{
737-
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory, dataFile, XivCache.GameInfo.GameLanguage);
737+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);
738738
mtrlTexs = await _mtrl.GetTexturePathsFromMtrlPath(mat, false, false, index, modlist);
739739
}
740740
}
@@ -1302,7 +1302,7 @@ public static async Task<List<string>> GetChildFiles(string internalFilePath)
13021302
try
13031303
{
13041304
var dataFile = IOUtil.GetDataFileFromPath(internalFilePath);
1305-
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory, dataFile, XivCache.GameInfo.GameLanguage);
1305+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);
13061306
var mtrlChildren = await _mtrl.GetTexturePathsFromMtrlPath(internalFilePath, false, false);
13071307
return mtrlChildren;
13081308
} catch

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,11 @@ public class Mtrl
4747
{
4848
private const string MtrlExtension = ".mtrl";
4949
private readonly DirectoryInfo _gameDirectory;
50-
private readonly XivLanguage _language;
51-
private XivDataFile _dataFile;
5250
private static SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1, 1);
5351

54-
public Mtrl(DirectoryInfo gameDirectory, XivDataFile dataFile, XivLanguage lang)
52+
public Mtrl(DirectoryInfo gameDirectory)
5553
{
5654
_gameDirectory = gameDirectory;
57-
_language = lang;
58-
DataFile = dataFile;
59-
}
60-
61-
public XivDataFile DataFile
62-
{
63-
get => _dataFile;
64-
set => _dataFile = value;
6555
}
6656

6757

@@ -405,13 +395,10 @@ public async Task<XivMtrl> GetMtrlData(long mtrlOffset, string mtrlPath, int dxV
405395
var index = new Index(_gameDirectory);
406396

407397
// Get uncompressed mtrl data
408-
var mtrlData = await dat.GetType2Data(mtrlOffset, DataFile);
398+
var df = IOUtil.GetDataFileFromPath(mtrlPath);
399+
var mtrlData = await dat.GetType2Data(mtrlOffset, df);
409400

410401
XivMtrl xivMtrl = null;
411-
412-
// Why is there a semaphore here to read an in memory byte block?
413-
await _semaphoreSlim.WaitAsync();
414-
415402
try
416403
{
417404
await Task.Run((Func<Task>)(async () =>
@@ -510,7 +497,7 @@ await Task.Run((Func<Task>)(async () =>
510497
if (String.IsNullOrEmpty(texturePath)) continue;
511498

512499
if (await index.FileExists(Path.GetDirectoryName(texturePath).Replace("\\", "/") + "/" + dx11FileName,
513-
DataFile))
500+
df))
514501
{
515502
texturePath = texturePath.Insert(texturePath.LastIndexOf("/") + 1, "--");
516503
}
@@ -638,7 +625,6 @@ await Task.Run((Func<Task>)(async () =>
638625
}
639626
finally
640627
{
641-
_semaphoreSlim.Release();
642628
}
643629

644630
return xivMtrl;
@@ -1183,7 +1169,6 @@ public static XivDependencyRootInfo GetHairMaterialRoot(XivDependencyRootInfo ro
11831169
}
11841170
public void Dipose()
11851171
{
1186-
_semaphoreSlim?.Dispose();
11871172
}
11881173

11891174
/// <summary>

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ public List<short> ShapePartCounts
768768
var originalBaseVertex = defaultBaseVerts[vIdx];
769769
var originalShapeVertex = defaultShapeVerts[vIdx];
770770

771-
var dot = Vector3.Dot(baseVertex.Binormal, originalBaseVertex.Binormal);
771+
var dot = Vector3.Dot(shapeVertex.Binormal, originalShapeVertex.Binormal);
772772

773773
vIdx++;
774774
}
@@ -786,7 +786,7 @@ public List<short> ShapePartCounts
786786

787787
if(originalVertex.Tangent != newVertex.Tangent || originalVertex.Normal != newVertex.Normal || originalVertex.UV1 != newVertex.UV1 || originalVertex.Binormal != newVertex.Binormal)
788788
{
789-
throw new Exception("???");
789+
//throw new Exception("???");
790790
}
791791

792792

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public static async Task ExportMaterialsForModel(TTModel model, string outputFil
273273
var directory = Path.GetDirectoryName(outputFilePath);
274274

275275
// Language doesn't actually matter here.
276-
var _mtrl = new Mtrl(gameDirectory, IOUtil.GetDataFileFromPath(model.Source), XivLanguage.None);
276+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);
277277
var _tex = new Tex(gameDirectory);
278278
var _index = new Index(gameDirectory);
279279
var materialIdx = 0;
@@ -1697,7 +1697,7 @@ public async Task<List<string>> GetReferencedMaterialPaths(string mdlPath, int m
16971697
{
16981698
// Language is irrelevant here.
16991699
var dataFile = IOUtil.GetDataFileFromPath(mdlPath);
1700-
var _mtrl = new Mtrl(_gameDirectory, dataFile, XivLanguage.None);
1700+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);
17011701
var _imc = new Imc(_gameDirectory);
17021702
if (index == null)
17031703
{
@@ -4431,10 +4431,12 @@ public async Task<long> CopyModel(string originalPath, string newPath, string so
44314431
var xMdl = await GetRawMdlData(originalPath, false, offset);
44324432
var model = TTModel.FromRaw(xMdl);
44334433

4434+
44344435
if (model == null)
44354436
{
44364437
throw new InvalidDataException("Source model file does not exist.");
44374438
}
4439+
var allFiles = new HashSet<string>() { newPath };
44384440

44394441
var originalRace = IOUtil.GetRaceFromPath(originalPath);
44404442
var newRace = IOUtil.GetRaceFromPath(newPath);
@@ -4448,7 +4450,7 @@ public async Task<long> CopyModel(string originalPath, string newPath, string so
44484450
}
44494451

44504452
// Language is irrelevant here.
4451-
var _mtrl = new Mtrl(_gameDirectory, IOUtil.GetDataFileFromPath(newPath), XivLanguage.None);
4453+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);
44524454

44534455
// Get all variant materials.
44544456
var materialPaths = await GetReferencedMaterialPaths(originalPath, -1, false, false, index, modlist);
@@ -4498,11 +4500,13 @@ public async Task<long> CopyModel(string originalPath, string newPath, string so
44984500

44994501
mtrl.TexturePathList[i] = ntex;
45004502

4503+
allFiles.Add(ntex);
45014504
await _dat.CopyFile(tex, ntex, source, true, item, index, modlist);
45024505
}
45034506
}
45044507

45054508
mtrl.MTRLPath = path;
4509+
allFiles.Add(mtrl.MTRLPath);
45064510
await _mtrl.ImportMtrl(mtrl, item, source, index, modlist);
45074511

45084512
if(!validNewMaterials.ContainsKey(newMatName))
@@ -4553,6 +4557,7 @@ public async Task<long> CopyModel(string originalPath, string newPath, string so
45534557
// Missing a material set, copy in the known valid material.
45544558
if(!copied)
45554559
{
4560+
allFiles.Add(testPath);
45564561
await _dat.CopyFile(validPath, testPath, source, true, item, index, modlist);
45574562
}
45584563
}
@@ -4567,6 +4572,7 @@ public async Task<long> CopyModel(string originalPath, string newPath, string so
45674572

45684573
await _index.SaveIndexFile(index);
45694574
await _modding.SaveModListAsync(modlist);
4575+
XivCache.QueueDependencyUpdate(allFiles.ToList());
45704576

45714577
return offset;
45724578
}

xivModdingFramework/Mods/Modding.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,26 @@ public async Task<ModList> GetModListAsync()
110110
public void SaveModList(ModList ml)
111111
{
112112
_modlistSemaphore.Wait();
113-
File.WriteAllText(ModListDirectory.FullName, JsonConvert.SerializeObject(ml, Formatting.Indented));
114-
_modlistSemaphore.Release();
113+
try
114+
{
115+
File.WriteAllText(ModListDirectory.FullName, JsonConvert.SerializeObject(ml, Formatting.Indented));
116+
}
117+
finally
118+
{
119+
_modlistSemaphore.Release();
120+
}
115121
}
116122
public async Task SaveModListAsync(ModList ml)
117123
{
118124
await _modlistSemaphore.WaitAsync();
119-
File.WriteAllText(ModListDirectory.FullName, JsonConvert.SerializeObject(ml, Formatting.Indented));
120-
_modlistSemaphore.Release();
125+
try
126+
{
127+
File.WriteAllText(ModListDirectory.FullName, JsonConvert.SerializeObject(ml, Formatting.Indented));
128+
}
129+
finally
130+
{
131+
_modlistSemaphore.Release();
132+
}
121133
}
122134

123135
public async Task DeleteAllFilesAddedByTexTools()

xivModdingFramework/Mods/RootCloner.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static async Task<Dictionary<string, string>> CloneRoot(XivDependencyRoot
6565
var _mdl = new Mdl(XivCache.GameInfo.GameDirectory, df);
6666
var _dat = new Dat(XivCache.GameInfo.GameDirectory);
6767
var _index = new Index(XivCache.GameInfo.GameDirectory);
68-
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory, df, XivCache.GameInfo.GameLanguage);
68+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);
6969
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
7070

7171
var doSave = false;
@@ -485,6 +485,8 @@ public static async Task<Dictionary<string, string>> CloneRoot(XivDependencyRoot
485485
await _modding.SaveModListAsync(modlist);
486486
}
487487

488+
XivCache.QueueDependencyUpdate(allFiles.ToList());
489+
488490
if(saveDirectory != null)
489491
{
490492

xivModdingFramework/Textures/FileTypes/Tex.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,8 @@ public async Task<long> TexColorImporter(XivMtrl xivMtrl, DirectoryInfo ddsFileD
906906
xivMtrl.Unknown2[0] = 12;
907907
}
908908

909-
var mtrl = new Mtrl(_gameDirectory, xivMtrl.TextureTypePathList[0].DataFile, lang);
910-
return await mtrl.ImportMtrl(xivMtrl, item, source);
909+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);
910+
return await _mtrl.ImportMtrl(xivMtrl, item, source);
911911
}
912912

913913

@@ -1019,8 +1019,8 @@ public byte[] DDStoMtrlData(XivMtrl xivMtrl, DirectoryInfo ddsFileDirectory, IIt
10191019
xivMtrl.Unknown2[0] = 12;
10201020
}
10211021

1022-
var mtrl = new Mtrl(_gameDirectory, xivMtrl.TextureTypePathList[0].DataFile, lang);
1023-
return mtrl.CreateMtrlFile(xivMtrl, item);
1022+
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);
1023+
return _mtrl.CreateMtrlFile(xivMtrl, item);
10241024
}
10251025

10261026
/// <summary>

0 commit comments

Comments
 (0)