Decompiled source of The Rat in Frozen Dark v1.1.0

BepInEx/plugins/com.shazixnar.TheRatinFrozenDarkTraits.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Obeliskial_Content;
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.shazixnar.TheRatinFrozenDarkTraits")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("The Rat in Frozen Dark Traits, made by Shazixnar")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("The Rat in Frozen Dark")]
[assembly: AssemblyTitle("com.shazixnar.TheRatinFrozenDarkTraits")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 TraitMod
{
	[HarmonyPatch]
	internal class Traits
	{
		public static string[] myTraitList = new string[3] { "zekdarkfeast", "zekcursepower", "zekfrozendark" };

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "IndirectDamage")]
		public static void IndirectDamagePrefix(ref Character __instance, ref int damage, ref DamageType damageType, ref string effect)
		{
			if ((int)damageType == 9 && AtOManager.Instance.TeamHaveTrait("zekdarkestabyss") && !__instance.IsHero && effect == "dark")
			{
				int auraCharges = __instance.GetAuraCharges("dark");
				damage += Functions.FuncRoundToInt((float)damage * 0.05f * (float)auraCharges);
				damage += Functions.FuncRoundToInt((float)damage * 0.3f);
			}
		}

		public static void myDoTrait(string _trait, ref Trait __instance)
		{
			//IL_0012: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Expected O, but got Unknown
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			EventActivation value = Traverse.Create((object)__instance).Field("theEvent").GetValue<EventActivation>();
			Character value2 = Traverse.Create((object)__instance).Field("character").GetValue<Character>();
			Character value3 = Traverse.Create((object)__instance).Field("target").GetValue<Character>();
			int value4 = Traverse.Create((object)__instance).Field("auxInt").GetValue<int>();
			string value5 = Traverse.Create((object)__instance).Field("auxString").GetValue<string>();
			CardData value6 = Traverse.Create((object)__instance).Field("castedCard").GetValue<CardData>();
			Traverse.Create((object)__instance).Field("character").SetValue((object)value2);
			Traverse.Create((object)__instance).Field("target").SetValue((object)value3);
			Traverse.Create((object)__instance).Field("theEvent").SetValue((object)value);
			Traverse.Create((object)__instance).Field("auxInt").SetValue((object)value4);
			Traverse.Create((object)__instance).Field("auxString").SetValue((object)value5);
			Traverse.Create((object)__instance).Field("castedCard").SetValue((object)value6);
			TraitData traitData = Globals.Instance.GetTraitData(_trait);
			List<CardData> list = new List<CardData>();
			List<string> heroHand = MatchManager.Instance.GetHeroHand(value2.HeroIndex);
			Hero[] teamHero = MatchManager.Instance.GetTeamHero();
			NPC[] teamNPC = MatchManager.Instance.GetTeamNPC();
			switch (_trait)
			{
			case "zekdarkfeast":
			{
				if (!((Object)(object)value2.HeroData != (Object)null))
				{
					break;
				}
				int num2 = value2.EffectCharges("dark");
				int num3 = 0;
				if (num2 >= 5 && num2 < 20)
				{
					num3 = 1;
				}
				else if (num2 >= 20)
				{
					num3 = 2;
				}
				if (num3 <= 0)
				{
					break;
				}
				heroHand = MatchManager.Instance.GetHeroHand(value2.HeroIndex);
				List<CardData> list2 = new List<CardData>();
				for (int k = 0; k < heroHand.Count; k++)
				{
					CardData cardData = MatchManager.Instance.GetCardData(heroHand[k]);
					if (cardData.GetCardFinalCost() > 0)
					{
						list2.Add(cardData);
					}
				}
				for (int l = 0; l < list2.Count; l++)
				{
					CardData val3 = list2[l];
					val3.EnergyReductionTemporal += num3;
					MatchManager.Instance.UpdateHandCards();
					CardItem cardFromTableByIndex = MatchManager.Instance.GetCardFromTableByIndex(val3.InternalId);
					cardFromTableByIndex.PlayDissolveParticle();
					cardFromTableByIndex.ShowEnergyModification(-num3);
					((CharacterItem)value2.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_Dark Feast", ""), (CombatScrollEffectType)7);
					MatchManager.Instance.CreateLogCardModification(val3.InternalId, MatchManager.Instance.GetHero(value2.HeroIndex));
				}
				break;
			}
			case "zekcursepower":
				if (value2 != null && value2.GetHp() > 0)
				{
					int num = Functions.FuncRoundToInt((float)value4 * 0.15f);
					CardClass val = (CardClass)11;
					if ((Object)(object)value6 != (Object)null)
					{
						val = value6.CardClass;
					}
					num = value2.HealWithCharacterBonus(num, val, 0);
					num = value2.HealReceivedFinal(num, false);
					value2.ModifyHp(num, true, true);
					CastResolutionForCombatText val2 = new CastResolutionForCombatText();
					val2.heal = num;
					if ((Object)(object)value2.HeroItem != (Object)null)
					{
						((CharacterItem)value2.HeroItem).ScrollCombatTextDamageNew(val2);
					}
					else if ((Object)(object)value2.NPCItem != (Object)null)
					{
						((CharacterItem)value2.NPCItem).ScrollCombatTextDamageNew(val2);
					}
				}
				break;
			case "zekfrozendark":
				if (!((Object)(object)MatchManager.Instance != (Object)null) || !((Object)(object)value6 != (Object)null))
				{
					break;
				}
				traitData = Globals.Instance.GetTraitData("zekfrozendark");
				if ((MatchManager.Instance.activatedTraits != null && MatchManager.Instance.activatedTraits.ContainsKey("zekfrozendark") && MatchManager.Instance.activatedTraits["zekfrozendark"] > traitData.TimesPerTurn - 1) || MatchManager.Instance.energyJustWastedByHero <= 0 || (!value6.GetCardTypes().Contains((CardType)6) && !value6.GetCardTypes().Contains((CardType)9)) || !((Object)(object)value2.HeroData != (Object)null))
				{
					break;
				}
				if (!MatchManager.Instance.activatedTraits.ContainsKey("zekfrozendark"))
				{
					MatchManager.Instance.activatedTraits.Add("zekfrozendark", 1);
				}
				else
				{
					MatchManager.Instance.activatedTraits["zekfrozendark"]++;
				}
				MatchManager.Instance.SetTraitInfoText();
				if (value6.GetCardTypes().Contains((CardType)6))
				{
					value2.ModifyEnergy(1, true);
					if ((Object)(object)value2.HeroItem != (Object)null)
					{
						((CharacterItem)value2.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_Frozen Dark", "") + TextChargesLeft(MatchManager.Instance.activatedTraits["zekfrozendark"], traitData.TimesPerTurn), (CombatScrollEffectType)7);
						EffectsManager.Instance.PlayEffectAC("energy", true, ((CharacterItem)value2.HeroItem).CharImageT, false, 0f);
					}
					NPC[] teamNPC2 = MatchManager.Instance.GetTeamNPC();
					for (int i = 0; i < teamNPC2.Length; i++)
					{
						if (teamNPC2[i] != null && ((Character)teamNPC2[i]).Alive)
						{
							((Character)teamNPC2[i]).SetAuraTrait(value2, "dark", 1);
						}
					}
				}
				else
				{
					if (!value6.GetCardTypes().Contains((CardType)9))
					{
						break;
					}
					NPC[] teamNPC3 = MatchManager.Instance.GetTeamNPC();
					for (int j = 0; j < teamNPC3.Length; j++)
					{
						if (teamNPC3[j] != null && ((Character)teamNPC3[j]).Alive)
						{
							((Character)teamNPC3[j]).SetAuraTrait(value2, "scourge", 2);
							((Character)teamNPC3[j]).SetAuraTrait(value2, "chill", 3);
						}
					}
				}
				break;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Trait), "DoTrait")]
		public static bool DoTrait(EventActivation _theEvent, string _trait, Character _character, Character _target, int _auxInt, string _auxString, CardData _castedCard, ref Trait __instance)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MatchManager.Instance == (Object)null)
			{
				return false;
			}
			Traverse.Create((object)__instance).Field("character").SetValue((object)_character);
			Traverse.Create((object)__instance).Field("target").SetValue((object)_target);
			Traverse.Create((object)__instance).Field("theEvent").SetValue((object)_theEvent);
			Traverse.Create((object)__instance).Field("auxInt").SetValue((object)_auxInt);
			Traverse.Create((object)__instance).Field("auxString").SetValue((object)_auxString);
			Traverse.Create((object)__instance).Field("castedCard").SetValue((object)_castedCard);
			if (Content.medsCustomTraitsSource.Contains(_trait) && myTraitList.Contains(_trait))
			{
				myDoTrait(_trait, ref __instance);
				return false;
			}
			return true;
		}

		public static string TextChargesLeft(int currentCharges, int chargesTotal)
		{
			int num = currentCharges;
			int num2 = chargesTotal;
			return "<br><color=#FFF>" + num + "/" + num2 + "</color>";
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GlobalAuraCurseModificationByTraitsAndItems")]
		public static void GlobalAuraCurseModificationByTraitsAndItemsPostfix(ref AtOManager __instance, ref AuraCurseData __result, string _type, string _acId, Character _characterCaster, Character _characterTarget)
		{
			bool flag = false;
			bool flag2 = false;
			if (_characterCaster != null && _characterCaster.IsHero)
			{
				flag = _characterCaster.IsHero;
			}
			if (_characterTarget != null && _characterTarget.IsHero)
			{
				flag2 = true;
			}
			float num = 2f;
			if (_acId == "dark")
			{
				if (_type == "set")
				{
					if (!flag2)
					{
						if (__instance.TeamHaveTrait("zekdarkfeast"))
						{
							__result.ResistModifiedPercentagePerStack = -1.5f;
						}
						if (__instance.TeamHaveTrait("malukahshadowform"))
						{
							num += 0.5f;
						}
						if (__instance.TeamHavePerk("mainperkdark2c"))
						{
							num += 0.7f;
						}
						if (__instance.TeamHavePerk("mainperkChill2d"))
						{
							int auraCharges = _characterTarget.GetAuraCharges("chill");
							num += (float)(auraCharges / 20) * 0.1f;
						}
					}
					else if (flag2 && _characterTarget != null && __instance.CharacterHaveTrait(_characterTarget.SubclassName, "zekcursepower"))
					{
						__result.AuraDamageType = (DamageType)10;
						__result.ExplodeAtStacks = 44;
						__result.AuraDamageIncreasedPercentPerStack = 10f;
						__result.Removable = false;
						__result.ResistModifiedPercentagePerStack = 0f;
					}
				}
				else if (_type == "consume" && !flag)
				{
					if (__instance.TeamHaveTrait("malukahshadowform"))
					{
						num += 0.5f;
					}
					if (__instance.TeamHavePerk("mainperkdark2c"))
					{
						num += 0.7f;
					}
					if (__instance.TeamHavePerk("mainperkChill2d"))
					{
						int auraCharges2 = _characterCaster.GetAuraCharges("chill");
						num += (float)(auraCharges2 / 20) * 0.1f;
					}
				}
				__result.DamageWhenConsumedPerCharge = num;
			}
			else if (_acId == "chill" && _type == "set" && !flag2 && __instance.TeamHaveTrait("zekfrozendark"))
			{
				__result.MaxCharges = 100;
				__result.MaxMadnessCharges = 100;
			}
		}
	}
}
namespace TheRatinFrozenDark
{
	[BepInPlugin("com.shazixnar.TheRatinFrozenDarkTraits", "The Rat in Frozen Dark", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("AcrossTheObelisk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal const int ModDate = 20231217;

		private readonly Harmony harmony = new Harmony("com.shazixnar.TheRatinFrozenDarkTraits");

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"com.shazixnar.TheRatinFrozenDarkTraits 1.0.2 has loaded!");
			Essentials.RegisterMod("The Rat in Frozen Dark", "Shazixnar", "Zek is better at curse or corrupting Cold cards now.", "1.0.2", 20231217, "https://across-the-obelisk.thunderstore.io/package/Shazixnar/The_Rat_in_Frozen_Dark/", (string[])null, "The Rat in Frozen Dark", 100, new string[5] { "content", "hero", "trait", "card", "perk" }, "", true);
			Essentials.medsTexts["custommainperkdark2c"] = "Dark explosion on enemies deals 0.7 more damage per charge.";
			Essentials.medsTexts["custommainperkchill2d"] = "Chill on enemies increases Dark explosion 0.1 more damage per 20 charges.";
			harmony.PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.shazixnar.TheRatinFrozenDarkTraits";

		public const string PLUGIN_NAME = "The Rat in Frozen Dark";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}