Decompiled source of BenBalanceMod v1.7.0

BenBalanceMod.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using R2API;
using R2API.Utils;
using RoR2;
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 = "")]
[assembly: AssemblyCompany("Test2")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Test2")]
[assembly: AssemblyTitle("Test2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BenJamminSpace;

[R2APISubmoduleDependency(new string[] { "LanguageAPI", "RecalculateStatsAPI" })]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Ben.BenBalanceMod", "Ben_Jammin's Balance Mod", "1.7.0")]
public class BenBalanceMod : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static Func<Instruction, bool> <>9__50_1;

		public static Func<Instruction, bool> <>9__50_2;

		public static Manipulator <>9__50_0;

		public static Func<Instruction, bool> <>9__52_1;

		public static Func<Instruction, bool> <>9__52_2;

		public static Func<Instruction, bool> <>9__52_3;

		public static Func<Instruction, bool> <>9__52_4;

		public static Manipulator <>9__52_0;

		public static Func<Instruction, bool> <>9__53_1;

		public static Func<Instruction, bool> <>9__53_2;

		public static Func<Instruction, bool> <>9__53_3;

		public static Func<Instruction, bool> <>9__53_4;

		public static Manipulator <>9__53_0;

		public static Func<Instruction, bool> <>9__54_1;

		public static Func<Instruction, bool> <>9__54_2;

		public static Func<Instruction, bool> <>9__54_3;

		public static Manipulator <>9__54_0;

		internal void <RBVisualConfig>b__50_0(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.TryGotoNext(new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_isSprinting")
			});
			val.Index += 12;
			val.Remove();
			val.Emit(OpCodes.Ldc_I4, 1000);
		}

		internal bool <RBVisualConfig>b__50_1(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdarg(x, 0);
		}

		internal bool <RBVisualConfig>b__50_2(Instruction x)
		{
			return ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_isSprinting");
		}

		internal void <ScytheConfig>b__52_0(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 4f),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 4),
				(Instruction x) => ILPatternMatchingExt.MatchConvR4(x),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 4f)
			});
			val.Index = val.Index;
			val.Remove();
			val.Emit(OpCodes.Ldc_R4, HScytheBase.Value);
			val.Index += 2;
			val.Remove();
			val.Emit(OpCodes.Ldc_R4, HScytheScale.Value);
		}

		internal bool <ScytheConfig>b__52_1(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdcR4(x, 4f);
		}

		internal bool <ScytheConfig>b__52_2(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdloc(x, 4);
		}

		internal bool <ScytheConfig>b__52_3(Instruction x)
		{
			return ILPatternMatchingExt.MatchConvR4(x);
		}

		internal bool <ScytheConfig>b__52_4(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdcR4(x, 4f);
		}

		internal void <MedkitPercentageNerf>b__53_0(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_maxHealth"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.05f),
				(Instruction x) => ILPatternMatchingExt.MatchMul(x)
			});
			val.Index += 2;
			val.Remove();
			val.Emit(OpCodes.Ldc_R4, MedkitNerf.Value);
		}

		internal bool <MedkitPercentageNerf>b__53_1(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdarg(x, 0);
		}

		internal bool <MedkitPercentageNerf>b__53_2(Instruction x)
		{
			return ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_maxHealth");
		}

		internal bool <MedkitPercentageNerf>b__53_3(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdcR4(x, 0.05f);
		}

		internal bool <MedkitPercentageNerf>b__53_4(Instruction x)
		{
			return ILPatternMatchingExt.MatchMul(x);
		}

		internal void <HappiestBuff>b__54_0(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Brfalse_S),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 7f),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 16)
			});
			val.Index += 1;
			val.Remove();
			val.Emit(OpCodes.Ldc_R4, MaskBuff.Value);
		}

		internal bool <HappiestBuff>b__54_1(Instruction x)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return ILPatternMatchingExt.Match(x, OpCodes.Brfalse_S);
		}

		internal bool <HappiestBuff>b__54_2(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdcR4(x, 7f);
		}

		internal bool <HappiestBuff>b__54_3(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdloc(x, 16);
		}
	}

	private static Vector3 rewardPositionOffset = new Vector3(0f, 3f, 0f);

	public static ConfigEntry<float> PSGPercent { get; set; }

	public static ConfigEntry<float> RBArmor { get; set; }

	public static ConfigEntry<float> RBSprint { get; set; }

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

	public static ConfigEntry<float> RWArmor { get; set; }

	public static ConfigEntry<float> RWArmor2 { get; set; }

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

	public static ConfigEntry<float> AegisArmor { get; set; }

	public static ConfigEntry<float> HScytheBase { get; set; }

	public static ConfigEntry<float> HScytheScale { get; set; }

	public static ConfigEntry<float> MaskBuff { get; set; }

	public static ConfigEntry<float> MedkitNerf { get; set; }

	public void Awake()
	{
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogMessage((object)"Execute Order 66");
		PSGPercent = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "PSGPercent", 0.02f, "Determines what additional percentage of health personal shield generators use to the default 0.08 or 8%. Default is 0.02 for a single psg to give you a 10% increase in health.");
		RBArmor = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "RoseBucklerArmor", 25f, "Determines how much armor Rose Buckler gives all the time in addition to sprinting. I.E., 10 for 10 armor. In vanilla this is 0.");
		RBSprint = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "RoseBucklerSprint", 20f, "Determines how much armor Rose Buckler subtracts from the vanilla 30 it gives while sprinting. This is accounts for the fact that it now gives armor all the time (see above). Default value is 20 so that the modded armor values are 25 all the time plus 30- (15) = 15, so a total of 15 additional armor while sprinting.");
		RBDisplay = ((BaseUnityPlugin)this).Config.Bind<bool>("BalanceMod", "RoseBucklerDisplay", true, "Toggles the Rose Buckler visual on or off. I.E. 'true' is on (vanilla), 'false' is off. Might be desired if you have the above value at 30.");
		RWArmor = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "RedWhipArmor", 7f, "Determines how much armor the 1st Red Whip gives. I.E., 7 for 7 armor. In vanilla this is 0.");
		RWArmor2 = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "RedWhipArmor2", 7f, "Determines how much armor every other Red Whip gives. I.E., 7 for 7 armor. In vanilla this is 0.");
		RWArmorToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("BalanceMod", "RedWhipArmorToggle", false, "Toggles if the armor addition by Red Whip only applies to when you have the RedWhip Buff. ");
		AegisArmor = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "AegisArmor", 40f, "Determines how armor every Aegis give. In vanilla this is 0.");
		HScytheBase = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "HarvestersScytheBaseHeal", 3f, "Determines how much base health Harvester's scythe gives. However, the calculations are done where one stack will give you this base value + the scaling value in the config below. I.E., if 2 for this field and 3 for the next field, then the first stack gives you 5 health, while additional stacks increases by 3. The vanilla values are 4 and 4 respectively.");
		HScytheScale = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "HarvestersScytheScaleHeal", 2f, "Determines the scaling health benefit of another stack of Harvester's Scythe. Remember, this also is included in the first stack (see above for example). In vanilla this is 4.");
		MaskBuff = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "HappiestMaskBuff", 12f, "Chance for happiest mask to proc. In vanilla this is 7 for 7%");
		MedkitNerf = ((BaseUnityPlugin)this).Config.Bind<float>("BalanceMod", "MedkitNerf", 0.033f, "Percentage of health medkit restores in addittion to the flat 20. In vanilla this is 0.05 or 5%");
		float num = 30f - RBSprint.Value;
		float num2 = (0.08f + PSGPercent.Value) * 100f;
		float num3 = HScytheBase.Value + HScytheScale.Value;
		float num4 = MedkitNerf.Value * 100f;
		if (RBArmor.Value > 0f)
		{
			LanguageAPI.Add("ITEM_SPRINTARMOR_PICKUP", "Reduce incoming damage, even more while sprinting.");
		}
		((BaseUnityPlugin)this).Logger.LogMessage((object)"Changing Descriptions");
		LanguageAPI.Add("ITEM_SPRINTARMOR_DESC", $"<style=cIsHealing>Increases armor</style> by <style=cIsHealing>{RBArmor.Value}</style> <style=cStack>(+{RBArmor.Value} per stack)</style>. <style=cIsHealing>Additionally increases armor</style> by <style=cIsHealing>{num}</style> <style=cStack>(+{num} per stack)</style> <style=cIsUtility>while sprinting</style>.");
		LanguageAPI.Add("ITEM_PERSONALSHIELD_DESC", $"Gain a <style=cIsHealing>shield</style> equal to <style=cIsHealing>{num2}%</style> <style=cStack>(+{num2}% per stack)</style> of your maximum health. Recharges outside of danger.");
		LanguageAPI.Add("ITEM_GHOSTONKILL_DESC", $"Killing enemies has a <style=cIsDamage>{MaskBuff.Value}%</style> chance to <style=cIsDamage>spawn a ghost</style> of the killed enemy with <style=cIsDamage>1500%</style> damage. Lasts <style=cIsDamage>30s</style> <style=cStack>(+30s per stack)</style>.");
		LanguageAPI.Add("ITEM_MEDKIT_DESC", $"2 seconds after getting hurt, <style=cIsHealing>heal</style> for <style=cIsHealing>20</style> plus an additional <style=cIsHealing>{num4}% <style=cStack>(+{num4}% per stack)</style></style> of <style=cIsHealing>maximum health</style>.");
		LanguageAPI.Add("ITEM_HEALONCRIT_DESC", $"Gain <style=cIsDamage>5% critical chance</style>. <style=cIsDamage>Critical strikes</style> <style=cIsHealing>heal</style> for <style=cIsHealing>{num3}</style>. <style=cStack>(+{HScytheScale.Value} per stack)</style> <style=cIsHealing>health</style>");
		LanguageAPI.Add("ITEM_SPRINTOUTOFCOMBAT_DESC", $"Leaving combat boosts your <style=cIsUtility>movement speed</style> by <style=cIsUtility>30%</style> <style=cStack>(+30% per stack)</style>. <style=cIsHealing>Increases armor</style> by <style=cIsHealing>{RWArmor.Value}</style> <style=cStack>(+{RWArmor2.Value} per stack)</style>.");
		LanguageAPI.Add("ITEM_BARRIERONOVERHEAL_DESC", $"Healing past full grants you a <style=cIsHealing>temporary barrier for 50%</style> <style=cStack>(+50% per stack)</style> of the amount you <style=cIsHealing>healed</style>. <style=cIsHealing>Increases armor</style> by <style=cIsHealing>{AegisArmor.Value}</style> <style=cStack>(+{AegisArmor.Value} per stack)</style>.");
		RBVisualConfig();
		ScytheConfig();
		HappiestBuff();
		MedkitPercentageNerf();
		RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(RecalcStats);
	}

	private void RBVisualConfig()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		if (RBDisplay.Value)
		{
			return;
		}
		object obj = <>c.<>9__50_0;
		if (obj == null)
		{
			Manipulator val = delegate(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val2 = new ILCursor(il);
				val2.TryGotoNext(new Func<Instruction, bool>[2]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_isSprinting")
				});
				val2.Index += 12;
				val2.Remove();
				val2.Emit(OpCodes.Ldc_I4, 1000);
			};
			<>c.<>9__50_0 = val;
			obj = (object)val;
		}
		CharacterBody.UpdateAllTemporaryVisualEffects += (Manipulator)obj;
	}

	private void RecalcStats(CharacterBody sender, StatHookEventArgs args)
	{
		if (!Object.op_Implicit((Object)(object)sender.inventory))
		{
			return;
		}
		int itemCount = sender.inventory.GetItemCount(Items.PersonalShield);
		if (itemCount > 0)
		{
			args.baseShieldAdd += (float)itemCount * (PSGPercent.Value * sender.maxHealth);
		}
		int itemCount2 = sender.inventory.GetItemCount(Items.SprintArmor);
		if (itemCount2 > 0)
		{
			args.armorAdd += (float)itemCount2 * RBArmor.Value;
		}
		int itemCount3 = sender.inventory.GetItemCount(Items.SprintOutOfCombat);
		if (itemCount3 > 0)
		{
			if (RWArmorToggle.Value)
			{
				if (sender.HasBuff(Buffs.WhipBoost))
				{
					args.armorAdd += RWArmor.Value + RWArmor2.Value * (float)(itemCount3 - 1);
				}
			}
			else
			{
				args.armorAdd += RWArmor.Value + RWArmor2.Value * (float)(itemCount3 - 1);
			}
		}
		if (sender.isSprinting)
		{
			args.armorAdd += (float)itemCount2 * RBSprint.Value * -1f;
		}
		int itemCount4 = sender.inventory.GetItemCount(Items.BarrierOnOverHeal);
		if (itemCount4 > 0)
		{
			args.armorAdd += (float)itemCount4 * AegisArmor.Value;
		}
	}

	private void ScytheConfig()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogMessage((object)"Scythe");
		object obj = <>c.<>9__52_0;
		if (obj == null)
		{
			Manipulator val = delegate(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00de: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val2 = new ILCursor(il);
				val2.GotoNext(new Func<Instruction, bool>[4]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 4f),
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 4),
					(Instruction x) => ILPatternMatchingExt.MatchConvR4(x),
					(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 4f)
				});
				val2.Index = val2.Index;
				val2.Remove();
				val2.Emit(OpCodes.Ldc_R4, HScytheBase.Value);
				val2.Index += 2;
				val2.Remove();
				val2.Emit(OpCodes.Ldc_R4, HScytheScale.Value);
			};
			<>c.<>9__52_0 = val;
			obj = (object)val;
		}
		GlobalEventManager.OnCrit += (Manipulator)obj;
	}

	private void MedkitPercentageNerf()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogMessage((object)"MedKit");
		object obj = <>c.<>9__53_0;
		if (obj == null)
		{
			Manipulator val = delegate(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val2 = new ILCursor(il);
				val2.GotoNext(new Func<Instruction, bool>[4]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_maxHealth"),
					(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.05f),
					(Instruction x) => ILPatternMatchingExt.MatchMul(x)
				});
				val2.Index += 2;
				val2.Remove();
				val2.Emit(OpCodes.Ldc_R4, MedkitNerf.Value);
			};
			<>c.<>9__53_0 = val;
			obj = (object)val;
		}
		CharacterBody.RemoveBuff_BuffIndex += (Manipulator)obj;
	}

	private void HappiestBuff()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogMessage((object)"Happy");
		object obj = <>c.<>9__54_0;
		if (obj == null)
		{
			Manipulator val = delegate(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val2 = new ILCursor(il);
				val2.GotoNext(new Func<Instruction, bool>[3]
				{
					(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Brfalse_S),
					(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 7f),
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 16)
				});
				val2.Index += 1;
				val2.Remove();
				val2.Emit(OpCodes.Ldc_R4, MaskBuff.Value);
			};
			<>c.<>9__54_0 = val;
			obj = (object)val;
		}
		GlobalEventManager.OnCharacterDeath += (Manipulator)obj;
	}
}