Some further cleanup.

This commit is contained in:
Ottermandias 2024-01-14 19:28:42 +01:00
parent 70e72f5790
commit b53a2f1def
24 changed files with 90 additions and 112 deletions

View file

@ -3,6 +3,7 @@ using Penumbra.Collections;
using Penumbra.Collections.Manager;
using Penumbra.Communication;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.Services;
using Penumbra.String.Classes;

View file

@ -4,6 +4,7 @@ using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
using Penumbra.Api.Enums;
using Penumbra.Communication;
using Penumbra.Mods.Editor;
using Penumbra.String.Classes;
using Penumbra.Mods.Manager;
using Penumbra.Mods.Subclasses;

View file

@ -1,5 +1,6 @@
using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.String.Classes;
namespace Penumbra.Collections.Cache;

View file

@ -5,6 +5,7 @@ using Penumbra.Interop.Structs;
using Penumbra.Meta;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.String.Classes;
namespace Penumbra.Collections.Cache;

View file

@ -7,6 +7,7 @@ using Penumbra.Meta.Manipulations;
using Penumbra.String.Classes;
using Penumbra.Collections.Cache;
using Penumbra.Interop.Services;
using Penumbra.Mods.Editor;
namespace Penumbra.Collections;

View file

@ -1,6 +1,7 @@
using OtterGui.Classes;
using Penumbra.Collections;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.String.Classes;
namespace Penumbra.Communication;

View file

@ -1,5 +1,4 @@
using Dalamud.Hooking;
using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle;
using OtterGui.Services;
namespace Penumbra.Interop.Hooks;
@ -32,12 +31,12 @@ public sealed unsafe class DebugHook : IHookService
public bool Finished
=> _task?.IsCompletedSuccessfully ?? true;
private delegate nint Delegate(ResourceHandle* resourceHandle);
private delegate void Delegate(nint a, int b, nint c, float* d);
private nint Detour(ResourceHandle* resourceHandle)
private void Detour(nint a, int b, nint c, float* d)
{
Penumbra.Log.Information($"[Debug Hook] Triggered with 0x{(nint)resourceHandle:X}.");
return _task!.Result.Original(resourceHandle);
_task!.Result.Original(a, b, c, d);
Penumbra.Log.Information($"[Debug Hook] Results with 0x{a:X} {b} {c:X} {d[0]} {d[1]} {d[2]} {d[3]}.");
}
}
#endif

View file

@ -1,4 +1,3 @@
using OtterGui.Services;
using Penumbra.Mods.Manager;
using Penumbra.Mods.Subclasses;
using Penumbra.Services;

View file

