Skip to content

Commit 819afc5

Browse files
committed
Merge branch 'meta_rework'
2 parents 250c403 + e05dbe9 commit 819afc5

File tree

192 files changed

+4106
-4104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+4106
-4104
lines changed

Penumbra/Api/Api/MetaApi.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
1+
using Newtonsoft.Json.Linq;
12
using OtterGui;
23
using OtterGui.Services;
4+
using Penumbra.Collections;
5+
using Penumbra.GameData.Structs;
36
using Penumbra.Interop.PathResolving;
47
using Penumbra.Meta.Manipulations;
58

69
namespace Penumbra.Api.Api;
710

811
public class MetaApi(CollectionResolver collectionResolver, ApiHelpers helpers) : IPenumbraApiMeta, IApiService
912
{
13+
public const int CurrentVersion = 0;
14+
1015
public string GetPlayerMetaManipulations()
1116
{
1217
var collection = collectionResolver.PlayerCollection();
13-
var set = collection.MetaCache?.Manipulations.ToArray() ?? [];
14-
return Functions.ToCompressedBase64(set, MetaManipulation.CurrentVersion);
18+
return CompressMetaManipulations(collection);
1519
}
1620

1721
public string GetMetaManipulations(int gameObjectIdx)
1822
{
1923
helpers.AssociatedCollection(gameObjectIdx, out var collection);
20-
var set = collection.MetaCache?.Manipulations.ToArray() ?? [];
21-
return Functions.ToCompressedBase64(set, MetaManipulation.CurrentVersion);
24+
return CompressMetaManipulations(collection);
25+
}
26+
27+
internal static string CompressMetaManipulations(ModCollection collection)
28+
{
29+
var array = new JArray();
30+
if (collection.MetaCache is { } cache)
31+
{
32+
MetaDictionary.SerializeTo(array, cache.GlobalEqp.Select(kvp => kvp.Key));
33+
MetaDictionary.SerializeTo(array, cache.Imc.Select(kvp => new KeyValuePair<ImcIdentifier, ImcEntry>(kvp.Key, kvp.Value.Entry)));
34+
MetaDictionary.SerializeTo(array, cache.Eqp.Select(kvp => new KeyValuePair<EqpIdentifier, EqpEntry>(kvp.Key, kvp.Value.Entry)));
35+
MetaDictionary.SerializeTo(array, cache.Eqdp.Select(kvp => new KeyValuePair<EqdpIdentifier, EqdpEntry>(kvp.Key, kvp.Value.Entry)));
36+
MetaDictionary.SerializeTo(array, cache.Est.Select(kvp => new KeyValuePair<EstIdentifier, EstEntry>(kvp.Key, kvp.Value.Entry)));
37+
MetaDictionary.SerializeTo(array, cache.Rsp.Select(kvp => new KeyValuePair<RspIdentifier, RspEntry>(kvp.Key, kvp.Value.Entry)));
38+
MetaDictionary.SerializeTo(array, cache.Gmp.Select(kvp => new KeyValuePair<GmpIdentifier, GmpEntry>(kvp.Key, kvp.Value.Entry)));
39+
}
40+
41+
return Functions.ToCompressedBase64(array, CurrentVersion);
2242
}
2343
}

Penumbra/Api/Api/TemporaryApi.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,32 +159,18 @@ private static bool ConvertPaths(IReadOnlyDictionary<string, string> redirection
159159
/// The empty string is treated as an empty set.
160160
/// Only returns true if all conversions are successful and distinct.
161161
/// </summary>
162-
private static bool ConvertManips(string manipString,
163-
[NotNullWhen(true)] out HashSet<MetaManipulation>? manips)
162+
private static bool ConvertManips(string manipString, [NotNullWhen(true)] out MetaDictionary? manips)
164163
{
165164
if (manipString.Length == 0)
166165
{
167-
manips = [];
166+
manips = new MetaDictionary();
168167
return true;
169168
}
170169

171-
if (Functions.FromCompressedBase64<MetaManipulation[]>(manipString, out var manipArray) != MetaManipulation.CurrentVersion)
172-
{
173-
manips = null;
174-
return false;
175-
}
176-
177-
manips = new HashSet<MetaManipulation>(manipArray!.Length);
178-
foreach (var manip in manipArray.Where(m => m.Validate()))
179-
{
180-
if (manips.Add(manip))
181-
continue;
182-
183-
Penumbra.Log.Warning($"Manipulation {manip} {manip.EntryToString()} is invalid and was skipped.");
184-
manips = null;
185-
return false;
186-
}
170+
if (Functions.FromCompressedBase64(manipString, out manips!) == MetaApi.CurrentVersion)
171+
return true;
187172

188-
return true;
173+
manips = null;
174+
return false;
189175
}
190176
}

