Force load all Unhollowed DLLs, use Assembly.LoadFile instead of .Load, blacklist some more types

This commit is contained in:
Sinai 2021-05-19 20:48:34 +10:00
parent 3cd9819790
commit a9a53ba924
6 changed files with 52 additions and 52 deletions

View File

@ -20,7 +20,6 @@
| Standalone | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Standalone.Il2Cpp.zip) | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Standalone.Mono.zip) | | Standalone | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Standalone.Il2Cpp.zip) | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Standalone.Mono.zip) |
### Known issues ### Known issues
* Issues with UnityEngine types in some 2020+ games - this is an issue with Unhollower, nothing I can do about it myself at the moment.
* Any `MissingMethodException` or `NotSupportedException`: please report the issue and provide a copy of your mod loader log and/or Unity log. * Any `MissingMethodException` or `NotSupportedException`: please report the issue and provide a copy of your mod loader log and/or Unity log.
* The C# console may unexpectedly produce a GC Mark Overflow crash when calling certain outside methods. Not clear yet what is causing this, but it's being looked into. * The C# console may unexpectedly produce a GC Mark Overflow crash when calling certain outside methods. Not clear yet what is causing this, but it's being looked into.
* In IL2CPP, some IEnumerable and IDictionary types may fail enumeration. Waiting for the Unhollower rewrite to address this any further. * In IL2CPP, some IEnumerable and IDictionary types may fail enumeration. Waiting for the Unhollower rewrite to address this any further.

View File

@ -61,7 +61,7 @@ namespace UnityExplorer.Core.Input
// First, just try to use the legacy input, see if its working. // First, just try to use the legacy input, see if its working.
// The InputSystem package may be present but not actually activated, so we can find out this way. // The InputSystem package may be present but not actually activated, so we can find out this way.
if (LegacyInput.TInput != null || (ReflectionUtility.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null)) if (LegacyInput.TInput != null)
{ {
try try
{ {
@ -80,7 +80,7 @@ namespace UnityExplorer.Core.Input
} }
} }
if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null)) if (InputSystem.TKeyboard != null)
{ {
try try
{ {

View File

@ -258,17 +258,17 @@ namespace UnityExplorer
} }
} }
private static bool IsAssignableFrom(Type thisType, Type fromType) //private static bool IsAssignableFrom(Type thisType, Type fromType)
{ //{
if (!Il2CppTypeNotNull(fromType, out IntPtr fromTypePtr) // if (!Il2CppTypeNotNull(fromType, out IntPtr fromTypePtr)
|| !Il2CppTypeNotNull(thisType, out IntPtr thisTypePtr)) // || !Il2CppTypeNotNull(thisType, out IntPtr thisTypePtr))
{ // {
// one or both of the types are not Il2Cpp types, use normal check // // one or both of the types are not Il2Cpp types, use normal check
return thisType.IsAssignableFrom(fromType); // return thisType.IsAssignableFrom(fromType);
} // }
//
return il2cpp_class_is_assignable_from(thisTypePtr, fromTypePtr); // return il2cpp_class_is_assignable_from(thisTypePtr, fromTypePtr);
} //}
#endregion #endregion
@ -450,42 +450,35 @@ namespace UnityExplorer
#region Force-loading game modules #region Force-loading game modules
internal static string UnhollowedFolderPath => Path.GetFullPath(
#if ML
Path.Combine("MelonLoader", "Managed")
#elif BIE
Path.Combine("BepInEx", "unhollowed")
#else
Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Modules")
#endif
);
// 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) //internal override bool Internal_LoadModule(string moduleName)
{ //{
if (!moduleName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase)) // if (!moduleName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase))
moduleName += ".dll"; // moduleName += ".dll";
#if ML //
var path = Path.Combine("MelonLoader", "Managed", $"{moduleName}"); // return DoLoadModule(Path.Combine(UnhollowedFolderPath, moduleName));
#else //}
var path = Path.Combine("BepInEx", "unhollowed", $"{moduleName}");
#endif
return DoLoadModule(path);
}
// Force loading all il2cpp modules // Force loading all il2cpp modules
internal void TryLoadGameModules() internal void TryLoadGameModules()
{ {
string dirpath = if (Directory.Exists(UnhollowedFolderPath))
#if ML
Path.Combine("MelonLoader", "Managed");
#elif BIE
Path.Combine("BepInEx", "unhollowed");
#else
Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Modules");
#endif
;
if (Directory.Exists(dirpath))
{ {
var files = Directory.GetFiles(dirpath); var files = Directory.GetFiles(UnhollowedFolderPath);
foreach (var filePath in files) foreach (var filePath in files)
{ {
var name = Path.GetFileName(filePath);
if (!name.StartsWith("Unity") && !name.StartsWith("Assembly-CSharp"))
continue;
try try
{ {
DoLoadModule(filePath, true); DoLoadModule(filePath, true);
@ -496,6 +489,8 @@ namespace UnityExplorer
} }
} }
} }
else
ExplorerCore.LogWarning($"Expected Unhollowed folder path does not exist: '{UnhollowedFolderPath}'");
} }
internal bool DoLoadModule(string fullPath, bool suppressWarning = false) internal bool DoLoadModule(string fullPath, bool suppressWarning = false)
@ -505,7 +500,8 @@ namespace UnityExplorer
try try
{ {
Assembly.Load(File.ReadAllBytes(fullPath)); Assembly.LoadFile(fullPath);
//Assembly.Load(File.ReadAllBytes(fullPath));
return true; return true;
} }
catch (Exception e) catch (Exception e)
@ -648,6 +644,9 @@ namespace UnityExplorer
"UnityEngine.Scripting.GarbageCollector+CollectIncrementalDelegate.Invoke", "UnityEngine.Scripting.GarbageCollector+CollectIncrementalDelegate.Invoke",
"UnityEngine.Scripting.GarbageCollector.CollectIncremental", "UnityEngine.Scripting.GarbageCollector.CollectIncremental",
"UnityEngine.SpherecastCommand.ScheduleBatch", "UnityEngine.SpherecastCommand.ScheduleBatch",
"UnityEngine.Texture.GetPixelDataSize",
"UnityEngine.Texture.GetPixelDataOffset",
"UnityEngine.Texture.GetPixelDataOffset",
"UnityEngine.Texture2D+SetPixelDataImplArrayDelegate.Invoke", "UnityEngine.Texture2D+SetPixelDataImplArrayDelegate.Invoke",
"UnityEngine.Texture2D+SetPixelDataImplDelegate.Invoke", "UnityEngine.Texture2D+SetPixelDataImplDelegate.Invoke",
"UnityEngine.Texture2D.SetPixelDataImpl", "UnityEngine.Texture2D.SetPixelDataImpl",
@ -669,6 +668,8 @@ namespace UnityExplorer
#endregion #endregion
#region IL2CPP IEnumerable and IDictionary
protected override bool Internal_TryGetEntryType(Type enumerableType, out Type type) protected override bool Internal_TryGetEntryType(Type enumerableType, out Type type)
{ {
// Check for system types (not unhollowed) // Check for system types (not unhollowed)
@ -713,8 +714,6 @@ namespace UnityExplorer
return false; return false;
} }
#region Temp il2cpp list/dictionary fixes
// Temp fix until Unhollower interface support improves // Temp fix until Unhollower interface support improves
internal static readonly Dictionary<string, MethodInfo> getEnumeratorMethods = new Dictionary<string, MethodInfo>(); internal static readonly Dictionary<string, MethodInfo> getEnumeratorMethods = new Dictionary<string, MethodInfo>();

