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 SwapCrestOnHit v1.2.1
SwapCrestOnHit.dll
Decompiled 6 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GlobalSettings; using HarmonyLib; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("SwapCrestOnHit")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SwapCrestOnHit")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("b3094e4e-6f0a-493a-92ee-c2a34b3bff4a")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] [BepInPlugin("com.chrismzz.swapcrestonhit", "Swap Crest On Hit", "1.2.1")] public class SwapCrestOnHit : BaseUnityPlugin { public static readonly Random rnd = new Random(); internal static ConfigEntry<bool> crestSanity; public static ManualLogSource Logger; public static int cooldown; private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Logger.LogInfo((object)"SwapCrestOnHit loaded and initialized."); crestSanity = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Crest Sanity", true, "Only use unlocked and available crests. Set to false if you want pure chaos."); cooldown = 100; Harmony.CreateAndPatchAll(typeof(SwapCrestOnHit), (string)null); } [HarmonyPatch(typeof(HeroController), "HeroDamaged")] [HarmonyPostfix] private static void HeroDamagedPostfix(HeroController __instance) { if (cooldown < 100) { return; } int silk = __instance.playerData.silk; List<ToolCrest> allCrests = ToolItemManager.GetAllCrests(); List<ToolCrest> list = new List<ToolCrest>(); foreach (ToolCrest item in allCrests) { if (!item.IsHidden && item.IsUnlocked && !item.IsUpgradedVersionUnlocked) { list.Add(item); } } bool flag = list.Count > 1 && __instance.playerData.CurrentCrestID != Gameplay.CursedCrest.name && __instance.playerData.CurrentCrestID != Gameplay.CloaklessCrest.name; List<ToolCrest> list2 = (crestSanity.Value ? list : allCrests); if (flag || !crestSanity.Value) { __instance.ResetAllCrestState(); int index = rnd.Next(0, list2.Count); ToolCrest val = list2[index]; while (__instance.playerData.CurrentCrestID == val.name) { index = rnd.Next(0, list2.Count); val = list2[index]; } ToolItemManager.SetEquippedCrest(val.name); ToolItemManager.SendEquippedChangedEvent(true); } __instance.playerData.silk = silk; cooldown = 0; } [HarmonyPatch(typeof(HeroController), "FixedUpdate")] [HarmonyPostfix] private static void CanSwapCrest() { if (cooldown < 100) { cooldown++; } } }