diff --git a/client/Plugin.cs b/client/Plugin.cs index 42cdfad..2752681 100644 --- a/client/Plugin.cs +++ b/client/Plugin.cs @@ -59,8 +59,8 @@ public class Plugin : IDalamudPlugin { this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration(); this.Vfx = new Vfx(this); this.Messages = new Messages(this); - this.ActorManager = new ActorManager(this); this.Ui = new PluginUi(this); + this.ActorManager = new ActorManager(this); this.VfxReplacer = new VfxReplacer(this); this.Commands = new Commands(this); this.Pinger = new Pinger(this); @@ -74,8 +74,8 @@ public class Plugin : IDalamudPlugin { this.Pinger.Dispose(); this.Commands.Dispose(); this.VfxReplacer.Dispose(); - this.Ui.Dispose(); this.ActorManager.Dispose(); + this.Ui.Dispose(); this.Messages.Dispose(); this.Vfx.Dispose(); } diff --git a/client/Ui/Viewer.cs b/client/Ui/Viewer.cs index 7d4a294..cda2509 100644 --- a/client/Ui/Viewer.cs +++ b/client/Ui/Viewer.cs @@ -13,7 +13,7 @@ internal class Viewer { internal bool Visible; internal delegate void MessageViewDelegate(Message? message); - internal event MessageViewDelegate View; + internal event MessageViewDelegate? View; private Guid _lastViewed = Guid.Empty; @@ -26,7 +26,7 @@ internal class Viewer { internal void Draw() { if (!this.Visible) { if (this._lastViewed != Guid.Empty) { - this.View(null); + this.View?.Invoke(null); } this._lastViewed = Guid.Empty; @@ -97,7 +97,7 @@ internal class Viewer { var message = nearby[this._idx]; if (this._lastViewed != message.Id) { try { - this.View(message); + this.View?.Invoke(message); } catch (Exception ex) { Plugin.Log.Error(ex, "Error in View event"); } diff --git a/client/Util/ActorManager.cs b/client/Util/ActorManager.cs index da226b1..5d3da10 100644 --- a/client/Util/ActorManager.cs +++ b/client/Util/ActorManager.cs @@ -10,7 +10,6 @@ internal class ActorManager : IDisposable { private readonly Queue _tasks = []; private enum Mode { - None, Enable, Disable, Delete, @@ -47,20 +46,24 @@ internal class ActorManager : IDisposable { switch (mode) { case Mode.Disable: { + Plugin.Log.Debug("disabling actor"); obj->DisableDraw(); success = true; break; } case Mode.Enable: { if (!obj->IsReadyToDraw()) { + Plugin.Log.Debug("not ready to draw"); break; } + Plugin.Log.Debug("drawing actor"); obj->EnableDraw(); success = true; break; } case Mode.Delete: { + Plugin.Log.Debug("deleting actor"); objMan->DeleteObjectByIndex((ushort) idx, 0); this._idx = null; success = true; @@ -69,11 +72,14 @@ internal class ActorManager : IDisposable { } if (success) { - this._tasks.Dequeue(); + var res = this._tasks.Dequeue(); + Plugin.Log.Debug($"deq {Enum.GetName(res)}"); } } private void OnView(Message? message) { + var msg = message == null ? "null" : "not null"; + Plugin.Log.Debug($"OnView message is {msg}"); this.Despawn(); if (message != null) { @@ -87,9 +93,12 @@ internal class ActorManager : IDisposable { return; } + Plugin.Log.Debug("spawning actor"); + var objMan = ClientObjectManager.Instance(); var idx = objMan->CreateBattleCharacter(); if (idx == 0xFFFFFFFF) { + Plugin.Log.Debug("actor could not be spawned"); return; } @@ -97,6 +106,7 @@ internal class ActorManager : IDisposable { var chara = (BattleChara*) objMan->GetObjectByIndex((ushort) idx); + chara->ObjectKind = ObjectKind.BattleNpc; chara->Position = message.Position; chara->Rotation = message.Yaw; var drawData = &chara->DrawData; @@ -109,8 +119,11 @@ internal class ActorManager : IDisposable { this._tasks.Enqueue(Mode.Enable); } - internal unsafe void Despawn() { - Plugin.Log.Debug("despawning actor"); + internal void Despawn() { + if (this._idx == null) { + return; + } + this._tasks.Enqueue(Mode.Disable); this._tasks.Enqueue(Mode.Delete); }