Decompiled source of LethalWeight v1.0.2

plugins/LethalWeight/LethalWeight.dll

Decompiled 9 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalWeight.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LethalWeight")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalWeight")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b93c5fd2-fa80-429f-a194-6f55af3bb371")]
[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 LethalWeight
{
	public class Logger
	{
		public enum LogLevelConfig
		{
			None,
			Important,
			Everything
		}

		internal ManualLogSource MLS;

		public string modName = "No-Name";

		public string modVersion = "No-Ver";

		public void Init(string modGUID = "")
		{
			MLS = Logger.CreateLogSource(modGUID);
		}

		public bool LogLevelAllow(LogLevelConfig severity = LogLevelConfig.Important, LogLevelConfig severity2 = LogLevelConfig.Everything)
		{
			if (severity2 == LogLevelConfig.None)
			{
				return false;
			}
			if (severity == LogLevelConfig.Everything)
			{
				return severity2 == LogLevelConfig.Everything;
			}
			return true;
		}

		public void Log(string text = "", LogLevel level = 16, LogLevelConfig severity = LogLevelConfig.Important)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (true)
			{
				string text2 = $"[{modName} v{modVersion}] - {text}";
				MLS.Log(level, (object)text2);
			}
		}
	}
	[BepInPlugin("thej01.lc.LethalFalling", "LethalFalling", "1.0.0")]
	public class LethalWeightMod : BaseUnityPlugin
	{
		private const string modGUID = "thej01.lc.LethalFalling";

		private const string modName = "LethalFalling";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("thej01.lc.LethalFalling");

		private static LethalWeightMod Instance;

		public static Logger lWeightLogger = new Logger();

		public static float fallPerLB = 0.09f;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			lWeightLogger.Init("thej01.lc.LethalFalling");
			lWeightLogger.modName = "LethalFalling";
			lWeightLogger.modVersion = "1.0.0";
			lWeightLogger.Log("lWeightLogger Initialised!", (LogLevel)16, Logger.LogLevelConfig.Everything);
			lWeightLogger.Log("Patching LethalWeightMod...", (LogLevel)16, Logger.LogLevelConfig.Everything);
			harmony.PatchAll(typeof(LethalWeightMod));
			lWeightLogger.Log("Patched LethalWeightMod.", (LogLevel)16, Logger.LogLevelConfig.Everything);
			lWeightLogger.Log("Patching PlayerControllerBPatch...", (LogLevel)16, Logger.LogLevelConfig.Everything);
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			lWeightLogger.Log("Patched PlayerControllerBPatch.", (LogLevel)16, Logger.LogLevelConfig.Everything);
		}
	}
}
namespace LethalWeight.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		public static float logTimer;

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		public static void PreUpdate(ref float ___carryWeight, ref float ___fallValueUncapped)
		{
			float num = Mathf.Clamp(___carryWeight - 1f, 0f, 100f) * 105f;
			float num2 = LethalWeightMod.fallPerLB * num;
			float deltaTime = Time.deltaTime;
			if (logTimer > 5f)
			{
				string text = $"Weight LB: {num}";
				LethalWeightMod.lWeightLogger.Log(text, (LogLevel)16);
				text = $"Fall Value Uncapped:{___fallValueUncapped}";
				LethalWeightMod.lWeightLogger.Log(text, (LogLevel)16);
				text = $"Extra Fall Value Uncapped:{num2}";
				LethalWeightMod.lWeightLogger.Log(text, (LogLevel)16);
				logTimer = 0f;
			}
			if (___fallValueUncapped < 0f)
			{
				___fallValueUncapped -= num2 * deltaTime;
			}
		}
	}
}