2020-10-16 19:40:01 +11:00
|
|
|
|
#if CPP
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-10-18 21:41:04 +11:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
using System.Runtime.InteropServices;
|
2020-10-16 19:40:01 +11:00
|
|
|
|
|
2020-10-23 01:50:33 +11:00
|
|
|
|
namespace ExplorerBeta.Helpers
|
2020-10-16 19:40:01 +11:00
|
|
|
|
{
|
2020-10-18 21:41:04 +11:00
|
|
|
|
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")]
|
2020-10-16 19:40:01 +11:00
|
|
|
|
public static class ICallHelper
|
|
|
|
|
{
|
|
|
|
|
private static readonly Dictionary<string, Delegate> iCallCache = new Dictionary<string, Delegate>();
|
|
|
|
|
|
|
|
|
|
public static T GetICall<T>(string iCallName) where T : Delegate
|
|
|
|
|
{
|
|
|
|
|
if (iCallCache.ContainsKey(iCallName))
|
|
|
|
|
return (T)iCallCache[iCallName];
|
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
IntPtr ptr = il2cpp_resolve_icall(iCallName);
|
2020-10-16 19:40:01 +11:00
|
|
|
|
|
|
|
|
|
if (ptr == IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
throw new MissingMethodException($"Could not resolve internal call by name '{iCallName}'!");
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
Delegate iCall = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T));
|
2020-10-16 19:40:01 +11:00
|
|
|
|
iCallCache.Add(iCallName, iCall);
|
|
|
|
|
|
|
|
|
|
return (T)iCall;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
|
|
|
public static extern IntPtr il2cpp_resolve_icall([MarshalAs(UnmanagedType.LPStr)] string name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|