Skip to content

Commit

Permalink
Merge pull request #746 from LavaGang/alpha-development
Browse files Browse the repository at this point in the history
MelonLoader v0.6.5 (P2)
  • Loading branch information
HerpDerpinstine authored Sep 24, 2024
2 parents bed7261 + 957b424 commit 4242569
Show file tree
Hide file tree
Showing 15 changed files with 823 additions and 79 deletions.
36 changes: 20 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@

### v0.6.5

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

---

Expand Down
4 changes: 2 additions & 2 deletions Dependencies/Il2CppAssemblyGenerator/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static int Run()
RemoteAPI.Contact();

cpp2il = new Cpp2IL();
cpp2il_scrs = new Cpp2IL_StrippedCodeRegSupport(cpp2il);
//cpp2il_scrs = new Cpp2IL_StrippedCodeRegSupport(cpp2il);

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

if (!cpp2il.Setup()
|| !cpp2il_scrs.Setup()
//|| !cpp2il_scrs.Setup()
|| !il2cppinterop.Setup()
|| !unitydependencies.Setup()
|| !deobfuscationMap.Setup())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<ItemGroup>
<ProjectReference Include="..\..\MelonLoader\MelonLoader.csproj" Private="false" />
<PackageReference Include="Iced" Version="1.21.0" ExcludeAssets="Runtime" />
<PackageReference Include="ds5678.Il2CppInterop.Generator" Version="1.5.4" ExcludeAssets="Runtime" />
<PackageReference Include="ds5678.Il2CppInterop.Common" Version="1.5.4" ExcludeAssets="Runtime" />
<PackageReference Include="ds5678.Il2CppInterop.Runtime" Version="1.5.4" ExcludeAssets="Runtime" />
<PackageReference Include="Il2CppInterop.Generator" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
<PackageReference Include="Il2CppInterop.Common" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
<PackageReference Include="Il2CppInterop.Runtime" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" ExcludeAssets="Runtime" />
<PackageReference Include="AssetRipper.VersionUtilities" Version="1.5.0" ExcludeAssets="Runtime" />
</ItemGroup>
Expand Down
58 changes: 40 additions & 18 deletions Dependencies/SupportModules/Component.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
using System;
using System.Reflection;
using UnityEngine;

#if SM_Il2Cpp
using Il2CppInterop.Runtime;
#else
using System.Reflection;
#endif
using UnityEngine;

