Decompiled source of FruityBarrierDecay v1.0.1

BarrierRework.dll

Decompiled 2 months 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 IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using On.RoR2.Items;
using R2API;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[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("BarrierRework")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BarrierRework")]
[assembly: AssemblyTitle("BarrierRework")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BarrierRework;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.RiskOfBrainrot.FruityBarrierDecay", "FruityBarrierDecay", "1.0.1")]
[R2APISubmoduleDependency(new string[] { "LanguageAPI", "ContentAddition" })]
public class BarrierReworkPlugin : BaseUnityPlugin
{
	public static float aegisBarrierFraction = 0.1f;

	public static float aegisBarrierFlat = 60f;

	public static BuffDef aegisDecayBuff;

	public const string guid = "com.RiskOfBrainrot.FruityBarrierDecay";

	public const string teamName = "RiskOfBrainrot";

	public const string modName = "FruityBarrierDecay";

	public const string version = "1.0.1";

	private float barrierDecayRateStatic = 0.033f;

	private float barrierDecayRateDynamic = 0.33f;

	private bool useDynamicDecay = true;

	public static PluginInfo PInfo { get; private set; }

	protected void ReworkAegis()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		CreateBuff();
		Hooks();
		HealthComponent.Heal += new Manipulator(RemoveAegisOverheal);
		LanguageAPI.Add("ITEM_BARRIERONOVERHEAL_PICKUP", "Gain barrier on any interaction. While out of danger, barrier stops decaying.");
		LanguageAPI.Add("ITEM_BARRIERONOVERHEAL_DESC", "Using any interactable grants a <style=cIsHealing>temporary barrier</style> " + $"for <style=cIsHealing>{aegisBarrierFlat} health</style> <style=cStack>(+{aegisBarrierFlat} per stack)</style>. " + "While outside of danger, <style=cIsUtility>barrier will not decay</style>.");
	}

	private void RemoveAegisOverheal(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_0039: 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)
		ILCursor val = new ILCursor(il);
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdfld<ItemCounts>(x, "barrierOnOverHeal")
		});
		val.Emit(OpCodes.Pop);
		val.Emit(OpCodes.Ldc_I4_0);
	}

	private void CreateBuff()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		aegisDecayBuff = ScriptableObject.CreateInstance<BuffDef>();
		((Object)aegisDecayBuff).name = "AegisDecayFreeze";
		aegisDecayBuff.buffColor = new Color(0.95f, 0.85f, 0.08f);
		aegisDecayBuff.canStack = false;
		aegisDecayBuff.isDebuff = false;
		aegisDecayBuff.iconSprite = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/Common/texBuffGenericShield.tif").WaitForCompletion();
		ContentAddition.AddBuffDef(aegisDecayBuff);
	}

	public void Hooks()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		MultiShopCardUtils.OnMoneyPurchase += new hook_OnMoneyPurchase(OnMoneyPurchase);
		MultiShopCardUtils.OnNonMoneyPurchase += new hook_OnNonMoneyPurchase(OnNonMoneyPurchase);
		CharacterBody.RecalculateStats += new hook_RecalculateStats(AegisBarrierDecay);
		CharacterBody.OnInventoryChanged += new hook_OnInventoryChanged(AddItemBehavior);
	}

	private void OnNonMoneyPurchase(orig_OnNonMoneyPurchase orig, PayCostContext context)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		AegisBarrierGrant(context);
		orig.Invoke(context);
	}

	private void OnMoneyPurchase(orig_OnMoneyPurchase orig, PayCostContext context)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		AegisBarrierGrant(context);
		orig.Invoke(context);
	}

	private void AddItemBehavior(orig_OnInventoryChanged orig, CharacterBody self)
	{
		orig.Invoke(self);
		if (NetworkServer.active)
		{
			self.AddItemBehavior<AegisDecayBehavior>(self.inventory.GetItemCount(Items.BarrierOnOverHeal));
		}
	}

	private void AegisBarrierDecay(orig_RecalculateStats orig, CharacterBody self)
	{
		orig.Invoke(self);
		if (self.HasBuff(aegisDecayBuff))
		{
			self.barrierDecayRate = 0f;
		}
	}

	private void AegisBarrierGrant(PayCostContext context)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		CharacterMaster activatorMaster = context.activatorMaster;
		CharacterBody val = ((activatorMaster != null) ? activatorMaster.GetBody() : null);
		if (Object.op_Implicit((Object)(object)val))
		{
			int itemCount = val.inventory.GetItemCount(Items.BarrierOnOverHeal);
			HealthComponent healthComponent = val.healthComponent;
			if (itemCount > 0 && (Object)(object)healthComponent != (Object)null)
			{
				float num = (float)itemCount * aegisBarrierFlat;
				healthComponent.AddBarrierAuthority(num);
			}
		}
	}

	public void Awake()
	{
		ReworkAegis();
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(BuffBarrier));
	}

	private void BuffBarrier()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		CharacterBody.FixedUpdate += new hook_FixedUpdate(BarrierBuff);
	}

	private void BarrierBuff(orig_FixedUpdate orig, CharacterBody self)
	{
		if (self.barrierDecayRate > 0f)
		{
			self.barrierDecayRate = (useDynamicDecay ? Mathf.Max(1f, self.healthComponent.barrier * barrierDecayRateDynamic) : (self.maxBarrier * barrierDecayRateStatic));
		}
		orig.Invoke(self);
	}
}
public class AegisDecayBehavior : ItemBehavior
{
	private bool decayFrozen = false;

	public void FixedUpdate()
	{
		if (base.body.outOfDanger != decayFrozen)
		{
			if (!decayFrozen)
			{
				FreezeDecay();
			}
			else
			{
				UnfreezeDecay();
			}
		}
	}

	private void FreezeDecay()
	{
		decayFrozen = true;
		base.body.AddBuff(BarrierReworkPlugin.aegisDecayBuff);
	}

	private void UnfreezeDecay()
	{
		decayFrozen = false;
		base.body.RemoveBuff(BarrierReworkPlugin.aegisDecayBuff);
	}

	private void OnDisable()
	{
		if (decayFrozen)
		{
			UnfreezeDecay();
		}
	}
}