Decompiled source of Vermin Tribe v1.4.0

VerminTribe.dll

Decompiled 11 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
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 DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Card;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VerminTribe.Resources;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("VerminTribe")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Makes the squirrel head into the vermin tribe")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VerminTribe")]
[assembly: AssemblyTitle("VerminTribe")]
[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 VerminTribe
{
	[BepInPlugin("extraVoid.inscryption.VerminTribe", "Vermin Tribe", "1.2.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string APIGUID = "cyantist.inscryption.api";

		public const string PluginGuid = "extraVoid.inscryption.VerminTribe";

		private const string PluginName = "Vermin Tribe";

		private const string PluginVersion = "1.2.1";

		public static string Directory;

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> configRandomStarterTribe;

		internal static ConfigEntry<bool> configNostartingHead;

		internal static ConfigEntry<bool> configSquirrelsAreVerminInKCM;

		internal static ConfigEntry<bool> configSquirrelsAreVermin;

		public static bool isSideDeckInstalled;

		public static bool KCM => CardLoader.GetCardByName("Boulder").HasAbility((Ability)105);

		private void Awake()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			configRandomStarterTribe = ((BaseUnityPlugin)this).Config.Bind<bool>("Random Starter Head", "Random Tribe", true, "Makes it so if you have the squirrel head unlocked, you instead get a random starting head instead of always squirrels.");
			configNostartingHead = ((BaseUnityPlugin)this).Config.Bind<bool>("Random Starter Head", "No Tribe", false, "Makes it so you dont start with any tribe head. this will override the above option if set to true.");
			configSquirrelsAreVerminInKCM = ((BaseUnityPlugin)this).Config.Bind<bool>("Squirrels are Vermin (Config is ignored if sidedeck mod is installed)", "Should Squirrels be Vermin in KCM?", false, "Set this to true to make Squirrels apart of the vermin tribe in KCM.");
			configSquirrelsAreVermin = ((BaseUnityPlugin)this).Config.Bind<bool>("Squirrels are Vermin (Config is ignored if sidedeck mod is installed)", "Should Squirrels be Vermin in act 1?", true, "Set this to false if you feel Squirrels being apart of the Vermin tribe is too OP.");
			Harmony val = new Harmony("extraVoid.inscryption.VerminTribe");
			val.PatchAll();
		}

		private void Start()
		{
			if (Chainloader.PluginInfos.ContainsKey("zorro.inscryption.infiniscryption.sidedecks"))
			{
				isSideDeckInstalled = true;
			}
		}
	}
}
namespace VerminTribe.Resources
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Artwork
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("VerminTribe.Resources.Artwork", typeof(Artwork).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] tribeicon_squirrel
		{
			get
			{
				object @object = ResourceManager.GetObject("tribeicon_squirrel", resourceCulture);
				return (byte[])@object;
			}
		}

		internal static byte[] tribeicon_squirrel_reward
		{
			get
			{
				object @object = ResourceManager.GetObject("tribeicon_squirrel_reward", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Artwork()
		{
		}
	}
}
namespace VerminTribe.Patchers
{
	internal class RodentTribeCardTweaks
	{
		[HarmonyPatch(typeof(LoadingScreenManager), "LoadGameData")]
		public class LoadingScreenManager_LoadGameData
		{
			public static void Postfix()
			{
				List<CardInfo> allData = ScriptableObjectLoader<CardInfo>.AllData;
				for (int i = 0; i < allData.Count; i++)
				{
					CardInfo val = allData[i];
					switch (((Object)val).name)
					{
					case "Squirrel":
						if (Plugin.KCM)
						{
							Plugin.Log.LogMessage((object)"Vermin Tribe KCM detected");
							if (!Plugin.configSquirrelsAreVerminInKCM.Value)
							{
								Plugin.Log.LogMessage((object)"Vermin Tribe Squirrels removed from verminin KCM");
								if (!val.IsOfTribe((Tribe)1))
								{
									val.tribes.Remove((Tribe)1);
								}
							}
							break;
						}
						Plugin.Log.LogMessage((object)"Vermin Tribe KCM not detected");
						if (!Plugin.configSquirrelsAreVermin.Value)
						{
							Plugin.Log.LogMessage((object)"Vermin Tribe squirrels set to be not vermin");
							if (!val.IsOfTribe((Tribe)1))
							{
								val.tribes.Remove((Tribe)1);
							}
						}
						else
						{
							Plugin.Log.LogMessage((object)"Vermin Tribe squirrels set to be vermin");
							if (!val.IsOfTribe((Tribe)1))
							{
								val.tribes.Add((Tribe)1);
							}
						}
						break;
					case "Beaver":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "Warren":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "RatKing":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "FieldMouse":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "Porcupine":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "Mole":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "MoleMan":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "Rabbit":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "Stoat":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "Opossum":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "PackRat":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "Void_Rabbit":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "Garethmod_Lemming":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "eri_RatSkeleton":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "eri_Hedgehog":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "lifecost_dice_mouse":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "lifepack_horn_cottentail":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "IGCC_rabbit_mum":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					case "IGCC_unskinned_porcupine":
						if (!val.IsOfTribe((Tribe)1))
						{
							val.tribes.Add((Tribe)1);
						}
						break;
					}
				}
			}
		}
	}
	internal class RodentTribeChoicePatches
	{
		[HarmonyPatch(typeof(Part1CardChoiceGenerator), "GenerateTribeChoices")]
		public class Part1CardChoiceGenerator_GenerateTribeChoices
		{
			[HarmonyPostfix]
			public static void Postfix(ref List<CardChoice> __result, int randomSeed)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				int num = 1;
				if (num == 1)
				{
					List<CardChoice> list = __result;
					list.Add(new CardChoice
					{
						tribe = (Tribe)1
					});
					list.RemoveAt(SeededRandom.Range(0, list.Count, randomSeed++));
					__result = list;
				}
			}
		}

		[HarmonyPatch(typeof(CardSingleChoicesSequencer), "GetCardbackTexture")]
		public class CardSingleChoicesSequencer_GetCardbackTexture
		{
			[HarmonyPostfix]
			public static void Postfix(ref Texture __result, CardChoice choice)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Invalid comparison between Unknown and I4
				if ((Object)(object)__result == (Object)null && (int)choice.tribe == 1)
				{
					__result = LoadTextureFromResource(Artwork.tribeicon_squirrel_reward);
				}
			}
		}

		public static Texture LoadTextureFromResource(byte[] imgBytes)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, imgBytes);
			((Texture)val).filterMode = (FilterMode)0;
			return (Texture)(object)val;
		}
	}
	internal class RodentTribeHeadPatches
	{
		[HarmonyPatch(typeof(CardDisplayer3D), "UpdateTribeIcon")]
		public class CardDisplayer3D_UpdateTribeIcon_Patch
		{
			[HarmonyPrefix]
			public static bool Prefix(CardDisplayer3D __instance, CardInfo info)
			{
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Invalid comparison between Unknown and I4
				foreach (SpriteRenderer tribeIconRenderer in __instance.tribeIconRenderers)
				{
					tribeIconRenderer.sprite = null;
				}
				for (int i = 0; i < 7; i++)
				{
					if (!info.IsOfTribe((Tribe)i))
					{
						continue;
					}
					foreach (SpriteRenderer tribeIconRenderer2 in __instance.tribeIconRenderers)
					{
						if ((Object)(object)tribeIconRenderer2.sprite == (Object)null)
						{
							SpriteRenderer val = tribeIconRenderer2;
							string text = "Art/Cards/TribeIcons/tribeicon_";
							Tribe val2 = (Tribe)i;
							if ((int)val2 == 1)
							{
								val.sprite = LoadSpriteFromResource(Artwork.tribeicon_squirrel);
							}
							else
							{
								val.sprite = ResourceBank.Get<Sprite>(text + ((object)(Tribe)(ref val2)).ToString().ToLowerInvariant());
							}
							break;
						}
					}
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(RunState), "InitializeStarterDeckAndItems")]
		public class RunState_InitializeStarterDeckAndItems_Patch
		{
			[HarmonyPostfix]
			public static void Postfix(ref RunState __instance)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				if (StoryEventsData.EventCompleted((StoryEvent)14) && Plugin.configRandomStarterTribe.Value)
				{
					__instance.totemTops.Remove((Tribe)1);
					Tribe item = (Tribe)SeededRandom.Range(1, 6, SaveManager.SaveFile.GetCurrentRandomSeed());
					__instance.totemTops.Add(item);
					if (StoryEventsData.EventCompleted((StoryEvent)103))
					{
						__instance.totemTops.Remove((Tribe)6);
					}
				}
				if (Plugin.configNostartingHead.Value)
				{
					__instance.totemTops.Clear();
				}
			}
		}

		[HarmonyPatch(typeof(BuildTotemSequencer), "GenerateTotemChoices")]
		public class BuildTotemSequencer_GenerateTotemChoices_Patch
		{
			[HarmonyPrefix]
			public static bool Prefix(BuildTotemNodeData nodeData, int randomSeed, ref List<ItemData> __result)
			{
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ce: Expected O, but got Unknown
				//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01da: Expected O, but got Unknown
				//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0206: Unknown result type (might be due to invalid IL or missing references)
				//IL_023a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0241: Expected O, but got Unknown
				//IL_0244: Unknown result type (might be due to invalid IL or missing references)
				//IL_024b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0255: Expected O, but got Unknown
				//IL_0271: Unknown result type (might be due to invalid IL or missing references)
				//IL_02de: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
				List<Tribe> list = new List<Tribe>
				{
					(Tribe)2,
					(Tribe)3,
					(Tribe)4,
					(Tribe)6,
					(Tribe)5
				};
				AddCustomTribesToList(list);
				if (StoryEventsData.EventCompleted((StoryEvent)14) || Plugin.KCM)
				{
					list.Add((Tribe)1);
				}
				for (int i = 0; i < list.Count; i++)
				{
					ManualLogSource log = Plugin.Log;
					Tribe val = list[i];
					log.LogWarning((object)((object)(Tribe)(ref val)).ToString());
				}
				foreach (Tribe totemTop in RunState.Run.totemTops)
				{
					list.Remove(totemTop);
				}
				List<Ability> list2 = new List<Ability>(ProgressionData.Data.learnedAbilities);
				list2.RemoveAll((Ability x) => RunState.Run.totemBottoms.Contains(x) || !AbilitiesUtil.GetInfo(x).metaCategories.Contains((AbilityMetaCategory)1));
				int num = 0;
				if (!ProgressionData.LearnedMechanic((MechanicsConcept)1))
				{
					if (RunState.Run.totemBottoms.Count > 0)
					{
						num = 3;
					}
				}
				else
				{
					num = SeededRandom.Range(1, 3, randomSeed++);
					if (RunState.Run.totemTops.Count == 0)
					{
						num = 2;
					}
					else if (RunState.Run.totemBottoms.Count == 0)
					{
						num = 1;
					}
				}
				num = Mathf.Min(num, list.Count);
				int num2 = Mathf.Min(3 - num, list2.Count);
				List<ItemData> list3 = new List<ItemData>();
				for (int j = 0; j < num; j++)
				{
					TotemTopData val2 = new TotemTopData();
					val2.prerequisites = new TriggerCardPrerequisites();
					val2.prerequisites.tribe = list[SeededRandom.Range(0, list.Count, randomSeed++)];
					list.Remove(val2.prerequisites.tribe);
					list3.Add((ItemData)(object)val2);
				}
				List<ItemData> list4 = new List<ItemData>();
				while (list4.Count < num2)
				{
					TotemBottomData val3 = new TotemBottomData();
					val3.effect = (TotemEffect)0;
					val3.effectParams = new EffectParameters();
					if (list2.Count == 0)
					{
						val3.effectParams.ability = (Ability)1;
						continue;
					}
					int powerLevelRoll = SeededRandom.Range(0, 7, randomSeed++);
					List<Ability> list5 = list2.FindAll((Ability x) => AbilitiesUtil.GetInfo(x).powerLevel <= powerLevelRoll);
					if (list5.Count > 0)
					{
						val3.effectParams.ability = list5[SeededRandom.Range(0, list5.Count, randomSeed++)];
						list2.Remove(val3.effectParams.ability);
						list4.Add((ItemData)(object)val3);
					}
				}
				__result = TotemsUtil.AlternateTopsAndBottoms(list3, list4);
				return false;
			}

			public static void AddCustomTribesToList(List<Tribe> list)
			{
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				List<CardInfo> tribedCards = CardManager.AllCardsCopy.FindAll((CardInfo x) => x.tribes.Count > 0);
				foreach (TribeInfo tribeInfo in TribeManager.NewTribes.Where((TribeInfo x) => x.tribeChoice))
				{
					if (tribedCards.Exists((CardInfo ci) => ci.IsOfTribe(tribeInfo.tribe)))
					{
						list.Add(tribeInfo.tribe);
					}
				}
				list.RemoveAll((Tribe x) => !tribedCards.Exists((CardInfo ci) => ci.IsOfTribe(x)));
			}
		}

		public static float Yposition = 0.5f;

		public static float Xposition = 0.5f;

		public static float pixelPerUnity = 100f;

		public static Vector2 vector = new Vector2(Xposition, Yposition);

		public static Sprite LoadSpriteFromResource(byte[] imgBytes)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, imgBytes);
			((Texture)val).filterMode = (FilterMode)0;
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), vector, pixelPerUnity);
		}
	}
}