Skip to content

Commit 675de17

Browse files
authored
Merge pull request #73 from senko-forks/pr-meow
Merge Senko's 'Some Things!' PR
2 parents 9b58024 + cdfdb1a commit 675de17

File tree

4 files changed

+126
-123
lines changed

4 files changed

+126
-123
lines changed

xivModdingFramework/Helpers/IOUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ public static string MakeLongPath(string path)
767767
{
768768
path = "\\\\?\\" + path;
769769
}
770-
return path;
770+
return path.Replace("/", "\\");
771771
}
772772

773773
public static byte[] GetImageSharpPixels(Image<Bgra32> img)

xivModdingFramework/Models/FileTypes/PDB.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ private static void BuildNewTransfromMatrices(SkeletonData node, Dictionary<stri
350350
{
351351
def.InvertedDeformations.Add(node.BoneName, def.Deformations[node.BoneName].Inverted());
352352

353-
var normalMatrix = def.Deformations[node.BoneName].Inverted();
353+
var normalMatrix = def.Deformations[node.BoneName];
354354
normalMatrix.Transpose();
355355
def.NormalDeformations.Add(node.BoneName, normalMatrix);
356356

357-
var invertexNormalMatrix = def.Deformations[node.BoneName].Inverted();
357+
var invertexNormalMatrix = def.Deformations[node.BoneName];
358358
normalMatrix.Transpose();
359359
invertexNormalMatrix.Invert();
360360
def.InvertedNormalDeformations.Add(node.BoneName, invertexNormalMatrix);

xivModdingFramework/Mods/FileTypes/PMP.cs

Lines changed: 106 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ await IOUtil.UnzipFiles(path, tempFolder, (file) =>
165165
foreach (var kv in op.Files)
166166
{
167167
var zipPath = kv.Value;
168-
allPmpFiles.Add(zipPath);
168+
allPmpFiles.Add(zipPath.ToLower());
169169
}
170170
}
171171
}
@@ -178,7 +178,7 @@ await IOUtil.UnzipFiles(path, tempFolder, (file) =>
178178
foreach (var kv in defOp.Files)
179179
{
180180
var zipPath = kv.Value;
181-
allPmpFiles.Add(zipPath);
181+
allPmpFiles.Add(zipPath.ToLower());
182182
}
183183
}
184184

@@ -194,8 +194,6 @@ await IOUtil.UnzipFiles(originalPath, path, (file) =>
194194
});
195195
}
196196

197-
198-
199197
return (pmp, path, image);
200198
}
201199

@@ -316,124 +314,124 @@ private static void ValidateOption(PmpStandardOptionJson op)
316314

317315
tx.ModPack = modPack;
318316

