Skip to content

Commit

Permalink
No more submodule, re-bypassing map saves
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Apr 19, 2022
1 parent e6c380f commit f6d18f4
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion BTD Mod Helper Core/ModHelperData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public static class ModHelperData
{
public const string currentVersion = "2.4.6";
public const string currentVersion = "2.4.7";
}
}
1 change: 0 additions & 1 deletion BloonsTD6 Mod Helper/Patches/ModdedClientChecking
Submodule ModdedClientChecking deleted from 5a0a8f
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Reflection;
using Assets.Scripts.Unity;
using BTD_Mod_Helper.Api;
using HarmonyLib;

namespace BTD_Mod_Helper.Patches.ModdedClientChecking
{
[HarmonyPatch]
internal static class IsModdedClientPatches
{
private static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.PropertyGetter(typeof(Game), nameof(Game.IsModdedClient));
yield return AccessTools.Method(typeof(Modding), nameof(Modding.CheckForMods));
}

[HarmonyPrefix]
private static bool Prefix(ref bool __result)
{
if (ModdedClientBypassing.CurrentlyBypassingCheck && MelonMain.BypassSavingRestrictions)
{
__result = false;
return false;
}
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Assets.Scripts.Unity;

namespace BTD_Mod_Helper.Patches.ModdedClientChecking
{
/// <summary>
/// You forced our hand :(
/// </summary>
public class ModdedClientBypassing
{
/// <summary>
/// The nuclear option would be just setting this to true, which would entirely bypass all of NK's clientside checks
/// </summary>
private const bool DefaultBypassCheck = false;

/// <summary>
/// Whether the ModdedClient check is currently being bypassed
/// </summary>
public static bool CurrentlyBypassingCheck { get; private set; }

/// <summary>
/// Called in prefix patches on methods where we think modded clients should be accepted
/// </summary>
internal static void StartBypassingCheck()
{
CurrentlyBypassingCheck = true;
Modding.isModdedClient = false;
}

/// <summary>
/// Called in postfix patches on methods where we think modded clients should be accepted
/// </summary>
internal static void StopBypassingCheck()
{
CurrentlyBypassingCheck = DefaultBypassCheck;
Modding.isModdedClient = !DefaultBypassCheck;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using System.Reflection;
using Assets.Scripts.Unity.Player;
using Assets.Scripts.Unity.UI_New.DailyChallenge;
using Assets.Scripts.Unity.UI_New.GameOver;
using Assets.Scripts.Unity.UI_New.InGame;
using Assets.Scripts.Utils;
using HarmonyLib;

namespace BTD_Mod_Helper.Patches.ModdedClientChecking
{
[HarmonyPatch]
internal static class ModdedClientUsagePatches
{
private static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(Btd6Player), nameof(Btd6Player.Save));
yield return AccessTools.Method(typeof(Btd6Player), nameof(Btd6Player.SaveNow));
yield return AccessTools.Method(typeof(Btd6Player), nameof(Btd6Player.SyncNow));
yield return AccessTools.Method(typeof(InGame), nameof(InGame.Continue));
yield return AccessTools.Method(typeof(InGame), nameof(InGame.ContinueFromCheckpoint));
yield return AccessTools.Method(typeof(InGame), nameof(InGame.CreateMapSave));
yield return AccessTools.Method(typeof(InGame), nameof(InGame.RoundEnd));
yield return AccessTools.Method(typeof(InGame), nameof(InGame.OnVictory));
yield return AccessTools.Method(typeof(OnlineProfileUpdater), nameof(OnlineProfileUpdater.LateUpdate));

yield return AccessTools.Method(typeof(OnlineProfileManager._Upload_d__13),
nameof(OnlineProfileManager._Upload_d__13.MoveNext));
yield return AccessTools.Method(typeof(Btd6Player._LoadOnlineData_d__38),
nameof(Btd6Player._LoadOnlineData_d__38.MoveNext));
yield return AccessTools.Method(typeof(BossVictoryScreen._Open_d__24),
nameof(BossVictoryScreen._Open_d__24.MoveNext));
yield return AccessTools.Method(typeof(BossEventScreenPlayPanel._Open_d__24),
nameof(BossEventScreenPlayPanel._Open_d__24.MoveNext));
yield return AccessTools.Method(typeof(BossEventScreen._Open_d__43),
nameof(BossEventScreen._Open_d__43.MoveNext));
}

[HarmonyPrefix]
private static void Prefix()
{
ModdedClientBypassing.StartBypassingCheck();
}

[HarmonyPostfix]
private static void Postfix()
{
ModdedClientBypassing.StopBypassingCheck();
}
}
}

0 comments on commit f6d18f4

Please sign in to comment.