From f022d2be6480f459e2163f8dc8bfff50c288636f Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Wed, 20 Dec 2023 18:47:30 +0100 Subject: [PATCH] Rework DalamudServices, --- OtterGui | 2 +- Penumbra/Api/IpcTester.cs | 85 ++++++++++--------- Penumbra/Api/PenumbraApi.cs | 47 +++++----- Penumbra/Api/PenumbraIpcProviders.cs | 8 +- Penumbra/Import/Textures/TexFileParser.cs | 6 +- .../ResourceLoading/CreateFileWHook.cs | 6 +- Penumbra/Penumbra.cs | 60 +++++++------ Penumbra/Penumbra.json | 2 +- Penumbra/Services/DalamudServices.cs | 81 +++++++----------- .../{ServiceManager.cs => ServiceManagerA.cs} | 74 ++++++---------- Penumbra/Services/ValidityChecker.cs | 2 +- .../ModEditWindow.Materials.MtrlTab.cs | 8 +- .../ModEditWindow.QuickImport.cs | 2 +- .../AdvancedWindow/ModEditWindow.Textures.cs | 2 +- Penumbra/UI/AdvancedWindow/ModEditWindow.cs | 20 +++-- Penumbra/UI/ModsTab/ModFileSystemSelector.cs | 4 +- Penumbra/UI/Tabs/Debug/DebugTab.cs | 24 +++--- Penumbra/UI/Tabs/SettingsTab.cs | 42 +++++---- Penumbra/packages.lock.json | 5 +- 19 files changed, 230 insertions(+), 250 deletions(-) rename Penumbra/Services/{ServiceManager.cs => ServiceManagerA.cs} (72%) diff --git a/OtterGui b/OtterGui index ac88abfe..197d23ee 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit ac88abfe9eb0bb5d03aec092dc8f4db642ecbd6a +Subproject commit 197d23eee167c232000f22ef40a7a2bded913b6c diff --git a/Penumbra/Api/IpcTester.cs b/Penumbra/Api/IpcTester.cs index f7b740b9..aea95156 100644 --- a/Penumbra/Api/IpcTester.cs +++ b/Penumbra/Api/IpcTester.cs @@ -40,23 +40,24 @@ public class IpcTester : IDisposable private readonly Temporary _temporary; private readonly ResourceTree _resourceTree; - public IpcTester(Configuration config, DalamudServices dalamud, PenumbraIpcProviders ipcProviders, ModManager modManager, - CollectionManager collections, TempModManager tempMods, TempCollectionManager tempCollections, SaveService saveService) + public IpcTester(Configuration config, DalamudPluginInterface pi, IObjectTable objects, IClientState clientState, + PenumbraIpcProviders ipcProviders, ModManager modManager, CollectionManager collections, TempModManager tempMods, + TempCollectionManager tempCollections, SaveService saveService) { _ipcProviders = ipcProviders; - _pluginState = new PluginState(dalamud.PluginInterface); - _ipcConfiguration = new IpcConfiguration(dalamud.PluginInterface); - _ui = new Ui(dalamud.PluginInterface); - _redrawing = new Redrawing(dalamud); - _gameState = new GameState(dalamud.PluginInterface); - _resolve = new Resolve(dalamud.PluginInterface); - _collections = new Collections(dalamud.PluginInterface); - _meta = new Meta(dalamud.PluginInterface); - _mods = new Mods(dalamud.PluginInterface); - _modSettings = new ModSettings(dalamud.PluginInterface); - _editing = new Editing(dalamud.PluginInterface); - _temporary = new Temporary(dalamud.PluginInterface, modManager, collections, tempMods, tempCollections, saveService, config); - _resourceTree = new ResourceTree(dalamud.PluginInterface, dalamud.Objects); + _pluginState = new PluginState(pi); + _ipcConfiguration = new IpcConfiguration(pi); + _ui = new Ui(pi); + _redrawing = new Redrawing(pi, objects, clientState); + _gameState = new GameState(pi); + _resolve = new Resolve(pi); + _collections = new Collections(pi); + _meta = new Meta(pi); + _mods = new Mods(pi); + _modSettings = new ModSettings(pi); + _editing = new Editing(pi); + _temporary = new Temporary(pi, modManager, collections, tempMods, tempCollections, saveService, config); + _resourceTree = new ResourceTree(pi, objects); UnsubscribeEvents(); } @@ -398,17 +399,21 @@ public class IpcTester : IDisposable private class Redrawing { - private readonly DalamudServices _dalamud; + private readonly DalamudPluginInterface _pi; + private readonly IClientState _clientState; + private readonly IObjectTable _objects; public readonly EventSubscriber Redrawn; private string _redrawName = string.Empty; private int _redrawIndex = 0; private string _lastRedrawnString = "None"; - public Redrawing(DalamudServices dalamud) + public Redrawing(DalamudPluginInterface pi, IObjectTable objects, IClientState clientState) { - _dalamud = dalamud; - Redrawn = Ipc.GameObjectRedrawn.Subscriber(_dalamud.PluginInterface, SetLastRedrawn); + _pi = pi; + _objects = objects; + _clientState = clientState; + Redrawn = Ipc.GameObjectRedrawn.Subscriber(_pi, SetLastRedrawn); } public void Draw() @@ -426,25 +431,25 @@ public class IpcTester : IDisposable ImGui.InputTextWithHint("##redrawName", "Name...", ref _redrawName, 32); ImGui.SameLine(); if (ImGui.Button("Redraw##Name")) - Ipc.RedrawObjectByName.Subscriber(_dalamud.PluginInterface).Invoke(_redrawName, RedrawType.Redraw); + Ipc.RedrawObjectByName.Subscriber(_pi).Invoke(_redrawName, RedrawType.Redraw); DrawIntro(Ipc.RedrawObject.Label, "Redraw Player Character"); - if (ImGui.Button("Redraw##pc") && _dalamud.ClientState.LocalPlayer != null) - Ipc.RedrawObject.Subscriber(_dalamud.PluginInterface).Invoke(_dalamud.ClientState.LocalPlayer, RedrawType.Redraw); + if (ImGui.Button("Redraw##pc") && _clientState.LocalPlayer != null) + Ipc.RedrawObject.Subscriber(_pi).Invoke(_clientState.LocalPlayer, RedrawType.Redraw); DrawIntro(Ipc.RedrawObjectByIndex.Label, "Redraw by Index"); var tmp = _redrawIndex; ImGui.SetNextItemWidth(100 * UiHelpers.Scale); - if (ImGui.DragInt("##redrawIndex", ref tmp, 0.1f, 0, _dalamud.Objects.Length)) - _redrawIndex = Math.Clamp(tmp, 0, _dalamud.Objects.Length); + if (ImGui.DragInt("##redrawIndex", ref tmp, 0.1f, 0, _objects.Length)) + _redrawIndex = Math.Clamp(tmp, 0, _objects.Length); ImGui.SameLine(); if (ImGui.Button("Redraw##Index")) - Ipc.RedrawObjectByIndex.Subscriber(_dalamud.PluginInterface).Invoke(_redrawIndex, RedrawType.Redraw); + Ipc.RedrawObjectByIndex.Subscriber(_pi).Invoke(_redrawIndex, RedrawType.Redraw); DrawIntro(Ipc.RedrawAll.Label, "Redraw All"); if (ImGui.Button("Redraw##All")) - Ipc.RedrawAll.Subscriber(_dalamud.PluginInterface).Invoke(RedrawType.Redraw); + Ipc.RedrawAll.Subscriber(_pi).Invoke(RedrawType.Redraw); DrawIntro(Ipc.GameObjectRedrawn.Label, "Last Redrawn Object:"); ImGui.TextUnformatted(_lastRedrawnString); @@ -453,12 +458,12 @@ public class IpcTester : IDisposable private void SetLastRedrawn(IntPtr address, int index) { if (index < 0 - || index > _dalamud.Objects.Length + || index > _objects.Length || address == IntPtr.Zero - || _dalamud.Objects[index]?.Address != address) + || _objects[index]?.Address != address) _lastRedrawnString = "Invalid"; - _lastRedrawnString = $"{_dalamud.Objects[index]!.Name} (0x{address:X}, {index})"; + _lastRedrawnString = $"{_objects[index]!.Name} (0x{address:X}, {index})"; } } @@ -1529,7 +1534,7 @@ public class IpcTester : IDisposable if (ImGui.Button("Get##GameObjectResourceTrees")) { var gameObjects = GetSelectedGameObjects(); - var subscriber = Ipc.GetGameObjectResourceTrees.Subscriber(_pi); + var subscriber = Ipc.GetGameObjectResourceTrees.Subscriber(_pi); _stopwatch.Restart(); var trees = subscriber.Invoke(_withUIData, gameObjects); @@ -1563,7 +1568,7 @@ public class IpcTester : IDisposable DrawPopup(nameof(Ipc.GetGameObjectResourcesOfType), ref _lastGameObjectResourcesOfType, DrawResourcesOfType, _lastCallDuration); DrawPopup(nameof(Ipc.GetPlayerResourcesOfType), ref _lastPlayerResourcesOfType, DrawResourcesOfType, _lastCallDuration); - DrawPopup(nameof(Ipc.GetGameObjectResourceTrees), ref _lastGameObjectResourceTrees, DrawResourceTrees, _lastCallDuration); + DrawPopup(nameof(Ipc.GetGameObjectResourceTrees), ref _lastGameObjectResourceTrees, DrawResourceTrees, _lastCallDuration); DrawPopup(nameof(Ipc.GetPlayerResourceTrees), ref _lastPlayerResourceTrees, DrawResourceTrees!, _lastCallDuration); } @@ -1695,9 +1700,10 @@ public class IpcTester : IDisposable { ImGui.TableSetupColumn("Type", ImGuiTableColumnFlags.WidthStretch, 0.5f); } - ImGui.TableSetupColumn("Game Path", ImGuiTableColumnFlags.WidthStretch, 0.5f); - ImGui.TableSetupColumn("Actual Path", ImGuiTableColumnFlags.WidthStretch, 0.5f); - ImGui.TableSetupColumn("Object Address", ImGuiTableColumnFlags.WidthStretch, 0.2f); + + ImGui.TableSetupColumn("Game Path", ImGuiTableColumnFlags.WidthStretch, 0.5f); + ImGui.TableSetupColumn("Actual Path", ImGuiTableColumnFlags.WidthStretch, 0.5f); + ImGui.TableSetupColumn("Object Address", ImGuiTableColumnFlags.WidthStretch, 0.2f); ImGui.TableSetupColumn("Resource Handle", ImGuiTableColumnFlags.WidthStretch, 0.2f); ImGui.TableHeadersRow(); @@ -1707,10 +1713,10 @@ public class IpcTester : IDisposable ImGui.TableNextColumn(); var hasChildren = node.Children.Any(); using var treeNode = ImRaii.TreeNode( - $"{(_withUIData ? (node.Name ?? "Unknown") : node.Type)}##{node.ObjectAddress:X8}", - hasChildren ? - ImGuiTreeNodeFlags.SpanFullWidth : - (ImGuiTreeNodeFlags.SpanFullWidth | ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.NoTreePushOnOpen)); + $"{(_withUIData ? node.Name ?? "Unknown" : node.Type)}##{node.ObjectAddress:X8}", + hasChildren + ? ImGuiTreeNodeFlags.SpanFullWidth + : ImGuiTreeNodeFlags.SpanFullWidth | ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.NoTreePushOnOpen); if (_withUIData) { ImGui.TableNextColumn(); @@ -1718,6 +1724,7 @@ public class IpcTester : IDisposable ImGui.TableNextColumn(); TextUnformattedMono(node.Icon.ToString()); } + ImGui.TableNextColumn(); ImGui.TextUnformatted(node.GamePath ?? "Unknown"); ImGui.TableNextColumn(); @@ -1728,10 +1735,8 @@ public class IpcTester : IDisposable TextUnformattedMono($"0x{node.ResourceHandle:X8}"); if (treeNode) - { foreach (var child in node.Children) DrawNode(child); - } } foreach (var node in tree.Nodes) diff --git a/Penumbra/Api/PenumbraApi.cs b/Penumbra/Api/PenumbraApi.cs index 97e69089..b7a46ae2 100644 --- a/Penumbra/Api/PenumbraApi.cs +++ b/Penumbra/Api/PenumbraApi.cs @@ -1,4 +1,5 @@ using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Plugin.Services; using Lumina.Data; using Newtonsoft.Json; using OtterGui; @@ -88,11 +89,13 @@ public class PenumbraApi : IDisposable, IPenumbraApi private CommunicatorService _communicator; private Lumina.GameData? _lumina; + private IDataManager _gameData; + private IFramework _framework; + private IObjectTable _objects; private ModManager _modManager; private ResourceLoader _resourceLoader; private Configuration _config; private CollectionManager _collectionManager; - private DalamudServices _dalamud; private TempCollectionManager _tempCollections; private TempModManager _tempMods; private ActorManager _actors; @@ -106,18 +109,20 @@ public class PenumbraApi : IDisposable, IPenumbraApi private TextureManager _textureManager; private ResourceTreeFactory _resourceTreeFactory; - public unsafe PenumbraApi(CommunicatorService communicator, ModManager modManager, ResourceLoader resourceLoader, - Configuration config, CollectionManager collectionManager, DalamudServices dalamud, TempCollectionManager tempCollections, - TempModManager tempMods, ActorManager actors, CollectionResolver collectionResolver, CutsceneService cutsceneService, - ModImportManager modImportManager, CollectionEditor collectionEditor, RedrawService redrawService, ModFileSystem modFileSystem, - ConfigWindow configWindow, TextureManager textureManager, ResourceTreeFactory resourceTreeFactory) + public unsafe PenumbraApi(CommunicatorService communicator, IDataManager gameData, IFramework framework, IObjectTable objects, + ModManager modManager, ResourceLoader resourceLoader, Configuration config, CollectionManager collectionManager, + TempCollectionManager tempCollections, TempModManager tempMods, ActorManager actors, CollectionResolver collectionResolver, + CutsceneService cutsceneService, ModImportManager modImportManager, CollectionEditor collectionEditor, RedrawService redrawService, + ModFileSystem modFileSystem, ConfigWindow configWindow, TextureManager textureManager, ResourceTreeFactory resourceTreeFactory) { _communicator = communicator; + _gameData = gameData; + _framework = framework; + _objects = objects; _modManager = modManager; _resourceLoader = resourceLoader; _config = config; _collectionManager = collectionManager; - _dalamud = dalamud; _tempCollections = tempCollections; _tempMods = tempMods; _actors = actors; @@ -130,7 +135,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi _configWindow = configWindow; _textureManager = textureManager; _resourceTreeFactory = resourceTreeFactory; - _lumina = _dalamud.GameData.GameData; + _lumina = gameData.GameData; _resourceLoader.ResourceLoaded += OnResourceLoaded; _communicator.ModPathChanged.Subscribe(ModPathChangeSubscriber, ModPathChanged.Priority.Api); @@ -153,7 +158,6 @@ public class PenumbraApi : IDisposable, IPenumbraApi _resourceLoader = null!; _config = null!; _collectionManager = null!; - _dalamud = null!; _tempCollections = null!; _tempMods = null!; _actors = null!; @@ -166,6 +170,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi _configWindow = null!; _textureManager = null!; _resourceTreeFactory = null!; + _framework = null!; } public event ChangedItemClick? ChangedItemClicked @@ -399,7 +404,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi return await Task.Run(async () => { - var playerCollection = await _dalamud.Framework.RunOnFrameworkThread(_collectionResolver.PlayerCollection).ConfigureAwait(false); + var playerCollection = await _framework.RunOnFrameworkThread(_collectionResolver.PlayerCollection).ConfigureAwait(false); var forwardTask = Task.Run(() => { var forwardRet = new string[forward.Length]; @@ -851,7 +856,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi { CheckInitialized(); - if (!ActorManager.VerifyPlayerName(character.AsSpan()) || tag.Length == 0) + if (!ActorIdentifierFactory.VerifyPlayerName(character.AsSpan()) || tag.Length == 0) return (PenumbraApiEc.InvalidArgument, string.Empty); var identifier = NameToIdentifier(character, ushort.MaxValue); @@ -889,10 +894,10 @@ public class PenumbraApi : IDisposable, IPenumbraApi { CheckInitialized(); - if (actorIndex < 0 || actorIndex >= _dalamud.Objects.Length) + if (actorIndex < 0 || actorIndex >= _objects.Length) return PenumbraApiEc.InvalidArgument; - var identifier = _actors.FromObject(_dalamud.Objects[actorIndex], false, false, true); + var identifier = _actors.FromObject(_objects[actorIndex], false, false, true); if (!identifier.IsValid) return PenumbraApiEc.InvalidArgument; @@ -1037,7 +1042,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi public IReadOnlyDictionary?[] GetGameObjectResourcePaths(ushort[] gameObjects) { - var characters = gameObjects.Select(index => _dalamud.Objects[index]).OfType(); + var characters = gameObjects.Select(index => _objects[index]).OfType(); var resourceTrees = _resourceTreeFactory.FromCharacters(characters, 0); var pathDictionaries = ResourceTreeApiHelper.GetResourcePathDictionaries(resourceTrees); @@ -1055,7 +1060,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi public IReadOnlyDictionary?[] GetGameObjectResourcesOfType(ResourceType type, bool withUIData, params ushort[] gameObjects) { - var characters = gameObjects.Select(index => _dalamud.Objects[index]).OfType(); + var characters = gameObjects.Select(index => _objects[index]).OfType(); var resourceTrees = _resourceTreeFactory.FromCharacters(characters, withUIData ? ResourceTreeFactory.Flags.WithUiData : 0); var resDictionaries = ResourceTreeApiHelper.GetResourcesOfType(resourceTrees, type); @@ -1074,7 +1079,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi public Ipc.ResourceTree?[] GetGameObjectResourceTrees(bool withUIData, params ushort[] gameObjects) { - var characters = gameObjects.Select(index => _dalamud.Objects[index]).OfType(); + var characters = gameObjects.Select(index => _objects[index]).OfType(); var resourceTrees = _resourceTreeFactory.FromCharacters(characters, withUIData ? ResourceTreeFactory.Flags.WithUiData : 0); var resDictionary = ResourceTreeApiHelper.EncapsulateResourceTrees(resourceTrees); @@ -1126,10 +1131,10 @@ public class PenumbraApi : IDisposable, IPenumbraApi private unsafe bool AssociatedCollection(int gameObjectIdx, out ModCollection collection) { collection = _collectionManager.Active.Default; - if (gameObjectIdx < 0 || gameObjectIdx >= _dalamud.Objects.Length) + if (gameObjectIdx < 0 || gameObjectIdx >= _objects.Length) return false; - var ptr = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)_dalamud.Objects.GetObjectAddress(gameObjectIdx); + var ptr = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)_objects.GetObjectAddress(gameObjectIdx); var data = _collectionResolver.IdentifyCollection(ptr, false); if (data.Valid) collection = data.ModCollection; @@ -1140,10 +1145,10 @@ public class PenumbraApi : IDisposable, IPenumbraApi [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] private unsafe ActorIdentifier AssociatedIdentifier(int gameObjectIdx) { - if (gameObjectIdx < 0 || gameObjectIdx >= _dalamud.Objects.Length) + if (gameObjectIdx < 0 || gameObjectIdx >= _objects.Length) return ActorIdentifier.Invalid; - var ptr = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)_dalamud.Objects.GetObjectAddress(gameObjectIdx); + var ptr = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)_objects.GetObjectAddress(gameObjectIdx); return _actors.FromObject(ptr, out _, false, true, true); } @@ -1168,7 +1173,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi if (Path.IsPathRooted(resolvedPath)) return _lumina?.GetFileFromDisk(resolvedPath); - return _dalamud.GameData.GetFile(resolvedPath); + return _gameData.GetFile(resolvedPath); } catch (Exception e) { diff --git a/Penumbra/Api/PenumbraIpcProviders.cs b/Penumbra/Api/PenumbraIpcProviders.cs index a564588b..1df90dd9 100644 --- a/Penumbra/Api/PenumbraIpcProviders.cs +++ b/Penumbra/Api/PenumbraIpcProviders.cs @@ -15,7 +15,6 @@ using CurrentSettings = ValueTuple GetGameObjectResourceTrees; internal readonly FuncProvider> GetPlayerResourceTrees; - public PenumbraIpcProviders(DalamudServices dalamud, IPenumbraApi api, ModManager modManager, CollectionManager collections, + public PenumbraIpcProviders(DalamudPluginInterface pi, IPenumbraApi api, ModManager modManager, CollectionManager collections, TempModManager tempMods, TempCollectionManager tempCollections, SaveService saveService, Configuration config) { - var pi = dalamud.PluginInterface; Api = api; // Plugin State @@ -260,15 +258,11 @@ public class PenumbraIpcProviders : IDisposable GetGameObjectResourceTrees = Ipc.GetGameObjectResourceTrees.Provider(pi, Api.GetGameObjectResourceTrees); GetPlayerResourceTrees = Ipc.GetPlayerResourceTrees.Provider(pi, Api.GetPlayerResourceTrees); - Tester = new IpcTester(config, dalamud, this, modManager, collections, tempMods, tempCollections, saveService); - Initialized.Invoke(); } public void Dispose() { - Tester.Dispose(); - // Plugin State Initialized.Dispose(); ApiVersion.Dispose(); diff --git a/Penumbra/Import/Textures/TexFileParser.cs b/Penumbra/Import/Textures/TexFileParser.cs index 629cdff5..6f854022 100644 --- a/Penumbra/Import/Textures/TexFileParser.cs +++ b/Penumbra/Import/Textures/TexFileParser.cs @@ -44,8 +44,8 @@ public static class TexFileParser if (offset == 0) return i; - var requiredSize = width * height * bits / 8; - if (offset + requiredSize > data.Length) + var Size = width * height * bits / 8; + if (offset + Size > data.Length) return i; var diff = offset - lastOffset; @@ -55,7 +55,7 @@ public static class TexFileParser width = Math.Max(width / 2, minSize); height = Math.Max(height / 2, minSize); lastOffset = offset; - lastSize = requiredSize; + lastSize = Size; } return 13; diff --git a/Penumbra/Interop/ResourceLoading/CreateFileWHook.cs b/Penumbra/Interop/ResourceLoading/CreateFileWHook.cs index b77ac1e0..7d94b1d5 100644 --- a/Penumbra/Interop/ResourceLoading/CreateFileWHook.cs +++ b/Penumbra/Interop/ResourceLoading/CreateFileWHook.cs @@ -13,7 +13,7 @@ namespace Penumbra.Interop.ResourceLoading; /// public unsafe class CreateFileWHook : IDisposable { - public const int RequiredSize = 28; + public const int Size = 28; public CreateFileWHook(IGameInteropProvider interop) { @@ -57,8 +57,8 @@ public unsafe class CreateFileWHook : IDisposable ptr[22] = (byte)(l >> 16); ptr[24] = (byte)(l >> 24); - ptr[RequiredSize - 2] = 0; - ptr[RequiredSize - 1] = 0; + ptr[Size - 2] = 0; + ptr[Size - 1] = 0; } public void Dispose() diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 9be40e66..900d2770 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -1,10 +1,9 @@ using Dalamud.Plugin; -using Dalamud.Plugin.Services; using ImGuiNET; using Lumina.Excel.GeneratedSheets; -using Microsoft.Extensions.DependencyInjection; using OtterGui; using OtterGui.Log; +using OtterGui.Services; using Penumbra.Api; using Penumbra.Api.Enums; using Penumbra.Collections; @@ -19,7 +18,6 @@ using Penumbra.UI.Tabs; using ChangedItemClick = Penumbra.Communication.ChangedItemClick; using ChangedItemHover = Penumbra.Communication.ChangedItemHover; using OtterGui.Tasks; -using Penumbra.GameData.Data; using Penumbra.GameData.Enums; using Penumbra.Interop.Structs; using Penumbra.UI; @@ -48,40 +46,40 @@ public class Penumbra : IDalamudPlugin private PenumbraWindowSystem? _windowSystem; private bool _disposed; - private readonly ServiceProvider _services; + private readonly ServiceManager _services; public Penumbra(DalamudPluginInterface pluginInterface) { try { - _services = ServiceManager.CreateProvider(this, pluginInterface, Log); - Messager = _services.GetRequiredService(); - _validityChecker = _services.GetRequiredService(); - var startup = _services.GetRequiredService().GetDalamudConfig(DalamudServices.WaitingForPluginsOption, out bool s) + _services = ServiceManagerA.CreateProvider(this, pluginInterface, Log); + Messager = _services.GetService(); + _validityChecker = _services.GetService(); + var startup = _services.GetService().GetDalamudConfig(DalamudConfigService.WaitingForPluginsOption, out bool s) ? s.ToString() : "Unknown"; Log.Information( $"Loading Penumbra Version {_validityChecker.Version}, Commit #{_validityChecker.CommitHash} with Waiting For Plugins: {startup}..."); - _services.GetRequiredService(); // Initialize because not required anywhere else. - _config = _services.GetRequiredService(); - _characterUtility = _services.GetRequiredService(); - _tempMods = _services.GetRequiredService(); - _residentResources = _services.GetRequiredService(); - _services.GetRequiredService(); // Initialize because not required anywhere else. - _modManager = _services.GetRequiredService(); - _collectionManager = _services.GetRequiredService(); - _tempCollections = _services.GetRequiredService(); - _redrawService = _services.GetRequiredService(); - _communicatorService = _services.GetRequiredService(); - _services.GetRequiredService(); // Initialize because not required anywhere else. - _services.GetRequiredService(); // Initialize because not required anywhere else. - _services.GetRequiredService(); // Initialize because not required anywhere else. + _services.GetService(); // Initialize because not required anywhere else. + _config = _services.GetService(); + _characterUtility = _services.GetService(); + _tempMods = _services.GetService(); + _residentResources = _services.GetService(); + _services.GetService(); // Initialize because not required anywhere else. + _modManager = _services.GetService(); + _collectionManager = _services.GetService(); + _tempCollections = _services.GetService(); + _redrawService = _services.GetService(); + _communicatorService = _services.GetService(); + _services.GetService(); // Initialize because not required anywhere else. + _services.GetService(); // Initialize because not required anywhere else. + _services.GetService(); // Initialize because not required anywhere else. _collectionManager.Caches.CreateNecessaryCaches(); - _services.GetRequiredService(); + _services.GetService(); - _services.GetRequiredService(); + _services.GetService(); - _services.GetRequiredService(); // Initialize before Interface. + _services.GetService(); // Initialize before Interface. SetupInterface(); SetupApi(); @@ -104,8 +102,8 @@ public class Penumbra : IDalamudPlugin private void SetupApi() { - var api = _services.GetRequiredService(); - _services.GetRequiredService(); + var api = _services.GetService(); + _services.GetService(); _communicatorService.ChangedItemHover.Subscribe(it => { if (it is (Item, FullEquipType)) @@ -123,9 +121,9 @@ public class Penumbra : IDalamudPlugin { AsyncTask.Run(() => { - var system = _services.GetRequiredService(); - system.Window.Setup(this, _services.GetRequiredService()); - _services.GetRequiredService(); + var system = _services.GetService(); + system.Window.Setup(this, _services.GetService()); + _services.GetService(); if (!_disposed) _windowSystem = system; else @@ -194,7 +192,7 @@ public class Penumbra : IDalamudPlugin sb.Append($"> **`Auto-Deduplication: `** {_config.AutoDeduplicateOnImport}\n"); sb.Append($"> **`Debug Mode: `** {_config.DebugMode}\n"); sb.Append( - $"> **`Synchronous Load (Dalamud): `** {(_services.GetRequiredService().GetDalamudConfig(DalamudServices.WaitingForPluginsOption, out bool v) ? v.ToString() : "Unknown")}\n"); + $"> **`Synchronous Load (Dalamud): `** {(_services.GetService().GetDalamudConfig(DalamudConfigService.WaitingForPluginsOption, out bool v) ? v.ToString() : "Unknown")}\n"); sb.Append( $"> **`Logging: `** Log: {_config.Ephemeral.EnableResourceLogging}, Watcher: {_config.Ephemeral.EnableResourceWatcher} ({_config.MaxResourceWatcherRecords})\n"); sb.Append($"> **`Use Ownership: `** {_config.UseOwnerNameForCharacterCollection}\n"); diff --git a/Penumbra/Penumbra.json b/Penumbra/Penumbra.json index d1682985..28dbc90d 100644 --- a/Penumbra/Penumbra.json +++ b/Penumbra/Penumbra.json @@ -9,7 +9,7 @@ "Tags": [ "modding" ], "DalamudApiLevel": 9, "LoadPriority": 69420, - "LoadRequiredState": 2, + "LoadState": 2, "LoadSync": true, "IconUrl": "https://raw.githubusercontent.com/xivdev/Penumbra/master/images/icon.png" } diff --git a/Penumbra/Services/DalamudServices.cs b/Penumbra/Services/DalamudServices.cs index 99539c39..51fb1192 100644 --- a/Penumbra/Services/DalamudServices.cs +++ b/Penumbra/Services/DalamudServices.cs @@ -5,15 +5,15 @@ using Dalamud.IoC; using Dalamud.Plugin; using Dalamud.Interface.DragDrop; using Dalamud.Plugin.Services; -using Microsoft.Extensions.DependencyInjection; +using OtterGui.Services; // ReSharper disable AutoPropertyCanBeMadeGetOnly.Local namespace Penumbra.Services; -public class DalamudServices +public class DalamudConfigService { - public DalamudServices(DalamudPluginInterface pluginInterface) + public DalamudConfigService(DalamudPluginInterface pluginInterface) { pluginInterface.Inject(this); try @@ -52,55 +52,6 @@ public class DalamudServices } } - public void AddServices(IServiceCollection services) - { - services.AddSingleton(PluginInterface); - services.AddSingleton(Commands); - services.AddSingleton(GameData); - services.AddSingleton(ClientState); - services.AddSingleton(Chat); - services.AddSingleton(Framework); - services.AddSingleton(Conditions); - services.AddSingleton(Targets); - services.AddSingleton(Objects); - services.AddSingleton(TitleScreenMenu); - services.AddSingleton(GameGui); - services.AddSingleton(KeyState); - services.AddSingleton(SigScanner); - services.AddSingleton(this); - services.AddSingleton(UiBuilder); - services.AddSingleton(DragDropManager); - services.AddSingleton(TextureProvider); - services.AddSingleton(TextureSubstitutionProvider); - services.AddSingleton(Interop); - services.AddSingleton(Log); - } - - // TODO remove static - // @formatter:off - [PluginService][RequiredVersion("1.0")] public DalamudPluginInterface PluginInterface { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public ICommandManager Commands { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IDataManager GameData { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IClientState ClientState { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IChatGui Chat { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IFramework Framework { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public ICondition Conditions { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public ITargetManager Targets { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IObjectTable Objects { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public ITitleScreenMenu TitleScreenMenu { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IGameGui GameGui { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IKeyState KeyState { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public ISigScanner SigScanner { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IDragDropManager DragDropManager { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public ITextureProvider TextureProvider { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public ITextureSubstitutionProvider TextureSubstitutionProvider { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IGameInteropProvider Interop { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public IPluginLog Log { get; private set; } = null!; - // @formatter:on - - public UiBuilder UiBuilder - => PluginInterface.UiBuilder; - public const string WaitingForPluginsOption = "IsResumeGameAfterPluginLoad"; private readonly object? _dalamudConfig; @@ -164,3 +115,29 @@ public class DalamudServices } } } + +public static class DalamudServices +{ + public static void AddServices(ServiceManager services, DalamudPluginInterface pi) + { + services.AddExistingService(pi); + services.AddExistingService(pi.UiBuilder); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + services.AddDalamudService(pi); + } +} diff --git a/Penumbra/Services/ServiceManager.cs b/Penumbra/Services/ServiceManagerA.cs similarity index 72% rename from Penumbra/Services/ServiceManager.cs rename to Penumbra/Services/ServiceManagerA.cs index 30f58701..410acfb9 100644 --- a/Penumbra/Services/ServiceManager.cs +++ b/Penumbra/Services/ServiceManagerA.cs @@ -7,11 +7,10 @@ using OtterGui.Services; using Penumbra.Api; using Penumbra.Collections.Cache; using Penumbra.Collections.Manager; -using Penumbra.GameData; using Penumbra.GameData.Actors; using Penumbra.GameData.Data; using Penumbra.GameData.DataContainers; -using Penumbra.GameData.DataContainers.Bases; +using Penumbra.GameData.Structs; using Penumbra.Import.Textures; using Penumbra.Interop.PathResolving; using Penumbra.Interop.ResourceLoading; @@ -33,14 +32,13 @@ using ResidentResourceManager = Penumbra.Interop.Services.ResidentResourceManage namespace Penumbra.Services; -public static class ServiceManager +public static class ServiceManagerA { - public static ServiceProvider CreateProvider(Penumbra penumbra, DalamudPluginInterface pi, Logger log) + public static ServiceManager CreateProvider(Penumbra penumbra, DalamudPluginInterface pi, Logger log) { - var services = new ServiceCollection() - .AddSingleton(log) - .AddSingleton(penumbra) - .AddDalamud(pi) + var services = new ServiceManager(log) + .AddExistingService(log) + .AddExistingService(penumbra) .AddMeta() .AddGameData() .AddInterop() @@ -51,37 +49,15 @@ public static class ServiceManager .AddResolvers() .AddInterface() .AddModEditor() - .AddApi() - .AddDataContainers() - .AddAsyncServices(); - - return services.BuildServiceProvider(new ServiceProviderOptions { ValidateOnBuild = true }); - } - - private static IServiceCollection AddDalamud(this IServiceCollection services, DalamudPluginInterface pi) - { - var dalamud = new DalamudServices(pi); - dalamud.AddServices(services); + .AddApi(); + services.AddIServices(typeof(EquipItem).Assembly); + services.AddIServices(typeof(Penumbra).Assembly); + DalamudServices.AddServices(services, pi); + services.CreateProvider(); return services; } - private static IServiceCollection AddDataContainers(this IServiceCollection services) - { - foreach (var type in typeof(IDataContainer).Assembly.GetExportedTypes() - .Where(t => t is { IsAbstract: false, IsInterface: false } && t.IsAssignableTo(typeof(IDataContainer)))) - services.AddSingleton(type); - return services; - } - - private static IServiceCollection AddAsyncServices(this IServiceCollection services) - { - foreach (var type in typeof(ActorManager).Assembly.GetExportedTypes() - .Where(t => t is { IsAbstract: false, IsInterface: false } && t.IsAssignableTo(typeof(IService)))) - services.AddSingleton(type); - return services; - } - - private static IServiceCollection AddMeta(this IServiceCollection services) + private static ServiceManager AddMeta(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton() @@ -89,15 +65,16 @@ public static class ServiceManager .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton(); - private static IServiceCollection AddGameData(this IServiceCollection services) + private static ServiceManager AddGameData(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton(); - private static IServiceCollection AddInterop(this IServiceCollection services) + private static ServiceManager AddInterop(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton() @@ -117,12 +94,12 @@ public static class ServiceManager .AddSingleton() .AddSingleton(); - private static IServiceCollection AddConfiguration(this IServiceCollection services) - => services.AddTransient() + private static ServiceManager AddConfiguration(this ServiceManager services) + => services.AddSingleton() .AddSingleton() .AddSingleton(); - private static IServiceCollection AddCollections(this IServiceCollection services) + private static ServiceManager AddCollections(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton() @@ -132,7 +109,7 @@ public static class ServiceManager .AddSingleton() .AddSingleton(); - private static IServiceCollection AddMods(this IServiceCollection services) + private static ServiceManager AddMods(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton() @@ -144,14 +121,14 @@ public static class ServiceManager .AddSingleton() .AddSingleton(s => (ModStorage)s.GetRequiredService()); - private static IServiceCollection AddResources(this IServiceCollection services) + private static ServiceManager AddResources(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton(); - private static IServiceCollection AddResolvers(this IServiceCollection services) + private static ServiceManager AddResolvers(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton() @@ -162,7 +139,7 @@ public static class ServiceManager .AddSingleton() .AddSingleton(); - private static IServiceCollection AddInterface(this IServiceCollection services) + private static ServiceManager AddInterface(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton() @@ -200,7 +177,7 @@ public static class ServiceManager .AddSingleton() .AddSingleton(p => new Diagnostics(p)); - private static IServiceCollection AddModEditor(this IServiceCollection services) + private static ServiceManager AddModEditor(this ServiceManager services) => services.AddSingleton() .AddSingleton() .AddSingleton() @@ -212,10 +189,11 @@ public static class ServiceManager .AddSingleton() .AddSingleton(); - private static IServiceCollection AddApi(this IServiceCollection services) + private static ServiceManager AddApi(this ServiceManager services) => services.AddSingleton() .AddSingleton(x => x.GetRequiredService()) .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton(); } diff --git a/Penumbra/Services/ValidityChecker.cs b/Penumbra/Services/ValidityChecker.cs index 0688850b..7287938c 100644 --- a/Penumbra/Services/ValidityChecker.cs +++ b/Penumbra/Services/ValidityChecker.cs @@ -15,7 +15,7 @@ public class ValidityChecker public readonly bool IsNotInstalledPenumbra; public readonly bool IsValidSourceRepo; - public readonly List ImcExceptions = new(); + public readonly List ImcExceptions = []; public readonly string Version; public readonly string CommitHash; diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Materials.MtrlTab.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Materials.MtrlTab.cs index 954e9b0f..09e22d67 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Materials.MtrlTab.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Materials.MtrlTab.cs @@ -103,7 +103,7 @@ public partial class ModEditWindow LoadedShpkPath = path; var data = LoadedShpkPath.IsRooted ? File.ReadAllBytes(LoadedShpkPath.FullName) - : _edit._dalamud.GameData.GetFile(LoadedShpkPath.InternalName.ToString())?.Data; + : _edit._gameData.GetFile(LoadedShpkPath.InternalName.ToString())?.Data; AssociatedShpk = data?.Length > 0 ? new ShpkFile(data) : throw new Exception("Failure to load file data."); LoadedShpkPathName = path.ToPath(); } @@ -457,13 +457,13 @@ public partial class ModEditWindow var foundMaterials = new HashSet(); foreach (var materialInfo in instances) { - var material = materialInfo.GetDrawObjectMaterial(_edit._dalamud.Objects); + var material = materialInfo.GetDrawObjectMaterial(_edit._objects); if (foundMaterials.Contains((nint)material)) continue; try { - MaterialPreviewers.Add(new LiveMaterialPreviewer(_edit._dalamud.Objects, materialInfo)); + MaterialPreviewers.Add(new LiveMaterialPreviewer(_edit._objects, materialInfo)); foundMaterials.Add((nint)material); } catch (InvalidOperationException) @@ -481,7 +481,7 @@ public partial class ModEditWindow { try { - ColorTablePreviewers.Add(new LiveColorTablePreviewer(_edit._dalamud.Objects, _edit._dalamud.Framework, materialInfo)); + ColorTablePreviewers.Add(new LiveColorTablePreviewer(_edit._objects, _edit._framework, materialInfo)); } catch (InvalidOperationException) { diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.QuickImport.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.QuickImport.cs index 64457c25..c9cd3d06 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.QuickImport.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.QuickImport.cs @@ -71,7 +71,7 @@ public partial class ModEditWindow } else { - var file = _dalamud.GameData.GetFile(path); + var file = _gameData.GetFile(path); writable = file == null ? null : new RawGameFileWritable(file); } diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs index a3b17848..e9facdf4 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs @@ -219,7 +219,7 @@ public partial class ModEditWindow if (tex.Path != path) return; - _dalamud.Framework.RunOnFrameworkThread(() => tex.Reload(_textures)); + _framework.RunOnFrameworkThread(() => tex.Reload(_textures)); }); } diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs index db9201ca..9b127fe4 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs @@ -36,7 +36,6 @@ public partial class ModEditWindow : Window, IDisposable private readonly ModEditor _editor; private readonly Configuration _config; private readonly ItemSwapTab _itemSwapTab; - private readonly DalamudServices _dalamud; private readonly MetaFileManager _metaFileManager; private readonly ActiveCollections _activeCollections; private readonly StainService _stainService; @@ -44,6 +43,9 @@ public partial class ModEditWindow : Window, IDisposable private readonly CommunicatorService _communicator; private readonly IDragDropManager _dragDropManager; private readonly GameEventManager _gameEvents; + private readonly IDataManager _gameData; + private readonly IFramework _framework; + private readonly IObjectTable _objects; private Mod? _mod; private Vector2 _iconSize = Vector2.Zero; @@ -562,37 +564,41 @@ public partial class ModEditWindow : Window, IDisposable public ModEditWindow(PerformanceTracker performance, FileDialogService fileDialog, ItemSwapTab itemSwapTab, IDataManager gameData, Configuration config, ModEditor editor, ResourceTreeFactory resourceTreeFactory, MetaFileManager metaFileManager, - StainService stainService, ActiveCollections activeCollections, DalamudServices dalamud, ModMergeTab modMergeTab, + StainService stainService, ActiveCollections activeCollections, ModMergeTab modMergeTab, CommunicatorService communicator, TextureManager textures, IDragDropManager dragDropManager, GameEventManager gameEvents, - ChangedItemDrawer changedItemDrawer) + ChangedItemDrawer changedItemDrawer, IObjectTable objects, IFramework framework) : base(WindowBaseLabel) { _performance = performance; _itemSwapTab = itemSwapTab; + _gameData = gameData; _config = config; _editor = editor; _metaFileManager = metaFileManager; _stainService = stainService; _activeCollections = activeCollections; - _dalamud = dalamud; _modMergeTab = modMergeTab; _communicator = communicator; _dragDropManager = dragDropManager; _textures = textures; _fileDialog = fileDialog; _gameEvents = gameEvents; + _objects = objects; + _framework = framework; _materialTab = new FileEditor(this, gameData, config, _editor.Compactor, _fileDialog, "Materials", ".mtrl", () => PopulateIsOnPlayer(_editor.Files.Mtrl, ResourceType.Mtrl), DrawMaterialPanel, () => _mod?.ModPath.FullName ?? string.Empty, (bytes, path, writable) => new MtrlTab(this, new MtrlFile(bytes), path, writable)); _modelTab = new FileEditor(this, gameData, config, _editor.Compactor, _fileDialog, "Models", ".mdl", - () => PopulateIsOnPlayer(_editor.Files.Mdl, ResourceType.Mdl), DrawModelPanel, () => _mod?.ModPath.FullName ?? string.Empty, (bytes, _, _) => new MdlFile(bytes)); + () => PopulateIsOnPlayer(_editor.Files.Mdl, ResourceType.Mdl), DrawModelPanel, () => _mod?.ModPath.FullName ?? string.Empty, + (bytes, _, _) => new MdlFile(bytes)); _shaderPackageTab = new FileEditor(this, gameData, config, _editor.Compactor, _fileDialog, "Shaders", ".shpk", - () => PopulateIsOnPlayer(_editor.Files.Shpk, ResourceType.Shpk), DrawShaderPackagePanel, () => _mod?.ModPath.FullName ?? string.Empty, + () => PopulateIsOnPlayer(_editor.Files.Shpk, ResourceType.Shpk), DrawShaderPackagePanel, + () => _mod?.ModPath.FullName ?? string.Empty, (bytes, _, _) => new ShpkTab(_fileDialog, bytes)); _center = new CombinedTexture(_left, _right); _textureSelectCombo = new TextureDrawer.PathSelectCombo(textures, editor, () => GetPlayerResourcesOfType(ResourceType.Tex)); _resourceTreeFactory = resourceTreeFactory; - _quickImportViewer = + _quickImportViewer = new ResourceTreeViewer(_config, resourceTreeFactory, changedItemDrawer, 2, OnQuickImportRefresh, DrawQuickImportActions); _communicator.ModPathChanged.Subscribe(OnModPathChanged, ModPathChanged.Priority.ModEditWindow); } diff --git a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs index cf65901e..8f12afbb 100644 --- a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs +++ b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs @@ -190,9 +190,9 @@ public sealed class ModFileSystemSelector : FileSystemSelector Label @@ -417,7 +421,7 @@ public class DebugTab : Window, ITab DrawSpecial("Current Card", _actors.GetCardPlayer()); DrawSpecial("Current Glamour", _actors.GetGlamourPlayer()); - foreach (var obj in _dalamud.Objects) + foreach (var obj in _objects) { ImGuiUtil.DrawTableColumn($"{((GameObject*)obj.Address)->ObjectIndex}"); ImGuiUtil.DrawTableColumn($"0x{obj.Address:X}"); @@ -827,7 +831,7 @@ public class DebugTab : Window, ITab /// Draw information about the models, materials and resources currently loaded by the local player. private unsafe void DrawPlayerModelInfo() { - var player = _dalamud.ClientState.LocalPlayer; + var player = _clientState.LocalPlayer; var name = player?.Name.ToString() ?? "NULL"; if (!ImGui.CollapsingHeader($"Player Model Info: {name}##Draw") || player == null) return; @@ -952,11 +956,11 @@ public class DebugTab : Window, ITab { if (!ImGui.CollapsingHeader("IPC")) { - _ipc.Tester.UnsubscribeEvents(); + _ipcTester.UnsubscribeEvents(); return; } - _ipc.Tester.Draw(); + _ipcTester.Draw(); } /// Helper to print a property and its value in a 2-column table. diff --git a/Penumbra/UI/Tabs/SettingsTab.cs b/Penumbra/UI/Tabs/SettingsTab.cs index 104f8d91..a03e7b87 100644 --- a/Penumbra/UI/Tabs/SettingsTab.cs +++ b/Penumbra/UI/Tabs/SettingsTab.cs @@ -1,5 +1,7 @@ using Dalamud.Interface; using Dalamud.Interface.Components; +using Dalamud.Plugin; +using Dalamud.Plugin.Services; using Dalamud.Utility; using ImGuiNET; using OtterGui; @@ -33,19 +35,23 @@ public class SettingsTab : ITab private readonly ModFileSystemSelector _selector; private readonly CharacterUtility _characterUtility; private readonly ResidentResourceManager _residentResources; - private readonly DalamudServices _dalamud; private readonly HttpApi _httpApi; private readonly DalamudSubstitutionProvider _dalamudSubstitutionProvider; private readonly FileCompactor _compactor; + private readonly DalamudConfigService _dalamudConfig; + private readonly DalamudPluginInterface _pluginInterface; + private readonly IDataManager _gameData; private int _minimumX = int.MaxValue; private int _minimumY = int.MaxValue; - public SettingsTab(Configuration config, FontReloader fontReloader, TutorialService tutorial, Penumbra penumbra, - FileDialogService fileDialog, ModManager modManager, ModFileSystemSelector selector, CharacterUtility characterUtility, - ResidentResourceManager residentResources, DalamudServices dalamud, ModExportManager modExportManager, HttpApi httpApi, - DalamudSubstitutionProvider dalamudSubstitutionProvider, FileCompactor compactor) + public SettingsTab(DalamudPluginInterface pluginInterface, Configuration config, FontReloader fontReloader, TutorialService tutorial, + Penumbra penumbra, FileDialogService fileDialog, ModManager modManager, ModFileSystemSelector selector, + CharacterUtility characterUtility, ResidentResourceManager residentResources, ModExportManager modExportManager, HttpApi httpApi, + DalamudSubstitutionProvider dalamudSubstitutionProvider, FileCompactor compactor, DalamudConfigService dalamudConfig, + IDataManager gameData) { + _pluginInterface = pluginInterface; _config = config; _fontReloader = fontReloader; _tutorial = tutorial; @@ -55,11 +61,12 @@ public class SettingsTab : ITab _selector = selector; _characterUtility = characterUtility; _residentResources = residentResources; - _dalamud = dalamud; _modExportManager = modExportManager; _httpApi = httpApi; _dalamudSubstitutionProvider = dalamudSubstitutionProvider; _compactor = compactor; + _dalamudConfig = dalamudConfig; + _gameData = gameData; if (_compactor.CanCompact) _compactor.Enabled = _config.UseFileSystemCompression; } @@ -164,14 +171,14 @@ public class SettingsTab : ITab if (IsSubPathOf(programFiles, newName) || IsSubPathOf(programFilesX86, newName)) return ("Path is not allowed to be in ProgramFiles.", false); - var dalamud = _dalamud.PluginInterface.ConfigDirectory.Parent!.Parent!; + var dalamud = _pluginInterface.ConfigDirectory.Parent!.Parent!; if (IsSubPathOf(dalamud.FullName, newName)) return ("Path is not allowed to be inside your Dalamud directories.", false); if (Functions.GetDownloadsFolder(out var downloads) && IsSubPathOf(downloads, newName)) return ("Path is not allowed to be inside your Downloads folder.", false); - var gameDir = _dalamud.GameData.GameData.DataPath.Parent!.Parent!.FullName; + var gameDir = _gameData.GameData.DataPath.Parent!.Parent!.FullName; if (IsSubPathOf(gameDir, newName)) return ("Path is not allowed to be inside your game folder.", false); @@ -368,21 +375,21 @@ public class SettingsTab : ITab v => { _config.HideUiWhenUiHidden = v; - _dalamud.UiBuilder.DisableUserUiHide = !v; + _pluginInterface.UiBuilder.DisableUserUiHide = !v; }); Checkbox("Hide Config Window when in Cutscenes", "Hide the Penumbra main window when you are currently watching a cutscene.", _config.HideUiInCutscenes, v => { - _config.HideUiInCutscenes = v; - _dalamud.UiBuilder.DisableCutsceneUiHide = !v; + _config.HideUiInCutscenes = v; + _pluginInterface.UiBuilder.DisableCutsceneUiHide = !v; }); Checkbox("Hide Config Window when in GPose", "Hide the Penumbra main window when you are currently in GPose mode.", _config.HideUiInGPose, v => { - _config.HideUiInGPose = v; - _dalamud.UiBuilder.DisableGposeUiHide = !v; + _config.HideUiInGPose = v; + _pluginInterface.UiBuilder.DisableGposeUiHide = !v; }); } @@ -847,7 +854,7 @@ public class SettingsTab : ITab /// Draw a checkbox that toggles the dalamud setting to wait for plugins on open. private void DrawWaitForPluginsReflection() { - if (!_dalamud.GetDalamudConfig(DalamudServices.WaitingForPluginsOption, out bool value)) + if (!_dalamudConfig.GetDalamudConfig(DalamudConfigService.WaitingForPluginsOption, out bool value)) { using var disabled = ImRaii.Disabled(); Checkbox("Wait for Plugins on Startup (Disabled, can not access Dalamud Configuration)", string.Empty, false, v => { }); @@ -855,9 +862,12 @@ public class SettingsTab : ITab else { Checkbox("Wait for Plugins on Startup", - "Some mods need to change files that are loaded once when the game starts and never afterwards.\nThis can cause issues with Penumbra loading after the files are already loaded.\nThis setting causes the game to wait until certain plugins have finished loading, making those mods work (in the base collection).\n\nThis changes a setting in the Dalamud Configuration found at /xlsettings -> General.", + "Some mods need to change files that are loaded once when the game starts and never afterwards.\n" + + "This can cause issues with Penumbra loading after the files are already loaded.\n" + + "This setting causes the game to wait until certain plugins have finished loading, making those mods work (in the base collection).\n\n" + + "This changes a setting in the Dalamud Configuration found at /xlsettings -> General.", value, - v => _dalamud.SetDalamudConfig(DalamudServices.WaitingForPluginsOption, v, "doWaitForPluginsOnStartup")); + v => _dalamudConfig.SetDalamudConfig(DalamudConfigService.WaitingForPluginsOption, v, "doWaitForPluginsOnStartup")); } } diff --git a/Penumbra/packages.lock.json b/Penumbra/packages.lock.json index 9172bb60..16353828 100644 --- a/Penumbra/packages.lock.json +++ b/Penumbra/packages.lock.json @@ -73,7 +73,10 @@ } }, "ottergui": { - "type": "Project" + "type": "Project", + "dependencies": { + "Microsoft.Extensions.DependencyInjection": "[7.0.0, )" + } }, "penumbra.api": { "type": "Project"