Decompiled source of ReduceRecycler v1.1.3

plugins/ReduceRecycler/ReduceRecycler.dll

Decompiled 7 months ago
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("ReduceRecycler")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReduceRecycler")]
[assembly: AssemblyTitle("ReduceRecycler")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ReduceRecycler;

internal static class ConfigManager
{
	private static ConfigFile OptionsConfig { get; set; }

	internal static ConfigEntry<bool> EnableOnlyAfterTeleporter { 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
		OptionsConfig = new ConfigFile(Paths.ConfigPath + "\\ReduceRecycler.cfg", true);
		ModSettingsManager.SetModDescription("Customize the behavior of the recycler equipment to shorten the time between uses.");
		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));
	}
}
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.1.3")]
public class ReduceRecycler : BaseUnityPlugin
{
	public const string PluginGUID = "quasikyo.ReduceRecycler";

	public const string PluginAuthor = "quasikyo";

	public const string PluginName = "ReduceRecycler";

	public const string PluginVersion = "1.1.3";

	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
		Log.Init(((BaseUnityPlugin)this).Logger);
		Log.Info("Performing setup for ReduceRecycler");
		ConfigManager.Init();
		EquipmentSlot.FireRecycle += (hook_FireRecycle)delegate(orig_FireRecycle orig, EquipmentSlot self)
		{
			bool num = orig.Invoke(self);
			if (num)
			{
				((MonoBehaviour)this).StartCoroutine(ResetRecyclerCooldown(self));
			}
			return num;
		};
	}

	private IEnumerator ResetRecyclerCooldown(EquipmentSlot equipment)
	{
		yield return (object)new WaitForSeconds(0.5f);
		float cooldownTimer = equipment.cooldownTimer;
		float runStopwatch = Run.instance.GetRunStopwatch();
		if (!float.IsInfinity(cooldownTimer))
		{
			bool flag = StageHasTeleporter(Stage.instance.sceneDef) && TeleporterInteraction.instance.isCharged;
			bool flag2 = !ConfigManager.EnableOnlyAfterTeleporter.Value || flag;
			if (GetEquipmentCharges(equipment) == 0 && flag2)
			{
				equipment.characterBody.inventory.DeductActiveEquipmentCooldown(cooldownTimer);
				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 int GetEquipmentCharges(EquipmentSlot equipmentSlot)
	{
		//IL_0013: 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).charges;
	}
}