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 ReduceRecycler v1.3.4
plugins/ReduceRecycler/ReduceRecycler.dll
Decompiled 5 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using IL.RoR2; using Mono.Cecil.Cil; using MonoMod.Cil; using On.RoR2; using R2API.Utils; using RiskOfOptions; using RiskOfOptions.Options; using RoR2; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("quasikyo")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.3.4.0")] [assembly: AssemblyInformationalVersion("1.3.4+d6c4e0c83c8b138b944e8e96fbd83ba91c8c77cf")] [assembly: AssemblyProduct("ReduceRecycler")] [assembly: AssemblyTitle("ReduceRecycler")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/quasikyo/ror2-mods/tree/main/ReduceRecycler")] [assembly: AssemblyVersion("1.0.0.0")] namespace ReduceRecycler; internal static class ConfigManager { private static ConfigFile OptionsConfig { get; set; } internal static ConfigEntry<bool> IsModEnabled { get; set; } internal static ConfigEntry<bool> EnableOnlyAfterTeleporter { get; set; } internal static ConfigEntry<ReduceRecycler.CooldownReset> CooldownReset { get; set; } internal static void Init() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown OptionsConfig = new ConfigFile(Paths.ConfigPath + "\\ReduceRecycler.cfg", true); ModSettingsManager.SetModDescription("Customize the behavior of the recycler equipment to shorten the time between uses."); IsModEnabled = OptionsConfig.Bind<bool>("Behavior", "Enable Mod", true, "Dynamically enable or disable the mod. If this is unchecked, the mod will not function until re-enabled."); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(IsModEnabled)); EnableOnlyAfterTeleporter = OptionsConfig.Bind<bool>("Behavior", "Enable Only After Teleporter", false, "Enable no-cooldown only after the teleporter for the stage has been completed. For stage without a teleporter (Hidden Realms, Void Fields, Commencement), this just makes the Recycler behave as normal."); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EnableOnlyAfterTeleporter)); CooldownReset = OptionsConfig.Bind<ReduceRecycler.CooldownReset>("Behavior", "Cooldown Reset", ReduceRecycler.CooldownReset.AfterUse, "When to reset the cooldown of Recycler. AfterUse will reset immediately after use. OnDemand will reset on button press."); ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)CooldownReset)); } } internal static class Log { private static ManualLogSource Logger { get; set; } internal static void Init(ManualLogSource logger) { Logger = logger; } [Conditional("DEBUG")] internal static void Debug(object data) { Logger.LogDebug(data); } internal static void Info(object data) { Logger.LogInfo(data); } internal static void Message(object data) { Logger.LogMessage(data); } internal static void Warning(object data) { Logger.LogWarning(data); } internal static void Error(object data) { Logger.LogError(data); } internal static void Fatal(object data) { Logger.LogFatal(data); } } [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [BepInPlugin("quasikyo.ReduceRecycler", "ReduceRecycler", "1.3.4")] public class ReduceRecycler : BaseUnityPlugin { internal enum CooldownReset { AfterUse, OnDemand } [CompilerGenerated] private sealed class <ExecuteWithDelay>d__11 : IEnumerator<object>, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public TimeSpan delay; public Action action; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <ExecuteWithDelay>d__11(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds((float)delay.TotalSeconds); <>1__state = 1; return true; case 1: <>1__state = -1; action(); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private const string finalStageSceneName = "moon2"; private const string voidFieldsStageSceneName = "arena"; public void Awake() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown Log.Init(((BaseUnityPlugin)this).Logger); Log.Info("Performing setup for ReduceRecycler"); ConfigManager.Init(); EquipmentSlot.FireRecycle += new hook_FireRecycle(ResetAfterUse); EquipmentSlot.MyFixedUpdate += new Manipulator(EquipmentActivationAllowedIfRecycler); EquipmentSlot.ExecuteIfReady += new Manipulator(ResetOnDemand); } private void EquipmentActivationAllowedIfRecycler(ILContext context) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown ILCursor val = new ILCursor(context); val.GotoNext(new Func<Instruction, bool>[3] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<EquipmentSlot>(x, "get_characterBody"), (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_isEquipmentActivationAllowed") }); val.Index += 2; val.Remove(); val.EmitDelegate<Func<CharacterBody, bool>>((Func<CharacterBody, bool>)delegate(CharacterBody body) { VehicleSeat currentVehicle = body.currentVehicle; bool flag = !Object.op_Implicit((Object)(object)currentVehicle) || currentVehicle.isEquipmentActivationAllowed; return IsRecycler(body.equipmentSlot) || flag; }); } private void ResetOnDemand(ILContext context) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown ILCursor val = new ILCursor(context); val.GotoNext(new Func<Instruction, bool>[1] { (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<EquipmentSlot>(x, "get_stock") }); val.Remove(); val.EmitDelegate<Func<EquipmentSlot, int>>((Func<EquipmentSlot, int>)delegate(EquipmentSlot slot) { if (ConfigManager.CooldownReset.Value == CooldownReset.OnDemand) { ResetRecyclerCooldown(slot); } return slot.stock; }); } private bool ResetAfterUse(orig_FireRecycle original, EquipmentSlot slot) { bool flag = original.Invoke(slot); if (ConfigManager.CooldownReset.Value == CooldownReset.AfterUse && flag) { ((MonoBehaviour)this).StartCoroutine(ExecuteWithDelay(delegate { ResetRecyclerCooldown(slot); }, TimeSpan.FromSeconds(0.5))); } return flag; } private void ResetRecyclerCooldown(EquipmentSlot slot) { if (!ConfigManager.IsModEnabled.Value || !IsRecycler(slot)) { return; } float cooldownTimer = slot.cooldownTimer; if (float.IsInfinity(cooldownTimer)) { return; } float runStopwatch = Run.instance.GetRunStopwatch(); bool flag = StageHasTeleporter(Stage.instance.sceneDef) && TeleporterInteraction.instance.isCharged; bool flag2 = !ConfigManager.EnableOnlyAfterTeleporter.Value || flag; if (GetEquipmentCharges(slot) == 0 && flag2) { slot.characterBody.inventory.DeductActiveEquipmentCooldown(cooldownTimer); if (!Run.instance.isRunStopwatchPaused) { Run.instance.SetRunStopwatch(runStopwatch + cooldownTimer); } } } private bool StageHasTeleporter(SceneDef scene) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 bool num = (int)scene.sceneType == 1; bool flag = scene.baseSceneName.Equals("moon2"); bool flag2 = scene.baseSceneName.Equals("arena"); if (num && !flag) { return !flag2; } return false; } private bool IsRecycler(EquipmentSlot slot) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) return (Object)(object)EquipmentCatalog.GetEquipmentDef((EquipmentIndex)((slot == null) ? (-1) : ((int)slot.equipmentIndex))) == (Object)(object)Equipment.Recycle; } private int GetEquipmentCharges(EquipmentSlot equipmentSlot) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = equipmentSlot.characterBody.inventory; uint activeEquipmentSlot = inventory.activeEquipmentSlot; return inventory.GetEquipment(activeEquipmentSlot, inventory.FindBestEquipmentSetIndex(false)).charges; } [IteratorStateMachine(typeof(<ExecuteWithDelay>d__11))] private IEnumerator ExecuteWithDelay(Action action, TimeSpan delay) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <ExecuteWithDelay>d__11(0) { action = action, delay = delay }; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "quasikyo.ReduceRecycler"; public const string PLUGIN_NAME = "ReduceRecycler"; public const string PLUGIN_VERSION = "1.3.4"; }