From d0e508727a8ff416379fd064338bdf0cead790cc Mon Sep 17 00:00:00 2001 From: Sinai Date: Wed, 19 May 2021 21:26:44 +1000 Subject: [PATCH] Prevent deobfuscation crash from using Il2CppType.From, and use faster method anyway --- src/Core/Reflection/Il2CppReflection.cs | 27 +++++++++++-------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Core/Reflection/Il2CppReflection.cs b/src/Core/Reflection/Il2CppReflection.cs index 9a6062c..3132308 100644 --- a/src/Core/Reflection/Il2CppReflection.cs +++ b/src/Core/Reflection/Il2CppReflection.cs @@ -15,6 +15,7 @@ using UnityExplorer.Core; using CppType = Il2CppSystem.Type; using BF = System.Reflection.BindingFlags; using UnityExplorer.Core.Config; +using UnhollowerBaseLib.Attributes; namespace UnityExplorer { @@ -80,15 +81,19 @@ namespace UnityExplorer { try { - // Thanks to Slaynash for this - if (type.CustomAttributes.Any(it => it.AttributeType.Name == "ObfuscatedNameAttribute")) - { - var cppType = Il2CppType.From(type); + if (!type.CustomAttributes.Any()) + return; - if (!DeobfuscatedTypes.ContainsKey(cppType.FullName)) + foreach (var att in type.CustomAttributes) + { + // Thanks to Slaynash for this + + if (att.AttributeType == typeof(ObfuscatedNameAttribute)) { - DeobfuscatedTypes.Add(cppType.FullName, type); - reverseDeobCache.Add(type.FullName, cppType.FullName); + string obfuscatedName = att.ConstructorArguments[0].Value.ToString(); + + DeobfuscatedTypes.Add(obfuscatedName, type); + reverseDeobCache.Add(type.FullName, obfuscatedName); } } } @@ -462,14 +467,6 @@ namespace UnityExplorer // Helper for IL2CPP to try to make sure the Unhollowed game assemblies are actually loaded. - //internal override bool Internal_LoadModule(string moduleName) - //{ - // if (!moduleName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase)) - // moduleName += ".dll"; - // - // return DoLoadModule(Path.Combine(UnhollowedFolderPath, moduleName)); - //} - // Force loading all il2cpp modules internal void TryLoadGameModules()