Decompiled source of ENV Toggle v1.1.0

ConsoleArti.dll

Decompiled 5 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 ArtificerExtended;
using ArtificerExtended.Passive;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using EntityStates;
using EntityStates.Mage;
using On.EntityStates.Mage;
using On.RoR2;
using RoR2;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("ConsoleArti")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ConsoleArti")]
[assembly: AssemblyTitle("ConsoleArti")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ConsoleArti;

public static class AECom
{
	public static void AECompatibility()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		Main.artiSkill = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Mage/MageBody.prefab").WaitForCompletion().GetComponent<SkillLocator>();
		PassiveSkillDef val = ScriptableObject.CreateInstance<PassiveSkillDef>();
		((SkillDef)val).skillNameToken = Main.artiSkill.passiveSkill.skillNameToken;
		((SkillDef)val).skillDescriptionToken = Main.artiSkill.passiveSkill.skillDescriptionToken;
		((SkillDef)val).icon = Main.artiSkill.passiveSkill.icon;
		((SkillDef)val).canceledFromSprinting = false;
		((SkillDef)val).cancelSprintingOnActivation = false;
		val.stateMachineDefaults = (StateMachineDefaults[])(object)new StateMachineDefaults[1]
		{
			new StateMachineDefaults
			{
				machineName = "Body",
				mainState = new SerializableEntityStateType(typeof(MageToggleCharcterMain)),
				initalState = new SerializableEntityStateType(typeof(MageToggleCharcterMain)),
				defaultMainState = new SerializableEntityStateType(typeof(GenericCharacterMain)),
				defaultInitalState = new SerializableEntityStateType(typeof(GenericCharacterMain))
			}
		};
		ArtificerExtendedPlugin.magePassiveFamily.variants[0].skillDef = (SkillDef)(object)val;
	}
}
public class MageToggleCharcterMain : GenericCharacterMain
{
	private EntityStateMachine jetpackMachine;

	public static ETHelper EnvMod;

	public override void OnEnter()
	{
		((GenericCharacterMain)this).OnEnter();
		EnvMod = ((EntityState)this).gameObject.GetComponent<ETHelper>();
		EnvMod.jetpackMachine = EntityStateMachine.FindByCustomName(((EntityState)this).gameObject, "Jet");
	}

