-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMod.cs
78 lines (74 loc) · 2.58 KB
/
Mod.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
using MelonLoader;
using UnityEngine;
using Assets.Scripts.Utils;
using BTD_Mod_Helper.Extensions;
using Assets.Scripts.Models.Towers.Behaviors;
using Assets.Scripts.Models.Towers;
using Il2CppSystem;
using Assets.Scripts.Unity;
using System.IO;
using Assets.Scripts.Models.Towers.Weapons;
using Assets.Scripts.Models.Towers.Projectiles.Behaviors;
namespace slons
{
public class Main : MelonMod
{
public override void OnApplicationStart()
{
base.OnApplicationStart();
}
public override void OnUpdate()
{
base.OnUpdate();
if (Input.GetKeyDown(KeyCode.F1))
{
log("saving towers");
foreach (TowerModel towerModel in Game.instance.model.towers)
{
removeCircularReferences(towerModel);
String path = "Towers\\" + towerModel.baseId + "\\" + towerModel.name + ".json";
if (File.Exists(path)) File.Delete(path);
FileIOUtil.SaveObject(path, towerModel);
}
log("finished");
}
}
void removeCircularReferences(TowerModel tower)
{
if (tower.baseId == "Alchemist" && tower.tiers[0] >= 2)
{
foreach (WeaponModel wModel in tower.GetWeapons())
{
AddAcidicMixtureToProjectileModel aa = wModel.projectile.GetBehavior<AddAcidicMixtureToProjectileModel>();
try { aa.Mutator.acidModel = null; }
catch (System.NullReferenceException e) { }
}
if (tower.tiers[0] == 5)
{
LoadAlchemistBrewInfoModel l = tower.GetBehavior<LoadAlchemistBrewInfoModel>();
l.addAcidicMixtureToProjectileModel.Mutator.acidModel = null;
}
}
else if (tower.baseId == "Benjamin" && tower.tier >= 7)
{
foreach (WeaponModel wModel in tower.GetWeapons())
{
StripChildrenModel strip = wModel.projectile.GetBehavior<StripChildrenModel>();
strip.Mutator.stripChildrenModel = null;
}
}
}
public static void log(Il2CppSystem.Object obj, string name)
{
FileIOUtil.LogToFile(name + ".json", obj);
}
public static void log(string s)
{
MelonLogger.Msg(s);
}
public static void log(bool b)
{
MelonLogger.Log(b.ToString());
}
}
}