This commit is contained in:
Liza 2024-07-02 17:35:40 +02:00
parent b5125d4b3f
commit 6c8e89c49d
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 15 additions and 34 deletions

View File

@ -14,13 +14,13 @@ namespace LLib;
/// </summary>
public sealed class DalamudReflector : IDisposable
{
private readonly DalamudPluginInterface _pluginInterface;
private readonly IDalamudPluginInterface _pluginInterface;
private readonly IFramework _framework;
private readonly IPluginLog _pluginLog;
private readonly Dictionary<string, IDalamudPlugin> _pluginCache = new();
private bool _pluginsChanged;
public DalamudReflector(DalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog)
public DalamudReflector(IDalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog)
{
_pluginInterface = pluginInterface;
_framework = framework;

View File

@ -11,14 +11,14 @@ public static class LAddon
public static unsafe AtkUnitBase* GetAddonById(uint id)
{
var unitManagers = &AtkStage.GetSingleton()->RaptureAtkUnitManager->AtkUnitManager.DepthLayerOneList;
var unitManagers = &AtkStage.Instance()->RaptureAtkUnitManager->AtkUnitManager.DepthLayerOneList;
for (var i = 0; i < UnitListCount; i++)
{
var unitManager = &unitManagers[i];
foreach (var j in Enumerable.Range(0, Math.Min(unitManager->Count, unitManager->EntriesSpan.Length)))
foreach (var j in Enumerable.Range(0, Math.Min(unitManager->Count, unitManager->Entries.Length)))
{
var unitBase = unitManager->EntriesSpan[j].Value;
if (unitBase != null && unitBase->ID == id)
var unitBase = unitManager->Entries[j].Value;
if (unitBase != null && unitBase->Id == id)
{
return unitBase;
}

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Plugin.Services;
namespace LLib;
@ -8,46 +10,25 @@ namespace LLib;
public sealed class IconCache : IDisposable
{
private readonly ITextureProvider _textureProvider;
private readonly Dictionary<uint, TextureContainer> _textureWraps = new();
private readonly Dictionary<uint, ISharedImmediateTexture> _textureWraps = new();
public IconCache(ITextureProvider textureProvider)
{
_textureProvider = textureProvider;
}
public IDalamudTextureWrap? GetIcon(uint iconId)
public ISharedImmediateTexture GetIcon(uint iconId)
{
if (_textureWraps.TryGetValue(iconId, out TextureContainer? container))
return container.Texture;
if (_textureWraps.TryGetValue(iconId, out ISharedImmediateTexture? iconTex))
return iconTex;
var iconTex = _textureProvider.GetIcon(iconId);
if (iconTex != null)
{
if (iconTex.ImGuiHandle != nint.Zero)
{
_textureWraps[iconId] = new TextureContainer { Texture = iconTex };
return iconTex;
}
iconTex.Dispose();
}
_textureWraps[iconId] = new TextureContainer { Texture = null };
return null;
iconTex = _textureProvider.GetFromGameIcon(new GameIconLookup(iconId));
_textureWraps[iconId] = iconTex;
return iconTex;
}
public void Dispose()
{
foreach (TextureContainer container in _textureWraps.Values)
container.Dispose();
_textureWraps.Clear();
}
private sealed class TextureContainer : IDisposable
{
public required IDalamudTextureWrap? Texture { get; init; }
public void Dispose() => Texture?.Dispose();
}
}