Prevent deobfuscation crash from using Il2CppType.From, and use faster method anyway

This commit is contained in:
Sinai 2021-05-19 21:26:44 +10:00
parent a9a53ba924
commit d0e508727a

View File

@ -15,6 +15,7 @@ using UnityExplorer.Core;
using CppType = Il2CppSystem.Type; using CppType = Il2CppSystem.Type;
using BF = System.Reflection.BindingFlags; using BF = System.Reflection.BindingFlags;
using UnityExplorer.Core.Config; using UnityExplorer.Core.Config;
using UnhollowerBaseLib.Attributes;
namespace UnityExplorer namespace UnityExplorer
{ {
@ -80,15 +81,19 @@ namespace UnityExplorer
{ {
try try
{ {
// Thanks to Slaynash for this if (!type.CustomAttributes.Any())
if (type.CustomAttributes.Any(it => it.AttributeType.Name == "ObfuscatedNameAttribute")) return;
{
var cppType = Il2CppType.From(type);
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); string obfuscatedName = att.ConstructorArguments[0].Value.ToString();
reverseDeobCache.Add(type.FullName, cppType.FullName);
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. // 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 // Force loading all il2cpp modules
internal void TryLoadGameModules() internal void TryLoadGameModules()