(ded4a3e0a) v0.9.0.7

This commit is contained in:
Joonas Rikkonen
2019-06-25 16:00:44 +03:00
parent e5ae622c77
commit 4a51db77b5
1777 changed files with 421528 additions and 917 deletions
@@ -0,0 +1,39 @@
using System;
using System.Runtime.InteropServices;
namespace TwoMGFX
{
internal class MarshalHelper
{
public static T Unmarshal<T>(IntPtr ptr)
{
var type = typeof(T);
var result = (T)Marshal.PtrToStructure(ptr, type);
return result;
}
public static T[] UnmarshalArray<T>(IntPtr ptr, int count)
{
var type = typeof(T);
var size = Marshal.SizeOf(type);
var ret = new T[count];
for (int i = 0; i < count; i++)
{
var offset = i * size;
var structPtr = new IntPtr(ptr.ToInt64() + offset);
ret[i] = (T)Marshal.PtrToStructure(structPtr, type);
}
return ret;
}
public static byte[] UnmarshalArray(IntPtr ptr, int count)
{
var result = new byte[count];
Marshal.Copy(ptr, result, 0, count);
return result;
}
}
}