Skip to content

Commit b2b12ef

Browse files
committed
Update v3.0.7.3
2 parents ee7183f + 440398b commit b2b12ef

File tree

8 files changed

+138
-26
lines changed

8 files changed

+138
-26
lines changed

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,13 @@ public static byte[] XivMtrlToUncompressedMtrl(XivMtrl xivMtrl)
659659
}
660660
if (xivMtrl.ColorSetData != null && xivMtrl.ColorSetData.Count > 0)
661661
{
662-
xivMtrl.AdditionalData[0] |= 0x04;
662+
//xivMtrl.AdditionalData[0] |= 0x04;
663663
}
664664
else
665665
{
666666
unchecked
667667
{
668-
xivMtrl.AdditionalData[0] &= (byte)(~0x04);
668+
//xivMtrl.AdditionalData[0] &= (byte)(~0x04);
669669
}
670670
}
671671

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ private static void MigrateImportDb(SQLiteConnection db)
16961696
/// </summary>
16971697
/// <param name="filePath"></param>
16981698
/// <param name="loggingFunction"></param>
1699-
public void SaveToFile(string filePath, string texturePath = null, Action<bool, string> loggingFunction = null)
1699+
public void SaveToFile(string filePath, string texturePath = null, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
17001700
{
17011701
if (loggingFunction == null)
17021702
{
@@ -1722,7 +1722,7 @@ public void SaveToFile(string filePath, string texturePath = null, Action<bool,
17221722
var boneDict = new Dictionary<string, SkeletonData>();
17231723
if (IsInternal && Bones.Count > 0)
17241724
{
1725-
boneDict = ResolveBoneHeirarchy(null, XivRace.All_Races, bones, loggingFunction);
1725+
boneDict = ResolveBoneHeirarchy(null, XivRace.All_Races, bones, loggingFunction, tx);
17261726
} else if(Bones.Count > 0)
17271727
{
17281728
var i = 0;
@@ -1993,7 +1993,7 @@ public void SaveToFile(string filePath, string texturePath = null, Action<bool,
19931993
ModelModifiers.MakeImportReady(this, loggingFunction);
19941994
}
19951995

1996-
public static Dictionary<string, SkeletonData> ResolveFullBoneHeirarchy(XivRace race, List<string> models, Action<bool, string> loggingFunction = null)
1996+
public static Dictionary<string, SkeletonData> ResolveFullBoneHeirarchy(XivRace race, List<string> models, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
19971997
{
19981998
if (loggingFunction == null)
19991999
{
@@ -2090,7 +2090,7 @@ public static Dictionary<string, SkeletonData> ResolveFullBoneHeirarchy(XivRace
20902090
rootsToResolve.Add(root);
20912091
}
20922092

2093-
var boneDict = TTModel.ResolveBoneHeirarchyRaw(rootsToResolve, race, null, loggingFunction);
2093+
var boneDict = TTModel.ResolveBoneHeirarchyRaw(rootsToResolve, race, null, loggingFunction, tx);
20942094
return boneDict;
20952095
}
20962096

@@ -2099,7 +2099,7 @@ public static Dictionary<string, SkeletonData> ResolveFullBoneHeirarchy(XivRace
20992099
/// </summary>
21002100
/// <param name="filePath"></param>
21012101
/// <param name="loggingFunction"></param>
2102-
public static void SaveFullToFile(string filePath, XivRace race, List<TTModel> models, Action<bool, string> loggingFunction = null)
2102+
public static void SaveFullToFile(string filePath, XivRace race, List<TTModel> models, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
21032103
{
21042104
if (loggingFunction == null)
21052105
{
@@ -2114,7 +2114,7 @@ public static void SaveFullToFile(string filePath, XivRace race, List<TTModel> m
21142114
paths.Add(m.Source);
21152115
}
21162116

2117-
var boneDict = ResolveFullBoneHeirarchy(race, paths, loggingFunction);
2117+
var boneDict = ResolveFullBoneHeirarchy(race, paths, loggingFunction, tx);
21182118

21192119

21202120

@@ -2400,7 +2400,7 @@ public static void SaveFullToFile(string filePath, XivRace race, List<TTModel> m
24002400
private static void WriteVertex(TTVertex v, SQLiteConnection db, int meshIdx, int partIdx, int vIdx)
24012401
{
24022402
var query = @"insert into vertices ( mesh, part, vertex_id, position_x, position_y, position_z, normal_x, normal_y, normal_z, binormal_x, binormal_y, binormal_z, tangent_x, tangent_y, tangent_z, color_r, color_g, color_b, color_a, color2_r, color2_g, color2_b, color2_a, uv_1_u, uv_1_v, uv_2_u, uv_2_v, bone_1_id, bone_1_weight, bone_2_id, bone_2_weight, bone_3_id, bone_3_weight, bone_4_id, bone_4_weight, bone_5_id, bone_5_weight, bone_6_id, bone_6_weight, bone_7_id, bone_7_weight, bone_8_id, bone_8_weight, uv_3_u, uv_3_v)
2403-
values ($mesh, $part, $vertex_id, $position_x, $position_y, $position_z, $normal_x, $normal_y, $normal_z, $binormal_x, $binormal_y, $binormal_z, $tangent_x, $tangent_y, $tangent_z, $color_r, $color_g, $color_b, $color2_a, $color2_r, $color2_g, $color2_b, $color2_a, $uv_1_u, $uv_1_v, $uv_2_u, $uv_2_v, $bone_1_id, $bone_1_weight, $bone_2_id, $bone_2_weight, $bone_3_id, $bone_3_weight, $bone_4_id, $bone_4_weight, $bone_5_id, $bone_5_weight, $bone_6_id, $bone_6_weight, $bone_7_id, $bone_7_weight, $bone_8_id, $bone_8_weight, $uv_3_u, $uv_3_v);";
2403+
values ($mesh, $part, $vertex_id, $position_x, $position_y, $position_z, $normal_x, $normal_y, $normal_z, $binormal_x, $binormal_y, $binormal_z, $tangent_x, $tangent_y, $tangent_z, $color_r, $color_g, $color_b, $color_a, $color2_r, $color2_g, $color2_b, $color2_a, $uv_1_u, $uv_1_v, $uv_2_u, $uv_2_v, $bone_1_id, $bone_1_weight, $bone_2_id, $bone_2_weight, $bone_3_id, $bone_3_weight, $bone_4_id, $bone_4_weight, $bone_5_id, $bone_5_weight, $bone_6_id, $bone_6_weight, $bone_7_id, $bone_7_weight, $bone_8_id, $bone_8_weight, $uv_3_u, $uv_3_v);";
24042404
using (var cmd = new SQLiteCommand(query, db))
24052405
{
24062406
cmd.Parameters.AddWithValue("part", partIdx);
@@ -2628,7 +2628,7 @@ private static float[] NewIdentityMatrix()
26282628
return arr;
26292629
}
26302630

2631-
public Dictionary<string, SkeletonData> ResolveBoneHeirarchy(List<XivDependencyRootInfo> roots = null, XivRace race = XivRace.All_Races, List<string> bones = null, Action<bool, string> loggingFunction = null)
2631+
public Dictionary<string, SkeletonData> ResolveBoneHeirarchy(List<XivDependencyRootInfo> roots = null, XivRace race = XivRace.All_Races, List<string> bones = null, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
26322632
{
26332633
if (roots == null || roots.Count == 0)
26342634
{
@@ -2651,7 +2651,7 @@ public Dictionary<string, SkeletonData> ResolveBoneHeirarchy(List<XivDependencyR
26512651
roots = new List<XivDependencyRootInfo>() { root };
26522652
}
26532653

2654-
return TTModel.ResolveBoneHeirarchyRaw(roots, race, bones, loggingFunction);
2654+
return TTModel.ResolveBoneHeirarchyRaw(roots, race, bones, loggingFunction, tx);
26552655
}
26562656
/// <summary>
26572657
/// Resolves the full bone heirarchy necessary to animate this TTModel.
@@ -2661,7 +2661,7 @@ public Dictionary<string, SkeletonData> ResolveBoneHeirarchy(List<XivDependencyR
26612661
/// This is niche enough to leave for the moment and come back to if it proves an issue.
26622662
/// </summary>
26632663
/// <returns></returns>
2664-
public static Dictionary<string, SkeletonData> ResolveBoneHeirarchyRaw(List<XivDependencyRootInfo> roots, XivRace race, List<string> bones = null, Action<bool, string> loggingFunction = null)
2664+
public static Dictionary<string, SkeletonData> ResolveBoneHeirarchyRaw(List<XivDependencyRootInfo> roots, XivRace race, List<string> bones = null, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
26652665
{
26662666
if (loggingFunction == null)
26672667
{
@@ -2704,7 +2704,7 @@ public static Dictionary<string, SkeletonData> ResolveBoneHeirarchyRaw(List<XivD
27042704
}
27052705

27062706

2707-
extraSkeletonPath = await Sklb.GetExtraSkeletonFile(root, race);
2707+
extraSkeletonPath = await Sklb.GetExtraSkeletonFile(root, race, tx);
27082708
// Did this root have an extra skeleton in use?
27092709
if (!String.IsNullOrEmpty(extraSkeletonPath))
27102710
{

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,40 @@ public static XivMdl GetXivMdl(byte[] mdlData, string mdlPath = "")
11301130
}
11311131

11321132

1133+
internal static List<Vector4> ReadBoundingBox(BinaryReader br)
1134+
{
1135+
var ret = new List<Vector4>();
1136+
1137+
ret.Add(new Vector4(
1138+
br.ReadSingle(),
1139+
br.ReadSingle(),
1140+
br.ReadSingle(),
1141+
br.ReadSingle()
1142+
));
1143+
1144+
ret.Add(new Vector4(
1145+
br.ReadSingle(),
1146+
br.ReadSingle(),
1147+
br.ReadSingle(),
1148+
br.ReadSingle()
1149+
));
1150+
1151+
return ret;
1152+
}
1153+
internal static void WriteBoundingBox(BinaryWriter bw, List<Vector4> bb)
1154+
{
1155+
bw.Write(BitConverter.GetBytes(bb[0][0]));
1156+
bw.Write(BitConverter.GetBytes(bb[0][1]));
1157+
bw.Write(BitConverter.GetBytes(bb[0][2]));
1158+
bw.Write(BitConverter.GetBytes(bb[0][3]));
1159+
1160+
bw.Write(BitConverter.GetBytes(bb[1][0]));
1161+
bw.Write(BitConverter.GetBytes(bb[1][1]));
1162+
bw.Write(BitConverter.GetBytes(bb[1][2]));
1163+
bw.Write(BitConverter.GetBytes(bb[1][3]));
1164+
}
1165+
1166+
11331167
/// <summary>
11341168
/// Extracts and calculates the full MTRL paths from a given MDL file.
11351169
/// A material variant of -1 gets the materials for ALL variants,
@@ -1438,7 +1472,7 @@ public static async Task ExportTTModelToFile(TTModel model, string outputFilePat
14381472
var converterFolder = cwd + "\\converters\\" + fileFormat;
14391473
Directory.CreateDirectory(converterFolder);
14401474
var dbPath = converterFolder + "\\input.db";
1441-
model.SaveToFile(dbPath, outputFilePath);
1475+
model.SaveToFile(dbPath, outputFilePath, null, tx);
14421476

14431477

14441478
if (fileFormat == "db")
@@ -2567,12 +2601,13 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
25672601
// Optional/Situational Elements
25682602
if (upgradePrecision)
25692603
{
2604+
/*
25702605
AddVertexHeader(source, new VertexDataStruct()
25712606
{
25722607
DataBlock = 1,
25732608
DataType = VertexDataType.Ubyte4n,
25742609
DataUsage = VertexUsageType.Tangent
2575-
});
2610+
});*/
25762611
}
25772612

25782613
AddVertexHeader(source, new VertexDataStruct()
@@ -3934,7 +3969,7 @@ private static bool WriteVectorData(List<byte> buffer, Dictionary<VertexUsageTyp
39343969
break;
39353970
case VertexUsageType.Tangent:
39363971
value = v.Tangent;
3937-
handedness = !v.Handedness;
3972+
handedness = v.Handedness;
39383973
break;
39393974
default:
39403975
return false;

xivModdingFramework/Models/FileTypes/Sklb.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static List<SkeletonData> GetParents(SkeletonData bone, List<SkeletonData
128128
/// </summary>
129129
/// <param name="fullMdlPath"></param>
130130
/// <returns></returns>
131-
public static async Task<string> GetExtraSkeletonFile(string fullMdlPath)
131+
public static async Task<string> GetExtraSkeletonFile(string fullMdlPath, ModTransaction tx = null)
132132
{
133133
var root = await XivCache.GetFirstRoot(fullMdlPath);
134134

@@ -138,7 +138,7 @@ public static async Task<string> GetExtraSkeletonFile(string fullMdlPath)
138138
// This is a hair/hat/face/body model at this point so this is a safe pull.
139139
var race = XivRaces.GetXivRace(fullMdlPath.Substring(1, 4));
140140

141-
return await GetExtraSkeletonFile(root.Info, race);
141+
return await GetExtraSkeletonFile(root.Info, race, tx);
142142

143143
}
144144

@@ -160,7 +160,7 @@ public static async Task<string> GetExtraSkeletonFile(XivDependencyRootInfo root
160160
root = nRoot;
161161
}
162162

163-
var file = await GetExtraSkelbPath(root, race);
163+
var file = await GetExtraSkelbPath(root, race, tx);
164164
if (file == null) return null;
165165

166166
var skelName = Path.GetFileNameWithoutExtension(file).Replace("skl_", "");
@@ -315,7 +315,7 @@ private static async Task<string> ConvertSkelToXml(string rawFile)
315315
return originalXml;
316316
}
317317

318-
private static async Task<string> GetExtraSkelbPath(XivDependencyRootInfo root, XivRace race = XivRace.All_Races)
318+
private static async Task<string> GetExtraSkelbPath(XivDependencyRootInfo root, XivRace race = XivRace.All_Races, ModTransaction tx = null)
319319
{
320320

321321
var type = Est.GetEstType(root);
@@ -338,7 +338,7 @@ private static async Task<string> GetExtraSkelbPath(XivDependencyRootInfo root,
338338
}
339339

340340

341-
var entry = await Est.GetExtraSkeletonEntry(type, race, id);
341+
var entry = await Est.GetExtraSkeletonEntry(type, race, id, false, tx);
342342
var skelId = entry.SkelId;
343343
if(skelId == 0)
344344
{
@@ -355,7 +355,7 @@ private static async Task<string> GetExtraSkelbPath(XivDependencyRootInfo root,
355355

356356
// It's worth noting in these cases, the Skeletal bones themselves will still be using the matrices appropriate
357357
// for their parent race in this method, but that should be sufficient for now.
358-
return await GetExtraSkelbPath(root, parent.Race);
358+
return await GetExtraSkelbPath(root, parent.Race, tx);
359359
}
360360

361361
var prefix = Est.GetSystemPrefix(type);

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
12451245
if (missingDeforms.Any())
12461246
{
12471247
// Get the skeleton for this model so we can use it to analyze missing bones.
1248-
var dict = model.ResolveBoneHeirarchy(null, XivRace.All_Races, null, loggingFunction);
1248+
var dict = model.ResolveBoneHeirarchy(null, XivRace.All_Races, null, loggingFunction, tx);
12491249

12501250

12511251
// For a bone to be missing in the deformation data completely, it has to have come from a different skeleton, which

xivModdingFramework/Mods/EndwalkerUpgrade.cs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ public struct UpgradeInfo
5555

5656
private const string _SampleHair = "chara/human/c0801/obj/hair/h0115/material/v0001/mt_c0801h0115_hir_a.mtrl";
5757

58+
public static async Task AssertIsDawntrail(ModTransaction tx = null)
59+
{
60+
if(tx == null)
61+
{
62+
tx = ModTransaction.BeginReadonlyTransaction();
63+
}
64+
65+
if(!await tx.FileExists(Eqp.DawntrailTestFile, true))
66+
{
67+
throw new InvalidDataException("The currently set FFXIV Directory is not a Dawntrail install.");
68+
}
69+
}
70+
5871
/// <summary>
5972
/// Performs Endwalker => Dawntrail Upgrades on an arbitrary set of internal files as part of a transaction.
6073
/// This is used primarily during Modpack installs.
@@ -69,6 +82,7 @@ public struct UpgradeInfo
6982
/// <returns></returns>
7083
public static async Task<Dictionary<string, UpgradeInfo>> UpdateEndwalkerFiles(IEnumerable<string> paths, string sourceApplication, bool includePartials = true, IProgress<(int current, int total, string message)> progress = null, ModTransaction tx = null)
7184
{
85+
await AssertIsDawntrail();
7286
var filePaths = new HashSet<string>(paths);
7387
var ret = new Dictionary<string, UpgradeInfo>();
7488

@@ -136,6 +150,7 @@ public static async Task<Dictionary<string, UpgradeInfo>> UpdateEndwalkerFiles(I
136150
/// <returns></returns>
137151
public static async Task<Dictionary<string, UpgradeInfo>> UpdateEndwalkerFiles(Dictionary<string, FileStorageInformation> files, IProgress<(int current, int total, string message)> progress = null)
138152
{
153+
await AssertIsDawntrail();
139154
var ret = new Dictionary<string, UpgradeInfo>();
140155

141156
HashSet<string> _ConvertedTextures = new HashSet<string>();
@@ -406,13 +421,57 @@ private static bool FastMdlv6Upgrade(BinaryReader br, BinaryWriter bw, long offs
406421
idx++;
407422
}
408423

409-
var end = bonesetStart + boneSetSize;
424+
// Net size of old bone sets
425+
var end = bonesetStart + (((64 * 2) + 4) * mdlData.BoneSetCount);
410426
while(bw.BaseStream.Position < end)
411427
{
412428
// Fill out the remainder of the block with 0s.
413429
bw.Write((byte)0);
414430
}
415431

432+
var endOfBoneSet = bw.BaseStream.Position;
433+
434+
// Shape Data is next.
435+
var shpCount = mdlData.ShapeCount;
436+
var shpParts = mdlData.ShapePartCount;
437+
var shpIndices = mdlData.ShapeDataCount;
438+
439+
var endOfShapeHeaders = endOfBoneSet + (shpCount * 16);
440+
var endOfShapePartHeaders = endOfShapeHeaders + (shpParts * 12);
441+
var endOfShapeIndices = endOfShapePartHeaders + (shpIndices * 4);
442+
443+
// Part Bone Sets
444+
br.BaseStream.Seek(endOfShapeIndices, SeekOrigin.Begin);
445+
var partBoneSets = br.ReadInt32();
446+
var endOfPartBones = br.BaseStream.Position + (partBoneSets);
447+
448+
// Padding
449+
br.BaseStream.Seek(endOfPartBones, SeekOrigin.Begin);
450+
var padding = br.ReadByte();
451+
br.BaseStream.Seek(br.BaseStream.Position + padding, SeekOrigin.Begin);
452+
453+
// Bounding Boxes
454+
var baseBox = Mdl.ReadBoundingBox(br);
455+
var mdlBox = Mdl.ReadBoundingBox(br);
456+
var waterBox = Mdl.ReadBoundingBox(br);
457+
var shadowBox = Mdl.ReadBoundingBox(br);
458+
459+
const float _Divisor = 20.0f;
460+
var min = -1 * (mdlData.Radius / _Divisor);
461+
var max = (mdlData.Radius / _Divisor);
462+
var bb = new List<Vector4>()
463+
{
464+
new Vector4(min, min, min, 1.0f),
465+
new Vector4(max, max, max, 1.0f),
466+
};
467+
468+
// Write new bone bounding boxes.
469+
bw.BaseStream.Seek(br.BaseStream.Position, SeekOrigin.Begin);
470+
for(int i = 0; i < mdlData.BoneCount; i++)
471+
{
472+
Mdl.WriteBoundingBox(bw, bb);
473+
}
474+
416475
return true;
417476
}
418477

@@ -1068,6 +1127,7 @@ private static async Task<Dictionary<string, UpgradeInfo>> UpdateEndwalkerHairMa
10681127
var constantBase = await Mtrl.GetXivMtrl(_SampleHair, true, tx);
10691128
var originalConsts = mtrl.ShaderConstants;
10701129
mtrl.ShaderConstants = constantBase.ShaderConstants;
1130+
mtrl.AdditionalData = constantBase.AdditionalData;
10711131

10721132
// Copy the alpha threshold over since the functionality there is unchanged.
10731133
var alpha = originalConsts.FirstOrDefault(x => x.ConstantId == 0x29AC0223);

xivModdingFramework/Mods/FileTypes/PMP.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,17 @@ public static async Task WritePmp(PMPJson pmp, string workingDirectory, string z
779779
var metapath = Path.Combine(workingDirectory, "meta.json");
780780
var defaultModPath = Path.Combine(workingDirectory, "default_mod.json");
781781

782-
if(pmp.Meta.ModTags == null)
782+
783+
var oldJsons = Directory.EnumerateFiles(workingDirectory, "*.json", SearchOption.TopDirectoryOnly);
784+
foreach(var j in oldJsons)
785+
{
786+
if (Path.GetFileName(j).StartsWith("group_"))
787+
{
788+
File.Delete(j);
789+
}
790+
}
791+
792+
if (pmp.Meta.ModTags == null)
783793
{
784794
pmp.Meta.ModTags = new List<string>();
785795
}

xivModdingFramework/Mods/WizardData.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,15 @@ public static async Task<WizardGroupEntry> FromWizardGroup(ModGroupJson tGroup,
710710
continue;
711711
}
712712
}
713+
if (data.Files.ContainsKey(mj.FullPath))
714+
{
713715

714-
data.Files.Add(mj.FullPath, finfo);
716+
data.Files[mj.FullPath] = finfo;
717+
}
718+
else
719+
{
720+
data.Files.Add(mj.FullPath, finfo);
721+
}
715722
}
716723
}
717724
}

0 commit comments

Comments
 (0)