Skip to content

Commit

Permalink
Merge pull request #22 from Derpy-Jacob-903/patch-1
Browse files Browse the repository at this point in the history
I love null checking!! (Plus 46.X Fixes!)
  • Loading branch information
mend-dev authored Dec 13, 2024
2 parents 5867144 + 3eb1038 commit 20e9004
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 34 deletions.
1 change: 1 addition & 0 deletions Bloon/Bosses/Vanilla/BloonariusBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Il2CppAssets.Scripts.Simulation.Bloons.Behaviors;
using UnityEngine;
using System;
using BloonType = BTD_Mod_Helper.Api.Enums.BloonType;

namespace BTD6Rogue;

Expand Down
1 change: 1 addition & 0 deletions Bloon/Bosses/Vanilla/LychBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Il2CppAssets.Scripts.Simulation.Bloons.Behaviors;
using BTD_Mod_Helper.Api.Enums;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using BloonType = BTD_Mod_Helper.Api.Enums.BloonType;

namespace BTD6Rogue;

Expand Down
8 changes: 4 additions & 4 deletions Patch/MenuManager/MenuManager_CloseMenuInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

namespace BTD6Rogue;

[HarmonyPatch(typeof(BTDMenuManager._CloseCurrentMenuInternal_d__58), nameof(BTDMenuManager._CloseCurrentMenuInternal_d__58.MoveNext))]
[HarmonyPatch(typeof(BTDMenuManager._CloseCurrentMenuInternal_d__57), nameof(BTDMenuManager._CloseCurrentMenuInternal_d__57.MoveNext))]
static class CloseCur {
[HarmonyPrefix]
static void Prefix(BTDMenuManager._CloseCurrentMenuInternal_d__58 __instance, out string __state) {
static void Prefix(BTDMenuManager._CloseCurrentMenuInternal_d__57 __instance, out string __state) {
__state = __instance._menuName_5__2;
Il2CppSystem.ValueTuple<string, Object> lastStackedMenu = __instance.__4__this.menuStack[__instance.__4__this.menuStack.Count - 1];

if (__instance.__1__state == 0 && lastStackedMenu.Item1.Contains("ModdedMenu")) {
__instance.__8__1 = new BTDMenuManager.__c__DisplayClass58_0();
__instance.__8__1 = new BTDMenuManager.__c__DisplayClass57_0();
__instance.__8__1.__4__this = __instance.__4__this;
__instance.__4__this.IsClosingOrOpeningMenu = true;
__instance.__8__1.closingMenu = __instance.__4__this.currMenu;
Expand Down Expand Up @@ -48,7 +48,7 @@ static void Prefix(BTDMenuManager._CloseCurrentMenuInternal_d__58 __instance, ou
}
}
[HarmonyPostfix]
static void Postfix(BTDMenuManager._CloseCurrentMenuInternal_d__58 __instance, string __state) {
static void Postfix(BTDMenuManager._CloseCurrentMenuInternal_d__57 __instance, string __state) {
if (__state != null && __state.Contains("ModdedMenu") && __instance.__4__this.menuStack.Count > 1) {
string oldName = __state.Split("-")[0];

Expand Down
6 changes: 3 additions & 3 deletions Patch/MenuManager/MenuManager_LoadSceneAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

namespace BTD6Rogue;

[HarmonyPatch(typeof(BTDMenuManager._LoadSceneAsync_d__35), nameof(BTDMenuManager._LoadSceneAsync_d__35.MoveNext))]
[HarmonyPatch(typeof(BTDMenuManager._LoadSceneAsync_d__34), nameof(BTDMenuManager._LoadSceneAsync_d__34.MoveNext))]
static class LoadSceneAsync_MoveNext {
[HarmonyPrefix]
static void Prefix(BTDMenuManager._LoadSceneAsync_d__35 __instance, out string __state) {
static void Prefix(BTDMenuManager._LoadSceneAsync_d__34 __instance, out string __state) {
__state = __instance.sceneName;
if (__instance.__1__state == 0 && __instance.sceneName.Contains("ModdedMenu")) {
string oldName = __instance.sceneName.Split("-")[0];
Expand All @@ -23,7 +23,7 @@ static void Prefix(BTDMenuManager._LoadSceneAsync_d__35 __instance, out string _
}

[HarmonyPostfix]
static void PostFix(BTDMenuManager._LoadSceneAsync_d__35 __instance, string __state) {
static void PostFix(BTDMenuManager._LoadSceneAsync_d__34 __instance, string __state) {
if (__instance.__1__state == -1 && __state.Contains("ModdedMenu")) {
Scene newScene = SceneManager.CreateScene(__state, new CreateSceneParameters());
Scene sceneFromName = SceneManager.GetSceneByName(__instance.sceneName);
Expand Down
8 changes: 4 additions & 4 deletions Patch/MenuManager/MenuManager_OpenMenuInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace BTD6Rogue;
// Praise the patch for it allows menus OF THE SAME TYPE TO BE STACKED OVER EACHOTHER!!!
// TODO: Menus of the same type overwrite eachother in the stack making it so if you press the back button, in this case, it sends the user back to the main menu rather than the previous menu
// TODO: Delete Il2Cpp and obfuscation from existence
[HarmonyPatch(typeof(BTDMenuManager._OpenMenuInternal_d__53), nameof(BTDMenuManager._OpenMenuInternal_d__53.MoveNext))]
[HarmonyPatch(typeof(BTDMenuManager._OpenMenuInternal_d__52), nameof(BTDMenuManager._OpenMenuInternal_d__52.MoveNext))]
static class MenuManagerOpenMenuInternal54_MoveNext {
[HarmonyPrefix]
static void Prefix(BTDMenuManager._OpenMenuInternal_d__53 __instance) {
static void Prefix(BTDMenuManager._OpenMenuInternal_d__52 __instance) {
bool isModdedMenu = false;
ModMenuData mmd = null!;
if (__instance.menuData != null) {
Expand All @@ -28,7 +28,7 @@ static void Prefix(BTDMenuManager._OpenMenuInternal_d__53 __instance) {
}
if (__instance.__1__state == 0 && isModdedMenu) {
__instance.__1__state = 1;
__instance.__8__1 = new BTDMenuManager.__c__DisplayClass53_0();
__instance.__8__1 = new BTDMenuManager.__c__DisplayClass52_0();
__instance.__8__1.__4__this = __instance.__4__this;
__instance.__8__1.previousMenu = __instance.__4__this.currMenu;

Expand All @@ -44,7 +44,7 @@ static void Prefix(BTDMenuManager._OpenMenuInternal_d__53 __instance) {
}
}
[HarmonyPostfix]
static void Postfix(BTDMenuManager._OpenMenuInternal_d__53 __instance) {
static void Postfix(BTDMenuManager._OpenMenuInternal_d__52 __instance) {
bool isModdedMenu = false;
ModMenuData mmd = null!;
if (__instance.menuData != null) {
Expand Down
4 changes: 2 additions & 2 deletions Patch/MenuManager/MenuManager_UnloadSceneAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

namespace BTD6Rogue;

[HarmonyPatch(typeof(BTDMenuManager._UnloadSceneAsync_d__36), nameof(BTDMenuManager._UnloadSceneAsync_d__36.MoveNext))]
[HarmonyPatch(typeof(BTDMenuManager._UnloadSceneAsync_d__35), nameof(BTDMenuManager._UnloadSceneAsync_d__35.MoveNext))]
static class LoadSceneAsync_MoveNexttttttttttttttttttttttttttttttttttttttt {
[HarmonyPrefix]
static void Prefix(BTDMenuManager._UnloadSceneAsync_d__36 __instance) {
static void Prefix(BTDMenuManager._UnloadSceneAsync_d__35 __instance) {
if (__instance.sceneName.Contains("ModdedMenu") && __instance.__1__state == 0) {
__instance.__4__this.sceneInstanceDict.Remove(__instance.sceneName);
Scene scene = SceneManager.GetSceneByName(__instance.sceneName);
Expand Down
39 changes: 24 additions & 15 deletions Patch/Spawner/Spawner_Emit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,38 @@ namespace BTD6Rogue;
internal static class Spawner_Emit {
[HarmonyPrefix]
private static void Prefix(Spawner __instance, ref BloonModel bloonModel, int roundNumber, int emissionIndex) {
if (bloonModel.isBoss || bloonModel.baseId.Contains("Lych") || bloonModel.IsRock) {
if (BTD6Rogue.rogueGame is null) { return; }
if (bloonModel.isBoss || bloonModel.baseId.Contains("Lych") || bloonModel.IsRock) {
BossUtil.GetBossFromBloonId(bloonModel.baseId).AdjustBloonModel(bloonModel, roundNumber / 20, false);
}
}

[HarmonyPostfix]
private static void Postfix(Spawner __instance, BloonModel bloonModel, int roundNumber, int emissionIndex, ref Bloon __result) {
if (bloonModel.isBoss || bloonModel.baseId.Contains("Lych") || bloonModel.IsRock) {
RogueBoss boss = BossUtil.GetBossFromBloonId(bloonModel.baseId);
boss.AdjustBloon(__result, roundNumber / 20, false);
if (boss.IsBoss) {
BTD6Rogue.rogueGame.roundManager.BossSpawned();
if (BTD6Rogue.rogueGame is not null)
{
if (bloonModel.isBoss || bloonModel.baseId.Contains("Lych") || bloonModel.IsRock)
{
RogueBoss boss = BossUtil.GetBossFromBloonId(bloonModel.baseId);
boss.AdjustBloon(__result, roundNumber / 20, false);
if (boss.IsBoss)
{
BTD6Rogue.rogueGame.roundManager.BossSpawned();
}
}
}

if (emissionIndex >= 5000) {
IncreaseBloonWorthModel.BloonWorthMutator bme = new IncreaseBloonWorthModel.BloonWorthMutator(
"CashlessBloon", 0, 0, "");
__result.AddMutator(bme, -1, false);
if (emissionIndex >= 5000)
{
IncreaseBloonWorthModel.BloonWorthMutator bme = new IncreaseBloonWorthModel.BloonWorthMutator(
"CashlessBloon", 0, 0, "");
__result.AddMutator(bme, -1, false);
}
}

if (bloonModel.isBoss) {
__instance.bossBloonManager.currentBoss = __result;
__instance.bossBloonManager.currentBossTier = Math.Min(((roundNumber + 1) / 20), 5);
if (bloonModel.isBoss)
{ //Todo: maybe don't do the BTD6Rogue-Boss UI in non BTD6Rogue GameModes?
__instance.bossBloonManager.currentBoss = __result;
__instance.bossBloonManager.currentBossTier = Math.Min(((roundNumber + 1) / 20), 5);
}

}
Expand All @@ -46,7 +54,8 @@ private static void Postfix(Spawner __instance, BloonModel bloonModel, int round
internal static class Spawner_Emasddsit {
[HarmonyPostfix]
private static void Postfix(SpawnChildren __instance, List<Bloon> childernCreatedIn) {
if (__instance.bloon.emissionIndex >= 5000) {
if (BTD6Rogue.rogueGame is null) { return; }
if (__instance.bloon.emissionIndex >= 5000) {
foreach (Bloon bloon in childernCreatedIn) {
IncreaseBloonWorthModel.BloonWorthMutator bme = new IncreaseBloonWorthModel.BloonWorthMutator(
"CashlessBloon", 0, 0, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ namespace BTD6Rogue;
[HarmonyPatch(typeof(TowerSelectionMenu), nameof(TowerSelectionMenu.IsUpgradePathClosed))]
internal static class TowerSelectionMenu_IsUpgradePathClosed {
[HarmonyPostfix]
private static void Postfix(TowerSelectionMenu __instance, int path, ref bool __result) {
private static void Postfix(TowerSelectionMenu __instance, int path, ref bool __result)
{
if (!InGame.instance.GetGameModel().gameMode.Contains("BTD6Rogue-")) { return; }

if (BTD6Rogue.rogueGame is null) { return; }

if (__instance.selectedTower == null) { return; }

Tower tower = __instance.selectedTower.tower;
Expand Down
Binary file added Resources/Buttons/UnknownHeroPortrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Buttons/UnknownParagonPortrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Buttons/UnknownTowerPortrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Buttons/UnknownTowerPortrait.xcf
Binary file not shown.
19 changes: 19 additions & 0 deletions Settings/RogueModSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using BTD_Mod_Helper.Api.Data;
using BTD_Mod_Helper.Api.ModOptions;
using BTD_Mod_Helper.Extensions;
using Il2CppAssets.Scripts.Unity.UI_New.Popups;

namespace BTD6Rogue;

Expand All @@ -12,4 +14,21 @@ public class RogueModSettings : ModSettings {
public static readonly ModSettingBool LogErrorMessages = new(true) { category = LoggingSettings };
public static readonly ModSettingBool LogCriticalMessages = new(true) { category = LoggingSettings };
public static readonly ModSettingBool LogDebugMessages = new(false) { category = LoggingSettings };


private static readonly ModSettingButton BloonValidationButton = new()
{
displayName = "Validate All RogueBloons",
description =
"Validates each RogueBloon to ensure it references existing Bloons in the GameModel. Logs warnings if invalid references are found. This is unnecessary if no new RogueBloons are being added by external mods.",
action = () =>
{
BloonValidation v = new();
v.ValidateAllRogueBloons();
PopupScreen.instance.SafelyQueue(screen =>
screen.ShowOkPopup($"Finished validating RogueBloons. Check the logs for details."));
},
buttonText = "Validate",
category = "Modding"
};
}
47 changes: 47 additions & 0 deletions Settings/ValdateBloon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Il2CppAssets.Scripts.Unity;

namespace BTD6Rogue
{
public class BloonValidation
{
public void ValidateRogueBloon(RogueBloon bloon)
{
string?[] arr = [bloon.BaseBloonId, null, null, null, null, null, null, null]; //
string[] brr = ["", "Camo", "Fortified", "FortifiedCamo", "Regrow", "RegrowCamo", "RegrowFortified", "RegrowFortifiedCamo"]; //Suffixes

if (bloon.Camo) { arr[1] = bloon.BaseBloonId + brr[1]; }
if (bloon.Fortified) { arr[2] = bloon.BaseBloonId + brr[2]; }
if (bloon.Camo && bloon.Fortified) { arr[3] = bloon.BaseBloonId + brr[3]; }
if (bloon.Regrow) { arr[4] = bloon.BaseBloonId + brr[4]; }
if (bloon.Regrow && bloon.Camo) { arr[5] = bloon.BaseBloonId + brr[5]; }
if (bloon.Regrow && bloon.Fortified) { arr[6] = bloon.BaseBloonId + brr[6]; }
if (bloon.Regrow && bloon.Fortified && bloon.Camo) { arr[7] = bloon.BaseBloonId + brr[7]; }

foreach (var j in arr) //Nullable string array
{
if (j is null) { continue; }
bool found = false;
foreach (var i in Game.instance.model.bloons) // Il2CppReferenceArray<BloonModel>
{
if (i.id == j)
{
found = true;
break; // Exit loop when a match is found
}
}
if (!found)
{
BTD6Rogue.LogMessage($"The {j} Bloon was not found. It may cause a crash ingame.", this, ErrorLevels.Warning);
}
}
}

public void ValidateAllRogueBloons()
{
foreach (var rogueBloon in BloonUtil.GetAllBloons())
{
ValidateRogueBloon(rogueBloon);
}
}
}
}
11 changes: 10 additions & 1 deletion Tower/Hero/HeroUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ public static List<RogueHero> GetEnabledRogueHeroes(RogueGame game) {
List<RogueHero> enabledTowers = new List<RogueHero>();

foreach (RogueHero tower in ModContent.GetContent<RogueHero>()) {
if (game.towerManager.disabledTowerSets.Contains(Il2CppAssets.Scripts.Models.TowerSets.TowerSet.Hero)) {
if (tower.GetBaseHero() is null)
{
BTD6Rogue.LogMessage("The RogueHero " + tower.Name + "'s BaseHeroId (" + tower.BaseHeroId + ") returns a null tower. They have been disabled.", tower, ErrorLevels.Error);
continue;
}
if (tower.GetBaseHero().towerSet != Il2CppAssets.Scripts.Models.TowerSets.TowerSet.Hero)
{
BTD6Rogue.LogMessage("The RogueTower " + tower.Name + "'s BaseTowerId (" + tower.BaseHeroId + ") returns a tower outside of the Hero TowerSet. This may cause issues.", tower, ErrorLevels.Warning);
}
if (game.towerManager.disabledTowerSets.Contains(Il2CppAssets.Scripts.Models.TowerSets.TowerSet.Hero)) {
continue;
}

Expand Down
6 changes: 4 additions & 2 deletions Tower/Hero/RogueHero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public abstract class RogueHero : NamedModContent {
public abstract string BaseHeroId { get; }

public virtual TowerModel GetBaseHero() {
return Game.instance.model.GetHeroWithNameAndLevel(BaseHeroId, 1);
}
return Game.instance.model.GetTowerFromId(BaseHeroId);

//return Game.instance.model.GetHeroWithNameAndLevel(BaseHeroId, 1);
}

public override void Register() {}
}
13 changes: 12 additions & 1 deletion Tower/Paragons/ParagonUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BTD_Mod_Helper.Api;
using Il2CppAssets.Scripts.Models.Towers;
using System;
using System.Collections.Generic;

Expand All @@ -10,7 +11,17 @@ public static List<RogueParagon> GetEnabledRogueParagons(RogueGame game) {
List<RogueParagon> enabledTowers = new List<RogueParagon>();

foreach (RogueParagon tower in ModContent.GetContent<RogueParagon>()) {
if (game.towerManager.disabledTowerSets.Contains(Il2CppAssets.Scripts.Models.TowerSets.TowerSet.Paragon)) {

if (tower.GetBaseTower() is null || tower.GetBaseParagon() is null)
{
BTD6Rogue.LogMessage("The RogueParagon " + tower.Name + "'s BaseTowerId (" + tower.BaseTowerId + ") returns a null tower.", tower, ErrorLevels.Error);
continue;
}
if (tower.GetBaseTower().towerSet == Il2CppAssets.Scripts.Models.TowerSets.TowerSet.Hero)
{
BTD6Rogue.LogMessage("The RogueParagon " + tower.Name + "'s BaseTowerId (" + tower.BaseTowerId + ") returns a tower in the Hero TowerSet. This may cause issues.", tower, ErrorLevels.Warning);
}
if (game.towerManager.disabledTowerSets.Contains(Il2CppAssets.Scripts.Models.TowerSets.TowerSet.Paragon)) {
continue;
}
if (game.towerManager.disabledTowerSets.Contains(tower.GetBaseTower().towerSet)) {
Expand Down
8 changes: 8 additions & 0 deletions Tower/Paragons/VanillaParagons/CrucibleOfSteelAndFlame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Il2CppAssets.Scripts.Models.Towers;

namespace BTD6Rogue;

public class ApexPlasmaMaster : RogueParagon {

Check failure on line 5 in Tower/Paragons/VanillaParagons/CrucibleOfSteelAndFlame.cs

View workflow job for this annotation

GitHub Actions / build

The namespace 'BTD6Rogue' already contains a definition for 'ApexPlasmaMaster'

Check failure on line 5 in Tower/Paragons/VanillaParagons/CrucibleOfSteelAndFlame.cs

View workflow job for this annotation

GitHub Actions / build

The namespace 'BTD6Rogue' already contains a definition for 'ApexPlasmaMaster'
public override string DisplayName => "Apex Plasma Master";
public override string BaseTowerId => TowerType.DartMonkey;
}
18 changes: 17 additions & 1 deletion Tower/TowerUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ public static List<RogueTower> GetEnabledRogueTowers(RogueGame game) {
List<RogueTower> enabledTowers = new List<RogueTower>();

foreach (RogueTower tower in ModContent.GetContent<RogueTower>()) {
if (game.towerManager.disabledTowerSets.Contains(tower.GetBaseTower().towerSet)) {
if (tower.GetBaseTower() is null)
{
BTD6Rogue.LogMessage("The RogueTower " + tower.Name + "'s BaseTowerId (" + tower.BaseTowerId + ") returns a null tower. It has been disabled.", tower, ErrorLevels.Error);
continue;
}

if (tower.GetBaseTower().towerSet == Il2CppAssets.Scripts.Models.TowerSets.TowerSet.Hero)
{
BTD6Rogue.LogMessage("The RogueTower " + tower.Name + "'s BaseTowerId (" + tower.BaseTowerId + ") returns a tower in the Hero TowerSet. This may cause issues.", tower, ErrorLevels.Warning);
}

if (tower.GetBaseTower().towerSet == Il2CppAssets.Scripts.Models.TowerSets.TowerSet.Paragon)
{
BTD6Rogue.LogMessage("The RogueTower " + tower.Name + "'s BaseTowerId (" + tower.BaseTowerId + ") returns a (base) tower in the Paragon TowerSet. This may cause issues.", tower, ErrorLevels.Warning);
}

if (game.towerManager.disabledTowerSets.Contains(tower.GetBaseTower().towerSet)) {
continue;
}

Expand Down

0 comments on commit 20e9004

Please sign in to comment.