Decompiled source of HuntersHarpoonReworked v1.0.2

ReworkedHuntersHarpoon.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 BepInEx.Configuration;
using BepInEx.Logging;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
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("ReworkedHuntersHarpoon")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReworkedHuntersHarpoon")]
[assembly: AssemblyTitle("ReworkedHuntersHarpoon")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ReworkedHuntersHarpoon
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("IrrationalIntegral.ReworkedHuntersHarpoon", "ReworkedHuntersHarpoon", "1.0.0")]
	public class ReworkedHuntersHarpoon : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__OnCharacterDeathHook;
		}

		public const string PluginGUID = "IrrationalIntegral.ReworkedHuntersHarpoon";

		public const string PluginAuthor = "IrrationalIntegral";

		public const string PluginName = "ReworkedHuntersHarpoon";

		public const string PluginVersion = "1.0.0";

		public static float Crittosprint;

		public void Awake()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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)
			//IL_0035: Expected O, but got Unknown
			LoadConfig();
			CharacterBody.RecalculateStats += new hook_RecalculateStats(ReCalculateStatsHook);
			object obj = <>O.<0>__OnCharacterDeathHook;
			if (obj == null)
			{
				Manipulator val = OnCharacterDeathHook;
				<>O.<0>__OnCharacterDeathHook = val;
				obj = (object)val;
			}
			GlobalEventManager.OnCharacterDeath += (Manipulator)obj;
			UpdateText();
		}

		private void ReCalculateStatsHook(orig_RecalculateStats orig, CharacterBody self)
		{
			orig.Invoke(self);
			if (!Object.op_Implicit((Object)(object)self.inventory))
			{
				return;
			}
			int itemCount = self.inventory.GetItemCount(Items.MoveSpeedOnKill);
			if (itemCount > 0)
			{
				self.crit += 5f;
			}
			if (self.isSprinting && itemCount > 0)
			{
				if (self.crit > 100f)
				{
					self.moveSpeed += Crittosprint * 100f / 10f * (float)itemCount / self.sprintingSpeedMultiplier;
				}
				else
				{
					self.moveSpeed += Crittosprint * self.crit / 10f * (float)itemCount / self.sprintingSpeedMultiplier;
				}
			}
		}

		public static void OnCharacterDeathHook(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			ILLabel val2 = val.DefineLabel();
			ILLabel val3 = default(ILLabel);
			if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 52),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref val3)
			}))
			{
				val.Index += 3;
				val.Emit(OpCodes.Br, (object)val2);
				if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 12)
				}))
				{
					val.MarkLabel(val2);
				}
			}
			else
			{
				Debug.LogWarning((object)"Failed to find the target IL instructions to modify.");
			}
		}

		private void UpdateText()
		{
			string token = "ITEM_MOVESPEEDONKILL_DESC";
			string text = "<style=cIsDamage>Gain 5% critical chance</style>. <style=cIsUtility>Sprint speed</style> is improved by <style=cIsUtility>" + d(Crittosprint) + "</style> of your <style=cIsDamage>critical strike chance</style> (+<style=cIsUtility>" + d(Crittosprint) + "</style> per stack)";
			string token2 = "ITEM_MOVESPEEDONKILL_PICKUP";
			ReplaceString(token, text, token2, text);
		}

		private void ReplaceString(string token, string Desc, string token2, string pickup)
		{
			LanguageAPI.Add(token, Desc);
			LanguageAPI.Add(token2, Desc);
		}

		private string d(float percentage)
		{
			return percentage * 100f + "%";
		}

		private void LoadConfig()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Expected O, but got Unknown
			Crittosprint = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Hunters Harpoon", "Speed Per Buff Stack"), 1f, new ConfigDescription("Gain sprint speed based on your critical strike chance, default 100%. Default value 1", (AcceptableValueBase)null, Array.Empty<object>())).Value;
		}
	}
}
namespace ExamplePlugin
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}