2022-09-03 23:45:16 +00:00
|
|
|
using System.Numerics;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Text;
|
2024-07-05 21:24:50 +00:00
|
|
|
using Dalamud.Memory;
|
|
|
|
using Dalamud.Plugin.Services;
|
2022-09-03 23:45:16 +00:00
|
|
|
using Dalamud.Utility.Signatures;
|
|
|
|
|
|
|
|
namespace OrangeGuidanceTomestone;
|
|
|
|
|
|
|
|
internal unsafe class Vfx : IDisposable {
|
2024-07-05 21:24:50 +00:00
|
|
|
private static readonly byte[] Pool = "Client.System.Scheduler.Instance.VfxObject\0"u8.ToArray();
|
2022-09-03 23:45:16 +00:00
|
|
|
|
|
|
|
[Signature("E8 ?? ?? ?? ?? F3 0F 10 35 ?? ?? ?? ?? 48 89 43 08")]
|
|
|
|
private delegate* unmanaged<byte*, byte*, VfxStruct*> _staticVfxCreate;
|
|
|
|
|
|
|
|
[Signature("E8 ?? ?? ?? ?? 8B 4B 7C 85 C9")]
|
2024-07-05 21:24:50 +00:00
|
|
|
private delegate* unmanaged<VfxStruct*, float, int, ulong> _staticVfxRun;
|
2022-09-03 23:45:16 +00:00
|
|
|
|
|
|
|
[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")]
|
2024-07-05 21:24:50 +00:00
|
|
|
private delegate* unmanaged<VfxStruct*, nint> _staticVfxRemove;
|
2022-09-03 23:45:16 +00:00
|
|
|
|
2024-07-05 21:24:50 +00:00
|
|
|
private Plugin Plugin { get; }
|
|
|
|
private Dictionary<Guid, nint> Spawned { get; } = [];
|
|
|
|
private Queue<nint> RemoveQueue { get; } = [];
|
|
|
|
private bool _disposed;
|
2022-09-03 23:45:16 +00:00
|
|
|
|
2023-09-29 00:53:50 +00:00
|
|
|
internal Vfx(Plugin plugin) {
|
2024-07-05 21:24:50 +00:00
|
|
|
this.Plugin = plugin;
|
|
|
|
|
|
|
|
this.Plugin.GameInteropProvider.InitializeFromAttributes(this);
|
|
|
|
this.Plugin.Framework.Update += this.OnFrameworkUpdate;
|
2022-09-03 23:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose() {
|
2024-07-05 21:24:50 +00:00
|
|
|
if (this._disposed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._disposed = true;
|
2022-09-03 23:45:16 +00:00
|
|
|
this.RemoveAll();
|
|
|
|
}
|
|
|
|
|
2024-07-05 21:24:50 +00:00
|
|
|
private void OnFrameworkUpdate(IFramework framework) {
|
|
|
|
if (this._disposed && this.RemoveQueue.Count == 0) {
|
|
|
|
this.Plugin.Framework.Update -= this.OnFrameworkUpdate;
|
2022-09-03 23:45:16 +00:00
|
|
|
}
|
|
|
|
|
2024-07-05 21:24:50 +00:00
|
|
|
if (!this.RemoveQueue.TryDequeue(out var vfx)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.RemoveStatic((VfxStruct*) vfx)) {
|
|
|
|
this.RemoveQueue.Enqueue(vfx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void RemoveAll() {
|
|
|
|
foreach (var spawned in this.Spawned.Keys.ToArray()) {
|
|
|
|
this.RemoveStatic(spawned);
|
|
|
|
}
|
2022-09-03 23:45:16 +00:00
|
|
|
}
|
|
|
|
|
2022-09-04 21:02:13 +00:00
|
|
|
internal VfxStruct* SpawnStatic(Guid id, string path, Vector3 pos, Quaternion rotation) {
|
2022-09-03 23:45:16 +00:00
|
|
|
VfxStruct* vfx;
|
2024-07-05 21:24:50 +00:00
|
|
|
fixed (byte* p = Encoding.UTF8.GetBytes(path).NullTerminate()) {
|
2022-09-03 23:45:16 +00:00
|
|
|
fixed (byte* pool = Pool) {
|
|
|
|
vfx = this._staticVfxCreate(p, pool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vfx == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update position
|
|
|
|
vfx->Position = new Vector3(pos.X, pos.Y, pos.Z);
|
2022-09-04 21:02:13 +00:00
|
|
|
// update rotation
|
|
|
|
vfx->Rotation = new Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W);
|
2022-09-03 23:45:16 +00:00
|
|
|
|
|
|
|
// update
|
|
|
|
vfx->Flags |= 2;
|
|
|
|
|
2024-07-05 21:24:50 +00:00
|
|
|
this._staticVfxRun(vfx, 0.0f, -1);
|
|
|
|
|
|
|
|
this.Spawned[id] = (nint) vfx;
|
2022-09-03 23:45:16 +00:00
|
|
|
|
|
|
|
return vfx;
|
|
|
|
}
|
|
|
|
|
2024-07-05 21:24:50 +00:00
|
|
|
internal bool RemoveStatic(VfxStruct* vfx) {
|
|
|
|
var result = this._staticVfxRemove(vfx);
|
|
|
|
var success = result != 0;
|
|
|
|
if (!success) {
|
|
|
|
this.RemoveQueue.Enqueue((nint) vfx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
2022-09-03 23:45:16 +00:00
|
|
|
}
|
|
|
|
|
2022-09-04 05:15:27 +00:00
|
|
|
internal void RemoveStatic(Guid id) {
|
2024-07-05 21:24:50 +00:00
|
|
|
if (!this.Spawned.Remove(id, out var vfx)) {
|
|
|
|
return;
|
2022-09-04 05:15:27 +00:00
|
|
|
}
|
2024-07-05 21:24:50 +00:00
|
|
|
|
|
|
|
this.RemoveStatic((VfxStruct*) vfx);
|
2022-09-04 05:15:27 +00:00
|
|
|
}
|
|
|
|
|
2022-09-03 23:45:16 +00:00
|
|
|
[StructLayout(LayoutKind.Explicit)]
|
|
|
|
internal struct VfxStruct {
|
|
|
|
[FieldOffset(0x38)]
|
|
|
|
public byte Flags;
|
|
|
|
|
|
|
|
[FieldOffset(0x50)]
|
|
|
|
public Vector3 Position;
|
|
|
|
|
2022-09-04 21:02:13 +00:00
|
|
|
[FieldOffset(0x60)]
|
|
|
|
public Quaternion Rotation;
|
|
|
|
|
2022-09-03 23:45:16 +00:00
|
|
|
[FieldOffset(0x70)]
|
|
|
|
public Vector3 Scale;
|
|
|
|
|
|
|
|
[FieldOffset(0x128)]
|
|
|
|
public int ActorCaster;
|
|
|
|
|
|
|
|
[FieldOffset(0x130)]
|
|
|
|
public int ActorTarget;
|
|
|
|
|
|
|
|
[FieldOffset(0x1B8)]
|
|
|
|
public int StaticCaster;
|
|
|
|
|
|
|
|
[FieldOffset(0x1C0)]
|
|
|
|
public int StaticTarget;
|
|
|
|
}
|
|
|
|
}
|