Skip to content

Commit

Permalink
Initial fixes for v33.0
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Oct 12, 2022
1 parent 9e3cfeb commit 5848712
Show file tree
Hide file tree
Showing 21 changed files with 239 additions and 67 deletions.
15 changes: 8 additions & 7 deletions BloonsTD6 Mod Helper/Api/Helpers/GameModelExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ internal static void ExportAll()
)
};

Directory.CreateDirectory(Path.Combine(FileIOUtil.sandboxRoot, "Skins", data.baseTowerName));
Directory.CreateDirectory(Path.Combine(FileIOHelper.sandboxRoot, "Skins", data.baseTowerName));
var path = $"Skins/{data.baseTowerName}/{data.name}.json";
File.WriteAllText(Path.Combine(FileIOUtil.sandboxRoot, path), jobject.ToString(Formatting.Indented));
ModHelper.Log("Saving " + FileIOUtil.sandboxRoot + path);
File.WriteAllText(Path.Combine(FileIOHelper.sandboxRoot, path), jobject.ToString(Formatting.Indented));
ModHelper.Log("Saving " + FileIOHelper.sandboxRoot + path);
});
}

Expand All @@ -110,12 +110,13 @@ public static void Export(Il2CppSystem.Object data, string path)
{
try
{
FileIOUtil.SaveObject(path, data);
ModHelper.Log("Saving " + Path.Combine(FileIOUtil.sandboxRoot, path));
FileIOHelper.SaveObject(path, data);
ModHelper.Log("Saving " + Path.Combine(FileIOHelper.sandboxRoot, path));
}
catch (Exception)
catch (Exception e)
{
ModHelper.Error("Failed to save " + Path.Combine(FileIOUtil.sandboxRoot, path));
ModHelper.Error("Failed to save " + Path.Combine(FileIOHelper.sandboxRoot, path));
ModHelper.Warning(e);
}
}
}
3 changes: 2 additions & 1 deletion BloonsTD6 Mod Helper/Api/ModByteLoader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using Assets.Scripts.Utils;
using BTD_Mod_Helper.Api.Helpers;
using Exception = System.Exception;
using Object = Il2CppSystem.Object;

Expand All @@ -19,7 +20,7 @@ public static void Generate<T>(T model, string loaderFilePath, string bytesFileP
{
Directory.CreateDirectory(ModHelper.ReplacedFilesDirectory);

var unconvertedLoader = $"{FileIOUtil.sandboxRoot}UnconvertedLoader.cs";
var unconvertedLoader = $"{FileIOHelper.sandboxRoot}UnconvertedLoader.cs";

var loaderName = Path.GetFileNameWithoutExtension(loaderFilePath);
var bytesFileName = Path.GetFileName(bytesFilePath);
Expand Down
4 changes: 4 additions & 0 deletions BloonsTD6 Mod Helper/Api/ModContentTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ internal class ModContentTask : ModLoadTask
/// </summary>
public override IEnumerator Coroutine()
{
if (ModHelper.FallbackToOldLoading)
{
ModHelper.Log(DisplayName);
}
var current = 0f;
foreach (var modContent in mod.Content)
{
Expand Down
4 changes: 2 additions & 2 deletions BloonsTD6 Mod Helper/Api/ModLoadTask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Assets.Scripts.Unity.Tasks;
/*using Assets.Scripts.Unity.Tasks;
namespace BTD_Mod_Helper.Api;
Expand All @@ -11,4 +11,4 @@ internal ITask CreateTask()
Cache[action.GetHashCode()] = this;
return new Task(DisplayName, action).Cast<ITask>();
}
}
}*/
11 changes: 1 addition & 10 deletions BloonsTD6 Mod Helper/Api/Towers/ModHero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,6 @@ internal override string TowerId(int[] tiers)
[Obsolete("No longer required to manually specify")]
public virtual int Abilities { get; }

/// <summary>
/// Modifies the HeroSprite used in the Heroes menu. Will already have modified the font/banner/color using
/// <see cref="NameStyle"/>, <see cref="GlowStyle"/> and <see cref="BackgroundStyle"/> at this point.
/// </summary>
/// <param name="heroSprite">The HeroSprite to modify</param>
public virtual void ModifyHeroSprite(HeroSprite heroSprite)
{
}

/// <summary>
/// Gets the font material for the default SkinData
/// </summary>
Expand All @@ -222,7 +213,7 @@ public virtual Material GetFontMaterial(Dictionary<string, SkinData> skinsByName
/// Gets the Background Banner for the default SkinData
/// </summary>
/// <param name="skinsByName">Existing hero skins by their skin/tower name</param>
public virtual GameObject GetBackgroundBanner(Dictionary<string, SkinData> skinsByName) =>
public virtual PrefabReference GetBackgroundBanner(Dictionary<string, SkinData> skinsByName) =>
skinsByName.TryGetValue(GlowStyle, out var dataForFont)
? dataForFont.backgroundBanner
: skinsByName[TowerType.Quincy].backgroundBanner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Assets.Scripts.Unity.Display;
using Assets.Scripts.Utils;
using System.IO;
using BTD_Mod_Helper.Api.Helpers;
using UnityEngine;

namespace BTD_Mod_Helper.Extensions;
Expand All @@ -16,17 +17,17 @@ public static partial class DumpNodeExt
/// </summary>
public static void Dump(this UnityDisplayNode node)
{
if (!Directory.Exists($"{FileIOUtil.sandboxRoot}DumpedTextures/"))
if (!Directory.Exists($"{FileIOHelper.sandboxRoot}DumpedTextures/"))
{
Directory.CreateDirectory($"{FileIOUtil.sandboxRoot}DumpedTextures/");
Directory.CreateDirectory($"{FileIOHelper.sandboxRoot}DumpedTextures/");
}
foreach (var item in node.genericRenderers)
{
if (item.materials.Length > 0)
{
if (item.material.mainTexture)
{
item.material.mainTexture.TrySaveToPNG($"{FileIOUtil.sandboxRoot}DumpedTextures/{item.material.mainTexture.name}.png");
item.material.mainTexture.TrySaveToPNG($"{FileIOHelper.sandboxRoot}DumpedTextures/{item.material.mainTexture.name}.png");
}
}
}
Expand All @@ -35,7 +36,7 @@ public static void Dump(this UnityDisplayNode node)
{
foreach (var spriteRenderer in node.gameObject.GetComponentsInChildren<SpriteRenderer>())
{
spriteRenderer.sprite.texture.TrySaveToPNG($"{FileIOUtil.sandboxRoot}DumpedTextures/{spriteRenderer.sprite.texture.name}.png");
spriteRenderer.sprite.texture.TrySaveToPNG($"{FileIOHelper.sandboxRoot}DumpedTextures/{spriteRenderer.sprite.texture.name}.png");
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
- Updated for the official MelonLoader v0.5.5 release
Initial Fixes for BloonsTD6 v33.0

Use this version of the mod alongside the MelonLoader 0.5.5 you get from the official installer, not the github actions / nightly builds that have been linked previously.
- Added the `FileIOHelper` class that replicates the methods of `FileIOUtil` that've been removed in v33.0
- Fixed the try-catching of Harmony Patches that wasn't working correctly on official release ML 0.5.5.
- **Reverted to the old loading system** until I update our custom load tasks to the new way NK is doing it internally
- This means we're temporarily going back to freezing after Step 8 of 8 to wait for mods to load rather than having our
own steps

Also as a PSA about MelonLoader, if things ever seem TOO frozen on Step 8 of 8, with no more log messages appearing,
check that you haven't accidentally clicked into the console as below, as that can stall things

![console clicking infographic](https://media.discordapp.net/attachments/800115046134186026/1029864079873032253/unknown.png)
4 changes: 2 additions & 2 deletions BloonsTD6 Mod Helper/MelonMain.Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ internal partial class MelonMain
private static readonly ModSettingButton OpenLocalDirectory = new()
{
displayName = "Open Local Files Directory",
action = () => Process.Start(FileIOUtil.sandboxRoot),
action = () => Process.Start(FileIOHelper.sandboxRoot),
buttonText = "Open",
description =
"This is the 'Sandbox Root' directory that many vanilla and modded services use to dump files into.",
Expand All @@ -177,7 +177,7 @@ internal partial class MelonMain
{
GameModelExporter.ExportAll();
PopupScreen.instance.SafelyQueue(screen =>
screen.ShowOkPopup($"Finished exporting Game Model to {FileIOUtil.sandboxRoot}"));
screen.ShowOkPopup($"Finished exporting Game Model to {FileIOHelper.sandboxRoot}"));
},
buttonText = "Export",
category = ModMaking,
Expand Down
4 changes: 3 additions & 1 deletion BloonsTD6 Mod Helper/Patches/GameModel_CreateModded.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Assets.Scripts.Data.Knowledge;
using Assets.Scripts.Models;
using Assets.Scripts.Models.Bloons;
using Assets.Scripts.Models.Towers;
Expand All @@ -15,7 +16,8 @@

namespace BTD_Mod_Helper.Patches;

[HarmonyPatch(typeof(GameModel), nameof(GameModel.CreateModded), typeof(GameModel), typeof(List<ModModel>))]
[HarmonyPatch(typeof(GameModel), nameof(GameModel.CreateModded), typeof(GameModel), typeof(List<ModModel>),
typeof(List<RelicKnowledgeItemBase>))]
internal class GameModel_CreateModded
{
[HarmonyPrefix]
Expand Down
5 changes: 2 additions & 3 deletions BloonsTD6 Mod Helper/Patches/Main_GetInitialLoadTasks.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using Assets.Scripts.Unity.Tasks;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Helpers;
using Il2CppSystem.Collections.Generic;
Expand All @@ -8,7 +7,7 @@

namespace BTD_Mod_Helper.Patches;

[HarmonyPatch(typeof(Main), nameof(Main.GetInitialLoadTasks))]
/*[HarmonyPatch(typeof(Main), nameof(Main))]
internal static class Main_GetInitialLoadTasks
{
/// <summary>
Expand Down Expand Up @@ -50,4 +49,4 @@ private static void Postfix(ref SeriesTasks __result)
__result.Tasks = new SeriesTasks(tasks.ToArray()).Cast<IEnumerable<ITask>>();
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Assets.Scripts.Unity.Tasks;
/*using Assets.Scripts.Unity.Tasks;
using BTD_Mod_Helper.Api;
namespace BTD_Mod_Helper.Patches.Resources;
Expand Down Expand Up @@ -29,4 +29,4 @@ private static bool Prefix(Task._EnumerateAction_d__11 __instance, ref bool __re
return true;
}
}
}*/
1 change: 1 addition & 0 deletions BloonsTD6 Mod Helper/btd6.targets
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Reference Include="$(ManagedFolder)\UnityEngine.UIModule.dll"/>
<Reference Include="$(ManagedFolder)\Newtonsoft.Json.dll"/>
<Reference Include="$(ManagedFolder)\Unity.Addressables.dll"/>
<Reference Include="$(ManagedFolder)\Il2CppNewtonsoft.Json.dll"/>
</ItemGroup>

<!--Mod Helper dependency-->
Expand Down
109 changes: 109 additions & 0 deletions Documentation/BTD_Mod_Helper.Api.Helpers.FileIOHelper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#### [BloonsTD6 Mod Helper](README.md 'README')
### [BTD_Mod_Helper.Api.Helpers](README.md#BTD_Mod_Helper.Api.Helpers 'BTD_Mod_Helper.Api.Helpers')

## FileIOHelper Class

Class replacing the original functionality of FileIOUtil before BTD6 update 33.0

```csharp
public static class FileIOHelper
```

Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.Object 'System.Object') &#129106; FileIOHelper
### Properties

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.sandboxRoot'></a>

## FileIOHelper.sandboxRoot Property

Same as the original FileIOUtil.sandboxRoot, INCLUDES A SLASH AT THE END

```csharp
public static string sandboxRoot { get; }
```

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

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.GetSandboxPath()'></a>

## FileIOHelper.GetSandboxPath() Method

Same as the original FileIOUtil.GetSandboxPath(), INCLUDES A SLASH AT THE END

```csharp
public static string GetSandboxPath();
```

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

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.LoadFile(string)'></a>

## FileIOHelper.LoadFile(string) Method

Same as the original FileIOUtil.LoadFile

```csharp
public static string LoadFile(string fileName);
```
#### Parameters

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.LoadFile(string).fileName'></a>

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

File name within the sandbox directory

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

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.LoadObject_T_(string)'></a>

## FileIOHelper.LoadObject<T>(string) Method

Same as the original FileIOUtil.LoadObject

```csharp
public static T LoadObject<T>(string fileName)
where T : Il2CppSystem.Object;
```
#### Type parameters

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.LoadObject_T_(string).T'></a>

`T`
#### Parameters

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.LoadObject_T_(string).fileName'></a>

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

File name within the sandbox directory

#### Returns
[T](BTD_Mod_Helper.Api.Helpers.FileIOHelper.md#BTD_Mod_Helper.Api.Helpers.FileIOHelper.LoadObject_T_(string).T 'BTD_Mod_Helper.Api.Helpers.FileIOHelper.LoadObject<T>(string).T')

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.SaveObject(string,Il2CppSystem.Object)'></a>

## FileIOHelper.SaveObject(string, Object) Method

Saves an il2cpp object directly to the sandbox path like the original FileIOUtil.SaveObject
<br/>
Will also create subdirectories as needed to save the file

```csharp
public static void SaveObject(string fileName, Il2CppSystem.Object data);
```
#### Parameters

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.SaveObject(string,Il2CppSystem.Object).fileName'></a>

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

Name of file, extension included

<a name='BTD_Mod_Helper.Api.Helpers.FileIOHelper.SaveObject(string,Il2CppSystem.Object).data'></a>

`data` [Il2CppSystem.Object](https://docs.microsoft.com/en-us/dotnet/api/Il2CppSystem.Object 'Il2CppSystem.Object')
22 changes: 2 additions & 20 deletions Documentation/BTD_Mod_Helper.Api.Towers.ModHero.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ Existing hero skins by their skin/tower name
Gets the Background Banner for the default SkinData

```csharp
public virtual UnityEngine.GameObject GetBackgroundBanner(System.Collections.Generic.Dictionary<string,Assets.Scripts.Data.Skins.SkinData> skinsByName);
public virtual Assets.Scripts.Utils.PrefabReference GetBackgroundBanner(System.Collections.Generic.Dictionary<string,Assets.Scripts.Data.Skins.SkinData> skinsByName);
```
#### Parameters

Expand All @@ -339,7 +339,7 @@ public virtual UnityEngine.GameObject GetBackgroundBanner(System.Collections.Gen
Existing hero skins by their skin/tower name

#### Returns
[UnityEngine.GameObject](https://docs.microsoft.com/en-us/dotnet/api/UnityEngine.GameObject 'UnityEngine.GameObject')
[Assets.Scripts.Utils.PrefabReference](https://docs.microsoft.com/en-us/dotnet/api/Assets.Scripts.Utils.PrefabReference 'Assets.Scripts.Utils.PrefabReference')
<a name='BTD_Mod_Helper.Api.Towers.ModHero.GetBackgroundColor(System.Collections.Generic.Dictionary_string,Assets.Scripts.Data.Skins.SkinData_)'></a>

Expand Down Expand Up @@ -399,24 +399,6 @@ public virtual int GetHeroIndex(System.Collections.Generic.List<Assets.Scripts.M
#### Returns
[System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32')
<a name='BTD_Mod_Helper.Api.Towers.ModHero.ModifyHeroSprite(Assets.Scripts.Data.Global.HeroSprite)'></a>

## ModHero.ModifyHeroSprite(HeroSprite) Method

Modifies the HeroSprite used in the Heroes menu. Will already have modified the font/banner/color using
[NameStyle](BTD_Mod_Helper.Api.Towers.ModHero.md#BTD_Mod_Helper.Api.Towers.ModHero.NameStyle 'BTD_Mod_Helper.Api.Towers.ModHero.NameStyle'), [GlowStyle](BTD_Mod_Helper.Api.Towers.ModHero.md#BTD_Mod_Helper.Api.Towers.ModHero.GlowStyle 'BTD_Mod_Helper.Api.Towers.ModHero.GlowStyle') and [BackgroundStyle](BTD_Mod_Helper.Api.Towers.ModHero.md#BTD_Mod_Helper.Api.Towers.ModHero.BackgroundStyle 'BTD_Mod_Helper.Api.Towers.ModHero.BackgroundStyle') at this point.

```csharp
public virtual void ModifyHeroSprite(Assets.Scripts.Data.Global.HeroSprite heroSprite);
```
#### Parameters

<a name='BTD_Mod_Helper.Api.Towers.ModHero.ModifyHeroSprite(Assets.Scripts.Data.Global.HeroSprite).heroSprite'></a>

`heroSprite` [Assets.Scripts.Data.Global.HeroSprite](https://docs.microsoft.com/en-us/dotnet/api/Assets.Scripts.Data.Global.HeroSprite 'Assets.Scripts.Data.Global.HeroSprite')
The HeroSprite to modify

<a name='BTD_Mod_Helper.Api.Towers.ModHero.TowerTiers()'></a>

## ModHero.TowerTiers() Method
Expand Down
1 change: 1 addition & 0 deletions Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
| :--- | :--- |
| [ActionHelper](BTD_Mod_Helper.Api.Helpers.ActionHelper.md 'BTD_Mod_Helper.Api.Helpers.ActionHelper') | Class for converting actions and functions |
| [CostHelper](BTD_Mod_Helper.Api.Helpers.CostHelper.md 'BTD_Mod_Helper.Api.Helpers.CostHelper') | Helper for scaling costs to difficulties |
| [FileIOHelper](BTD_Mod_Helper.Api.Helpers.FileIOHelper.md 'BTD_Mod_Helper.Api.Helpers.FileIOHelper') | Class replacing the original functionality of FileIOUtil before BTD6 update 33.0 |
| [GameModelExporter](BTD_Mod_Helper.Api.Helpers.GameModelExporter.md 'BTD_Mod_Helper.Api.Helpers.GameModelExporter') | Class for handily exporting elements of the GameModel to json files |
| [MapHelper](BTD_Mod_Helper.Api.Helpers.MapHelper.md 'BTD_Mod_Helper.Api.Helpers.MapHelper') | Contains helper methods for working with maps and custom maps. |
| [MatchScale](BTD_Mod_Helper.Api.Helpers.MatchScale.md 'BTD_Mod_Helper.Api.Helpers.MatchScale') | Component to make this transform continuously match the scale of another transform |
Expand Down
Loading

0 comments on commit 5848712

Please sign in to comment.