Penumbra/Api/IpcTester/TemporaryIpcTester.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using OtterGui;
55
using OtterGui.Raii;
66
using OtterGui.Services;
7+
using OtterGui.Text;
8+
using Penumbra.Api.Api;
79
using Penumbra.Api.Enums;
810
using Penumbra.Api.IpcSubscribers;
911
using Penumbra.Collections.Manager;
@@ -49,7 +51,7 @@ public void Draw()
4951
ImGui.InputTextWithHint("##tempMod", "Temporary Mod Name...", ref _tempModName, 32);
5052
ImGui.InputTextWithHint("##tempGame", "Game Path...", ref _tempGamePath, 256);
5153
ImGui.InputTextWithHint("##tempFile", "File Path...", ref _tempFilePath, 256);
52-
ImGui.InputTextWithHint("##tempManip", "Manipulation Base64 String...", ref _tempManipulation, 256);
54+
ImUtf8.InputText("##tempManip"u8, ref _tempManipulation, "Manipulation Base64 String..."u8);
5355
ImGui.Checkbox("Force Character Collection Overwrite", ref _forceOverwrite);
5456

5557
using var table = ImRaii.Table(string.Empty, 3, ImGuiTableFlags.SizingFixedFit);
@@ -101,8 +103,7 @@ public void Draw()
101103
&& copyCollection is { HasCache: true })
102104
{
103105
var files = copyCollection.ResolvedFiles.ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.Path.ToString());
104-
var manips = Functions.ToCompressedBase64(copyCollection.MetaCache?.Manipulations.ToArray() ?? Array.Empty<MetaManipulation>(),
105-
MetaManipulation.CurrentVersion);
106+
var manips = MetaApi.CompressMetaManipulations(copyCollection);
106107
_lastTempError = new AddTemporaryMod(pi).Invoke(_tempModName, guid, files, manips, 999);
107108
}
108109

@@ -187,8 +188,8 @@ void PrintList(string collectionName, IReadOnlyList<TemporaryMod> list)
187188
if (ImGui.IsItemHovered())
188189
{
189190
using var tt = ImRaii.Tooltip();
190-
foreach (var manip in mod.Default.Manipulations)
191-
ImGui.TextUnformatted(manip.ToString());
191+
foreach (var identifier in mod.Default.Manipulations.Identifiers)
192+
ImGui.TextUnformatted(identifier.ToString());
192193
}
193194
}
194195
}

Penumbra/Api/TempModManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using OtterGui.Services;
12
using Penumbra.Api.Enums;
23
using Penumbra.Collections;
34
using Penumbra.Meta.Manipulations;
@@ -18,7 +19,7 @@ public enum RedirectResult
1819
FilteredGamePath = 3,
1920
}
2021

