42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
using Dalamud.Game.ClientState.Objects.Types;
|
|
using System.Text.Json;
|
|
|
|
namespace MareSynchronos.Utils;
|
|
|
|
public static class VariousExtensions
|
|
{
|
|
public static T DeepClone<T>(this T obj)
|
|
{
|
|
return JsonSerializer.Deserialize<T>(JsonSerializer.Serialize(obj))!;
|
|
}
|
|
|
|
public static unsafe int? ObjectTableIndex(this GameObject? gameObject)
|
|
{
|
|
if (gameObject == null || gameObject.Address == IntPtr.Zero)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)gameObject.Address)->ObjectIndex;
|
|
}
|
|
|
|
public static void CancelDispose(this CancellationTokenSource? cts)
|
|
{
|
|
try
|
|
{
|
|
cts?.Cancel();
|
|
cts?.Dispose();
|
|
}
|
|
catch(ObjectDisposedException)
|
|
{
|
|
// swallow it
|
|
}
|
|
}
|
|
|
|
public static CancellationTokenSource CancelRecreate(this CancellationTokenSource? cts)
|
|
{
|
|
cts.CancelDispose();
|
|
return new CancellationTokenSource();
|
|
}
|
|
}
|