Decompiled source of ToggleEverything BepInEx v0.2.0

MegabonkToggleEverything.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Assets.Scripts.Inventory__Items__Pickups;
using Assets.Scripts.Saves___Serialization.Progression.Achievements;
using Assets.Scripts.Saves___Serialization.Progression.Unlocks;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
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("MegabonkToggleEverything")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("MegabonkToggleEverything")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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;
		}
	}
}
namespace MegabonkToggleEverything
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MegabonkToggleEverything";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MegabonkToggleEverythingBepInEx
{
	[BepInPlugin("MegabonkToggleEverything", "MegabonkToggleEverything", "0.2.0")]
	public class ToggleEverything : BasePlugin
	{
		internal static ManualLogSource Logger;

		public override void Load()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Harmony val = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(51, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Initialized MegabonkToggleEverything with ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(val.GetPatchedMethods().Count());
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" patches!");
			}
			logger.LogInfo(val2);
		}
	}
	internal static class Extensions
	{
		internal static bool In<T>(this T item, params T[] array)
		{
			return array.Contains(item);
		}

		internal static bool IsModTogglable(this UnlockableBase unlockable)
		{
			if (((Il2CppObjectBase)unlockable).TryCast<WeaponData>() == null && ((Il2CppObjectBase)unlockable).TryCast<TomeData>() == null)
			{
				return ((Il2CppObjectBase)unlockable).TryCast<ItemData>() != null;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class MyAchievementsPatches
	{
		[HarmonyPatch(typeof(MyAchievements), "CanToggleActivation")]
		[HarmonyPrefix]
		private static bool MyAchievements_CanToggleActivation_Prefix(ref bool __result, UnlockableBase unlockable)
		{
			if (unlockable.IsModTogglable())
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(MyAchievements), "IsActivated")]
		[HarmonyPrefix]
		private static bool MyAchievements_IsActivated_Prefix(ref bool __result, UnlockableBase unlockable)
		{
			__result = !SaveManager.Instance.progression.inactivated.Contains(unlockable.GetInternalName());
			return false;
		}

		[HarmonyPatch(typeof(RunUnlockables), "OnNewRunStarted")]
		[HarmonyPostfix]
		private static void RunUnlockables_OnNewRunStarted_Postfix()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			if (SaveManager.Instance.progression.inactivated.Count == 0)
			{
				return;
			}
			ManualLogSource logger = ToggleEverything.Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Banishing:");
			}
			logger.LogInfo(val);
			Enumerator<string> enumerator = SaveManager.Instance.progression.inactivated.GetEnumerator();
			while (enumerator.MoveNext())
			{
				string item = enumerator.Current;
				UnlockableBase val2 = DataManager.Instance.unsortedUnlockables.Find(Predicate<UnlockableBase>.op_Implicit((Func<UnlockableBase, bool>)((UnlockableBase x) => x.GetInternalName() == item && x.IsModTogglable())));
				if ((Object)(object)val2 != (Object)null)
				{
					RunUnlockables.BanishUpgradable(val2);
					ManualLogSource logger2 = ToggleEverything.Logger;
					val = new BepInExInfoLogInterpolatedStringHandler(18, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("- ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)val2).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" / ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(val2.GetInternalName());
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (Upgradable)");
					}
					logger2.LogInfo(val);
				}
				ItemData val3 = DataManager.Instance.unsortedItems.Find(Predicate<ItemData>.op_Implicit((Func<ItemData, bool>)((ItemData x) => ((UnlockableBase)x).GetInternalName() == item)));
				if ((Object)(object)val3 != (Object)null)
				{
					RunUnlockables.BanishItem(val3);
					ManualLogSource logger3 = ToggleEverything.Logger;
					val = new BepInExInfoLogInterpolatedStringHandler(12, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("- ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)val2).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" / ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((UnlockableBase)val3).GetInternalName());
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (Item)");
					}
					logger3.LogInfo(val);
				}
			}
		}
	}
}