Decompiled source of ImmersiveMovement v1.1.0

plugins/ImmersiveMovement.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ImmersiveMovement")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fd18034234b1bc5b3744e48ee190066c38503ea8")]
[assembly: AssemblyProduct("ImmersiveMovement")]
[assembly: AssemblyTitle("ImmersiveMovement")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ImmersiveMovement;

[BepInPlugin("ImmersiveMovement", "ImmersiveMovement", "1.1.0")]
public class ImmersiveMovement : BasePlugin
{
	public static ManualLogSource Logger;

	private Harmony harmony;

	public static ConfigEntry<float> walkSpeedMultiplier;

	public static ConfigEntry<float> runSpeedMultiplier;

	public static ConfigEntry<float> leanSpeedMultiplier;

	public static ConfigEntry<bool> cameraJolt;

	public override void Load()
	{
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Expected O, but got Unknown
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Expected O, but got Unknown
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Expected O, but got Unknown
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Expected O, but got Unknown
		Logger = ((BasePlugin)this).Log;
		Logger.LogInfo((object)"Loading ImmersiveMovement...");
		walkSpeedMultiplier = ((BasePlugin)this).Config.Bind<float>("Player", "Walk Speed", 1.7f, "Player walking speed. (Game default 4)");
		runSpeedMultiplier = ((BasePlugin)this).Config.Bind<float>("Player", "Run Speed", 3f, "Player running speed. (Game default 8)");
		leanSpeedMultiplier = ((BasePlugin)this).Config.Bind<float>("Player", "Lean Speed", 2f, "Player lean speed. (Game default 10)");
		cameraJolt = ((BasePlugin)this).Config.Bind<bool>("Player", "Camera Jolt", true, "Less camera jolt from falling.");
		ManualLogSource logger = Logger;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(23, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Walk speed multiplier: ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(walkSpeedMultiplier.Value);
		}
		logger.LogInfo(val);
		ManualLogSource logger2 = Logger;
		val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Run speed multiplier: ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(runSpeedMultiplier.Value);
		}
		logger2.LogInfo(val);
		ManualLogSource logger3 = Logger;
		val = new BepInExInfoLogInterpolatedStringHandler(23, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Lean speed multiplier: ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(leanSpeedMultiplier.Value);
		}
		logger3.LogInfo(val);
		ManualLogSource logger4 = Logger;
		val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Override camera jolt: ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(cameraJolt.Value);
		}
		logger4.LogInfo(val);
		try
		{
			harmony = new Harmony("ImmersiveMovement");
			Logger.LogInfo((object)"Harmony instance created.");
			harmony.PatchAll();
			Logger.LogInfo((object)"All patches applied.");
		}
		catch (Exception ex)
		{
			ManualLogSource logger5 = Logger;
			BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(19, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error during Load: ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
			}
			logger5.LogError(val2);
		}
	}
}
[HarmonyPatch(typeof(Player), "FixedUpdate")]
public class PlayerPatch
{
	[HarmonyPatch(typeof(FirstPersonController), "Update")]
	public class LeanSpeedPatch
	{
		private static bool logSent;

		private static void Postfix(FirstPersonController __instance)
		{
			if (!logSent)
			{
				ImmersiveMovement.Logger.LogInfo((object)"Player lean speed modified.");
				logSent = true;
			}
			__instance.leanSpeed = ImmersiveMovement.leanSpeedMultiplier.Value;
		}

		[HarmonyPatch(typeof(FirstPersonController), "JoltCamera")]
		private static void Prefix(ref float amplitude, Vector3 direction, float speed)
		{
			if (ImmersiveMovement.cameraJolt.Value)
			{
				amplitude = Mathf.Min(amplitude, 30f);
			}
		}
	}

	private static bool logSent;

	[HarmonyPrefix]
	public static void Prefix(Player __instance)
	{
		if ((Object)(object)__instance != (Object)null)
		{
			GameplayControls instance = GameplayControls.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.playerWalkSpeed = ImmersiveMovement.walkSpeedMultiplier.Value;
				instance.playerRunSpeed = ImmersiveMovement.runSpeedMultiplier.Value;
				if (!logSent)
				{
					logSent = true;
					ImmersiveMovement.Logger.LogInfo((object)"Player speed modified.");
				}
			}
			else
			{
				ImmersiveMovement.Logger.LogWarning((object)"GameplayControls instance is null.");
			}
		}
		else
		{
			ImmersiveMovement.Logger.LogWarning((object)"Player instance is null.");
		}
	}
}