diff --git a/src/Core/Reflection/Il2CppReflection.cs b/src/Core/Reflection/Il2CppReflection.cs index 9e83455..50736df 100644 --- a/src/Core/Reflection/Il2CppReflection.cs +++ b/src/Core/Reflection/Il2CppReflection.cs @@ -64,7 +64,7 @@ namespace UnityExplorer #region Deobfuscation cache private static readonly Dictionary DeobfuscatedTypes = new Dictionary(); - //internal static Dictionary s_deobfuscatedTypeNames = new Dictionary(); + private static readonly Dictionary reverseDeobCache = new Dictionary(); private static void BuildDeobfuscationCache() { @@ -83,7 +83,6 @@ namespace UnityExplorer try { // Thanks to Slaynash for this - if (type.CustomAttributes.Any(it => it.AttributeType.Name == "ObfuscatedNameAttribute")) { var cppType = Il2CppType.From(type); @@ -91,13 +90,21 @@ namespace UnityExplorer if (!DeobfuscatedTypes.ContainsKey(cppType.FullName)) { DeobfuscatedTypes.Add(cppType.FullName, type); - //s_deobfuscatedTypeNames.Add(cppType.FullName, type.FullName); + reverseDeobCache.Add(type.FullName, cppType.FullName); } } } catch { } } + internal override string Internal_ProcessTypeInString(string theString, Type type) + { + if (reverseDeobCache.TryGetValue(type.FullName, out string obName)) + return theString.Replace(obName, type.FullName); + + return theString; + } + #endregion // Get type by name @@ -287,10 +294,7 @@ namespace UnityExplorer return null; if (type.IsEnum) - { - // TODO not tested return Il2CppSystem.Enum.ToObject(Il2CppType.From(type), (ulong)value); - } if (type.IsPrimitive && AllTypes.TryGetValue($"Il2Cpp{type.FullName}", out Type cppType)) { @@ -358,22 +362,6 @@ namespace UnityExplorer return s; } - internal override string Internal_ProcessTypeInString(string theString, Type type, ref string typeName) - { - if (!Il2CppTypeNotNull(type)) - return theString; - - var cppType = Il2CppType.From(type); - if (cppType != null && DeobfuscatedTypes.ContainsKey(cppType.FullName)) - { - typeName = DeobfuscatedTypes[cppType.FullName].FullName; - theString = theString.Replace(cppType.FullName, typeName); - } - - return theString; - } - - #endregion diff --git a/src/Core/Reflection/ReflectionUtility.cs b/src/Core/Reflection/ReflectionUtility.cs index 393c18f..d26631e 100644 --- a/src/Core/Reflection/ReflectionUtility.cs +++ b/src/Core/Reflection/ReflectionUtility.cs @@ -105,10 +105,10 @@ namespace UnityExplorer => obj; // Processing deobfuscated type names in strings - public static string ProcessTypeInString(Type type, string theString, ref string typeName) - => Instance.Internal_ProcessTypeInString(theString, type, ref typeName); + public static string ProcessTypeInString(Type type, string theString) + => Instance.Internal_ProcessTypeInString(theString, type); - internal virtual string Internal_ProcessTypeInString(string theString, Type type, ref string typeName) + internal virtual string Internal_ProcessTypeInString(string theString, Type type) => theString; // Force loading modules diff --git a/src/UI/Utility/ToStringUtility.cs b/src/UI/Utility/ToStringUtility.cs index 495469a..e5bcdb6 100644 --- a/src/UI/Utility/ToStringUtility.cs +++ b/src/UI/Utility/ToStringUtility.cs @@ -166,15 +166,14 @@ namespace UnityExplorer.UI.Utility toString = ex.ReflectionExToString(); } - string _ = null; - toString = ReflectionUtility.ProcessTypeInString(type, toString, ref _); + toString = ReflectionUtility.ProcessTypeInString(type, toString); #if CPP if (value is Il2CppSystem.Type cppType) { var monoType = Il2CppReflection.GetUnhollowedType(cppType); if (monoType != null) - toString = ReflectionUtility.ProcessTypeInString(monoType, toString, ref _); + toString = ReflectionUtility.ProcessTypeInString(monoType, toString); } #endif