Skip to content

Commit

Permalink
PR BepInEx#103 changes & logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dlbuhtig4096 committed Sep 28, 2023
1 parent f38c606 commit 233f000
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Il2CppInterop.Runtime/Injection/ClassInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ static void FindAbstractMethods(List<INativeMethodInfoStruct> list, INativeClass

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

Logger.Instance.LogInformation("Processing {type}::{methodName}", type, methodName);

if (methodName == "Finalize") // slot number is not static
{
vTablePointer[i].method = methodPointerArray[0];
Expand Down Expand Up @@ -1138,8 +1140,13 @@ private static string GetIl2CppTypeFullName(Il2CppTypeStruct* typePointer)

internal static Type SystemTypeFromIl2CppType(Il2CppTypeStruct* typePointer)
{
var fullName = GetIl2CppTypeFullName(typePointer);
var type = Type.GetType(fullName) ?? throw new NullReferenceException($"Couldn't find System.Type for Il2Cpp type: {fullName}");
var il2cppType = UnityVersionHandler.Wrap(typePointer);

if (!InjectorHelpers.TryGetType((IntPtr)il2cppType.TypePointer, out var type))
{
var fullName = GetIl2CppTypeFullName(typePointer);
type = Type.GetType(fullName) ?? throw new NullReferenceException($"Couldn't find System.Type for Il2Cpp type: {fullName}");
}
return RewriteType(type);
}

Expand Down
7 changes: 7 additions & 0 deletions Il2CppInterop.Runtime/Injection/InjectorHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ internal static void AddTypeToLookup(Type type, IntPtr typePointer)
{
s_ClassNameLookup.Add((namespaze, klass, image), typePointer);
}
s_TypeLookup[typePointer] = type;
}

internal static bool TryGetType(IntPtr typePointer, out Type type)
{
return s_TypeLookup.TryGetValue(typePointer, out type);
}

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

#region Class::Init
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
Expand Down

0 comments on commit 233f000

Please sign in to comment.