Skip to content

Commit bd7171f

Browse files
Added support for energy
1 parent 0e026f8 commit bd7171f

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

Patches/Energy.cs

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Reflection;
5+
using System.Linq;
6+
using APIPlugin;
7+
using DiskCardGame;
8+
using HarmonyLib;
9+
using UnityEngine;
10+
using UnityEngine.SceneManagement;
11+
using MonoMod.Cil;
12+
using Mono.Cecil.Cil;
13+
14+
namespace API.Patches
15+
{
16+
[HarmonyPatch(typeof(Part1ResourcesManager), "CleanUp")]
17+
public class Part1ResourcesManager_CleanUp
18+
{
19+
public static void Prefix(Part1ResourcesManager __instance)
20+
{
21+
ResourcesManager baseResourceManager = (ResourcesManager) __instance;
22+
if (Plugin.configEnergy.Value)
23+
{
24+
var baseTraverse = Traverse.Create(baseResourceManager);
25+
baseTraverse.Property("PlayerEnergy").SetValue(0);
26+
baseTraverse.Property("PlayerMaxEnergy").SetValue(0);
27+
}
28+
if ( Plugin.configDrone.Value)
29+
{
30+
Singleton<ResourceDrone>.Instance.CloseAllCells(false);
31+
Singleton<ResourceDrone>.Instance.SetOnBoard(false, false);
32+
}
33+
}
34+
}
35+
36+
[HarmonyPatch(typeof(ResourcesManager), "Setup")]
37+
public class ResourcesManager_Setup
38+
{
39+
public static void Prefix(ResourcesManager __instance)
40+
{
41+
if (__instance is Part1ResourcesManager && Plugin.configDrone.Value)
42+
{
43+
Singleton<ResourceDrone>.Instance.SetOnBoard(true, false);
44+
}
45+
}
46+
}
47+
48+
[HarmonyPatch(typeof(ResourcesManager), "ShowAddMaxEnergy")]
49+
public class ResourcesManager_ShowAddMaxEnergy
50+
{
51+
public static IEnumerator Postfix(IEnumerator result, ResourcesManager __instance)
52+
{
53+
if (__instance is Part1ResourcesManager && Plugin.configDrone.Value)
54+
{
55+
Singleton<ResourceDrone>.Instance.OpenCell(__instance.PlayerMaxEnergy - 1);
56+
yield return new WaitForSeconds(0.4f);
57+
}
58+
yield return result;
59+
}
60+
}
61+
62+
[HarmonyPatch(typeof(ResourcesManager), "ShowAddEnergy")]
63+
public class ResourcesManager_ShowAddEnergy
64+
{
65+
public static IEnumerator Postfix(IEnumerator result, int amount, ResourcesManager __instance)
66+
{
67+
if (__instance is Part1ResourcesManager && Plugin.configDrone.Value)
68+
{
69+
int num;
70+
for (int i = __instance.PlayerEnergy - amount; i < __instance.PlayerEnergy; i = num + 1)
71+
{
72+
Singleton<ResourceDrone>.Instance.SetCellOn(i, true, false);
73+
yield return new WaitForSeconds(0.05f);
74+
num = i;
75+
}
76+
}
77+
yield return result;
78+
}
79+
}
80+
81+
[HarmonyPatch(typeof(ResourcesManager), "ShowSpendEnergy")]
82+
public class ResourcesManager_ShowSpendEnergy
83+
{
84+
public static IEnumerator Postfix(IEnumerator result, int amount, ResourcesManager __instance)
85+
{
86+
if (__instance is Part1ResourcesManager && Plugin.configDrone.Value)
87+
{
88+
int num;
89+
for (int i = __instance.PlayerEnergy + amount - 1; i >= __instance.PlayerEnergy; i = num - 1)
90+
{
91+
AudioController.Instance.PlaySound3D("crushBlip3", MixerGroup.TableObjectsSFX, __instance.transform.position, 0.4f, 0f, new AudioParams.Pitch(0.9f + (float)(__instance.PlayerEnergy + i) * 0.05f), null, null, null, false);
92+
Singleton<ResourceDrone>.Instance.SetCellOn(i, false, false);
93+
yield return new WaitForSeconds(0.05f);
94+
num = i;
95+
}
96+
}
97+
yield return result;
98+
}
99+
}
100+
101+
[HarmonyPatch]
102+
public class TurnManager_PlayerTurn
103+
{
104+
static IEnumerable<MethodBase> TargetMethods()
105+
{
106+
Type targetType = AccessTools.TypeByName("DiskCardGame.TurnManager+<PlayerTurn>d__73");
107+
return AccessTools.GetDeclaredMethods(targetType).Where(m => m.Name.Equals("MoveNext"));
108+
}
109+
110+
static MethodInfo trigger = AccessTools.Method(typeof(TurnManager), "DoUpkeepPhase", new Type[] {typeof(bool)});
111+
public static void ILManipulator(ILContext il, MethodBase original, ILLabel retLabel)
112+
{
113+
if(Plugin.configEnergy.Value)
114+
{
115+
Type targetType = AccessTools.TypeByName("DiskCardGame.TurnManager+<PlayerTurn>d__73");
116+
ILCursor c = new ILCursor(il);
117+
c.GotoNext(inst => inst.MatchCall(AccessTools.Method(typeof(SaveManager), "get_SaveFile")));
118+
c.RemoveRange(6);
119+
120+
c.GotoNext(inst => inst.MatchLdcI4(0));
121+
c.Next.OpCode = OpCodes.Ldc_I4_1;
122+
foreach (ILLabel branch in c.IncomingLabels)
123+
{
124+
c.GotoNext(inst => inst.MatchStfld(AccessTools.Field(targetType, "<showEnergyModule>5__2")));
125+
branch.Target = c.Next;
126+
foreach (Instruction inst in branch.Branches)
127+
{
128+
inst.OpCode = OpCodes.Br_S;
129+
}
130+
c.GotoPrev(inst => inst.MatchBr(branch));
131+
}
132+
c.Emit(OpCodes.Clt);
133+
134+
c.GotoNext(inst => inst.MatchCall(AccessTools.Method(typeof(SaveManager), "get_SaveFile")));
135+
foreach (ILLabel branch in c.IncomingLabels)
136+
{
137+
c.GotoNext(inst => inst.MatchLdcI4(1));
138+
branch.Target = c.Next;
139+
}
140+
141+
c.GotoPrev(inst => inst.MatchCall(AccessTools.Method(typeof(SaveManager), "get_SaveFile")));
142+
c.RemoveRange(3);
143+
}
144+
}
145+
}
146+
}

0 commit comments

Comments
 (0)