Decompiled source of Challenging Corruptors v1.3.0

BepInEx/plugins/com.stiffmeds.challengingcorruptors.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cards;
using Challenging_Corruptors;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Obeliskial_Essentials;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.stiffmeds.challengingcorruptors")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Allows you to choose the minimum difficulty of corruptors")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+f3b94af21528f935448ccfc4694d64601025c097")]
[assembly: AssemblyProduct("com.stiffmeds.challengingcorruptors")]
[assembly: AssemblyTitle("com.stiffmeds.challengingcorruptors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
public static class EssentialsCompatibility
{
	private static bool? _enabled;

	public static bool Enabled
	{
		get
		{
			bool valueOrDefault = _enabled == true;
			if (!_enabled.HasValue)
			{
				valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.stiffmeds.obeliskialessentials");
				_enabled = valueOrDefault;
			}
			return _enabled.Value;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void EssentialsRegister()
	{
		Essentials.RegisterMod(Plugin.PluginName, "Stiff Meds", "Challenging Corruptors", Plugin.PluginVersion, Plugin.ModDate, "https://github.com/binbinmods/Challenging_Corruptors", (string[])null, "", 100, (string[])null, "", true);
		Plugin.LogInfo(Plugin.PluginGUID + " " + Plugin.PluginVersion + " has loaded with Essentials!");
	}
}
namespace Challenging_Corruptors
{
	[BepInPlugin("com.meds.challengingcorruptors", "com.stiffmeds.challengingcorruptors", "1.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("com.meds.challengingcorruptors");

		public static string PluginName;

		public static string PluginVersion;

		public static string PluginGUID;

		internal static int ModDate = int.Parse(DateTime.Today.ToString("yyyyMMdd"));

		internal static ManualLogSource Log;

		public static string debugBase = "com.stiffmeds.challengingcorruptors ";

		public static ConfigEntry<bool> EnableMod { get; set; }

		public static ConfigEntry<bool> EnableDebugging { get; set; }

		public static ConfigEntry<bool> ForceUpwind { get; set; }

		public static ConfigEntry<int> medsMinimumCorruptor { get; private set; }

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0039: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0066: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00c5: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			string text = "Challenging Corruptors";
			EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableMod"), true, new ConfigDescription("Enables the mod. If false, the mod will not work then next time you load the game.", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableDebugging = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableDebugging"), false, new ConfigDescription("Enables the debugging", (AcceptableValueBase)null, Array.Empty<object>()));
			medsMinimumCorruptor = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Minimum Corruptor Difficulty", 4, new ConfigDescription("1: easy (vanilla); 2: average; 3: hard; 4: extreme; 5: tabula rasa only o:", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5), Array.Empty<object>()));
			ForceUpwind = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "ForceUpwind"), false, new ConfigDescription("Forces Upwind to always be an option for a corruptor.", (AcceptableValueBase)null, Array.Empty<object>()));
			medsMinimumCorruptor.SettingChanged += delegate
			{
				Challenging_Corruptors.UpdateChallengeCorruptors();
			};
			ForceUpwind.SettingChanged += delegate
			{
				Challenging_Corruptors.UpdateChallengeCorruptors();
			};
			PluginName = "com.stiffmeds.challengingcorruptors";
			PluginVersion = "1.3.0";
			PluginGUID = "com.stiffmeds.challengingcorruptors";
			if (EnableMod.Value)
			{
				if (EssentialsCompatibility.Enabled)
				{
					EssentialsCompatibility.EssentialsRegister();
				}
				else
				{
					LogInfo(PluginGUID + " " + PluginVersion + " has loaded!");
				}
				harmony.PatchAll();
			}
		}

		internal static void LogDebug(string msg, [CallerMemberName] string caller = "")
		{
			if (EnableDebugging.Value)
			{
				Log.LogDebug((object)(debugBase + "- " + caller + " - " + msg));
			}
		}

		internal static void LogInfo(string msg)
		{
			Log.LogInfo((object)(debugBase + msg));
		}

		internal static void LogError(string msg, [CallerMemberName] string caller = "")
		{
			Log.LogError((object)(debugBase + "- " + caller + " - " + msg));
		}

		public static IEnumerator RunAfter(IEnumerator original, Action action)
		{
			while (original.MoveNext())
			{
				yield return original.Current;
			}
			action();
		}
	}
	[HarmonyPatch]
	public class Challenging_Corruptors
	{
		public static List<string> medsCorruptors = new List<string>();

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "CreateGameContentRoutine")]
		public static void CreateGameContentRoutinePrefix(ref IEnumerator __result)
		{
			Plugin.LogDebug("Creating game content routine", "CreateGameContentRoutinePrefix");
			__result = Plugin.RunAfter(__result, CreateGameContentPostfix);
		}

		public static void CreateGameContentPostfix()
		{
			medsCorruptors = Globals.Instance.CardListByType[(CardType)27];
			UpdateChallengeCorruptors();
		}

		public static void UpdateChallengeCorruptors()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Invalid comparison between Unknown and I4
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Invalid comparison between Unknown and I4
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Invalid comparison between Unknown and I4
			Plugin.LogDebug("Updating challenge corruptors", "UpdateChallengeCorruptors");
			Globals.Instance.CardListByType[(CardType)27] = new List<string>();
			if (Plugin.medsMinimumCorruptor.Value == 5)
			{
				AddCorruptor("windsofamnesia");
			}
			else
			{
				foreach (string medsCorruptor in medsCorruptors)
				{
					CardRealtimeData cardData = Globals.Instance.GetCardData(medsCorruptor, true);
					if (cardData != (CardRealtimeData)null && (((int)cardData.CardRarity == 0 && Plugin.medsMinimumCorruptor.Value == 1) || ((int)cardData.CardRarity == 1 && Plugin.medsMinimumCorruptor.Value <= 2) || ((int)cardData.CardRarity == 2 && Plugin.medsMinimumCorruptor.Value <= 3) || (int)cardData.CardRarity == 3))
					{
						Globals.Instance.CardListByType[(CardType)27].Add(medsCorruptor);
					}
				}
			}
			if (Plugin.ForceUpwind.Value)
			{
				if (Plugin.medsMinimumCorruptor.Value == 4)
				{
					MakeCardEpic("upwind");
					MakeCardEpic("upwinda");
					MakeCardEpic("upwindb");
					MakeCardEpic("upwindrare");
				}
				AddCorruptor("upwind");
			}
		}

		public static void AddCorruptor(string corruptorID)
		{
			if (!Globals.Instance.CardListByType[(CardType)27].Contains(corruptorID))
			{
				Plugin.LogDebug("Adding corruptor " + corruptorID + " and variants", "AddCorruptor");
				Globals.Instance.CardListByType[(CardType)27].Add(corruptorID);
				Globals.Instance.CardListByType[(CardType)27].Add(corruptorID + "a");
				Globals.Instance.CardListByType[(CardType)27].Add(corruptorID + "b");
				Globals.Instance.CardListByType[(CardType)27].Add(corruptorID + "rare");
			}
			else
			{
				Plugin.LogDebug("Corruptor " + corruptorID + " already present", "AddCorruptor");
			}
		}

		public static void MakeCardEpic(string cardID)
		{
			CardRealtimeData cardData = Globals.Instance.GetCardData(cardID, true);
			Dictionary<string, CardRealtimeData> value = Traverse.Create((object)Globals.Instance).Field("_Cards").GetValue<Dictionary<string, CardRealtimeData>>();
			Dictionary<string, CardDataNew> value2 = Traverse.Create((object)Globals.Instance).Field("_CardsSource").GetValue<Dictionary<string, CardDataNew>>();
			CardRealtimeData val = CloneWithRarity(cardData, (CardRarity)3);
			CardDataNew value3;
			CardDataNew val2 = (value2.TryGetValue(cardID, out value3) ? value3 : null);
			if (val != (CardRealtimeData)null)
			{
				value[cardID] = val;
				Traverse.Create((object)Globals.Instance).Field("_Cards").SetValue((object)value);
				Traverse.Create((object)Globals.Instance).Field("_CardsSource").SetValue((object)value2);
				Plugin.LogDebug("Made Realtime " + cardID + " epic", "MakeCardEpic");
			}
			if ((Object)(object)val2 != (Object)null)
			{
				Traverse.Create((object)val2).Field("cardRarity").SetValue((object)(CardRarity)3);
				value2[cardID] = val2;
				Traverse.Create((object)Globals.Instance).Field("_CardsSource").SetValue((object)value2);
				Plugin.LogDebug("Made New " + cardID + " epic", "MakeCardEpic");
			}
		}

		public static CardRealtimeData CloneWithRarity(CardRealtimeData card, CardRarity newRarity)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			MethodInfo method = typeof(CardRealtimeData).GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic);
			CardRealtimeData val = (CardRealtimeData)method.Invoke(card, null);
			FieldInfo field = typeof(CardRealtimeData).GetField("<CardRarity>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				throw new InvalidOperationException("Could not find backing field for CardRarity — check the actual field name.");
			}
			field.SetValue(val, newRarity);
			return val;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.stiffmeds.challengingcorruptors";

		public const string PLUGIN_NAME = "com.stiffmeds.challengingcorruptors";

		public const string PLUGIN_VERSION = "1.3.0";
	}
}