Skip to content

Commit 872329d

Browse files
committed
Update v2.3.4.9
2 parents aaf1398 + e7af911 commit 872329d

File tree

19 files changed

+1206
-260
lines changed

19 files changed

+1206
-260
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/DataContainers/XivMtrl.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class XivMtrl
6262
/// </remarks>
6363
public ushort ColorSetDataSize { get {
6464
var size = ColorSetData.Count * 2;
65-
size += ColorSetExtraData == null ? 0 : ColorSetExtraData.Length;
65+
size += ColorSetDyeData == null ? 0 : ColorSetDyeData.Length;
6666
return (ushort) size;
6767
} }
6868

@@ -168,7 +168,7 @@ public ushort ColorSetDataSize { get {
168168
/// <summary>
169169
/// The byte array containing the extra ColorSet data
170170
/// </summary>
171-
public byte[] ColorSetExtraData { get; set; }
171+
public byte[] ColorSetDyeData { get; set; }
172172

173173
/// <summary>
174174
/// The size of the additional MTRL Data
@@ -534,17 +534,17 @@ public void SetShaderInfo(ShaderInfo info, bool forced = false)
534534
// ColorSetCount seems to always be 1, even when the data is empty.
535535
ColorSetCount = 1;
536536
ColorSetData = new List<Half>();
537-
ColorSetExtraData = null;
537+
ColorSetDyeData = null;
538538
} else
539539
{
540540
if(ColorSetCount == 0 || ColorSetData == null || ColorSetData.Count != 256)
541541
{
542542
// Get default Colorset Data.
543543
ColorSetData = Tex.GetColorsetDataFromDDS(Tex.GetDefaultTexturePath(XivTexType.ColorSet));
544544
}
545-
if(ColorSetExtraData == null || ColorSetExtraData.Length != 32)
545+
if(ColorSetDyeData == null || ColorSetDyeData.Length != 32)
546546
{
547-
ColorSetExtraData = Tex.GetColorsetExtraDataFromDDS(Tex.GetDefaultTexturePath(XivTexType.ColorSet));
547+
ColorSetDyeData = Tex.GetColorsetExtraDataFromDDS(Tex.GetDefaultTexturePath(XivTexType.ColorSet));
548548
}
549549
}
550550

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 10 additions & 23 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 () =>
@@ -507,8 +494,10 @@ await Task.Run((Func<Task>)(async () =>
507494
.Replace("\0", "");
508495
var dx11FileName = Path.GetFileName(texturePath).Insert(0, "--");
509496

497+
if (String.IsNullOrEmpty(texturePath)) continue;
498+
510499
if (await index.FileExists(Path.GetDirectoryName(texturePath).Replace("\\", "/") + "/" + dx11FileName,
511-
DataFile))
500+
df))
512501
{
513502
texturePath = texturePath.Insert(texturePath.LastIndexOf("/") + 1, "--");
514503
}
@@ -542,7 +531,7 @@ await Task.Run((Func<Task>)(async () =>
542531
xivMtrl.Unknown2 = br.ReadBytes(xivMtrl.UnknownDataSize);
543532

544533
xivMtrl.ColorSetData = new List<Half>();
545-
xivMtrl.ColorSetExtraData = null;
534+
xivMtrl.ColorSetDyeData = null;
546535
if (colorSetDataSize > 0)
547536
{
548537
// Color Data is always 512 (6 x 14 = 64 x 8bpp = 512)
@@ -556,7 +545,7 @@ await Task.Run((Func<Task>)(async () =>
556545
// If the color set is 544 in length, it has an extra 32 bytes at the end
557546
if (colorSetDataSize == 544)
558547
{
559-
xivMtrl.ColorSetExtraData = br.ReadBytes(32);
548+
xivMtrl.ColorSetDyeData = br.ReadBytes(32);
560549
}
561550
}
562551

@@ -636,7 +625,6 @@ await Task.Run((Func<Task>)(async () =>
636625
}
637626
finally
638627
{
639-
_semaphoreSlim.Release();
640628
}
641629

642630
return xivMtrl;
@@ -681,7 +669,7 @@ public Task<XivTex> MtrlToXivTex(XivMtrl xivMtrl, TexTypePath ttp)
681669
/// <param name="race">The selected race for the item</param>
682670
public void SaveColorSetExtraData(IItem item, XivMtrl xivMtrl, DirectoryInfo saveDirectory, XivRace race)
683671
{
684-
var toWrite = xivMtrl.ColorSetExtraData != null ? xivMtrl.ColorSetExtraData : new byte[32];
672+
var toWrite = xivMtrl.ColorSetDyeData != null ? xivMtrl.ColorSetDyeData : new byte[32];
685673
var path = IOUtil.MakeItemSavePath(item, saveDirectory, race);
686674

687675
Directory.CreateDirectory(path);
@@ -868,7 +856,7 @@ public byte[] CreateMtrlFile(XivMtrl xivMtrl, IItem item)
868856

869857
if (xivMtrl.ColorSetDataSize == 544)
870858
{
871-
mtrlBytes.AddRange(xivMtrl.ColorSetExtraData);
859+
mtrlBytes.AddRange(xivMtrl.ColorSetDyeData);
872860
}
873861

874862

@@ -1181,7 +1169,6 @@ public static XivDependencyRootInfo GetHairMaterialRoot(XivDependencyRootInfo ro
11811169
}
11821170
public void Dipose()
11831171
{
1184-
_semaphoreSlim?.Dispose();
11851172
}
11861173

11871174
/// <summary>

xivModdingFramework/Materials/FileTypes/STM.cs

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using System.Text;
99
using System.Threading.Tasks;
1010
using xivModdingFramework.Cache;
11+
using xivModdingFramework.Exd.Enums;
12+
using xivModdingFramework.Exd.FileTypes;
1113
using xivModdingFramework.Items.DataContainers;
1214
using xivModdingFramework.Mods;
1315
using xivModdingFramework.Mods.DataContainers;
@@ -40,6 +42,7 @@ public static async Task<StainingTemplateFile> GetStainingTemplateFile(bool forc
4042

4143
public static async Task SaveStainingTemplateFile(StainingTemplateFile file, string applicationSource, IndexFile index = null, ModList modlist = null)
4244
{
45+
throw new NotImplementedException();
4346
var data = new byte[0];//file.GetBytes();
4447

4548
var _dat = new Dat(XivCache.GameInfo.GameDirectory);
@@ -53,6 +56,40 @@ public static async Task SaveStainingTemplateFile(StainingTemplateFile file, str
5356
await _dat.ImportType2Data(data, GearStainingTemplatePath, applicationSource, null, index, modlist);
5457

5558
}
59+
public static async Task<Dictionary<int, string>> GetDyeNames()
60+
{
61+
62+
var lang = XivCache.GameInfo.GameLanguage;
63+
if (lang == General.Enums.XivLanguage.None)
64+
{
65+
lang = General.Enums.XivLanguage.English;
66+
}
67+
68+
Dictionary<int, string> Dyes = new Dictionary<int, string>();
69+
70+
var ex = new Ex(XivCache.GameInfo.GameDirectory, lang);
71+
var exData = await ex.ReadExData(XivEx.stain);
72+
73+
74+
var dataLength = exData[0].Length - 2;
75+
76+
foreach (var kv in exData)
77+
{
78+
if (kv.Key == 0) continue;
79+
80+
var size = kv.Value.Length - dataLength;
81+
var name = Encoding.UTF8.GetString(kv.Value, dataLength, size).Replace("\0", "");
82+
var dyeId = kv.Key - 1;
83+
if (String.IsNullOrEmpty(name)) {
84+
name = "Dye " + dyeId.ToString();
85+
}
86+
87+
Dyes.Add(dyeId, name);
88+
}
89+
90+
91+
return Dyes;
92+
}
5693
}
5794

5895
public enum StainingTemplateArrayType
@@ -64,19 +101,11 @@ public enum StainingTemplateArrayType
64101

65102
public class StainingTemplateEntry
66103
{
67-
public int Size
68-
{
69-
get
70-
{
71-
return 0;
72-
}
73-
}
74-
75-
List<Half[]> DiffuseEntries = new List<Half[]>();
76-
List<Half[]> SpecularEntries = new List<Half[]>();
77-
List<Half[]> EmissiveEntries = new List<Half[]>();
78-
List<Half> TileMaterialEntries = new List<Half>();
79-
List<Half> GlossEntries = new List<Half>();
104+
public readonly List<Half[]> DiffuseEntries = new List<Half[]>();
105+
public readonly List<Half[]> SpecularEntries = new List<Half[]>();
106+
public readonly List<Half[]> EmissiveEntries = new List<Half[]>();
107+
public readonly List<Half> SpecularPowerEntries = new List<Half>();
108+
public readonly List<Half> GlossEntries = new List<Half>();
80109

81110
public StainingTemplateEntry(byte[] data, int offset)
82111
{
@@ -140,7 +169,7 @@ public StainingTemplateEntry(byte[] data, int offset)
140169

141170
Half[] halfs = new Half[3];
142171

143-
var elementStart = offsetStart + (i * 2);
172+
var elementStart = offsetStart + ((i * 2) * elementSize);
144173

145174
var reversed = new byte[] { data[elementStart + 1], data[elementStart] };
146175
var test = new Half(BitConverter.ToUInt16(reversed, 0));
@@ -157,22 +186,32 @@ public StainingTemplateEntry(byte[] data, int offset)
157186
if(type == StainingTemplateArrayType.Indexed)
158187
{
159188
var nArray = new List<Half[]>();
189+
var indexes = new byte[128];
160190
for (int i = 0; i < 128; i++)
161191
{
162-
var index = data[indexStart + i];
163-
var entry = new Half[3];
164-
if (index == 255)
192+
try
165193
{
166-
nArray.Add(new Half[] { new Half(), new Half(), new Half() } );
167-
continue;
168-
}
169-
170-
if(index == 0)
194+
var index = data[indexStart + i + 1];
195+
var entry = new Half[3];
196+
if (index > halfData.Count)
197+
{
198+
nArray.Add(new Half[] { new Half(), new Half(), new Half() });
199+
continue;
200+
}
201+
202+
if (index == 0)
203+
{
204+
nArray.Add(new Half[] { new Half(), new Half(), new Half() });
205+
continue;
206+
}
207+
208+
index -= 1;
209+
210+
nArray.Add(halfData[index]);
211+
} catch(Exception ex)
171212
{
172-
nArray.Add(new Half[] { new Half(), new Half(), new Half() });
173-
continue;
213+
throw;
174214
}
175-
nArray.Add(halfData[index - 1]);
176215
}
177216

178217
halfData = nArray;
@@ -204,11 +243,11 @@ public StainingTemplateEntry(byte[] data, int offset)
204243
}
205244
else if (x == 3)
206245
{
207-
TileMaterialEntries.Add(arr[0]);
246+
GlossEntries.Add(arr[0]);
208247
}
209248
else if (x == 4)
210249
{
211-
GlossEntries.Add(arr[0]);
250+
SpecularPowerEntries.Add(arr[0]);
212251
}
213252
}
214253

@@ -243,7 +282,11 @@ public void SetTemplate(ushort key, StainingTemplateEntry entry)
243282
}
244283
public StainingTemplateEntry GetTemplate(ushort key)
245284
{
246-
return Templates[key];
285+
if (Templates.ContainsKey(key))
286+
{
287+
return Templates[key];
288+
}
289+
return null;
247290
}
248291
public StainingTemplateFile(byte[] data)
249292
{
@@ -283,5 +326,6 @@ public StainingTemplateFile(byte[] data)
283326
}
284327

285328

329+
286330
}
287331
}

xivModdingFramework/Models/DataContainers/MdlModelData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class MdlModelData
7878
/// <summary>
7979
/// The total number of indices that the mesh shapes uses
8080
/// </summary>
81-
public short ShapeDataCount { get; set; }
81+
public ushort ShapeDataCount { get; set; }
8282

8383
/// <summary>
8484
/// Unknown Usage

0 commit comments

Comments
 (0)