Skip to content

Commit

Permalink
Improve some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Aug 8, 2024
1 parent d1a2ef0 commit b8b8427
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
6 changes: 5 additions & 1 deletion BloonsTD6 Mod Helper/BloonsMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,12 @@ public void ApplyHarmonyPatches(Type type)
}
catch (Exception e)
{
var message = e.InnerException?.Message ?? e.Message;

if (ModHelper.IsEpic && message.Contains("Il2CppFacepunch.Steamworks")) return;

MelonLogger.Warning(
$"Failed to apply {Info.Name} patch(es) in {type.Name}: \"{e.InnerException?.Message ?? e.Message}\" " +
$"Failed to apply {Info.Name} patch(es) in {type.Name}: \"{message}\" " +
$"The mod might not function correctly. This needs to be fixed by {Info.Author}");

loadErrors.Add($"Failed to apply patch(es) in {type.Name}");
Expand Down
4 changes: 3 additions & 1 deletion BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
- Removed a no longer needed patch that had side effects with X/3+/X Mermonkey damage calculations
- An error indicator will now show on the main menu Mods Button if any mods have load errors
- Added a new load error for not being on MelonLoader 0.6.1
- Fixed unneeded errors on Epic about Il2CppFacepunch.Steamworks
10 changes: 8 additions & 2 deletions BloonsTD6 Mod Helper/MelonMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
using Il2CppAssets.Scripts.Data;
using Il2CppAssets.Scripts.Unity;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
using MelonLoader.Utils;
using Newtonsoft.Json.Linq;
using TaskScheduler = BTD_Mod_Helper.Api.TaskScheduler;
[assembly: MelonInfo(typeof(MelonMain), ModHelper.Name, ModHelper.Version, ModHelper.Author)]
[assembly: MelonGame("Ninja Kiwi", "BloonsTD6")]
[assembly: MelonGame("Ninja Kiwi", "BloonsTD6-Epic")]
[assembly: MelonPriority(-1000)]
[assembly: MelonOptionalDependencies("NAudio.WinMM", "NAudio.Wasapi")] // Avoids the warning about these not getting ILRepacked; they're not needed
[assembly: MelonOptionalDependencies("NAudio.WinMM", "NAudio.Wasapi", "Il2CppFacepunch.Steamworks")]

namespace BTD_Mod_Helper;

Expand Down Expand Up @@ -78,6 +78,12 @@ public override void OnInitialize()
{
HarmonyInstance.CreateClassProcessor(typeof(EmbeddedBrowser.SteamWebView_OnGUI), true).Patch();
}

if (typeof(MelonEnvironment).Assembly.GetName().Version is {Minor: 6, Build: > 1})
{
loadErrors.Add("MelonLoader versions higher than 0.6.1 are not yet considered stable for BloonsTD6. " +
"Please downgrade to MelonLoader 0.6.1 via its installer for best results.");
}
}

public override void OnUpdate()
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 @@ -16,7 +16,7 @@ namespace BTD_Mod_Helper;
public static class ModHelper
{
internal const string Name = "BloonsTD6 Mod Helper";
internal const string Version = "3.1.24";
internal const string Version = "3.1.25";
internal const string RepoOwner = "gurrenm3";
internal const string RepoName = "BTD-Mod-Helper";
internal const string Description =
Expand Down
7 changes: 7 additions & 0 deletions BloonsTD6 Mod Helper/UI/Modded/ModsButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public static void Create(MainMenu mainMenu)
indicator.Find("Glow").GetComponent<Image>().color = Color.green;
indicator.Find("Icon").GetComponent<Image>().SetSprite(VanillaSprites.UpgradeBtn);

var error = indicator.gameObject.Duplicate(indicator.parent);
error.transform.localPosition = error.transform.localPosition with {x = error.transform.localPosition.x * -1};
error.gameObject.SetActive(ModHelper.Mods.Any(mod => mod.loadErrors.Any()));
error.transform.Find("Glow").gameObject.SetActive(false);
error.transform.Find("Icon").GetComponent<Image>().SetSprite(VanillaSprites.NoticeBtn);
error.GetComponentInChildren<CustomScaleAnimator>().enabled = false;

var matchLocalPosition = modsButton.transform.GetChild(0).gameObject.AddComponent<MatchLocalPosition>();
matchLocalPosition.transformToCopy = copyLocalFrom.transform.GetChild(0);

Expand Down
27 changes: 27 additions & 0 deletions Documentation/BTD_Mod_Helper.Extensions.StringExt.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ public static class StringExt
Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.Object 'System.Object') &#129106; StringExt
### Methods

<a name='BTD_Mod_Helper.Extensions.StringExt.GetBtd6Localization(thisstring,bool)'></a>

## StringExt.GetBtd6Localization(this string, bool) Method

Gets the localization from the current localization text table, or the default one if it's not present in the current one.
If the id is not present in any of these, returned as spaced or not spaced depending on parameters.

```csharp
public static string GetBtd6Localization(this string id, bool returnAsSpacedIfNoEntry=true);
```
#### Parameters

<a name='BTD_Mod_Helper.Extensions.StringExt.GetBtd6Localization(thisstring,bool).id'></a>

`id` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')

The ID of the thing you're trying to get the localization of.

<a name='BTD_Mod_Helper.Extensions.StringExt.GetBtd6Localization(thisstring,bool).returnAsSpacedIfNoEntry'></a>

`returnAsSpacedIfNoEntry` [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean')

Should this return the id with spaces if there's no localization present?

#### Returns
[System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')

<a name='BTD_Mod_Helper.Extensions.StringExt.NullIfEmpty(thisstring)'></a>

## StringExt.NullIfEmpty(this string) Method
Expand Down

0 comments on commit b8b8427

Please sign in to comment.