Skip to content

Commit

Permalink
some fixes for Godot 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RinLovesYou committed Oct 8, 2024
1 parent c63d40f commit dcd49d5
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions MelonLoader/MelonLoader.Shared/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 6 additions & 0 deletions MelonLoader/MelonLoader.Shared/Melons/MelonPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
}
32 changes: 30 additions & 2 deletions MelonLoader/MelonLoader.Shared/NativeUtils/MelonNativeLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -65,6 +65,34 @@ public static IntPtr GetExport(IntPtr handle, string name)
return returnval;
}

public static bool TryGetExport<T>(IntPtr handle, string name, out T result) where T : Delegate
{
bool wasSuccessful = false;
try
{
result = GetExport<T>(handle, name);
wasSuccessful = true; //GetDelegate will throw instead of returning null.
}
catch { result = null; }
return wasSuccessful;
}

public static T GetExport<T>(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<T>();
}

public static T ReflectiveLoad<T>(string name)
{
// Attempt to load Native Library
Expand Down
24 changes: 7 additions & 17 deletions MelonLoader/MelonLoader.Shared/Utils/OsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dRtlGetVersion>(ntdll, "RtlGetVersion", out var rtlGetVersion))
RtlGetVersion = rtlGetVersion;

if (MelonNativeLibrary.TryGetExport<dWineGetVersion>(ntdll, "wine_get_version", out var wineGetVersion))
WineGetVersion = wineGetVersion;
}

internal static bool IsWineOrProton()
Expand Down
11 changes: 11 additions & 0 deletions MelonLoader/Modules/Godot/Godot.Shared/Utils/GodotEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Rust/MelonProxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dcd49d5

Please sign in to comment.