From a3fe0d2d2634680635539c9217371c88035af8f5 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Wed, 11 Oct 2023 03:14:45 +0200 Subject: [PATCH] Add LLib --- .gitmodules | 3 + Deliveroo.sln | 6 ++ Deliveroo/Deliveroo.csproj | 6 +- Deliveroo/External/DalamudReflector.cs | 113 -------------------- Deliveroo/External/ExternalPluginHandler.cs | 1 + Deliveroo/External/YesAlreadyIpc.cs | 2 +- Deliveroo/Windows/ConfigWindow.cs | 3 + Deliveroo/Windows/TurnInWindow.cs | 3 + Deliveroo/packages.lock.json | 3 + LLib | 1 + 10 files changed, 26 insertions(+), 115 deletions(-) create mode 100644 .gitmodules delete mode 100644 Deliveroo/External/DalamudReflector.cs create mode 160000 LLib diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9124e51 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "LLib"] + path = LLib + url = git@git.carvel.li:liza/LLib.git diff --git a/Deliveroo.sln b/Deliveroo.sln index 0bc9a1a..75d8fb9 100644 --- a/Deliveroo.sln +++ b/Deliveroo.sln @@ -2,6 +2,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Deliveroo", "Deliveroo\Deliveroo.csproj", "{978F4598-921A-4F9D-A975-1463D3BA96C3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LLib", "LLib\LLib.csproj", "{B4EFA106-69ED-4E45-8646-425C0708CBAC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +14,9 @@ Global {978F4598-921A-4F9D-A975-1463D3BA96C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {978F4598-921A-4F9D-A975-1463D3BA96C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {978F4598-921A-4F9D-A975-1463D3BA96C3}.Release|Any CPU.Build.0 = Release|Any CPU + {B4EFA106-69ED-4E45-8646-425C0708CBAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4EFA106-69ED-4E45-8646-425C0708CBAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4EFA106-69ED-4E45-8646-425C0708CBAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4EFA106-69ED-4E45-8646-425C0708CBAC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Deliveroo/Deliveroo.csproj b/Deliveroo/Deliveroo.csproj index 33e0ec2..6a063a6 100644 --- a/Deliveroo/Deliveroo.csproj +++ b/Deliveroo/Deliveroo.csproj @@ -11,6 +11,7 @@ true true portable + $(SolutionDir)=X:\ @@ -21,6 +22,10 @@ $(DALAMUD_HOME)/ + + + + @@ -52,7 +57,6 @@ - diff --git a/Deliveroo/External/DalamudReflector.cs b/Deliveroo/External/DalamudReflector.cs deleted file mode 100644 index 83747ac..0000000 --- a/Deliveroo/External/DalamudReflector.cs +++ /dev/null @@ -1,113 +0,0 @@ -using Dalamud.Plugin; -using System; -using System.Collections.Generic; -using System.Reflection; -using Dalamud.Plugin.Services; - -namespace Deliveroo.External; - -/// -/// Originally part of ECommons by NightmareXIV. -/// -/// https://github.com/NightmareXIV/ECommons/blob/master/ECommons/Reflection/DalamudReflector.cs -/// -internal sealed class DalamudReflector : IDisposable -{ - private readonly DalamudPluginInterface _pluginInterface; - private readonly IFramework _framework; - private readonly IPluginLog _pluginLog; - private readonly Dictionary _pluginCache = new(); - private bool _pluginsChanged = false; - - public DalamudReflector(DalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog) - { - _pluginInterface = pluginInterface; - _framework = framework; - _pluginLog = pluginLog; - var pm = GetPluginManager(); - pm.GetType().GetEvent("OnInstalledPluginsChanged")!.AddEventHandler(pm, OnInstalledPluginsChanged); - - _framework.Update += FrameworkUpdate; - } - - public void Dispose() - { - _framework.Update -= FrameworkUpdate; - - var pm = GetPluginManager(); - pm.GetType().GetEvent("OnInstalledPluginsChanged")!.RemoveEventHandler(pm, OnInstalledPluginsChanged); - } - - private void FrameworkUpdate(IFramework framework) - { - if (_pluginsChanged) - { - _pluginsChanged = false; - _pluginCache.Clear(); - } - } - - private object GetPluginManager() - { - return _pluginInterface.GetType().Assembly.GetType("Dalamud.Service`1", true)! - .MakeGenericType( - _pluginInterface.GetType().Assembly.GetType("Dalamud.Plugin.Internal.PluginManager", true)!) - .GetMethod("Get")!.Invoke(null, BindingFlags.Default, null, Array.Empty(), null)!; - } - - public bool TryGetDalamudPlugin(string internalName, out IDalamudPlugin? instance, bool suppressErrors = false, - bool ignoreCache = false) - { - if (!ignoreCache && _pluginCache.TryGetValue(internalName, out instance)) - { - return true; - } - - try - { - var pluginManager = GetPluginManager(); - var installedPlugins = - (System.Collections.IList)pluginManager.GetType().GetProperty("InstalledPlugins")!.GetValue( - pluginManager)!; - - foreach (var t in installedPlugins) - { - if ((string?)t.GetType().GetProperty("Name")!.GetValue(t) == internalName) - { - var type = t.GetType().Name == "LocalDevPlugin" ? t.GetType().BaseType : t.GetType(); - var plugin = (IDalamudPlugin?)type! - .GetField("instance", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(t); - if (plugin == null) - { - _pluginLog.Warning($"[DalamudReflector] Found requested plugin {internalName} but it was null"); - } - else - { - instance = plugin; - _pluginCache[internalName] = plugin; - return true; - } - } - } - - instance = null; - return false; - } - catch (Exception e) - { - if (!suppressErrors) - { - _pluginLog.Error(e, $"Can't find {internalName} plugin: {e.Message}"); - } - - instance = null; - return false; - } - } - - private void OnInstalledPluginsChanged() - { - _pluginLog.Verbose("Installed plugins changed event fired"); - _pluginsChanged = true; - } -} diff --git a/Deliveroo/External/ExternalPluginHandler.cs b/Deliveroo/External/ExternalPluginHandler.cs index 3e8cd60..51a6d8d 100644 --- a/Deliveroo/External/ExternalPluginHandler.cs +++ b/Deliveroo/External/ExternalPluginHandler.cs @@ -1,5 +1,6 @@ using Dalamud.Plugin; using Dalamud.Plugin.Services; +using LLib; namespace Deliveroo.External; diff --git a/Deliveroo/External/YesAlreadyIpc.cs b/Deliveroo/External/YesAlreadyIpc.cs index 0de845f..1b7272e 100644 --- a/Deliveroo/External/YesAlreadyIpc.cs +++ b/Deliveroo/External/YesAlreadyIpc.cs @@ -1,5 +1,5 @@ using System.Reflection; -using Dalamud.Logging; +using LLib; namespace Deliveroo.External; diff --git a/Deliveroo/Windows/ConfigWindow.cs b/Deliveroo/Windows/ConfigWindow.cs index a0b9167..022afc8 100644 --- a/Deliveroo/Windows/ConfigWindow.cs +++ b/Deliveroo/Windows/ConfigWindow.cs @@ -11,6 +11,7 @@ using Dalamud.Plugin.Services; using Deliveroo.GameData; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using ImGuiNET; +using LLib; namespace Deliveroo.Windows; @@ -51,6 +52,8 @@ internal sealed class ConfigWindow : Window public override void Draw() { + LImGui.AddPatreonIcon(_pluginInterface); + if (_configuration.AddVentureIfNoItemToPurchaseSelected()) Save(); diff --git a/Deliveroo/Windows/TurnInWindow.cs b/Deliveroo/Windows/TurnInWindow.cs index 3deb53c..5fcee10 100644 --- a/Deliveroo/Windows/TurnInWindow.cs +++ b/Deliveroo/Windows/TurnInWindow.cs @@ -12,6 +12,7 @@ using Deliveroo.GameData; using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using ImGuiNET; +using LLib; namespace Deliveroo.Windows; @@ -90,6 +91,8 @@ internal sealed class TurnInWindow : Window public override void Draw() { + LImGui.AddPatreonIcon(_pluginInterface); + GrandCompany grandCompany = _plugin.GetGrandCompany(); if (grandCompany == GrandCompany.None) { diff --git a/Deliveroo/packages.lock.json b/Deliveroo/packages.lock.json index 6cf1c73..784f99f 100644 --- a/Deliveroo/packages.lock.json +++ b/Deliveroo/packages.lock.json @@ -7,6 +7,9 @@ "requested": "[2.1.12, )", "resolved": "2.1.12", "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" + }, + "llib": { + "type": "Project" } } } diff --git a/LLib b/LLib new file mode 160000 index 0000000..e7f5017 --- /dev/null +++ b/LLib @@ -0,0 +1 @@ +Subproject commit e7f5017cbfb0f52b767640cfd4eb1bc913df248c