Hopefully fix all AllaganTools code

master v0.17
Liza 2024-06-06 22:01:06 +02:00
parent bb44f02ade
commit 2d21b37592
Signed by: liza
GPG Key ID: 7199F8D727D55F67
13 changed files with 79 additions and 58 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc;
using Dalamud.Plugin.Ipc.Exceptions; using Dalamud.Plugin.Ipc.Exceptions;
@ -21,7 +22,7 @@ internal sealed class AllaganToolsIpc : IDisposable
private ICharacterMonitor _characters; private ICharacterMonitor _characters;
private IInventoryMonitor _inventories; private IInventoryMonitor _inventories;
private IFilterService _filters; private IListService _lists;
public AllaganToolsIpc(DalamudPluginInterface pluginInterface, IChatGui chatGui, DalamudReflector dalamudReflector, public AllaganToolsIpc(DalamudPluginInterface pluginInterface, IChatGui chatGui, DalamudReflector dalamudReflector,
IFramework framework, IPluginLog pluginLog) IFramework framework, IPluginLog pluginLog)
@ -37,7 +38,7 @@ internal sealed class AllaganToolsIpc : IDisposable
_characters = new UnavailableCharacterMonitor(_pluginLog); _characters = new UnavailableCharacterMonitor(_pluginLog);
_inventories = new UnavailableInventoryMonitor(_pluginLog); _inventories = new UnavailableInventoryMonitor(_pluginLog);
_filters = new UnavailableFilterService(_pluginLog); _lists = new UnavailableListService(_pluginLog);
_initialized.Subscribe(ConfigureIpc); _initialized.Subscribe(ConfigureIpc);
@ -64,12 +65,27 @@ internal sealed class AllaganToolsIpc : IDisposable
{ {
if (_dalamudReflector.TryGetDalamudPlugin("Allagan Tools", out var it, false, true)) if (_dalamudReflector.TryGetDalamudPlugin("Allagan Tools", out var it, false, true))
{ {
var pluginService = it.GetType().Assembly.GetType("InventoryTools.PluginService")!; var pluginLoader = it.GetType()
.GetProperty("PluginLoader", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(it)!;
var host = pluginLoader.GetType().GetProperty("Host")!.GetValue(pluginLoader)!;
var serviceProvider = host.GetType().GetProperty("Services")!.GetValue(host)!;
var getServiceMethod = serviceProvider.GetType().GetMethod("GetService")!;
object GetService(Type t) => getServiceMethod.Invoke(serviceProvider, [t])!;
_characters = new CharacterMonitor(pluginService.GetProperty("CharacterMonitor")!.GetValue(null)!); var ccl = it.GetType()
.GetField("_service", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(it)!
.GetType()
.Assembly;
_characters =
new CharacterMonitor(GetService(ccl.GetType("CriticalCommonLib.Services.ICharacterMonitor")!));
_inventories = new InventoryMonitor( _inventories = new InventoryMonitor(
pluginService.GetProperty("InventoryMonitor")!.GetValue(null)!); GetService(ccl.GetType("CriticalCommonLib.Services.IInventoryMonitor")!));
_filters = new FilterService(pluginService.GetProperty("FilterService")!.GetValue(null)!); _lists = new ListService(
GetService(it.GetType().Assembly.GetType("InventoryTools.Services.Interfaces.IListService")!),
GetService(it.GetType().Assembly.GetType("InventoryTools.Lists.ListFilterService")!));
} }
else else
{ {
@ -97,11 +113,11 @@ internal sealed class AllaganToolsIpc : IDisposable
} }
} }
public Filter? GetFilter(string keyOrName) public FilterResult? GetFilter(string keyOrName)
{ {
try try
{ {
return _filters.GetFilterByKeyOrName(keyOrName); return _lists.GetFilterByKeyOrName(keyOrName);
} }
catch (IpcError e) catch (IpcError e)
{ {
@ -140,7 +156,7 @@ internal sealed class AllaganToolsIpc : IDisposable
_initialized.Unsubscribe(ConfigureIpc); _initialized.Unsubscribe(ConfigureIpc);
_characters = new UnavailableCharacterMonitor(_pluginLog); _characters = new UnavailableCharacterMonitor(_pluginLog);
_inventories = new UnavailableInventoryMonitor(_pluginLog); _inventories = new UnavailableInventoryMonitor(_pluginLog);
_filters = new UnavailableFilterService(_pluginLog); _lists = new UnavailableListService(_pluginLog);
} }
private sealed class InventoryWrapper(IEnumerable<InventoryItem> items) private sealed class InventoryWrapper(IEnumerable<InventoryItem> items)

View File

@ -16,8 +16,9 @@ internal sealed class CharacterMonitor : ICharacterMonitor
{ {
ArgumentNullException.ThrowIfNull(@delegate); ArgumentNullException.ThrowIfNull(@delegate);
_delegate = @delegate; _delegate = @delegate;
_getPlayerCharacters = _delegate.GetType().GetMethod("GetPlayerCharacters")!; _getPlayerCharacters =
_allCharacters = _delegate.GetType().GetMethod("AllCharacters")!; _delegate.GetType().GetMethod("GetPlayerCharacters") ?? throw new MissingMethodException();
_allCharacters = _delegate.GetType().GetMethod("AllCharacters") ?? throw new MissingMethodException();
} }
public IEnumerable<Character> PlayerCharacters => GetCharactersInternal(_getPlayerCharacters); public IEnumerable<Character> PlayerCharacters => GetCharactersInternal(_getPlayerCharacters);

View File

@ -7,23 +7,22 @@ using System.Threading.Tasks;
namespace Influx.AllaganTools; namespace Influx.AllaganTools;
internal sealed class Filter internal sealed class FilterResult
{ {
private readonly object _delegate; private readonly object _delegate;
private readonly MethodInfo _generateFilteredList; private readonly PropertyInfo _sortedItems;
public Filter(object @delegate) public FilterResult(object @delegate)
{ {
ArgumentNullException.ThrowIfNull(@delegate); ArgumentNullException.ThrowIfNull(@delegate);
_delegate = @delegate; _delegate = @delegate;
_generateFilteredList = _delegate.GetType().GetMethod("GenerateFilteredList")!; _sortedItems =
_delegate.GetType().GetProperty("SortedItems") ?? throw new MissingMemberException();
} }
public IReadOnlyList<SortingResult> GenerateFilteredList() public IReadOnlyList<SortingResult> GenerateFilteredList()
{ {
Task task = (Task)_generateFilteredList.Invoke(_delegate, new object?[] { null })!; return ((IEnumerable)_sortedItems.GetValue(_delegate)!)
object result = task.GetType().GetProperty("Result")!.GetValue(task)!;
return ((IEnumerable)result.GetType().GetProperty("SortedItems")!.GetValue(result)!)
.Cast<object>() .Cast<object>()
.Select(x => new SortingResult(x)) .Select(x => new SortingResult(x))
.ToList(); .ToList();

View File

@ -1,23 +0,0 @@
using System;
using System.Reflection;
namespace Influx.AllaganTools;
internal sealed class FilterService : IFilterService
{
private readonly object _delegate;
private readonly MethodInfo _getFilterByKeyOrName;
public FilterService(object @delegate)
{
ArgumentNullException.ThrowIfNull(@delegate);
_delegate = @delegate;
_getFilterByKeyOrName = _delegate.GetType().GetMethod("GetFilterByKeyOrName")!;
}
public Filter? GetFilterByKeyOrName(string keyOrName)
{
var f = _getFilterByKeyOrName.Invoke(_delegate, [keyOrName]);
return f != null ? new Filter(f) : null;
}
}

View File

@ -1,6 +0,0 @@
namespace Influx.AllaganTools;
internal interface IFilterService
{
Filter? GetFilterByKeyOrName(string keyOrName);
}

View File

@ -0,0 +1,6 @@
namespace Influx.AllaganTools;
internal interface IListService
{
FilterResult? GetFilterByKeyOrName(string keyOrName);
}

View File

@ -15,7 +15,7 @@ internal sealed class Inventory
{ {
ArgumentNullException.ThrowIfNull(@delegate); ArgumentNullException.ThrowIfNull(@delegate);
_delegate = @delegate; _delegate = @delegate;
_getAllInventories = _delegate.GetType().GetMethod("GetAllInventories")!; _getAllInventories = _delegate.GetType().GetMethod("GetAllInventories") ?? throw new MissingMethodException();
CharacterId = (ulong)_delegate.GetType().GetProperty("CharacterId")!.GetValue(_delegate)!; CharacterId = (ulong)_delegate.GetType().GetProperty("CharacterId")!.GetValue(_delegate)!;
} }

View File

@ -1,5 +1,5 @@
using System; using System;
using FFXIVClientStructs.FFXIV.Client.Game; using Dalamud.Logging;
namespace Influx.AllaganTools; namespace Influx.AllaganTools;
@ -10,7 +10,7 @@ internal sealed class InventoryItem
ArgumentNullException.ThrowIfNull(@delegate); ArgumentNullException.ThrowIfNull(@delegate);
Category = (int)@delegate.GetType().GetField("SortedCategory")!.GetValue(@delegate)!; Category = (int)@delegate.GetType().GetField("SortedCategory")!.GetValue(@delegate)!;
Container = (int)@delegate.GetType().GetField("SortedContainer")!.GetValue(@delegate)!; Container = (int)@delegate.GetType().GetField("SortedContainer")!.GetValue(@delegate)!;
ItemId = (uint)@delegate.GetType().GetField("ItemId")!.GetValue(@delegate)!; ItemId = (uint)@delegate.GetType().GetProperty("ItemId")!.GetValue(@delegate)!;
Quantity = (uint)@delegate.GetType().GetField("Quantity")!.GetValue(@delegate)!; Quantity = (uint)@delegate.GetType().GetField("Quantity")!.GetValue(@delegate)!;
} }

View File

@ -0,0 +1,28 @@
using System;
using System.Reflection;
namespace Influx.AllaganTools;
internal sealed class ListService : IListService
{
private readonly object _listService;
private readonly object _listFilterService;
private readonly MethodInfo _getListByKeyOrName;
private readonly MethodInfo _refreshList;
public ListService(object listService, object listFilterService)
{
ArgumentNullException.ThrowIfNull(listService);
_listService = listService;
_listFilterService = listFilterService;
_getListByKeyOrName =
_listService.GetType().GetMethod("GetListByKeyOrName") ?? throw new MissingMethodException();
_refreshList = _listFilterService.GetType().GetMethod("RefreshList") ?? throw new MissingMethodException();
}
public FilterResult? GetFilterByKeyOrName(string keyOrName)
{
var f = _getListByKeyOrName.Invoke(_listService, [keyOrName]);
return f != null ? new FilterResult(_refreshList.Invoke(_listFilterService, [f])!) : null;
}
}

View File

@ -13,7 +13,7 @@ internal sealed class SortingResult
Quantity = (int)@delegate.GetType().GetProperty("Quantity")!.GetValue(@delegate)!; Quantity = (int)@delegate.GetType().GetProperty("Quantity")!.GetValue(@delegate)!;
var inventoryItem = @delegate.GetType().GetProperty("InventoryItem")!.GetValue(@delegate)!; var inventoryItem = @delegate.GetType().GetProperty("InventoryItem")!.GetValue(@delegate)!;
ItemId = (uint)inventoryItem.GetType().GetField("ItemId")!.GetValue(inventoryItem)!; ItemId = (uint)inventoryItem.GetType().GetProperty("ItemId")!.GetValue(inventoryItem)!;
Flags = (ItemFlags)inventoryItem.GetType().GetField("Flags")!.GetValue(inventoryItem)!; Flags = (ItemFlags)inventoryItem.GetType().GetField("Flags")!.GetValue(inventoryItem)!;
} }

View File

@ -2,9 +2,9 @@
namespace Influx.AllaganTools; namespace Influx.AllaganTools;
internal sealed class UnavailableFilterService(IPluginLog pluginLog) : IFilterService internal sealed class UnavailableListService(IPluginLog pluginLog) : IListService
{ {
public Filter? GetFilterByKeyOrName(string keyOrName) public FilterResult? GetFilterByKeyOrName(string keyOrName)
{ {
pluginLog.Warning("Filter Service is unavailable"); pluginLog.Warning("Filter Service is unavailable");
return null; return null;

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<Version>0.16</Version> <Version>0.17</Version>
<LangVersion>12</LangVersion> <LangVersion>12</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
@ -25,7 +25,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12"/> <PackageReference Include="DalamudPackager" Version="2.1.12"/>
<PackageReference Include="InfluxDB.Client" Version="4.14.0" /> <PackageReference Include="InfluxDB.Client" Version="4.14.0" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.3" /> <PackageReference Include="Microsoft.Extensions.ObjectPool" Version="9.0.0-preview.1.24081.5" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -25,9 +25,9 @@
}, },
"Microsoft.Extensions.ObjectPool": { "Microsoft.Extensions.ObjectPool": {
"type": "Direct", "type": "Direct",
"requested": "[8.0.3, )", "requested": "[9.0.0-preview.1.24081.5, )",
"resolved": "8.0.3", "resolved": "9.0.0-preview.1.24081.5",
"contentHash": "sk/TGiccSeXUtVeBfFlWJnzp6xLlAxIW+bCHs7uVPLFPQk8vICNmu9Gc3JsKOn6fQuRkrPetQ8EHv4dCiMqhxg==" "contentHash": "aAR7YW+pUUdvHk3vj7GtAi71dWGDIuY9270lsmQ6lKw23zzY+r8pLP3cGNbJdlnA9VWl+S+gnIVkBCqj2ROlEg=="
}, },
"CsvHelper": { "CsvHelper": {
"type": "Transitive", "type": "Transitive",