@@ -275,21 +275,25 @@ public async Task<List<string>> GetTexturePathsFromMtrlPath(string mtrlPath, boo
275
275
using ( var br = new BinaryReader ( new MemoryStream ( mtrlData ) ) )
276
276
{
277
277
// 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 ( ) ;
279
281
var textureCount = br . ReadByte ( ) ;
280
282
var mapCount = br . ReadByte ( ) ;
281
283
var cSetCount = br . ReadByte ( ) ;
284
+ var dxInfoDataSize = br . ReadByte ( ) ;
282
285
283
286
var offset = 0 ;
284
287
285
288
var dataOffsetBase = 16 + ( mapCount * 4 ) + ( cSetCount * 4 ) + ( textureCount * 4 ) ;
286
289
287
-
290
+ var textureDxInfo = new Dictionary < string , ushort > ( ) ;
288
291
for ( int i = 0 ; i < textureCount ; i ++ )
289
292
{
290
293
// Jump to the texture name offset.
291
294
br . BaseStream . Seek ( 16 + offset , SeekOrigin . Begin ) ;
292
295
var textureNameOffset = br . ReadInt16 ( ) ;
296
+ var texDxInfo = br . ReadUInt16 ( ) ;
293
297
294
298
// Jump to the texture name.
295
299
br . BaseStream . Seek ( dataOffsetBase + textureNameOffset , SeekOrigin . Begin ) ;
@@ -308,11 +312,53 @@ public async Task<List<string>> GetTexturePathsFromMtrlPath(string mtrlPath, boo
308
312
{
309
313
uniqueTextures . Add ( st ) ;
310
314
}
315
+ textureDxInfo [ st ] = texDxInfo ;
311
316
312
317
// Bump to next texture name offset.
313
318
offset += 4 ;
314
319
}
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
+ }
315
359
}
360
+
361
+
316
362
return uniqueTextures . ToList ( ) ;
317
363
}
318
364
@@ -324,7 +370,6 @@ public async Task<List<string>> GetTexturePathsFromMtrlPath(string mtrlPath, boo
324
370
/// <returns>XivMtrl containing all the mtrl data</returns>
325
371
public async Task < XivMtrl > GetMtrlData ( int mtrlOffset , string mtrlPath , int dxVersion )
326
372
{
327
- await GetTexturePathsFromMtrlPath ( mtrlPath ) ;
328
373
var dat = new Dat ( _gameDirectory ) ;
329
374
var index = new Index ( _gameDirectory ) ;
330
375
0 commit comments