Rework DalamudServices,

This commit is contained in:
Ottermandias 2023-12-20 18:47:30 +01:00
parent d8f5851e0c
commit f022d2be64
19 changed files with 230 additions and 250 deletions

View file

@ -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<IntPtr, int> 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)

View file

@ -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<string, string[]>?[] GetGameObjectResourcePaths(ushort[] gameObjects)
{
var characters = gameObjects.Select(index => _dalamud.Objects[index]).OfType<Character>();
var characters = gameObjects.Select(index => _objects[index]).OfType<Character>();
var resourceTrees = _resourceTreeFactory.FromCharacters(characters, 0);
var pathDictionaries = ResourceTreeApiHelper.GetResourcePathDictionaries(resourceTrees);
@ -1055,7 +1060,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
public IReadOnlyDictionary<nint, (string, string, ChangedItemIcon)>?[] GetGameObjectResourcesOfType(ResourceType type, bool withUIData,
params ushort[] gameObjects)
{
var characters = gameObjects.Select(index => _dalamud.Objects[index]).OfType<Character>();
var characters = gameObjects.Select(index => _objects[index]).OfType<Character>();
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<Character>();
var characters = gameObjects.Select(index => _objects[index]).OfType<Character>();
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<T>(resolvedPath);
return _dalamud.GameData.GetFile<T>(resolvedPath);
return _gameData.GetFile<T>(resolvedPath);
}
catch (Exception e)
{

View file

@ -15,7 +15,6 @@ using CurrentSettings = ValueTuple<PenumbraApiEc, (bool, int, IDictionary<string
public class PenumbraIpcProviders : IDisposable
{
internal readonly IPenumbraApi Api;
internal readonly IpcTester Tester;
// Plugin State
internal readonly EventProvider Initialized;
@ -133,10 +132,9 @@ public class PenumbraIpcProviders : IDisposable
internal readonly FuncProvider<bool, ushort[], Ipc.ResourceTree?[]> GetGameObjectResourceTrees;
internal readonly FuncProvider<bool, IReadOnlyDictionary<ushort, Ipc.ResourceTree>> 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();