319-
if (pmp.Groups == null || pmp.Groups.Count == 0)
317+
var defMod = pmp.DefaultMod as PmpStandardOptionJson;
318+
319+
// Default option is always selected and always applied first, if it is present
320+
if (defMod != null && !defMod.IsEmptyOption)
320321
{
321-
// No options, just default.
322322
var groupRes = await ImportOption(pmp.DefaultMod, unzippedPath, tx, progress);
323323
UnionDict(imported, groupRes.Imported);
324324
notImported.UnionWith(groupRes.NotImported);
325325
}
326-
else
326+
327+
// Order groups by Priority, Lowest => Highest, tiebreaker default order
328+
var orderedGroups = pmp.Groups.OrderBy(x => x.Priority).ToList();
329+
var groupIdx = 0;
330+
foreach (var group in orderedGroups)
327331
{
328-
// Order groups by Priority, Lowest => Highest, tiebreaker default order
329-
var orderedGroups = pmp.Groups.OrderBy(x => x.Priority).ToList();
330-
var groupIdx = 0;
331-
foreach (var group in orderedGroups)
332+
if (group.Options == null || group.Options.Count == 0)
332333
{
333-
if (group.Options == null || group.Options.Count == 0)
334-
{
335-
// No valid options.
336-
groupIdx++;
337-
continue;
338-
}
339-
var optionIdx = 0;
334+
// No valid options.
335+
groupIdx++;
336+
continue;
337+
}
338+
var optionIdx = 0;
340339

341-
// Get Default selection.
342-
var selected = group.DefaultSettings;
340+
// Get Default selection.
341+
var selected = group.DefaultSettings;
343342

344-
// If the user selected custom settings, use those.
345-
if (group.SelectedSettings >= 0)
343+
// If the user selected custom settings, use those.
344+
if (group.SelectedSettings >= 0)
345+
{
346+
selected = group.SelectedSettings;
347+
}
348+
349+
if (group.Type == "Single")
350+
{
351+
if (selected < 0 || selected >= group.Options.Count)
346352
{
347-
selected = group.SelectedSettings;
353+
selected = 0;
348354
}
355+
var groupRes = await ImportOption(group.Options[selected], unzippedPath, tx, progress, groupIdx, optionIdx);
356+
UnionDict(imported, groupRes.Imported);
357+
notImported.UnionWith(groupRes.NotImported);
358+
}
359+
else if(group.Type == "Multi")
360+
{
361+
var ordered = group.Options.OrderBy(x => ((PmpStandardOptionJson)x).Priority).ToList();
349362

350-
if (group.Type == "Single")
363+
// Bitmask options. Install in priority order.
364+
foreach(var op in ordered)
351365
{
352-
if (selected < 0 || selected >= group.Options.Count)
366+
var i = group.Options.IndexOf(op);
367+
var value = 1 << i;
368+
if ((selected & value) > 0)
353369
{
354-
selected = 0;
370+
var groupRes = await ImportOption(group.Options[i], unzippedPath, tx, progress, groupIdx, optionIdx);
371+
UnionDict(imported, groupRes.Imported);
372+
notImported.UnionWith(groupRes.NotImported);
373+
optionIdx++;
355374
}
356-
var groupRes = await ImportOption(group.Options[selected], unzippedPath, tx, progress, groupIdx, optionIdx);
357-
UnionDict(imported, groupRes.Imported);
358-
notImported.UnionWith(groupRes.NotImported);
359375
}
360-
else if(group.Type == "Multi")
361-
{
362-
var ordered = group.Options.OrderBy(x => ((PmpStandardOptionJson)x).Priority).ToList();
363376

364-
// Bitmask options. Install in priority order.
365-
foreach(var op in ordered)
377+
} else if(group.Type == "Imc")
378+
{
379+
// Could do with popping this out to its own function.
380+
var imcGroup = group as PMPImcGroupJson;
381+
var xivImc = imcGroup.DefaultEntry.ToXivImc();
382+
383+
bool disabled = false;
384+
// Bitmask options.
385+
for (int i = 0; i < group.Options.Count; i++)
386+
{
387+
var value = 1 << i;
388+
if ((selected & value) > 0)
366389
{
367-
var i = group.Options.IndexOf(op);
368-
var value = 1 << i;
369-
if ((selected & value) > 0)
390+
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
391+
if (disableOpt != null)
370392
{
371-
var groupRes = await ImportOption(group.Options[i], unzippedPath, tx, progress, groupIdx, optionIdx);
372-
UnionDict(imported, groupRes.Imported);
373-
notImported.UnionWith(groupRes.NotImported);
374-
optionIdx++;
393+
// No options allowed >:|
394+
disabled = true;
395+
break;
375396
}
397+
398+
var opt = group.Options[i] as PmpImcOptionJson;
399+
optionIdx++;
400+
401+
xivImc.AttributeMask |= opt.AttributeMask;
376402
}
403+
}
377404

378-
} else if(group.Type == "Imc")
405+
if (!disabled)
379406
{
380-
// Could do with popping this out to its own function.
381-
var imcGroup = group as PMPImcGroupJson;
382-
var xivImc = imcGroup.DefaultEntry.ToXivImc();
383-
384-
bool disabled = false;
385-
// Bitmask options.
386-
for (int i = 0; i < group.Options.Count; i++)
407+
var root = imcGroup.GetRoot();
408+
var metaData = await GetImportMetadata(imported, root, tx);
409+
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
387410
{
388-
var value = 1 << i;
389-
if ((selected & value) > 0)
411+
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
390412
{
391-
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
392-
if (disableOpt != null)
393-
{
394-
// No options allowed >:|
395-
disabled = true;
396-
break;
397-
}
398-
399-
var opt = group.Options[i] as PmpImcOptionJson;
400-
optionIdx++;
401-
402-
xivImc.AttributeMask |= opt.AttributeMask;
413+
metaData.ImcEntries.Add((XivImc)xivImc.Clone());
403414
}
404415
}
405-
406-
if (!disabled)
416+
else
407417
{
408-
var root = imcGroup.GetRoot();
409-
var metaData = await GetImportMetadata(imported, root, tx);
410-
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
411-
{
412-
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
413-
{
414-
metaData.ImcEntries.Add((XivImc)xivImc.Clone());
415-
}
416-
}
417-
else
418-
{
419-
metaData.ImcEntries[(int)imcGroup.Identifier.Variant] = xivImc;
420-
}
418+
metaData.ImcEntries[(int)imcGroup.Identifier.Variant] = xivImc;
419+
}
421420

422-
if (imcGroup.AllVariants)
421+
if (imcGroup.AllVariants)
422+
{
423+
for (int i = 0; i < metaData.ImcEntries.Count; i++)
423424
{
424-
for (int i = 0; i < metaData.ImcEntries.Count; i++)
425-
{
426-
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
427-
}
425+
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
428426
}
427+
}
429428

430-
await ItemMetadata.SaveMetadata(metaData, _Source, tx);
431-
await ItemMetadata.ApplyMetadata(metaData, tx);
429+
await ItemMetadata.SaveMetadata(metaData, _Source, tx);
430+
await ItemMetadata.ApplyMetadata(metaData, tx);
432431

433-
}
434432
}
435-
groupIdx++;
436433
}
434+
groupIdx++;
437435
}
438436

