-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSandSpaceMod.cs
More file actions
91 lines (80 loc) · 2.79 KB
/
SandSpaceMod.cs
File metadata and controls
91 lines (80 loc) · 2.79 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
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
using System;
using System.Reflection;
using HarmonyLib;
using UnityEngine;
namespace SandSpace
{
public static class SandSpaceMod
{
public const string VERSION = "0.6.2";
public static IModSettings Settings { get; internal set; }
internal static IModLogger Logger { get; set; }
public static ModInfo ModInfo { get; internal set; }
internal static Harmony Harmony { get; set; }
internal static void StaticPatches ()
{
Harmony.PatchAll (Assembly.GetExecutingAssembly ());
}
internal static void DynamicPathes ()
{
if (Settings.EnableAllExplosionsPatch)
Harmony.Patch (
AccessTools.Method (typeof (HazardManager), nameof (HazardManager.CreateAreaHazard)),
prefix : new HarmonyMethod (typeof (HazardPatches.HazardManager_CreateAreaHazard_Patch), "Prefix")
);
if (Settings.EnableShockwaveExplosionsPatch)
Harmony.Patch (
AccessTools.Method (
typeof (ShockwaveGenerator), nameof (ShockwaveGenerator.SpawnShockwave),
new Type[] { typeof (Vector3), typeof (float), typeof (float), typeof (float), typeof (float), typeof (bool) }
),
prefix: new HarmonyMethod (typeof (HazardPatches.ShockwaveGenerator_SpawnShockwave_Patch), "Prefix")
);
if (Settings.EnableRezDropPatch)
Harmony.Patch (
AccessTools.Method (typeof (PickupRez), nameof (PickupRez.OnPickedUp)),
prefix: new HarmonyMethod (typeof (ResourcesPatces.PickupRez_OnPickedUp_Patch), "Prefix")
);
if (Settings.EnableSandboxCampaign)
{
Harmony.Patch (
AccessTools.Method (typeof (GameFlowManager), nameof (GameFlowManager.SetSandboxMode)),
prefix: new HarmonyMethod (typeof (NewGamePatches.GameFlowManager_SetSandboxMode_Patch), "Prefix")
);
Harmony.Patch (
AccessTools.Method (typeof (MenuManager), nameof (MenuManager.ActivateMenu)),
prefix: new HarmonyMethod (typeof (NewGamePatches.MenuManager_ActivateMenu_Patch), "Prefix")
);
Harmony.Patch (
AccessTools.Method (typeof (SinglePlayerMenu), nameof (SinglePlayerMenu.windowFunc)),
transpiler: new HarmonyMethod (typeof (NewGamePatches.SinglePlayerMenu_windowFunc_Patch), "Transpiler")
);
}
if (Settings.EnablePartCostPatch)
Harmony.Patch (
AccessTools.Method (typeof (ShipPartDatabase), nameof (ShipPartDatabase.GetBuildInfoScrapPrice)),
transpiler: new HarmonyMethod (typeof (ShipPartsPatches.ShipPartDatabase_GetBuildInfoScrapPrice_Patch), "Transpiler")
);
}
internal static void ApplyHarmonyPatches ()
{
StaticPatches ();
DynamicPathes ();
}
internal static void ReloadHarmonyPatches ()
{
if (!Settings.Changed &&
Settings.InGameLock)
return;
try
{
Harmony.UnpatchAll (ModInfo.ID);
ApplyHarmonyPatches ();
}
catch (Exception ex)
{
Logger.Error ($"{ex.Message}\n{ex.StackTrace}");
}
}
}
}