Skip to content

Commit 4242569

Browse files
Merge pull request #746 from LavaGang/alpha-development
MelonLoader v0.6.5 (P2)
2 parents bed7261 + 957b424 commit 4242569

File tree

15 files changed

+823
-79
lines changed

15 files changed

+823
-79
lines changed

CHANGELOG.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@
3939

4040
### v0.6.5
4141

42-
1. Replaced [BepInEx/Il2CppInterop](https://github.com/BepInEx/Il2CppInterop) with [ds5678/Il2CppInterop](https://github.com/ds5678/Il2CppInterop)
43-
2. Updated Il2CppInterop to 1.5.4
44-
3. Updated Cpp2IL to 2022.1.0-pre-release.18
45-
4. Updated AsmResolver to 6.0.0-beta.1
46-
5. Updated AssetRipper.VersionUtilities to 1.5.0
47-
6. Updated AssetsTools.NET to 3.0.0
48-
7. Updated UnityEngine.Il2CppAssetBundleManager for latest compatibility
49-
8. Updated UnityEngine.Il2CppImageConversionManager for latest compatibility
50-
9. Implemented `--cpp2il.callanalyzer` launch option to enable Cpp2IL's CallAnalyzer processor
51-
10. Implemented `--cpp2il.nativemethoddetector` launch option to enable Cpp2IL's NativeMethodDetector processor
52-
11. Implemented several fixes for Il2CppInterop related issues
53-
12. Implemented Cpp2IL's StrippedCodeRegSupport plugin
54-
13. Implemented `ExternalArguments` Dictionary for MelonLaunchOptions (Credits to [HAHOOS](https://github.com/HAHOOS) :P)
55-
14. Implemented `Peek` Method for LemonEnumerator
42+
1. Updated Il2CppInterop to 1.4.6-ci.545
43+
2. Updated Cpp2IL to 2022.1.0-pre-release.18
44+
3. Updated AsmResolver to 6.0.0-beta.1
45+
4. Updated AssetRipper.VersionUtilities to 1.5.0
46+
5. Updated AssetsTools.NET to 3.0.0
47+
6. Updated UnityEngine.Il2CppAssetBundleManager for latest compatibility
48+
7. Updated UnityEngine.Il2CppImageConversionManager for latest compatibility
49+
8. Implemented `--cpp2il.callanalyzer` launch option to enable Cpp2IL's CallAnalyzer processor
50+
9. Implemented `--cpp2il.nativemethoddetector` launch option to enable Cpp2IL's NativeMethodDetector processor
51+
10. Implemented several fixes for Il2CppInterop related issues
52+
11. Implemented `ExternalArguments` Dictionary for MelonLaunchOptions (Credits to [HAHOOS](https://github.com/HAHOOS) :P)
53+
12. Implemented `MsgPastel` Method for MelonLogger (Credits to [HAHOOS](https://github.com/HAHOOS) :P)
54+
13. Implemented `Peek` Method for LemonEnumerator
55+
14. Implemented ICallInjector for handling when Unity strips or renames Internal Calls
5656
15. Fixed an accidental regression with LemonSHA256
5757
16. Fixed an issue with Native logs using the wrong Colors
5858
17. Fixed an issue with Preload module not replacing Mono libraries on Older Mono Games
@@ -66,9 +66,13 @@
6666
25. Fixed an issue with EOS Support Module not being properly error handled
6767
26. Fixed an issue with NativeStackWalk not unregistering addresses
6868
27. Fixed an issue with Errors being Spammed if `UnityEngine.Transform::SetAsLastSibling` fails to resolve
69-
28. Fixed an issue with MelonLaunchOptions failing to parse arguments if an `=` sign is used instead of a space
70-
29. Fixed an issue with MelonLaunchOptions failing to parse options if a `-` prefix is used instead of `--`
69+
28. Fixed an issue with MelonLaunchOptions failing to parse options if a `-` prefix is used instead of `--`
70+
29. Fixed an issue with MelonLaunchOptions failing to parse option arguments if an `=` sign is used instead of a space
7171
30. Fixed an issue with Command Line Arguments not being logged
72+
31. Fixed an issue with Il2CppInterop Assembly Resolving when Il2Cpp Prefixing is used
73+
32. Fixed an issue with .NET Executables not being Resolved properly when used as Dependencies
74+
33. Fixed an issue with Dependency Graph failing to Resolve Assemblies properly
75+
34. Fixed an issue with Il2Cpp Support Module not attempting to use direct references
7276

7377
---
7478

Dependencies/Il2CppAssemblyGenerator/Core.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static int Run()
6060
RemoteAPI.Contact();
6161

6262
cpp2il = new Cpp2IL();
63-
cpp2il_scrs = new Cpp2IL_StrippedCodeRegSupport(cpp2il);
63+
//cpp2il_scrs = new Cpp2IL_StrippedCodeRegSupport(cpp2il);
6464

6565
il2cppinterop = new Packages.Il2CppInterop();
6666
unitydependencies = new UnityDependencies();
@@ -73,7 +73,7 @@ private static int Run()
7373
Logger.Msg($"Using Deobfuscation Regex = {(string.IsNullOrEmpty(deobfuscationRegex.Regex) ? "null" : deobfuscationRegex.Regex)}");
7474

7575
if (!cpp2il.Setup()
76-
|| !cpp2il_scrs.Setup()
76+
//|| !cpp2il_scrs.Setup()
7777
|| !il2cppinterop.Setup()
7878
|| !unitydependencies.Setup()
7979
|| !deobfuscationMap.Setup())

Dependencies/Il2CppAssemblyGenerator/Il2CppAssemblyGenerator.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<ItemGroup>
1616
<ProjectReference Include="..\..\MelonLoader\MelonLoader.csproj" Private="false" />
1717
<PackageReference Include="Iced" Version="1.21.0" ExcludeAssets="Runtime" />
18-
<PackageReference Include="ds5678.Il2CppInterop.Generator" Version="1.5.4" ExcludeAssets="Runtime" />
19-
<PackageReference Include="ds5678.Il2CppInterop.Common" Version="1.5.4" ExcludeAssets="Runtime" />
20-
<PackageReference Include="ds5678.Il2CppInterop.Runtime" Version="1.5.4" ExcludeAssets="Runtime" />
18+
<PackageReference Include="Il2CppInterop.Generator" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
19+
<PackageReference Include="Il2CppInterop.Common" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
20+
<PackageReference Include="Il2CppInterop.Runtime" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
2121
<PackageReference Include="Mono.Cecil" Version="0.11.5" ExcludeAssets="Runtime" />
2222
<PackageReference Include="AssetRipper.VersionUtilities" Version="1.5.0" ExcludeAssets="Runtime" />
2323
</ItemGroup>

Dependencies/SupportModules/Component.cs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
using System;
2+
using System.Reflection;
3+
using UnityEngine;
4+
25
#if SM_Il2Cpp
36
using Il2CppInterop.Runtime;
4-
#else
5-
using System.Reflection;
67
#endif
7-
using UnityEngine;
88

99
namespace MelonLoader.Support
1010
{
1111
internal class SM_Component : MonoBehaviour
1212
{
1313
private bool isQuitting;
1414
private static bool hadError;
15+
private static bool useGeneratedAssembly = true;
16+
17+
private static MethodInfo SetAsLastSiblingMethod;
1518

1619
#if SM_Il2Cpp
1720
private delegate bool SetAsLastSiblingDelegate(IntPtr transformptr);
1821
private static SetAsLastSiblingDelegate SetAsLastSiblingDelegateField;
1922
public SM_Component(IntPtr value) : base(value) { }
20-
#else
21-
private static MethodInfo SetAsLastSiblingMethod;
2223
#endif
2324

2425
static SM_Component()
2526
{
2627
try
2728
{
2829
#if SM_Il2Cpp
30+
SetAsLastSiblingMethod = typeof(Transform).GetMethod("SetAsLastSibling", BindingFlags.Public | BindingFlags.Instance);
31+
if (SetAsLastSiblingMethod != null)
32+
return;
33+
34+
useGeneratedAssembly = false;
2935
SetAsLastSiblingDelegateField = IL2CPP.ResolveICall<SetAsLastSiblingDelegate>("UnityEngine.Transform::SetAsLastSibling");
3036
if (SetAsLastSiblingDelegateField == null)
3137
throw new Exception("Unable to find Internal Call for UnityEngine.Transform::SetAsLastSibling");
3238
#else
3339
SetAsLastSiblingMethod = typeof(Transform).GetMethod("SetAsLastSibling", BindingFlags.Public | BindingFlags.Instance);
3440
if (SetAsLastSiblingMethod == null)
35-
throw new Exception("Unable to find Internal Call for UnityEngine.Transform::SetAsLastSibling");
41+
throw new Exception("Unable to find UnityEngine.Transform::SetAsLastSibling");
3642
#endif
3743
}
38-
catch (Exception ex)
39-
{
40-
hadError = true;
41-
MelonLogger.Warning($"Exception while Getting Transform.SetAsLastSibling: {ex}");
42-
MelonLogger.Warning("Melon Events might run before some MonoBehaviour Events");
43-
}
44+
catch (Exception ex) { LogError("Getting UnityEngine.Transform::SetAsLastSibling", ex); }
4445
}
4546

4647
internal static void Create()
@@ -51,34 +52,55 @@ internal static void Create()
5152
Main.obj = new GameObject();
5253
DontDestroyOnLoad(Main.obj);
5354
Main.obj.hideFlags = HideFlags.DontSave;
55+
5456
#if SM_Il2Cpp
5557
Main.component = Main.obj.AddComponent(Il2CppType.Of<SM_Component>()).TryCast<SM_Component>();
5658
#else
5759
Main.component = (SM_Component)Main.obj.AddComponent(typeof(SM_Component));
5860
#endif
61+
5962
Main.component.SiblingFix();
6063
}
6164

65+
private static void LogError(string cat, Exception ex)
66+
{
67+
hadError = true;
68+
useGeneratedAssembly = false;
69+
MelonLogger.Warning($"Exception while {cat}: {ex}");
70+
MelonLogger.Warning("Melon Events might run before some MonoBehaviour Events");
71+
}
72+
6273
private void SiblingFix()
6374
{
6475
if (hadError)
6576
return;
6677

6778
try
6879
{
80+
if (useGeneratedAssembly)
81+
{
82+
gameObject.transform.SetAsLastSibling();
83+
transform.SetAsLastSibling();
84+
return;
85+
}
86+
6987
#if SM_Il2Cpp
7088
SetAsLastSiblingDelegateField(IL2CPP.Il2CppObjectBaseToPtrNotNull(gameObject.transform));
7189
SetAsLastSiblingDelegateField(IL2CPP.Il2CppObjectBaseToPtrNotNull(transform));
72-
#else
73-
SetAsLastSiblingMethod?.Invoke(gameObject.transform, new object[0]);
74-
SetAsLastSiblingMethod?.Invoke(transform, new object[0]);
7590
#endif
7691
}
7792
catch (Exception ex)
7893
{
79-
hadError = true;
80-
MelonLogger.Warning($"Exception while Invoking Transform.SetAsLastSibling: {ex}");
81-
MelonLogger.Warning("Melon Events might run before some MonoBehaviour Events");
94+
#if SM_Il2Cpp
95+
if (useGeneratedAssembly)
96+
{
97+
useGeneratedAssembly = false;
98+
SiblingFix();
99+
return;
100+
}
101+
#endif
102+
103+
LogError("Invoking UnityEngine.Transform::SetAsLastSibling", ex);
82104
}
83105
}
84106

Dependencies/SupportModules/Il2Cpp/Il2Cpp.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
<PackageReference Include="HarmonyX" Version="2.10.2" ExcludeAssets="Runtime" />
4242
<PackageReference Include="AssetRipper.VersionUtilities" Version="1.5.0" ExcludeAssets="Runtime" />
4343
<PackageReference Include="Iced" Version="1.21.0" ExcludeAssets="Runtime" />
44-
<PackageReference Include="ds5678.Il2CppInterop.Common" Version="1.5.4" ExcludeAssets="Runtime" />
45-
<PackageReference Include="ds5678.Il2CppInterop.Runtime" Version="1.5.4" ExcludeAssets="Runtime" />
46-
<PackageReference Include="ds5678.Il2CppInterop.HarmonySupport" Version="1.5.4" ExcludeAssets="Runtime" />
44+
<PackageReference Include="Il2CppInterop.Common" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
45+
<PackageReference Include="Il2CppInterop.Runtime" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
46+
<PackageReference Include="Il2CppInterop.HarmonySupport" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
4747
<PackageReference Include="Mono.Cecil" Version="0.11.5" ExcludeAssets="Runtime" />
4848
<PackageReference Include="MonoMod.RuntimeDetour" Version="22.7.31.1" ExcludeAssets="Runtime" />
4949
<PackageReference Include="MonoMod.Utils" Version="22.7.31.1" ExcludeAssets="Runtime" />

Dependencies/SupportModules/Il2Cpp/Main.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using Il2CppInterop.Common;
1414
using Il2CppInterop.Runtime.InteropTypes;
1515
using Microsoft.Extensions.Logging;
16+
using MelonLoader.Utils;
17+
using System.IO;
1618

1719
namespace MelonLoader.Support
1820
{
@@ -28,7 +30,17 @@ internal static class Main
2830

2931
private static ISupportModule_To Initialize(ISupportModule_From interface_from)
3032
{
31-
Interface = interface_from;
33+
Interface = interface_from;
34+
35+
foreach (var file in Directory.GetFiles(MelonEnvironment.Il2CppAssembliesDirectory, "*.dll"))
36+
{
37+
try
38+
{
39+
Assembly.LoadFrom(file);
40+
}
41+
catch { }
42+
}
43+
3244
UnityMappers.RegisterMappers();
3345

3446
Il2CppInteropRuntime runtime = Il2CppInteropRuntime.Create(new()

MelonLoader/Core.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ internal static int Initialize()
9494

9595
#if NET6_0_OR_GREATER
9696
Fixes.Il2CppInteropFixes.Install();
97+
Fixes.Il2CppICallInjector.Install();
9798
#endif
9899

99100
PatchShield.Install();
@@ -173,26 +174,29 @@ internal static void WelcomeMessage()
173174
var archString = MelonUtils.IsGame32Bit() ? "x86" : "x64";
174175
MelonLogger.MsgDirect($"Game Arch: {archString}");
175176
MelonLogger.MsgDirect("------------------------------");
176-
MelonLogger.MsgDirect($"CommandLine: {string.Join(" ", MelonLaunchOptions.CommandLineArgs)}");
177+
MelonLogger.MsgDirect($"Command-Line: {string.Join(" ", MelonLaunchOptions.CommandLineArgs)}");
177178
MelonLogger.MsgDirect("------------------------------");
178179

179-
180180
MelonEnvironment.PrintEnvironment();
181181
}
182182

183-
184183
internal static void Quit()
185184
{
186-
MelonDebug.Msg("[ML Core] Received Quit from Support Module. Shutting down...");
185+
MelonDebug.Msg("[ML Core] Received Quit Request! Shutting down...");
187186

188187
MelonPreferences.Save();
189188

190189
HarmonyInstance.UnpatchSelf();
191190
bHapticsManager.Disconnect();
192191

192+
#if NET6_0_OR_GREATER
193+
Fixes.Il2CppInteropFixes.Shutdown();
194+
Fixes.Il2CppICallInjector.Shutdown();
195+
#endif
196+
193197
MelonLogger.Flush();
194198
//MelonLogger.Close();
195-
199+
196200
Thread.Sleep(200);
197201

198202
if (MelonLaunchOptions.Core.QuitFix)

MelonLoader/Fixes/DotnetAssemblyLoadContextFix.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ internal static void Install()
4242

4343
public static bool PreAssemblyLoad(byte[] rawAssembly, byte[] rawSymbolStore, ref Assembly __result)
4444
{
45-
if(MelonDebug.IsEnabled() && !Environment.StackTrace.Contains("HarmonyLib"))
46-
MelonDebug.Msg($"[.NET AssemblyLoadContext Fix] Redirecting Assembly.Load call with {rawAssembly.Length}-byte assembly to AssemblyLoadContext.Default. Mod Devs: You may wish to use this explictly.");
45+
//if(MelonDebug.IsEnabled() && !Environment.StackTrace.Contains("HarmonyLib"))
46+
// MelonDebug.Msg($"[.NET AssemblyLoadContext Fix] Redirecting Assembly.Load call with {rawAssembly.Length}-byte assembly to AssemblyLoadContext.Default. Mod Devs: You may wish to use this explictly.");
4747

4848
var (ok, reason) = AssemblyVerifier.VerifyByteArray(rawAssembly);
4949
if (!ok)
@@ -59,7 +59,7 @@ public static bool PreAssemblyLoad(byte[] rawAssembly, byte[] rawSymbolStore, re
5959

6060
public static bool PreAssemblyLoadFile(string path, ref Assembly __result)
6161
{
62-
MelonDebug.Msg($"[.NET AssemblyLoadContext Fix] Redirecting Assembly.LoadFile({path}) call to AssemblyLoadContext.Default.LoadFromAssemblyPath. Mod Devs: You may wish to use this explictly.");
62+
//MelonDebug.Msg($"[.NET AssemblyLoadContext Fix] Redirecting Assembly.LoadFile({path}) call to AssemblyLoadContext.Default.LoadFromAssemblyPath. Mod Devs: You may wish to use this explictly.");
6363

6464
string normalizedPath = Path.GetFullPath(path);
6565

0 commit comments

Comments
 (0)