Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit a9a53ba

Browse files
committed
Force load all Unhollowed DLLs, use Assembly.LoadFile instead of .Load, blacklist some more types
1 parent 3cd9819 commit a9a53ba

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
| 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) |
2121

2222
### Known issues
23-
* Issues with UnityEngine types in some 2020+ games - this is an issue with Unhollower, nothing I can do about it myself at the moment.
2423
* Any `MissingMethodException` or `NotSupportedException`: please report the issue and provide a copy of your mod loader log and/or Unity log.
2524
* 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.
2625
* In IL2CPP, some IEnumerable and IDictionary types may fail enumeration. Waiting for the Unhollower rewrite to address this any further.

src/Core/Input/InputManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static void InitHandler()
6161
// First, just try to use the legacy input, see if its working.
6262
// The InputSystem package may be present but not actually activated, so we can find out this way.
6363

64-
if (LegacyInput.TInput != null || (ReflectionUtility.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
64+
if (LegacyInput.TInput != null)
6565
{
6666
try
6767
{
@@ -80,7 +80,7 @@ private static void InitHandler()
8080
}
8181
}
8282

83-
if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
83+
if (InputSystem.TKeyboard != null)
8484
{
8585
try
8686
{

src/Core/Reflection/Il2CppReflection.cs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,17 @@ internal override object Internal_TryCast(object obj, Type castTo)
258258
}
259259
}
260260

261-
private static bool IsAssignableFrom(Type thisType, Type fromType)
262-
{
263-
if (!Il2CppTypeNotNull(fromType, out IntPtr fromTypePtr)
264-
|| !Il2CppTypeNotNull(thisType, out IntPtr thisTypePtr))
265-
{
266-
// one or both of the types are not Il2Cpp types, use normal check
267-
return thisType.IsAssignableFrom(fromType);
268-
}
269-
270-
return il2cpp_class_is_assignable_from(thisTypePtr, fromTypePtr);
271-
}
261+
//private static bool IsAssignableFrom(Type thisType, Type fromType)
262+
//{
263+
// if (!Il2CppTypeNotNull(fromType, out IntPtr fromTypePtr)
264+
// || !Il2CppTypeNotNull(thisType, out IntPtr thisTypePtr))
265+
// {
266+
// // one or both of the types are not Il2Cpp types, use normal check
267+
// return thisType.IsAssignableFrom(fromType);
268+
// }
269+
//
270+
// return il2cpp_class_is_assignable_from(thisTypePtr, fromTypePtr);
271+
//}
272272

273273
#endregion
274274

@@ -450,42 +450,35 @@ internal override void Internal_FindSingleton(string[] possibleNames, Type type,
450450

451451
#region Force-loading game modules
452452

453-
// Helper for IL2CPP to try to make sure the Unhollowed game assemblies are actually loaded.
454-
455-
internal override bool Internal_LoadModule(string moduleName)
456-
{
457-
if (!moduleName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase))
458-
moduleName += ".dll";
453+
internal static string UnhollowedFolderPath => Path.GetFullPath(
459454
#if ML
460-
var path = Path.Combine("MelonLoader", "Managed", $"{moduleName}");
455+
Path.Combine("MelonLoader", "Managed")
456+
#elif BIE
457+
Path.Combine("BepInEx", "unhollowed")
461458
#else
462-
var path = Path.Combine("BepInEx", "unhollowed", $"{moduleName}");
459+
Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Modules")
463460
#endif
464-
return DoLoadModule(path);
465-
}
461+
);
462+
463+
// Helper for IL2CPP to try to make sure the Unhollowed game assemblies are actually loaded.
464+
465+
//internal override bool Internal_LoadModule(string moduleName)
466+
//{
467+
// if (!moduleName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase))
468+
// moduleName += ".dll";
469+
//
470+
// return DoLoadModule(Path.Combine(UnhollowedFolderPath, moduleName));
471+
//}
466472

467473
// Force loading all il2cpp modules
468474

469475
internal void TryLoadGameModules()
470476
{
471-
string dirpath =
472-
#if ML
473-
Path.Combine("MelonLoader", "Managed");
474-
#elif BIE
475-
Path.Combine("BepInEx", "unhollowed");
476-
#else
477-
Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Modules");
478-
#endif
479-
;
480-
481-
if (Directory.Exists(dirpath))
477+
if (Directory.Exists(UnhollowedFolderPath))
482478
{
483-
var files = Directory.GetFiles(dirpath);
479+
var files = Directory.GetFiles(UnhollowedFolderPath);
484480
foreach (var filePath in files)
485481
{
486-
var name = Path.GetFileName(filePath);
487-
if (!name.StartsWith("Unity") && !name.StartsWith("Assembly-CSharp"))
488-
continue;
489482
try
490483
{
491484
DoLoadModule(filePath, true);
@@ -496,6 +489,8 @@ internal void TryLoadGameModules()
496489
}
497490
}
498491
}
492+
else
493+
ExplorerCore.LogWarning($"Expected Unhollowed folder path does not exist: '{UnhollowedFolderPath}'");
499494
}
500495

501496
internal bool DoLoadModule(string fullPath, bool suppressWarning = false)
@@ -505,7 +500,8 @@ internal bool DoLoadModule(string fullPath, bool suppressWarning = false)
505500

506501
try
507502
{
508-
Assembly.Load(File.ReadAllBytes(fullPath));
503+
Assembly.LoadFile(fullPath);
504+
//Assembly.Load(File.ReadAllBytes(fullPath));
509505
return true;
510506
}
511507
catch (Exception e)
@@ -648,6 +644,9 @@ internal bool DoLoadModule(string fullPath, bool suppressWarning = false)
648644
"UnityEngine.Scripting.GarbageCollector+CollectIncrementalDelegate.Invoke",
649645
"UnityEngine.Scripting.GarbageCollector.CollectIncremental",
650646
"UnityEngine.SpherecastCommand.ScheduleBatch",
647+
"UnityEngine.Texture.GetPixelDataSize",
648+
"UnityEngine.Texture.GetPixelDataOffset",
649+
"UnityEngine.Texture.GetPixelDataOffset",
651650
"UnityEngine.Texture2D+SetPixelDataImplArrayDelegate.Invoke",
652651
"UnityEngine.Texture2D+SetPixelDataImplDelegate.Invoke",
653652
"UnityEngine.Texture2D.SetPixelDataImpl",
@@ -669,6 +668,8 @@ internal bool DoLoadModule(string fullPath, bool suppressWarning = false)
669668
#endregion
670669

671670

671+
#region IL2CPP IEnumerable and IDictionary
672+
672673
protected override bool Internal_TryGetEntryType(Type enumerableType, out Type type)
673674
{
674675
// Check for system types (not unhollowed)
@@ -713,8 +714,6 @@ protected override bool Internal_TryGetEntryTypes(Type type, out Type keys, out
713714
return false;
714715
}
715716

716-
#region Temp il2cpp list/dictionary fixes
717-
718717
// Temp fix until Unhollower interface support improves
719718

720719
internal static readonly Dictionary<string, MethodInfo> getEnumeratorMethods = new Dictionary<string, MethodInfo>();

src/Core/Reflection/ReflectionUtility.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ public static string ProcessTypeInString(Type type, string theString)
151151
internal virtual string Internal_ProcessTypeInString(string theString, Type type)
152152
=> theString;
153153

154-
// Force loading modules
155-
public static bool LoadModule(string moduleName)
156-
=> Instance.Internal_LoadModule(moduleName);
154+
//// Force loading modules
155+
//public static bool LoadModule(string moduleName)
156+
// => Instance.Internal_LoadModule(moduleName);
157+
//
158+
//internal virtual bool Internal_LoadModule(string moduleName)
159+
// => false;
157160

158-
internal virtual bool Internal_LoadModule(string moduleName)
159-
=> false;
161+
// Singleton finder
160162

161163
public static void FindSingleton(string[] possibleNames, Type type, BindingFlags flags, List<object> instances)
162164
=> Instance.Internal_FindSingleton(possibleNames, type, flags, instances);
@@ -441,7 +443,6 @@ public static void LoadBlacklistString(string blacklist)
441443
blacklist = Instance.DefaultReflectionBlacklist;
442444
ConfigManager.Reflection_Signature_Blacklist.Value = blacklist;
443445
ConfigManager.Handler.SaveConfig();
444-
return;
445446
}
446447

447448
if (string.IsNullOrEmpty(blacklist))
@@ -466,6 +467,7 @@ public static bool IsBlacklisted(MemberInfo member)
466467
return false;
467468

468469
var sig = $"{member.DeclaringType.FullName}.{member.Name}";
470+
469471
return currentBlacklist.Contains(sig);
470472
}
471473

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace UnityExplorer
1919
public static class ExplorerCore
2020
{
2121
public const string NAME = "UnityExplorer";
22-
public const string VERSION = "4.0.1";
22+
public const string VERSION = "4.0.2";
2323
public const string AUTHOR = "Sinai";
2424
public const string GUID = "com.sinai.unityexplorer";
2525

src/UI/CacheObject/CacheMember.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ private static void TryCacheMember(MemberInfo member, List<CacheMember> list, Ha
246246
var sig = GetSig(member);
247247

248248
//ExplorerCore.Log($"Trying to cache member {sig}...");
249-
//ExplorerCore.Log(member.DeclaringType.FullName + "." + member.Name);
250249

251250
CacheMember cached;
252251
Type returnType;
@@ -324,7 +323,8 @@ private static void TryCacheMember(MemberInfo member, List<CacheMember> list, Ha
324323
}
325324
}
326325

327-
internal static string GetSig(MemberInfo member) => $"{member.DeclaringType.Name}.{member.Name}";
326+
internal static string GetSig(MemberInfo member)
327+
=> $"{member.DeclaringType.Name}.{member.Name}";
328328

329329
internal static string GetArgumentString(ParameterInfo[] args)
330330
{

0 commit comments

Comments
 (0)