Skip to content

Commit 5cd6811

Browse files
committed
Episode 14
1 parent 20b867c commit 5cd6811

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

ExampleMod.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ namespace ExampleMod;
1919

2020
public class ExampleMod : BloonsTD6Mod
2121
{
22+
public static int ExampleMonkeysPlaced = 0;
23+
public static string SaveDataKey => "ExampleMod-ExampleMonkeysPlaced";
24+
2225
public override void OnMatchStart()
2326
{
2427
ModdedMonkeys.CreateMenu(Game.instance.model.towers.ToList());
@@ -63,6 +66,7 @@ public static void Postfix(MainMenu __instance)
6366
public override void OnMatchEnd()
6467
{
6568
ModdedMonkeys.instance.Close();
69+
ExampleMonkeysPlaced = 0;
6670
}
6771

6872
public override void OnApplicationStart()

ModHelperData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace ExampleMod;
33
public static class ModHelperData
44
{
55
public const string WorksOnVersion = "47.0";
6-
public const string Version = "1.13.0";
6+
public const string Version = "1.14.0";
77
public const string Name = "(Unofficial) Example Mod";
88

99
public const string Description = "An Example Mod For my Youtube Series, look at the github for more info. If you have any questions contact me on discord: @lerpmcgerk";

Patches/MapPatches.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using BTD_Mod_Helper;
2+
using BTD_Mod_Helper.Api;
3+
using BTD_Mod_Helper.Api.Towers;
4+
using HarmonyLib;
5+
using Il2CppAssets.Scripts.Models.Profile;
6+
using Il2CppAssets.Scripts.Simulation.Track;
7+
using Newtonsoft.Json;
8+
using System.Collections.Generic;
9+
10+
11+
namespace ExampleMod.Patches
12+
{
13+
//Saving
14+
[HarmonyPatch(typeof(Map), nameof(Map.GetSaveData))]
15+
public static class Map_GetSaveData
16+
{
17+
public static void Postfix(MapSaveDataModel mapData)
18+
{
19+
if(ExampleMod.ExampleMonkeysPlaced > 0)
20+
{
21+
mapData.metaData[ExampleMod.SaveDataKey] = JsonConvert.SerializeObject(ModContent.GetContent<ModTower>()[0]);
22+
}
23+
}
24+
}
25+
//Loading
26+
[HarmonyPatch(typeof(Map), nameof(Map.SetSaveData))]
27+
public static class Map_SetSaveData
28+
{
29+
public static void Postfix(MapSaveDataModel mapData)
30+
{
31+
if (mapData.metaData.TryGetValue(ExampleMod.SaveDataKey, out string json))
32+
{
33+
ExampleMod.ExampleMonkeysPlaced = JsonConvert.DeserializeObject<int>(json);
34+
ModHelper.Log<ExampleMod>($"Placed {ExampleMod.ExampleMonkeysPlaced} Example Monkey(s)");
35+
}
36+
}
37+
}
38+
}

Patches/Tower_Initilize.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BTD_Mod_Helper;
2+
using BTD_Mod_Helper.Api;
23
using BTD_Mod_Helper.Extensions;
34
using HarmonyLib;
45
using Il2CppAssets.Scripts.Models;
@@ -20,6 +21,10 @@ public static void Postfix(Tower __instance)
2021
{
2122
__instance.UpdatedModel(Game.instance.model.GetTower(TowerType.MonkeyVillage));
2223
}
24+
if(__instance.towerModel.baseId == ModContent.TowerID<ExampleMonkey>())
25+
{
26+
ExampleMod.ExampleMonkeysPlaced++;
27+
}
2328
}
2429
}
2530
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ Episode 12: [UI Part 2](https://youtu.be/tMy-_JhKes4?si=F9IKJ55cFvB2AN8e)
3737

3838
Episode 13: [Changing Vanilla Bloon Displays and Custom Moab](https://youtu.be/rqYJv55ji60)
3939

40+
Episode 14: [Saving Mod Data](https://youtu.be/La5xuNZXSds)
41+
4042
## Planned Topics
4143
All of the topics that haven't been covered
4244

4345
Extracting the Game's Textures
4446

4547
Towers P2
4648

47-
Saving Mod Data
48-
4949
[![Requires BTD6 Mod Helper](https://raw.githubusercontent.com/gurrenm3/BTD-Mod-Helper/master/banner.png)](https://github.com/gurrenm3/BTD-Mod-Helper#readme)

0 commit comments

Comments
 (0)