-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.cs
More file actions
62 lines (50 loc) · 1.8 KB
/
Loader.cs
File metadata and controls
62 lines (50 loc) · 1.8 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using SpaceEngineersLoader.Patches;
namespace SpaceEngineersLoader;
internal static class Loader
{
[STAThread]
public static void Main(string[] args)
{
try
{
MessageBox.Show("PID: " + Environment.ProcessId, "Space Engineer Loader");
Prepare();
Run(args);
}
catch (Exception e)
{
Console.WriteLine(e);
Console.WriteLine("Press enter to exit");
Console.ReadLine();
Environment.Exit(0);
}
}
private static void Prepare()
{
Console.WriteLine("Initializing runtime...");
AssemblyLoader.AddPath(typeof(Loader).Assembly.Location);
AssemblyLoader.AddPath(Environment.CurrentDirectory);
AppDomain.CurrentDomain.AssemblyResolve += (_, e) => AssemblyLoader.GetOrLoadManaged(e.Name);
Console.WriteLine("Applying patches...");
Assembly_Patches.SetEntryAssembly(AssemblyLoader.GetOrLoadManaged("SpaceEngineers.exe")!);
AssemblyLoader.GetOrLoadManaged("VRage.Scripting");
Harmony harmony = new Harmony("opekope2.spaceengineersloader");
harmony.PatchAll();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Run(string[] args)
{
Console.WriteLine("Starting game...");
string file = Environment.GetEnvironmentVariable("SELDR_EXE") ?? "SpaceEngineers.exe";
Assembly? se = AssemblyLoader.GetOrLoadManaged(file);
if (se == null)
{
throw new FileNotFoundException("Cannot find entry point", file);
}
Action<string[]> main = (Action<string[]>)Delegate.CreateDelegate(typeof(Action<string[]>), se.EntryPoint!);
main(args);
}
}