21-
public class TempModManager : IDisposable
22+
public class TempModManager : IDisposable, IService
2223
{
2324
private readonly CommunicatorService _communicator;
2425

@@ -43,7 +44,7 @@ public IReadOnlyList<TemporaryMod> ModsForAllCollections
4344
=> _modsForAllCollections;
4445

4546
public RedirectResult Register(string tag, ModCollection? collection, Dictionary<Utf8GamePath, FullPath> dict,
46-
HashSet<MetaManipulation> manips, ModPriority priority)
47+
MetaDictionary manips, ModPriority priority)
4748
{
4849
var mod = GetOrCreateMod(tag, collection, priority, out var created);
4950
Penumbra.Log.Verbose($"{(created ? "Created" : "Changed")} temporary Mod {mod.Name}.");

Penumbra/Collections/Cache/CmpCache.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

Penumbra/Collections/Cache/CollectionCache.cs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ public HashSet<Utf8GamePath>[] ReverseResolvePaths(IReadOnlyCollection<string> f
125125
return ret;
126126
}
127127

128-
public void ForceFile(Utf8GamePath path, FullPath fullPath)
129-
=> _manager.AddChange(ChangeData.ForcedFile(this, path, fullPath));
130-
131-
public void RemovePath(Utf8GamePath path)
132-
=> _manager.AddChange(ChangeData.ForcedFile(this, path, FullPath.Empty));
133-
134128
public void ReloadMod(IMod mod, bool addMetaChanges)
135129
=> _manager.AddChange(ChangeData.ModReload(this, mod, addMetaChanges));
136130

@@ -233,15 +227,24 @@ internal void AddModSync(IMod mod, bool addMetaChanges)
233227
foreach (var (path, file) in files.FileRedirections)
234228
AddFile(path, file, mod);
235229

236-
foreach (var manip in files.Manipulations)
237-
AddManipulation(manip, mod);
230+
foreach (var (identifier, entry) in files.Manipulations.Eqp)
231+
AddManipulation(mod, identifier, entry);
232+
foreach (var (identifier, entry) in files.Manipulations.Eqdp)
233+
AddManipulation(mod, identifier, entry);
234+
foreach (var (identifier, entry) in files.Manipulations.Est)
235+
AddManipulation(mod, identifier, entry);
236+
foreach (var (identifier, entry) in files.Manipulations.Gmp)
237+
AddManipulation(mod, identifier, entry);
238+
foreach (var (identifier, entry) in files.Manipulations.Rsp)
239+
AddManipulation(mod, identifier, entry);
240+
foreach (var (identifier, entry) in files.Manipulations.Imc)
241+
AddManipulation(mod, identifier, entry);
242+
foreach (var identifier in files.Manipulations.GlobalEqp)
243+
AddManipulation(mod, identifier, null!);
238244

239245
if (addMetaChanges)
240246
{
241247
_collection.IncrementCounter();
242-
if (mod.TotalManipulations > 0)
243-
AddMetaFiles(false);
244-
245248
_manager.MetaFileManager.ApplyDefaultFiles(_collection);
246249
}
247250
}
@@ -342,7 +345,7 @@ private bool AddConflict(object data, IMod addedMod, IMod existingMod)
342345
foreach (var conflict in tmpConflicts)
343346
{
344347
if (data is Utf8GamePath path && conflict.Conflicts.RemoveAll(p => p is Utf8GamePath x && x.Equals(path)) > 0
345-
|| data is MetaManipulation meta && conflict.Conflicts.RemoveAll(m => m is MetaManipulation x && x.Equals(meta)) > 0)
348+
|| data is IMetaIdentifier meta && conflict.Conflicts.RemoveAll(m => m.Equals(meta)) > 0)
346349
AddConflict(data, addedMod, conflict.Mod2);
347350
}
348351

@@ -374,33 +377,28 @@ private bool AddConflict(object data, IMod addedMod, IMod existingMod)
374377
// For different mods, higher mod priority takes precedence before option group priority,
375378
// which takes precedence before option priority, which takes precedence before ordering.
376379
// Inside the same mod, conflicts are not recorded.
377-
private void AddManipulation(MetaManipulation manip, IMod mod)
380+
private void AddManipulation(IMod mod, IMetaIdentifier identifier, object entry)
378381
{
379-
if (!Meta.TryGetValue(manip, out var existingMod))
382+
if (!Meta.TryGetMod(identifier, out var existingMod))
380383
{
381-
Meta.ApplyMod(manip, mod);
382-
ModData.AddManip(mod, manip);
384+
Meta.ApplyMod(mod, identifier, entry);
385+
ModData.AddManip(mod, identifier);
383386
return;
384387
}
385388

386389
// Lower prioritized option in the same mod.
387390
if (mod == existingMod)
388391
return;
389392

390-
if (AddConflict(manip, mod, existingMod))
393+
if (AddConflict(identifier, mod, existingMod))
391394
{
392-
ModData.RemoveManip(existingMod, manip);
393-
Meta.ApplyMod(manip, mod);
394-
ModData.AddManip(mod, manip);
395+
ModData.RemoveManip(existingMod, identifier);
396+
Meta.ApplyMod(mod, identifier, entry);
397+
ModData.AddManip(mod, identifier);
395398
}
396399
}
397400

