-
Notifications
You must be signed in to change notification settings - Fork 5
/
AstralBypass.cs
40 lines (34 loc) · 1.59 KB
/
AstralBypass.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using MelonLoader;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
[assembly: MelonInfo(typeof(Astrum.AstralBypass), nameof(Astrum.AstralBypass), "0.2.1", downloadLink: "github.com/Astrum-Project/" + nameof(Astrum.AstralBypass))]
[assembly: MelonColor(ConsoleColor.DarkMagenta)]
namespace Astrum
{
// if this bypass breaks, open an issue on the github
// i have a more aggressive fix than this non-intrusive one
public partial class AstralBypass : MelonPlugin
{
private const BindingFlags PrivateStatic = BindingFlags.NonPublic | BindingFlags.Static;
static AstralBypass() => PEBKACHelper.CheckForUserError();
public override void OnApplicationEarlyStart()
{
HarmonyInstance.Patch(
typeof(Assembly).GetMethod(nameof(Assembly.Load), new Type[2] { typeof(byte[]), typeof(byte[]) }),
typeof(AstralBypass).GetMethod(nameof(AssemblyLoadPre), PrivateStatic).ToNewHarmonyMethod(),
typeof(AstralBypass).GetMethod(nameof(AssemblyLoadPost), PrivateStatic).ToNewHarmonyMethod()
);
}
private static void AssemblyLoadPre()
{
// this may be slow, but it is what MelonModLogger/MelonLogger has been doing since day 1 :)
StackTrace stack = new();
if (stack.FrameCount < 2 || stack.GetFrame(2).GetMethod().Name != "LoadFromByteArray")
return;
IntegrityChecks.Bypass();
}
private static void AssemblyLoadPost() => IntegrityChecks.Repair();
}
}