-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
328 lines (298 loc) · 12.2 KB
/
Main.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
using MelonLoader;
using BTD_Mod_Helper;
using BergsMapPack;
using UnityEngine;
using BTD_Mod_Helper.Api;
using Il2CppAssets.Scripts.Data.MapSets;
using Il2CppAssets.Scripts.Data;
using Il2CppAssets.Scripts.Unity;
using BTD_Mod_Helper.Extensions;
using Il2CppAssets.Scripts.Models.Towers;
using HarmonyLib;
using Main = BergsMapPack.Main;
using Il2CppAssets.Scripts.Models.Map;
using System;
using System.Linq;
using Il2CppAssets.Scripts.Unity.Bridge;
using Il2CppAssets.Scripts.Unity.Map;
using Il2CppAssets.Scripts.Models.Map.Spawners;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppAssets.Scripts.Unity.Scenes;
using Il2CppAssets.Scripts.Unity.UI_New.Main.MapSelect;
using Il2CppAssets.Scripts.Unity.Player;
using BergsMapPack.Map1;
using static BTD_Mod_Helper.Api.ModContent;
using static UnityEngine.InputSystem.LowLevel.InputStateHistory;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using Il2CppAssets.Scripts.Unity.UI_New.Utils;
using UnityEngine.Playables;
using Il2CppAssets.Scripts.Simulation.Track;
using Il2CppAssets.Scripts.Simulation.Bloons;
using System.Collections.Generic;
using Il2CppAssets.Scripts.Simulation.Towers;
[assembly: MelonInfo(typeof(Main), ModHelperData.Name, ModHelperData.Version, ModHelperData.RepoOwner)]
[assembly: MelonGame("Ninja Kiwi", "BloonsTD6")]
namespace BergsMapPack;
[HarmonyPatch]
public partial class Main : BloonsTD6Mod
{
public static GameObject SummonBR = null;
public static GameObject BadorRocket = null;
static string lastMap = "";
public string activeMap = "";
public static AssetBundle? MoonwayAssetBundle;
public override void OnTitleScreen()
{
MoonwayAssetBundle ??= GetBundle<Main>("badorrocket");
if(MoonwayAssetBundle != null)
{
if (BadorRocket == null)
{
BadorRocket = MoonwayAssetBundle.LoadAsset("BadorRocket").Cast<GameObject>();
SummonBR = GameObject.Instantiate(BadorRocket);
}
}
}
public int FrameCount;
public override void OnUpdate()
{
if(InGameData.CurrentGame != null)
{
var ActiveMapInfo = InGameData.CurrentGame.selectedMap;
activeMap = ActiveMapInfo.ToString();
}
if (!GameObject.Find("BadorRocket(Clone)").Exists() && activeMap == "Moonway")
{
MoonwayAssetBundle ??= GetBundle<Main>("badorrocket");
BadorRocket = MoonwayAssetBundle.LoadAsset("BadorRocket").Cast<GameObject>();
SummonBR = GameObject.Instantiate(BadorRocket);
}
if(GameObject.Find("BadorRocket(Clone)").Exists() && activeMap != "Moonway")
{
GameObject.Find("BadorRocket(Clone)").Destroy();
}
if (GameObject.Find("BadorRocket(Clone)").Exists())
{
Animator animator = GameObject.Find("BadorRocket(Clone)").GetComponent<Animator>();
FrameCount++;
var second = FrameCount / 60;
if (second == 25)
{
animator.SetBool("flugstart", true);
FrameCount = FrameCount + 90;
}
if (second >= 26)
{
animator.SetBool("flugstart", false);
FrameCount = 0;
}
}
}
static bool isCustom(string map)
{
return mapList.Where(x => x.name == map).Count() > 0;
}
public static Il2CppReferenceArray<Il2CppAssets.Scripts.Simulation.SMath.Polygon> Empty()
{
return new Il2CppReferenceArray<Il2CppAssets.Scripts.Simulation.SMath.Polygon>(0);
}
class MapData
{
public string name;
public MapDifficulty difficulty;
public PathModel[] paths;
public PathSpawnerModel spawner;
public Il2CppReferenceArray<AreaModel> areas;
public string mapMusic;
public string mapDisplayName;
public string mapType;
public MapData(string name, MapDifficulty difficulty, PathModel[] paths, PathSpawnerModel spawner, Il2CppReferenceArray<AreaModel> areas, string mapMusic, string mapDisplayName, string mapType)
{
this.name = name;
this.difficulty = difficulty;
this.paths = paths;
this.spawner = spawner;
this.areas = areas;
this.mapMusic = mapMusic;
this.mapDisplayName = mapDisplayName;
this.mapType = mapType;
}
}
static MapData[] mapList = new MapData[]
{
new MapData("Moonway", MapDifficulty.Advanced, Moonway.pathmodel(), Moonway.spawner(), Moonway.areas(), "MusicDarkA", "Moonway", "EasyBergbauerMaps"),
new MapData("ShellShock", MapDifficulty.Expert, ShellShock.pathmodel(), ShellShock.spawner(), ShellShock.areas(), "MusicDarkA", "ShellShock", "EasyBergbauerMaps"),
};
[HarmonyPatch(typeof(InputManager), nameof(InputManager.CursorDown))]
internal class InputManager_CursorDown
{
[HarmonyPostfix]
public static void Postfix(InputManager __instance)
{
int pierce = 1;
int damage = 0;
float Value = 0;
List<Tower> towers = InGame.instance.GetTowers();
int TC = towers.Count;
for (int i = 0; i < TC; i++)
{
if (towers[i] != null)
{
string text = towers[i].model.name;
if (text.Contains("MortarMonkey") || text.Contains("HeliPilot") || text.Contains("MonkeyAce") || text.Contains("MonkeyBuccaneer") || text.Contains("MonkeySub") || text.Contains("SniperMonkey") || text.Contains("DartlingGunner"))
{
Value = towers[i].SaleValue + Value;
}
if (text.Contains("CaptainChurchill"))
{
pierce = pierce * 3;
}
}
}
for(int i = 0; i <= (Value / 5000); i++)
{
damage++;
}
if (InGameData.CurrentGame != null)
{
var ActiveMapInfo = InGameData.CurrentGame.selectedMap;
if(ActiveMapInfo.ToString() != "ShellShock")
{
damage = 0;
}
}
BloonToSimulation[] bloonsims = InGame.instance.bridge.GetAllBloons().ToArray();
foreach (BloonToSimulation sim in bloonsims)
{
Bloon bloon = sim.GetBloon();
if (Math.Sqrt(Math.Pow(bloon.Position.X - __instance.cursorPositionWorld.x, 2) + Math.Pow(bloon.Position.Y - __instance.cursorPositionWorld.y, 2)) < bloon.radius + 2)
{
bloon.Damage(damage, null, true, true, true);
if (--pierce <= 0) break;
}
}
}
}
[HarmonyPatch(typeof(TitleScreen), "Start")]
public class Awake_Patch
{
[HarmonyPostfix]
public static void Postfix()
{
foreach (var mapdata in mapList)
{
if (mapdata.mapType == "EasyBergbauerMaps")
{
GameData._instance.mapSet.Maps.items = GameData._instance.mapSet.Maps.items.AddTo(new MapDetails
{
id = mapdata.name,
isBrowserOnly = false,
isDebug = false,
difficulty = mapdata.difficulty,
unlockDifficulty = MapDifficulty.Beginner,
mapMusic = mapdata.mapMusic,
mapSprite = ModContent.GetSpriteReference<Main>(mapdata.name),
coopMapDivisionType = CoopDivision.FREE_FOR_ALL,
}).ToArray();
}
}
}
[HarmonyPatch(typeof(MapButton), "ShowMedal")]
public class ShowMedal_Patch2
{
[HarmonyPrefix]
public static bool Prefix(MapButton __instance, Btd6Player player, Animator medalAnimator, string mapId, string difficulty, string mode)
{
foreach (var mapData in mapList)
{
Game.instance.GetBtd6Player().UnlockMap(mapData.name);
}
return true;
}
}
[HarmonyPatch(typeof(MapLoader), nameof(MapLoader.LoadScene))]
public class LoadMap
{
[HarmonyPrefix]
internal static bool Fix(ref MapLoader __instance)
{
lastMap = __instance.currentMapName;
if (isCustom(lastMap))
{
__instance.currentMapName = "MuddyPuddles";
}
return true;
}
}
static bool shouldRun = true;
[HarmonyPatch(typeof(UnityToSimulation), nameof(UnityToSimulation.InitMap))]
internal class InitMap_Patch
{
[HarmonyPrefix]
internal static bool Prefix(UnityToSimulation __instance, ref MapModel map)
{
try
{
if (!isCustom(lastMap))
{
try
{
GameObject.Destroy(GameObject.Find("mapcube"));
}
catch
{
}
return true;
}
var ob2 = GameObject.Find("MuddyPuddlesTerrain");
try
{
GameObject.Destroy(GameObject.Find("mapcube"));
}
catch
{
}
MapData mapdata = mapList.Where(x => x.name == lastMap).First();
Texture2D tex = ModContent.GetTexture<Main>(mapdata.name);
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.name = "mapcube";
cube.transform.position = new Vector3(0, -0.4901f, 0);
cube.transform.localScale = new Vector3(-300, 1f, -235);
cube.GetComponent<Renderer>().material = ob2.GetComponent<Renderer>().material;
cube.GetComponent<Renderer>().material.mainTexture = tex;
foreach (var ob in UnityEngine.Object.FindObjectsOfType<GameObject>())
{
if (ob.name.Contains("Festive") || ob.name.Contains("Rocket") || ob.name.Contains("Firework") || ob.name.Contains("Box") || ob.name.Contains("Candy") || ob.name.Contains("Gift") || ob.name.Contains("Snow") || ob.name.Contains("Ripples") || ob.name.Contains("Grass") || ob.name.Contains("Christmas") || ob.name.Contains("WhiteFlower") || ob.name.Contains("Tree") || ob.name.Contains("Rock") || ob.name.Contains("Shadow") || ob.name.Contains("WaterSplashes"))
if (ob.name != "MuddyPuddlesTerrain")
ob.transform.position = new Vector3(1000, 1000, 1000);
}
map.areas = mapdata.areas;
map.spawner = mapdata.spawner;
map.paths = mapdata.paths;
map.name = mapdata.name;
map.mapName = mapdata.name;
if (GameObject.Find("Rain"))
GameObject.Find("Rain").active = false;
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
return true;
}
}
[HarmonyPatch(typeof(TowerModel), "IsPlaceableInAreaType")]
public class IsTowerPlaceableInAreaType_Patch
{
[HarmonyPrefix]
static bool Prefix(ref bool __result, AreaType areaType)
{
if (lastMap != "Epilogue" && lastMap != "Crossover") return true;
__result = true;
return false;
}
}
}
}
}