Decompiled source of Erenshor JumpPlus v1.0.0

plugins/Erenshor_JumpPlus.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Erenshor_Difficulty_Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Erenshor_Difficulty_Mod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("baccbf9b-8842-41a2-a31f-ca5bc84ba1eb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace JumpPlusMod;

[BepInPlugin("com.Recks.jumpplus", "Jump Plus", "1.4.0")]
public class JumpPlusPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(PlayerControl), "LandMovement")]
	private class PlayerJumpPatch
	{
		private static void Postfix(PlayerControl __instance)
		{
			//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_0064: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)F_PC_Grav.GetValue(__instance);
			if (Mathf.Approximately(num, 5f))
			{
				float num2 = 5f * JumpMult.Value;
				F_PC_Grav.SetValue(__instance, num2);
				Vector3 val = (Vector3)F_PC_Gravity.GetValue(__instance);
				val.y = num2;
				F_PC_Gravity.SetValue(__instance, val);
			}
		}
	}

	[CompilerGenerated]
	private sealed class <Hop>d__12 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public SimPlayer sim;

		public NavMeshAgent agent;

		public JumpPlusPlugin <>4__this;

		private Animator <anim>5__1;

		private bool <restore>5__2;

		private float <half>5__3;

		private float <t>5__4;

		private float <prog>5__5;

		private float <height>5__6;

		private Vector3 <next>5__7;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <Hop>d__12(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<anim>5__1 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
			{
				<>1__state = -1;
				<>4__this.hopping.Add(sim);
				<anim>5__1 = ((Component)sim).GetComponent<Animator>();
				Animator obj = <anim>5__1;
				if (obj != null)
				{
					obj.SetTrigger("Jump");
				}
				<restore>5__2 = agent.updatePosition;
				agent.updatePosition = false;
				<half>5__3 = HopTime.Value * 0.5f;
				<t>5__4 = 0f;
				break;
			}
			case 1:
				<>1__state = -1;
				break;
			}
			if (<t>5__4 < HopTime.Value)
			{
				<t>5__4 += Time.deltaTime;
				<prog>5__5 = ((<t>5__4 < <half>5__3) ? (<t>5__4 / <half>5__3) : ((HopTime.Value - <t>5__4) / <half>5__3));
				<height>5__6 = Mathf.Lerp(0f, HopHeight.Value, <prog>5__5);
				<next>5__7 = agent.nextPosition;
				((Component)sim).transform.position = <next>5__7 + Vector3.up * <height>5__6;
				<>2__current = null;
				<>1__state = 1;
				return true;
			}
			((Component)sim).transform.position = agent.nextPosition;
			agent.updatePosition = <restore>5__2;
			<>4__this.hopping.Remove(sim);
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <SimHopLoop>d__11 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public JumpPlusPlugin <>4__this;

		private WaitForSeconds <wait>5__1;

		private PlayerControl <player>5__2;

		private Vector3 <playerPos>5__3;

		private SimPlayer[] <>s__4;

		private int <>s__5;

		private SimPlayer <sim>5__6;

		private Character <me>5__7;

		private NavMeshAgent <agent>5__8;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <SimHopLoop>d__11(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<wait>5__1 = null;
			<player>5__2 = null;
			<>s__4 = null;
			<sim>5__6 = null;
			<me>5__7 = null;
			<agent>5__8 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_007e: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<wait>5__1 = new WaitForSeconds(2f);
				break;
			case 1:
				<>1__state = -1;
				<player>5__2 = GameData.PlayerControl;
				if ((Object)(object)<player>5__2 == (Object)null)
				{
					break;
				}
				<playerPos>5__3 = ((Component)<player>5__2).transform.position;
				<>s__4 = Object.FindObjectsOfType<SimPlayer>();
				for (<>s__5 = 0; <>s__5 < <>s__4.Length; <>s__5++)
				{
					<sim>5__6 = <>s__4[<>s__5];
					if (!<>4__this.hopping.Contains(<sim>5__6) && !(Vector3.Distance(((Component)<sim>5__6).transform.position, <playerPos>5__3) > SimRadius.Value) && !(Random.value > HopChance.Value))
					{
						ref Character reference = ref <me>5__7;
						object? value = F_Myself.GetValue(<sim>5__6);
						reference = (Character)((value is Character) ? value : null);
						if (!((Object)(object)<me>5__7 == (Object)null) && <me>5__7.Alive)
						{
							<agent>5__8 = ((Component)<sim>5__6).GetComponent<NavMeshAgent>();
							if (!((Object)(object)<agent>5__8 == (Object)null))
							{
								Vector3 velocity = <agent>5__8.velocity;
								if (!(((Vector3)(ref velocity)).sqrMagnitude < 0.01f))
								{
									((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.Hop(<sim>5__6, <agent>5__8));
									<me>5__7 = null;
									<agent>5__8 = null;
									<sim>5__6 = null;
								}
							}
						}
					}
				}
				<>s__4 = null;
				<player>5__2 = null;
				break;
			}
			<>2__current = <wait>5__1;
			<>1__state = 1;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private static ConfigEntry<float> JumpMult;

	private static ConfigEntry<float> HopChance;

	private static ConfigEntry<float> HopHeight;

	private static ConfigEntry<float> HopTime;

	private static ConfigEntry<float> SimRadius;

	private static readonly FieldInfo F_PC_Grav = AccessTools.Field(typeof(PlayerControl), "grav");

	private static readonly FieldInfo F_PC_Gravity = AccessTools.Field(typeof(PlayerControl), "gravity");

	private static readonly FieldInfo F_Myself = AccessTools.Field(typeof(SimPlayer), "Myself");

	private readonly HashSet<SimPlayer> hopping = new HashSet<SimPlayer>();

	private void Awake()
	{
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		JumpMult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "JumpMultiplier", 1.6f, "Player jump multiplier");
		HopChance = ((BaseUnityPlugin)this).Config.Bind<float>("SimPlayers", "HopChance", 0.15f, "Probability (0-1) every 2s a moving Sim hops");
		HopHeight = ((BaseUnityPlugin)this).Config.Bind<float>("SimPlayers", "HopHeight", 1f, "Hop height in meters");
		HopTime = ((BaseUnityPlugin)this).Config.Bind<float>("SimPlayers", "HopTime", 0.6f, "Hop duration in seconds");
		SimRadius = ((BaseUnityPlugin)this).Config.Bind<float>("SimPlayers", "HopRadius", 100f, "Max distance from player for Sim hops (meters)");
		new Harmony("com.Recks.jumpplus").PatchAll();
		((MonoBehaviour)this).StartCoroutine(SimHopLoop());
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Jump Plus 1.4.0 loaded – player x{JumpMult.Value} jump, Sim hop chance {HopChance.Value:P0} within {SimRadius.Value}m.");
	}

	[IteratorStateMachine(typeof(<SimHopLoop>d__11))]
	private IEnumerator SimHopLoop()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <SimHopLoop>d__11(0)
		{
			<>4__this = this
		};
	}

	[IteratorStateMachine(typeof(<Hop>d__12))]
	private IEnumerator Hop(SimPlayer sim, NavMeshAgent agent)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <Hop>d__12(0)
		{
			<>4__this = this,
			sim = sim,
			agent = agent
		};
	}
}