Decompiled source of Bubbet Bhop Itemless v1.0.9

BubbetBhopItemless.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 BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using IL.EntityStates;
using IL.RoR2;
using IL.RoR2.Projectile;
using KinematicCharacterController;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.EntityStates;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("BubbetBhopItemless")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7ded0b707d47604b7b1679967eeafa8e232a102f")]
[assembly: AssemblyProduct("BubbetBhopItemless")]
[assembly: AssemblyTitle("BubbetBhopItemless")]
[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 BubbetBhopItemless
{
	public static class AutoBhop
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_GatherInputs <0>__GenericCharacterMain_GatherInputs;
		}

		public static ConfigEntry<bool> EnableAutoBhop;

		public static void Init(ConfigFile config)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			EnableAutoBhop = config.Bind<bool>("General", "Enable AutoBhop", false, "Hold down [JUMP] to auto jump instead of timing jumps for bhops.");
			if (EnableAutoBhop.Value)
			{
				object obj = <>O.<0>__GenericCharacterMain_GatherInputs;
				if (obj == null)
				{
					hook_GatherInputs val = GenericCharacterMain_GatherInputs;
					<>O.<0>__GenericCharacterMain_GatherInputs = val;
					obj = (object)val;
				}
				GenericCharacterMain.GatherInputs += (hook_GatherInputs)obj;
			}
		}

		private static void GenericCharacterMain_GatherInputs(orig_GatherInputs orig, GenericCharacterMain self)
		{
			orig.Invoke(self);
			if (((BaseCharacterMain)self).hasInputBank)
			{
				self.jumpInputReceived = ((EntityState)self).inputBank.jump.down;
			}
		}
	}
	public static class BubbetBhop
	{
		private delegate Vector3 NewMove(Vector3 velocityFromMoveTowards, Vector3 velocityOld, Vector3 target, float deltaTime, CharacterMotor self, CharacterBody body, bool disableAirControlUntilCollision);

		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__GripState_FixedUpdateBehavior;

			public static Manipulator <1>__GenericCharacterMain_ApplyJumpVelocity;

			public static Manipulator <2>__CharacterMotor_PreMove;
		}

		public static ConfigEntry<float> BaseAirControl;

		public static ConfigEntry<int> ScalingFunction;

		public static ConfigEntry<float> ScalingFunctionValA;

		private static Func<float, float, int, float, float>[] ScalingFuncs = new Func<float, float, int, float, float>[3]
		{
			(float @base, float added, int count, float _) => @base + (float)(count - 1) * added,
			(float @base, float added, int count, float arg1) => @base + Mathf.Pow((float)count, arg1) * added,
			(float @base, float added, int count, float arg1) => arg1 / ((float)count - added) + @base
		};

		public static void Init(ConfigFile config)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			BaseAirControl = config.Bind<float>("General", "Base Air Control", 3f, "Base air control, more = easier to turn and still gain speed.");
			ScalingFunction = config.Bind<int>("Advanced", "Scaling Function", 0, "Changes the scaling function of the bunny feet: 0 = linear(base + (count-1)*added), 1 = power law (base + Mathf.Pow(count, arg1) * added), 2 = Rectangular Hyperbola (arg1 / (count-added) + base)");
			ScalingFunctionValA = config.Bind<float>("Advanced", "Scaling Function Arg1", 0.5f, "Changes the first arbitrary value in scaling function: ex: power law's exponent (arg1)");
			object obj = <>O.<0>__GripState_FixedUpdateBehavior;
			if (obj == null)
			{
				Manipulator val = GripState_FixedUpdateBehavior;
				<>O.<0>__GripState_FixedUpdateBehavior = val;
				obj = (object)val;
			}
			GripState.FixedUpdateBehavior += (Manipulator)obj;
			object obj2 = <>O.<1>__GenericCharacterMain_ApplyJumpVelocity;
			if (obj2 == null)
			{
				Manipulator val2 = GenericCharacterMain_ApplyJumpVelocity;
				<>O.<1>__GenericCharacterMain_ApplyJumpVelocity = val2;
				obj2 = (object)val2;
			}
			GenericCharacterMain.ApplyJumpVelocity += (Manipulator)obj2;
			object obj3 = <>O.<2>__CharacterMotor_PreMove;
			if (obj3 == null)
			{
				Manipulator val3 = CharacterMotor_PreMove;
				<>O.<2>__CharacterMotor_PreMove = val3;
				obj3 = (object)val3;
			}
			CharacterMotor.PreMove += (Manipulator)obj3;
		}

		private static void GripState_FixedUpdateBehavior(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<Vector3>(x, "op_Multiply"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1)
			});
			val.Index += 2;
			val.Remove();
			val.Emit(OpCodes.Ldc_I4_0);
		}

		private static void CharacterMotor_PreMove(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[6]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterMotor>(x, "velocity"),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 2),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchMul(x)
			});
			val.Index += 7;
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldfld, typeof(CharacterMotor).GetRuntimeField("velocity"));
			val.Emit(OpCodes.Ldloc_2);
			val.Emit(OpCodes.Ldarg_1);
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldfld, typeof(CharacterMotor).GetField("body", BindingFlags.Instance | BindingFlags.NonPublic));
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldfld, typeof(CharacterMotor).GetField("disableAirControlUntilCollision", BindingFlags.Instance | BindingFlags.Public));
			val.EmitDelegate<NewMove>((NewMove)NewMoveMeth);
		}

		private static void GenericCharacterMain_ApplyJumpVelocity(ILContext il)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			Func<Vector3, CharacterMotor, CharacterBody, Vector3> func = delegate(Vector3 vector, CharacterMotor cm, CharacterBody cb)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//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_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				Vector3 result = vector + Vector3.down * vector.y;
				Vector3 val2 = cm.velocity + Vector3.down * cm.velocity.y;
				if (((Vector3)(ref val2)).sqrMagnitude > ((Vector3)(ref result)).sqrMagnitude)
				{
					result = val2;
				}
				result.y = vector.y;
				return result;
			};
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchStfld<CharacterMotor>(x, "velocity")
			});
			val.Index += 2;
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldarg_1);
			val.EmitDelegate<Func<Vector3, CharacterMotor, CharacterBody, Vector3>>(func);
			val.GotoNext(new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 2),
				(Instruction x) => ILPatternMatchingExt.MatchStfld<CharacterMotor>(x, "velocity")
			});
			val.Index += 2;
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldarg_1);
			val.EmitDelegate<Func<Vector3, CharacterMotor, CharacterBody, Vector3>>(func);
		}

		private static Vector3 NewMoveMeth(Vector3 velocityFromMoveTowards, Vector3 velocityOld, Vector3 target, float deltaTime, CharacterMotor self, CharacterBody body, bool disableAirControlUntilCollision)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (!disableAirControlUntilCollision && !((BaseCharacterController)self).Motor.GroundingStatus.IsStableOnGround)
			{
				Vector3 val = target;
				if (!self.isFlying)
				{
					val.y = 0f;
				}
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				float wishspeed = self.walkSpeed * ((Vector3)(ref normalized)).magnitude;
				return Accelerate(velocityOld, normalized, wishspeed, ScalingFuncs[ScalingFunction.Value](BaseAirControl.Value, 1.5f, 1, ScalingFunctionValA.Value), self.acceleration, deltaTime);
			}
			return velocityFromMoveTowards;
		}

		private static Vector3 Accelerate(Vector3 velocity, Vector3 wishdir, float wishspeed, float speedLimit, float acceleration, float deltaTime)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (speedLimit > 0f && wishspeed > speedLimit)
			{
				wishspeed = speedLimit;
			}
			float num = Vector3.Dot(velocity, wishdir);
			float num2 = wishspeed - num;
			if (num2 <= 0f)
			{
				return velocity;
			}
			float num3 = acceleration * deltaTime * wishspeed;
			if (num3 > num2)
			{
				num3 = num2;
			}
			return velocity + wishdir * num3;
		}
	}
	internal static class Log
	{
		internal static ManualLogSource _logSource;

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

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

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

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

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

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

		internal static void LogWarning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("kruumy.Bubbet_Bhop_Itemless", "Bubbet_Bhop_Itemless", "1.0.8")]
	public class Main : BaseUnityPlugin
	{
		public const string PluginGUID = "kruumy.Bubbet_Bhop_Itemless";

		public const string PluginAuthor = "kruumy";

		public const string PluginName = "Bubbet_Bhop_Itemless";

		public const string PluginVersion = "1.0.8";

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			BubbetBhop.Init(((BaseUnityPlugin)this).Config);
			Log.LogInfo("BubbetBhop Initialized");
			AutoBhop.Init(((BaseUnityPlugin)this).Config);
			Log.LogInfo("AutoBhop Initialized");
			Log.LogInfo("Awake done.");
		}
	}
}