From 968121b93a1eef3327ac2b81554704ec5a13a2e8 Mon Sep 17 00:00:00 2001 From: EtherealPsyche Date: Mon, 6 Apr 2026 00:59:20 +0800 Subject: [PATCH] Skip hook `MetadataCache::GetTypeInfoFromTypeDefinitionIndex` if detected HybridCLR --- .../Injection/InjectorHelpers.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Il2CppInterop.Runtime/Injection/InjectorHelpers.cs b/Il2CppInterop.Runtime/Injection/InjectorHelpers.cs index 9bd9b0de..22e3d00a 100644 --- a/Il2CppInterop.Runtime/Injection/InjectorHelpers.cs +++ b/Il2CppInterop.Runtime/Injection/InjectorHelpers.cs @@ -75,13 +75,26 @@ internal static void Setup() GenericMethodGetMethodHook_Unity6.ApplyHook(); else GenericMethodGetMethodHook.ApplyHook(); - GetTypeInfoFromTypeDefinitionIndexHook.ApplyHook(); + if (IsHybridClrPresent()) + { + Logger.Instance.LogTrace("HybridCLR detected in game; MetadataCache::GetTypeInfoFromTypeDefinitionIndex will not be hooked."); + } + else + { + Logger.Instance.LogTrace("HybridCLR not detected; MetadataCache::GetTypeInfoFromTypeDefinitionIndex will be hooked."); + GetTypeInfoFromTypeDefinitionIndexHook.ApplyHook(); + } GetFieldDefaultValueHook.ApplyHook(); ClassInit ??= FindClassInit(); FromIl2CppTypeHook.ApplyHook(); FromNameHook.ApplyHook(); } + internal static bool IsHybridClrPresent() + { + return Il2CppSystem.Type.GetType("HybridCLR.RuntimeApi") != null; + } + internal static long CreateClassToken(IntPtr classPointer) { long newToken = Interlocked.Decrement(ref s_LastInjectedToken);