Skip to content

Commit 4fdc943

Browse files
committed
Update 2.3.0.3
2 parents 7a8cfc2 + b1d00bd commit 4fdc943

File tree

8 files changed

+249
-70
lines changed

8 files changed

+249
-70
lines changed

xivModdingFramework/Cache/XivCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static class XivCache
2929
private static GameInfo _gameInfo;
3030
private static DirectoryInfo _dbPath;
3131
private static DirectoryInfo _rootCachePath;
32-
public static readonly Version CacheVersion = new Version("1.0.1.6");
32+
public static readonly Version CacheVersion = new Version("1.0.2.0");
3333
private const string dbFileName = "mod_cache.db";
3434
private const string rootCacheFileName = "item_sets.db";
3535
private const string creationScript = "CreateCacheDB.sql";

xivModdingFramework/Cache/XivDependencyGraph.cs

Lines changed: 139 additions & 68 deletions
Large diffs are not rendered by default.

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ public async Task<XivMtrl> GetMtrlData(string mtrlFile, int materialSet = -1, in
276276

277277
mtrlOffset = await index.GetDataOffset(mtrlPath);
278278

279+
if(mtrlOffset == 0)
280+
{
281+
return null;
282+
}
283+
279284
var mtrlData = await GetMtrlData(mtrlOffset, mtrlPath, dxVersion);
280285

281286
return mtrlData;

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,11 @@ public void SetFullModelDBMetaData(string filePath, string fullModelName)
15571557
/// <returns></returns>
15581558
public static TTModel FromRaw(XivMdl rawMdl, Action<bool, string> loggingFunction = null)
15591559
{
1560+
if(rawMdl == null)
1561+
{
1562+
return null;
1563+
}
1564+
15601565
if (loggingFunction == null)
15611566
{
15621567
loggingFunction = ModelModifiers.NoOp;

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public async Task<XivMdl> GetRawMdlData(string mdlPath, bool getOriginal = false
433433

434434
if (offset == 0)
435435
{
436-
throw new Exception($"Could not find offset for {mdlPath}");
436+
return null;
437437
}
438438

439439
var mdlData = await dat.GetType3Data(offset, _dataFile);

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,48 @@ public static void ApplyRacialDeform(TTModel model, XivRace targetRace, bool inv
10931093
v.Tangent = tangent;
10941094
}
10951095
}
1096+
1097+
// Same thing, but for the Shape Data parts.
1098+
foreach(var p in m.ShapeParts)
1099+
{
1100+
foreach(var v in p.Vertices)
1101+
{
1102+
Vector3 position = Vector3.Zero;
1103+
Vector3 normal = Vector3.Zero;
1104+
Vector3 binormal = Vector3.Zero;
1105+
Vector3 tangent = Vector3.Zero;
1106+
1107+
// And each bone in that vertex.
1108+
for (var b = 0; b < 4; b++)
1109+
{
1110+
if (v.Weights[b] == 0) continue;
1111+
var boneName = m.Bones[v.BoneIds[b]];
1112+
var boneWeight = (v.Weights[b]) / 255f;
1113+
1114+
var matrix = Matrix.Identity;
1115+
var normalMatrix = Matrix.Identity;
1116+
matrix = deformations[boneName];
1117+
normalMatrix = normalmatrixes[boneName];
1118+
1119+
if (invert)
1120+
{
1121+
matrix = inverted[boneName];
1122+
normalMatrix = invertednormalmatrixes[boneName];
1123+
}
1124+
1125+
1126+
position += MatrixTransform(v.Position, matrix) * boneWeight;
1127+
normal += MatrixTransform(v.Normal, normalMatrix) * boneWeight;
1128+
binormal += MatrixTransform(v.Binormal, normalMatrix) * boneWeight;
1129+
tangent += MatrixTransform(v.Tangent, normalMatrix) * boneWeight;
1130+
}
1131+
1132+
v.Position = position;
1133+
v.Normal = normal;
1134+
v.Binormal = binormal;
1135+
v.Tangent = tangent;
1136+
}
1137+
}
10961138
}
10971139
}
10981140
catch(Exception ex)
@@ -1287,6 +1329,7 @@ public static void CalculateTangents(TTModel model, Action<bool, string> logging
12871329
{
12881330
loggingFunction = NoOp;
12891331
}
1332+
if (model == null) return;
12901333

12911334
loggingFunction(false, "Calculating Tangents...");
12921335
var hasTangents = model.MeshGroups.Any(x => x.Parts.Any(x => x.Vertices.Any(x => x.Tangent != Vector3.Zero)));

xivModdingFramework/Models/ModelTextures/ModelTexture.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class CustomModelColors
5656
// Optional values.
5757
public Color? HairHighlightColor;
5858

59+
public bool InvertNormalGreen = false;
60+
5961

6062

6163
// One for each colorset row. Null for undyed.
@@ -75,6 +77,7 @@ public CustomModelColors()
7577
FurnitureColor = new Color(141, 60, 204, 255);
7678

7779
HairHighlightColor = new Color(77, 126, 240, 255);
80+
InvertNormalGreen = false;
7881

7982
DyeColors = new List<Color?>(16);
8083
for(int i = 0; i < 16; i++)
@@ -211,6 +214,11 @@ await Task.Run(() =>
211214
baseSpecularColor = new Color(specularPixels[i - 3], specularPixels[i - 2], specularPixels[i - 1], specularPixels[i]);
212215
}
213216

217+
if(colors != null && colors.InvertNormalGreen)
218+
{
219+
baseNormalColor[1] = (byte)(255 - baseNormalColor[1]);
220+
}
221+
214222
byte colorsetValue = baseNormalColor.A;
215223

216224
// Calculate real colors from the inputs and shader.

xivModdingFramework/SqPack/FileTypes/Index.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,53 @@ await Task.Run(() =>
985985
return fileHashesList;
986986
}
987987

988+
/// <summary>
989+
/// Gets the entire universe of hash pairs (folder, file) for a datafile.
990+
/// </summary>
991+
public async Task<Dictionary<int, HashSet<int>>> GetAllHashes(XivDataFile dataFile)
992+
{
993+
var ret = new Dictionary<int, HashSet<int>>();
994+
995+
// These are the offsets to relevant data
996+
const int fileCountOffset = 1036;
997+
const int dataStartOffset = 2048;
998+
999+
var indexPath = Path.Combine(_gameDirectory.FullName, $"{dataFile.GetDataFileName()}{IndexExtension}");
1000+
1001+
await _semaphoreSlim.WaitAsync();
1002+
try
1003+
{
1004+
await Task.Run(() =>
1005+
{
1006+
using (var br = new BinaryReader(File.OpenRead(indexPath)))
1007+
{
1008+
br.BaseStream.Seek(fileCountOffset, SeekOrigin.Begin);
1009+
var totalFiles = br.ReadInt32();
1010+
1011+
br.BaseStream.Seek(dataStartOffset, SeekOrigin.Begin);
1012+
for (var i = 0; i < totalFiles; i += 16)
1013+
{
1014+
var hashedFile = br.ReadInt32();
1015+
var folderPathHash = br.ReadInt32();
1016+
if(!ret.ContainsKey(folderPathHash))
1017+
{
1018+
ret.Add(folderPathHash, new HashSet<int>());
1019+
}
1020+
ret[folderPathHash].Add(hashedFile);
1021+
1022+
br.ReadBytes(4);
1023+
br.ReadBytes(4);
1024+
}
1025+
}
1026+
});
1027+
}
1028+
finally
1029+
{
1030+
_semaphoreSlim.Release();
1031+
}
1032+
return ret;
1033+
}
1034+
9881035
/// <summary>
9891036
/// Get all the file hash and file offset in a given folder
9901037
/// </summary>

0 commit comments

Comments
 (0)