@ -1,7 +1,7 @@
using OtterGui.Classes;
using Penumbra.Mods.Subclasses;
namespace Penumbra.Mods;
namespace Penumbra.Mods.Editor;
public interface IMod
{

View file

@ -2,25 +2,19 @@ using OtterGui;
using OtterGui.Compression;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Files;
using Penumbra.Mods.Editor;
namespace Penumbra.Mods;
namespace Penumbra.Mods.Editor;
public partial class MdlMaterialEditor
public partial class MdlMaterialEditor(ModFileCollection files)
{
[GeneratedRegex(@"/mt_c(?'RaceCode'\d{4})b0001_(?'Suffix'.*?)\.mtrl", RegexOptions.ExplicitCapture | RegexOptions.NonBacktracking)]
private static partial Regex MaterialRegex();
private readonly ModFileCollection _files;
private readonly List<ModelMaterialInfo> _modelFiles = new();
private readonly List<ModelMaterialInfo> _modelFiles = [];
public IReadOnlyList<ModelMaterialInfo> ModelFiles
=> _modelFiles;
public MdlMaterialEditor(ModFileCollection files)
=> _files = files;
public void SaveAllModels(FileCompactor compactor)
{
foreach (var info in _modelFiles)
@ -73,7 +67,7 @@ public partial class MdlMaterialEditor
public void ScanModels(Mod mod)
{
_modelFiles.Clear();
foreach (var file in _files.Mdl)
foreach (var file in files.Mdl)
{
try
{

View file

@ -4,16 +4,25 @@ using Penumbra.Mods.Subclasses;
namespace Penumbra.Mods.Editor;
public class ModEditor : IDisposable
public class ModEditor(
ModNormalizer modNormalizer,
ModMetaEditor metaEditor,
ModFileCollection files,
ModFileEditor fileEditor,
DuplicateManager duplicates,
ModSwapEditor swapEditor,
MdlMaterialEditor mdlMaterialEditor,
FileCompactor compactor)
: IDisposable
{
public readonly ModNormalizer ModNormalizer;
public readonly ModMetaEditor MetaEditor;
public readonly ModFileEditor FileEditor;
public readonly DuplicateManager Duplicates;
public readonly ModFileCollection Files;
public readonly ModSwapEditor SwapEditor;
public readonly MdlMaterialEditor MdlMaterialEditor;
public readonly FileCompactor Compactor;
public readonly ModNormalizer ModNormalizer = modNormalizer;
public readonly ModMetaEditor MetaEditor = metaEditor;
public readonly ModFileEditor FileEditor = fileEditor;
public readonly DuplicateManager Duplicates = duplicates;
public readonly ModFileCollection Files = files;
public readonly ModSwapEditor SwapEditor = swapEditor;
public readonly MdlMaterialEditor MdlMaterialEditor = mdlMaterialEditor;
public readonly FileCompactor Compactor = compactor;
public Mod? Mod { get; private set; }
public int GroupIdx { get; private set; }
@ -22,20 +31,6 @@ public class ModEditor : IDisposable
public IModGroup? Group { get; private set; }
public ISubMod? Option { get; private set; }
public ModEditor(ModNormalizer modNormalizer, ModMetaEditor metaEditor, ModFileCollection files,
ModFileEditor fileEditor, DuplicateManager duplicates, ModSwapEditor swapEditor, MdlMaterialEditor mdlMaterialEditor,
FileCompactor compactor)
{
ModNormalizer = modNormalizer;
MetaEditor = metaEditor;
Files = files;
FileEditor = fileEditor;
Duplicates = duplicates;
SwapEditor = swapEditor;
MdlMaterialEditor = mdlMaterialEditor;
Compactor = compactor;
}
public void LoadMod(Mod mod)
=> LoadMod(mod, -1, 0);

View file

@ -6,20 +6,20 @@ namespace Penumbra.Mods.Editor;
public class ModFileCollection : IDisposable
{
private readonly List<FileRegistry> _available = new();
private readonly List<FileRegistry> _mtrl = new();
private readonly List<FileRegistry> _mdl = new();
private readonly List<FileRegistry> _tex = new();
private readonly List<FileRegistry> _shpk = new();
private readonly List<FileRegistry> _available = [];
private readonly List<FileRegistry> _mtrl = [];
private readonly List<FileRegistry> _mdl = [];
private readonly List<FileRegistry> _tex = [];
private readonly List<FileRegistry> _shpk = [];
private readonly SortedSet<FullPath> _missing = new();
private readonly HashSet<Utf8GamePath> _usedPaths = new();
private readonly SortedSet<FullPath> _missing = [];
private readonly HashSet<Utf8GamePath> _usedPaths = [];
public IReadOnlySet<FullPath> Missing
=> Ready ? _missing : new HashSet<FullPath>();
=> Ready ? _missing : [];
public IReadOnlySet<Utf8GamePath> UsedPaths
=> Ready ? _usedPaths : new HashSet<Utf8GamePath>();
=> Ready ? _usedPaths : [];
public IReadOnlyList<FileRegistry> Available
=> Ready ? _available : Array.Empty<FileRegistry>();
@ -38,9 +38,6 @@ public class ModFileCollection : IDisposable
public bool Ready { get; private set; } = true;
public ModFileCollection()
{ }
public void UpdateAll(Mod mod, ISubMod option)
{
UpdateFiles(mod, new CancellationToken());

View file

@ -1,23 +1,13 @@
using Penumbra.Mods.Editor;
using Penumbra.Mods.Manager;
using Penumbra.Mods.Subclasses;
using Penumbra.String.Classes;
namespace Penumbra.Mods;
namespace Penumbra.Mods.Editor;
public class ModFileEditor
public class ModFileEditor(ModFileCollection files, ModManager modManager)
{
private readonly ModFileCollection _files;
private readonly ModManager _modManager;
public bool Changes { get; private set; }
public ModFileEditor(ModFileCollection files, ModManager modManager)
{
_files = files;
_modManager = modManager;
}
public void Clear()
{
Changes = false;
@ -27,21 +17,21 @@ public class ModFileEditor
{
var dict = new Dictionary<Utf8GamePath, FullPath>();
var num = 0;
foreach (var file in _files.Available)
foreach (var file in files.Available)
{
foreach (var path in file.SubModUsage.Where(p => p.Item1 == option))
num += dict.TryAdd(path.Item2, file.File) ? 0 : 1;
}
_modManager.OptionEditor.OptionSetFiles(mod, option.GroupIdx, option.OptionIdx, dict);
_files.UpdatePaths(mod, option);
modManager.OptionEditor.OptionSetFiles(mod, option.GroupIdx, option.OptionIdx, dict);
files.UpdatePaths(mod, option);
Changes = false;
return num;
}
public void Revert(Mod mod, ISubMod option)
{
_files.UpdateAll(mod, option);
files.UpdateAll(mod, option);
Changes = false;
}
@ -53,16 +43,16 @@ public class ModFileEditor
var newDict = subMod.Files.Where(kvp => CheckAgainstMissing(mod, subMod, kvp.Value, kvp.Key, subMod == option))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
if (newDict.Count != subMod.Files.Count)
_modManager.OptionEditor.OptionSetFiles(mod, groupIdx, optionIdx, newDict);
modManager.OptionEditor.OptionSetFiles(mod, groupIdx, optionIdx, newDict);
}
ModEditor.ApplyToAllOptions(mod, HandleSubMod);
_files.ClearMissingFiles();
files.ClearMissingFiles();
}
/// <summary> Return whether the given path is already used in the current option. </summary>
public bool CanAddGamePath(Utf8GamePath path)
=> !_files.UsedPaths.Contains(path);
=> !files.UsedPaths.Contains(path);
/// <summary>
/// Try to set a given path for a given file.
@ -72,17 +62,17 @@ public class ModFileEditor
/// </summary>
public bool SetGamePath(ISubMod option, int fileIdx, int pathIdx, Utf8GamePath path)
{
if (!CanAddGamePath(path) || fileIdx < 0 || fileIdx > _files.Available.Count)
if (!CanAddGamePath(path) || fileIdx < 0 || fileIdx > files.Available.Count)
return false;
var registry = _files.Available[fileIdx];
var registry = files.Available[fileIdx];
if (pathIdx > registry.SubModUsage.Count)
return false;
if ((pathIdx == -1 || pathIdx == registry.SubModUsage.Count) && !path.IsEmpty)
_files.AddUsedPath(option, registry, path);
files.AddUsedPath(option, registry, path);
else
_files.ChangeUsedPath(registry, pathIdx, path);
files.ChangeUsedPath(registry, pathIdx, path);
Changes = true;
@ -93,10 +83,10 @@ public class ModFileEditor
/// Transform a set of files to the appropriate game paths with the given number of folders skipped,
/// and add them to the given option.
/// </summary>
public int AddPathsToSelected(ISubMod option, IEnumerable<FileRegistry> files, int skipFolders = 0)
public int AddPathsToSelected(ISubMod option, IEnumerable<FileRegistry> files1, int skipFolders = 0)
{
var failed = 0;
foreach (var file in files)
foreach (var file in files1)
{
var gamePath = file.RelPath.ToGamePath(skipFolders);
if (gamePath.IsEmpty)
@ -107,7 +97,7 @@ public class ModFileEditor
if (CanAddGamePath(gamePath))
{
_files.AddUsedPath(option, file, gamePath);
files.AddUsedPath(option, file, gamePath);
Changes = true;
}
else
@ -120,9 +110,9 @@ public class ModFileEditor
}
/// <summary> Remove all paths in the current option from the given files. </summary>
public void RemovePathsFromSelected(ISubMod option, IEnumerable<FileRegistry> files)
public void RemovePathsFromSelected(ISubMod option, IEnumerable<FileRegistry> files1)
{
foreach (var file in files)
foreach (var file in files1)
{
for (var i = 0; i < file.SubModUsage.Count; ++i)
{
@ -130,7 +120,7 @@ public class ModFileEditor
if (option != opt)
continue;
_files.RemoveUsedPath(option, file, path);
files.RemoveUsedPath(option, file, path);
Changes = true;
--i;
}
@ -138,10 +128,10 @@ public class ModFileEditor
}
/// <summary> Delete all given files from your filesystem </summary>
public void DeleteFiles(Mod mod, ISubMod option, IEnumerable<FileRegistry> files)
public void DeleteFiles(Mod mod, ISubMod option, IEnumerable<FileRegistry> files1)
{
var deletions = 0;
foreach (var file in files)
foreach (var file in files1)
{
try
{
@ -158,18 +148,18 @@ public class ModFileEditor
if (deletions <= 0)
return;
_modManager.Creator.ReloadMod(mod, false, out _);
_files.UpdateAll(mod, option);
modManager.Creator.ReloadMod(mod, false, out _);
files.UpdateAll(mod, option);
}
private bool CheckAgainstMissing(Mod mod, ISubMod option, FullPath file, Utf8GamePath key, bool removeUsed)
{
if (!_files.Missing.Contains(file))
if (!files.Missing.Contains(file))
return true;
if (removeUsed)
_files.RemoveUsedPath(option, file, key);
files.RemoveUsedPath(option, file, key);
Penumbra.Log.Debug($"[RemoveMissingPaths] Removing {key} -> {file} from {mod.Name}.");
return false;

View file

@ -4,16 +4,14 @@ using Penumbra.Mods.Subclasses;
namespace Penumbra.Mods;
public class ModMetaEditor
public class ModMetaEditor(ModManager modManager)
{
private readonly ModManager _modManager;
private readonly HashSet<ImcManipulation> _imc = new();
private readonly HashSet<EqpManipulation> _eqp = new();
private readonly HashSet<EqdpManipulation> _eqdp = new();
private readonly HashSet<GmpManipulation> _gmp = new();
private readonly HashSet<EstManipulation> _est = new();
private readonly HashSet<RspManipulation> _rsp = new();
private readonly HashSet<ImcManipulation> _imc = [];
private readonly HashSet<EqpManipulation> _eqp = [];
private readonly HashSet<EqdpManipulation> _eqdp = [];
private readonly HashSet<GmpManipulation> _gmp = [];
private readonly HashSet<EstManipulation> _est = [];
private readonly HashSet<RspManipulation> _rsp = [];
public int OtherImcCount { get; private set; }
public int OtherEqpCount { get; private set; }
@ -22,11 +20,7 @@ public class ModMetaEditor
public int OtherEstCount { get; private set; }
public int OtherRspCount { get; private set; }
public ModMetaEditor(ModManager modManager)
=> _modManager = modManager;
public bool Changes { get; private set; } = false;
public bool Changes { get; private set; }
public IReadOnlySet<ImcManipulation> Imc
=> _imc;
@ -156,7 +150,7 @@ public class ModMetaEditor
if (!Changes)
return;
_modManager.OptionEditor.OptionSetManipulations(mod, groupIdx, optionIdx, Recombine().ToHashSet());
modManager.OptionEditor.OptionSetManipulations(mod, groupIdx, optionIdx, Recombine().ToHashSet());
Changes = false;
}

View file

@ -10,7 +10,7 @@ namespace Penumbra.Mods.Editor;
public class ModNormalizer(ModManager _modManager, Configuration _config)
{
private readonly List<List<Dictionary<Utf8GamePath, FullPath>>> _redirections = new();
private readonly List<List<Dictionary<Utf8GamePath, FullPath>>> _redirections = [];
public Mod Mod { get; private set; } = null!;
private string _normalizationDirName = null!;
@ -141,7 +141,7 @@ public class ModNormalizer(ModManager _modManager, Configuration _config)
{
var directory = Directory.CreateDirectory(_normalizationDirName);
for (var i = _redirections.Count; i < Mod.Groups.Count + 1; ++i)
_redirections.Add(new List<Dictionary<Utf8GamePath, FullPath>>());
_redirections.Add([]);
if (_redirections[0].Count == 0)
_redirections[0].Add(new Dictionary<Utf8GamePath, FullPath>(Mod.Default.Files.Count));
@ -169,7 +169,7 @@ public class ModNormalizer(ModManager _modManager, Configuration _config)
{
_redirections[groupIdx + 1].EnsureCapacity(group.Count);
for (var i = _redirections[groupIdx + 1].Count; i < group.Count; ++i)
_redirections[groupIdx + 1].Add(new Dictionary<Utf8GamePath, FullPath>());
_redirections[groupIdx + 1].Add([]);
var groupDir = ModCreator.CreateModFolder(directory, group.Name, _config.ReplaceNonAsciiOnImport, true);
foreach (var option in group.OfType<SubMod>())

View file

@ -4,17 +4,13 @@ using Penumbra.Mods.Subclasses;
using Penumbra.String.Classes;
using Penumbra.Util;
public class ModSwapEditor
public class ModSwapEditor(ModManager modManager)
{
private readonly ModManager _modManager;
private readonly Dictionary<Utf8GamePath, FullPath> _swaps = new();
private readonly Dictionary<Utf8GamePath, FullPath> _swaps = [];
public IReadOnlyDictionary<Utf8GamePath, FullPath> Swaps
=> _swaps;
public ModSwapEditor(ModManager modManager)
=> _modManager = modManager;
public void Revert(ISubMod option)
{
_swaps.SetTo(option.FileSwaps);
@ -26,7 +22,7 @@ public class ModSwapEditor
if (!Changes)
return;
_modManager.OptionEditor.OptionSetFileSwaps(mod, groupIdx, optionIdx, _swaps);
modManager.OptionEditor.OptionSetFileSwaps(mod, groupIdx, optionIdx, _swaps);
Changes = false;
}

View file

@ -1,5 +1,6 @@
using OtterGui;
using OtterGui.Classes;
using Penumbra.Mods.Editor;
using Penumbra.Mods.Subclasses;
using Penumbra.String.Classes;

View file

@ -1,5 +1,6 @@
using Newtonsoft.Json.Linq;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods.Editor;
using Penumbra.String.Classes;
namespace Penumbra.Mods.Subclasses;

View file

@ -1,6 +1,7 @@
using OtterGui.Classes;
using Penumbra.Collections;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods.Editor;
using Penumbra.Mods.Manager;
using Penumbra.Mods.Subclasses;
using Penumbra.Services;

View file

@ -33,6 +33,7 @@ using Penumbra.UI.ModsTab;
using Penumbra.UI.ResourceWatcher;
using Penumbra.UI.Tabs;
using Penumbra.UI.Tabs.Debug;
using MdlMaterialEditor = Penumbra.Mods.Editor.MdlMaterialEditor;
using ResidentResourceManager = Penumbra.Interop.Services.ResidentResourceManager;
namespace Penumbra.Services;

View file

@ -26,6 +26,7 @@ using Penumbra.String;
using Penumbra.String.Classes;
using Penumbra.UI.Classes;
using Penumbra.Util;
using MdlMaterialEditor = Penumbra.Mods.Editor.MdlMaterialEditor;
namespace Penumbra.UI.AdvancedWindow;

View file

@ -8,6 +8,7 @@ using Penumbra.Collections.Cache;
using Penumbra.Collections.Manager;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.String.Classes;
using Penumbra.UI.Classes;

View file

@ -6,6 +6,7 @@ using OtterGui.Widgets;
using Penumbra.Api.Enums;
using Penumbra.Collections.Manager;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.Services;
using Penumbra.UI.Classes;

View file

@ -9,6 +9,7 @@ using Penumbra.Collections.Cache;
using Penumbra.Collections.Manager;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.String.Classes;
using Penumbra.UI.Classes;