Decompiled source of GolemClapAttackSpeedFix v1.0.2

plugins/GolemClapAttackSpeedFix.dll

Decompiled 4 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.Logging;
using EntityStates;
using EntityStates.GolemMonster;
using IL.EntityStates.GolemMonster;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GolemClapAttackSpeedFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c0707bf8752da038f51d546725d50b7a095aba78")]
[assembly: AssemblyProduct("GolemClapAttackSpeedFix")]
[assembly: AssemblyTitle("GolemClapAttackSpeedFix")]
[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 GolemClapAttackSpeedFix
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

		internal static void Debug(object 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);
		}
	}
	internal static class Main
	{
		internal static void ClapState_OnEnter(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "Clap"),
				(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "Clap.playbackRate"),
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld<ClapState>(x, "duration")
			}))
			{
				Log.Error("COULD NOT IL HOOK EntityStates.GolemMonster.ClapState.OnEnter");
				LogILStuff(il, val);
			}
			else
			{
				MakeDurationUseAttackSpeed(val);
			}
		}

		internal static void ClapState_FixedUpdate(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			MethodReference val2 = default(MethodReference);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val2),
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld<ClapState>(x, "duration")
			}))
			{
				Log.Error("COULD NOT IL HOOK EntityStates.GolemMonster.ClapState.FixedUpdate");
				LogILStuff(il, val);
			}
			else
			{
				MakeDurationUseAttackSpeed(val);
			}
		}

		internal static void ClapState_OnExit(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il)
			{
				Index = 0
			};
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<ClapState>>((Action<ClapState>)delegate(ClapState clapState)
			{
				clapState.modelAnimator.speed = 1f;
			});
		}

		private static void MakeDurationUseAttackSpeed(ILCursor c)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			c.Emit(OpCodes.Ldarg_0);
			c.EmitDelegate<Func<float, ClapState, float>>((Func<float, ClapState, float>)delegate(float clapStateDuration, ClapState currentClapState)
			{
				currentClapState.modelAnimator.speed = 1f * ((BaseState)currentClapState).attackSpeedStat;
				return clapStateDuration / ((BaseState)currentClapState).attackSpeedStat;
			});
		}

		private static void LogILStuff(ILContext il, ILCursor c)
		{
			Log.Warning($"cursor is {c}");
			Log.Warning($"il is {il}");
		}
	}
	[BepInPlugin("LordVGames.GolemClapAttackSpeedFix", "GolemClapAttackSpeedFix", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__ClapState_OnEnter;

			public static Manipulator <1>__ClapState_FixedUpdate;

			public static Manipulator <2>__ClapState_OnExit;
		}

		public const string PluginGUID = "LordVGames.GolemClapAttackSpeedFix";

		public const string PluginAuthor = "LordVGames";

		public const string PluginName = "GolemClapAttackSpeedFix";

		public const string PluginVersion = "1.0.0";

		public void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			object obj = <>O.<0>__ClapState_OnEnter;
			if (obj == null)
			{
				Manipulator val = Main.ClapState_OnEnter;
				<>O.<0>__ClapState_OnEnter = val;
				obj = (object)val;
			}
			ClapState.OnEnter += (Manipulator)obj;
			object obj2 = <>O.<1>__ClapState_FixedUpdate;
			if (obj2 == null)
			{
				Manipulator val2 = Main.ClapState_FixedUpdate;
				<>O.<1>__ClapState_FixedUpdate = val2;
				obj2 = (object)val2;
			}
			ClapState.FixedUpdate += (Manipulator)obj2;
			object obj3 = <>O.<2>__ClapState_OnExit;
			if (obj3 == null)
			{
				Manipulator val3 = Main.ClapState_OnExit;
				<>O.<2>__ClapState_OnExit = val3;
				obj3 = (object)val3;
			}
			ClapState.OnExit += (Manipulator)obj3;
		}
	}
}