Skip to content

Commit

Permalink
Attempt to fix EOS module
Browse files Browse the repository at this point in the history
  • Loading branch information
HerpDerpinstine committed Aug 20, 2024
1 parent 4dd884b commit ce711e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 54 deletions.
50 changes: 16 additions & 34 deletions Dependencies/CompatibilityLayers/EOS/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,35 @@ internal class EOS_Module : MelonModule
private delegate IntPtr LoadLibraryDetour(IntPtr path);
private NativeHook<LoadLibraryDetour> _hookWin;

//private delegate IntPtr dlopenDetour(IntPtr path, int flags);
//private NativeHook<dlopenDetour> _hookUnix;

public override void OnInitialize()
{
IntPtr ldlib = NativeLibrary.AgnosticGetLoadLibraryPtr();
if (ldlib == IntPtr.Zero)
return;

var platform = Environment.OSVersion.Platform;
switch (platform)
{
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.Win32NT:
case PlatformID.WinCE:
_hookWin = new NativeHook<LoadLibraryDetour>(ldlib,
Marshal.GetFunctionPointerForDelegate(DetourWin));
_hookWin.Attach();
NativeLibrary lib = NativeLibrary.Load("kernel32");
if (lib != null)
{
IntPtr loadLibraryWPtr = lib.GetExport("LoadLibraryW");
if (loadLibraryWPtr != IntPtr.Zero)
{
_hookWin = new NativeHook<LoadLibraryDetour>(loadLibraryWPtr,
Marshal.GetFunctionPointerForDelegate(DetourWin));
_hookWin.Attach();
}
}
break;

case PlatformID.Unix:
case PlatformID.MacOSX:

// TO-DO

//_hookUnix = new NativeHook<dlopenDetour>(ldlib,
// Marshal.GetFunctionPointerForDelegate(DetourUnix));
//_hookUnix.Attach();
// libdl.so.2
// dlopen

break;
}
Expand All @@ -61,7 +62,8 @@ private IntPtr DetourWin(IntPtr path)
return _hookWin.Trampoline(path);

var pathString = Marshal.PtrToStringUni(path);
if (pathString.EndsWith("EOSOVH-Win64-Shipping.dll") || pathString.EndsWith("EOSOVH-Win32-Shipping.dll"))
if (pathString.EndsWith("EOSOVH-Win64-Shipping.dll")
|| pathString.EndsWith("EOSOVH-Win32-Shipping.dll"))
{
_hookWin.Detach();
return IntPtr.Zero;
Expand All @@ -70,30 +72,10 @@ private IntPtr DetourWin(IntPtr path)
return _hookWin.Trampoline(path);
}

/*
private IntPtr DetourUnix(IntPtr path, int flags)
{
if (path == IntPtr.Zero)
return _hookUnix.Trampoline(path, flags);
var pathString = Marshal.PtrToStringUni(path);
if (pathString.StartsWith("EOSOVH-"))
{
_hookUnix.Detach();
return IntPtr.Zero;
}
return _hookUnix.Trampoline(path, flags);
}
*/

~EOS_Module()
{
_hookWin?.Detach();
_hookWin = null;

//_hookUnix?.Detach();
//_hookUnix = null;
}
}
}
20 changes: 0 additions & 20 deletions MelonLoader/Utils/NativeLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,6 @@ public static IntPtr AgnosticGetProcAddress(IntPtr hModule, string lpProcName)
throw new PlatformNotSupportedException($"Unsupported platform: {platform}");
}

public static IntPtr AgnosticGetLoadLibraryPtr()
{
var platform = Environment.OSVersion.Platform;

switch (platform)
{
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.Win32NT:
case PlatformID.WinCE:
return Marshal.GetFunctionPointerForDelegate(LoadLibrary);

case PlatformID.Unix:
case PlatformID.MacOSX:
return Marshal.GetFunctionPointerForDelegate(dlopen);
}

throw new PlatformNotSupportedException($"Unsupported platform: {platform}");
}

[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string lpLibFileName);
[DllImport("kernel32")]
Expand Down

0 comments on commit ce711e7

Please sign in to comment.