Decompiled source of Parkour v1.0.2

Parkour.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using DM;
using Functions;
using HarmonyLib;
using InControl;
using Landfall.TABS;
using Landfall.TABS_Input;
using Parkour;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Parkour")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("GeeztJeez")]
[assembly: AssemblyProduct("Parkour")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7acfaef0-7669-4401-8bff-5a9a02e18c75")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace Parkour
{
	[BepInPlugin("GeeztJeez.Parkour", "Parkour", "1.0.2")]
	internal class Loader : BaseUnityPlugin
	{
		private static ConfigEntry<float> configJumpForce;

		private static ConfigEntry<bool> configEnableMod;

		public static bool Enabled => configEnableMod.Value;

		public static float JumpForce => configJumpForce.Value;

		private void Awake()
		{
			((MonoBehaviour)this).StartCoroutine("Call");
		}

		private IEnumerator Call()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null));
			yield return (object)new WaitUntil((Func<bool>)(() => ServiceLocator.GetService<ISaveLoaderService>() != null));
			yield return (object)new WaitForSeconds(0.5f);
			Debug.Log((object)"Loading Parkour...");
			_ = ContentDatabase.Instance().LandfallContentDatabase;
			new Harmony("Parkour").PatchAll();
			GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
			for (int i = 0; i < array.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)array[i].GetComponent<Unit>()))
				{
					array[i].gameObject.AddComponent<ParkourPossessionMechanic>();
				}
			}
			DoConfig();
			((MonoBehaviour)this).StartCoroutine(GenerateSettings());
			Debug.Log((object)"Loaded Parkour Successfully!");
		}

		private IEnumerator GenerateSettings()
		{
			GlobalSettingsHandler service = null;
			yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)(service = ServiceLocator.GetService<GlobalSettingsHandler>()))));
			List<SettingsInstance> list = service.GameplaySettings.ToList();
			SettingsInstance val2 = new SettingsInstance();
			val2.settingsType = (SettingsType)0;
			val2.options = new string[2] { "On", "Off" };
			val2.currentValue = ((!configEnableMod.Value) ? 1 : 0);
			val2.m_settingsKey = "Use Parkour";
			val2.toolTip = "Enables Parkour mod.";
			SettingsInstance val3 = val2;
			val3.OnValueChanged += delegate(int val)
			{
				configEnableMod.Value = val == 0;
			};
			list.Add(val3);
			SettingsInstance val4 = new SettingsInstance
			{
				currentSliderValue = configJumpForce.Value,
				defaultSliderValue = 1f,
				max = 2f,
				min = 0.1f,
				m_settingsKey = "Jump Force",
				settingsType = (SettingsType)1,
				toolTip = "Determines the force of parkour jumps. (default: 1)"
			};
			val4.OnSliderValueChanged += delegate(float val)
			{
				configJumpForce.Value = val;
			};
			list.Add(val4);
			((object)service).GetType().GetField("m_gameplaySettings", (BindingFlags)(-1)).SetValue(service, list.ToArray());
		}

		private void DoConfig()
		{
			configJumpForce = ((BaseUnityPlugin)this).Config.Bind<float>("General", "JumpForce", 1f, "Determines the force of unit jump.");
			configEnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable Parkour Mod");
		}
	}
}
namespace Functions
{
	public class ParkourPossessionMechanic : MonoBehaviour
	{
		public Unit unit;

		public GeneralInput input;

		private MovementHandler movementHandler;

		public float moveMultiplier;

		public float dashCooldown;

		public PlayerActions playerActions;

		public float dashMultiplier;

		public float jumpMultiplier;

		private bool m_toggledPause;

		private bool m_toggledSlowmo;

		private bool m_toggledSuperSlowmo;

		private bool canJump;

		public float damageFallReductionTime = 10f;

		public bool originallyTakeFallDamage;

		private bool canDash;

		private bool wait;

		public ParkourPossessionMechanic()
		{
			moveMultiplier = 12000f;
			dashCooldown = 4f;
			dashMultiplier = 1750f;
			jumpMultiplier = 15000f;
			canJump = true;
			canDash = true;
		}

		public void Start()
		{
			unit = ((Component)((Component)this).gameObject.transform.root).GetComponentInChildren<Unit>();
			movementHandler = ((Component)unit).GetComponentInChildren<MovementHandler>();
			input = unit.Input;
			playerActions = PlayerActions.Instance;
		}

		public void Update()
		{
			CameraAbilityPossess componentInParent = ((Component)MainCam.instance).GetComponentInParent<CameraAbilityPossess>();
			if (!Object.op_Implicit((Object)(object)componentInParent) || !((Object)(object)componentInParent.currentUnit == (Object)(object)unit) || unit.data.Dead)
			{
				return;
			}
			unit.data.takeFallDamage = false;
			unit.data.cantFallForSeconds = 1f;
			TimePossessionManager();
			if (Object.op_Implicit((Object)(object)input) && input.hasControl)
			{
				DynamicMovement(moveMultiplier * Time.deltaTime);
				if (!canDash && !wait)
				{
					wait = true;
					((MonoBehaviour)this).StartCoroutine((IEnumerator)DashCooldown(dashCooldown));
				}
				else if (canDash && ((OneAxisInputControl)playerActions.m_moveFast).IsPressed)
				{
					canDash = false;
					Dash(dashMultiplier);
				}
			}
			if (unit.data.isGrounded && ((OneAxisInputControl)playerActions.m_flyUp).IsPressed && canJump)
			{
				canJump = false;
				((MonoBehaviour)this).StartCoroutine((IEnumerator)Jump(jumpMultiplier * Loader.JumpForce));
			}
		}

