diff --git a/Dependencies/Modules/Engines/Unity/Engine.Unity/UnityLoader.cs b/Dependencies/Modules/Engines/Unity/Engine.Unity/UnityLoader.cs index 2e864e44..4452e377 100644 --- a/Dependencies/Modules/Engines/Unity/Engine.Unity/UnityLoader.cs +++ b/Dependencies/Modules/Engines/Unity/Engine.Unity/UnityLoader.cs @@ -32,10 +32,14 @@ public override bool Validate() return false; } - public override void Stage2() + public override void Stage3(string supportModulePath) { if (!IsIl2Cpp) + { + // Run Stage3 + base.Stage3(supportModulePath); return; + } string genBasePath = Path.Combine(LoaderPath, "Il2CppAssemblyGenerator"); if (!Directory.Exists(genBasePath)) @@ -50,9 +54,6 @@ public override void Stage2() Il2CppInteropFixes.Install(genOutputPath); Il2CppICallInjector.Install(); - // Run Stage2 - base.Stage2(); - // Generate Il2Cpp Wrapper Assemblies try { @@ -77,8 +78,8 @@ public override void Stage2() return; } - // Il2Cpp Games just run Stage3 after Assembly Generation - Stage3(SupportModulePath); + // Run Stage3 after Assembly Generation + base.Stage3(supportModulePath); } public override void Initialize() @@ -104,11 +105,15 @@ public override void Initialize() SetEngineInfo("Unity", UnityInformationHandler.EngineVersion.ToStringWithoutType(), indentifier); SetApplicationInfo(UnityInformationHandler.GameDeveloper, UnityInformationHandler.GameName, UnityInformationHandler.GameVersion); + PrintAppInfo(); if (IsIl2Cpp) { + // Run Stage2 + Stage2(); + // Initialize Il2Cpp Loader - Il2CppLoader.Initialize(this, new(GameAssemblyPath, + Il2CppLoader.Initialize(this, new(GameAssemblyPath, SupportModulePath, [ "Internal_ActiveSceneChanged", "UnityEngine.ISerializationCallbackReceiver.OnAfterSerialize" diff --git a/Dependencies/Modules/Runtimes/Il2Cpp/Runtime.Il2Cpp/Il2CppLoader.cs b/Dependencies/Modules/Runtimes/Il2Cpp/Runtime.Il2Cpp/Il2CppLoader.cs index d5e79892..546acec0 100644 --- a/Dependencies/Modules/Runtimes/Il2Cpp/Runtime.Il2Cpp/Il2CppLoader.cs +++ b/Dependencies/Modules/Runtimes/Il2Cpp/Runtime.Il2Cpp/Il2CppLoader.cs @@ -109,8 +109,8 @@ private static IntPtr h_il2cpp_runtime_invoke(IntPtr method, IntPtr obj, void** // Detach il2cpp_runtime_invoke Detour il2cpp_runtime_invoke_detour.Detach(); - // Initiate Stage2 - EngineModule.Stage2(); + // Initiate Stage3 + EngineModule.Stage3(RuntimeInfo.SupportModulePath); // Return original Invoke without Trampoline return _lib.il2cpp_runtime_invoke(method, obj, param, ref exc); diff --git a/Dependencies/Modules/Runtimes/Il2Cpp/Runtime.Il2Cpp/Il2CppRuntimeInfo.cs b/Dependencies/Modules/Runtimes/Il2Cpp/Runtime.Il2Cpp/Il2CppRuntimeInfo.cs index 74db87f5..5b0ec611 100644 --- a/Dependencies/Modules/Runtimes/Il2Cpp/Runtime.Il2Cpp/Il2CppRuntimeInfo.cs +++ b/Dependencies/Modules/Runtimes/Il2Cpp/Runtime.Il2Cpp/Il2CppRuntimeInfo.cs @@ -14,9 +14,11 @@ public class Il2CppRuntimeInfo : MelonRuntimeInfo public Il2CppRuntimeInfo( string libPath, + string supportModulePath, string[] triggerMethods) { LibPath = libPath; + SupportModulePath = supportModulePath; TriggerMethods = triggerMethods; } diff --git a/MelonLoader/Core.cs b/MelonLoader/Core.cs index ae59b5ef..87f918ce 100644 --- a/MelonLoader/Core.cs +++ b/MelonLoader/Core.cs @@ -20,7 +20,7 @@ internal static class Core internal static HarmonyLib.Harmony HarmonyInstance; // Runtime Initialization - internal static void Stage1() + internal static void Stage1(bool isNativeHost) { ServicePointManager.DefaultConnectionLimit = int.MaxValue; @@ -34,17 +34,16 @@ internal static void Stage1() MelonLaunchOptions.Load(); -#if NET35 - - // Disabled for now because of issues - //Net20Compatibility.TryInstall(); - -#elif NET6_0_OR_GREATER - - if (LoaderConfig.Current.Loader.LaunchDebugger && MelonEnvironment.IsDotnetRuntime) +#if NET6_0_OR_GREATER + if (isNativeHost) { - MelonLogger.Msg("[Init] User requested debugger, attempting to launch now..."); - Debugger.Launch(); + MelonEnvironment.PrintBuild(); + + if (LoaderConfig.Current.Loader.LaunchDebugger && MelonEnvironment.IsDotnetRuntime) + { + MelonLogger.Msg("[Init] User requested debugger, attempting to launch now..."); + Debugger.Launch(); + } } // if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -52,7 +51,7 @@ internal static void Stage1() #endif - if (OsUtils.IsWineOrProton()) + if (isNativeHost && OsUtils.IsWineOrProton()) Pastel.ConsoleExtensions.Disable(); Fixes.UnhandledException.Install(AppDomain.CurrentDomain); @@ -63,17 +62,24 @@ internal static void Stage1() HarmonyInstance = new HarmonyLib.Harmony(BuildInfo.Name); - Fixes.DetourContextDisposeFix.Install(); - Fixes.ForcedCultureInfo.Install(); - Fixes.InstancePatchFix.Install(); - Fixes.ProcessFix.Install(); +#if NET35 + + // Disabled for now because of issues + Fixes.Net20Compatibility.TryInstall(); + +#elif NET6_0_OR_GREATER -#if NET6_0_OR_GREATER Fixes.AsmResolverFix.Install(); Fixes.DotnetAssemblyLoadContextFix.Install(); Fixes.DotnetModHandlerRedirectionFix.Install(); + #endif + Fixes.DetourContextDisposeFix.Install(); + Fixes.ForcedCultureInfo.Install(); + Fixes.InstancePatchFix.Install(); + Fixes.ProcessFix.Install(); + PatchShield.Install(); MelonPreferences.Load(); } @@ -81,8 +87,6 @@ internal static void Stage1() // After Engine Module Initializes internal static void Stage2() { - MelonEnvironment.WelcomeMessage(); - ModuleFolderHandler.ScanForFolders(); ModuleFolderHandler.LoadMelons(ModuleFolderHandler.eScanType.UserLibs); ModuleFolderHandler.LoadMelons(ModuleFolderHandler.eScanType.Plugins); diff --git a/MelonLoader/InternalUtils/BootstrapInterop.cs b/MelonLoader/InternalUtils/BootstrapInterop.cs index 621e30ce..c5bf3e20 100644 --- a/MelonLoader/InternalUtils/BootstrapInterop.cs +++ b/MelonLoader/InternalUtils/BootstrapInterop.cs @@ -75,7 +75,7 @@ internal static void Stage1(nint bootstrapHandle) try { - Core.Stage1(); + Core.Stage1(true); } catch (Exception ex) { diff --git a/MelonLoader/Modules/MelonEngineModule.cs b/MelonLoader/Modules/MelonEngineModule.cs index dce5d98b..b8c9e88a 100644 --- a/MelonLoader/Modules/MelonEngineModule.cs +++ b/MelonLoader/Modules/MelonEngineModule.cs @@ -10,36 +10,13 @@ public abstract class MelonEngineModule : MelonModule public void SetEngineInfo(string name, string version, string variant = null) => MelonEnvironment.SetEngineInfo(name, version, variant); - public void SetApplicationInfo(string developer, string name, string version) => MelonEnvironment.SetApplicationInfo(developer, name, version); - + public void PrintAppInfo() + => MelonEnvironment.PrintAppInfo(); public virtual void Stage2() - { - try - { - Core.Stage2(); - } - catch (Exception ex) - { - MelonLogger.Error("Failed to run Stage2 of MelonLoader"); - MelonLogger.Error(ex); - throw new("Error at Stage2"); - } - } - + => ModuleInterop.Stage2(); public virtual void Stage3(string supportModulePath) - { - try - { - Core.Stage3(supportModulePath); - } - catch (Exception ex) - { - MelonLogger.Error("Failed to run Stage3 of MelonLoader"); - MelonLogger.Error(ex); - throw new("Error at Stage3"); - } - } + => ModuleInterop.Stage3(supportModulePath); } } diff --git a/MelonLoader/Modules/ModuleInterop.cs b/MelonLoader/Modules/ModuleInterop.cs index 42eeff5e..2159d915 100644 --- a/MelonLoader/Modules/ModuleInterop.cs +++ b/MelonLoader/Modules/ModuleInterop.cs @@ -1,4 +1,7 @@ -namespace MelonLoader.Modules +using MelonLoader.Utils; +using System; + +namespace MelonLoader.Modules { internal static class ModuleInterop { @@ -11,8 +14,9 @@ internal static void StartEngine() if (Engine == null) { MelonLogger.Warning("No Engine Module Found! Using Fallback Environment..."); - Core.Stage2(); - Core.Stage3(null); + MelonEnvironment.PrintAppInfo(); + Stage2(); + Stage3(null); return; } @@ -29,5 +33,33 @@ internal static void StartSupport(string path) MelonLogger.Msg($"Support Module Found: {path}"); Support.Initialize(); } + + public static void Stage2() + { + try + { + Core.Stage2(); + } + catch (Exception ex) + { + MelonLogger.Error("Failed to run Stage2 of MelonLoader"); + MelonLogger.Error(ex); + throw new("Error at Stage2"); + } + } + + public static void Stage3(string supportModulePath) + { + try + { + Core.Stage3(supportModulePath); + } + catch (Exception ex) + { + MelonLogger.Error("Failed to run Stage3 of MelonLoader"); + MelonLogger.Error(ex); + throw new("Error at Stage3"); + } + } } } diff --git a/MelonLoader/Utils/MelonEnvironment.cs b/MelonLoader/Utils/MelonEnvironment.cs index 09756fb0..a24aaf9d 100644 --- a/MelonLoader/Utils/MelonEnvironment.cs +++ b/MelonLoader/Utils/MelonEnvironment.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System; using MelonLoader.Properties; +using System.Drawing; namespace MelonLoader.Utils { @@ -133,35 +134,42 @@ internal static void Initialize(AppDomain domain) SetApplicationInfo(ApplicationExecutableName, ApplicationExecutableName, "0.0.0"); } - internal static void WelcomeMessage() + internal static void PrintBuild() { - MelonUtils.SetConsoleTitle($"{GetVersionString()} - {CurrentApplicationInfo.Name} {CurrentApplicationInfo.Version ?? ""}"); - MelonLogger.WriteSpacer(); - MelonLogger.MsgDirect("------------------------------"); + MelonLogger.MsgDirect(Color.Pink, "------------------------------"); MelonLogger.MsgDirect(GetVersionString()); - MelonLogger.MsgDirect("------------------------------"); + MelonLogger.MsgDirect(Color.Pink, "------------------------------"); MelonLogger.MsgDirect($"OS: {OsUtils.GetOSVersion()}"); MelonLogger.MsgDirect($"Arch: {(OsUtils.Is32Bit ? "x86" : "x64")}"); - MelonLogger.MsgDirect($"Runtime: {OurRuntimeName}"); MelonLogger.MsgDirect($"Hash Code: {HashCode}"); - MelonLogger.MsgDirect("------------------------------"); - MelonLogger.MsgDirect($"Engine: {CurrentEngineInfo.Name} {CurrentEngineInfo.Version}"); - MelonLogger.MsgDirect($"Engine Version: {CurrentEngineInfo.Version}"); - if (!string.IsNullOrEmpty(CurrentEngineInfo.Variant)) - MelonLogger.MsgDirect($"Engine Variant: {CurrentEngineInfo.Variant}"); - MelonLogger.MsgDirect("------------------------------"); - MelonLogger.MsgDirect($"Application Name: {CurrentApplicationInfo.Name}"); - MelonLogger.MsgDirect($"Application Developer: {CurrentApplicationInfo.Name}"); - MelonLogger.MsgDirect($"Application Version: {CurrentApplicationInfo.Version}"); - MelonLogger.MsgDirect("------------------------------"); + MelonLogger.MsgDirect(Color.Pink, "------------------------------"); MelonLogger.MsgDirect("Command-Line: "); foreach (var pair in MelonLaunchOptions.InternalArguments) if (string.IsNullOrEmpty(pair.Value)) MelonLogger.MsgDirect($" {pair.Key}"); else MelonLogger.MsgDirect($" {pair.Key} = {pair.Value}"); - MelonLogger.MsgDirect("------------------------------"); + MelonLogger.MsgDirect(Color.Pink, "------------------------------"); + MelonLogger.WriteSpacer(); + } + + internal static void PrintAppInfo() + { + MelonUtils.SetConsoleTitle($"{GetVersionString()} - {CurrentApplicationInfo.Name} {CurrentApplicationInfo.Version ?? ""}"); + MelonLogger.WriteSpacer(); + MelonLogger.MsgDirect(Color.Pink, "------------------------------"); + MelonLogger.MsgDirect($"Runtime: {OurRuntimeName}"); + MelonLogger.MsgDirect(Color.Pink, "------------------------------"); + MelonLogger.MsgDirect($"Engine: {CurrentEngineInfo.Name}"); + MelonLogger.MsgDirect($"Engine Version: {CurrentEngineInfo.Version}"); + if (!string.IsNullOrEmpty(CurrentEngineInfo.Variant)) + MelonLogger.MsgDirect($"Engine Variant: {CurrentEngineInfo.Variant}"); + MelonLogger.MsgDirect(Color.Pink, "------------------------------"); + MelonLogger.MsgDirect($"Application Name: {CurrentApplicationInfo.Name}"); + MelonLogger.MsgDirect($"Application Developer: {CurrentApplicationInfo.Name}"); + MelonLogger.MsgDirect($"Application Version: {CurrentApplicationInfo.Version}"); + MelonLogger.MsgDirect(Color.Pink, "------------------------------"); } } } \ No newline at end of file