Skip to content

Commit

Permalink
Merge branch 'preview'
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Aug 16, 2022
2 parents 1a58041 + ba9b283 commit f8fc6d0
Show file tree
Hide file tree
Showing 32 changed files with 350 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-net6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- '*'

env:
PROJECT_NAME: Btd6ModHelper
PROJECT_NAME: BloonsTD6 Mod Helper
CSPROJ: "./BloonsTD6 Mod Helper/BloonsTD6 Mod Helper.csproj"
BLOONSTD6: ./BloonsTD6
MELONLOADER_BRANCH: bootstrap-dotnet
Expand Down
1 change: 0 additions & 1 deletion BTD Mod Helper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Global
{E3CD0038-ADB1-4C15-970B-C9F72102F5D5}.Release|Any CPU.Build.0 = Release|Any CPU
{45CB0AF9-EB5F-4D6A-846C-830DD4F60B49}.BTD6_Release_net6|Any CPU.ActiveCfg = BTD6_Release_net6|Any CPU
{45CB0AF9-EB5F-4D6A-846C-830DD4F60B49}.BTD6_Debug_net6|Any CPU.ActiveCfg = BTD6_Debug_net6|Any CPU
{45CB0AF9-EB5F-4D6A-846C-830DD4F60B49}.BTD6_Debug_net6|Any CPU.Build.0 = BTD6_Debug_net6|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
46 changes: 41 additions & 5 deletions BloonsTD6 Mod Helper/Api/Components/ModBrowserMenuMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using Assets.Scripts.Unity.Menu;
using Assets.Scripts.Unity.UI_New.Popups;
using BTD_Mod_Helper.Api.Enums;
using BTD_Mod_Helper.Api.Helpers;
using BTD_Mod_Helper.UI.Menus;
Expand Down Expand Up @@ -30,6 +31,7 @@ internal class ModBrowserMenuMod : ModHelperPanel
public ModHelperImage Installed => GetDescendent<ModHelperImage>("Installed");
public ModHelperButton Star => GetDescendent<ModHelperButton>("Star");
public ModHelperText StarCount => GetDescendent<ModHelperText>("StarCount");
public ModHelperButton Verified => GetDescendent<ModHelperButton>("Verified");

public bool descriptionShowing;

Expand Down Expand Up @@ -76,19 +78,40 @@ public static ModBrowserMenuMod CreateTemplate()
Size = ModsMenu.ModIconSize
}, VanillaSprites.UISprite);

panel.AddText(new Info("Name")
var name = panel.AddText(new Info("Name")
{
Height = ModsMenu.ModNameHeight,
FlexWidth = 3
}, "Name", ModsMenu.FontMedium, TextAlignmentOptions.CaplineLeft);

}, "Name", ModsMenu.FontMedium, TextAlignmentOptions.MidlineLeft);
name.Text.enableAutoSizing = true;

panel.AddPanel(new Info("LackOfIconPanel", size: 200));

