Decompiled source of BalancedTranscendence v1.0.0

BalancedTranscendence.dll

Decompiled a day 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 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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BalancedTranscendence")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BalancedTranscendence")]
[assembly: AssemblyTitle("BalancedTranscendence")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BalancedTranscendence;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Sagittariod.BalancedTranscendence", "Balanced Transcendence", "1.0.0")]
public class TranscendenceNerfPlugin : BaseUnityPlugin
{
	public static ConfigEntry<float> healthMaxBase;

	public static ConfigEntry<float> healthMaxStack;

	public static ConfigEntry<float> rechargeDelayBaseIncrease;

	public static ConfigEntry<float> rechargeDelayStackIncrease;

	public void Awake()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		BindConfigs();
		UpdateItemDescription();
		CharacterBody.RecalculateStats += new Manipulator(CharacterBody_RecalculateStats_IL);
		CharacterBody.UpdateOutOfCombatAndDanger += new Manipulator(CharacterBody_get_outOfDanger_IL);
	}

	private void BindConfigs()
	{
		healthMaxBase = ((BaseUnityPlugin)this).Config.Bind<float>("Transcendence", "Base Max Health", 0.5f, "Maximum health increase on the first stack (Vanilla = 0.5");
		healthMaxStack = ((BaseUnityPlugin)this).Config.Bind<float>("Transcendence", "Stack Max Health", 0.5f, "Maximum health increase per additional stack (Vanilla = 0.25)");
		rechargeDelayBaseIncrease = ((BaseUnityPlugin)this).Config.Bind<float>("Transcendence", "Base Recharge Delay Penalty", 0.5f, "Added delay before being considered out of danger from first stack.");
		rechargeDelayStackIncrease = ((BaseUnityPlugin)this).Config.Bind<float>("Transcendence", "Stack Recharge Delay Penalty", 0.5f, "Added delay before being considered out of danger from additional stacks.");
	}

	private void UpdateItemDescription()
	{
		LanguageAPI.Add("ITEM_SHIELDONLY_PICKUP", "Convert all your health into shield. Increase maximum health. <color=#FF7F7F>You are considered in danger for longer.</color>");
		LanguageAPI.Add("ITEM_SHIELDONLY_DESC", $"Convert all but <style=cIsHealing>1 health</style> into <style=cIsHealing>regenerating shields</style>. Gain <style=cIsHealth>{healthMaxBase.Value * 100f}%</style> <style=cStack>(+{healthMaxStack.Value * 100f}% per stack)</style> maximum health. <style=cIsUtility>Increases the delay after getting hit before being considered out of danger delay</style> by <style=cIsUtility>{rechargeDelayBaseIncrease.Value * 100f}%</style> <style=cStack>(+{rechargeDelayStackIncrease.Value * 100f}% per stack)</style>.");
	}

	private void CharacterBody_RecalculateStats_IL(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		if (val.TryGotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "ShieldOnly")
		}))
		{
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.5f)
			}))
			{
				val.Next.Operand = healthMaxBase.Value;
			}
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.25f)
			}))
			{
				val.Next.Operand = healthMaxStack.Value;
			}
		}
	}

	private void CharacterBody_get_outOfDanger_IL(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		if (!val.TryGotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 7f)
		}))
		{
			return;
		}
		int index = val.Index;
		val.Index = index + 1;
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Func<float, CharacterBody, float>>((Func<float, CharacterBody, float>)delegate(float vanillaDelay, CharacterBody body)
		{
			if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.inventory))
			{
				int itemCountEffective = body.inventory.GetItemCountEffective(Items.ShieldOnly);
				if (itemCountEffective > 0)
				{
					float num = rechargeDelayBaseIncrease.Value + rechargeDelayStackIncrease.Value * (float)(itemCountEffective - 1);
					return vanillaDelay * (1f + num);
				}
			}
			return vanillaDelay;
		});
	}
}