-
Notifications
You must be signed in to change notification settings - Fork 2
/
CookieClicker.cs
232 lines (218 loc) · 7.74 KB
/
CookieClicker.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
using Assets.Scripts.Models;
using Assets.Scripts.Models.Bloons.Behaviors;
using Assets.Scripts.Models.GenericBehaviors;
using Assets.Scripts.Models.Towers;
using Assets.Scripts.Models.Towers.Behaviors.Attack;
using Assets.Scripts.Simulation;
using Assets.Scripts.Unity;
using Assets.Scripts.Unity.Display;
using Assets.Scripts.Unity.UI_New.InGame;
using Assets.Scripts.Unity.UI_New.InGame.Stats;
using BTD_Mod_Helper;
using BTD_Mod_Helper.Api.Enums;
using BTD_Mod_Helper.Api.Towers;
using BTD_Mod_Helper.Extensions;
using CookieClicker;
using HarmonyLib;
using Il2CppSystem;
using JetBrains.Annotations;
using MelonLoader;
using System;
using System.Reflection;
using UnityEngine;
using String = Il2CppSystem.String;
[assembly: MelonInfo(typeof(CookieClicker.CookieClicker), ModHelperData.Name, ModHelperData.Version, ModHelperData.RepoOwner)]
[assembly: MelonGame("Ninja Kiwi", "BloonsTD6")]
namespace CookieClicker;
public class CookieClicker : BloonsTD6Mod
{
public static float time = 0;
public static float timer = 0;
public static int grandma = 0;
public static int mines = 0;
public static int factory = 0;
public static int god = 0;
public static bool menushop = false;
public static bool menuinv = false;
public override void OnApplicationStart()
{
//previous two lines are for debugging/finding names of assets
assetBundle = AssetBundle.LoadFromMemory(ExtractResource("cookie.bundle"));// if using unityexplorer, there is an error, but everything still works
ModHelper.Msg<CookieClicker>("Cookie loaded!");
}
public static void PlaySound(string name)
{
Game.instance.audioFactory.PlaySoundFromUnity(null, name, "FX", 1, 1);
}
public static AssetBundle assetBundle;
private byte[] ExtractResource(String filename)
{
Assembly a = MelonAssembly.Assembly; // get the assembly
return a.GetEmbeddedResource(filename).GetByteArray(); // get the embedded bundle as a raw file that unity can read
}
public override void OnMatchStart()
{
InGame.instance.SetCash(0);
foreach (var bloon in InGame.instance.bridge.GetAllBloons())
{
bloon.GetBaseModel().GetBehavior<DistributeCashModel>().cash = 0f;
}
base.OnMatchStart();
}
public override void OnRoundEnd()
{
InGame.instance.AddCash(100);
base.OnRoundEnd();
}
public override void OnUpdate()
{
if (InGame.instance != null && InGame.instance.bridge != null)
{
time += UnityEngine.Time.deltaTime;
if (time > 1f)
{
time = 0;
int money = 0;
money += grandma;
money += mines * 5;
money += factory * 25;
money += god * 1000;
InGame.instance.AddCash(money);
}
if (InGame.instance != null && InGame.instance.bridge != null)
{
if (Input.GetMouseButtonDown(0))
{
InGame.instance.AddCash(1);
}
}
}
}
}
[HarmonyPatch(typeof(Simulation), "AddCash")]
public class NoCash
{
[HarmonyPrefix]
public static bool Prefix(ref double c, ref Simulation.CashSource source)
{
if (source == Simulation.CashSource.Normal)
{
c = 0f;
}
return true;
}
}
[HarmonyPatch(typeof(RoundDisplay), nameof(RoundDisplay.OnUpdate))]
public sealed class Display
{
[HarmonyPostfix]
public static void Fix(ref RoundDisplay __instance)
{
__instance.text.text = $"{__instance.cachedRoundDisp}\n";
if (Input.GetKeyDown(KeyCode.F2))
{
if (CookieClicker.timer < 1)
{
CookieClicker.timer = 20;
CookieClicker.menuinv = false;
switch (CookieClicker.menushop)
{
case true:
CookieClicker.menushop = false;
break;
case false:
CookieClicker.menushop = true;
break;
}
}
}
else if (Input.GetKeyDown(KeyCode.F1))
{
if (CookieClicker.timer < 1)
{
CookieClicker.timer = 20;
CookieClicker.menushop = false;
switch (CookieClicker.menuinv)
{
case true:
CookieClicker.menuinv = false;
break;
case false:
CookieClicker.menuinv = true;
break;
}
}
}
else if (CookieClicker.timer > 0)
{
CookieClicker.timer -= 1;
}
if (CookieClicker.menushop == true)
{
if (CookieClicker.timer < 1)
{
if (Input.GetKey(KeyCode.F5))
{
if (InGame.instance.GetCash() > 349)
{
CookieClicker.grandma += 1;
InGame.instance.AddCash(-350);
CookieClicker.timer = 10;
}
}
if (Input.GetKey(KeyCode.F6))
{
if (InGame.instance.GetCash() > 1599)
{
CookieClicker.mines += 1;
InGame.instance.AddCash(-1600);
CookieClicker.timer = 10;
}
}
if (Input.GetKey(KeyCode.F7))
{
if (InGame.instance.GetCash() > 6499)
{
CookieClicker.factory += 1;
InGame.instance.AddCash(-6500);
CookieClicker.timer = 10;
}
}
if (Input.GetKey(KeyCode.F8))
{
if (InGame.instance.GetCash() > 99999)
{
CookieClicker.god += 1;
InGame.instance.AddCash(-100000);
CookieClicker.timer = 10;
}
}
}
__instance.text.text += "F5 | Buy Cookie Grandma (1/cps): Cost 350" + "\n";
__instance.text.text += "F6 | Buy Cookie Mine (5/cps): Cost 1600" + "\n";
__instance.text.text += "F7 | Buy Cookie Factory (25/cps): Cost 6500" + "\n";
__instance.text.text += "F8 | Buy Cookie ??? (???/cps): Cost 100000" + "\n";
__instance.text.text += "F2 to toggle shop" + "\n";
}
else if (CookieClicker.menuinv == true)
{
__instance.text.text += "Cookie Grandmas owned: " + CookieClicker.grandma + "\n";
__instance.text.text += "Cookie Mines owned: " + CookieClicker.mines + "\n";
__instance.text.text += "Cookie Factorys owned: " + CookieClicker.factory + "\n";
if (CookieClicker.god != 0)
{
__instance.text.text += "Cookie Gods owned: " + CookieClicker.god + "\n";
}
else
{
__instance.text.text += "Cookie ???s owned: ???" + "\n";
}
__instance.text.text += "F1 to toggle inventory" + "\n";
}
else
{
__instance.text.text += "F1 to toggle inventory" + "\n";
__instance.text.text += "F2 to toggle shop" + "\n";
}
}
}