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.
68 lines
2.4 KiB
68 lines
2.4 KiB
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
public static class SystemLibrary
|
|
{
|
|
#if UNITY_STANDALONE_WIN || UNITY_GAMECORE
|
|
[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);
|
|
#elif UNITY_PS4 || UNITY_PS5
|
|
[DllImport("SceKernelShim.prx", EntryPoint = "LoadLibrary")]
|
|
private static extern Int32 LoadLibraryNative(string filename);
|
|
|
|
public static IntPtr LoadLibrary(string filename)
|
|
{
|
|
Int32 moduleHandle = LoadLibraryNative(filename);
|
|
if (moduleHandle <= 0)
|
|
{
|
|
UnityEngine.Debug.LogError($"Error loading PRX module '{filename}', error code = 0x{moduleHandle:X}");
|
|
return IntPtr.Zero;
|
|
}
|
|
|
|
return new IntPtr(moduleHandle);
|
|
}
|
|
|
|
[DllImport("SceKernelShim.prx", EntryPoint = "FreeLibrary")]
|
|
private static extern bool FreeLibraryNative(Int32 moduleHandle);
|
|
|
|
public static bool FreeLibrary(IntPtr hModule)
|
|
{
|
|
return FreeLibraryNative(hModule.ToInt32());
|
|
}
|
|
|
|
[DllImport("SceKernelShim.prx")]
|
|
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
|
|
#endif
|
|
|
|
#if UNITY_GAMECORE
|
|
[DllImport("kernel32", SetLastError = true)]
|
|
public static extern IntPtr GetProcessHeap();
|
|
|
|
[DllImport("kernel32")]
|
|
public static extern IntPtr HeapAlloc(IntPtr hHeap, int dwFlags, IntPtr dwBytes);
|
|
|
|
[DllImport("kernel32")]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool HeapFree(IntPtr hHeap, int dwFlags, IntPtr lpMem);
|
|
#endif
|
|
}
|