Services here, too!

This commit is contained in:
Ottermandias 2023-04-23 19:50:51 +02:00
parent 1eb16b98a8
commit 85adc3626e
47 changed files with 1015 additions and 562 deletions

View file

@ -24,14 +24,14 @@ public unsafe partial struct Actor : IEquatable<Actor>, IDesignable
public static implicit operator IntPtr(Actor actor)
=> actor.Pointer == null ? IntPtr.Zero : (IntPtr)actor.Pointer;
public ActorIdentifier GetIdentifier()
=> Glamourer.Actors.FromObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)Pointer, out _, true, true, false);
public ActorIdentifier GetIdentifier(ActorManager actors)
=> actors.FromObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)Pointer, out _, true, true, false);
public bool Identifier(out ActorIdentifier ident)
public bool Identifier(ActorManager actors, out ActorIdentifier ident)
{
if (Valid)
{
ident = GetIdentifier();
ident = GetIdentifier(actors);
return true;
}
@ -39,9 +39,6 @@ public unsafe partial struct Actor : IEquatable<Actor>, IDesignable
return false;
}
public Character? Character
=> Pointer == null ? null : Dalamud.Objects[Pointer->GameObject.ObjectIndex] as Character;
public bool IsAvailable
=> Pointer->GameObject.GetIsTargetable();

View file

