Updated submodules

This commit is contained in:
RisaDev
2024-03-26 00:26:02 +03:00
parent abb92e741e
commit ec0914a8a1
8 changed files with 45 additions and 67 deletions

View File

@@ -1,28 +1,29 @@
using CustomizePlus.GameData.Data; using CustomizePlus.GameData.Data;
using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Objects;
using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game.Control; using FFXIVClientStructs.FFXIV.Client.Game.Control;
using FFXIVClientStructs.FFXIV.Client.UI.Agent; using OtterGui.Log;
using Penumbra.GameData.Actors; using Penumbra.GameData.Actors;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using Penumbra.GameData.Interop; using Penumbra.GameData.Interop;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomizePlus.GameData.Services; namespace CustomizePlus.GameData.Services;
public class ObjectManager(IFramework framework, IClientState clientState, global::Penumbra.GameData.Interop.ObjectManager objects, ActorManager actorManager, ITargetManager targetManager) public class ObjectManager(
: IReadOnlyDictionary<ActorIdentifier, ActorData> IFramework framework,
IClientState clientState,
IObjectTable objects,
DalamudPluginInterface pi,
Logger log,
ActorManager actors,
ITargetManager targets)
: global::Penumbra.GameData.Interop.ObjectManager(pi, log, framework, objects)
{ {
public global::Penumbra.GameData.Interop.ObjectManager Objects public DateTime LastUpdate
=> objects; => LastFrame;
public DateTime LastUpdate { get; private set; }
private DateTime _identifierUpdate;
public bool IsInGPose { get; private set; } public bool IsInGPose { get; private set; }
public ushort World { get; private set; } public ushort World { get; private set; }
@@ -33,41 +34,27 @@ public class ObjectManager(IFramework framework, IClientState clientState, globa
public IReadOnlyDictionary<ActorIdentifier, ActorData> Identifiers public IReadOnlyDictionary<ActorIdentifier, ActorData> Identifiers
=> _identifiers; => _identifiers;
public void Update() public override bool Update()
{ {
var lastUpdate = framework.LastUpdate; if (!base.Update() && _identifierUpdate >= LastUpdate)
if (lastUpdate <= LastUpdate) return false;
return;
LastUpdate = lastUpdate; _identifierUpdate = LastUpdate;
World = (ushort)(clientState.LocalPlayer?.CurrentWorld.Id ?? 0u); World = (ushort)(this[0].Valid ? this[0].HomeWorld : 0);
_identifiers.Clear(); _identifiers.Clear();
_allWorldIdentifiers.Clear(); _allWorldIdentifiers.Clear();
_nonOwnedIdentifiers.Clear(); _nonOwnedIdentifiers.Clear();
for (var i = 0; i < (int)ScreenActor.CutsceneStart; ++i) foreach (var actor in BattleNpcs.Concat(CutsceneCharacters))
{ {
Actor character = objects[i]; if (actor.Identifier(actors, out var identifier))
if (character.Identifier(actorManager, out var identifier)) HandleIdentifier(identifier, actor);
HandleIdentifier(identifier, character);
}
for (var i = (int)ScreenActor.CutsceneStart; i < (int)ScreenActor.CutsceneEnd; ++i)
{
Actor character = objects[i];
// Technically the game does not create holes in cutscenes or GPose.
// But for Brio compatibility, we allow holes in GPose.
// Since GPose always has the event actor in the first cutscene slot, we can still optimize in this case.
if (!character.Valid && i == (int)ScreenActor.CutsceneStart)
break;
HandleIdentifier(character.GetIdentifier(actorManager), character);
} }
void AddSpecial(ScreenActor idx, string label) void AddSpecial(ScreenActor idx, string label)
{ {
Actor actor = objects[(int)idx]; var actor = this[(int)idx];
if (actor.Identifier(actorManager, out var ident)) if (actor.Identifier(actors, out var ident))
{ {
var data = new ActorData(actor, label); var data = new ActorData(actor, label);
_identifiers.Add(ident, data); _identifiers.Add(ident, data);
@@ -83,15 +70,15 @@ public class ObjectManager(IFramework framework, IClientState clientState, globa
AddSpecial(ScreenActor.Card7, "Card Actor 7"); AddSpecial(ScreenActor.Card7, "Card Actor 7");
AddSpecial(ScreenActor.Card8, "Card Actor 8"); AddSpecial(ScreenActor.Card8, "Card Actor 8");
for (var i = (int)ScreenActor.ScreenEnd; i < objects.Count; ++i) foreach (var actor in EventNpcs)
{ {
Actor character = objects[i]; if (actor.Identifier(actors, out var identifier))
if (character.Identifier(actorManager, out var identifier)) HandleIdentifier(identifier, actor);
HandleIdentifier(identifier, character);
} }
var gPose = GPosePlayer; var gPose = GPosePlayer;
IsInGPose = gPose.Utf8Name.Length > 0; IsInGPose = gPose.Utf8Name.Length > 0;
return true;
} }
private void HandleIdentifier(ActorIdentifier identifier, Actor character) private void HandleIdentifier(ActorIdentifier identifier, Actor character)
@@ -111,7 +98,7 @@ public class ObjectManager(IFramework framework, IClientState clientState, globa
if (identifier.Type is IdentifierType.Player or IdentifierType.Owned) if (identifier.Type is IdentifierType.Player or IdentifierType.Owned)
{ {
var allWorld = actorManager.CreateIndividualUnchecked(identifier.Type, identifier.PlayerName, ushort.MaxValue, var allWorld = actors.CreateIndividualUnchecked(identifier.Type, identifier.PlayerName, ushort.MaxValue,
identifier.Kind, identifier.Kind,
identifier.DataId); identifier.DataId);
@@ -128,7 +115,7 @@ public class ObjectManager(IFramework framework, IClientState clientState, globa
if (identifier.Type is IdentifierType.Owned) if (identifier.Type is IdentifierType.Owned)
{ {
var nonOwned = actorManager.CreateNpc(identifier.Kind, identifier.DataId); var nonOwned = actors.CreateNpc(identifier.Kind, identifier.DataId);
if (!_nonOwnedIdentifiers.TryGetValue(nonOwned, out var nonOwnedData)) if (!_nonOwnedIdentifiers.TryGetValue(nonOwned, out var nonOwnedData))
{ {
nonOwnedData = new ActorData(character, nonOwned.ToString()); nonOwnedData = new ActorData(character, nonOwned.ToString());
@@ -142,26 +129,26 @@ public class ObjectManager(IFramework framework, IClientState clientState, globa
} }
public Actor GPosePlayer public Actor GPosePlayer
=> objects[(int)ScreenActor.GPosePlayer]; => this[(int)ScreenActor.GPosePlayer];
public Actor Player public Actor Player
=> objects[0]; => this[0];
public unsafe Actor Target public unsafe Actor Target
=> clientState.IsGPosing ? TargetSystem.Instance()->GPoseTarget : TargetSystem.Instance()->Target; => clientState.IsGPosing ? TargetSystem.Instance()->GPoseTarget : TargetSystem.Instance()->Target;
public Actor Focus public Actor Focus
=> targetManager.FocusTarget?.Address ?? nint.Zero; => targets.FocusTarget?.Address ?? nint.Zero;
public Actor MouseOver public Actor MouseOver
=> targetManager.MouseOverTarget?.Address ?? nint.Zero; => targets.MouseOverTarget?.Address ?? nint.Zero;
public (ActorIdentifier Identifier, ActorData Data) PlayerData public (ActorIdentifier Identifier, ActorData Data) PlayerData
{ {
get get
{ {
Update(); Update();
return Player.Identifier(actorManager, out var ident) && _identifiers.TryGetValue(ident, out var data) return Player.Identifier(actors, out var ident) && _identifiers.TryGetValue(ident, out var data)
? (ident, data) ? (ident, data)
: (ident, ActorData.Invalid); : (ident, ActorData.Invalid);
} }
@@ -172,21 +159,12 @@ public class ObjectManager(IFramework framework, IClientState clientState, globa
get get
{ {
Update(); Update();
return Target.Identifier(actorManager, out var ident) && _identifiers.TryGetValue(ident, out var data) return Target.Identifier(actors, out var ident) && _identifiers.TryGetValue(ident, out var data)
? (ident, data) ? (ident, data)
: (ident, ActorData.Invalid); : (ident, ActorData.Invalid);
} }
} }
public IEnumerator<KeyValuePair<ActorIdentifier, ActorData>> GetEnumerator()
=> Identifiers.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
public int Count
=> Identifiers.Count;
/// <summary> Also handles All Worlds players and non-owned NPCs. </summary> /// <summary> Also handles All Worlds players and non-owned NPCs. </summary>
public bool ContainsKey(ActorIdentifier key) public bool ContainsKey(ActorIdentifier key)
=> Identifiers.ContainsKey(key) || _allWorldIdentifiers.ContainsKey(key) || _nonOwnedIdentifiers.ContainsKey(key); => Identifiers.ContainsKey(key) || _allWorldIdentifiers.ContainsKey(key) || _nonOwnedIdentifiers.ContainsKey(key);

View File

@@ -139,7 +139,7 @@ public unsafe sealed class ArmatureManager : IDisposable
return null; return null;
} }
foreach (var obj in _objectManager) foreach (var obj in _objectManager.Identifiers)
{ {
var actorIdentifier = obj.Key.CreatePermanent(); var actorIdentifier = obj.Key.CreatePermanent();
if (!Armatures.ContainsKey(actorIdentifier)) if (!Armatures.ContainsKey(actorIdentifier))

View File

@@ -50,7 +50,7 @@ public class GameObjectService
/// <returns></returns> /// <returns></returns>
public IEnumerable<(ActorIdentifier, Actor)> FindActorsByName(string name) public IEnumerable<(ActorIdentifier, Actor)> FindActorsByName(string name)
{ {
foreach (var kvPair in _objectManager) foreach (var kvPair in _objectManager.Identifiers)
{ {
var identifier = kvPair.Key; var identifier = kvPair.Key;

View File

@@ -88,7 +88,7 @@ public class StateMonitoringTab
private void DrawObjectManager() private void DrawObjectManager()
{ {
foreach (var kvPair in _objectManager) foreach (var kvPair in _objectManager.Identifiers)
{ {
var show = ImGui.CollapsingHeader($"{kvPair.Key} ({kvPair.Value.Objects.Count} objects)###object-{kvPair.Key}"); var show = ImGui.CollapsingHeader($"{kvPair.Key} ({kvPair.Value.Objects.Count} objects)###object-{kvPair.Key}");