From 8a7872cf3a443c91bd4eeff98402cbad7ca6b597 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 24 Aug 2020 19:08:51 +0200 Subject: [PATCH] Fixed issue where .ArrayPtr() would not give the pointer to the desired array, and instead returned a pointer to an array of C# objects. --- PkmnLibSharp/Utilities/MarshalHelper.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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;