panel.AddText(new Info("Author")
var authorPanel = panel.AddPanel(new Info("AuthorPanel")
{
Height = ModsMenu.ModNameHeight,
FlexWidth = 3
FlexWidth = 2
});
var authorResizingPanel = authorPanel.AddPanel(new Info("AuthorResizingPanel")
{
Height = ModsMenu.ModNameHeight
}, null, RectTransform.Axis.Horizontal);

var contentSizeFitter = authorResizingPanel.AddComponent<ContentSizeFitter>();
contentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;

var authorText = authorResizingPanel.AddText(new Info("Author")
{
Height = ModsMenu.ModNameHeight
}, "Author", ModsMenu.FontMedium);
authorText.RemoveComponent<LayoutElement>();
var verified = authorText.AddButton(new Info("Verified", 75)
{
Anchor = new Vector2(1, 0.5f),
Pivot = new Vector2(0, 0.5f),
X = ModsMenu.Padding / 2f
}, VanillaSprites.VerifiedIcon, null);
verified.RemoveComponent<Animator>();

panel.AddText(new Info("Version")
{
Expand Down Expand Up @@ -162,6 +185,9 @@ public static void SetMod(this ModBrowserMenuMod mod, ModHelperData modHelperDat
mod.Author.SetText(modHelperData.DisplayAuthor);
mod.Author.Text.color = BlatantFavoritism.GetColor(modHelperData.RepoOwner);

mod.Icon.RectTransform.sizeDelta = modHelperData.SquareIcon
? new Vector2(ModsMenu.ModPanelHeight - 4, ModsMenu.ModPanelHeight - 4)
: new Vector2(ModsMenu.ModIconSize, ModsMenu.ModIconSize);
Task.Run(async () =>
{
var success = await modHelperData.LoadIconFromRepoAsync();
Expand Down Expand Up @@ -208,6 +234,16 @@ await ModHelperGithub.DownloadLatest(current, false, _ =>
mod.StarCount.SetText($"{modHelperData.Stars}{(string.IsNullOrEmpty(modHelperData.SubPath) ? "" : "+")}");
mod.Star.Button.SetOnClick(() => ProcessHelper.OpenURL(modHelperData.StarsUrl));

mod.Verified.SetActive(ModHelperGithub.VerifiedModders.Contains(modHelperData.RepoOwner));
var coolKidsClub = BlatantFavoritism.GetColor(modHelperData.RepoOwner) != Color.white;
mod.Verified.Button.SetOnClick(() => PopupScreen.instance.SafelyQueue(screen => screen.ShowOkPopup(
"This modder has been manually verified with the maintainers of BTD Mod Helper. " +
"Their work is trusted to not be unsafe, exploitative, obscene, or malicious. " +
(coolKidsClub
? " Additionally, the special color indicates they are a significant Mod Helper contributor."
: ""))
));
mod.Verified.Image.color = BlatantFavoritism.GetColor(modHelperData.RepoOwner);
mod.SetDescriptionShowing(false);

mod.SetActive(true);
Expand Down
3 changes: 3 additions & 0 deletions BloonsTD6 Mod Helper/Api/Components/ModsMenuMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public static void Refresh(this ModsMenuMod mod, ModHelperData modHelperData)
: Color.white;

mod.Icon.SetActive(!modHelperData.HasNoIcon);
mod.Icon.RectTransform.sizeDelta = modHelperData.SquareIcon
? new Vector2(ModsMenu.ModPanelHeight - 4, ModsMenu.ModPanelHeight - 4)
: new Vector2(ModsMenu.ModIconSize, ModsMenu.ModIconSize);
}

public static string GetBackground(ModHelperData data)
Expand Down
2 changes: 2 additions & 0 deletions BloonsTD6 Mod Helper/BloonsTD6 Mod Helper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

<PropertyGroup Condition="('$(Configuration)' == 'BTD6_Debug_net6') Or ('$(Configuration)' == 'BTD6_Release_net6')">
<TargetFramework>net6.0</TargetFramework>
<ProjectName>BloonsTD6 Mod Helper</ProjectName> <!--net6 needs old name still-->
<DocumentationFile>bin\BTD6_Debug_net6\BloonsTD6 Mod Helper.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net6.0'">
Expand Down
35 changes: 10 additions & 25 deletions BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
# Mod Helper 3.0 Update

A long time in the making, this update finishes the v32.0 fixes for Sprites / Displays and adds a ton of other stuff.

### What's most important to immediately know about installing this update is that it requires [MelonLoader v0.5.5](https://github.com/LavaGang/MelonLoader/suites/7738215183/artifacts/324586390). See the new [Install Guide](https://github.com/gurrenm3/BTD-Mod-Helper/wiki/Install-Guide) page for further details.

The most notable 3.0 addition is a revamped <u>Mods Menu</u> and new <u>In-Game Mod Browser</u>, which you can use to view and download mods updated for 3.0 that have been published on GitHub.
See the [3.0 Update Overview](https://github.com/gurrenm3/BTD-Mod-Helper/wiki/3.0-Update-Overview) page for a more comprehensive list of changes (there's a lot!).

For modders, I've put together a [3.0 Migration Guide](https://github.com/gurrenm3/BTD-Mod-Helper/wiki/%5B3.0%5D-Migration-Guide) page for information about how to best make use of the new features.


Note that this is not a universal fix for every mod broken by v32.0, many mods will still need to apply similar fixes to the ones done internally in Mod Helper before they'll be working again.

Also, this update has been in public alpha for a couple weeks now, but there still may need to be some hotfix updates within the days following this release. Luckily they'll be easily downloadable from right within your BTD6 game :D

Special thanks to Silentstorm, GrahamKracker, CommanderCat, and chrisroberts777 for doing as much testing as they did!

Hope everyone enjoys <3

-doombubbles

![Mods Menu](https://media.discordapp.net/attachments/800115046134186026/1007790104904998932/unknown.png)

![Mod Browser](https://media.discordapp.net/attachments/800115046134186026/1007790297025106040/unknown.png)
- Added the `SquareIcon` ModHelperData bool property to make the icon draw as constrained within panels rather than being allowed to slightly overflow
- Added an impossible to miss Popup for if you're not using a compatible MelonLoader version
- Added the ability to use a `<!--Mod Browser Message Start-->` markdown comment in release messages to only include information beyond a certain point
- Added checkmark icons for Verified Modders in the Mod Browser
- Fixed issue where Double Cash mode was doubling cash generation it wasn't supposed to
- Fixed Round Set Changer setting
- Fixed sporadic issue with backing out of a Mod Settings menu
- Fixed `OnMenuClosed()` still happening if you pressed Escape too early for the menu to actually close
- Fixed monorepo mods using ZipName without DllName not showing up in the Mod Browser
- Internally switched from `.parent =` to `SetParent` calls to avoid flooding the MelonLoader debug log
16 changes: 16 additions & 0 deletions BloonsTD6 Mod Helper/MelonMain.Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Helpers;
using BTD_Mod_Helper.Api.ModOptions;
using UnityEngine;
using static BTD_Mod_Helper.Api.Enums.VanillaSprites;

namespace BTD_Mod_Helper;
Expand Down Expand Up @@ -98,6 +99,9 @@ internal partial class MelonMain
min = 5,
max = 300,
stepSize = 1,
#if NET6_0
requiresRestart = true,
#endif
icon = DartTimeIcon
};

Expand All @@ -119,6 +123,9 @@ internal partial class MelonMain
min = .1,
max = 50,
stepSize = .1f,
#if NET6_0
requiresRestart = true,
#endif
icon = LocalNetworkIcon
};

Expand All @@ -130,6 +137,9 @@ internal partial class MelonMain
min = 1,
max = 1000,
stepSize = 1,
#if NET6_0
requiresRestart = true,
#endif
icon = LocalNetworkIcon
};

Expand Down Expand Up @@ -257,5 +267,11 @@ internal partial class MelonMain
buttonText = "Generate"
};

private static readonly ModSettingHotkey ExportSelectedTower = new(KeyCode.Backslash)
{
category = Debug,
description = "While in game, exports the exact TowerModel being used by the selected tower."
};

#endregion
}
37 changes: 32 additions & 5 deletions BloonsTD6 Mod Helper/MelonMain.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Assets.Scripts.Models.TowerSets.Mods;
using Assets.Scripts.Simulation;
using Assets.Scripts.Simulation.Towers;
using Assets.Scripts.Unity;
using Assets.Scripts.Unity.UI_New.InGame;
using Assets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
using Assets.Scripts.Unity.UI_New.Popups;
using BTD_Mod_Helper;
using BTD_Mod_Helper.Api;
Expand All @@ -30,7 +34,7 @@ public override void OnApplicationStart()

// Mod Settings
ModSettingsHandler.InitializeModSettings();

try
{
ModHelperHttp.Init();
Expand All @@ -49,8 +53,8 @@ public override void OnApplicationStart()

// Utility to patch all valid UI "Open" methods for custom UI
ModGameMenu.PatchAllTheOpens(HarmonyInstance);


Schedule_GameModel_Loaded();

try
Expand All @@ -70,6 +74,20 @@ public override void OnApplicationStart()

public override void OnUpdate()
{
if (!MelonLoaderChecker.IsVersionNewEnough())
{
if (PopupScreen.instance != null && !PopupScreen.instance.IsPopupActive())
{
PopupScreen.instance.ShowPopup(PopupScreen.Placement.menuCenter, "Not On MelonLoader 0.5.5",
"Mod Helper failed to load. Not On MelonLoader 0.5.5. Click ok to be taken to a page with more information.",
new Action(() =>
{
ProcessHelper.OpenURL("https://github.com/gurrenm3/BTD-Mod-Helper/wiki/Install-Guide");
}), "Ok", null, "Cancel", Popup.TransitionAnim.Scale, instantClose: true);
}
return;
}

ModByteLoader.OnUpdate();

if (Game.instance is null)
Expand All @@ -85,6 +103,15 @@ public override void OnUpdate()

NotificationMgr.CheckForNotifications();
RoundSetChanger.EnsureHidden();

#if BTD6_DEBUG
if (TowerSelectionMenu.instance != null &&
TowerSelectionMenu.instance.selectedTower != null &&
ExportSelectedTower.JustPressed())
{
GameModelExporter.Export(TowerSelectionMenu.instance.selectedTower.tower.towerModel, "selected_tower.json");
}
#endif
}

public override void OnTitleScreen()
Expand All @@ -98,7 +125,7 @@ public override void OnTitleScreen()
if (!scheduledInGamePatch) Schedule_InGame_Loaded();

AutoSave.InitAutosave(this.GetModSettingsDir(true));

foreach (var gameMode in Game.instance.model.mods)
{
if (gameMode.name.EndsWith("Only"))
Expand All @@ -109,7 +136,7 @@ public override void OnTitleScreen()
.Select(set => new LockTowerSetModModel(gameMode.name, set.Id)));
gameMode.mutatorMods = mutatorModModels.ToIl2CppReferenceArray();
}

if (gameMode.mutatorMods == null) continue;

foreach (var mutatorMod in gameMode.mutatorMods)
Expand Down
15 changes: 9 additions & 6 deletions BloonsTD6 Mod Helper/Patches/AudioFactory_Start.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Assets.Scripts.Unity.Audio;

namespace BTD_Mod_Helper.Patches{
[HarmonyPatch(typeof(AudioFactory),"Start")]
internal class AudioFactory_Start{
namespace BTD_Mod_Helper.Patches
{
[HarmonyPatch(typeof(AudioFactory), "Start")]
internal class AudioFactory_Start
{
[HarmonyPostfix]
public static void Postfix(AudioFactory __instance){
ModHelper.PerformHook(mod=>mod.OnAudioFactoryStart(__instance));
public static void Postfix(AudioFactory __instance)
{
ModHelper.PerformHook(mod => mod.OnAudioFactoryStart(__instance));
}
}
}
}

This file was deleted.

6 changes: 2 additions & 4 deletions BloonsTD6 Mod Helper/Patches/Main_GetInitialLoadTasks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Assets.Scripts.Unity.Tasks;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Helpers;
using Il2CppSystem.Collections.Generic;
using UnhollowerBaseLib;
using Main = Assets.Main.Main;
Expand All @@ -21,10 +22,7 @@ internal static class Main_GetInitialLoadTasks
[HarmonyPostfix]
private static void Postfix(ref SeriesTasks __result)
{
if (ModHelper.FallbackToOldLoading)
{
return;
}
if (ModHelper.FallbackToOldLoading || !MelonLoaderChecker.IsVersionNewEnough()) return;

var tasks = __result.Tasks.Cast<Il2CppReferenceArray<ITask>>().ToList();
var gameModelLoad = tasks.Last();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Helpers;
using NinjaKiwi.Common;

namespace BTD_Mod_Helper.Patches.Resources;
Expand All @@ -11,6 +12,8 @@ internal static class LocalizationManger_LoadTableAsync
[HarmonyPostfix]
private static void Postfix(LocalizationManager._LoadTableAsync_d__45 __instance)
{
if (!MelonLoaderChecker.IsVersionNewEnough()) return;

var result = __instance.__t__builder.Task.Result;
if (result != null)
{
Expand Down
Loading

0 comments on commit f8fc6d0

Please sign in to comment.