Decompiled source of CoyoteTime v1.0.0

ror2coyotetime.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.Bootstrap;
using BepInEx.Configuration;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("ror2coyotetime")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2fb8dfc3ec84b2ce723273bb34a4a2b440581032")]
[assembly: AssemblyProduct("ror2coyotetime")]
[assembly: AssemblyTitle("ror2coyotetime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ror2coyotetime;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.DestroyedClone.CoyoteTime", "Coyote Time", "1.0.0")]
public class Main : BaseUnityPlugin
{
	private class CoyoteTimeBehaviour : MonoBehaviour
	{
		public CharacterMotor characterMotor;

		public int jumpCountOnStart = 0;

		private float age = 0f;

		public EntityStateMachine entityStateMachine;

		private float Duration => cfgWindowOfTimeForActivation.Value;

		public void Awake()
		{
			if (!Object.op_Implicit((Object)(object)characterMotor))
			{
				characterMotor = ((Component)this).gameObject.GetComponent<CharacterMotor>();
			}
			characterMotor.useGravity = false;
		}

		public void FixedUpdate()
		{
			age += Time.fixedDeltaTime;
			if (characterMotor.jumpCount > jumpCountOnStart || characterMotor.isGrounded || age >= Duration)
			{
				ConsumeJumpIfUnspent();
				Object.Destroy((Object)(object)this);
			}
		}

		public void OnDestroy()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			CharacterMotor obj = characterMotor;
			CharacterGravityParameters gravityParameters = characterMotor.gravityParameters;
			obj.useGravity = ((CharacterGravityParameters)(ref gravityParameters)).CheckShouldUseGravity();
		}

		public void ConsumeJumpIfUnspent()
		{
			if (!characterMotor.isGrounded && characterMotor.jumpCount == jumpCountOnStart)
			{
				CharacterMotor obj = characterMotor;
				obj.jumpCount++;
			}
		}
	}

	public const string modGUID = "com.DestroyedClone.CoyoteTime";

	public static ConfigEntry<float> cfgWindowOfTimeForActivation;

	public static ConfigEntry<bool> cfgPlayerOnly;

	public const float maxSeconds = 0.6f;

	public const float minSeconds = 0f;

	public const float incrementSeconds = 0.01f;

	public void Start()
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected O, but got Unknown
		cfgWindowOfTimeForActivation = ((BaseUnityPlugin)this).Config.Bind<float>(string.Empty, "Time Window", 0.2f, $"The amount of time in seconds that the character can walk off a platform before they can no longer jump. Range: {0f} to {0.6f} seconds. Recommendation: 0.1 seconds.");
		cfgPlayerOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("Server", "Player Only", true, "If true, then only players can activate coyote time. AI does not have the logic to use this correctly, though you can turn it on if you want to for some reason.");
		CharacterMotor.OnLeaveStableGround += new hook_OnLeaveStableGround(OnLeaveStableGround);
		cfgWindowOfTimeForActivation.SettingChanged += CfgWindowOfTimeForActivation_SettingChanged;
		if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
		{
			Compat_RiskOfOptions();
		}
	}

	private void CfgWindowOfTimeForActivation_SettingChanged(object sender, EventArgs e)
	{
		if (cfgWindowOfTimeForActivation.Value < 0f)
		{
			cfgWindowOfTimeForActivation.Value = 0f;
		}
		else if (cfgWindowOfTimeForActivation.Value > 0.6f)
		{
			cfgWindowOfTimeForActivation.Value = 0.6f;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public void Compat_RiskOfOptions()
	{
		//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_002b: 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_0046: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		ModSettingsManager.SetModDescription("Adds Coyote Time to RoR2", "com.DestroyedClone.CoyoteTime", "Coyote Time");
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(cfgWindowOfTimeForActivation, new StepSliderConfig
		{
			min = 0f,
			max = 0.6f,
			increment = 0.01f
		}));
	}

	private void OnLeaveStableGround(orig_OnLeaveStableGround orig, CharacterMotor self)
	{
		int jumpCount = self.jumpCount;
		orig.Invoke(self);
		if ((cfgPlayerOnly.Value && !self.body.isPlayerControlled) || self.jumpCount == jumpCount)
		{
			return;
		}
		self.jumpCount = jumpCount;
		CoyoteTimeBehaviour coyoteTimeBehaviour = default(CoyoteTimeBehaviour);
		if (!((Component)self).gameObject.TryGetComponent<CoyoteTimeBehaviour>(ref coyoteTimeBehaviour))
		{
			EntityStateMachine val = EntityStateMachine.FindByCustomName(((Component)self).gameObject, "Body");
			if (Object.op_Implicit((Object)(object)val) && val.IsInMainState())
			{
				CoyoteTimeBehaviour coyoteTimeBehaviour2 = ((Component)self).gameObject.AddComponent<CoyoteTimeBehaviour>();
				coyoteTimeBehaviour2.entityStateMachine = val;
				coyoteTimeBehaviour2.characterMotor = self;
				coyoteTimeBehaviour2.jumpCountOnStart = jumpCount;
			}
		}
	}
}