From d9dc37c994b032cb6d68830b830b011e8ee89eb9 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 30 Apr 2023 10:48:07 +0200 Subject: [PATCH] Disable Meta Edits when mods are disabled. --- Penumbra/Interop/PathResolving/MetaState.cs | 8 +++++--- Penumbra/Interop/Services/DecalReverter.cs | 5 ++++- Penumbra/Interop/Services/MetaList.cs | 2 ++ Penumbra/Meta/MetaFileManager.cs | 13 +++++++------ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Penumbra/Interop/PathResolving/MetaState.cs b/Penumbra/Interop/PathResolving/MetaState.cs index 75985a31..656b00b6 100644 --- a/Penumbra/Interop/PathResolving/MetaState.cs +++ b/Penumbra/Interop/PathResolving/MetaState.cs @@ -45,6 +45,7 @@ public unsafe class MetaState : IDisposable [Signature(Sigs.HumanVTable, ScanType = ScanType.StaticAddress)] private readonly nint* _humanVTable = null!; + private readonly Configuration _config; private readonly CommunicatorService _communicator; private readonly PerformanceTracker _performance; private readonly CollectionResolver _collectionResolver; @@ -56,7 +57,7 @@ public unsafe class MetaState : IDisposable private DisposableContainer _characterBaseCreateMetaChanges = DisposableContainer.Empty; public MetaState(PerformanceTracker performance, CommunicatorService communicator, CollectionResolver collectionResolver, - ResourceService resources, GameEventManager gameEventManager, CharacterUtility characterUtility) + ResourceService resources, GameEventManager gameEventManager, CharacterUtility characterUtility, Configuration config) { _performance = performance; _communicator = communicator; @@ -64,6 +65,7 @@ public unsafe class MetaState : IDisposable _resources = resources; _gameEventManager = gameEventManager; _characterUtility = characterUtility; + _config = config; SignatureHelper.Initialise(this); _onModelLoadCompleteHook = Hook.FromAddress(_humanVTable[58], OnModelLoadCompleteDetour); _getEqpIndirectHook.Enable(); @@ -127,7 +129,7 @@ public unsafe class MetaState : IDisposable _communicator.CreatingCharacterBase.Invoke(_lastCreatedCollection.AssociatedGameObject, _lastCreatedCollection.ModCollection.Name, (nint)(&modelCharaId), customize, equipData); - var decal = new DecalReverter(_characterUtility, _resources, _lastCreatedCollection.ModCollection, UsesDecal(modelCharaId, equipData)); + var decal = new DecalReverter(_config, _characterUtility, _resources, _lastCreatedCollection.ModCollection, UsesDecal(modelCharaId, equipData)); var cmp = _lastCreatedCollection.ModCollection.TemporarilySetCmpFile(_characterUtility); _characterBaseCreateMetaChanges.Dispose(); // Should always be empty. _characterBaseCreateMetaChanges = new DisposableContainer(decal, cmp); @@ -254,7 +256,7 @@ public unsafe class MetaState : IDisposable var resolveData = _collectionResolver.IdentifyCollection((DrawObject*)human, true); using var cmp = resolveData.ModCollection.TemporarilySetCmpFile(_characterUtility); using var decals = - new DecalReverter(_characterUtility, _resources, resolveData.ModCollection, UsesDecal(0, data)); + new DecalReverter(_config, _characterUtility, _resources, resolveData.ModCollection, UsesDecal(0, data)); var ret = _changeCustomize.Original(human, data, skipEquipment); _inChangeCustomize = false; return ret; diff --git a/Penumbra/Interop/Services/DecalReverter.cs b/Penumbra/Interop/Services/DecalReverter.cs index cc9c6403..a0a8c84d 100644 --- a/Penumbra/Interop/Services/DecalReverter.cs +++ b/Penumbra/Interop/Services/DecalReverter.cs @@ -19,12 +19,15 @@ public sealed unsafe class DecalReverter : IDisposable private readonly Structs.TextureResourceHandle* _decal; private readonly Structs.TextureResourceHandle* _transparent; - public DecalReverter(CharacterUtility utility, ResourceService resources, ModCollection? collection, bool doDecal) + public DecalReverter(Configuration config, CharacterUtility utility, ResourceService resources, ModCollection? collection, bool doDecal) { _utility = utility; var ptr = _utility.Address; _decal = null; _transparent = null; + if (!config.EnableMods) + return; + if (doDecal) { var decalPath = collection?.ResolvePath(DecalPath)?.InternalName ?? DecalPath.Path; diff --git a/Penumbra/Interop/Services/MetaList.cs b/Penumbra/Interop/Services/MetaList.cs index 98471c5f..e2603f79 100644 --- a/Penumbra/Interop/Services/MetaList.cs +++ b/Penumbra/Interop/Services/MetaList.cs @@ -106,6 +106,8 @@ public unsafe class MetaList : IDisposable public sealed class MetaReverter : IDisposable { + public static readonly MetaReverter Disabled = new(null!) { Disposed = true }; + public readonly MetaList MetaList; public readonly nint Data; public readonly int Length; diff --git a/Penumbra/Meta/MetaFileManager.cs b/Penumbra/Meta/MetaFileManager.cs index 30186768..8e764b14 100644 --- a/Penumbra/Meta/MetaFileManager.cs +++ b/Penumbra/Meta/MetaFileManager.cs @@ -5,7 +5,6 @@ using Dalamud.Data; using Dalamud.Utility.Signatures; using FFXIVClientStructs.FFXIV.Client.System.Memory; using Penumbra.Collections; -using Penumbra.Collections.Cache; using Penumbra.Collections.Manager; using Penumbra.GameData; using Penumbra.Import; @@ -66,12 +65,12 @@ public unsafe class MetaFileManager { Penumbra.Log.Error($"Error writing TexToolsMeta:\n{e}"); } - } + } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public void SetFile(MetaBaseFile? file, MetaIndex metaIndex) { - if (file == null) + if (file == null || !Config.EnableMods) CharacterUtility.ResetResource(metaIndex); else CharacterUtility.SetResource(metaIndex, (nint)file.Data, file.Length); @@ -79,9 +78,11 @@ public unsafe class MetaFileManager [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public MetaList.MetaReverter TemporarilySetFile(MetaBaseFile? file, MetaIndex metaIndex) - => file == null - ? CharacterUtility.TemporarilyResetResource(metaIndex) - : CharacterUtility.TemporarilySetResource(metaIndex, (nint)file.Data, file.Length); + => Config.EnableMods + ? file == null + ? CharacterUtility.TemporarilyResetResource(metaIndex) + : CharacterUtility.TemporarilySetResource(metaIndex, (nint)file.Data, file.Length) + : MetaList.MetaReverter.Disabled; public void ApplyDefaultFiles(ModCollection collection) {