diff --git a/Penumbra/Collections/ModCollection.Cache.Access.cs b/Penumbra/Collections/ModCollection.Cache.Access.cs index 7597f7ca..a3e43afd 100644 --- a/Penumbra/Collections/ModCollection.Cache.Access.cs +++ b/Penumbra/Collections/ModCollection.Cache.Access.cs @@ -71,11 +71,11 @@ public partial class ModCollection internal SingleArray Conflicts(Mod mod) => _cache?.Conflicts(mod) ?? new SingleArray(); - public void SetFiles() + public void SetFiles(CharacterUtility utility) { if (_cache == null) { - Penumbra.CharacterUtility.ResetAll(); + utility.ResetAll(); } else { @@ -84,32 +84,32 @@ public partial class ModCollection } } - public void SetMetaFile(MetaIndex idx) + public void SetMetaFile(CharacterUtility utility, MetaIndex idx) { if (_cache == null) - Penumbra.CharacterUtility.ResetResource(idx); + utility.ResetResource(idx); else _cache.Meta.SetFile(idx); } // Used for short periods of changed files. - public MetaList.MetaReverter TemporarilySetEqdpFile(GenderRace genderRace, bool accessory) + public MetaList.MetaReverter TemporarilySetEqdpFile(CharacterUtility utility, GenderRace genderRace, bool accessory) => _cache?.Meta.TemporarilySetEqdpFile(genderRace, accessory) - ?? Penumbra.CharacterUtility.TemporarilyResetResource(Interop.Structs.CharacterUtilityData.EqdpIdx(genderRace, accessory)); + ?? utility.TemporarilyResetResource(Interop.Structs.CharacterUtilityData.EqdpIdx(genderRace, accessory)); - public MetaList.MetaReverter TemporarilySetEqpFile() + public MetaList.MetaReverter TemporarilySetEqpFile(CharacterUtility utility) => _cache?.Meta.TemporarilySetEqpFile() - ?? Penumbra.CharacterUtility.TemporarilyResetResource(MetaIndex.Eqp); + ?? utility.TemporarilyResetResource(MetaIndex.Eqp); - public MetaList.MetaReverter TemporarilySetGmpFile() + public MetaList.MetaReverter TemporarilySetGmpFile(CharacterUtility utility) => _cache?.Meta.TemporarilySetGmpFile() - ?? Penumbra.CharacterUtility.TemporarilyResetResource(MetaIndex.Gmp); + ?? utility.TemporarilyResetResource(MetaIndex.Gmp); - public MetaList.MetaReverter TemporarilySetCmpFile() + public MetaList.MetaReverter TemporarilySetCmpFile(CharacterUtility utility) => _cache?.Meta.TemporarilySetCmpFile() - ?? Penumbra.CharacterUtility.TemporarilyResetResource(MetaIndex.HumanCmp); + ?? utility.TemporarilyResetResource(MetaIndex.HumanCmp); - public MetaList.MetaReverter TemporarilySetEstFile(EstManipulation.EstType type) + public MetaList.MetaReverter TemporarilySetEstFile(CharacterUtility utility, EstManipulation.EstType type) => _cache?.Meta.TemporarilySetEstFile(type) - ?? Penumbra.CharacterUtility.TemporarilyResetResource((MetaIndex)type); + ?? utility.TemporarilyResetResource((MetaIndex)type); } \ No newline at end of file diff --git a/Penumbra/Interop/PathResolving/MetaState.cs b/Penumbra/Interop/PathResolving/MetaState.cs index 82dc3914..75985a31 100644 --- a/Penumbra/Interop/PathResolving/MetaState.cs +++ b/Penumbra/Interop/PathResolving/MetaState.cs @@ -45,18 +45,18 @@ public unsafe class MetaState : IDisposable [Signature(Sigs.HumanVTable, ScanType = ScanType.StaticAddress)] private readonly nint* _humanVTable = null!; - private readonly CommunicatorService _communicator; - private readonly PerformanceTracker _performance; - private readonly CollectionResolver _collectionResolver; - private readonly ResourceService _resources; - private readonly GameEventManager _gameEventManager; - private readonly Services.CharacterUtility _characterUtility; + private readonly CommunicatorService _communicator; + private readonly PerformanceTracker _performance; + private readonly CollectionResolver _collectionResolver; + private readonly ResourceService _resources; + private readonly GameEventManager _gameEventManager; + private readonly CharacterUtility _characterUtility; private ResolveData _lastCreatedCollection = ResolveData.Invalid; private DisposableContainer _characterBaseCreateMetaChanges = DisposableContainer.Empty; public MetaState(PerformanceTracker performance, CommunicatorService communicator, CollectionResolver collectionResolver, - ResourceService resources, GameEventManager gameEventManager, Services.CharacterUtility characterUtility) + ResourceService resources, GameEventManager gameEventManager, CharacterUtility characterUtility) { _performance = performance; _communicator = communicator; @@ -90,17 +90,17 @@ public unsafe class MetaState : IDisposable return false; } - public static DisposableContainer ResolveEqdpData(ModCollection collection, GenderRace race, bool equipment, bool accessory) + public DisposableContainer ResolveEqdpData(ModCollection collection, GenderRace race, bool equipment, bool accessory) { var races = race.Dependencies(); if (races.Length == 0) return DisposableContainer.Empty; var equipmentEnumerable = equipment - ? races.Select(r => collection.TemporarilySetEqdpFile(r, false)) + ? races.Select(r => collection.TemporarilySetEqdpFile(_characterUtility, r, false)) : Array.Empty().AsEnumerable(); var accessoryEnumerable = accessory - ? races.Select(r => collection.TemporarilySetEqdpFile(r, true)) + ? races.Select(r => collection.TemporarilySetEqdpFile(_characterUtility, r, true)) : Array.Empty().AsEnumerable(); return new DisposableContainer(equipmentEnumerable.Concat(accessoryEnumerable)); } @@ -128,7 +128,7 @@ public unsafe class MetaState : IDisposable _lastCreatedCollection.ModCollection.Name, (nint)(&modelCharaId), customize, equipData); var decal = new DecalReverter(_characterUtility, _resources, _lastCreatedCollection.ModCollection, UsesDecal(modelCharaId, equipData)); - var cmp = _lastCreatedCollection.ModCollection.TemporarilySetCmpFile(); + var cmp = _lastCreatedCollection.ModCollection.TemporarilySetCmpFile(_characterUtility); _characterBaseCreateMetaChanges.Dispose(); // Should always be empty. _characterBaseCreateMetaChanges = new DisposableContainer(decal, cmp); } @@ -149,7 +149,7 @@ public unsafe class MetaState : IDisposable private void OnModelLoadCompleteDetour(nint drawObject) { var collection = _collectionResolver.IdentifyCollection((DrawObject*)drawObject, true); - using var eqp = collection.ModCollection.TemporarilySetEqpFile(); + using var eqp = collection.ModCollection.TemporarilySetEqpFile(_characterUtility); using var eqdp = ResolveEqdpData(collection.ModCollection, GetDrawObjectGenderRace(drawObject), true, true); _onModelLoadCompleteHook.Original.Invoke(drawObject); } @@ -169,7 +169,7 @@ public unsafe class MetaState : IDisposable using var performance = _performance.Measure(PerformanceType.UpdateModels); var collection = _collectionResolver.IdentifyCollection((DrawObject*)drawObject, true); - using var eqp = collection.ModCollection.TemporarilySetEqpFile(); + using var eqp = collection.ModCollection.TemporarilySetEqpFile(_characterUtility); using var eqdp = ResolveEqdpData(collection.ModCollection, GetDrawObjectGenderRace(drawObject), true, true); _updateModelsHook.Original.Invoke(drawObject); } @@ -198,7 +198,7 @@ public unsafe class MetaState : IDisposable using var performance = _performance.Measure(PerformanceType.GetEqp); var resolveData = _collectionResolver.IdentifyCollection((DrawObject*)drawObject, true); - using var eqp = resolveData.ModCollection.TemporarilySetEqpFile(); + using var eqp = resolveData.ModCollection.TemporarilySetEqpFile(_characterUtility); _getEqpIndirectHook.Original(drawObject); } @@ -214,7 +214,7 @@ public unsafe class MetaState : IDisposable { using var performance = _performance.Measure(PerformanceType.SetupVisor); var resolveData = _collectionResolver.IdentifyCollection((DrawObject*)drawObject, true); - using var gmp = resolveData.ModCollection.TemporarilySetGmpFile(); + using var gmp = resolveData.ModCollection.TemporarilySetGmpFile(_characterUtility); return _setupVisorHook.Original(drawObject, modelId, visorState); } @@ -234,7 +234,7 @@ public unsafe class MetaState : IDisposable { using var performance = _performance.Measure(PerformanceType.SetupCharacter); var resolveData = _collectionResolver.IdentifyCollection((DrawObject*)drawObject, true); - using var cmp = resolveData.ModCollection.TemporarilySetCmpFile(); + using var cmp = resolveData.ModCollection.TemporarilySetCmpFile(_characterUtility); _rspSetupCharacterHook.Original(drawObject, unk2, unk3, unk4, unk5); } } @@ -252,11 +252,11 @@ public unsafe class MetaState : IDisposable using var performance = _performance.Measure(PerformanceType.ChangeCustomize); _inChangeCustomize = true; var resolveData = _collectionResolver.IdentifyCollection((DrawObject*)human, true); - using var cmp = resolveData.ModCollection.TemporarilySetCmpFile(); + using var cmp = resolveData.ModCollection.TemporarilySetCmpFile(_characterUtility); using var decals = new DecalReverter(_characterUtility, _resources, resolveData.ModCollection, UsesDecal(0, data)); var ret = _changeCustomize.Original(human, data, skipEquipment); - _inChangeCustomize = false; + _inChangeCustomize = false; return ret; } diff --git a/Penumbra/Interop/PathResolving/PathState.cs b/Penumbra/Interop/PathResolving/PathState.cs index 440aed32..de9d65ee 100644 --- a/Penumbra/Interop/PathResolving/PathState.cs +++ b/Penumbra/Interop/PathResolving/PathState.cs @@ -5,6 +5,7 @@ using System.Threading; using Dalamud.Utility.Signatures; using Penumbra.Collections; using Penumbra.GameData; +using Penumbra.Interop.Services; using Penumbra.String; namespace Penumbra.Interop.PathResolving; @@ -24,6 +25,8 @@ public unsafe class PathState : IDisposable private readonly nint* _monsterVTable = null!; public readonly CollectionResolver CollectionResolver; + public readonly MetaState MetaState; + public readonly CharacterUtility CharacterUtility; private readonly ResolvePathHooks _human; private readonly ResolvePathHooks _weapon; @@ -35,10 +38,12 @@ public unsafe class PathState : IDisposable public IList CurrentData => _resolveData.Values; - public PathState(CollectionResolver collectionResolver) + public PathState(CollectionResolver collectionResolver, MetaState metaState, CharacterUtility characterUtility) { SignatureHelper.Initialise(this); CollectionResolver = collectionResolver; + MetaState = metaState; + CharacterUtility = characterUtility; _human = new ResolvePathHooks(this, _humanVTable, ResolvePathHooks.Type.Human); _weapon = new ResolvePathHooks(this, _weaponVTable, ResolvePathHooks.Type.Weapon); _demiHuman = new ResolvePathHooks(this, _demiHumanVTable, ResolvePathHooks.Type.Other); @@ -59,7 +64,7 @@ public unsafe class PathState : IDisposable _monster.Dispose(); } - public bool Consume(ByteString path, out ResolveData collection) + public bool Consume(ByteString _, out ResolveData collection) { if (_resolveData.IsValueCreated) { diff --git a/Penumbra/Interop/PathResolving/ResolvePathHooks.cs b/Penumbra/Interop/PathResolving/ResolvePathHooks.cs index fab9fd92..609c131d 100644 --- a/Penumbra/Interop/PathResolving/ResolvePathHooks.cs +++ b/Penumbra/Interop/PathResolving/ResolvePathHooks.cs @@ -144,7 +144,7 @@ public unsafe class ResolvePathHooks : IDisposable var data = _parent.CollectionResolver.IdentifyCollection((DrawObject*)drawObject, true); using var eqdp = modelType > 9 ? DisposableContainer.Empty - : MetaState.ResolveEqdpData(data.ModCollection, MetaState.GetHumanGenderRace(drawObject), modelType < 5, modelType > 4); + : _parent.MetaState.ResolveEqdpData(data.ModCollection, MetaState.GetHumanGenderRace(drawObject), modelType < 5, modelType > 4); return ResolvePath(data, _resolveMdlPathHook.Original(drawObject, path, unk3, modelType)); } @@ -175,10 +175,10 @@ public unsafe class ResolvePathHooks : IDisposable private DisposableContainer GetEstChanges(nint drawObject, out ResolveData data) { data = _parent.CollectionResolver.IdentifyCollection((DrawObject*)drawObject, true); - return new DisposableContainer(data.ModCollection.TemporarilySetEstFile(EstManipulation.EstType.Face), - data.ModCollection.TemporarilySetEstFile(EstManipulation.EstType.Body), - data.ModCollection.TemporarilySetEstFile(EstManipulation.EstType.Hair), - data.ModCollection.TemporarilySetEstFile(EstManipulation.EstType.Head)); + return new DisposableContainer(data.ModCollection.TemporarilySetEstFile(_parent.CharacterUtility, EstManipulation.EstType.Face), + data.ModCollection.TemporarilySetEstFile(_parent.CharacterUtility, EstManipulation.EstType.Body), + data.ModCollection.TemporarilySetEstFile(_parent.CharacterUtility, EstManipulation.EstType.Hair), + data.ModCollection.TemporarilySetEstFile(_parent.CharacterUtility, EstManipulation.EstType.Head)); } private nint ResolveDecalWeapon(nint drawObject, nint path, nint unk3, uint unk4) diff --git a/Penumbra/Interop/Services/MetaList.cs b/Penumbra/Interop/Services/MetaList.cs index c0c38ff4..98471c5f 100644 --- a/Penumbra/Interop/Services/MetaList.cs +++ b/Penumbra/Interop/Services/MetaList.cs @@ -89,7 +89,7 @@ public unsafe class MetaList : IDisposable => SetResourceInternal(_defaultResourceData, _defaultResourceSize); private void SetResourceToDefaultCollection() - => _utility.Active.Default.SetMetaFile(GlobalMetaIndex); + => _utility.Active.Default.SetMetaFile(_utility, GlobalMetaIndex); public void Dispose() { diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 4892f5d9..d4c867ab 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -33,8 +33,6 @@ public class Penumbra : IDalamudPlugin public static Logger Log { get; private set; } = null!; public static ChatService ChatService { get; private set; } = null!; - public static CharacterUtility CharacterUtility { get; private set; } = null!; - public readonly RedrawService RedrawService; public readonly ModFileSystem ModFileSystem; public HttpApi HttpApi = null!; @@ -64,7 +62,6 @@ public class Penumbra : IDalamudPlugin _tmp.Services.GetRequiredService(); _config = _tmp.Services.GetRequiredService(); _characterUtility = _tmp.Services.GetRequiredService(); - CharacterUtility = _characterUtility; _tempMods = _tmp.Services.GetRequiredService(); _residentResources = _tmp.Services.GetRequiredService(); _tmp.Services.GetRequiredService(); @@ -149,7 +146,7 @@ public class Penumbra : IDalamudPlugin { if (_characterUtility.Ready) { - _collectionManager.Active.Default.SetFiles(); + _collectionManager.Active.Default.SetFiles(_characterUtility); _residentResources.Reload(); RedrawService.RedrawAll(RedrawType.Redraw); }