Disable Meta Edits when mods are disabled.

This commit is contained in:
Ottermandias 2023-04-30 10:48:07 +02:00
parent 361244385f
commit d9dc37c994
4 changed files with 18 additions and 10 deletions

View file

@ -45,6 +45,7 @@ public unsafe class MetaState : IDisposable
[Signature(Sigs.HumanVTable, ScanType = ScanType.StaticAddress)] [Signature(Sigs.HumanVTable, ScanType = ScanType.StaticAddress)]
private readonly nint* _humanVTable = null!; private readonly nint* _humanVTable = null!;
private readonly Configuration _config;
private readonly CommunicatorService _communicator; private readonly CommunicatorService _communicator;
private readonly PerformanceTracker _performance; private readonly PerformanceTracker _performance;
private readonly CollectionResolver _collectionResolver; private readonly CollectionResolver _collectionResolver;
@ -56,7 +57,7 @@ public unsafe class MetaState : IDisposable
private DisposableContainer _characterBaseCreateMetaChanges = DisposableContainer.Empty; private DisposableContainer _characterBaseCreateMetaChanges = DisposableContainer.Empty;
public MetaState(PerformanceTracker performance, CommunicatorService communicator, CollectionResolver collectionResolver, public MetaState(PerformanceTracker performance, CommunicatorService communicator, CollectionResolver collectionResolver,
ResourceService resources, GameEventManager gameEventManager, CharacterUtility characterUtility) ResourceService resources, GameEventManager gameEventManager, CharacterUtility characterUtility, Configuration config)
{ {
_performance = performance; _performance = performance;
_communicator = communicator; _communicator = communicator;
@ -64,6 +65,7 @@ public unsafe class MetaState : IDisposable
_resources = resources; _resources = resources;
_gameEventManager = gameEventManager; _gameEventManager = gameEventManager;
_characterUtility = characterUtility; _characterUtility = characterUtility;
_config = config;
SignatureHelper.Initialise(this); SignatureHelper.Initialise(this);
_onModelLoadCompleteHook = Hook<OnModelLoadCompleteDelegate>.FromAddress(_humanVTable[58], OnModelLoadCompleteDetour); _onModelLoadCompleteHook = Hook<OnModelLoadCompleteDelegate>.FromAddress(_humanVTable[58], OnModelLoadCompleteDetour);
_getEqpIndirectHook.Enable(); _getEqpIndirectHook.Enable();
@ -127,7 +129,7 @@ public unsafe class MetaState : IDisposable
_communicator.CreatingCharacterBase.Invoke(_lastCreatedCollection.AssociatedGameObject, _communicator.CreatingCharacterBase.Invoke(_lastCreatedCollection.AssociatedGameObject,
_lastCreatedCollection.ModCollection.Name, (nint)(&modelCharaId), customize, equipData); _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); var cmp = _lastCreatedCollection.ModCollection.TemporarilySetCmpFile(_characterUtility);
_characterBaseCreateMetaChanges.Dispose(); // Should always be empty. _characterBaseCreateMetaChanges.Dispose(); // Should always be empty.
_characterBaseCreateMetaChanges = new DisposableContainer(decal, cmp); _characterBaseCreateMetaChanges = new DisposableContainer(decal, cmp);
@ -254,7 +256,7 @@ public unsafe class MetaState : IDisposable
var resolveData = _collectionResolver.IdentifyCollection((DrawObject*)human, true); var resolveData = _collectionResolver.IdentifyCollection((DrawObject*)human, true);
using var cmp = resolveData.ModCollection.TemporarilySetCmpFile(_characterUtility); using var cmp = resolveData.ModCollection.TemporarilySetCmpFile(_characterUtility);
using var decals = 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); var ret = _changeCustomize.Original(human, data, skipEquipment);
_inChangeCustomize = false; _inChangeCustomize = false;
return ret; return ret;

View file

@ -19,12 +19,15 @@ public sealed unsafe class DecalReverter : IDisposable
private readonly Structs.TextureResourceHandle* _decal; private readonly Structs.TextureResourceHandle* _decal;
private readonly Structs.TextureResourceHandle* _transparent; 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; _utility = utility;
var ptr = _utility.Address; var ptr = _utility.Address;
_decal = null; _decal = null;
_transparent = null; _transparent = null;
if (!config.EnableMods)
return;
if (doDecal) if (doDecal)
{ {
var decalPath = collection?.ResolvePath(DecalPath)?.InternalName ?? DecalPath.Path; var decalPath = collection?.ResolvePath(DecalPath)?.InternalName ?? DecalPath.Path;

View file

@ -106,6 +106,8 @@ public unsafe class MetaList : IDisposable
public sealed class MetaReverter : IDisposable public sealed class MetaReverter : IDisposable
{ {
public static readonly MetaReverter Disabled = new(null!) { Disposed = true };
public readonly MetaList MetaList; public readonly MetaList MetaList;
public readonly nint Data; public readonly nint Data;
public readonly int Length; public readonly int Length;

View file

@ -5,7 +5,6 @@ using Dalamud.Data;
using Dalamud.Utility.Signatures; using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.System.Memory; using FFXIVClientStructs.FFXIV.Client.System.Memory;
using Penumbra.Collections; using Penumbra.Collections;
using Penumbra.Collections.Cache;
using Penumbra.Collections.Manager; using Penumbra.Collections.Manager;
using Penumbra.GameData; using Penumbra.GameData;
using Penumbra.Import; using Penumbra.Import;
@ -66,12 +65,12 @@ public unsafe class MetaFileManager
{ {
Penumbra.Log.Error($"Error writing TexToolsMeta:\n{e}"); Penumbra.Log.Error($"Error writing TexToolsMeta:\n{e}");
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public void SetFile(MetaBaseFile? file, MetaIndex metaIndex) public void SetFile(MetaBaseFile? file, MetaIndex metaIndex)
{ {
if (file == null) if (file == null || !Config.EnableMods)
CharacterUtility.ResetResource(metaIndex); CharacterUtility.ResetResource(metaIndex);
else else
CharacterUtility.SetResource(metaIndex, (nint)file.Data, file.Length); CharacterUtility.SetResource(metaIndex, (nint)file.Data, file.Length);
@ -79,9 +78,11 @@ public unsafe class MetaFileManager
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public MetaList.MetaReverter TemporarilySetFile(MetaBaseFile? file, MetaIndex metaIndex) public MetaList.MetaReverter TemporarilySetFile(MetaBaseFile? file, MetaIndex metaIndex)
=> file == null => Config.EnableMods
? CharacterUtility.TemporarilyResetResource(metaIndex) ? file == null
: CharacterUtility.TemporarilySetResource(metaIndex, (nint)file.Data, file.Length); ? CharacterUtility.TemporarilyResetResource(metaIndex)
: CharacterUtility.TemporarilySetResource(metaIndex, (nint)file.Data, file.Length)
: MetaList.MetaReverter.Disabled;
public void ApplyDefaultFiles(ModCollection collection) public void ApplyDefaultFiles(ModCollection collection)
{ {