Decompiled source of BetterSoulCost v1.0.4

BetterSoulCost.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
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("BetterSoulCost")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterSoulCost")]
[assembly: AssemblyTitle("BetterSoulCost")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BetterSoulCost;

[BepInPlugin("com.RiskOfBrainrot.BetterSoulCost", "BetterSoulCost", "1.0.4")]
public class SoulCostPlugin : BaseUnityPlugin
{
	public const string guid = "com.RiskOfBrainrot.BetterSoulCost";

	public const string teamName = "RiskOfBrainrot";

	public const string modName = "BetterSoulCost";

	public const string version = "1.0.4";

	public static PluginInfo PInfo { get; private set; }

	internal static ConfigFile CustomConfigFile { get; set; }

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

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		CustomConfigFile = new ConfigFile(Paths.ConfigPath + "\\BetterSoulCost.cfg", true);
		DoCradleSoulCost = CustomConfigFile.Bind<bool>("BetterSoulCost: Reworks", "Change Soul Cost Stacking", true, "If true, soul penalties will increase exponentially to approximate consistent health loss, rather than hyperbolically.");
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(FixSoulPayCost));
		ShrineColossusAccessBehavior.OnInteraction += new Manipulator(ShapingShrineSoulSpread);
	}

	private void ShapingShrineSoulSpread(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);
		val.GotoNext((MoveType)0, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "SetBuffCount")
		});
		val.Remove();
		val.EmitDelegate<Action<CharacterBody, int, int>>((Action<CharacterBody, int, int>)delegate(CharacterBody body, int buffIndex, int buffCount)
		{
			AddSoulCostToBody(body, (BuffIndex)buffIndex, buffCount);
		});
	}

	public static void AddSoulCostToBody(CharacterBody body, float soulCost)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		AddSoulCostToBody(body, Buffs.SoulCost.buffIndex, soulCost);
	}

	public static void AddSoulCostToBody(CharacterBody body, BuffIndex buffIndex, float soulCost)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		soulCost = Mathf.Min(soulCost, 0.99f);
		int buffCount = body.GetBuffCount(buffIndex);
		float num = soulCost * 10f;
		if (DoCradleSoulCost.Value)
		{
			float num2 = 1f;
			if (buffCount > 0)
			{
				num2 = 1f / (1f + 0.1f * (float)buffCount);
			}
			float num3 = num * num / (num2 * (10f - num));
			num += num3;
		}
		body.SetBuffCount(buffIndex, buffCount + Mathf.CeilToInt(num));
	}

	[SystemInitializer(new Type[] { typeof(CostTypeCatalog) })]
	private void FixSoulPayCost()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		CostTypeDef costTypeDef = CostTypeCatalog.GetCostTypeDef((CostTypeIndex)15);
		MethodInfo method = ((Delegate)(object)costTypeDef.payCost).Method;
		ILHook val = new ILHook((MethodBase)method, new Manipulator(FixSoulCost));
	}

	private void FixSoulCost(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((MoveType)0, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "SetBuffCount")
		}))
		{
			val.Remove();
			val.EmitDelegate<Action<CharacterBody, int, int>>((Action<CharacterBody, int, int>)delegate(CharacterBody body, int buffIndex, int buffCount)
			{
				if (buffCount > 0)
				{
					float soulCost = (float)buffCount * 0.1f;
					AddSoulCostToBody(body, (BuffIndex)buffIndex, soulCost);
				}
			});
		}
		else
		{
			Debug.LogError((object)"Could not hook void cradle paycost");
		}
	}
}