Decompiled source of KillingSpree v1.0.0

KillingSpree.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Math;
using Pigeon.Movement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.0")]
[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 KillingSpreeMod
{
	[BepInPlugin("com.coloron.killingspree", "KillingSpree", "1.0.0")]
	[MycoMod(/*Could not decode attribute arguments.*/)]
	public class KillingSpreePlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.coloron.killingspree";

		public const int ModUpgradeID = 88888;

		public const string TARGET_PROPERTY_CLASS = "UpgradeProperty_Bruiser_NoseDiveDamage";

		public static Upgrade CustomUpgradeInstance;

		public static IUpgradable BruiserRef;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading KillingSpree 1.0.0...");
			new Harmony("com.coloron.killingspree").PatchAll();
			PlayerData.AddRegisterUpgradesCallback((Action)InitializeUpgrades);
		}

		private static void InitializeUpgrades()
		{
			//IL_0040: 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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			BruiserRef = PlayerData.FindGear("Bruiser");
			if (BruiserRef == null)
			{
				Debug.LogError((object)"[KillingSpree] Could not find Bruiser gear!");
				return;
			}
			CustomUpgradeParams val = CustomUpgradeParams.Create(BruiserRef, 88888, "Killing Spree", "Increases damage and radius of the nose dive. Kills refund nose dive charge.", (Rarity)3, (Sprite)null);
			ref UpgradeFlags flags = ref val.flags;
			flags = (UpgradeFlags)((uint)flags | 0x2008u);
			UpgradeProperty[] array = (UpgradeProperty[])(object)new UpgradeProperty[1]
			{
				new UpgradeProperty_KillingSpree()
			};
			CustomUpgradeInstance = PlayerData.CreateUpgrade("com.coloron.killingspree", val, array);
			ApplyCustomPattern(CustomUpgradeInstance);
		}

		private static void ApplyCustomPattern(Upgrade upgrade)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)upgrade == (Object)null))
			{
				HexMap val = new HexMap(3, 3);
				val[0, 1].enabled = true;
				val[0, 1].connections = (Direction)10;
				val[0, 2].enabled = true;
				val[0, 2].connections = (Direction)4;
				val[1, 0].enabled = true;
				val[1, 1].enabled = true;
				val[1, 1].connections = (Direction)57;
				val[1, 2].enabled = true;
				SetPrivateField(upgrade, "pattern", val);
			}
		}

		public static float GetTotalBonus(int count, float baseValue)
		{
			float num = 0f;
			for (int i = 1; i <= count; i++)
			{
				num = ((i > 2) ? (num + baseValue / Mathf.Pow(2f, (float)(i - 2))) : (num + baseValue));
			}
			return num;
		}

		public static int GetStackCount(IUpgradable gear)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (gear == null || (Object)(object)CustomUpgradeInstance == (Object)null)
			{
				return 0;
			}
			GearData gearData = PlayerData.GetGearData(gear);
			if (gearData == null)
			{
				return 0;
			}
			int num = 0;
			try
			{
				FieldInfo field = typeof(GearData).GetField("equippedUpgrades", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					IEnumerable enumerable = (IEnumerable)field.GetValue(gearData);
					if (enumerable != null)
					{
						foreach (object item in enumerable)
						{
							FieldInfo field2 = item.GetType().GetField("upgradeID", BindingFlags.Instance | BindingFlags.Public);
							if (field2 != null)
							{
								int num2 = (int)field2.GetValue(item);
								UpgradeInstance upgradeInstanceFromID = PlayerData.GetUpgradeInstanceFromID(num2);
								if (upgradeInstanceFromID != null && (Object)(object)upgradeInstanceFromID.Upgrade != (Object)null && upgradeInstanceFromID.Upgrade.ID == CustomUpgradeInstance.ID)
								{
									num++;
								}
							}
						}
					}
				}
			}
			catch
			{
			}
			return num;
		}

		public static bool IsTurboActive(IUpgradable gear)
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if (gear == null || (Object)(object)CustomUpgradeInstance == (Object)null)
			{
				return false;
			}
			try
			{
				GearData gearData = PlayerData.GetGearData(gear);
				FieldInfo field = typeof(GearData).GetField("equippedUpgrades", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					IEnumerable enumerable = (IEnumerable)field.GetValue(gearData);
					if (enumerable != null)
					{
						foreach (object item in enumerable)
						{
							FieldInfo field2 = item.GetType().GetField("upgradeID", BindingFlags.Instance | BindingFlags.Public);
							if (field2 != null)
							{
								int num = (int)field2.GetValue(item);
								UpgradeInstance upgradeInstanceFromID = PlayerData.GetUpgradeInstanceFromID(num);
								if (upgradeInstanceFromID != null && upgradeInstanceFromID.Upgrade.ID == CustomUpgradeInstance.ID && upgradeInstanceFromID.IsTurbocharged)
								{
									return true;
								}
							}
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		public static bool IsKneeDiveEquipped(IUpgradable gear)
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (gear == null)
			{
				return false;
			}
			try
			{
				GearData gearData = PlayerData.GetGearData(gear);
				if (gearData == null)
				{
					return false;
				}
				FieldInfo field = typeof(GearData).GetField("equippedUpgrades", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					IEnumerable enumerable = (IEnumerable)field.GetValue(gearData);
					if (enumerable != null)
					{
						foreach (object item in enumerable)
						{
							FieldInfo field2 = item.GetType().GetField("upgradeID", BindingFlags.Instance | BindingFlags.Public);
							if (!(field2 != null))
							{
								continue;
							}
							int num = (int)field2.GetValue(item);
							UpgradeInstance upgradeInstanceFromID = PlayerData.GetUpgradeInstanceFromID(num);
							if (upgradeInstanceFromID == null || !((Object)(object)upgradeInstanceFromID.Upgrade != (Object)null))
							{
								continue;
							}
							bool flag = false;
							UpgradePropertyList properties = upgradeInstanceFromID.Upgrade.Properties;
							foreach (UpgradeProperty item2 in (UpgradePropertyList)(ref properties))
							{
								if (item2 != null && ((object)item2).GetType().Name == "UpgradeProperty_Bruiser_NoseDiveDamage")
								{
									flag = true;
									break;
								}
							}
							if (flag)
							{
								string text = ((Object)upgradeInstanceFromID.Upgrade).name ?? "";
								string text2 = upgradeInstanceFromID.Upgrade.GetInstanceName(0) ?? "";
								if (text.IndexOf("Knee", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("Knee", StringComparison.OrdinalIgnoreCase) >= 0)
								{
									return true;
								}
							}
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		public static void ApplyDirectHeal(Player p, float amount)
		{
			if ((Object)(object)p == (Object)null)
			{
				return;
			}
			try
			{
				FieldInfo field = typeof(Player).GetField("data", BindingFlags.Instance | BindingFlags.Public);
				if (!(field != null))
				{
					return;
				}
				object value = field.GetValue(p);
				FieldInfo field2 = value.GetType().GetField("health", BindingFlags.Instance | BindingFlags.Public);
				if (!(field2 != null))
				{
					return;
				}
				float num = (float)field2.GetValue(value);
				float num2 = num + amount;
				FieldInfo field3 = value.GetType().GetField("maxHealth", BindingFlags.Instance | BindingFlags.Public);
				if (field3 != null)
				{
					float num3 = (float)field3.GetValue(value);
					if (num2 > num3)
					{
						num2 = num3;
					}
				}
				field2.SetValue(value, num2);
				field.SetValue(p, value);
			}
			catch
			{
			}
		}

		public static bool SetPrivateField(object target, string name, object value)
		{
			Type type = target.GetType();
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			while (field == null && type.BaseType != null)
			{
				type = type.BaseType;
				field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (field != null)
			{
				field.SetValue(target, value);
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(NoseDiveUpgrade), "EndDiveSlam")]
	public static class NoseDivePatch
	{
		private static float _originalDamage;

		private static float _originalRadius;

		private static int _killsStart;

		private static int _activeStacks;

		private static void Prefix(NoseDiveUpgrade __instance, ref bool __state)
		{
			__state = false;
			if (!((Object)(object)Player.LocalPlayer == (Object)null) && KillingSpreePlugin.BruiserRef != null && !((Object)(object)KillingSpreePlugin.CustomUpgradeInstance == (Object)null))
			{
				_activeStacks = KillingSpreePlugin.GetStackCount(KillingSpreePlugin.BruiserRef);
				if (_activeStacks > 0)
				{
					ref Data noseDiveData = ref __instance.NoseDiveData;
					_originalDamage = noseDiveData.landDamage.damage;
					_originalRadius = noseDiveData.landDamageRadius;
					_killsStart = PlayerData.Instance.targetsKilled;
					bool flag = KillingSpreePlugin.IsKneeDiveEquipped(KillingSpreePlugin.BruiserRef);
					float baseValue = (flag ? 0.25f : 0.5f);
					float totalBonus = KillingSpreePlugin.GetTotalBonus(_activeStacks, baseValue);
					noseDiveData.landDamage.damage *= 1f + totalBonus;
					float baseValue2 = (flag ? 1.5f : 0.5f);
					float totalBonus2 = KillingSpreePlugin.GetTotalBonus(_activeStacks, baseValue2);
					noseDiveData.landDamageRadius *= 1f + totalBonus2;
					__state = true;
				}
			}
		}

		private static void Postfix(NoseDiveUpgrade __instance, bool __state)
		{
			if (!__state)
			{
				return;
			}
			ref Data noseDiveData = ref __instance.NoseDiveData;
			noseDiveData.landDamage.damage = _originalDamage;
			noseDiveData.landDamageRadius = _originalRadius;
			int targetsKilled = PlayerData.Instance.targetsKilled;
			if (targetsKilled > _killsStart && __instance.Cooldown != null)
			{
				float num = 0.25f * (float)_activeStacks;
				if (num > 1f)
				{
					num = 1f;
				}
				__instance.Cooldown.AddCharge(num);
				if ((Object)(object)PlayerLook.Instance != (Object)null)
				{
					PlayerLook.Instance.GetRechargeUI((IActivatedAbility)(object)__instance.Cooldown).UpdateBackgroundColor();
				}
			}
			if (KillingSpreePlugin.IsTurboActive(KillingSpreePlugin.BruiserRef))
			{
				KillingSpreePlugin.ApplyDirectHeal(Player.LocalPlayer, 5f);
			}
		}
	}
	[Serializable]
	public class UpgradeProperty_KillingSpree : UpgradeProperty
	{
		[CompilerGenerated]
		private sealed class <GetStatData>d__0 : IEnumerator<StatData>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private StatData <>2__current;

			public Random rand;

			public IUpgradable gear;

			public UpgradeInstance upgrade;

			public UpgradeProperty_KillingSpree <>4__this;

			private int <stacks>5__1;

			private int <dispStacks>5__2;

			private bool <hasSynergy>5__3;

			private float <baseDmg>5__4;

			private float <totalDmgVal>5__5;

			private string <dmgStackInfo>5__6;

			private string <dmgSynergyText>5__7;

			private float <baseSize>5__8;

			private float <totalSizeVal>5__9;

			private string <sizeStackInfo>5__10;

			private string <sizeSynergyText>5__11;

			private string <refStackInfo>5__12;

			StatData IEnumerator<StatData>.Current
			{
				[DebuggerHidden]
				get
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GetStatData>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<dmgStackInfo>5__6 = null;
				<dmgSynergyText>5__7 = null;
				<sizeStackInfo>5__10 = null;
				<sizeSynergyText>5__11 = null;
				<refStackInfo>5__12 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_025f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0264: Unknown result type (might be due to invalid IL or missing references)
				//IL_029a: Unknown result type (might be due to invalid IL or missing references)
				//IL_029f: Unknown result type (might be due to invalid IL or missing references)
				//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_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<stacks>5__1 = KillingSpreePlugin.GetStackCount(gear);
					<dispStacks>5__2 = ((<stacks>5__1 == 0) ? 1 : <stacks>5__1);
					<hasSynergy>5__3 = KillingSpreePlugin.IsKneeDiveEquipped(gear);
					<baseDmg>5__4 = (<hasSynergy>5__3 ? 0.25f : 0.5f);
					<totalDmgVal>5__5 = KillingSpreePlugin.GetTotalBonus(<dispStacks>5__2, <baseDmg>5__4) * 100f;
					<dmgStackInfo>5__6 = ((<dispStacks>5__2 > 1) ? $" <color=#888888>(x{<dispStacks>5__2}: <b>+{<totalDmgVal>5__5:0.##}%</b>)</color>" : "");
					<dmgSynergyText>5__7 = (<hasSynergy>5__3 ? " <color=#fffb2e>(Low Efficiency)</color>" : "");
					<>2__current = new StatData($"Damage: <b>+{<baseDmg>5__4 * 100f}%</b>{<dmgStackInfo>5__6}{<dmgSynergyText>5__7}");
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<baseSize>5__8 = (<hasSynergy>5__3 ? 1.5f : 0.5f);
					<totalSizeVal>5__9 = KillingSpreePlugin.GetTotalBonus(<dispStacks>5__2, <baseSize>5__8) * 100f;
					<sizeStackInfo>5__10 = ((<dispStacks>5__2 > 1) ? $" <color=#888888>(x{<dispStacks>5__2}: <b>+{<totalSizeVal>5__9:0.##}%</b>)</color>" : "");
					<sizeSynergyText>5__11 = (<hasSynergy>5__3 ? " <color=green>(Knee-Dive Bonus)</color>" : " <color=grey>(Base: 50% | Synergy: 200%)</color>");
					<>2__current = new StatData($"Size: <b>+{<baseSize>5__8 * 100f}%</b>{<sizeStackInfo>5__10}{<sizeSynergyText>5__11}");
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<refStackInfo>5__12 = ((<dispStacks>5__2 > 1) ? $" <color=#888888>(x{<dispStacks>5__2}: <b>{Mathf.Min(100, 25 * <dispStacks>5__2)}%</b>)</color>" : "");
					<>2__current = new StatData("Refund/Kill: <b>25%</b>" + <refStackInfo>5__12);
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					if (upgrade != null && upgrade.IsTurbocharged)
					{
						<>2__current = new StatData("\n<color=red><b>Turbocharged</b></color>\nHealing: <b>+5</b>\n");
						<>1__state = 4;
						return true;
					}
					break;
				case 4:
					<>1__state = -1;
					break;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[IteratorStateMachine(typeof(<GetStatData>d__0))]
		public override IEnumerator<StatData> GetStatData(Random rand, IUpgradable gear, UpgradeInstance upgrade)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetStatData>d__0(0)
			{
				<>4__this = this,
				rand = rand,
				gear = gear,
				upgrade = upgrade
			};
		}

		public override string GetTurbochargedInfo(Random rand, IUpgradable gear, UpgradeInstance upgrade)
		{
			return "<color=red>Turbocharged</color>\nHealing: <b>+5</b>";
		}

		public override void Apply(Player p, UpgradeInstance u, ref Random r)
		{
		}

		public override void Remove(Player p, Player pf, UpgradeInstance i, ref Random r)
		{
		}
	}
}