diff --git a/PkmnLibSharp/Utilities/MarshalHelper.cs b/PkmnLibSharp/Utilities/MarshalHelper.cs index 0595908..4256106 100644 --- a/PkmnLibSharp/Utilities/MarshalHelper.cs +++ b/PkmnLibSharp/Utilities/MarshalHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Runtime.InteropServices; namespace PkmnLibSharp.Utilities @@ -15,11 +16,22 @@ namespace PkmnLibSharp.Utilities { return i == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(i); } - - internal static IntPtr ArrayPtr(this Array a) + + internal static IntPtr ArrayPtr(this IntPtr[] a) { return Marshal.UnsafeAddrOfPinnedArrayElement(a, 0); } + internal static IntPtr ArrayPtr(this T[] a) where T : struct, IConvertible + { + return Marshal.UnsafeAddrOfPinnedArrayElement(a, 0); + } + + internal static IntPtr ArrayPtr(this PointerWrapper?[] a) + { + return Marshal.UnsafeAddrOfPinnedArrayElement(a.Select(x => x?.Ptr ?? IntPtr.Zero).ToArray(), 0); + } + + internal const byte True = 1; internal const byte False = 0;