	public override void OnExit()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		EnvMod = ((EntityState)this).gameObject.GetComponent<ETHelper>();
		if (((EntityState)this).isAuthority && Object.op_Implicit((Object)(object)jetpackMachine))
		{
			EnvMod.jetpackMachine.SetNextState((EntityState)new Idle());
		}
		((GenericCharacterMain)this).OnExit();
	}

	public override void ProcessJump()
	{
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Expected O, but got Unknown
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Expected O, but got Unknown
		EnvMod = ((EntityState)this).gameObject.GetComponent<ETHelper>();
		EnvMod.featherCheck = false;
		EnvMod.quailCheck = false;
		if (!base.jumpInputReceived || !Object.op_Implicit((Object)(object)((EntityState)this).characterBody))
		{
			return;
		}
		if (EnvMod.graceTimer > 0f && !EnvMod.delayHover)
		{
			EnvMod.delayHover = true;
		}
		else if (base.jumpInputReceived && Object.op_Implicit((Object)(object)((EntityState)this).characterBody) && ((EntityState)this).characterMotor.jumpCount < ((EntityState)this).characterBody.maxJumpCount)
		{
			if (((EntityState)this).characterMotor.velocity.y >= 0f || ((EntityState)this).characterMotor.isGrounded)
			{
				if (Main.UpDelay.Value && !((EntityState)this).characterMotor.isGrounded)
				{
					EnvMod.delayUp = true;
				}
				else
				{
					Jump();
				}
			}
			else
			{
				EnvMod.delayTimer = 0f;
				EnvMod.tapJump = true;
			}
			if (Main.HoldJump.Value && ((EntityState)this).characterMotor.isGrounded)
			{
				EnvMod.autoJump = true;
			}
		}
		else
		{
			if (((EntityState)this).characterMotor.jumpCount != ((EntityState)this).characterBody.maxJumpCount || ((EntityState)this).characterMotor.isGrounded)
			{
				return;
			}
			bool flag = ((object)EnvMod.jetpackMachine.state).GetType() == typeof(JetpackOn);
			if (((EntityState)this).characterMotor.velocity.y < 0f && !flag)
			{
				EnvMod.jetpackMachine.SetNextState((EntityState)new JetpackOn());
				return;
			}
			if (!flag && !EnvMod.delayHover && Main.DelayJet.Value)
			{
				EnvMod.delayHover = true;
				return;
			}
			if (EnvMod.delayHover)
			{
				EnvMod.delayHover = false;
			}
			if (flag)
			{
				EnvMod.jetpackMachine.SetNextState((EntityState)new Idle());
			}
		}
	}

	public override void FixedUpdate()
	{
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Expected O, but got Unknown
		//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Expected O, but got Unknown
		//IL_0337: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Expected O, but got Unknown
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Expected O, but got Unknown
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Expected O, but got Unknown
		EnvMod = ((EntityState)this).gameObject.GetComponent<ETHelper>();
		EnvMod.jumpUp = !((EntityState)this).characterMotor.isGrounded && ((EntityState)this).characterMotor.velocity.y >= 0f;
		if (EnvMod.delayUp)
		{
			if (((ButtonState)(ref ((EntityState)this).outer.commonComponents.inputBank.jump)).justReleased)
			{
				Jump();
				EnvMod.delayUp = false;
			}
			else if (((EntityState)this).characterMotor.velocity.y <= 0f)
			{
				EnvMod.delayUp = false;
				if (!EnvMod.delayHover)
				{
					EnvMod.jetpackMachine.SetNextState((EntityState)new JetpackOn());
				}
				else
				{
					EnvMod.delayHover = false;
				}
			}
		}
		if (EnvMod.graceTimer > 0f)
		{
			EnvMod.graceTimer -= Time.fixedDeltaTime;
		}
		if (((ButtonState)(ref ((EntityState)this).outer.commonComponents.inputBank.jump)).justReleased && EnvMod.autoJump)
		{
			EnvMod.autoJump = false;
		}
		else if (EnvMod.delayHover && !((EntityState)this).characterMotor.isGrounded)
		{
			EnvMod.autoJump = false;
		}
		if (!((EntityState)this).characterMotor.isGrounded && EnvMod.autoJump && !EnvMod.tapJump && ((EntityState)this).characterMotor.velocity.y < 0f)
		{
			EnvMod.autoJump = false;
			EnvMod.jetpackMachine.SetNextState((EntityState)new JetpackOn());
		}
		if (Main.DelayJet.Value)
		{
			if (EnvMod.delayHover && ((EntityState)this).characterMotor.isGrounded)
			{
				EnvMod.delayHover = false;
			}
			if (EnvMod.delayHover && ((EntityState)this).characterMotor.velocity.y < 0f)
			{
				EnvMod.delayHover = false;
				EnvMod.jetpackMachine.SetNextState((EntityState)new JetpackOn());
			}
		}
		if (EnvMod.tapJump)
		{
			EnvMod.delayTimer += Time.fixedDeltaTime;
			if (((ButtonState)(ref ((EntityState)this).outer.commonComponents.inputBank.jump)).justReleased)
			{
				Jump();
				EnvMod.tapJump = false;
			}
			else if (EnvMod.delayTimer >= Main.TapLength.Value)
			{
				EntityState state = EnvMod.jetpackMachine.state;
				if (state != null && ((object)state).GetType() == typeof(JetpackOn))
				{
					EnvMod.jetpackMachine.SetNextState((EntityState)new Idle());
				}
				else if (state != null)
				{
					EnvMod.jetpackMachine.SetNextState((EntityState)new JetpackOn());
				}
				EnvMod.tapJump = false;
				EnvMod.delayTimer = 0f;
			}
		}
		if (((EntityState)this).characterMotor.isGrounded && ((object)EnvMod.jetpackMachine.state).GetType() == typeof(JetpackOn))
		{
			EnvMod.jetpackMachine.SetNextState((EntityState)new Idle());
			EnvMod.delayHover = false;
		}
		((GenericCharacterMain)this).FixedUpdate();
	}

	private void Jump()
	{
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Expected O, but got Unknown
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Expected O, but got Unknown
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Expected O, but got Unknown
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Expected O, but got Unknown
		int itemCount = ((EntityState)this).characterBody.inventory.GetItemCount(Items.JumpBoost);
		float num = 1f;
		float num2 = 1f;
		if (((EntityState)this).characterMotor.jumpCount >= ((EntityState)this).characterBody.baseJumpCount)
		{
			EnvMod.featherCheck = true;
			num = 1.5f;
			num2 = 1.5f;
		}
		else if ((float)itemCount > 0f && ((EntityState)this).characterBody.isSprinting)
		{
			float num3 = ((EntityState)this).characterBody.acceleration * ((EntityState)this).characterMotor.airControl;
			if (((EntityState)this).characterBody.moveSpeed > 0f && num3 > 0f)
			{
				EnvMod.quailCheck = true;
				float num4 = Mathf.Sqrt(10f * (float)itemCount / num3);
				float num5 = ((EntityState)this).characterBody.moveSpeed / num3;
				num = (num4 + num5) / num5;
			}
		}
		if (((object)EnvMod.jetpackMachine.state).GetType() == typeof(JetpackOn))
		{
			if (Main.DelayJet.Value)
			{
				EnvMod.delayHover = true;
			}
			EnvMod.jetpackMachine.SetNextState((EntityState)new Idle());
		}
		GenericCharacterMain.ApplyJumpVelocity(((EntityState)this).characterMotor, ((EntityState)this).characterBody, num, num2, false);
		if (((BaseCharacterMain)this).hasModelAnimator)
		{
			int layerIndex = ((BaseCharacterMain)this).modelAnimator.GetLayerIndex("Body");
			if (layerIndex >= 0)
			{
				if (((EntityState)this).characterMotor.jumpCount == 0 || ((EntityState)this).characterBody.baseJumpCount == 1)
				{
					((BaseCharacterMain)this).modelAnimator.CrossFadeInFixedTime("Jump", ((BaseCharacterMain)this).smoothingParameters.intoJumpTransitionTime, layerIndex);
				}
				else
				{
					((BaseCharacterMain)this).modelAnimator.CrossFadeInFixedTime("BonusJump", ((BaseCharacterMain)this).smoothingParameters.intoJumpTransitionTime, layerIndex);
				}
			}
		}
		if (EnvMod.featherCheck)
		{
			EffectManager.SpawnEffect(LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/FeatherEffect"), new EffectData
			{
				origin = ((EntityState)this).characterBody.footPosition
			}, true);
		}
		else if (((EntityState)this).characterMotor.jumpCount > 0)
		{
			EffectManager.SpawnEffect(LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/ImpactEffects/CharacterLandImpact"), new EffectData
			{
				origin = ((EntityState)this).characterBody.footPosition,
				scale = ((EntityState)this).characterBody.radius
			}, true);
		}
		if (EnvMod.quailCheck)
		{
			EffectManager.SpawnEffect(LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/BoostJumpEffect"), new EffectData
			{
				origin = ((EntityState)this).characterBody.footPosition,
				rotation = Util.QuaternionSafeLookRotation(((EntityState)this).characterMotor.velocity)
			}, true);
		}
		CharacterMotor characterMotor = ((EntityState)this).characterMotor;
		characterMotor.jumpCount++;
		if (Main.Grace.Value > 0f)
		{
			EnvMod.graceTimer = Main.Grace.Value;
		}
	}
}
public class ETHelper : MonoBehaviour
{
	internal EntityStateMachine jetpackMachine;