View File

@ -151,12 +151,14 @@ namespace UnityExplorer
internal virtual string Internal_ProcessTypeInString(string theString, Type type) internal virtual string Internal_ProcessTypeInString(string theString, Type type)
=> theString; => theString;
// Force loading modules //// Force loading modules
public static bool LoadModule(string moduleName) //public static bool LoadModule(string moduleName)
=> Instance.Internal_LoadModule(moduleName); // => Instance.Internal_LoadModule(moduleName);
//
//internal virtual bool Internal_LoadModule(string moduleName)
// => false;
internal virtual bool Internal_LoadModule(string moduleName) // Singleton finder
=> false;
public static void FindSingleton(string[] possibleNames, Type type, BindingFlags flags, List<object> instances) public static void FindSingleton(string[] possibleNames, Type type, BindingFlags flags, List<object> instances)
=> Instance.Internal_FindSingleton(possibleNames, type, flags, instances); => Instance.Internal_FindSingleton(possibleNames, type, flags, instances);
@ -441,7 +443,6 @@ namespace UnityExplorer
blacklist = Instance.DefaultReflectionBlacklist; blacklist = Instance.DefaultReflectionBlacklist;
ConfigManager.Reflection_Signature_Blacklist.Value = blacklist; ConfigManager.Reflection_Signature_Blacklist.Value = blacklist;
ConfigManager.Handler.SaveConfig(); ConfigManager.Handler.SaveConfig();
return;
} }
if (string.IsNullOrEmpty(blacklist)) if (string.IsNullOrEmpty(blacklist))
@ -466,6 +467,7 @@ namespace UnityExplorer
return false; return false;
var sig = $"{member.DeclaringType.FullName}.{member.Name}"; var sig = $"{member.DeclaringType.FullName}.{member.Name}";
return currentBlacklist.Contains(sig); return currentBlacklist.Contains(sig);
} }

View File

@ -19,7 +19,7 @@ namespace UnityExplorer
public static class ExplorerCore public static class ExplorerCore
{ {
public const string NAME = "UnityExplorer"; public const string NAME = "UnityExplorer";
public const string VERSION = "4.0.1"; public const string VERSION = "4.0.2";
public const string AUTHOR = "Sinai"; public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer"; public const string GUID = "com.sinai.unityexplorer";

View File

@ -246,7 +246,6 @@ namespace UnityExplorer.UI.CacheObject
var sig = GetSig(member); var sig = GetSig(member);
//ExplorerCore.Log($"Trying to cache member {sig}..."); //ExplorerCore.Log($"Trying to cache member {sig}...");
//ExplorerCore.Log(member.DeclaringType.FullName + "." + member.Name);
CacheMember cached; CacheMember cached;
Type returnType; Type returnType;
@ -324,7 +323,8 @@ namespace UnityExplorer.UI.CacheObject
} }
} }
internal static string GetSig(MemberInfo member) => $"{member.DeclaringType.Name}.{member.Name}"; internal static string GetSig(MemberInfo member)
=> $"{member.DeclaringType.Name}.{member.Name}";
internal static string GetArgumentString(ParameterInfo[] args) internal static string GetArgumentString(ParameterInfo[] args)
{ {