33 lines
907 B
C#
33 lines
907 B
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace PkmnLibSharp.Utils
|
|
{
|
|
internal static class FFIExtensions
|
|
{
|
|
internal static byte ForeignBool(this bool b)
|
|
{
|
|
return b ? (byte)1 : (byte)0;
|
|
}
|
|
|
|
internal static IntPtr ToPtr(this string? s)
|
|
{
|
|
if (s == null) return IntPtr.Zero;
|
|
return Marshal.StringToHGlobalAnsi(s);
|
|
}
|
|
|
|
internal static string? PtrString(this IntPtr i)
|
|
{
|
|
return i == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(i);
|
|
}
|
|
|
|
internal static IntPtr ArrayPtr(this IntPtr[] a)
|
|
{
|
|
return Marshal.UnsafeAddrOfPinnedArrayElement(a, 0);
|
|
}
|
|
internal static IntPtr ArrayPtr<T>(this T[] a) where T : struct, IConvertible
|
|
{
|
|
return Marshal.UnsafeAddrOfPinnedArrayElement(a, 0);
|
|
}
|
|
}
|
|
} |