Decompiled source of HuntersHarpoonReturns v1.0.0

RoRRHarpoon.dll

Decompiled 6 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 R2API;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

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

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Wolfo.RoRRHuntersHarpoon", "HuntersHarpoonReturns", "1.0.0")]
public class RoRRHarpoonMain : BaseUnityPlugin
{
	public void Awake()
	{
		//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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		CharacterBody.RecalculateStats += new Manipulator(ChangeMoveSpeed);
		GlobalEventManager.OnCharacterDeath += new Manipulator(ChangeDuration);
		Addressables.LoadAssetAsync<BuffDef>((object)"RoR2/DLC1/MoveSpeedOnKill/bdKillMoveSpeed.asset").WaitForCompletion().canStack = false;
		LanguageAPI.Add("ITEM_MOVESPEEDONKILL_DESC", "Killing an enemy increases <style=cIsUtility>movement speed</style> by <style=cIsUtility>125%</style> for <style=cIsUtility>1</style> <style=cStack>(+1 per stack)</style> seconds. Consecutive kills increase buff duration for up to 25 seconds.", "en");
	}

	public static void ChangeMoveSpeed(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>[3]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.25f),
			(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
			(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "RoR2.DLC1Content/Buffs", "KillMoveSpeed")
		}))
		{
			val.Next.Operand = 1.25f;
		}
		else
		{
			Debug.LogWarning((object)"Failed to apply Hunter's Harpoon Move Speed Increase hook");
		}
	}

	private void ChangeDuration(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		int num2 = default(int);
		if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[4]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 1f),
			(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num2),
			(Instruction x) => ILPatternMatchingExt.MatchConvR4(x),
			(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.5f)
		}))
		{
			val.Index -= 2;
			val.Next.OpCode = OpCodes.Ldc_I4_0;
			val.Index += 9;
			val.RemoveRange(3);
			val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, "RoR2.CharacterBody", "get_corePosition")
			});
			val.EmitDelegate<Func<CharacterBody, CharacterBody>>((Func<CharacterBody, CharacterBody>)delegate(CharacterBody attackerBody)
			{
				//IL_003b: 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)
				int itemCount = attackerBody.master.inventory.GetItemCount(Items.MoveSpeedOnKill);
				float num = itemCount;
				if (attackerBody.HasBuff(Buffs.KillMoveSpeed))
				{
					for (int i = 0; i < attackerBody.timedBuffs.Count; i++)
					{
						if (attackerBody.timedBuffs[i].buffIndex == Buffs.KillMoveSpeed.buffIndex)
						{
							num += attackerBody.timedBuffs[i].timer;
							break;
						}
					}
				}
				if (num > 25f)
				{
					num = 25f;
				}
				attackerBody.ClearTimedBuffs(Buffs.KillMoveSpeed);
				attackerBody.AddTimedBuff(Buffs.KillMoveSpeed, num);
				return attackerBody;
			});
			Debug.LogWarning((object)"Applied Hunter's Harpoon Duration hook");
		}
		else
		{
			Debug.LogWarning((object)"Failed to apply Hunter's Harpoon Duration hook");
		}
	}
}