This commit is contained in:
Anna 2022-09-04 01:15:27 -04:00
parent d5ffdd41e7
commit 803f3c139b
4 changed files with 19 additions and 17 deletions

View File

@ -41,7 +41,7 @@ internal class Messages : IDisposable {
} }
PluginLog.Log($"spawning vfx for {message.Id}"); PluginLog.Log($"spawning vfx for {message.Id}");
if (this.Plugin.Vfx.SpawnStatic(VfxPath, message.Position) == null) { if (this.Plugin.Vfx.SpawnStatic(message.Id, VfxPath, message.Position) == null) {
PluginLog.Log("trying again"); PluginLog.Log("trying again");
this.SpawnQueue.Enqueue(message); this.SpawnQueue.Enqueue(message);
} }

View File

@ -38,7 +38,7 @@ public class Plugin : IDalamudPlugin {
}); });
} }
this.Vfx = new Vfx(this); this.Vfx = new Vfx();
this.Ui = new PluginUi(this); this.Ui = new PluginUi(this);
this.Messages = new Messages(this); this.Messages = new Messages(this);
this.Commands = new Commands(this); this.Commands = new Commands(this);

View File

@ -24,11 +24,16 @@ internal class MessageList : ITab {
foreach (var message in this.Messages) { foreach (var message in this.Messages) {
ImGui.TextUnformatted(message.Text); ImGui.TextUnformatted(message.Text);
ImGui.TreePush();
ImGui.TextUnformatted($"Likes: {message.PositiveVotes}"); ImGui.TextUnformatted($"Likes: {message.PositiveVotes}");
ImGui.TextUnformatted($"Dislikes: {message.NegativeVotes}"); ImGui.TextUnformatted($"Dislikes: {message.NegativeVotes}");
if (ImGui.Button($"Delete##{message.Id}")) { if (ImGui.Button($"Delete##{message.Id}")) {
this.Delete(message.Id); this.Delete(message.Id);
} }
ImGui.TreePop();
ImGui.Separator();
} }
this.MessagesMutex.Release(); this.MessagesMutex.Release();
@ -60,14 +65,8 @@ internal class MessageList : ITab {
if (resp.IsSuccessStatusCode) { if (resp.IsSuccessStatusCode) {
this.Refresh(); this.Refresh();
this.Plugin.Messages.SpawnVfx(); this.Plugin.Vfx.RemoveStatic(id);
} }
}); });
} }
internal void Add(MessageWithTerritory message) {
this.Messages.Clear();
this.Messages.Add(message);
this.MessagesMutex.Release();
}
} }

View File

@ -8,8 +8,6 @@ namespace OrangeGuidanceTomestone;
internal unsafe class Vfx : IDisposable { internal unsafe class Vfx : IDisposable {
private static readonly byte[] Pool = Encoding.UTF8.GetBytes("Client.System.Scheduler.Instance.VfxObject"); private static readonly byte[] Pool = Encoding.UTF8.GetBytes("Client.System.Scheduler.Instance.VfxObject");
private Plugin Plugin { get; }
[Signature("E8 ?? ?? ?? ?? F3 0F 10 35 ?? ?? ?? ?? 48 89 43 08")] [Signature("E8 ?? ?? ?? ?? F3 0F 10 35 ?? ?? ?? ?? 48 89 43 08")]
private delegate* unmanaged<byte*, byte*, VfxStruct*> _staticVfxCreate; private delegate* unmanaged<byte*, byte*, VfxStruct*> _staticVfxCreate;
@ -19,10 +17,9 @@ internal unsafe class Vfx : IDisposable {
[Signature("40 53 48 83 EC 20 48 8B D9 48 8B 89 ?? ?? ?? ?? 48 85 C9 74 28 33 D2 E8 ?? ?? ?? ?? 48 8B 8B ?? ?? ?? ?? 48 85 C9")] [Signature("40 53 48 83 EC 20 48 8B D9 48 8B 89 ?? ?? ?? ?? 48 85 C9 74 28 33 D2 E8 ?? ?? ?? ?? 48 8B 8B ?? ?? ?? ?? 48 85 C9")]
private delegate* unmanaged<VfxStruct*, void> _staticVfxRemove; private delegate* unmanaged<VfxStruct*, void> _staticVfxRemove;
private List<IntPtr> Spawned { get; } = new(); private Dictionary<Guid, IntPtr> Spawned { get; } = new();
internal Vfx(Plugin plugin) { internal Vfx() {
this.Plugin = plugin;
SignatureHelper.Initialise(this); SignatureHelper.Initialise(this);
} }
@ -31,14 +28,14 @@ internal unsafe class Vfx : IDisposable {
} }
internal void RemoveAll() { internal void RemoveAll() {
foreach (var spawned in this.Spawned) { foreach (var spawned in this.Spawned.Values) {
this.RemoveStatic((VfxStruct*) spawned); this.RemoveStatic((VfxStruct*) spawned);
} }
this.Spawned.Clear(); this.Spawned.Clear();
} }
internal VfxStruct* SpawnStatic(string path, Vector3 pos) { internal VfxStruct* SpawnStatic(Guid id, string path, Vector3 pos) {
VfxStruct* vfx; VfxStruct* vfx;
fixed (byte* p = Encoding.UTF8.GetBytes(path)) { fixed (byte* p = Encoding.UTF8.GetBytes(path)) {
fixed (byte* pool = Pool) { fixed (byte* pool = Pool) {
@ -61,7 +58,7 @@ internal unsafe class Vfx : IDisposable {
// update // update
vfx->Flags |= 2; vfx->Flags |= 2;
this.Spawned.Add((IntPtr) vfx); this.Spawned[id] = (IntPtr) vfx;
return vfx; return vfx;
} }
@ -70,6 +67,12 @@ internal unsafe class Vfx : IDisposable {
this._staticVfxRemove(vfx); this._staticVfxRemove(vfx);
} }
internal void RemoveStatic(Guid id) {
if (this.Spawned.TryGetValue(id, out var vfx)) {
this.RemoveStatic((VfxStruct*) vfx);
}
}
[StructLayout(LayoutKind.Explicit)] [StructLayout(LayoutKind.Explicit)]
internal struct VfxStruct { internal struct VfxStruct {
[FieldOffset(0x38)] [FieldOffset(0x38)]