-
Notifications
You must be signed in to change notification settings - Fork 0
/
PPModEnabler.cs
76 lines (56 loc) · 1.53 KB
/
PPModEnabler.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
using System.Collections.Generic;
using System;
using Base.Core;
using HarmonyLib;
using PhoenixPoint.Common.Game;
namespace Doorstop
{
// Support old and new entry points of Doorstop
static class Loader
{
public static void Main(string[] args)
{
Entrypoint.Start();
}
}
public class Entrypoint
{
public static void Start()
{
AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;
}
private static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
if (args.LoadedAssembly.GetName().Name == "Assembly-CSharp")
{
// Patch game
Harmony harmony = new Harmony("PPModEnabler");
harmony.PatchAll();
}
}
}
}
[HarmonyPatch(typeof(PhoenixGame), "InitMods")]
public class InitMods
{
static bool Prefix(PhoenixGame __instance, ref IEnumerator<NextUpdate> __result)
{
__result = new List<NextUpdate>() { NextUpdate.Never }.GetEnumerator();
__instance.ModManager.CanUseMods = true;
// Disable mods if demo
if (__instance.Platform.IsDemo())
__instance.ModManager.CanUseMods = false;
OptionsComponent optionsComponent = __instance.GetComponent<OptionsComponent>();
if (__instance.ModManager.CanUseMods)
{
while (!optionsComponent.InitialOptionsLoaded)
System.Threading.Thread.Sleep(1);
if (!__instance.ModManager.Initialize(__instance))
return false;
__instance.ModManager.DiscoverMods();
__instance.ModManager.EnableModsFromStore(optionsComponent.Options);
__instance.ModManager.SaveModConfig();
}
return false;
}
}