Decompiled source of LethalSuperJump v1.0.5

LethalSuperJump.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Ant8490")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Jump mod for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyProduct("LethalSuperJump")]
[assembly: AssemblyTitle("LethalSuperJump")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 LethalSuperJump
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ant8490.LethalSuperJump";

		public const string PLUGIN_NAME = "LethalSuperJump";

		public const string PLUGIN_VERSION = "1.0.5";
	}
	public class JumpBind : LcInputActions
	{
		[InputAction("<Keyboard>/f", Name = "Toggle Super Jump")]
		public InputAction JumpKey { get; set; }
	}
	[BepInPlugin("ant8490.LethalSuperJump", "LethalSuperJump", "1.0.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin instance;

		private readonly Harmony harmony = new Harmony("ant8490.LethalSuperJump");

		internal static JumpBind InputActionsInstance = new JumpBind();

		public static ConfigEntry<int>? config_highjumpforce;

		public static ConfigEntry<int>? config_defaultjumpforce;

		public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>();

		private void Awake()
		{
			instance = this;
			config_highjumpforce = AddConfigEntry<int>(((BaseUnityPlugin)this).Config.Bind<int>("JUMP SETTINGS", "Super Jump Force", 50, "Set high jump force"));
			config_defaultjumpforce = AddConfigEntry<int>(((BaseUnityPlugin)this).Config.Bind<int>("JUMP SETTINGS", "Standard Jump Force", 13, "Set standard jump force"));
			DeleteOldConfigSettings();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LethalSuperJump is loaded!");
			harmony.PatchAll();
		}

		public static ConfigEntry<T> AddConfigEntry<T>(ConfigEntry<T> configEntry)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			currentConfigEntries.Add(((ConfigEntryBase)configEntry).Definition.Key, (ConfigEntryBase)configEntry);
			return configEntry;
		}

		private void DeleteOldConfigSettings()
		{
			HashSet<string> hashSet = new HashSet<string>();
			HashSet<string> hashSet2 = new HashSet<string>();
			foreach (ConfigEntryBase value in currentConfigEntries.Values)
			{
				hashSet.Add(value.Definition.Section);
				hashSet2.Add(value.Definition.Key);
			}
			try
			{
				ConfigFile config = ((BaseUnityPlugin)instance).Config;
				string configFilePath = config.ConfigFilePath;
				if (!File.Exists(configFilePath))
				{
					return;
				}
				string text = File.ReadAllText(configFilePath);
				string[] array = File.ReadAllLines(configFilePath);
				string text2 = "";
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = array[i].Replace("\n", "");
					if (array[i].Length <= 0)
					{
						continue;
					}
					if (array[i].StartsWith("["))
					{
						if (text2 != "" && !hashSet.Contains(text2))
						{
							text2 = "[" + text2 + "]";
							int num = text.IndexOf(text2);
							int num2 = text.IndexOf(array[i]);
							text = text.Remove(num, num2 - num);
						}
						text2 = array[i].Replace("[", "").Replace("]", "").Trim();
					}
					else
					{
						if (!(text2 != ""))
						{
							continue;
						}
						if (i <= array.Length - 4 && array[i].StartsWith("##"))
						{
							int j;
							for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++)
							{
							}
							if (hashSet.Contains(text2))
							{
								int num3 = array[i + j - 1].IndexOf("=");
								string item = array[i + j - 1].Substring(0, num3 - 1);
								if (!hashSet2.Contains(item))
								{
									int num4 = text.IndexOf(array[i]);
									int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length;
									text = text.Remove(num4, num5 - num4);
								}
							}
							i += j - 1;
						}
						else if (array[i].Length > 3)
						{
							text = text.Replace(array[i], "");
						}
					}
				}
				if (!hashSet.Contains(text2))
				{
					text2 = "[" + text2 + "]";
					int num6 = text.IndexOf(text2);
					text = text.Remove(num6, text.Length - num6);
				}
				while (text.Contains("\n\n\n"))
				{
					text = text.Replace("\n\n\n", "\n\n");
				}
				File.WriteAllText(configFilePath, text);
				config.Reload();
			}
			catch
			{
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LethalSuperJump";

		public const string PLUGIN_NAME = "LethalSuperJump";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}
namespace LethalSuperJump.Patch
{
	[HarmonyPatch]
	internal class SuperJump
	{
		private static float displaytime;

		private static float delay;

		public static bool SuperJump_delaydmg;

		public static bool SuperJumpEnabled { get; set; }

		[HarmonyPatch(typeof(StartOfRound), "OnEnable")]
		[HarmonyPostfix]
		public static void OnEnable()
		{
			Plugin.InputActionsInstance.JumpKey.performed += OnJumpKeyPressed;
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDisable")]
		[HarmonyPostfix]
		public static void OnDisable()
		{
			Plugin.InputActionsInstance.JumpKey.performed -= OnJumpKeyPressed;
		}

		private static void OnJumpKeyPressed(CallbackContext jumpConext)
		{
			SuperJumpEnabled = !SuperJumpEnabled;
			if (SuperJumpEnabled)
			{
				HUDManager.Instance.ChangeControlTip(3, "Super Jump Enabled", false);
			}
			else
			{
				HUDManager.Instance.ChangeControlTip(3, "Super Jump Disabled", false);
				SuperJump_delaydmg = true;
				delay = 5f;
				((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(ReEnableFallDmg());
			}
			displaytime = 3f;
			((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(DisableText());
		}

		private static IEnumerator DisableText()
		{
			while (displaytime > 0f)
			{
				float num = displaytime;
				displaytime = 0f;
				yield return (object)new WaitForSeconds(num);
			}
			HUDManager.Instance.ChangeControlTip(3, "", false);
		}

		private static IEnumerator ReEnableFallDmg()
		{
			while (delay > 0f)
			{
				float num = delay;
				delay = 0f;
				yield return (object)new WaitForSeconds(num);
			}
			SuperJump_delaydmg = false;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void ModifyJumpForce(PlayerControllerB __instance)
		{
			if (SuperJump.SuperJumpEnabled)
			{
				__instance.jumpForce = Plugin.config_highjumpforce.Value;
			}
			else
			{
				__instance.jumpForce = Plugin.config_defaultjumpforce.Value;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void ModifyFallDamage(PlayerControllerB __instance)
		{
			if (SuperJump.SuperJumpEnabled || SuperJump.SuperJump_delaydmg)
			{
				__instance.takingFallDamage = false;
			}
		}
	}
}