	internal bool featherCheck;

	internal bool quailCheck;

	internal bool delayHover;

	internal bool tapJump;

	internal float delayTimer;

	internal bool autoJump;

	internal float graceTimer = 0f;

	internal bool jumpUp = false;

	internal bool delayUp;
}
[BepInPlugin("com.FMRadio11.ENVToggle", "ENV_Toggle", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class Main : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static hook_OnExit <>9__0_1;

		internal void <Awake>b__0_1(orig_OnExit orig, FlyUpState self)
		{
			if (AutoSurge.Value)
			{
				((EntityState)self).gameObject.GetComponent<ETHelper>().delayHover = true;
			}
			orig.Invoke(self);
		}
	}

	private GameObject artiPrefab;

	internal static SkillLocator artiSkill;

	private EntityStateMachine artiMachine;

	public static bool AECompat;

	public static ConfigEntry<bool> DelayJet { get; set; }

	public static ConfigEntry<float> TapLength { get; set; }

	public static ConfigEntry<bool> AutoSurge { get; set; }

	public static ConfigEntry<bool> HoldJump { get; set; }

	public static ConfigEntry<float> Grace { get; set; }

	public static ConfigEntry<bool> UpDelay { get; set; }

	public void Awake()
	{
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Expected O, but got Unknown
		DelayJet = ((BaseUnityPlugin)this).Config.Bind<bool>("Mechanics", "Delay Hover", true, "Toggles whether Artificer will automatically begin hovering on fall after jumping while hovering.");
		TapLength = ((BaseUnityPlugin)this).Config.Bind<float>("Mechanics", "Tap Jump Duration", 0.12f, "Determines how long jump must be held when Artificer falls while still having jumps remaining to automatically hover. If jump is released before this duration is up, she will jump instead.");
		AutoSurge = ((BaseUnityPlugin)this).Config.Bind<bool>("Mechanics", "Enable Auto Surge?", true, "If active, Artificer will always hover after using Ion Surge. If not, Artificer must be holding jump at the end of the move to hover.");
		HoldJump = ((BaseUnityPlugin)this).Config.Bind<bool>("Mechanics", "Hold Jump to hover?", true, "If active, Artificer will automatically hover when she begins falling after a grounded jump if the button/key isn't released.");
		Grace = ((BaseUnityPlugin)this).Config.Bind<float>("Mechanics", "Tap Jump delay", 0.15f, "If greater than 0, inputting jump within this time period (in seconds) while grounded will make Artificer hover automatically. If set to (or below) 0, this function is disabled.");
		UpDelay = ((BaseUnityPlugin)this).Config.Bind<bool>("Mechanics", "Upward jump toggle?", false, "If active, Artificer will not execute Hopoo Feather jumps while rising until the button is released, and will toggle hover on/off if jump is input and held mid-jump. This is disabled by default due to not being vanilla behavior, but is recommended if you find the original execution clunky like I did.");
		AECompat = Chainloader.PluginInfos.ContainsKey("com.Borbo.ArtificerExtended");
		if (AECompat)
		{
			AECom.AECompatibility();
		}
		BodyCatalog.Init += (hook_Init)delegate(orig_Init orig)
		{
			orig.Invoke();
			artiPrefab = BodyCatalog.FindBodyPrefab("MageBody");
			artiPrefab.AddComponent<ETHelper>();
			artiMachine = EntityStateMachine.FindByCustomName(artiPrefab, "Body");
		};
		object obj = <>c.<>9__0_1;
		if (obj == null)
		{
			hook_OnExit val = delegate(orig_OnExit orig, FlyUpState self)
			{
				if (AutoSurge.Value)
				{
					((EntityState)self).gameObject.GetComponent<ETHelper>().delayHover = true;
				}
				orig.Invoke(self);
			};
			<>c.<>9__0_1 = val;
			obj = (object)val;
		}
		FlyUpState.OnExit += (hook_OnExit)obj;
		if (!AECompat)
		{
			Run.onRunStartGlobal += GHCheck;
		}
	}

	public void GHCheck(Run obj)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		SerializableEntityStateType val = default(SerializableEntityStateType);
		((SerializableEntityStateType)(ref val))..ctor(typeof(MageToggleCharcterMain));
		artiMachine.initialStateType = val;
		artiMachine.mainStateType = val;
	}
}