Skip to content

Commit 233f000

Browse files
author
dlbuhtig4096
committed
PR BepInEx#103 changes & logging
1 parent f38c606 commit 233f000

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Il2CppInterop.Runtime/Injection/ClassInjector.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ static void FindAbstractMethods(List<INativeMethodInfoStruct> list, INativeClass
412412

413413
var methodName = Marshal.PtrToStringAnsi(baseMethod.Name);
414414

415+
Logger.Instance.LogInformation("Processing {type}::{methodName}", type, methodName);
416+
415417
if (methodName == "Finalize") // slot number is not static
416418
{
417419
vTablePointer[i].method = methodPointerArray[0];
@@ -1138,8 +1140,13 @@ private static string GetIl2CppTypeFullName(Il2CppTypeStruct* typePointer)
11381140

11391141
internal static Type SystemTypeFromIl2CppType(Il2CppTypeStruct* typePointer)
11401142
{
1141-
var fullName = GetIl2CppTypeFullName(typePointer);
1142-
var type = Type.GetType(fullName) ?? throw new NullReferenceException($"Couldn't find System.Type for Il2Cpp type: {fullName}");
1143+
var il2cppType = UnityVersionHandler.Wrap(typePointer);
1144+
1145+
if (!InjectorHelpers.TryGetType((IntPtr)il2cppType.TypePointer, out var type))
1146+
{
1147+
var fullName = GetIl2CppTypeFullName(typePointer);
1148+
type = Type.GetType(fullName) ?? throw new NullReferenceException($"Couldn't find System.Type for Il2Cpp type: {fullName}");
1149+
}
11431150
return RewriteType(type);
11441151
}
11451152

Il2CppInterop.Runtime/Injection/InjectorHelpers.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ internal static void AddTypeToLookup(Type type, IntPtr typePointer)
9898
{
9999
s_ClassNameLookup.Add((namespaze, klass, image), typePointer);
100100
}
101+
s_TypeLookup[typePointer] = type;
102+
}
103+
104+
internal static bool TryGetType(IntPtr typePointer, out Type type)
105+
{
106+
return s_TypeLookup.TryGetValue(typePointer, out type);
101107
}
102108

103109
internal static IntPtr GetIl2CppExport(string name)
@@ -137,6 +143,7 @@ internal static IntPtr GetIl2CppMethodPointer(MethodBase proxyMethod)
137143
internal static readonly ConcurrentDictionary<long, IntPtr> s_InjectedClasses = new();
138144
/// <summary> (namespace, class, image) : class </summary>
139145
internal static readonly Dictionary<(string _namespace, string _class, IntPtr imagePtr), IntPtr> s_ClassNameLookup = new();
146+
internal static readonly Dictionary<IntPtr, Type> s_TypeLookup = new();
140147

141148
#region Class::Init
142149
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]

0 commit comments

Comments
 (0)