Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some things! #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xivModdingFramework/Helpers/IOUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ public static string MakeLongPath(string path)
{
path = "\\\\?\\" + path;
}
return path;
return path.Replace("/", "\\");
}

public static byte[] GetImageSharpPixels(Image<Bgra32> img)
Expand Down
4 changes: 2 additions & 2 deletions xivModdingFramework/Models/FileTypes/PDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ private static void BuildNewTransfromMatrices(SkeletonData node, Dictionary<stri
{
def.InvertedDeformations.Add(node.BoneName, def.Deformations[node.BoneName].Inverted());

var normalMatrix = def.Deformations[node.BoneName].Inverted();
var normalMatrix = def.Deformations[node.BoneName];
normalMatrix.Transpose();
def.NormalDeformations.Add(node.BoneName, normalMatrix);

var invertexNormalMatrix = def.Deformations[node.BoneName].Inverted();
var invertexNormalMatrix = def.Deformations[node.BoneName];
normalMatrix.Transpose();
invertexNormalMatrix.Invert();
def.InvertedNormalDeformations.Add(node.BoneName, invertexNormalMatrix);
Expand Down
205 changes: 106 additions & 99 deletions xivModdingFramework/Mods/FileTypes/PMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ await IOUtil.UnzipFiles(path, tempFolder, (file) =>
foreach (var kv in op.Files)
{
var zipPath = kv.Value;
allPmpFiles.Add(zipPath);
allPmpFiles.Add(zipPath.ToLower());
}
}
}
Expand All @@ -178,7 +178,7 @@ await IOUtil.UnzipFiles(path, tempFolder, (file) =>
foreach (var kv in defOp.Files)
{
var zipPath = kv.Value;
allPmpFiles.Add(zipPath);
allPmpFiles.Add(zipPath.ToLower());
}
}

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



return (pmp, path, image);
}

Expand Down Expand Up @@ -316,124 +314,124 @@ private static void ValidateOption(PmpStandardOptionJson op)

tx.ModPack = modPack;

if (pmp.Groups == null || pmp.Groups.Count == 0)
var defMod = pmp.DefaultMod as PmpStandardOptionJson;

// Default option is always selected and always applied first, if it is present
if (defMod != null && !defMod.IsEmptyOption)
{
// No options, just default.
var groupRes = await ImportOption(pmp.DefaultMod, unzippedPath, tx, progress);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
}
else

// Order groups by Priority, Lowest => Highest, tiebreaker default order
var orderedGroups = pmp.Groups.OrderBy(x => x.Priority).ToList();
var groupIdx = 0;
foreach (var group in orderedGroups)
{
// Order groups by Priority, Lowest => Highest, tiebreaker default order
var orderedGroups = pmp.Groups.OrderBy(x => x.Priority).ToList();
var groupIdx = 0;
foreach (var group in orderedGroups)
if (group.Options == null || group.Options.Count == 0)
{
if (group.Options == null || group.Options.Count == 0)
{
// No valid options.
groupIdx++;
continue;
}
var optionIdx = 0;
// No valid options.
groupIdx++;
continue;
}
var optionIdx = 0;

// Get Default selection.
var selected = group.DefaultSettings;
// Get Default selection.
var selected = group.DefaultSettings;

// If the user selected custom settings, use those.
if (group.SelectedSettings >= 0)
// If the user selected custom settings, use those.
if (group.SelectedSettings >= 0)
{
selected = group.SelectedSettings;
}

if (group.Type == "Single")
{
if (selected < 0 || selected >= group.Options.Count)
{
selected = group.SelectedSettings;
selected = 0;
}
var groupRes = await ImportOption(group.Options[selected], unzippedPath, tx, progress, groupIdx, optionIdx);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
}
else if(group.Type == "Multi")
{
var ordered = group.Options.OrderBy(x => ((PmpStandardOptionJson)x).Priority).ToList();

if (group.Type == "Single")
// Bitmask options. Install in priority order.
foreach(var op in ordered)
{
if (selected < 0 || selected >= group.Options.Count)
var i = group.Options.IndexOf(op);
var value = 1 << i;
if ((selected & value) > 0)
{
selected = 0;
var groupRes = await ImportOption(group.Options[i], unzippedPath, tx, progress, groupIdx, optionIdx);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
optionIdx++;
}
var groupRes = await ImportOption(group.Options[selected], unzippedPath, tx, progress, groupIdx, optionIdx);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
}
else if(group.Type == "Multi")
{
var ordered = group.Options.OrderBy(x => ((PmpStandardOptionJson)x).Priority).ToList();

// Bitmask options. Install in priority order.
foreach(var op in ordered)
} else if(group.Type == "Imc")
{
// Could do with popping this out to its own function.
var imcGroup = group as PMPImcGroupJson;
var xivImc = imcGroup.DefaultEntry.ToXivImc();

bool disabled = false;
// Bitmask options.
for (int i = 0; i < group.Options.Count; i++)
{
var value = 1 << i;
if ((selected & value) > 0)
{
var i = group.Options.IndexOf(op);
var value = 1 << i;
if ((selected & value) > 0)
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
if (disableOpt != null)
{
var groupRes = await ImportOption(group.Options[i], unzippedPath, tx, progress, groupIdx, optionIdx);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
optionIdx++;
// No options allowed >:|
disabled = true;
break;
}

var opt = group.Options[i] as PmpImcOptionJson;
optionIdx++;

xivImc.AttributeMask |= opt.AttributeMask;
}
}

} else if(group.Type == "Imc")
if (!disabled)
{
// Could do with popping this out to its own function.
var imcGroup = group as PMPImcGroupJson;
var xivImc = imcGroup.DefaultEntry.ToXivImc();

bool disabled = false;
// Bitmask options.
for (int i = 0; i < group.Options.Count; i++)
var root = imcGroup.GetRoot();
var metaData = await GetImportMetadata(imported, root, tx);
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
{
var value = 1 << i;
if ((selected & value) > 0)
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
{
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
if (disableOpt != null)
{
// No options allowed >:|
disabled = true;
break;
}

var opt = group.Options[i] as PmpImcOptionJson;
optionIdx++;

xivImc.AttributeMask |= opt.AttributeMask;
metaData.ImcEntries.Add((XivImc)xivImc.Clone());
}
}

if (!disabled)
else
{
var root = imcGroup.GetRoot();
var metaData = await GetImportMetadata(imported, root, tx);
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
{
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
{
metaData.ImcEntries.Add((XivImc)xivImc.Clone());
}
}
else
{
metaData.ImcEntries[(int)imcGroup.Identifier.Variant] = xivImc;
}
metaData.ImcEntries[(int)imcGroup.Identifier.Variant] = xivImc;
}

if (imcGroup.AllVariants)
if (imcGroup.AllVariants)
{
for (int i = 0; i < metaData.ImcEntries.Count; i++)
{
for (int i = 0; i < metaData.ImcEntries.Count; i++)
{
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
}
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
}
}

await ItemMetadata.SaveMetadata(metaData, _Source, tx);
await ItemMetadata.ApplyMetadata(metaData, tx);
await ItemMetadata.SaveMetadata(metaData, _Source, tx);
await ItemMetadata.ApplyMetadata(metaData, tx);

}
}
groupIdx++;
}
groupIdx++;
}

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

