Decompiled source of AutoStandIfRun v0.3.1

BepInEx/plugins/AutoStandIfRun/AutoStandIfRun.dll

Decompiled a day 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 Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("TactiKot")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.1.0")]
[assembly: AssemblyInformationalVersion("0.3.1+5bbc8680aa35444c4ce01d389ab2f800b8f533e1")]
[assembly: AssemblyProduct("AutoStandIfRun")]
[assembly: AssemblyTitle("AutoStandIfRun")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[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 AutoStandIfRun
{
	[BepInPlugin("TactiKot.AutoStandIfRun", "AutoStandIfRun", "0.3.1")]
	public class AutoStandIfRun : BaseUnityPlugin
	{
		private PlayerController? _standAttemptPlayer;

		private void Awake()
		{
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private void LateUpdate()
		{
			PlayerController instance = PlayerController.instance;
			InputManager instance2 = InputManager.instance;
			if (_standAttemptPlayer != instance)
			{
				_standAttemptPlayer = null;
			}
			if (!Object.op_Implicit((Object)(object)instance) || !((Behaviour)instance).isActiveAndEnabled || !Object.op_Implicit((Object)(object)instance2) || !Object.op_Implicit((Object)(object)LevelGenerator.Instance) || !LevelGenerator.Instance.Generated || !Object.op_Implicit((Object)(object)RunManager.instance) || SemiFunc.MenuLevel())
			{
				EndStandAttempt(restoreCrouch: false);
				return;
			}
			if (!Application.isFocused || instance.InputDisableTimer > 0f || instance2.disableMovementTimer > 0f || (Object.op_Implicit((Object)(object)GameDirector.instance) && GameDirector.instance.DisableInput) || !Object.op_Implicit((Object)(object)instance.playerAvatarScript) || instance.playerAvatarScript.isDisabled || instance.playerAvatarScript.isTumbling)
			{
				EndStandAttempt(restoreCrouch: true);
				return;
			}
			bool flag = SemiFunc.InputDown((InputKey)12);
			if (_standAttemptPlayer == instance && (!instance.Crouching || instance.toggleCrouch || instance.Sliding || flag || !instance2.InputToggleGet((InputKey)12)))
			{
				EndStandAttempt(restoreCrouch: false);
			}
			if (!flag && SemiFunc.InputDown((InputKey)15) && instance.toggleCrouch && !instance.Sliding)
			{
				_standAttemptPlayer = instance;
				instance.toggleCrouch = false;
			}
			if (_standAttemptPlayer == instance && !SemiFunc.InputHold((InputKey)15) && !instance.toggleSprint)
			{
				EndStandAttempt(restoreCrouch: true);
			}
		}

		private void EndStandAttempt(bool restoreCrouch)
		{
			PlayerController standAttemptPlayer = _standAttemptPlayer;
			_standAttemptPlayer = null;
			if (restoreCrouch && Object.op_Implicit((Object)(object)standAttemptPlayer) && standAttemptPlayer == PlayerController.instance && standAttemptPlayer.Crouching && !standAttemptPlayer.Sliding)
			{
				standAttemptPlayer.toggleCrouch = true;
			}
		}

		private void OnDisable()
		{
			EndStandAttempt(restoreCrouch: true);
		}

		private void OnApplicationFocus(bool hasFocus)
		{
			if (!hasFocus)
			{
				EndStandAttempt(restoreCrouch: true);
			}
		}
	}
}