muffin v7.5.5
This commit is contained in:
parent
a8f2c1df37
commit
6266f9e6b7
110 changed files with 14907 additions and 6073 deletions
64
Auspex/Auspex.Vfx.Internal/ActorBoundVfx.cs
Normal file
64
Auspex/Auspex.Vfx.Internal/ActorBoundVfx.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using Auspex.Vfx.Native;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
|
||||
namespace Auspex.Vfx.Internal;
|
||||
|
||||
public sealed class ActorBoundVfx : IDisposable
|
||||
{
|
||||
internal IGameObject target;
|
||||
|
||||
internal IGameObject source;
|
||||
|
||||
internal Vector3 scale;
|
||||
|
||||
internal Vector4 color;
|
||||
|
||||
internal unsafe VfxData* data;
|
||||
|
||||
public static ActorBoundVfx Create(string path, IGameObject target, IGameObject source, Vector3 scale, Vector4 color)
|
||||
{
|
||||
return new ActorBoundVfx(path, target, source, scale, color);
|
||||
}
|
||||
|
||||
private unsafe ActorBoundVfx(string path, IGameObject target, IGameObject source, Vector3 scale, Vector4 color)
|
||||
{
|
||||
this.target = target;
|
||||
this.source = source;
|
||||
this.scale = scale;
|
||||
this.color = color;
|
||||
data = CreateGameObjectVfxInternal(path, target, source, scale, color);
|
||||
}
|
||||
|
||||
public unsafe void Dispose()
|
||||
{
|
||||
if (data != null && data->Instance != null)
|
||||
{
|
||||
VfxNativeBridge.DestroyVfx(data);
|
||||
}
|
||||
data = null;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private unsafe static VfxData* CreateGameObjectVfxInternal(string path, IGameObject target, IGameObject source, Vector3 scale, Vector4 color)
|
||||
{
|
||||
fixed (byte* bytes = Encoding.UTF8.GetBytes(path + "\0"))
|
||||
{
|
||||
VfxData* intPtr = VfxNativeBridge.CreateGameObjectVfxInternal(bytes, target.Address, source.Address, 1f, 0, 0, 1);
|
||||
intPtr->Instance->Scale = scale;
|
||||
intPtr->Instance->Color = color;
|
||||
return intPtr;
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void UpdateColor(Vector4 color)
|
||||
{
|
||||
if (!(this.color == color))
|
||||
{
|
||||
this.color = color;
|
||||
VfxNativeBridge.UpdateVfxColor(data->Instance, color.X, color.Y, color.Z, color.W);
|
||||
}
|
||||
}
|
||||
}
|
||||
87
Auspex/Auspex.Vfx.Internal/FrameLifetimeTracker.cs
Normal file
87
Auspex/Auspex.Vfx.Internal/FrameLifetimeTracker.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Auspex.Vfx.Internal;
|
||||
|
||||
internal sealed class FrameLifetimeTracker<T> : IDisposable where T : IDisposable
|
||||
{
|
||||
private Dictionary<(string, string), T> prevActive;
|
||||
|
||||
private Dictionary<(string, string), T> currActive;
|
||||
|
||||
internal FrameLifetimeTracker()
|
||||
{
|
||||
prevActive = new Dictionary<(string, string), T>();
|
||||
currActive = new Dictionary<(string, string), T>();
|
||||
}
|
||||
|
||||
internal bool IsTouched((string, string) key)
|
||||
{
|
||||
return currActive.ContainsKey(key);
|
||||
}
|
||||
|
||||
internal bool TryTouchExisting((string, string) key, [MaybeNullWhen(false)] out T o)
|
||||
{
|
||||
if (prevActive.TryGetValue(key, out o))
|
||||
{
|
||||
prevActive.Remove(key);
|
||||
currActive.Add(key, o);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void TouchNew((string, string) key, T t)
|
||||
{
|
||||
currActive.Add(key, t);
|
||||
}
|
||||
|
||||
internal bool Remove((string, string) key)
|
||||
{
|
||||
if (currActive.Remove(key, out var value))
|
||||
{
|
||||
value.Dispose();
|
||||
return true;
|
||||
}
|
||||
if (prevActive.Remove(key, out var value2))
|
||||
{
|
||||
value2.Dispose();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach (KeyValuePair<(string, string), T> item in prevActive)
|
||||
{
|
||||
item.Value.Dispose();
|
||||
}
|
||||
prevActive.Clear();
|
||||
Dictionary<(string, string), T> dictionary = prevActive;
|
||||
prevActive = currActive;
|
||||
currActive = dictionary;
|
||||
}
|
||||
|
||||
internal void ForEachActive(Action<T> action)
|
||||
{
|
||||
foreach (KeyValuePair<(string, string), T> item in prevActive)
|
||||
{
|
||||
action(item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (KeyValuePair<(string, string), T> item in prevActive)
|
||||
{
|
||||
item.Value.Dispose();
|
||||
}
|
||||
foreach (KeyValuePair<(string, string), T> item2 in currActive)
|
||||
{
|
||||
item2.Value.Dispose();
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
26
Auspex/Auspex.Vfx.Internal/PinnedAlignedMatrix.cs
Normal file
26
Auspex/Auspex.Vfx.Internal/PinnedAlignedMatrix.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Auspex.Vfx.Internal;
|
||||
|
||||
internal sealed class PinnedAlignedMatrix : IDisposable
|
||||
{
|
||||
private IntPtr rawptr;
|
||||
|
||||
private IntPtr aligned;
|
||||
|
||||
public unsafe Matrix4x4* Get => (Matrix4x4*)aligned;
|
||||
|
||||
public unsafe PinnedAlignedMatrix()
|
||||
{
|
||||
rawptr = Marshal.AllocHGlobal(sizeof(Matrix4x4) + 8);
|
||||
aligned = new IntPtr(16 * (((long)(nint)rawptr + 15L) / 16));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Marshal.FreeHGlobal(rawptr);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
150
Auspex/Auspex.Vfx.Internal/VfxInstance.cs
Normal file
150
Auspex/Auspex.Vfx.Internal/VfxInstance.cs
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using Auspex.Vfx.Native;
|
||||
|
||||
namespace Auspex.Vfx.Internal;
|
||||
|
||||
public sealed class VfxInstance : IDisposable
|
||||
{
|
||||
internal string? path;
|
||||
|
||||
internal Vector3 position;
|
||||
|
||||
internal Vector3 size;
|
||||
|
||||
internal float rotation;
|
||||
|
||||
internal Vector4 color;
|
||||
|
||||
internal unsafe VfxData* data;
|
||||
|
||||
internal bool libOwned;
|
||||
|
||||
public unsafe bool IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
return data->Instance != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static VfxInstance Create(string path, Vector3 position, Vector3 size, float rotation, Vector4? color = null)
|
||||
{
|
||||
VfxData* ptr = CreateVfxInternal(path, position, size, rotation, color ?? Vector4.One);
|
||||
return new VfxInstance(path, ptr, position, size, rotation, color ?? Vector4.One)
|
||||
{
|
||||
libOwned = true
|
||||
};
|
||||
}
|
||||
|
||||
public unsafe static VfxInstance Wrap(VfxData* data, Vector3 position, Vector3 size, float rotation, Vector4? color = null)
|
||||
{
|
||||
return new VfxInstance(null, data, position, size, rotation, color ?? Vector4.One);
|
||||
}
|
||||
|
||||
private unsafe VfxInstance(string? path, VfxData* data, Vector3 position, Vector3 size, float rotation, Vector4 color)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
throw new ArgumentNullException("data");
|
||||
}
|
||||
this.path = path;
|
||||
this.data = data;
|
||||
this.position = position;
|
||||
this.size = size;
|
||||
this.rotation = rotation;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public unsafe void Dispose()
|
||||
{
|
||||
if (libOwned && IsValid)
|
||||
{
|
||||
VfxNativeBridge.DestroyVfx(data);
|
||||
}
|
||||
data = null;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private unsafe static VfxData* CreateVfxInternal(string path, Vector3 position, Vector3 size, float rotation, Vector4 color)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(path + "\0");
|
||||
VfxInitData vfxInitData = default(VfxInitData);
|
||||
VfxNativeBridge.VfxInitDataCtor(&vfxInitData);
|
||||
fixed (byte* ptr = bytes)
|
||||
{
|
||||
VfxData* intPtr = VfxNativeBridge.CreateVfx(ptr, &vfxInitData, 2, 0, position.X, position.Y, position.Z, size.X, size.Y, size.Z, rotation, 1f, -1);
|
||||
intPtr->Instance->Color = color;
|
||||
return intPtr;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePosition(Vector3 position)
|
||||
{
|
||||
UpdateTransform(position, size, rotation);
|
||||
}
|
||||
|
||||
public void UpdateScale(Vector3 scale)
|
||||
{
|
||||
UpdateTransform(position, scale, rotation);
|
||||
}
|
||||
|
||||
public void UpdateRotation(float rotation)
|
||||
{
|
||||
UpdateTransform(position, size, rotation);
|
||||
}
|
||||
|
||||
public unsafe void UpdateTransform(Vector3 position, Vector3 size, float rotation)
|
||||
{
|
||||
MaybeRefreshVfxResourceInstance();
|
||||
if (!IsValid || (this.position == position && this.rotation == rotation && this.size == size))
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.position = position;
|
||||
this.size = size;
|
||||
this.rotation = rotation;
|
||||
using PinnedAlignedMatrix pinnedAlignedMatrix = new PinnedAlignedMatrix();
|
||||
Matrix4x4* get = pinnedAlignedMatrix.Get;
|
||||
get->M11 = size.X;
|
||||
get->M12 = 0f;
|
||||
get->M13 = 0f;
|
||||
get->M14 = 0f;
|
||||
get->M21 = 0f;
|
||||
get->M22 = size.Y;
|
||||
get->M23 = 0f;
|
||||
get->M24 = 0f;
|
||||
get->M31 = 0f;
|
||||
get->M32 = 0f;
|
||||
get->M33 = size.Z;
|
||||
get->M34 = 0f;
|
||||
VfxNativeBridge.RotateMatrix(get, rotation);
|
||||
get->M41 = position.X;
|
||||
get->M42 = position.Y;
|
||||
get->M43 = position.Z;
|
||||
get->M44 = 1f;
|
||||
VfxNativeBridge.UpdateVfxTransform(data->Instance, get);
|
||||
}
|
||||
|
||||
public unsafe void UpdateColor(Vector4 color)
|
||||
{
|
||||
if (IsValid && !(this.color == color))
|
||||
{
|
||||
this.color = color;
|
||||
VfxNativeBridge.UpdateVfxColor(data->Instance, color.X, color.Y, color.Z, color.W);
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe void MaybeRefreshVfxResourceInstance()
|
||||
{
|
||||
if (!IsValid && libOwned && path != null)
|
||||
{
|
||||
data = CreateVfxInternal(path, position, size, rotation, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
Auspex/Auspex.Vfx.Internal/VfxNativeBridge.cs
Normal file
68
Auspex/Auspex.Vfx.Internal/VfxNativeBridge.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using Auspex.Vfx.Native;
|
||||
|
||||
namespace Auspex.Vfx.Internal;
|
||||
|
||||
public static class VfxNativeBridge
|
||||
{
|
||||
public unsafe delegate VfxInitData* VfxInitDataCtorDelegate(VfxInitData* self);
|
||||
|
||||
public unsafe delegate VfxData* CreateVfxDelegate(byte* path, VfxInitData* init, byte a3, byte a4, float originX, float originY, float originZ, float sizeX, float sizeY, float sizeZ, float angle, float duration, int a13);
|
||||
|
||||
public unsafe delegate VfxData* CreateGameObjectVfxDelegate(byte* path, IntPtr target, IntPtr source, float a4, byte a5, ushort a6, byte a7);
|
||||
|
||||
public unsafe delegate void DestroyVfxDataDelegate(VfxData* self);
|
||||
|
||||
public unsafe delegate long UpdateVfxTransformDelegate(VfxResourceInstance* vfxInstance, Matrix4x4* transform);
|
||||
|
||||
public unsafe delegate long UpdateVfxColorDelegate(VfxResourceInstance* vfxInstance, float r, float g, float b, float a);
|
||||
|
||||
public unsafe delegate void RotateMatrixDelegate(Matrix4x4* matrix, float rotation);
|
||||
|
||||
public const string VfxInitDataCtorSig = "E8 ?? ?? ?? ?? 8D 57 06 48 8D 4C 24 ??";
|
||||
|
||||
public static VfxInitDataCtorDelegate VfxInitDataCtor;
|
||||
|
||||
public const string CreateVfxSig = "E8 ?? ?? ?? ?? 48 8B D8 48 8D 95";
|
||||
|
||||
public static CreateVfxDelegate CreateVfx;
|
||||
|
||||
public const string CreateGameObjectVfxSig = "E8 ?? ?? ?? ?? 48 8B D8 48 85 C0 74 27 B2 01";
|
||||
|
||||
public static CreateGameObjectVfxDelegate CreateGameObjectVfxInternal;
|
||||
|
||||
public const string DestroyVfxSig = "E8 ?? ?? ?? ?? 4D 89 A4 DE ?? ?? ?? ??";
|
||||
|
||||
public static DestroyVfxDataDelegate DestroyVfx;
|
||||
|
||||
public const string UpdateVfxTransformSig = "E8 ?? ?? ?? ?? EB 19 48 8B 0B";
|
||||
|
||||
public static UpdateVfxTransformDelegate UpdateVfxTransform;
|
||||
|
||||
public const string UpdateVfxColorSig = "E8 ?? ?? ?? ?? 8B 4B F3";
|
||||
|
||||
public static UpdateVfxColorDelegate UpdateVfxColor;
|
||||
|
||||
public const string RotateMatrixSig = "E8 ?? ?? ?? ?? 4C 8D 76 20";
|
||||
|
||||
public static RotateMatrixDelegate RotateMatrix;
|
||||
|
||||
internal static void Initialize()
|
||||
{
|
||||
VfxInitDataCtorDelegate vfxInitDataCtor = SigScanHelper.Scan<VfxInitDataCtorDelegate>("E8 ?? ?? ?? ?? 8D 57 06 48 8D 4C 24 ??", "VfxInitDataCtor");
|
||||
CreateVfxDelegate createVfx = SigScanHelper.Scan<CreateVfxDelegate>("E8 ?? ?? ?? ?? 48 8B D8 48 8D 95", "CreateVfx");
|
||||
CreateGameObjectVfxDelegate createGameObjectVfxInternal = SigScanHelper.Scan<CreateGameObjectVfxDelegate>("E8 ?? ?? ?? ?? 48 8B D8 48 85 C0 74 27 B2 01", "CreateGameObjectVfxInternal");
|
||||
DestroyVfxDataDelegate destroyVfx = SigScanHelper.Scan<DestroyVfxDataDelegate>("E8 ?? ?? ?? ?? 4D 89 A4 DE ?? ?? ?? ??", "DestroyVfx");
|
||||
UpdateVfxTransformDelegate updateVfxTransform = SigScanHelper.Scan<UpdateVfxTransformDelegate>("E8 ?? ?? ?? ?? EB 19 48 8B 0B", "UpdateVfxTransform");
|
||||
UpdateVfxColorDelegate updateVfxColor = SigScanHelper.Scan<UpdateVfxColorDelegate>("E8 ?? ?? ?? ?? 8B 4B F3", "UpdateVfxColor");
|
||||
RotateMatrixDelegate rotateMatrix = SigScanHelper.Scan<RotateMatrixDelegate>("E8 ?? ?? ?? ?? 4C 8D 76 20", "RotateMatrix");
|
||||
VfxInitDataCtor = vfxInitDataCtor;
|
||||
CreateVfx = createVfx;
|
||||
CreateGameObjectVfxInternal = createGameObjectVfxInternal;
|
||||
DestroyVfx = destroyVfx;
|
||||
UpdateVfxTransform = updateVfxTransform;
|
||||
UpdateVfxColor = updateVfxColor;
|
||||
RotateMatrix = rotateMatrix;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue