Skip to content

Commit

Permalink
Further fixes for v45
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Oct 9, 2024
1 parent aa8b7a3 commit 6fbd6fb
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 30 deletions.
19 changes: 19 additions & 0 deletions BloonsTD6 Mod Helper/Api/Helpers/TimeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Il2CppAssets.Scripts;
using Il2CppAssets.Scripts.Utils;
namespace BTD_Mod_Helper.Api.Helpers;

/// <summary>
/// Properties and methods for helping change in game time / time related values
/// </summary>
public static class TimeHelper
{
/// <summary>
/// Override for <see cref="TimeManager.FastForwardTimeScale"/>
/// </summary>
public static double OverrideFastForwardTimeScale { get; set; } = Constants.fastForwardTimeScaleMultiplier;

/// <summary>
/// Override for <see cref="TimeManager.MaxSimulationStepsPerUpdate"/>
/// </summary>
public static double OverrideMaxSimulationStepsPerUpdate { get; set; } = Constants.maxSimulationStepsPerUpdate;
}
19 changes: 10 additions & 9 deletions BloonsTD6 Mod Helper/Api/ModByteLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,29 @@ public abstract class ModByteLoader : ModContent
internal static Task currentLoadTask;

private static readonly string[] References =
{
[
"Il2CppAssets.Scripts.Models.Towers.TargetType"
};
];

private static readonly string[] Structs =
{
[
"Il2CppAssets.Scripts.Simulation.SMath.Vector3"
};
];

private static readonly string[] Enums =
{
[
"Il2CppAssets.Scripts.Models.Towers.TowerModel.TowerSize",
"Il2CppAssets.Scripts.Models.Map.AreaType",
"Il2CppAssets.Scripts.Models.TowerSets.TowerSet"
};
];

private static readonly string[] AssetRefTypes =
{
[
"SpriteReference",
"PrefabReference",
"AudioSourceReference"
};
"AudioSourceReference",
"AudioClipReference"
];

/// <summary>
/// The array of object that NinjaKiwi programmed the loader to utilize
Expand Down
9 changes: 9 additions & 0 deletions BloonsTD6 Mod Helper/Api/ModContent.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ public static SpriteReference GetSpriteReferenceOrDefault<T>(string name) where
{
guidRef = guid
};

/// <summary>
/// Returns a new AudioClipReference that uses the given guid
/// </summary>
/// <param name="guid">The guid that you'd like to assign to the AudioClipReference</param>
public static AudioClipReference CreateAudioClipReference(string guid) => new()
{
guidRef = guid
};

/// <summary>
/// Creates a Prefab Reference for a ModDisplay
Expand Down
5 changes: 3 additions & 2 deletions BloonsTD6 Mod Helper/Api/Towers/ModTowerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ internal static void FinalizeHero(ModHero modHero)
if (index >= 0)
{
var heroDetailsModel =
new HeroDetailsModel(modHero.Id, index, 20, 1, 0, 0,false);
new HeroDetailsModel(modHero.Id, index, 20, 1, 0, 0, false);
Game.instance.model.AddHeroDetails(heroDetailsModel, index);

var skinsData = GameData.Instance.skinsData;
Expand All @@ -299,8 +299,9 @@ internal static void FinalizeHero(ModHero modHero)
public static TowerModel CreateTowerModel(string name, string baseId = null, TowerSet towerSet = TowerSet.None)
{
var sprite = Il2CppSystem.Nullable<SpriteReference>.Unbox(ModContent.CreateSpriteReference(""));
var prefab = Il2CppSystem.Nullable<PrefabReference>.Unbox(ModContent.CreatePrefabReference(""));
var display = ModContent.CreatePrefabReference("");
return new TowerModel(name, baseId ?? name, towerSet, display, icon: sprite, portrait: sprite, instaIcon: sprite,
emoteSpriteSmall: sprite, emoteSpriteLarge: sprite, secondarySelectionMenu: display);
emoteSpriteSmall: sprite, emoteSpriteLarge: sprite, secondarySelectionMenu: display, icon3D: prefab);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Object GetItem<T>(this IEnumerable<T> enumerable, int index)
/// <typeparam name="T"></typeparam>
/// <param name="enumerable"></param>
/// <returns></returns>
public static List<T> ToIl2CppList<T>(this IEnumerable<T> enumerable) where T : Object
public static List<T> ToIl2CppList<T>(this IEnumerable<T> enumerable) where T : Il2CppObjectBase
{
var il2CppList = new List<T>();

Expand Down
10 changes: 5 additions & 5 deletions BloonsTD6 Mod Helper/Extensions/LINQExtensions/Il2CppGenerics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class Il2CppGenerics
/// <param name="source"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public static T First<T>(this List<T> source, System.Func<T, bool> predicate) where T : Object =>
public static T First<T>(this List<T> source, System.Func<T, bool> predicate) where T : Il2CppObjectBase =>
source.Cast<IEnumerable<T>>().First(predicate);

/// <summary>
Expand All @@ -25,7 +25,7 @@ public static T First<T>(this List<T> source, System.Func<T, bool> predicate) wh
/// <param name="source"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public static T FirstOrDefault<T>(this List<T> source, System.Func<T, bool> predicate) where T : Object =>
public static T FirstOrDefault<T>(this List<T> source, System.Func<T, bool> predicate) where T : Il2CppObjectBase =>
Enumerable.FirstOrDefault(source.Cast<IEnumerable<T>>(), predicate);

/// <summary>
Expand All @@ -35,7 +35,7 @@ public static T FirstOrDefault<T>(this List<T> source, System.Func<T, bool> pred
/// <param name="source"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public static List<T> Where<T>(this List<T> source, System.Func<T, bool> predicate) where T : Object =>
public static List<T> Where<T>(this List<T> source, System.Func<T, bool> predicate) where T : Il2CppObjectBase =>
source.Cast<IEnumerable<T>>().Where(predicate).ToIl2CppList();

/// <summary>
Expand All @@ -45,7 +45,7 @@ public static List<T> Where<T>(this List<T> source, System.Func<T, bool> predica
/// <param name="source"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public static int FindIndex<T>(this List<T> source, System.Func<T, bool> predicate) where T : Object =>
public static int FindIndex<T>(this List<T> source, System.Func<T, bool> predicate) where T : Il2CppObjectBase =>
source.FindIndex(predicate);

/// <summary>
Expand All @@ -63,7 +63,7 @@ public static int FindIndex<T>(this List<T> source, System.Func<T, bool> predica
/// <param name="source"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public static bool Any<T>(this List<T> source, System.Func<T, bool> predicate) where T : Object
public static bool Any<T>(this List<T> source, System.Func<T, bool> predicate) where T : Il2CppObjectBase
{
foreach (var _ in source.Where(predicate))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public static class AudioClipExtensions
/// <summary>
/// Plays a sound through the default Game AudioFactory
/// </summary>
/// <param name="audioClip">The audio clip to play</param>
/// <param name="audioClip">The audio audioClip to play</param>
/// <param name="volume">How loud it should be</param>
/// <param name="groupId">TODO group stuff</param>
public static void Play(this AudioClip audioClip, string groupId = "FX", float volume = 1f)
{
Game.instance.audioFactory.PlaySoundFromUnity(audioClip, groupId, -1, 0, volume);
Game.instance.audioFactory.PlaySoundFromUnity(audioClip, groupId, -1, volume);
}
}
7 changes: 5 additions & 2 deletions BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
## NOTE: BTD6 v45 will require MelonLoader v0.6.5 to work
- Fixed for BTD6 v45.0
- Fixed a performance issue with the background Task Scheduler
- Also added new `ScheduleType.WaitForSecondsScaled` that is affected by fast-forward mode
- Added a `ModRoundSet.Rounds1Index` override that changes the behavior of the `ModifyRoundModels` methods to match the
player facing 1, 2, 3 and not the internal 0, 1, 2.
- This will become the default in a later Mod Helper update
- Updated the way VanillaSprites.cs is generated, so it no longer includes many "false positives" of Sprites that have
GUIDs but aren't properly able to be loaded on demand
- Updated the way VanillaSprites.cs is generated, so it no longer includes some duplicates and many "false positives" of
Sprites that have GUIDs but aren't properly able to be loaded on demand
- Added a Renderer extension `.ReplaceColor(Color targetColor, Color replacementColor, float threshold)` that
replaces all the colors in the main texture within a certain threshold of the target with a new color.
- Added a Renderer extension `.AdjustHSV(float hueAdjust, float saturationAdjust, float valueAdjust)` that edits
the Hue/Saturation/Value of the main texture.
- Can also do
`.AdjustHSV(float hueAdjust, float saturationAdjust, float valueAdjust, Color targetColor, float threshold)` to only
apply the adjustment to certain colors in the texture
- Added `TimeHelper` class with properties `OverrideFastForwardTimeScale` and `OverrideMaxSimulationStepsPerUpdate`

### Custom Jukebox Tracks

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.2.1";
internal const string Version = "3.3.0";
internal const string RepoOwner = "gurrenm3";
internal const string RepoName = "BTD-Mod-Helper";
internal const string Description =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Internal;
using Il2CppNinjaKiwi.Common.ResourceUtils;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

namespace BTD_Mod_Helper.Patches.Resources;

/// <summary>
/// Fixes a weird bug that cropped up with v45 where custom sprites wouldn't always finish loading
/// <br/>
/// TODO investigate this further, fix initial flash of white square?
/// </summary>
[HarmonyPatch(typeof(ResourceLoader), nameof(ResourceLoader.OnSpriteLoaded))]
internal static class ResourceLoader_OnSpriteLoaded
{
[HarmonyPrefix]
internal static void Prefix(ref AsyncOperationHandle<Sprite> handle)
{
if (handle.Succeeded() &&
handle.Result == null &&
handle.LocationName.Contains(ModContent.HijackSpriteAtlas + ".spriteatlasv2"))
{
var name = handle.LocationName
[(handle.LocationName.IndexOf("[", StringComparison.Ordinal) + 1)..^1];
if (ResourceHandler.GetSprite(name) is Sprite spr)
{
handle = Addressables.Instance.ResourceManager.CreateCompletedOperation(spr, "");
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using BTD_Mod_Helper.Api.Helpers;
using Il2CppAssets.Scripts;
using Il2CppAssets.Scripts.Utils;
namespace BTD_Mod_Helper.Patches.Sim;

[HarmonyPatch(typeof(TimeManager), nameof(TimeManager.FastForwardTimeScale), MethodType.Getter)]
internal static class TimeManager_FastForwardTimeScale
{
[HarmonyPrefix]
internal static bool Prefix(ref double __result)
{
__result = TimeHelper.OverrideFastForwardTimeScale;
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using BTD_Mod_Helper.Api.Helpers;
using Il2CppAssets.Scripts.Utils;
namespace BTD_Mod_Helper.Patches.Sim;

[HarmonyPatch(typeof(TimeManager), nameof(TimeManager.MaxSimulationStepsPerUpdate), MethodType.Getter)]
internal static class TimeManager_MaxSimulationStepsPerUpdate
{
[HarmonyPrefix]
internal static bool Prefix(ref double __result)
{
__result = TimeHelper.OverrideMaxSimulationStepsPerUpdate;
return false;

}
}
32 changes: 32 additions & 0 deletions BloonsTD6 Mod Helper/Patches/Sim/TimeManager_Update.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using BTD_Mod_Helper.Api.Helpers;
using Il2CppAssets.Scripts.Unity.Menu;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using Il2CppAssets.Scripts.Utils;
using UnityEngine;
namespace BTD_Mod_Helper.Patches.Sim;

/// <summary>
/// Sadly the FastForwardTimeScale call seems to have been inlined for 45.0
/// </summary>
[HarmonyPatch(typeof(TimeManager), nameof(TimeManager.Update))]
internal static class TimeManager_Update
{
[HarmonyPostfix]
internal static void Postfix()
{
if (InGame.Bridge == null || InGame.instance == null) return;

var paused = InGame.instance.IsCoop
? TimeManager.coopPaused
: !InGame.instance._reviewMapMode && TimeManager.gamePaused;

var baseTime = paused ? 0 : 1;
var fastForwardScale = TimeManager.FastForwardActive && !TimeManager.inBetweenRounds
? TimeHelper.OverrideFastForwardTimeScale
: 1;

var time = baseTime * fastForwardScale * TimeManager.replayTimeScaleMultiplier;

Time.timeScale = Mathf.Clamp((float) time, 0, 100);
}
}
39 changes: 39 additions & 0 deletions Documentation/BTD_Mod_Helper.Api.Helpers.TimeHelper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#### [BloonsTD6 Mod Helper](README.md 'README')
### [BTD_Mod_Helper.Api.Helpers](README.md#BTD_Mod_Helper.Api.Helpers 'BTD_Mod_Helper.Api.Helpers')

## TimeHelper Class

Properties and methods for helping change in game time / time related values

```csharp
public static class TimeHelper
```

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

<a name='BTD_Mod_Helper.Api.Helpers.TimeHelper.OverrideFastForwardTimeScale'></a>

## TimeHelper.OverrideFastForwardTimeScale Property

Override for [Il2CppAssets.Scripts.Utils.TimeManager.FastForwardTimeScale](https://docs.microsoft.com/en-us/dotnet/api/Il2CppAssets.Scripts.Utils.TimeManager.FastForwardTimeScale 'Il2CppAssets.Scripts.Utils.TimeManager.FastForwardTimeScale')
```csharp
public static double OverrideFastForwardTimeScale { get; set; }
```

#### Property Value
[System.Double](https://docs.microsoft.com/en-us/dotnet/api/System.Double 'System.Double')
<a name='BTD_Mod_Helper.Api.Helpers.TimeHelper.OverrideMaxSimulationStepsPerUpdate'></a>

## TimeHelper.OverrideMaxSimulationStepsPerUpdate Property

Override for [Il2CppAssets.Scripts.Utils.TimeManager.MaxSimulationStepsPerUpdate](https://docs.microsoft.com/en-us/dotnet/api/Il2CppAssets.Scripts.Utils.TimeManager.MaxSimulationStepsPerUpdate 'Il2CppAssets.Scripts.Utils.TimeManager.MaxSimulationStepsPerUpdate')
```csharp
public static double OverrideMaxSimulationStepsPerUpdate { get; set; }
```

#### Property Value
[System.Double](https://docs.microsoft.com/en-us/dotnet/api/System.Double 'System.Double')
20 changes: 20 additions & 0 deletions Documentation/BTD_Mod_Helper.Api.ModContent.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ public static string BloonID<T>()
#### Returns
[System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')
<a name='BTD_Mod_Helper.Api.ModContent.CreateAudioClipReference(string)'></a>

## ModContent.CreateAudioClipReference(string) Method

Returns a new AudioClipReference that uses the given guid

```csharp
public static AudioClipReference CreateAudioClipReference(string guid);
```
#### Parameters

<a name='BTD_Mod_Helper.Api.ModContent.CreateAudioClipReference(string).guid'></a>

`guid` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')
The guid that you'd like to assign to the AudioClipReference

#### Returns
[Il2CppNinjaKiwi.Common.ResourceUtils.AudioClipReference](https://docs.microsoft.com/en-us/dotnet/api/Il2CppNinjaKiwi.Common.ResourceUtils.AudioClipReference 'Il2CppNinjaKiwi.Common.ResourceUtils.AudioClipReference')
<a name='BTD_Mod_Helper.Api.ModContent.CreateAudioSourceReference(string)'></a>

## ModContent.CreateAudioSourceReference(string) Method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void Play(this AudioClip audioClip, string groupId="FX", float vol

`audioClip` [UnityEngine.AudioClip](https://docs.microsoft.com/en-us/dotnet/api/UnityEngine.AudioClip 'UnityEngine.AudioClip')
The audio clip to play
The audio audioClip to play

<a name='BTD_Mod_Helper.Extensions.AudioClipExtensions.Play(thisAudioClip,string,float).groupId'></a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Return as Il2CppSystem.List

```csharp
public static List<T> ToIl2CppList<T>(this IEnumerable<T> enumerable)
where T : Object;
where T : Il2CppObjectBase;
```
#### Type parameters

Expand Down
Loading

0 comments on commit 6fbd6fb

Please sign in to comment.