Skip to content

Commit d9db56d

Browse files
Merge pull request #81 from senko-forks/pr-inthecage
Put out more neck related fires
2 parents 8e3603a + 0521e00 commit d9db56d

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,10 @@ public static XivMdl GetXivMdl(byte[] mdlData, string mdlPath = "")
10041004
}
10051005
}
10061006
else {
1007-
if (xivMdl.LoDList[0].VertexDataOffset < br.BaseStream.Position
1008-
|| (xivMdl.LoDList[0].VertexDataOffset % 8 != br.BaseStream.Position % 8)
1009-
&& xivMdl.LoDList[1].VertexDataSize == 0)
1007+
if ((xivMdl.LoDList[0].VertexDataOffset < br.BaseStream.Position
1008+
|| (xivMdl.LoDList[0].VertexDataOffset % 8 != br.BaseStream.Position % 8))
1009+
&& xivMdl.LoDList[1].VertexDataSize == 0 // Avoid applying this fix to vanilla models
1010+
&& xivMdl.ModelData.NeckMorphTableSize != 0x0A) // Avoid applying to face models, which were written incorrectly after patch 7.1
10101011
{
10111012

10121013
var delta = (int)(xivMdl.LoDList[0].VertexDataOffset - br.BaseStream.Position);
@@ -3608,6 +3609,10 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
36083609
bones.Add((byte)boneset0Index);
36093610
}
36103611

3612+
// Fully abort building neck data if we gave up inside the previous loop
3613+
if (basicModelBlock[neckMorphTableSizePointer] == 0)
3614+
break;
3615+
36113616
// Serialize
36123617
neckMorphDataBlock.AddRange(BitConverter.GetBytes(positionAdjust.X));
36133618
neckMorphDataBlock.AddRange(BitConverter.GetBytes(positionAdjust.Y));

xivModdingFramework/Mods/FileTypes/PMP.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,14 @@ private static void ValidateOption(PmpStandardOptionJson op)
401401
var value = 1UL << i;
402402
if ((selected & value) > 0)
403403
{
404-
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
405-
if (disableOpt != null)
404+
var opt = group.Options[i] as PmpImcOptionJson;
405+
if (opt.IsDisableSubMod)
406406
{
407407
// No options allowed >:|
408408
disabled = true;
409409
break;
410410
}
411411

412-
var opt = group.Options[i] as PmpImcOptionJson;
413412
optionIdx++;
414413

415414
xivImc.AttributeMask ^= opt.AttributeMask;
@@ -420,6 +419,26 @@ private static void ValidateOption(PmpStandardOptionJson op)
420419
{
421420
var root = imcGroup.GetRoot();
422421
var metaData = await GetImportMetadata(imported, root, tx);
422+
423+
// If the OnlyAttribute flag is set on the group, fill in the fields that should be ignored from the current values instead
424+
// ( The source can be null, in the case that we're going to be synthesizing new variants from thin air )
425+
void CopyNonMaskImcValues(XivImc xivImc, XivImc src)
426+
{
427+
xivImc.Animation = src?.Animation ?? 0;
428+
xivImc.SoundId = src?.SoundId ?? 0;
429+
xivImc.MaterialSet = src?.MaterialSet ?? 0;
430+
xivImc.Decal = src?.Decal ?? 0;
431+
xivImc.Vfx = src?.Vfx ?? 0;
432+
};
433+
434+
if (imcGroup.OnlyAttributes)
435+
{
436+
XivImc copyFromEntry = null;
437+
if (imcGroup.Identifier.Variant < metaData.ImcEntries.Count)
438+
copyFromEntry = metaData.ImcEntries[(int)imcGroup.Identifier.Variant];
439+
CopyNonMaskImcValues(xivImc, copyFromEntry);
440+
}
441+
423442
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
424443
{
425444
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
@@ -436,7 +455,10 @@ private static void ValidateOption(PmpStandardOptionJson op)
436455
{
437456
for (int i = 0; i < metaData.ImcEntries.Count; i++)
438457
{
439-
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
458+
var variantXivImc = (XivImc)xivImc.Clone();
459+
if (imcGroup.OnlyAttributes)
460+
CopyNonMaskImcValues(variantXivImc, metaData.ImcEntries[i]);
461+
metaData.ImcEntries[i] = variantXivImc;
440462
}
441463
}
442464

@@ -1479,16 +1501,13 @@ public class PmpMultiOptionJson : PmpStandardOptionJson
14791501
public int Priority = 0;
14801502
}
14811503

1482-
public class PmpDisableImcOptionJson : PMPOptionJson
1483-
{
1484-
public bool IsDisableSubMod = true;
1485-
}
1486-
1487-
[JsonConverter(typeof(JsonSubtypes))]
1488-
[JsonSubtypes.KnownSubTypeWithProperty(typeof(PmpDisableImcOptionJson), "IsDisableSubMod")]
14891504
public class PmpImcOptionJson : PMPOptionJson
14901505
{
1491-
public ushort AttributeMask;
1506+
public bool IsDisableSubMod = false;
1507+
public ushort AttributeMask = 0;
1508+
1509+
public bool ShouldSerializeIsDisableSubMod() { return IsDisableSubMod; }
1510+
public bool ShouldSerializeAttributeMask() { return !IsDisableSubMod; }
14921511
}
14931512

14941513
#endregion

xivModdingFramework/Mods/WizardData.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,12 @@ public async Task<PMPOptionJson> ToPmpOption(string tempFolder, IEnumerable<File
514514
PMPOptionJson op;
515515
if (GroupType == EGroupType.Imc)
516516
{
517-
if (ImcData.IsDisableOption)
518-
{
519-
var io = new PmpDisableImcOptionJson();
520-
op = io;
521-
}
522-
else
523-
{
524-
var io = new PmpImcOptionJson();
525-
op = io;
517+
var io = new PmpImcOptionJson();
518+
op = io;
519+
if (!ImcData.IsDisableOption)
526520
io.AttributeMask = ImcData.AttributeMask;
527-
}
521+
else
522+
io.IsDisableSubMod = true;
528523
}
529524
else
530525
{
@@ -831,17 +826,10 @@ public static async Task<WizardGroupEntry> FromPMPGroup(PMPGroupJson pGroup, str
831826
{
832827
var imcData = new WizardImcOptionData();
833828
var imcOp = o as PmpImcOptionJson;
834-
if (imcOp != null)
835-
{
836-
imcData.IsDisableOption = false;
829+
if (!imcOp.IsDisableSubMod)
837830
imcData.AttributeMask = imcOp.AttributeMask;
838-
}
839-
var defOp = o as PmpDisableImcOptionJson;
840-
if (defOp != null)
841-
{
842-
imcData.IsDisableOption = defOp.IsDisableSubMod;
843-
imcData.AttributeMask = 0;
844-
}
831+
else
832+
imcData.IsDisableOption = imcOp.IsDisableSubMod;
845833
wizOp.ImcData = imcData;
846834
}
847835

0 commit comments

Comments
 (0)