-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrusherCoreBoostPlugin.cs
113 lines (99 loc) · 4.15 KB
/
CrusherCoreBoostPlugin.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
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using EquinoxsModUtils;
using EquinoxsModUtils.Additions;
using System.Collections.Generic;
using System;
namespace CrusherCoreBoost
{
[BepInPlugin(MyGUID, PluginName, VersionString)]
public class CrusherCoreBoostPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.jrinker03.CrusherCoreBoost";
private const string PluginName = "CrusherCoreBoost";
private const string VersionString = "1.0.2";
private const string UnlockDisplayName = "Core Boost (Crushing)";
private static readonly Harmony Harmony = new Harmony(MyGUID);
public static ConfigEntry<int> CoresToUnlock;
public static ManualLogSource Log = new ManualLogSource(PluginName);
public static int UnlockId
{
get;
private set;
}
/// <summary>
/// Initialise the configuration settings and patch methods
/// </summary>
private void Awake()
{
// Apply all of our patches
Logger.LogInfo($"PluginName: {PluginName}, VersionString: {VersionString} is loading...");
Harmony.PatchAll();
CreateConfigEntries();
CreateUnlock();
EMU.Events.GameDefinesLoaded += OnGameDefinesLoaded;
EMU.Events.SaveStateLoaded += OnSaveStateLoaded;
Logger.LogInfo($"PluginName: {PluginName}, VersionString: {VersionString} is loaded.");
Log = Logger;
}
private void CreateConfigEntries()
{
CoresToUnlock = Config.Bind("General", "Cores To Unlock", 250, new ConfigDescription("How many yellow cores required to unlock 'Core Boost (Crushing)' in Tech Tree."));
}
private void CreateUnlock()
{
// Add the new unlock to Sierra T8 [same as Core Boost (Assembly)] and above Core Boost (Threshing)
EMUAdditions.AddNewUnlock(new NewUnlockDetails()
{
displayName = UnlockDisplayName,
description = "Increase speed of all Crushers by 0.01% per Core Cluster.",
category = Unlock.TechCategory.Science,
requiredTier = TechTreeState.ResearchTier.Tier25,
coreTypeNeeded = ResearchCoreDefinition.CoreType.Gold,
coreCountNeeded = CoresToUnlock.Value,
dependencyNames = new System.Collections.Generic.List<string>() { EMU.Names.Unlocks.CoreBoostThreshing },
});
}
private void OnGameDefinesLoaded()
{
Unlock coreBoostCrusher = EMU.Unlocks.GetUnlockByName(UnlockDisplayName);
if (coreBoostCrusher == null)
{
Logger.LogError($"Unable to find unlock '{UnlockDisplayName}'. Halting unlock setup.");
}
UnlockId = coreBoostCrusher.uniqueId;
#if DEBUG
Logger.LogInfo($"Setting up unlock '{UnlockDisplayName}'. ID is {UnlockId}");
#endif
coreBoostCrusher.requiredTier = EMU.Unlocks.GetUnlockByName(EMU.Names.Unlocks.CoreBoostAssembly).requiredTier;
coreBoostCrusher.treePosition = (int)EMU.Unlocks.GetUnlockByName(EMU.Names.Unlocks.CoreBoostThreshing).treePosition;
coreBoostCrusher.sprite = EMU.Resources.GetResourceInfoByName(EMU.Names.Resources.Crusher).rawSprite;
}
private void OnSaveStateLoaded(object sender, EventArgs e)
{
#if DEBUG
if (TechTreeState.instance.unlockStates.Length > UnlockId)
{
Logger.LogInfo($"Core Boost (Crushing) isActive = {TechTreeState.instance.unlockStates[UnlockId].isActive}");
}
else
{
Logger.LogError($"unlockStates.Length < {UnlockId}");
}
#endif
}
#if DEBUG
internal void LogIl(IEnumerable<CodeInstruction> instructions)
{
Logger.LogInfo("***** Logging IL START *****");
foreach (CodeInstruction instruction in instructions)
{
Logger.LogInfo(instruction.ToString());
}
Logger.LogInfo("***** Logging IL END *****");
}
#endif
}
}