if (defMod != null && (defMod.FileSwaps.Count > 0 || defMod.Manipulations.Count > 0 || defMod.Files.Count > 0) && pmp.Groups.Count == 0)
// Default mod is always present, but may be void of any data
if (defMod != null && !defMod.IsEmptyOption)
{
// Valid Default Mod Option
option = defMod;
}
else

if (pmp.Groups.Count == 1)
{
if (pmp.Groups.Count == 1)
var group = pmp.Groups[0];
if (group.Options.Count == 1)
{
var group = pmp.Groups[0];
if (group.Options.Count == 1)
{
option = group.Options[0] as PmpStandardOptionJson;
}
else if (group.Options.Count > 1)
{
// The default option was already found to be valid, leaving us with two valid options
// Return null so it gets treated as a wizard modpack instead
if (option != null)
return null;
}
} else if(pmp.Groups.Count > 1)
option = group.Options[0] as PmpStandardOptionJson;
}
else if (group.Options.Count > 1)
{
return null;
}
} else if(pmp.Groups.Count > 1)
{
return null;
}

if (option == null)
Expand Down Expand Up @@ -1401,6 +1402,12 @@ public class PmpStandardOptionJson : PMPOptionJson
public Dictionary<string, string> FileSwaps;
public List<PMPManipulationWrapperJson> Manipulations;
public int Priority;

[JsonIgnore] public bool IsEmptyOption => !(
(FileSwaps != null && FileSwaps.Count > 0) ||
(Manipulations != null && Manipulations.Count > 0) ||
(Files != null && Files.Count > 0)
);
}

public class PmpDisableImcOptionJson : PMPOptionJson
Expand Down
38 changes: 17 additions & 21 deletions xivModdingFramework/Mods/WizardData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,30 +1088,26 @@ public static async Task<WizardData> FromPmp(PMPJson pmp, string unzipPath)
data.ModPack = mp;
data.RawSource = pmp;

var def = pmp.DefaultMod as PmpStandardOptionJson;
if (def != null)
var defMod = pmp.DefaultMod as PmpStandardOptionJson;
if (defMod != null && !defMod.IsEmptyOption)
{
var anyData = (def.Manipulations != null && def.Manipulations.Count > 0) || def.FileSwaps.Count > 0 || def.Files.Count > 0;
if (anyData)
{
// Just drum up a basic group containing the default option.
var fakeGroup = new PMPGroupJson();
fakeGroup.Name = "Default";
fakeGroup.Options = new List<PMPOptionJson>() { pmp.DefaultMod };
fakeGroup.SelectedSettings = 1;
fakeGroup.Type = "Single";

if (string.IsNullOrWhiteSpace(pmp.DefaultMod.Name))
{
pmp.DefaultMod.Name = "Default";
}
// Just drum up a basic group containing the default option.
var fakeGroup = new PMPGroupJson();
fakeGroup.Name = "Default";
fakeGroup.Options = new List<PMPOptionJson>() { pmp.DefaultMod };
fakeGroup.SelectedSettings = 1;
fakeGroup.Type = "Single";

var page = new WizardPageEntry();
page.Name = "Page 1";
page.Groups = new List<WizardGroupEntry>();
page.Groups.Add(await WizardGroupEntry.FromPMPGroup(fakeGroup, unzipPath));
data.DataPages.Add(page);
if (string.IsNullOrWhiteSpace(pmp.DefaultMod.Name))
{
pmp.DefaultMod.Name = "Default";
}

var page = new WizardPageEntry();
page.Name = "Page 1";
page.Groups = new List<WizardGroupEntry>();
page.Groups.Add(await WizardGroupEntry.FromPMPGroup(fakeGroup, unzipPath));
data.DataPages.Add(page);
}

if (pmp.Groups.Count > 0)
Expand Down