Decompiled source of AutoSkipChestAnimations v1.0.0

AutoSkipChestAnimations.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Assets.Scripts.Actors.Player;
using Assets.Scripts.Managers;
using Assets.Scripts.Saves___Serialization.Progression.Achievements;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AutoSkipChestAnimations")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Automatically sets Skip Chest Animation to true when all Banishes have been used")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4")]
[assembly: AssemblyProduct("AutoSkipChestAnimations")]
[assembly: AssemblyTitle("AutoSkipChestAnimations")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte flag)
		{
			NullableFlags = new byte[1] { flag };
		}

		public NullableAttribute(byte[] flags)
		{
			NullableFlags = flags;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte flag)
		{
			Flag = flag;
		}
	}
}
namespace AutoSkipChestAnimations
{
	[BepInPlugin("ZeusesNeckMeat_AutoSkipChestAnimations", "AutoSkipChestAnimations", "0.1.0")]
	public class AutoSkipChestAnimations : BasePlugin
	{
		public static ManualLogSource Logger;

		private static AutoSkipChestAnimations _instance;

		public AutoSkipChestAnimations()
		{
			Logger = ((BasePlugin)this).Log;
			_instance = this;
		}

		public override void Load()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Harmony harmony = new Harmony("ZeusesNeckMeat_AutoSkipChestAnimations");
			SkipChestConfig.SetupConfig(((BasePlugin)this).Config);
			if (SkipChestConfig.IsEnabled)
			{
				Logger.LogDebug((object)"Mod enabled. Applying Harmony patches...");
				harmony.PatchAll();
			}
			else
			{
				Logger.LogDebug((object)"Mod is disabled. Skipping Harmony patching, but listening for config updates...");
			}
			SkipChestConfig.OnIsEnabledChanged(delegate
			{
				if (SkipChestConfig.IsEnabled)
				{
					Logger.LogInfo((object)"Skip Chest Animations has been enabled via config. Applying Harmony patches...");
					harmony.PatchAll();
				}
			});
		}
	}
	internal static class Constants
	{
		public const string MODNAME = "AutoSkipChestAnimations";

		public const string AUTHOR = "ZeusesNeckMeat";

		public const string GUID = "ZeusesNeckMeat_AutoSkipChestAnimations";

		public const string VERSION = "0.1.0";
	}
	internal enum AutoEnableSkipChestAnimations
	{
		BanishesUsed,
		SkipsUsed,
		BanishesAndSkipsUsed
	}
	[HarmonyPatch(typeof(LevelupScreen), "Skip")]
	internal class LevelUpScreenPatches
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			if (!SkipChestConfig.IsEnabled)
			{
				AutoSkipChestAnimations.Logger.LogDebug((object)"Auto Disable Skip Chest Animations on Level Up is disabled, not disabling Skip Chest Animations setting when leveling up");
				return;
			}
			if (SaveManager.Instance.config.cfGameSettings.skip_chest_animation == 1)
			{
				AutoSkipChestAnimations.Logger.LogDebug((object)"Skip chest animations already enabled.");
				return;
			}
			ManualLogSource logger = AutoSkipChestAnimations.Logger;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(33, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Skips Info: Skips: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(MyPlayer.Instance.inventory.skips);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Skips Used: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(MyPlayer.Instance.inventory.skipsUsed);
			}
			logger.LogDebug(val);
		}
	}
	[HarmonyPatch(typeof(MapController), "RestartRun")]
	internal static class MapController_RestartRun_Patch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			AutoSkipChestAnimations.Logger.LogDebug((object)"RestartRun called, checking if Skip Chest Animations should be disabled when restarting a run...");
			if (!SkipChestConfig.ShouldAutoDisableOnStart)
			{
				AutoSkipChestAnimations.Logger.LogDebug((object)"Auto Disable Skip Chest Animations on Run Start is disabled, not disabling Skip Chest Animations setting when restarting a run");
				return;
			}
			AutoSkipChestAnimations.Logger.LogDebug((object)"Disabling Skip Chest Animations setting on run restart...");
			SaveManager.Instance.config.cfGameSettings.skip_chest_animation = 0;
			SaveManager.Instance.SaveConfig();
		}
	}
	[HarmonyPatch(typeof(MapController), "StartNewMap")]
	internal static class MapController_StartNewMap_Patch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			if (!SkipChestConfig.ShouldAutoDisableOnStart)
			{
				AutoSkipChestAnimations.Logger.LogDebug((object)"Auto Disable Skip Chest Animations on Run Start is disabled, not disabling Skip Chest Animations setting when starting a new map");
				return;
			}
			bool flag = MapController.IsFirstStage();
			ManualLogSource logger = AutoSkipChestAnimations.Logger;
			bool flag2 = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(36, 1, ref flag2);
			if (flag2)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("StartNewMap called. Is First Stage: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(flag);
			}
			logger.LogDebug(val);
			if (!flag)
			{
				AutoSkipChestAnimations.Logger.LogDebug((object)"Will only attempt to auto disable Skip Chest Animations on the first stage");
				return;
			}
			AutoSkipChestAnimations.Logger.LogDebug((object)"Disabling Skip Chest Animations setting on new map start...");
			SaveManager.Instance.config.cfGameSettings.skip_chest_animation = 0;
			SaveManager.Instance.SaveConfig();
		}
	}
	[HarmonyPatch(typeof(BanishItem), "Set")]
	internal static class BanishItem_Set_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(UnlockableBase unlockable)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			ManualLogSource logger = AutoSkipChestAnimations.Logger;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(118, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("BanishItem.Set called for item: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)unlockable).name);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(". Checking if Skip Chest Animations should be enabled when all banishes are used up...");
			}
			logger.LogDebug(val);
			if (!SkipChestConfig.IsEnabled)
			{
				AutoSkipChestAnimations.Logger.LogDebug((object)"Auto Skip Chest Animations when all banishes used up is disabled, not enabling Skip Chest Animations setting when banishing an item");
				return;
			}
			int banishes = MyPlayer.Instance.inventory.banishes;
			ManualLogSource logger2 = AutoSkipChestAnimations.Logger;
			val = new BepInExDebugLogInterpolatedStringHandler(20, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Banishes Remaining: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(banishes);
			}
			logger2.LogDebug(val);
			if (banishes <= 0)
			{
				AutoSkipChestAnimations.Logger.LogInfo((object)"All banishes have been used. Enabling Skip Chest Animations setting...");
				SaveManager.Instance.config.cfGameSettings.skip_chest_animation = 1;
				SaveManager.Instance.SaveConfig();
			}
			else
			{
				AutoSkipChestAnimations.Logger.LogDebug((object)"Not all banishes have been used");
			}
		}
	}
	internal static class SkipChestConfig
	{
		private static ConfigEntry<bool> _isEnabled;

		private static ConfigEntry<bool> _shouldAutoDisableOnStart;

		public static bool IsEnabled => _isEnabled.Value;

		public static bool ShouldAutoDisableOnStart
		{
			get
			{
				if (IsEnabled)
				{
					return _shouldAutoDisableOnStart.Value;
				}
				return false;
			}
		}

		public static void SetupConfig(ConfigFile configFile)
		{
			_isEnabled = configFile.Bind<bool>("General", "EnableAutoSkipChestAnimations", true, "When enabled the mod will automatically enable or disable Skip Chest Animations when all banishes have been used");
			_shouldAutoDisableOnStart = configFile.Bind<bool>("General", "AutoDisableSkipChestAnimOnRunStart", true, "When enabled the Skip Chest Animations setting will automatically be disabled when a new run starts");
		}

		public static void OnIsEnabledChanged(Action callback)
		{
			_isEnabled.SettingChanged += delegate
			{
				callback();
			};
		}
	}
}