From f978b35b764fac7037f72f9ffa6f60dc2cd7bf13 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 19 Jul 2024 14:24:29 +0200 Subject: [PATCH] Make ResourceTrees work with UseNoMods. --- Penumbra.GameData | 2 +- Penumbra/Collections/Cache/MetaCache.cs | 4 ---- .../Collections/ModCollection.Cache.Access.cs | 9 --------- Penumbra/Import/Models/ModelManager.cs | 6 ++++-- .../ResourceTree/ResolveContext.PathResolution.cs | 15 ++++++++------- Penumbra/Interop/ResourceTree/ResolveContext.cs | 10 ++++++++-- .../Interop/ResourceTree/ResourceTreeFactory.cs | 4 +++- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/Penumbra.GameData b/Penumbra.GameData index c5ad1f3a..a1e637f8 160000 --- a/Penumbra.GameData +++ b/Penumbra.GameData @@ -1 +1 @@ -Subproject commit c5ad1f3ae9818baa446327bdcf49fac65088c703 +Subproject commit a1e637f835c1a42732825e8e0690aeef0024b101 diff --git a/Penumbra/Collections/Cache/MetaCache.cs b/Penumbra/Collections/Cache/MetaCache.cs index 02056fad..1a6924a9 100644 --- a/Penumbra/Collections/Cache/MetaCache.cs +++ b/Penumbra/Collections/Cache/MetaCache.cs @@ -103,10 +103,6 @@ public class MetaCache(MetaFileManager manager, ModCollection collection) ~MetaCache() => Dispose(); - /// Try to obtain a manipulated IMC file. - public bool GetImcFile(Utf8GamePath path, [NotNullWhen(true)] out Meta.Files.ImcFile? file) - => Imc.GetFile(path.Path, out file); - internal EqdpEntry GetEqdpEntry(GenderRace race, bool accessory, PrimaryId primaryId) => Eqdp.ApplyFullEntry(primaryId, race, accessory, Meta.Files.ExpandedEqdpFile.GetDefault(manager, race, accessory, primaryId)); diff --git a/Penumbra/Collections/ModCollection.Cache.Access.cs b/Penumbra/Collections/ModCollection.Cache.Access.cs index 81751128..983509a4 100644 --- a/Penumbra/Collections/ModCollection.Cache.Access.cs +++ b/Penumbra/Collections/ModCollection.Cache.Access.cs @@ -43,15 +43,6 @@ public partial class ModCollection internal MetaCache? MetaCache => _cache?.Meta; - public bool GetImcFile(Utf8GamePath path, [NotNullWhen(true)] out ImcFile? file) - { - if (_cache != null) - return _cache.Meta.GetImcFile(path, out file); - - file = null; - return false; - } - internal IReadOnlyDictionary ResolvedFiles => _cache?.ResolvedFiles ?? new ConcurrentDictionary(); diff --git a/Penumbra/Import/Models/ModelManager.cs b/Penumbra/Import/Models/ModelManager.cs index 01396cfb..0c19bc0a 100644 --- a/Penumbra/Import/Models/ModelManager.cs +++ b/Penumbra/Import/Models/ModelManager.cs @@ -12,6 +12,8 @@ using Penumbra.GameData.Structs; using Penumbra.Import.Models.Export; using Penumbra.Import.Models.Import; using Penumbra.Import.Textures; +using Penumbra.Meta; +using Penumbra.Meta.Files; using Penumbra.Meta.Manipulations; using SharpGLTF.Scenes; using SixLabors.ImageSharp; @@ -22,7 +24,7 @@ namespace Penumbra.Import.Models; using Schema2 = SharpGLTF.Schema2; using LuminaMaterial = Lumina.Models.Materials.Material; -public sealed class ModelManager(IFramework framework, ActiveCollections collections, GamePathParser parser) +public sealed class ModelManager(IFramework framework, MetaFileManager metaFileManager, ActiveCollections collections, GamePathParser parser) : SingleTaskQueue, IDisposable, IService { private readonly IFramework _framework = framework; @@ -97,7 +99,7 @@ public sealed class ModelManager(IFramework framework, ActiveCollections collect // Try to use an entry from provided manipulations, falling back to the current collection. var targetId = modEst?.Value ?? collections.Current.MetaCache?.GetEstEntry(type, info.GenderRace, info.PrimaryId) - ?? EstEntry.Zero; + ?? EstFile.GetDefault(metaFileManager, type, info.GenderRace, info.PrimaryId); // If there's no entries, we can assume that there's no additional skeleton. if (targetId == EstEntry.Zero) diff --git a/Penumbra/Interop/ResourceTree/ResolveContext.PathResolution.cs b/Penumbra/Interop/ResourceTree/ResolveContext.PathResolution.cs index 72cb1681..07f305ac 100644 --- a/Penumbra/Interop/ResourceTree/ResolveContext.PathResolution.cs +++ b/Penumbra/Interop/ResourceTree/ResolveContext.PathResolution.cs @@ -3,6 +3,7 @@ using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle; using Penumbra.GameData.Data; using Penumbra.GameData.Enums; using Penumbra.GameData.Structs; +using Penumbra.Meta; using Penumbra.Meta.Files; using Penumbra.Meta.Manipulations; using Penumbra.String; @@ -51,10 +52,8 @@ internal partial record ResolveContext return GenderRace.MidlanderMale; var metaCache = Global.Collection.MetaCache; - if (metaCache == null) - return GenderRace.MidlanderMale; - - var entry = metaCache.GetEqdpEntry(characterRaceCode, accessory, primaryId); + var entry = metaCache?.GetEqdpEntry(characterRaceCode, accessory, primaryId) + ?? ExpandedEqdpFile.GetDefault(Global.MetaFileManager, characterRaceCode, accessory, primaryId); if (entry.ToBits(slot).Item2) return characterRaceCode; @@ -62,7 +61,8 @@ internal partial record ResolveContext if (fallbackRaceCode == GenderRace.MidlanderMale) return GenderRace.MidlanderMale; - entry = metaCache.GetEqdpEntry(fallbackRaceCode, accessory, primaryId); + entry = metaCache?.GetEqdpEntry(fallbackRaceCode, accessory, primaryId) + ?? ExpandedEqdpFile.GetDefault(Global.MetaFileManager, fallbackRaceCode, accessory, primaryId); if (entry.ToBits(slot).Item2) return fallbackRaceCode; @@ -271,8 +271,9 @@ internal partial record ResolveContext private (GenderRace RaceCode, string Slot, PrimaryId Set) ResolveHumanExtraSkeletonData(GenderRace raceCode, EstType type, PrimaryId primary) { - var metaCache = Global.Collection.MetaCache; - var skeletonSet = metaCache?.GetEstEntry(type, raceCode, primary) ?? default; + var metaCache = Global.Collection.MetaCache; + var skeletonSet = metaCache?.GetEstEntry(type, raceCode, primary) + ?? EstFile.GetDefault(Global.MetaFileManager, type, raceCode, primary); return (raceCode, type.ToName(), skeletonSet.AsId); } diff --git a/Penumbra/Interop/ResourceTree/ResolveContext.cs b/Penumbra/Interop/ResourceTree/ResolveContext.cs index a852a4cc..acb320d4 100644 --- a/Penumbra/Interop/ResourceTree/ResolveContext.cs +++ b/Penumbra/Interop/ResourceTree/ResolveContext.cs @@ -11,6 +11,7 @@ using Penumbra.GameData.Enums; using Penumbra.GameData.Structs; using Penumbra.Interop.Hooks.PostProcessing; using Penumbra.Interop.PathResolving; +using Penumbra.Meta; using Penumbra.String; using Penumbra.String.Classes; using Penumbra.UI; @@ -19,7 +20,12 @@ using ModelType = FFXIVClientStructs.FFXIV.Client.Graphics.Scene.CharacterBase.M namespace Penumbra.Interop.ResourceTree; -internal record GlobalResolveContext(ObjectIdentification Identifier, ModCollection Collection, TreeBuildCache TreeBuildCache, bool WithUiData) +internal record GlobalResolveContext( + MetaFileManager MetaFileManager, + ObjectIdentification Identifier, + ModCollection Collection, + TreeBuildCache TreeBuildCache, + bool WithUiData) { public readonly Dictionary<(Utf8GamePath, nint), ResourceNode> Nodes = new(128); @@ -111,7 +117,7 @@ internal unsafe partial record ResolveContext( if (resourceHandle == null) throw new ArgumentNullException(nameof(resourceHandle)); - var fileName = (ReadOnlySpan) resourceHandle->FileName.AsSpan(); + var fileName = (ReadOnlySpan)resourceHandle->FileName.AsSpan(); var additionalData = ByteString.Empty; if (PathDataHandler.Split(fileName, out fileName, out var data)) additionalData = ByteString.FromSpanUnsafe(data, false).Clone(); diff --git a/Penumbra/Interop/ResourceTree/ResourceTreeFactory.cs b/Penumbra/Interop/ResourceTree/ResourceTreeFactory.cs index 1f6d1f6f..46c7ce35 100644 --- a/Penumbra/Interop/ResourceTree/ResourceTreeFactory.cs +++ b/Penumbra/Interop/ResourceTree/ResourceTreeFactory.cs @@ -8,6 +8,7 @@ using Penumbra.GameData.Data; using Penumbra.GameData.Enums; using Penumbra.GameData.Interop; using Penumbra.Interop.PathResolving; +using Penumbra.Meta; using Penumbra.String.Classes; namespace Penumbra.Interop.ResourceTree; @@ -15,6 +16,7 @@ namespace Penumbra.Interop.ResourceTree; public class ResourceTreeFactory( IDataManager gameData, ObjectManager objects, + MetaFileManager metaFileManager, CollectionResolver resolver, ObjectIdentification identifier, Configuration config, @@ -78,7 +80,7 @@ public class ResourceTreeFactory( var networked = character.EntityId != 0xE0000000; var tree = new ResourceTree(name, anonymizedName, character.ObjectIndex, (nint)gameObjStruct, (nint)drawObjStruct, localPlayerRelated, related, networked, collectionResolveData.ModCollection.Name, collectionResolveData.ModCollection.AnonymizedName); - var globalContext = new GlobalResolveContext(identifier, collectionResolveData.ModCollection, + var globalContext = new GlobalResolveContext(metaFileManager, identifier, collectionResolveData.ModCollection, cache, (flags & Flags.WithUiData) != 0); using (var _ = pathState.EnterInternalResolve()) {