-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCore.cs
117 lines (88 loc) · 3.57 KB
/
Core.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Diagnostics;
using MelonLoader.InternalUtils;
using MelonLoader.MonoInternals;
using bHapticsLib;
using BepInEx.Configuration;
#pragma warning disable IDE0051 // Prevent the IDE from complaining about private unreferenced methods
namespace MelonLoader
{
internal static class Core
{
internal static HarmonyLib.Harmony HarmonyInstance;
internal static bool IsIl2Cpp = false;
internal static int Initialize(ConfigFile config, bool isIl2Cpp)
{
IsIl2Cpp = isIl2Cpp;
MelonLaunchOptions.LoadConfig(config);
AppDomain curDomain = AppDomain.CurrentDomain;
if (MelonLaunchOptions.Core.EnableFixes)
{
Fixes.UnhandledException.Install(curDomain);
Fixes.ServerCertificateValidation.Install();
}
MelonUtils.Setup(curDomain);
Assertions.LemonAssertMapping.Setup();
if (!MonoResolveManager.Setup())
return 1;
HarmonyInstance = new HarmonyLib.Harmony(BuildInfo.Name);
if (MelonLaunchOptions.Core.EnableFixes)
{
Fixes.ForcedCultureInfo.Install();
Fixes.InstancePatchFix.Install();
Fixes.ProcessFix.Install();
}
if (MelonLaunchOptions.Core.EnablePatchShield)
PatchShield.Install();
if (MelonLaunchOptions.Core.EnableObfuscationCheck)
ObfuscationCheck.Initialize();
MelonPreferences.Load();
if (MelonLaunchOptions.Core.EnableCompatibilityLayers)
MelonCompatibilityLayer.LoadModules();
if (MelonLaunchOptions.Core.EnableBHapticsIntegration)
bHapticsManager.Connect(BuildInfo.Name, UnityInformationHandler.GameName);
MelonHandler.LoadMelonsFromDirectory<MelonPlugin>(MelonHandler.PluginsDirectory);
MelonEvents.MelonHarmonyEarlyInit.Invoke();
MelonEvents.OnPreInitialization.Invoke();
return 0;
}
internal static int PreStart()
{
MelonEvents.OnApplicationEarlyStart.Invoke();
if (MelonLaunchOptions.Core.EnableAssemblyGeneration && MelonUtils.IsGameIl2Cpp())
Il2CppAssemblyGenerator.Run();
return 1;
}
internal static int Start()
{
MelonEvents.OnPreModsLoaded.Invoke();
MelonHandler.LoadMelonsFromDirectory<MelonMod>(MelonHandler.ModsDirectory);
MelonEvents.OnPreSupportModule.Invoke();
if (!SupportModule.Setup())
return 1;
AddUnityDebugLog();
RegisterTypeInIl2Cpp.SetReady();
MelonEvents.MelonHarmonyInit.Invoke();
MelonEvents.OnApplicationStart.Invoke();
return 0;
}
internal static void Quit()
{
MelonPreferences.Save();
HarmonyInstance.UnpatchSelf();
if (MelonLaunchOptions.Core.EnableBHapticsIntegration)
bHapticsManager.Disconnect();
MelonLogger.Flush();
if (MelonLaunchOptions.Core.QuitFix)
Process.GetCurrentProcess().Kill();
}
private static void AddUnityDebugLog()
{
var msg = "~ This Game has been MODIFIED using MelonLoader. DO NOT report any issues to the Game Developers! ~";
var line = new string('-', msg.Length);
SupportModule.Interface.UnityDebugLog(line);
SupportModule.Interface.UnityDebugLog(msg);
SupportModule.Interface.UnityDebugLog(line);
}
}
}