Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of FleaFestivalDifficulty v1.0.1
FleaFestivalDifficulty.dll
Decompiled 5 months agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using FleaFestivalDifficulty.Speed; using HarmonyLib; using HutongGames.PlayMaker; using HutongGames.PlayMaker.Actions; using Microsoft.CodeAnalysis; using Silksong.FsmUtil; using Silksong.UnityHelper.Extensions; using TMProOld; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("FleaFestivalDifficulty")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+e89ff0466a1d5c3c1cce27ac4f5306202397358d")] [assembly: AssemblyProduct("FleaFestivalDifficulty")] [assembly: AssemblyTitle("FleaFestivalDifficulty")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/BobbyTheCatfish/FleaFestivalDifficulty")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace FleaFestivalDifficulty { internal class ConstPatch { public ConstPatch() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown Harmony val = new Harmony("festival"); Type typeFromHandle = typeof(int); MethodInfo method = typeof(Constants).GetMethod("GetConstantValue"); MethodInfo methodInfo = method.MakeGenericMethod(typeFromHandle); MethodInfo method2 = typeof(ConstPatch).GetMethod("GetConstantValue"); val.Patch((MethodBase)methodInfo, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.PatchAll(typeof(ConstPatch)); } public static bool GetConstantValue(string variableName, ref int __result) { if (variableName.StartsWith("FLEA_F")) { switch (variableName) { case "FLEA_FESTIVAL_CHAMP_JUGGLE": __result = Scores.Juggle.Champ; break; case "FLEA_FESTIVAL_SETH_JUGGLE": __result = Scores.Juggle.Seth; break; case "FLEA_FESTIVAL_CHAMP_DODGE": __result = Scores.Dodge.Champ; break; case "FLEA_FESTIVAL_SETH_DODGE": __result = Scores.Dodge.Seth; break; case "FLEA_FESTIVAL_CHAMP_BOUNCE": __result = Scores.Bounce.Champ; break; case "FLEA_FESTIVAL_SETH_BOUNCE": __result = Scores.Bounce.Seth; break; default: return true; } return false; } return true; } [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyPrefix] public static bool FleaGamesIsJugglingChampion(PlayerData __instance, ref bool __result) { Log.LogInfo("TESTING JUGGLE CHAMP"); __result = __instance.fleaGames_juggling_highscore > Scores.Juggle.Champ; return false; } [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyPrefix] public static bool FleaGamesIsJugglingSethChampion(PlayerData __instance, ref bool __result) { __result = __instance.fleaGames_juggling_highscore > Scores.Juggle.Seth; return false; } [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyPrefix] public static bool FleaGamesIsBouncingChampion(PlayerData __instance, ref bool __result) { __result = __instance.fleaGames_bouncing_highscore > Scores.Bounce.Champ; return false; } [HarmonyPatch(/*Could not decode attribute arguments.*/)] public static bool FleaGamesIsBouncingSethChampion(PlayerData __instance, ref bool __result) { __result = __instance.fleaGames_bouncing_highscore > Scores.Bounce.Seth; return false; } [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyPrefix] public static bool FleaGamesIsDodgingChampion(PlayerData __instance, ref bool __result) { __result = __instance.fleaGames_dodging_highscore > Scores.Dodge.Champ; return false; } [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyPrefix] public static bool FleaGamesIsDodgingSethChampion(PlayerData __instance, ref bool __result) { __result = __instance.fleaGames_dodging_highscore > Scores.Dodge.Seth; return false; } } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("io.github.bobbythecatfish.FleaFestivalDifficulty", "FleaFestivalDifficulty", "1.0.1")] public class FFDPlugin : BaseUnityPlugin { internal static JuggleSpeed JuggleSpeed = new JuggleSpeed(); internal static BounceSpeed BounceSpeed = new BounceSpeed(); internal static DodgeSpeed DodgeSpeed = new DodgeSpeed(); private static ConstPatch constPatch; public const string Id = "io.github.bobbythecatfish.FleaFestivalDifficulty"; public static string Name => "FleaFestivalDifficulty"; public static string Version => "1.0.1"; private void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.bobbythecatfish.FleaFestivalDifficulty) has loaded!")); Harmony.CreateAndPatchAll(typeof(FFDPlugin), (string)null); constPatch = new ConstPatch(); SceneManager.sceneLoaded += OnSceneChange; Log.SetLogger(((BaseUnityPlugin)this).Logger); Config.Init(((BaseUnityPlugin)this).Config); Scores.Init(); } private void Update() { if (Input.GetKeyDown((KeyCode)48)) { Log.LogInfo(Constants.GetConstantValue<int>("FLEA_FESTIVAL_CHAMP_JUGGLE")); } } private void OnSceneChange(Scene scene, LoadSceneMode mode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) if ((int)mode == 1 && !(((Scene)(ref scene)).name != "Aqueduct_05_festival")) { JuggleSpeed.Init(scene, "Juggling"); DodgeSpeed.Init(scene, "Dodging"); BounceSpeed.Init(scene, "Bouncing"); Log.LogInfo("Loaded the festival"); } } [HarmonyPatch(typeof(ScoreBoardUI), "Awake")] [HarmonyPrefix] private static void ScoreboardAwake(ScoreBoardUI __instance) { Scores.LoadScoreboard(((Component)__instance).gameObject); Scores.SetScoreboard(((Component)__instance).gameObject); } [HarmonyPatch(typeof(ScoreBoardUI), "Refresh")] [HarmonyPrefix] private static void ScoreboardRefresh(ScoreBoardUI __instance) { Scores.LoadScoreboard(((Component)__instance).gameObject); Scores.SetScoreboard(((Component)__instance).gameObject); } } internal class Game { public ConfigEntry<float> _multiplier; private int _seth; private int _champ; private int _grish = 0; private int _vog = 0; private int _moosh = 0; private int _varg = 0; private int _kratt = 0; private int index; public float Multiplier => _multiplier?.Value ?? 1f; public int Seth => Score(_seth); public int Champ => Score(_champ); public int Grish => Score(_grish); public int Vog => Score(_vog); public int Moosh => Score(_moosh); public int Varg => Score(_varg); public int Kratt => Score(_kratt); public Game(ConfigEntry<float> mult, int seth, int champ, int index) { _multiplier = mult; _seth = seth; _champ = champ; this.index = index; } public void Init(GameObject ui) { Transform child = ui.transform.GetChild(2).GetChild(index); _grish = GetScore(child, "Score Badge Short"); _vog = GetScore(child, "Score Badge Hunter"); _moosh = GetScore(child, "Score Badge Leader"); _varg = GetScore(child, "Score Badge Tall Variant"); _kratt = GetScore(child, "Score Badge Lech"); } private static GameObject GetBadge(Transform root, string name) { for (int i = 0; i < root.childCount; i++) { Transform child = root.GetChild(i); if (((Object)child).name == name) { return ((Component)child).gameObject; } } return null; } private static int GetScore(Transform root, string badgeName) { GameObject badge = GetBadge(root, badgeName); if ((Object)(object)badge == (Object)null) { return 0; } ScoreBoardUIBadge component = badge.GetComponent<ScoreBoardUIBadge>(); return component.score; } private int Score(int raw) { return (int)((float)raw * Multiplier); } public void SetScoreboard(GameObject ui) { Transform child = ui.transform.GetChild(2).GetChild(index); SetScore(child, "Score Badge Short", Grish); SetScore(child, "Score Badge Hunter", Vog); SetScore(child, "Score Badge Leader", Moosh); SetScore(child, "Score Badge Tall Variant", Varg); SetScore(child, "Score Badge Lech", Kratt); } private void SetScore(Transform root, string badgeName, int score) { GameObject badge = GetBadge(root, badgeName); if (!((Object)(object)badge == (Object)null)) { ScoreBoardUIBadge component = badge.GetComponent<ScoreBoardUIBadge>(); component.score = score; TextMeshPro component2 = ((Component)badge.transform.GetChild(2)).GetComponent<TextMeshPro>(); if (component2 != null) { ((TMP_Text)component2).text = score.ToString(); } } } } internal static class Scores { public static Game Juggle; public static Game Dodge; public static Game Bounce; private static bool initialized; public static void Init() { Juggle = new Game(Config.JuggleScoreMult, 55, 30, 5); Dodge = new Game(Config.DodgeScoreMult, 90, 65, 7); Bounce = new Game(Config.BounceScoreMult, 68, 42, 9); } public static void LoadScoreboard(GameObject root) { if (!initialized) { Juggle.Init(root); Dodge.Init(root); Bounce.Init(root); initialized = true; } } public static void SetScoreboard(GameObject root) { Juggle.SetScoreboard(root); Dodge.SetScoreboard(root); Bounce.SetScoreboard(root); } } internal static class Config { public static ConfigEntry<float> JuggleScoreMult; public static ConfigEntry<float> DodgeScoreMult; public static ConfigEntry<float> BounceScoreMult; public static ConfigEntry<float> JuggleSpeedMult; public static ConfigEntry<float> DodgeSpeedMult; public static ConfigEntry<float> BounceSpeedMult; public static void Init(ConfigFile config) { JuggleScoreMult = config.Bind<float>("Score Multipliers", "Juggle", 1f, "Multiplies all flea/seth scores for this game"); DodgeScoreMult = config.Bind<float>("Score Multipliers", "Dodge", 1f, "Multiplies all flea/seth scores for this game"); BounceScoreMult = config.Bind<float>("Score Multipliers", "Bounce", 1f, "Multiplies all flea/seth scores for this game"); JuggleSpeedMult = config.Bind<float>("Speed Multipliers", "Juggle", 1f, "Higher number = faster fleas"); JuggleSpeedMult.SettingChanged += FFDPlugin.JuggleSpeed.SetSpeed; DodgeSpeedMult = config.Bind<float>("Speed Multipliers", "Dodge", 1f, "Higher number = faster fleas"); DodgeSpeedMult.SettingChanged += FFDPlugin.DodgeSpeed.SetSpeed; BounceSpeedMult = config.Bind<float>("Speed Multipliers", "Bounce", 1f, "Higher number = faster fleas"); BounceSpeedMult.SettingChanged += FFDPlugin.BounceSpeed.SetSpeed; } } internal static class Log { private static ManualLogSource logger; public static void SetLogger(ManualLogSource log) { logger = log; } public static void LogInfo(params object[] data) { foreach (object obj in data) { logger.LogInfo(obj); } } public static void LogWarning(params object[] data) { foreach (object obj in data) { logger.LogWarning(obj); } } public static void LogError(params object[] data) { foreach (object obj in data) { logger.LogError(obj); } } public static void LogFatal(params object[] data) { foreach (object obj in data) { logger.LogFatal(obj); } } public static void LogDebug(params object[] data) { foreach (object obj in data) { logger.LogDebug(obj); } } public static void LogMessage(params object[] data) { foreach (object obj in data) { logger.LogMessage(obj); } } } } namespace FleaFestivalDifficulty.Speed { internal abstract class BaseSpeed { protected GameObject Controller; protected abstract float Speed { get; } public void Init(Scene scene, string gameName) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) Controller = UnityExtensions.FindGameObject(scene, "Caravan_States/Flea Festival/Flea Game - " + gameName); if ((Object)(object)Controller == (Object)null) { Log.LogError("Couldn't find minigame controller"); } else { Log.LogDebug("Found minigame controller"); SetSpeed(); } } public void SetSpeed(object sender, EventArgs e) { SetSpeed(); } public abstract void SetSpeed(); protected void SetAction(PlayMakerFSM fsm, string state, int actionIndex, bool inverse = false) { SetFloatValue action = FsmUtil.GetAction<SetFloatValue>(fsm, state, actionIndex); if (action != null) { DoSpeedMult(action.floatValue, inverse); } } protected void DoSpeedMult(FsmFloat fsmFloat, bool inverse = false) { if (inverse) { fsmFloat.Value /= Speed; } else { fsmFloat.Value *= Speed; } } protected void DoSpeedMult(FsmInt fsmInt, bool inverse = false) { if (inverse) { fsmInt.Value = (int)((float)fsmInt.Value / Speed); } else { fsmInt.Value = (int)((float)fsmInt.Value * Speed); } } } internal class BounceSpeed : BaseSpeed { protected override float Speed => Mathf.Max(0.01f, Config.BounceSpeedMult?.Value ?? 1f); public override void SetSpeed() { if (!((Object)(object)Controller == (Object)null)) { PlayMakerFSM fsm = FsmUtil.GetFsm(Controller, "Game Specific Control"); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Flea Speed")); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Flea Speed Initial")); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Spawn Frequency")); SetAction(fsm, "Start Pause", 2); SetAction(fsm, "Increase Difficulty", 1); DoSpeedMult(FsmUtil.GetAction<FloatClamp>(fsm, "Increase Difficulty", 3).maxValue); DoSpeedMult(FsmUtil.GetAction<FloatAdd>(fsm, "Shorten Pause?", 1).add); DoSpeedMult(FsmUtil.GetAction<FloatClamp>(fsm, "Shorten Pause?", 2).maxValue); DoSpeedMult(FsmUtil.GetAction<FloatAdd>(fsm, "Lengthen Pause", 0).add); DoSpeedMult(FsmUtil.GetAction<FloatClamp>(fsm, "Lengthen Pause", 1).minValue); DoSpeedMult(FsmUtil.GetAction<FloatClamp>(fsm, "Lengthen Pause", 1).maxValue); } } } internal class DodgeSpeed : BaseSpeed { protected override float Speed => Mathf.Max(0.01f, Config.DodgeSpeedMult?.Value ?? 1f); public override void SetSpeed() { if (!((Object)(object)Controller == (Object)null)) { PlayMakerFSM fsm = FsmUtil.GetFsm(Controller, "Game Specific Control"); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Flea Speed")); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Flea Speed Initial")); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Max Difficulty Score"), inverse: true); SetAction(fsm, "Start Pause", 1); DoSpeedMult(FsmUtil.GetAction<IntCompare>(fsm, "Quicken?", 1).integer2); DoSpeedMult(FsmUtil.GetAction<IntCompare>(fsm, "Choice", 3).integer2); DoSpeedMult(FsmUtil.GetAction<IntTestToBool>(fsm, "Choice", 4).int2); DoSpeedMult(FsmUtil.GetAction<IntTestToBool>(fsm, "Choice", 5).int2); DoSpeedMult(FsmUtil.GetAction<IntCompare>(fsm, "Choice", 3).integer2); SetTimings(fsm, 3, hasLate: true); SetTimings(fsm, 4); SetTimings(fsm, 5); SetAction(fsm, "Min Difficulty", 0); SetAction(fsm, "Max Difficulty", 0); Transform child = Controller.transform.GetChild(5); int childCount = child.childCount; for (int i = 0; i < childCount; i++) { GameObject gameObject = ((Component)child.GetChild(i)).gameObject; PlayMakerFSM fsm2 = FsmUtil.GetFsm(gameObject, "Control"); DoSpeedMult(FsmUtil.GetFloatVariable(fsm2, "Charge Speed")); DoSpeedMult(FsmUtil.GetFloatVariable(fsm2, "Max Difficulty Score"), inverse: true); DoSpeedMult(FsmUtil.GetAction<FloatOperator>(fsm2, "Set Speed", 6).float1); SetAction(fsm2, "Min Speed", 0); SetAction(fsm2, "Max Speed", 0); } } } private void SetTimings(PlayMakerFSM fsm, int fleaCount, bool hasLate = false) { for (int i = 0; i < fleaCount - 1; i++) { SetAction(fsm, $"{fleaCount} Even", i, inverse: true); if (hasLate) { SetAction(fsm, $"{fleaCount} Early", i, inverse: true); SetAction(fsm, $"{fleaCount} Late", i, inverse: true); } else { SetAction(fsm, $"{fleaCount} Split", i, inverse: true); } } } } internal class JuggleSpeed : BaseSpeed { protected override float Speed => Mathf.Max(0.01f, Config.JuggleSpeedMult?.Value ?? 1f); public override void SetSpeed() { if (!((Object)(object)Controller == (Object)null)) { PlayMakerFSM fsm = FsmUtil.GetFsm(Controller, "Game Specific Control"); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Bounce Time"), inverse: true); SetAction(fsm, "Start Pause", 1, inverse: true); SetAction(fsm, "Single", 1, inverse: true); SetAction(fsm, "Double", 1, inverse: true); SetAction(fsm, "Triple", 1, inverse: true); SetAction(fsm, "Quad", 1, inverse: true); DoSpeedMult(FsmUtil.GetAction<SetFsmFloat>(fsm, "Quick Flea", 2).setValue, inverse: true); DoSpeedMult(FsmUtil.GetAction<SetFsmFloat>(fsm, "Quick Flea", 4).setValue, inverse: true); SetAction(fsm, "Stage Check", 1, inverse: true); SetAction(fsm, "Stage Check", 4, inverse: true); SetAction(fsm, "Stage Check", 6, inverse: true); SetAction(fsm, "Stage Check", 10, inverse: true); SetAction(fsm, "Stage Check", 12, inverse: true); SetAction(fsm, "Stage Check", 16, inverse: true); SetAction(fsm, "Stage Check", 18, inverse: true); SetAction(fsm, "Stage Check", 22, inverse: true); SetAction(fsm, "Stage Check", 24, inverse: true); SetAction(fsm, "Stage Check", 26, inverse: true); SetAction(fsm, "Stage Check", 30, inverse: true); SetAction(fsm, "Stage Check", 35, inverse: true); SetSpecialFleaSpeed(4); SetSpecialFleaSpeed(5); Transform child = Controller.transform.GetChild(10).GetChild(0); fsm = FsmUtil.GetFsm(((Component)child).gameObject, "Control"); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Bounce Time"), inverse: true); DoSpeedMult(FsmUtil.GetAction<FloatMultiply>(fsm, "BounceAway Start", 7).multiplyBy, inverse: true); DoSpeedMult(FsmUtil.GetAction<FloatMultiply>(fsm, "GiantAway Start", 4).multiplyBy, inverse: true); } } private void SetSpecialFleaSpeed(int index) { Transform child = Controller.transform.GetChild(index); PlayMakerFSM fsm = FsmUtil.GetFsm(((Component)child).gameObject, "Control"); DoSpeedMult(FsmUtil.GetFloatVariable(fsm, "Bounce Time"), inverse: true); SetAction(fsm, "Varga Setup", 15, inverse: true); } } }