398401

399-
// Add all necessary meta file redirects.
400-
public void AddMetaFiles(bool fromFullCompute)
401-
=> Meta.SetImcFiles(fromFullCompute);
402-
403-
404402
// Identify and record all manipulated objects for this entire collection.
405403
private void SetChangedItems()
406404
{
@@ -437,9 +435,9 @@ void AddItems(IMod mod)
437435
AddItems(modPath.Mod);
438436
}
439437

440-
foreach (var (manip, mod) in Meta)
438+
foreach (var (manip, mod) in Meta.IdentifierSources)
441439
{
442-
identifier.MetaChangedItems(items, manip);
440+
manip.AddChangedItems(identifier, items);
443441
AddItems(mod);
444442
}
445443

Penumbra/Collections/Cache/CollectionCacheManager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Dalamud.Plugin.Services;
22
using OtterGui.Classes;
3+
using OtterGui.Services;
34
using Penumbra.Api;
45
using Penumbra.Api.Enums;
56
using Penumbra.Collections.Manager;
@@ -17,7 +18,7 @@
1718

1819
namespace Penumbra.Collections.Cache;
1920

20-
public class CollectionCacheManager : IDisposable
21+
public class CollectionCacheManager : IDisposable, IService
2122
{
2223
private readonly FrameworkManager _framework;
2324
private readonly CommunicatorService _communicator;
@@ -180,8 +181,6 @@ private void FullRecalculation(ModCollection collection)
180181
foreach (var mod in _modStorage)
181182
cache.AddModSync(mod, false);
182183

183-
cache.AddMetaFiles(true);
184-
185184
collection.IncrementCounter();
186185

187186
MetaFileManager.ApplyDefaultFiles(collection);

Penumbra/Collections/Cache/CollectionModData.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ namespace Penumbra.Collections.Cache;
99
/// </summary>
1010
public class CollectionModData
1111
{
12-
private readonly Dictionary<IMod, (HashSet<Utf8GamePath>, HashSet<MetaManipulation>)> _data = new();
12+
private readonly Dictionary<IMod, (HashSet<Utf8GamePath>, HashSet<IMetaIdentifier>)> _data = new();
1313

14-
public IEnumerable<(IMod, IReadOnlySet<Utf8GamePath>, IReadOnlySet<MetaManipulation>)> Data
15-
=> _data.Select(kvp => (kvp.Key, (IReadOnlySet<Utf8GamePath>)kvp.Value.Item1, (IReadOnlySet<MetaManipulation>)kvp.Value.Item2));
14+
public IEnumerable<(IMod, IReadOnlySet<Utf8GamePath>, IReadOnlySet<IMetaIdentifier>)> Data
15+
=> _data.Select(kvp => (kvp.Key, (IReadOnlySet<Utf8GamePath>)kvp.Value.Item1, (IReadOnlySet<IMetaIdentifier>)kvp.Value.Item2));
1616

17-
public (IReadOnlyCollection<Utf8GamePath> Paths, IReadOnlyCollection<MetaManipulation> Manipulations) RemoveMod(IMod mod)
17+
public (IReadOnlyCollection<Utf8GamePath> Paths, IReadOnlyCollection<IMetaIdentifier> Manipulations) RemoveMod(IMod mod)
1818
{
1919
if (_data.Remove(mod, out var data))
2020
return data;
@@ -35,7 +35,7 @@ public void AddPath(IMod mod, Utf8GamePath path)
3535
}
3636
}
3737

38-
public void AddManip(IMod mod, MetaManipulation manipulation)
38+
public void AddManip(IMod mod, IMetaIdentifier manipulation)
3939
{
4040
if (_data.TryGetValue(mod, out var data))
4141
{
@@ -54,7 +54,7 @@ public void RemovePath(IMod mod, Utf8GamePath path)
5454
_data.Remove(mod);
5555
}
5656

57-
public void RemoveManip(IMod mod, MetaManipulation manip)
57+
public void RemoveManip(IMod mod, IMetaIdentifier manip)
5858
{
5959
if (_data.TryGetValue(mod, out var data) && data.Item2.Remove(manip) && data.Item1.Count == 0 && data.Item2.Count == 0)
6060
_data.Remove(mod);

0 commit comments

Comments
 (0)