@ -4,35 +4,50 @@ using System.Collections.Generic;
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Objects;
using Glamourer.Services;
using Penumbra.GameData.Actors;
namespace Glamourer.Interop;
public class ObjectManager : IReadOnlyDictionary<ActorIdentifier, ObjectManager.ActorData>
public readonly struct ActorData
{
public readonly struct ActorData
public readonly List<Actor> Objects;
public readonly string Label;
public bool Valid
=> Objects.Count > 0;
public ActorData(Actor actor, string label)
{
public readonly List<Actor> Objects;
public readonly string Label;
public bool Valid
=> Objects.Count > 0;
public ActorData(Actor actor, string label)
{
Objects = new List<Actor> { actor };
Label = label;
}
public static readonly ActorData Invalid = new(false);
private ActorData(bool _)
{
Objects = new List<Actor>(0);
Label = string.Empty;
}
Objects = new List<Actor> { actor };
Label = label;
}
public static readonly ActorData Invalid = new(false);
private ActorData(bool _)
{
Objects = new List<Actor>(0);
Label = string.Empty;
}
}
public class ObjectManager : IReadOnlyDictionary<ActorIdentifier, ActorData>
{
private readonly Framework _framework;
private readonly ClientState _clientState;
private readonly ObjectTable _objects;
private readonly ActorService _actors;
public ObjectManager(Framework framework, ClientState clientState, ObjectTable objects, ActorService actors)
{
_framework = framework;
_clientState = clientState;
_objects = objects;
_actors = actors;
}
public DateTime LastUpdate { get; private set; }
public bool IsInGPose { get; private set; }
@ -56,16 +71,6 @@ public class ObjectManager : IReadOnlyDictionary<ActorIdentifier, ObjectManager.
}
}
private readonly Framework _framework;
private readonly ClientState _clientState;
private readonly ObjectTable _objects;
public ObjectManager(Framework framework, ClientState clientState, ObjectTable objects)
{
_framework = framework;
_clientState = clientState;
_objects = objects;
}
public void Update()
{
@ -80,14 +85,14 @@ public class ObjectManager : IReadOnlyDictionary<ActorIdentifier, ObjectManager.
for (var i = 0; i < (int)ScreenActor.CutsceneStart; ++i)
{
Actor character = _objects.GetObjectAddress(i);
if (character.Identifier(out var identifier))
if (character.Identifier(_actors.AwaitedService, out var identifier))
HandleIdentifier(identifier, character);
}
for (var i = (int)ScreenActor.CutsceneStart; i < (int)ScreenActor.CutsceneEnd; ++i)
{
Actor character = _objects.GetObjectAddress(i);
if (!character.Identifier(out var identifier))
if (!character.Identifier(_actors.AwaitedService, out var identifier))
break;
HandleIdentifier(identifier, character);
@ -96,7 +101,7 @@ public class ObjectManager : IReadOnlyDictionary<ActorIdentifier, ObjectManager.
void AddSpecial(ScreenActor idx, string label)
{
Actor actor = _objects.GetObjectAddress((int)idx);
if (actor.Identifier(out var ident))
if (actor.Identifier(_actors.AwaitedService, out var ident))
{
var data = new ActorData(actor, label);
_identifiers.Add(ident, data);
@ -112,10 +117,10 @@ public class ObjectManager : IReadOnlyDictionary<ActorIdentifier, ObjectManager.
AddSpecial(ScreenActor.Card7, "Card Actor 7");
AddSpecial(ScreenActor.Card8, "Card Actor 8");
for (var i = (int)ScreenActor.ScreenEnd; i < Dalamud.Objects.Length; ++i)
for (var i = (int)ScreenActor.ScreenEnd; i < _objects.Length; ++i)
{
Actor character = _objects.GetObjectAddress(i);
if (character.Identifier(out var identifier))
if (character.Identifier(_actors.AwaitedService, out var identifier))
HandleIdentifier(identifier, character);
}

View file

@ -34,8 +34,8 @@ public unsafe partial class RedrawManager
var character = (Actor)(characterOffset - CharacterWeaponOffset);
try
{
var identifier = character.GetIdentifier();
if (_fixedDesigns.TryGetDesign(identifier, out var save))
var identifier = character.GetIdentifier(_actors.AwaitedService);
if (_fixedDesignManager.TryGetDesign(identifier, out var save))
{
PluginLog.Information($"Loaded weapon from fixed design for {identifier}.");
weapon = slot switch

View file

@ -6,6 +6,7 @@ using Dalamud.Logging;
using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using Glamourer.Customization;
using Glamourer.Services;
using Glamourer.State;
using Glamourer.Structs;
using Penumbra.GameData.Enums;
@ -16,8 +17,11 @@ namespace Glamourer.Interop;
public partial class Interop : IDisposable
{
public Interop()
private readonly JobService _jobService;
public Interop(JobService jobService)
{
_jobService = jobService;
SignatureHelper.Initialise(this);
_changeJobHook.Enable();
_flagSlotForUpdateHook.Enable();
@ -187,7 +191,7 @@ public partial class Interop
private void ChangeJobDetour(IntPtr data, uint job)
{
_changeJobHook.Original(data, job);
JobChanged?.Invoke(data - Offsets.Character.ClassJobContainer, GameData.Jobs(Dalamud.GameData)[(byte)job]);
JobChanged?.Invoke(data - Offsets.Character.ClassJobContainer, _jobService.Jobs[(byte)job]);
}
public event Action<Actor, Job>? JobChanged;
@ -195,14 +199,18 @@ public partial class Interop
public unsafe partial class RedrawManager : IDisposable
{
private readonly FixedDesigns _fixedDesigns;
private readonly ItemManager _items;
private readonly ActorService _actors;
private readonly FixedDesignManager _fixedDesignManager;
private readonly ActiveDesign.Manager _stateManager;
public RedrawManager(FixedDesigns fixedDesigns, ActiveDesign.Manager stateManager)
public RedrawManager(FixedDesignManager fixedDesignManager, ActiveDesign.Manager stateManager, ItemManager items, ActorService actors)
{
SignatureHelper.Initialise(this);
_fixedDesigns = fixedDesigns;
_stateManager = stateManager;
_fixedDesignManager = fixedDesignManager;
_stateManager = stateManager;
_items = items;
_actors = actors;
_flagSlotForUpdateHook.Enable();
_loadWeaponHook.Enable();
}
@ -221,8 +229,8 @@ public unsafe partial class RedrawManager : IDisposable
return;
// Check if we have a current design in use, or if not if the actor has a fixed design.
var identifier = actor.GetIdentifier();
if (!(_stateManager.TryGetValue(identifier, out var save) || _fixedDesigns.TryGetDesign(identifier, out var save2)))
var identifier = actor.GetIdentifier(_actors.AwaitedService);
if (!(_stateManager.TryGetValue(identifier, out var save) || _fixedDesignManager.TryGetDesign(identifier, out var save2)))
return;
// Compare game object customize data against draw object customize data for transformations.
@ -240,7 +248,7 @@ public unsafe partial class RedrawManager : IDisposable
foreach (var slot in EquipSlotExtensions.EqdpSlots)
{
(_, equip[slot]) =
Glamourer.Items.ResolveRestrictedGear(saveEquip[slot], slot, customize.Race, customize.Gender);
_items.ResolveRestrictedGear(saveEquip[slot], slot, customize.Race, customize.Gender);
}
}
}