You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.1 KiB

using System;
using System.IO;
using System.Runtime.InteropServices;
using AOT;
using Epic.OnlineServices;
public static class EOSNativeHelper
{
#if UNITY_STANDALONE_WIN
[DllImport("kernel32", EntryPoint = "LoadLibrary", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibraryNative(string lpFileName);
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetDllDirectory(string lpPathName);
public static IntPtr LoadLibrary(string lpFileName)
{
string lpPathName = Path.GetDirectoryName(lpFileName);
lpFileName = Path.GetFileName(lpFileName);
SetDllDirectory(lpPathName.Replace('/', '\\'));
return LoadLibraryNative(lpFileName);
}
[DllImport("kernel32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
#endif
[UnmanagedFunctionPointer(Config.LibraryCallingConvention)]
public delegate IntPtr AllocateMemoryFunc(IntPtr size, IntPtr alignment);
[MonoPInvokeCallback(typeof(AllocateMemoryFunc))]
public static IntPtr AllocateMemory(IntPtr size, IntPtr alignment)
{
return Marshal.AllocHGlobal(size);
}
[UnmanagedFunctionPointer(Config.LibraryCallingConvention)]
public delegate IntPtr ReallocateMemoryFunc(IntPtr pointer, IntPtr size, IntPtr alignment);
[MonoPInvokeCallback(typeof(ReallocateMemoryFunc))]
public static IntPtr ReallocateMemory(IntPtr pointer, IntPtr size, IntPtr alignment)
{
if (pointer == IntPtr.Zero)
return Marshal.AllocHGlobal(size);
return Marshal.ReAllocHGlobal(pointer, size);
}
[UnmanagedFunctionPointer(Config.LibraryCallingConvention)]
public delegate void ReleaseMemoryFunc(IntPtr pointer);
[MonoPInvokeCallback(typeof(ReleaseMemoryFunc))]
public static void ReleaseMemory(IntPtr pointer)
{
Marshal.FreeHGlobal(pointer);
}
}