		public void Dash(float force)
		{
			//IL_0020: 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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0091: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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)
			Vector3 val = ((TwoAxisInputControl)playerActions.m_move).X * unit.data.characterForwardObject.right;
			Vector3 val2 = ((TwoAxisInputControl)playerActions.m_move).Y * unit.data.characterForwardObject.forward;
			((Vector3)(ref val)).Normalize();
			((Vector3)(ref val2)).Normalize();
			Rigidbody[] allRigs = unit.data.allRigs.AllRigs;
			for (int i = 0; i < allRigs.Length; i++)
			{
				allRigs[i].AddForce(val * force, (ForceMode)5);
				allRigs[i].AddForce(val2 * force, (ForceMode)5);
				ServiceLocator.GetService<ParticlePlayer>().PlayEffect(1, allRigs[i].position, Vector3.up, (SkinnedMeshRenderer)null);
			}
			ServiceLocator.GetService<SoundPlayer>().PlaySoundEffect("Effects/Log", 1.5f, unit.data.mainRig.position, (MaterialType)0, (Transform)null, 0.7f);
		}

		public void DynamicMovement(float forwardForce)
		{
			//IL_0020: 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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((TwoAxisInputControl)playerActions.m_move).X * unit.data.characterForwardObject.right;
			Vector3 val2 = ((TwoAxisInputControl)playerActions.m_move).Y * unit.data.characterForwardObject.forward;
			((Vector3)(ref val)).Normalize();
			((Vector3)(ref val2)).Normalize();
			Rigidbody[] allRigs = unit.data.allRigs.AllRigs;
			for (int i = 0; i < allRigs.Length; i++)
			{
				allRigs[i].AddForce(val * (forwardForce / 3f) / allRigs[i].mass, (ForceMode)5);
				allRigs[i].AddForce(val2 * forwardForce / allRigs[i].mass, (ForceMode)5);
			}
		}

		private void SetTime(float targetTime)
		{
			Time.timeScale = targetTime;
		}

		public IEnumerator<WaitForSeconds> Jump(float jumpForce)
		{
			Rigidbody[] allRigs = unit.data.allRigs.AllRigs;
			for (int i = 0; i < allRigs.Length; i++)
			{
				allRigs[i].AddForce(Vector3.down * (jumpForce / 4f) / allRigs[i].mass, (ForceMode)5);
			}
			ServiceLocator.GetService<SoundPlayer>().PlaySoundEffect("Effects/Log", 1f, unit.data.mainRig.position, (MaterialType)0, (Transform)null, 0.5f);
			yield return new WaitForSeconds(0.15f);
			Rigidbody[] allRigs2 = unit.data.allRigs.AllRigs;
			for (int j = 0; j < allRigs2.Length; j++)
			{
				allRigs2[j].AddForce(Vector3.up * jumpForce / allRigs2[j].mass, (ForceMode)5);
				ServiceLocator.GetService<ParticlePlayer>().PlayEffect(1, allRigs2[j].position, Vector3.up, (SkinnedMeshRenderer)null);
			}
			ServiceLocator.GetService<SoundPlayer>().PlaySoundEffect("Effects/Log", 1.5f, unit.data.mainRig.position, (MaterialType)0, (Transform)null, 0.7f);
			yield return new WaitForSeconds(0.5f);
			canJump = true;
		}

		public void TimePossessionManager()
		{
			bool wasPressed = ((OneAxisInputControl)playerActions.m_toggleSuperSlow).WasPressed;
			bool wasPressed2 = ((OneAxisInputControl)playerActions.m_toggleTime).WasPressed;
			bool wasPressed3 = ((OneAxisInputControl)playerActions.m_toggleSlowMotion).WasPressed;
			if (!(wasPressed || wasPressed2 || wasPressed3))
			{
				return;
			}
			if (wasPressed2)
			{
				m_toggledSlowmo = false;
				m_toggledSuperSlowmo = false;
				m_toggledPause = !m_toggledPause;
				if (m_toggledPause)
				{
					SetTime(0f);
				}
			}
			else if (wasPressed3)
			{
				m_toggledPause = false;
				m_toggledSuperSlowmo = false;
				m_toggledSlowmo = !m_toggledSlowmo;
				if (m_toggledSlowmo)
				{
					SetTime(0.1f);
				}
			}
			else if (wasPressed)
			{
				m_toggledPause = false;
				m_toggledSlowmo = false;
				m_toggledSuperSlowmo = !m_toggledSuperSlowmo;
				if (m_toggledSuperSlowmo)
				{
					SetTime(0.01f);
				}
			}
			if (!m_toggledPause && !m_toggledSlowmo && !m_toggledSuperSlowmo)
			{
				SetTime(1f);
			}
		}

		public IEnumerator<WaitForSeconds> DashCooldown(float cooldown)
		{
			yield return new WaitForSeconds(cooldown);
			ServiceLocator.GetService<SoundPlayer>().PlaySoundEffect("Effects/Candlehead", 1.5f, unit.data.mainRig.position, (MaterialType)0, (Transform)null, 0.7f);
			Rigidbody[] allRigs = unit.data.allRigs.AllRigs;
			for (int i = 0; i < allRigs.Length; i++)
			{
				ServiceLocator.GetService<ParticlePlayer>().PlayEffect(2, allRigs[i].position, Vector3.up, (SkinnedMeshRenderer)null);
			}
			wait = false;
			canDash = true;
		}
	}
}