Decompiled source of ShockwaveLanding v1.0.0

ShockwaveLanding.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using ShockwaveLanding;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(ShockwaveMod), "Shockwave Landing", "1.0.0", "TonPseudo", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ShockwaveLanding")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShockwaveLanding")]
[assembly: AssemblyTitle("ShockwaveLanding")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 ShockwaveLanding
{
	public class ShockwaveMod : MelonMod
	{
		private static MelonPreferences_Category _category;

		private static MelonPreferences_Entry<bool> _enabled;

		private static MelonPreferences_Entry<float> _intensity;

		private static MelonPreferences_Entry<float> _minFallHeight;

		private static MelonPreferences_Entry<float> _radius;

		private static MelonPreferences_Entry<float> _upwardsModifier;

		private static MelonPreferences_Entry<bool> _scaleWithFall;

		private static MelonPreferences_Entry<float> _maxFallScale;

		private float _previousY;

		private bool _hasPreviousY;

		private float _peakY;

		private bool _isFalling;

		private const float FallSpeedThreshold = 2f;

		private const float LandingSpeedThreshold = 0.5f;

		private bool _menuBuilt;

		public override void OnInitializeMelon()
		{
			_category = MelonPreferences.CreateCategory("ShockwaveLanding");
			_enabled = _category.CreateEntry<bool>("Enabled", true, (string)null, "Active ou désactive complètement le mod", false, false, (ValueValidator)null, (string)null);
			_intensity = _category.CreateEntry<float>("Intensity", 20f, (string)null, "Force appliquée aux objets/ennemis dans le rayon (plus haut = plus fort)", false, false, (ValueValidator)null, (string)null);
			_minFallHeight = _category.CreateEntry<float>("MinFallHeight", 3f, (string)null, "Hauteur de chute minimum (mètres) avant de déclencher l'onde de choc", false, false, (ValueValidator)null, (string)null);
			_radius = _category.CreateEntry<float>("Radius", 8f, (string)null, "Rayon d'effet de l'onde de choc en mètres", false, false, (ValueValidator)null, (string)null);
			_upwardsModifier = _category.CreateEntry<float>("UpwardsModifier", 1.5f, (string)null, "Composante verticale ajoutée au knockback (façon AddExplosionForce)", false, false, (ValueValidator)null, (string)null);
			_scaleWithFall = _category.CreateEntry<bool>("ScaleWithFallHeight", true, (string)null, "Si activé, l'intensité augmente avec la hauteur de chute réelle", false, false, (ValueValidator)null, (string)null);
			_maxFallScale = _category.CreateEntry<float>("MaxFallScaleMultiplier", 3f, (string)null, "Multiplicateur maximum appliqué à l'intensité pour les très grandes chutes", false, false, (ValueValidator)null, (string)null);
			Hooking.OnUIRigCreated += SetupBoneMenu;
			MelonLogger.Msg("[ShockwaveLanding] Mod chargé. Intensité=" + _intensity.Value + " MinFall=" + _minFallHeight.Value + "m Radius=" + _radius.Value + "m");
		}

		private void SetupBoneMenu()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			if (!_menuBuilt)
			{
				_menuBuilt = true;
				Page obj = Page.Root.CreatePage("Shockwave Landing", Color.red, 0, true);
				obj.CreateBool("Mod active", Color.green, _enabled.Value, (Action<bool>)delegate(bool val)
				{
					_enabled.Value = val;
				});
				obj.CreateFloat("Intensite", Color.white, _intensity.Value, 5f, 0f, 500f, (Action<float>)delegate(float val)
				{
					_intensity.Value = val;
				});
				obj.CreateFloat("Hauteur min de chute (m)", Color.white, _minFallHeight.Value, 0.5f, 0.5f, 30f, (Action<float>)delegate(float val)
				{
					_minFallHeight.Value = val;
				});
				obj.CreateFloat("Rayon (m)", Color.white, _radius.Value, 0.5f, 1f, 30f, (Action<float>)delegate(float val)
				{
					_radius.Value = val;
				});
				obj.CreateFloat("Modificateur vertical", Color.white, _upwardsModifier.Value, 0.25f, 0f, 10f, (Action<float>)delegate(float val)
				{
					_upwardsModifier.Value = val;
				});
				obj.CreateBool("Scaler avec la chute", Color.white, _scaleWithFall.Value, (Action<bool>)delegate(bool val)
				{
					_scaleWithFall.Value = val;
				});
				obj.CreateFloat("Multiplicateur max", Color.white, _maxFallScale.Value, 0.25f, 1f, 10f, (Action<float>)delegate(float val)
				{
					_maxFallScale.Value = val;
				});
				MelonLogger.Msg("[ShockwaveLanding] Page BoneMenu créée.");
			}
		}

		public override void OnUpdate()
		{
			TrackFallAndLanding();
		}

		private void TrackFallAndLanding()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (!_enabled.Value)
			{
				return;
			}
			Transform head = Player.Head;
			if ((Object)(object)head == (Object)null)
			{
				return;
			}
			float y = head.position.y;
			if (!_hasPreviousY)
			{
				_previousY = y;
				_hasPreviousY = true;
				return;
			}
			float deltaTime = Time.deltaTime;
			if (deltaTime <= 0f)
			{
				return;
			}
			float num = (y - _previousY) / deltaTime;
			if (!_isFalling)
			{
				if (num <= -2f)
				{
					_isFalling = true;
					_peakY = _previousY;
				}
			}
			else
			{
				_peakY = Mathf.Max(_peakY, _previousY);
				if (num > -0.5f)
				{
					_isFalling = false;
					float num2 = _peakY - y;
					if (num2 >= _minFallHeight.Value)
					{
						TriggerShockwave(head.position, num2);
					}
				}
			}
			_previousY = y;
		}

		private void TriggerShockwave(Vector3 origin, float fallDistance)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			float num = _intensity.Value;
			if (_scaleWithFall.Value && _minFallHeight.Value > 0f)
			{
				float num2 = Mathf.Clamp(fallDistance / _minFallHeight.Value, 1f, _maxFallScale.Value);
				num *= num2;
			}
			Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(origin, _radius.Value));
			Transform val = (((Object)(object)Player.Head != (Object)null) ? Player.Head.root : null);
			Collider[] array2 = array;
			foreach (Collider val2 in array2)
			{
				Rigidbody attachedRigidbody = val2.attachedRigidbody;
				if (!((Object)(object)attachedRigidbody == (Object)null) && (!((Object)(object)val != (Object)null) || !((Object)(object)((Component)val2).transform.root == (Object)(object)val)))
				{
					attachedRigidbody.AddExplosionForce(num, origin, _radius.Value, _upwardsModifier.Value, (ForceMode)1);
				}
			}
			SpawnShockwaveVfx(origin);
			MelonLogger.Msg($"[ShockwaveLanding] Atterrissage détecté (chute={fallDistance:F1}m) -> intensité={num:F1}, {array.Length} colliders touchés.");
		}

		private void SpawnShockwaveVfx(Vector3 origin)
		{
			//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_002e: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)2);
			((Object)val).name = "ShockwaveLanding_VFX";
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			val.transform.position = origin + Vector3.up * 0.02f;
			val.transform.localScale = new Vector3(0.1f, 0.02f, 0.1f);
			Renderer component = val.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.material.color = new Color(1f, 0.5f, 0.1f, 0.6f);
			}
			MelonCoroutines.Start(AnimateRing(val, _radius.Value));
		}

		private IEnumerator AnimateRing(GameObject ring, float targetRadius)
		{
			float duration = 0.35f;
			float t = 0f;
			float startScale = 0.1f;
			float endScale = targetRadius * 2f;
			while (t < duration && (Object)(object)ring != (Object)null)
			{
				t += Time.deltaTime;
				float num = t / duration;
				float num2 = Mathf.Lerp(startScale, endScale, num);
				ring.transform.localScale = new Vector3(num2, 0.02f, num2);
				Renderer component = ring.GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null)
				{
					Color color = component.material.color;
					color.a = Mathf.Lerp(0.6f, 0f, num);
					component.material.color = color;
				}
				yield return null;
			}
			if ((Object)(object)ring != (Object)null)
			{
				Object.Destroy((Object)(object)ring);
			}
		}
	}
}