diff --git a/Cargo.lock b/Cargo.lock index e36d74bd5..c392e904e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -1558,8 +1558,8 @@ dependencies = [ [[package]] name = "proxygen-macros" -version = "0.5.0" -source = "git+https://github.com/RinLovesYou/proxygen#c549e4fad7cd50e1d3db252c97f2e1e94713d869" +version = "0.5.1" +source = "git+https://github.com/RinLovesYou/proxygen?rev=4fb48af618a815b49c4f72afce0d51b6d76f11f0#4fb48af618a815b49c4f72afce0d51b6d76f11f0" dependencies = [ "quote", "syn 2.0.39", diff --git a/MelonLoader/MelonLoader.Shared/Core.cs b/MelonLoader/MelonLoader.Shared/Core.cs index 168a3189b..95febb99d 100644 --- a/MelonLoader/MelonLoader.Shared/Core.cs +++ b/MelonLoader/MelonLoader.Shared/Core.cs @@ -28,12 +28,12 @@ public static void Startup(string engineModulePath) UnhandledException.Install(AppDomain.CurrentDomain); UnhandledAssemblyResolve.Install(); - if (!string.IsNullOrEmpty(engineModulePath)) - { - MelonDebug.Msg($"Engine Module Path: {engineModulePath}"); - IEngineModule module = ModuleManager.LoadModule(engineModulePath); - module.Initialize(); - } + if (string.IsNullOrEmpty(engineModulePath)) + return; + + MelonDebug.Msg($"Engine Module Path: {engineModulePath}"); + IEngineModule module = ModuleManager.LoadModule(engineModulePath); + module.Initialize(); WelcomeMessage(); diff --git a/MelonLoader/MelonLoader.Shared/Melons/MelonPlugin.cs b/MelonLoader/MelonLoader.Shared/Melons/MelonPlugin.cs index 9036b366b..c777458bf 100644 --- a/MelonLoader/MelonLoader.Shared/Melons/MelonPlugin.cs +++ b/MelonLoader/MelonLoader.Shared/Melons/MelonPlugin.cs @@ -7,6 +7,12 @@ public class MelonPlugin : IMelonBase, IMelonPlugin { public MelonLogger.Instance Logger { get; set; } + protected MelonPlugin() + { + MelonEvents.OnApplicationPreStart += OnApplicationPreStart; + MelonEvents.OnApplicationStart += OnApplicationStart; + } + public virtual void OnApplicationPreStart() { } public virtual void OnApplicationStart() { } } \ No newline at end of file diff --git a/MelonLoader/MelonLoader.Shared/NativeUtils/MelonNativeLibrary.cs b/MelonLoader/MelonLoader.Shared/NativeUtils/MelonNativeLibrary.cs index 52a949d27..bce854832 100644 --- a/MelonLoader/MelonLoader.Shared/NativeUtils/MelonNativeLibrary.cs +++ b/MelonLoader/MelonLoader.Shared/NativeUtils/MelonNativeLibrary.cs @@ -53,8 +53,8 @@ public static IntPtr GetExport(IntPtr handle, string name) throw new ArgumentNullException(nameof(handle)); // Check if being passed valid Export Name - if (string.IsNullOrEmpty(name)) - throw new ArgumentNullException(nameof(name)); + if (handle == IntPtr.Zero) + throw new ArgumentNullException(nameof(handle)); // Get the Export Pointer IntPtr returnval = BootstrapInterop.NativeGetExport(handle, name); @@ -65,6 +65,34 @@ public static IntPtr GetExport(IntPtr handle, string name) return returnval; } + public static bool TryGetExport(IntPtr handle, string name, out T result) where T : Delegate + { + bool wasSuccessful = false; + try + { + result = GetExport(handle, name); + wasSuccessful = true; //GetDelegate will throw instead of returning null. + } + catch { result = null; } + return wasSuccessful; + } + + public static T GetExport(IntPtr handle, string name) where T : Delegate + { + if (handle == IntPtr.Zero) + throw new ArgumentNullException(nameof(handle)); + + if (handle == IntPtr.Zero) + throw new ArgumentNullException(nameof(handle)); + + IntPtr export = GetExport(handle, name); + + if (export == IntPtr.Zero) + throw new Exception($"Unable to Find Native Library Export {name}!"); + + return export.GetDelegate(); + } + public static T ReflectiveLoad(string name) { // Attempt to load Native Library diff --git a/MelonLoader/MelonLoader.Shared/Utils/OsUtils.cs b/MelonLoader/MelonLoader.Shared/Utils/OsUtils.cs index f4137e5ab..8a3b49c37 100644 --- a/MelonLoader/MelonLoader.Shared/Utils/OsUtils.cs +++ b/MelonLoader/MelonLoader.Shared/Utils/OsUtils.cs @@ -33,24 +33,14 @@ static OsUtils() { if (!MelonUtils.IsWindows) return; - + IntPtr ntdll = MelonNativeLibrary.Load("ntdll.dll"); - if (ntdll == IntPtr.Zero) - return; - - MelonNativeLibrary.TryGetExport(ntdll, "RtlGetVersion", out IntPtr rtlGetVersionProc); - if (rtlGetVersionProc != IntPtr.Zero) - RtlGetVersion = (dRtlGetVersion)Marshal.GetDelegateForFunctionPointer( - rtlGetVersionProc, - typeof(dRtlGetVersion) - ); - - MelonNativeLibrary.TryGetExport(ntdll, "wine_get_version", out IntPtr wineGetVersionProc); - if (wineGetVersionProc != IntPtr.Zero) - WineGetVersion = (dWineGetVersion)Marshal.GetDelegateForFunctionPointer( - wineGetVersionProc, - typeof(dWineGetVersion) - ); + + if (MelonNativeLibrary.TryGetExport(ntdll, "RtlGetVersion", out var rtlGetVersion)) + RtlGetVersion = rtlGetVersion; + + if (MelonNativeLibrary.TryGetExport(ntdll, "wine_get_version", out var wineGetVersion)) + WineGetVersion = wineGetVersion; } internal static bool IsWineOrProton() diff --git a/MelonLoader/Modules/Godot/Godot.Shared/Utils/GodotEnvironment.cs b/MelonLoader/Modules/Godot/Godot.Shared/Utils/GodotEnvironment.cs index f3a2425dc..b82d67e24 100644 --- a/MelonLoader/Modules/Godot/Godot.Shared/Utils/GodotEnvironment.cs +++ b/MelonLoader/Modules/Godot/Godot.Shared/Utils/GodotEnvironment.cs @@ -86,8 +86,19 @@ private static void ReadGameInfo(string pckPath) GameName = Path.GetFileNameWithoutExtension(_pckReader.PackPath); EngineVersion = new GodotVersion(_pckReader.PCK_VersionMajor, _pckReader.PCK_VersionMinor, _pckReader.PCK_VersionRevision); #endif + + string platformSuffix = "windows"; + if (MelonUtils.IsUnix) + platformSuffix = "linuxbsd"; + + //macos structure is weird, TODO. GameDataPath = $"data_{MelonEnvironment.GameExecutableName}_{(MelonUtils.Is32Bit ? "x86" : "x86_64")}"; + + //newer godot version add a platform suffix + if (!Directory.Exists(GameDataPath)) + GameDataPath = GameDataPath.Replace(MelonUtils.Is32Bit ? "x86" : "x86_64", + $"{platformSuffix}_{(MelonUtils.Is32Bit ? "x86" : "x86_64")}"); if (!MelonUtils.IsWindows) return; diff --git a/Rust/MelonProxy/Cargo.toml b/Rust/MelonProxy/Cargo.toml index 9674f9028..50c8d9caa 100644 --- a/Rust/MelonProxy/Cargo.toml +++ b/Rust/MelonProxy/Cargo.toml @@ -11,7 +11,7 @@ libloading = "0.8.1" [target.'cfg(target_os = "windows")'.dependencies] #proxygen-macros = "0.5.0" -proxygen-macros = { git = "https://github.com/RinLovesYou/proxygen" } # temporary until update is published +proxygen-macros = { git = "https://github.com/RinLovesYou/proxygen", rev="4fb48af618a815b49c4f72afce0d51b6d76f11f0" } # temporary until update is published winapi = { version = "0.3.9", features = [ "minwindef", "libloaderapi",