Decompiled source of SpongesMovementTweaks v1.0.0

plugins/SpongeMods.MovementTweaks.dll

Decompiled a day 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SpongeMods.ModMenu;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("FishNet.Runtime")]
[assembly: AssemblyCompany("SpongeMods")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Swimming and launch-jump movement tuning.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a149c533da6d929b7267867242f5011f9c2152dc")]
[assembly: AssemblyProduct("SpongeMods.MovementTweaks")]
[assembly: AssemblyTitle("SpongeMods.MovementTweaks")]
[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 SpongeMods.MovementTweaks
{
	[HarmonyPatch(typeof(Weapon), "Shoot")]
	internal static class LaunchPatch
	{
		private static void Prefix(Weapon __instance, out int __state)
		{
			__state = (((Object)(object)__instance != (Object)null) ? __instance.Ammo : 0);
		}

		private static void Postfix(Weapon __instance, int __state)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.LaunchEnabled.Value || (Object)(object)__instance == (Object)null || __instance.Ammo >= __state)
			{
				return;
			}
			Player holder = ((Item)__instance).Holder;
			if ((Object)(object)holder == (Object)null || (Object)(object)holder != (Object)(object)Player.LocalPlayer)
			{
				return;
			}
			PlayerMovement movement = holder.Movement;
			if ((Object)(object)movement == (Object)null || (Object)(object)movement._rig == (Object)null || (Plugin.LaunchAirborneOnly.Value && movement.Grounded))
			{
				return;
			}
			Transform val = (((Object)(object)__instance.Attachments != (Object)null) ? __instance.Attachments.FirePoint : null);
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 val2 = -val.forward;
				val2.y += Plugin.LaunchUpBias.Value;
				float value = Plugin.LaunchForce.Value;
				if (!(value <= 0f) && !(((Vector3)(ref val2)).sqrMagnitude < 0.0001f))
				{
					movement._rig.AddForce(((Vector3)(ref val2)).normalized * value, (ForceMode)2);
				}
			}
		}
	}
	[BepInPlugin("SpongeMods.MovementTweaks", "Sponge's Movement Tweaks", "1.0.0")]
	[BepInDependency("SpongeMods.ModMenu", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Id = "SpongeMods.MovementTweaks";

		public const string Version = "1.0.0";

		internal static ConfigEntry<bool> SwimEnabled;

		internal static ConfigEntry<float> SwimSpeedScale;

		internal static ConfigEntry<float> SinkScale;

		internal static ConfigEntry<bool> LaunchEnabled;

		internal static ConfigEntry<float> LaunchForce;

		internal static ConfigEntry<bool> LaunchAirborneOnly;

		internal static ConfigEntry<float> LaunchUpBias;

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			SwimEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Swimming", "Enabled", true, "Swim faster than the stock pace.");
			SwimSpeedScale = ((BaseUnityPlugin)this).Config.Bind<float>("Swimming", "Speed multiplier", 1.6f, new ConfigDescription("Multiplies your movement speed while swimming. 1 is unchanged. Note that you cannot sprint in water, so the starting point is walking pace, not running pace -- 1.6 is a comfortable swim, and 4 or more is properly fast.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 8f), Array.Empty<object>()));
			SinkScale = ((BaseUnityPlugin)this).Config.Bind<float>("Swimming", "Sink multiplier", 0.5f, new ConfigDescription("Scales how fast you sink while treading water. Below 1 makes you sink more slowly; 1 is unchanged.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			LaunchEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Launch jump", "Enabled", false, "Firing a weapon shoves you away from the shot, so you can launch yourself by firing at the ground. Off by default, because it changes how the weapon feels.");
			LaunchForce = ((BaseUnityPlugin)this).Config.Bind<float>("Launch jump", "Force", 9f, new ConfigDescription("How hard a shot shoves you.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 40f), Array.Empty<object>()));
			LaunchAirborneOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("Launch jump", "Airborne only", false, "Only launch while off the ground, so ordinary firing on foot is unaffected.");
			LaunchUpBias = ((BaseUnityPlugin)this).Config.Bind<float>("Launch jump", "Upward bias", 0.25f, new ConfigDescription("Adds some straight-up push regardless of aim, which makes a ground shot launch rather than skid.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			try
			{
				new Harmony("SpongeMods.MovementTweaks").PatchAll();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Movement tuning could not be installed: " + ex.Message));
				return;
			}
			Tabs.Register();
			Log.LogInfo((object)"Movement Tweaks ready.");
		}
	}
	internal static class Swimmer
	{
		public static bool IsLocal(PlayerMovement movement)
		{
			if ((Object)(object)movement != (Object)null && (Object)(object)movement._player != (Object)null)
			{
				return (Object)(object)movement._player == (Object)(object)Player.LocalPlayer;
			}
			return false;
		}

		public static bool InWater(PlayerMovement movement)
		{
			if (movement._isSwimming)
			{
				return !movement.OnBoat;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(PlayerMovement), "UpdateMoveSpeed")]
	internal static class SwimSpeedPatch
	{
		private static void Postfix(PlayerMovement __instance)
		{
			if (Plugin.SwimEnabled.Value && Swimmer.IsLocal(__instance) && Swimmer.InWater(__instance))
			{
				float value = Plugin.SwimSpeedScale.Value;
				if (!Mathf.Approximately(value, 1f))
				{
					__instance._curMoveSpeed *= value;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerMovement), "Move")]
	internal static class SinkRatePatch
	{
		private static void Prefix(PlayerMovement __instance, out float __state)
		{
			__state = __instance._sinkSpeed;
			if (Plugin.SwimEnabled.Value && Swimmer.IsLocal(__instance) && Swimmer.InWater(__instance))
			{
				__instance._sinkSpeed *= Plugin.SinkScale.Value;
			}
		}

		private static void Postfix(PlayerMovement __instance, float __state)
		{
			__instance._sinkSpeed = __state;
		}
	}
	internal static class Tabs
	{
		public static void Register()
		{
			SpongeMenu.Tab("SpongeMods.MovementTweaks", "Movement", 40).Heading("Swimming").Toggle("Faster swimming", Plugin.SwimEnabled)
				.Number("Speed", Plugin.SwimSpeedScale)
				.Number("Sinking", Plugin.SinkScale)
				.Note("You cannot sprint in water, so the starting point is walking pace. Around 1.6 is a comfortable swim and 4 is properly fast.")
				.Heading("Launch jump")
				.Toggle("Recoil shoves you", Plugin.LaunchEnabled)
				.Number("Force", Plugin.LaunchForce)
				.Number("Upward bias", Plugin.LaunchUpBias)
				.Toggle("Only while airborne", Plugin.LaunchAirborneOnly)
				.Note("Fire at the ground to launch yourself. Off by default, because it changes how a weapon feels to use normally.");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}