Skip to content

Commit

Permalink
Update for 39.0
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Oct 10, 2023
1 parent af181fe commit f8284ca
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 76 deletions.
5 changes: 3 additions & 2 deletions BloonsTD6 Mod Helper/Api/Helpers/FileIOHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Il2CppNewtonsoft.Json;
using Il2CppSystem;
using Il2CppSystem.IO;
using UnityEngine;
using Directory = System.IO.Directory;
Expand Down Expand Up @@ -34,8 +35,8 @@ public static void SaveObject(string fileName, Object data)
var text = JsonConvert.SerializeObject(data, new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
TypeNameHandling = TypeNameHandling.Objects
TypeNameHandling = TypeNameHandling.Objects,
_referenceLoopHandling = new Nullable<ReferenceLoopHandling> {value = ReferenceLoopHandling.Ignore}
});

SaveFile(fileName, text);
Expand Down
2 changes: 1 addition & 1 deletion BloonsTD6 Mod Helper/Api/Towers/ModHero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ internal override string TowerId(int[] tiers)
/// Gets the font material for the default SkinData
/// </summary>
/// <param name="skinsByName">Existing hero skins by their skin/tower name</param>
public virtual Material GetFontMaterial(Dictionary<string, SkinData> skinsByName) =>
public virtual string GetFontMaterial(Dictionary<string, SkinData> skinsByName) =>
skinsByName.TryGetValue(NameStyle, out var dataForFont)
? dataForFont.fontMaterial
: skinsByName[TowerType.Quincy].fontMaterial;
Expand Down
5 changes: 4 additions & 1 deletion BloonsTD6 Mod Helper/Api/UI/ModGameMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Il2CppAssets.Scripts.Unity.UI_New.Coop;
using Il2CppAssets.Scripts.Unity.UI_New.GameEvents;
using Il2CppAssets.Scripts.Unity.UI_New.HeroInGame;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.EditorMenus;
using Il2CppAssets.Scripts.Unity.UI_New.LevelUp;
using Il2CppAssets.Scripts.Unity.UI_New.Main.PowersSelect;
using Il2CppAssets.Scripts.Unity.UI_New.Settings;
Expand Down Expand Up @@ -38,7 +39,9 @@ public abstract class ModGameMenu : ModContent
{typeof(GameEventsScreen), SceneNames.GameEventsUI},
{typeof(HeroInGameScreen), SceneNames.HeroInGameUI},
{typeof(LevelUpScreen), SceneNames.LevelUpUI},
{typeof(ContentBrowser), SceneNames.ContentBrowser}
{typeof(ContentBrowser), SceneNames.ContentBrowser},
{typeof(MapEditorScreen), SceneNames.MapEditorUI},
{typeof(ChallengeEditorPlay), SceneNames.ChallengeEditorPlay}
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ public static IEnumerable<Tower> GetTowersInRange(this Tower tower)
/// </summary>
/// <returns></returns>
public static MonkeyAnimationController GetMonkeyAnimController(this Tower tower) =>
tower.GetUnityDisplayNode()?.monkeyAnimationController;
tower.GetUnityDisplayNode()?.animationController.TryCast<MonkeyAnimationController>();
}
4 changes: 4 additions & 0 deletions BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- Fixes for v39
- Due to the new Community Button, the Round Set Changer button now only appears while selecting the dificulty/mode for a map
- Fixed ModHero font name material reference
- Fixed JSON settings
- Added setting to toggle Mod Browser Populating on Startup
- From my personal testing, this leads to ~1s faster startup on average, in exchange for waiting 5s - 10s when you
first open the browser
Expand Down
1 change: 1 addition & 0 deletions BloonsTD6 Mod Helper/MelonMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public override void OnInitialize()
public override void OnUpdate()
{
ModByteLoader.OnUpdate();
RoundSetChanger.OnUpdate();
// InitialLoadTasks_MoveNext.Update();

if (Game.instance is null || InGame.instance is null)
Expand Down
2 changes: 1 addition & 1 deletion BloonsTD6 Mod Helper/ModHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace BTD_Mod_Helper;
public static class ModHelper
{
internal const string Name = "BloonsTD6 Mod Helper";
internal const string Version = "3.1.14";
internal const string Version = "3.1.15";
internal const string RepoOwner = "gurrenm3";
internal const string RepoName = "BTD-Mod-Helper";
internal const string Description =
Expand Down
13 changes: 2 additions & 11 deletions BloonsTD6 Mod Helper/Patches/Towers/TowerCreateTower_OnDestroy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,9 @@ internal static class TowerCreateTower_OnDestroy
[HarmonyPrefix]
private static void Prefix(TowerCreateTower __instance)
{
if (__instance.towerAdded && !__instance.tower.IsDestroyed)
if (__instance.tower is {IsDestroyed: false} && __instance.createdTower is {IsDestroyed: false})
{
var baseId = __instance.createTowerModel.towerModel.baseId;
var tower = __instance.Sim.towerManager
.GetChildTowers(__instance.tower)
.ToList()
.OrderBy(t => t.createdAt)
.FirstOrDefault(tower => tower.towerModel.baseId == baseId);
if (tower != null)
{
__instance.Sim.DestroyTower(tower, tower.owner);
}
__instance.Sim.DestroyTower(__instance.createdTower, __instance.createdTower.owner);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Il2CppAssets.Scripts.Unity.Menu;
namespace BTD_Mod_Helper.Patches.UI;

[HarmonyPatch(typeof(MenuManager), nameof(MenuManager.CloseCurrentMenuIfPossible))]
[HarmonyPatch(typeof(MenuManager), nameof(MenuManager.CloseCurrentMenu))]
internal static class MenuManager_CloseCurrentMenu
{
[HarmonyPrefix]
Expand All @@ -26,7 +26,6 @@ private static void Postfix(MenuManager __instance, ref GameMenu __state)
modGameMenu.OnMenuClosed();
}

RoundSetChanger.OnMenuChanged(__state.Exists()?.name ?? "",
__instance.menuStack.ToList().SkipLast(1).LastOrDefault()?.Item1 ?? "");
// RoundSetChanger.OnMenuChanged(__state.Exists()?.name ?? "", __instance.menuStack.ToList().SkipLast(1).LastOrDefault()?.Item1 ?? "");
}
}
2 changes: 1 addition & 1 deletion BloonsTD6 Mod Helper/Patches/UI/MenuManager_OpenMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ internal static class MenuManager_OpenMenu
[HarmonyPrefix]
private static void Prefix(MenuManager __instance, string menuName)
{
RoundSetChanger.OnMenuChanged(__instance.GetCurrentMenu().Exists()?.name ?? "", menuName);
// RoundSetChanger.OnMenuChanged(__instance.GetCurrentMenu().Exists()?.name ?? "", menuName);
}
}
37 changes: 0 additions & 37 deletions BloonsTD6 Mod Helper/UI/BTD6/EmbeddedBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,43 +178,6 @@ private static bool Prefix(HtmlSurface __instance, HTML_FileOpenDialog_t callbac
#endregion*/

/// <summary>
/// Implement JS alerts using Ok popups
/// </summary>
[HarmonyPatch(typeof(HtmlSurface), nameof(HtmlSurface.OnJSAlertAPI))]
internal static class HtmlSurface_OnJSAlertAPI
{
[HarmonyPrefix]
private static bool Prefix(HtmlSurface __instance, HTML_JSAlert_t callbackdata)
{
var nativeHtmlSurface = __instance.client.native.htmlSurface;

PopupScreen.instance.SafelyQueue(screen => screen.ShowOkPopup(callbackdata.PchMessage,
new Action(() => nativeHtmlSurface.JSDialogResponse(callbackdata.UnBrowserHandle, true))));
return false;
}
}

/// <summary>
/// Implement JS confirms using Ok/Cancel popups
/// </summary>
[HarmonyPatch(typeof(HtmlSurface), nameof(HtmlSurface.OnJSConfirmAPI))]
internal static class HtmlSurface_OnJSConfirmAPI
{
[HarmonyPrefix]
private static bool Prefix(HtmlSurface __instance, HTML_JSConfirm_t callbackdata)
{
var nativeHtmlSurface = __instance.client.native.htmlSurface;

PopupScreen.instance.SafelyQueue(screen =>
screen.ShowPopup(PopupScreen.Placement.menuCenter, "Confirm", callbackdata.PchMessage,
new Action(() => nativeHtmlSurface.JSDialogResponse(callbackdata.UnBrowserHandle, true)), "Ok",
new Action(() => nativeHtmlSurface.JSDialogResponse(callbackdata.UnBrowserHandle, false)), "Cancel",
Popup.TransitionAnim.Scale));
return false;
}
}

/// <summary>
/// Allow mod files to be downloaded through the browser
/// </summary>
Expand Down
39 changes: 36 additions & 3 deletions BloonsTD6 Mod Helper/UI/Modded/RoundSetChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using BTD_Mod_Helper.Api.Bloons;
using BTD_Mod_Helper.Api.Components;
using BTD_Mod_Helper.Api.Enums;
using Il2CppAssets.Scripts;
using Il2CppAssets.Scripts.Unity.Menu;
using Il2CppAssets.Scripts.Unity.UI_New;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using Il2CppAssets.Scripts.Unity.UI_New.Main.Facebook;
using Il2CppAssets.Scripts.Unity.UI_New.Main.MapSelect;
using UnityEngine;
Expand All @@ -24,8 +26,8 @@ public static class RoundSetChanger // TODO make this internal, add alt way to g

private static readonly string[] ShowOnMenus =
{
"MapSelectUI", "DifficultySelectUI", "ModeSelectUI",
"MapSelectScreen", "DifficultySelectScreen", "ModeSelectScreen"
"DifficultySelectUI", "ModeSelectUI",
"DifficultySelectScreen", "ModeSelectScreen"
};

private static ModHelperPanel buttonPanel;
Expand All @@ -36,6 +38,8 @@ public static class RoundSetChanger // TODO make this internal, add alt way to g

private static ModHelperPanel invisibleCancel;

private static bool lastShowing;

/// <summary>
/// The round set override currently chosen, or null
/// </summary>
Expand Down Expand Up @@ -204,13 +208,15 @@ private static void Show()
Init();
RevealButton();
optionsPanel.SetActive(false);
lastShowing = true;
}

private static void Hide()
{
Init();
HideButton();
HideOptions();
lastShowing = false;
}

internal static void EnsureHidden()
Expand All @@ -224,11 +230,38 @@ internal static void EnsureHidden()
{
optionsPanel.SetActive(false);
}

lastShowing = false;
}

internal static void OnUpdate()
{
if (!MelonMain.ShowRoundsetChanger || MenuManager.instance == null) return;

if (InGame.instance != null)
{
EnsureHidden();
return;
}

var shouldShow = ShowOnMenus.Contains(MenuManager.instance.GetCurrentMenuName());

if (shouldShow != lastShowing)
{
if (shouldShow)
{
Show();
ModifyBlockClicks();
}
else
{
Hide();
}
}
}

internal static void OnMenuChanged(string currentMenu, string newMenu)
{
if (!MelonMain.ShowRoundsetChanger) return;

if (ShowOnMenus.Contains(newMenu))
{
Expand Down
15 changes: 0 additions & 15 deletions Shared/ModHelper.cs

This file was deleted.

0 comments on commit f8284ca

Please sign in to comment.