Fixed issue where .ArrayPtr() would not give the pointer to the desired array, and instead returned a pointer to an array of C# objects.

This commit is contained in:
Deukhoofd 2020-08-24 19:08:51 +02:00
parent 2c5f35c640
commit 8a7872cf3a
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 14 additions and 2 deletions

View File

@ -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<T>(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;