Skip to content

Commit bc3bd84

Browse files
committed
- Better detection for DX9/11 conversion textures in materials.
- Some sanity checks on standard modpack creation to not crash if a file doesn't exist.
1 parent a4fff77 commit bc3bd84

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

xivModdingFramework/Cache/XivDependencyGraph.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,25 @@ public static async Task<List<IItemModel>> GetSharedMaterialItems(this IItemMode
6767
var sameModelItems = new List<IItemModel>();
6868
sameModelItems = await item.GetSharedModelItems();
6969

70-
var imc = new Imc(XivCache.GameInfo.GameDirectory);
71-
var originalInfo = await imc.GetImcInfo(item);
72-
7370
var sameMaterialItems = new List<IItemModel>();
74-
foreach (var i in sameModelItems)
71+
try
7572
{
76-
var info = await imc.GetImcInfo(i);
77-
if (info.Variant == originalInfo.Variant)
73+
var imc = new Imc(XivCache.GameInfo.GameDirectory);
74+
var originalInfo = await imc.GetImcInfo(item);
75+
foreach (var i in sameModelItems)
7876
{
79-
sameMaterialItems.Add(i);
77+
var info = await imc.GetImcInfo(i);
78+
if (info.Variant == originalInfo.Variant)
79+
{
80+
sameMaterialItems.Add(i);
81+
}
8082
}
83+
} catch
84+
{
85+
// No IMC file exists for this item.
86+
// It is by requirement the only item of its type then.
87+
sameMaterialItems.Add((IItemModel) item.Clone());
8188
}
82-
8389
sameMaterialItems = sameMaterialItems.OrderBy(x => x.Name, new ItemNameComparer()).ToList();
8490
return sameMaterialItems;
8591
}

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,25 @@ public async Task<List<string>> GetTexturePathsFromMtrlPath(string mtrlPath, boo
275275
using (var br = new BinaryReader(new MemoryStream(mtrlData)))
276276
{
277277
// Texture count position.
278-
br.BaseStream.Seek(12, SeekOrigin.Begin);
278+
br.BaseStream.Seek(8, SeekOrigin.Begin);
279+
var materialDataSize = br.ReadUInt16();
280+
var pathsDataSize = br.ReadUInt16();
279281
var textureCount = br.ReadByte();
280282
var mapCount = br.ReadByte();
281283
var cSetCount = br.ReadByte();
284+
var dxInfoDataSize = br.ReadByte();
282285

283286
var offset = 0;
284287

285288
var dataOffsetBase = 16 + (mapCount * 4) + (cSetCount * 4) + (textureCount * 4);
286289

287-
290+
var textureDxInfo = new Dictionary<string, ushort>();
288291
for(int i = 0; i < textureCount; i++)
289292
{
290293
// Jump to the texture name offset.
291294
br.BaseStream.Seek(16 + offset, SeekOrigin.Begin);
292295
var textureNameOffset = br.ReadInt16();
296+
var texDxInfo = br.ReadUInt16();
293297

294298
// Jump to the texture name.
295299
br.BaseStream.Seek(dataOffsetBase + textureNameOffset, SeekOrigin.Begin);
@@ -308,11 +312,53 @@ public async Task<List<string>> GetTexturePathsFromMtrlPath(string mtrlPath, boo
308312
{
309313
uniqueTextures.Add(st);
310314
}
315+
textureDxInfo[st] = texDxInfo;
311316

312317
// Bump to next texture name offset.
313318
offset += 4;
314319
}
320+
321+
322+
if (dxInfoDataSize > 0)
323+
{
324+
var dxInfoOffset = dataOffsetBase + materialDataSize;
325+
br.BaseStream.Seek(dxInfoOffset, SeekOrigin.Begin);
326+
var dxInfoByte = br.ReadByte();
327+
328+
// This is an old DX9 Style material with DX11 conversion textures.
329+
// Make sure we have both texture versions referenced.
330+
if((dxInfoByte & 12) != 12)
331+
{
332+
List<string> add = new List<string>();
333+
foreach(var texture in uniqueTextures)
334+
{
335+
// If this is a texture that has a DX Conversion.
336+
if (textureDxInfo[texture] != 0)
337+
{
338+
if (texture.Contains("--"))
339+
{
340+
add.Add(texture.Replace("--", ""));
341+
}
342+
else
343+
{
344+
add.Add(texture.Insert(texture.LastIndexOf("/") + 1, "--"));
345+
}
346+
}
347+
else
348+
{
349+
// This texture does not have a DX 11 conversion texture.
350+
}
351+
}
352+
353+
foreach(var s in add)
354+
{
355+
uniqueTextures.Add(s);
356+
}
357+
}
358+
}
315359
}
360+
361+
316362
return uniqueTextures.ToList();
317363
}
318364

@@ -324,7 +370,6 @@ public async Task<List<string>> GetTexturePathsFromMtrlPath(string mtrlPath, boo
324370
/// <returns>XivMtrl containing all the mtrl data</returns>
325371
public async Task<XivMtrl> GetMtrlData(int mtrlOffset, string mtrlPath, int dxVersion)
326372
{
327-
await GetTexturePathsFromMtrlPath(mtrlPath);
328373
var dat = new Dat(_gameDirectory);
329374
var index = new Index(_gameDirectory);
330375

0 commit comments

Comments
 (0)