439437
var preRootTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
@@ -910,28 +908,31 @@ internal static async Task<Dictionary<string, FileStorageInformation>> UnpackPMP
910908
var defMod = pmp.DefaultMod as PmpStandardOptionJson;
911909
PmpStandardOptionJson option = null;
912910

913-
if (defMod != null && (defMod.FileSwaps.Count > 0 || defMod.Manipulations.Count > 0 || defMod.Files.Count > 0) && pmp.Groups.Count == 0)
911+
// Default mod is always present, but may be void of any data
912+
if (defMod != null && !defMod.IsEmptyOption)
914913
{
915914
// Valid Default Mod Option
916915
option = defMod;
917916
}
918-
else
917+
918+
if (pmp.Groups.Count == 1)
919919
{
920-
if (pmp.Groups.Count == 1)
920+
var group = pmp.Groups[0];
921+
if (group.Options.Count == 1)
921922
{
922-
var group = pmp.Groups[0];
923-
if (group.Options.Count == 1)
924-
{
925-
option = group.Options[0] as PmpStandardOptionJson;
926-
}
927-
else if (group.Options.Count > 1)
928-
{
923+
// The default option was already found to be valid, leaving us with two valid options
924+
// Return null so it gets treated as a wizard modpack instead
925+
if (option != null)
929926
return null;
930-
}
931-
} else if(pmp.Groups.Count > 1)
927+
option = group.Options[0] as PmpStandardOptionJson;
928+
}
929+
else if (group.Options.Count > 1)
932930
{
933931
return null;
934932
}
933+
} else if(pmp.Groups.Count > 1)
934+
{
935+
return null;
935936
}
936937

937938
if (option == null)
@@ -1402,6 +1403,12 @@ public class PmpStandardOptionJson : PMPOptionJson
14021403
public Dictionary<string, string> FileSwaps;
14031404
public List<PMPManipulationWrapperJson> Manipulations;
14041405
public int Priority;
1406+
1407+
[JsonIgnore] public bool IsEmptyOption => !(
1408+
(FileSwaps != null && FileSwaps.Count > 0) ||
1409+
(Manipulations != null && Manipulations.Count > 0) ||
1410+
(Files != null && Files.Count > 0)
1411+
);
14051412
}
14061413

14071414
public class PmpDisableImcOptionJson : PMPOptionJson

xivModdingFramework/Mods/WizardData.cs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,30 +1088,26 @@ public static async Task<WizardData> FromPmp(PMPJson pmp, string unzipPath)
10881088
data.ModPack = mp;
10891089
data.RawSource = pmp;
10901090

1091-
var def = pmp.DefaultMod as PmpStandardOptionJson;
1092-
if (def != null)
1091+
var defMod = pmp.DefaultMod as PmpStandardOptionJson;
1092+
if (defMod != null && !defMod.IsEmptyOption)
10931093
{
1094-
var anyData = (def.Manipulations != null && def.Manipulations.Count > 0) || def.FileSwaps.Count > 0 || def.Files.Count > 0;
1095-
if (anyData)
1096-
{
1097-
// Just drum up a basic group containing the default option.
1098-
var fakeGroup = new PMPGroupJson();
1099-
fakeGroup.Name = "Default";
1100-
fakeGroup.Options = new List<PMPOptionJson>() { pmp.DefaultMod };
1101-
fakeGroup.SelectedSettings = 1;
1102-
fakeGroup.Type = "Single";
1103-
1104-
if (string.IsNullOrWhiteSpace(pmp.DefaultMod.Name))
1105-
{
1106-
pmp.DefaultMod.Name = "Default";
1107-
}
1094+
// Just drum up a basic group containing the default option.
1095+
var fakeGroup = new PMPGroupJson();
1096+
fakeGroup.Name = "Default";
1097+
fakeGroup.Options = new List<PMPOptionJson>() { pmp.DefaultMod };
1098+
fakeGroup.SelectedSettings = 1;
1099+
fakeGroup.Type = "Single";
11081100

1109-
var page = new WizardPageEntry();
1110-
page.Name = "Page 1";
1111-
page.Groups = new List<WizardGroupEntry>();
1112-
page.Groups.Add(await WizardGroupEntry.FromPMPGroup(fakeGroup, unzipPath));
1113-
data.DataPages.Add(page);
1101+
if (string.IsNullOrWhiteSpace(pmp.DefaultMod.Name))
1102+
{
1103+
pmp.DefaultMod.Name = "Default";
11141104
}
1105+
1106+
var page = new WizardPageEntry();
1107+
page.Name = "Page 1";
1108+
page.Groups = new List<WizardGroupEntry>();
1109+
page.Groups.Add(await WizardGroupEntry.FromPMPGroup(fakeGroup, unzipPath));
1110+
data.DataPages.Add(page);
11151111
}
11161112

11171113
if (pmp.Groups.Count > 0)

0 commit comments

Comments
 (0)