Hopefully fix all AllaganTools code
This commit is contained in:
parent
bb44f02ade
commit
2d21b37592
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Ipc;
|
||||
using Dalamud.Plugin.Ipc.Exceptions;
|
||||
@ -21,7 +22,7 @@ internal sealed class AllaganToolsIpc : IDisposable
|
||||
|
||||
private ICharacterMonitor _characters;
|
||||
private IInventoryMonitor _inventories;
|
||||
private IFilterService _filters;
|
||||
private IListService _lists;
|
||||
|
||||
public AllaganToolsIpc(DalamudPluginInterface pluginInterface, IChatGui chatGui, DalamudReflector dalamudReflector,
|
||||
IFramework framework, IPluginLog pluginLog)
|
||||
@ -37,7 +38,7 @@ internal sealed class AllaganToolsIpc : IDisposable
|
||||
|
||||
_characters = new UnavailableCharacterMonitor(_pluginLog);
|
||||
_inventories = new UnavailableInventoryMonitor(_pluginLog);
|
||||
_filters = new UnavailableFilterService(_pluginLog);
|
||||
_lists = new UnavailableListService(_pluginLog);
|
||||
|
||||
_initialized.Subscribe(ConfigureIpc);
|
||||
|
||||
@ -64,12 +65,27 @@ internal sealed class AllaganToolsIpc : IDisposable
|
||||
{
|
||||
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(
|
||||
pluginService.GetProperty("InventoryMonitor")!.GetValue(null)!);
|
||||
_filters = new FilterService(pluginService.GetProperty("FilterService")!.GetValue(null)!);
|
||||
GetService(ccl.GetType("CriticalCommonLib.Services.IInventoryMonitor")!));
|
||||
_lists = new ListService(
|
||||
GetService(it.GetType().Assembly.GetType("InventoryTools.Services.Interfaces.IListService")!),
|
||||
GetService(it.GetType().Assembly.GetType("InventoryTools.Lists.ListFilterService")!));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -97,11 +113,11 @@ internal sealed class AllaganToolsIpc : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public Filter? GetFilter(string keyOrName)
|
||||
public FilterResult? GetFilter(string keyOrName)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _filters.GetFilterByKeyOrName(keyOrName);
|
||||
return _lists.GetFilterByKeyOrName(keyOrName);
|
||||
}
|
||||
catch (IpcError e)
|
||||
{
|
||||
@ -140,7 +156,7 @@ internal sealed class AllaganToolsIpc : IDisposable
|
||||
_initialized.Unsubscribe(ConfigureIpc);
|
||||
_characters = new UnavailableCharacterMonitor(_pluginLog);
|
||||
_inventories = new UnavailableInventoryMonitor(_pluginLog);
|
||||
_filters = new UnavailableFilterService(_pluginLog);
|
||||
_lists = new UnavailableListService(_pluginLog);
|
||||
}
|
||||
|
||||
private sealed class InventoryWrapper(IEnumerable<InventoryItem> items)
|
||||
|
@ -16,8 +16,9 @@ internal sealed class CharacterMonitor : ICharacterMonitor
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(@delegate);
|
||||
_delegate = @delegate;
|
||||
_getPlayerCharacters = _delegate.GetType().GetMethod("GetPlayerCharacters")!;
|
||||
_allCharacters = _delegate.GetType().GetMethod("AllCharacters")!;
|
||||
_getPlayerCharacters =
|
||||
_delegate.GetType().GetMethod("GetPlayerCharacters") ?? throw new MissingMethodException();
|
||||
_allCharacters = _delegate.GetType().GetMethod("AllCharacters") ?? throw new MissingMethodException();
|
||||
}
|
||||
|
||||
public IEnumerable<Character> PlayerCharacters => GetCharactersInternal(_getPlayerCharacters);
|
||||
|
@ -7,23 +7,22 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Influx.AllaganTools;
|
||||
|
||||
internal sealed class Filter
|
||||
internal sealed class FilterResult
|
||||
{
|
||||
private readonly object _delegate;
|
||||
private readonly MethodInfo _generateFilteredList;
|
||||
private readonly PropertyInfo _sortedItems;
|
||||
|
||||
public Filter(object @delegate)
|
||||
public FilterResult(object @delegate)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(@delegate);
|
||||
_delegate = @delegate;
|
||||
_generateFilteredList = _delegate.GetType().GetMethod("GenerateFilteredList")!;
|
||||
_sortedItems =
|
||||
_delegate.GetType().GetProperty("SortedItems") ?? throw new MissingMemberException();
|
||||
}
|
||||
|
||||
public IReadOnlyList<SortingResult> GenerateFilteredList()
|
||||
{
|
||||
Task task = (Task)_generateFilteredList.Invoke(_delegate, new object?[] { null })!;
|
||||
object result = task.GetType().GetProperty("Result")!.GetValue(task)!;
|
||||
return ((IEnumerable)result.GetType().GetProperty("SortedItems")!.GetValue(result)!)
|
||||
return ((IEnumerable)_sortedItems.GetValue(_delegate)!)
|
||||
.Cast<object>()
|
||||
.Select(x => new SortingResult(x))
|
||||
.ToList();
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace Influx.AllaganTools;
|
||||
|
||||
internal interface IFilterService
|
||||
{
|
||||
Filter? GetFilterByKeyOrName(string keyOrName);
|
||||
}
|
6
Influx/AllaganTools/IListService.cs
Normal file
6
Influx/AllaganTools/IListService.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace Influx.AllaganTools;
|
||||
|
||||
internal interface IListService
|
||||
{
|
||||
FilterResult? GetFilterByKeyOrName(string keyOrName);
|
||||
}
|
@ -15,7 +15,7 @@ internal sealed class Inventory
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(@delegate);
|
||||
_delegate = @delegate;
|
||||
_getAllInventories = _delegate.GetType().GetMethod("GetAllInventories")!;
|
||||
_getAllInventories = _delegate.GetType().GetMethod("GetAllInventories") ?? throw new MissingMethodException();
|
||||
CharacterId = (ulong)_delegate.GetType().GetProperty("CharacterId")!.GetValue(_delegate)!;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||
using Dalamud.Logging;
|
||||
|
||||
namespace Influx.AllaganTools;
|
||||
|
||||
@ -10,7 +10,7 @@ internal sealed class InventoryItem
|
||||
ArgumentNullException.ThrowIfNull(@delegate);
|
||||
Category = (int)@delegate.GetType().GetField("SortedCategory")!.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)!;
|
||||
}
|
||||
|
||||
|
28
Influx/AllaganTools/ListService.cs
Normal file
28
Influx/AllaganTools/ListService.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ internal sealed class SortingResult
|
||||
Quantity = (int)@delegate.GetType().GetProperty("Quantity")!.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)!;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
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");
|
||||
return null;
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Version>0.16</Version>
|
||||
<Version>0.17</Version>
|
||||
<LangVersion>12</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
@ -25,7 +25,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
|
||||
<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>
|
||||
|
@ -25,9 +25,9 @@
|
||||
},
|
||||
"Microsoft.Extensions.ObjectPool": {
|
||||
"type": "Direct",
|
||||
"requested": "[8.0.3, )",
|
||||
"resolved": "8.0.3",
|
||||
"contentHash": "sk/TGiccSeXUtVeBfFlWJnzp6xLlAxIW+bCHs7uVPLFPQk8vICNmu9Gc3JsKOn6fQuRkrPetQ8EHv4dCiMqhxg=="
|
||||
"requested": "[9.0.0-preview.1.24081.5, )",
|
||||
"resolved": "9.0.0-preview.1.24081.5",
|
||||
"contentHash": "aAR7YW+pUUdvHk3vj7GtAi71dWGDIuY9270lsmQ6lKw23zzY+r8pLP3cGNbJdlnA9VWl+S+gnIVkBCqj2ROlEg=="
|
||||
},
|
||||
"CsvHelper": {
|
||||
"type": "Transitive",
|
||||
|
Loading…
Reference in New Issue
Block a user