namespace MelonLoader.Support
{
internal class SM_Component : MonoBehaviour
{
private bool isQuitting;
private static bool hadError;
private static bool useGeneratedAssembly = true;

private static MethodInfo SetAsLastSiblingMethod;

#if SM_Il2Cpp
private delegate bool SetAsLastSiblingDelegate(IntPtr transformptr);
private static SetAsLastSiblingDelegate SetAsLastSiblingDelegateField;
public SM_Component(IntPtr value) : base(value) { }
#else
private static MethodInfo SetAsLastSiblingMethod;
#endif

static SM_Component()
{
try
{
#if SM_Il2Cpp
SetAsLastSiblingMethod = typeof(Transform).GetMethod("SetAsLastSibling", BindingFlags.Public | BindingFlags.Instance);
if (SetAsLastSiblingMethod != null)
return;

useGeneratedAssembly = false;
SetAsLastSiblingDelegateField = IL2CPP.ResolveICall<SetAsLastSiblingDelegate>("UnityEngine.Transform::SetAsLastSibling");
if (SetAsLastSiblingDelegateField == null)
throw new Exception("Unable to find Internal Call for UnityEngine.Transform::SetAsLastSibling");
#else
SetAsLastSiblingMethod = typeof(Transform).GetMethod("SetAsLastSibling", BindingFlags.Public | BindingFlags.Instance);
if (SetAsLastSiblingMethod == null)
throw new Exception("Unable to find Internal Call for UnityEngine.Transform::SetAsLastSibling");
throw new Exception("Unable to find UnityEngine.Transform::SetAsLastSibling");
#endif
}
catch (Exception ex)
{
hadError = true;
MelonLogger.Warning($"Exception while Getting Transform.SetAsLastSibling: {ex}");
MelonLogger.Warning("Melon Events might run before some MonoBehaviour Events");
}
catch (Exception ex) { LogError("Getting UnityEngine.Transform::SetAsLastSibling", ex); }
}

internal static void Create()
Expand All @@ -51,34 +52,55 @@ internal static void Create()
Main.obj = new GameObject();
DontDestroyOnLoad(Main.obj);
Main.obj.hideFlags = HideFlags.DontSave;

#if SM_Il2Cpp
Main.component = Main.obj.AddComponent(Il2CppType.Of<SM_Component>()).TryCast<SM_Component>();
#else
Main.component = (SM_Component)Main.obj.AddComponent(typeof(SM_Component));
#endif

Main.component.SiblingFix();
}

private static void LogError(string cat, Exception ex)
{
hadError = true;
useGeneratedAssembly = false;
MelonLogger.Warning($"Exception while {cat}: {ex}");
MelonLogger.Warning("Melon Events might run before some MonoBehaviour Events");
}

private void SiblingFix()
{
if (hadError)
return;

try
{
if (useGeneratedAssembly)
{
gameObject.transform.SetAsLastSibling();
transform.SetAsLastSibling();
return;
}

#if SM_Il2Cpp
SetAsLastSiblingDelegateField(IL2CPP.Il2CppObjectBaseToPtrNotNull(gameObject.transform));
SetAsLastSiblingDelegateField(IL2CPP.Il2CppObjectBaseToPtrNotNull(transform));
#else
SetAsLastSiblingMethod?.Invoke(gameObject.transform, new object[0]);
SetAsLastSiblingMethod?.Invoke(transform, new object[0]);
#endif
}
catch (Exception ex)
{
hadError = true;
MelonLogger.Warning($"Exception while Invoking Transform.SetAsLastSibling: {ex}");
MelonLogger.Warning("Melon Events might run before some MonoBehaviour Events");
#if SM_Il2Cpp
if (useGeneratedAssembly)
{
useGeneratedAssembly = false;
SiblingFix();
return;
}
#endif

LogError("Invoking UnityEngine.Transform::SetAsLastSibling", ex);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Dependencies/SupportModules/Il2Cpp/Il2Cpp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
<PackageReference Include="HarmonyX" Version="2.10.2" ExcludeAssets="Runtime" />
<PackageReference Include="AssetRipper.VersionUtilities" Version="1.5.0" ExcludeAssets="Runtime" />
<PackageReference Include="Iced" Version="1.21.0" ExcludeAssets="Runtime" />
<PackageReference Include="ds5678.Il2CppInterop.Common" Version="1.5.4" ExcludeAssets="Runtime" />
<PackageReference Include="ds5678.Il2CppInterop.Runtime" Version="1.5.4" ExcludeAssets="Runtime" />
<PackageReference Include="ds5678.Il2CppInterop.HarmonySupport" Version="1.5.4" ExcludeAssets="Runtime" />
<PackageReference Include="Il2CppInterop.Common" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
<PackageReference Include="Il2CppInterop.Runtime" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
<PackageReference Include="Il2CppInterop.HarmonySupport" Version="1.4.6-ci.545" ExcludeAssets="Runtime" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" ExcludeAssets="Runtime" />
<PackageReference Include="MonoMod.RuntimeDetour" Version="22.7.31.1" ExcludeAssets="Runtime" />
<PackageReference Include="MonoMod.Utils" Version="22.7.31.1" ExcludeAssets="Runtime" />
Expand Down
14 changes: 13 additions & 1 deletion Dependencies/SupportModules/Il2Cpp/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Il2CppInterop.Common;
using Il2CppInterop.Runtime.InteropTypes;
using Microsoft.Extensions.Logging;
using MelonLoader.Utils;
using System.IO;

namespace MelonLoader.Support
{
Expand All @@ -28,7 +30,17 @@ internal static class Main

private static ISupportModule_To Initialize(ISupportModule_From interface_from)
{
Interface = interface_from;
Interface = interface_from;

foreach (var file in Directory.GetFiles(MelonEnvironment.Il2CppAssembliesDirectory, "*.dll"))
{
try
{
Assembly.LoadFrom(file);
}
catch { }
}

UnityMappers.RegisterMappers();

Il2CppInteropRuntime runtime = Il2CppInteropRuntime.Create(new()
Expand Down
14 changes: 9 additions & 5 deletions MelonLoader/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ internal static int Initialize()

#if NET6_0_OR_GREATER
Fixes.Il2CppInteropFixes.Install();
Fixes.Il2CppICallInjector.Install();
#endif

PatchShield.Install();
Expand Down Expand Up @@ -173,26 +174,29 @@ internal static void WelcomeMessage()
var archString = MelonUtils.IsGame32Bit() ? "x86" : "x64";
MelonLogger.MsgDirect($"Game Arch: {archString}");
MelonLogger.MsgDirect("------------------------------");
MelonLogger.MsgDirect($"CommandLine: {string.Join(" ", MelonLaunchOptions.CommandLineArgs)}");
MelonLogger.MsgDirect($"Command-Line: {string.Join(" ", MelonLaunchOptions.CommandLineArgs)}");
MelonLogger.MsgDirect("------------------------------");


MelonEnvironment.PrintEnvironment();
}


internal static void Quit()
{
MelonDebug.Msg("[ML Core] Received Quit from Support Module. Shutting down...");
MelonDebug.Msg("[ML Core] Received Quit Request! Shutting down...");

MelonPreferences.Save();

HarmonyInstance.UnpatchSelf();
bHapticsManager.Disconnect();

#if NET6_0_OR_GREATER
Fixes.Il2CppInteropFixes.Shutdown();
Fixes.Il2CppICallInjector.Shutdown();
#endif

MelonLogger.Flush();
//MelonLogger.Close();

Thread.Sleep(200);

if (MelonLaunchOptions.Core.QuitFix)
Expand Down
6 changes: 3 additions & 3 deletions MelonLoader/Fixes/DotnetAssemblyLoadContextFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ internal static void Install()

public static bool PreAssemblyLoad(byte[] rawAssembly, byte[] rawSymbolStore, ref Assembly __result)
{
if(MelonDebug.IsEnabled() && !Environment.StackTrace.Contains("HarmonyLib"))
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.");
//if(MelonDebug.IsEnabled() && !Environment.StackTrace.Contains("HarmonyLib"))
// 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.");

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

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

string normalizedPath = Path.GetFullPath(path);

Expand Down
Loading

0 comments on commit 4242569

Please sign in to comment.