Decompiled source of LethalWeights v0.5.1

LethalWeights.dll

Decompiled 2 hours ago
using System.Diagnostics;
using System.Linq;
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 LethalWeights.Patches;
using Unity.Netcode;
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("LethalWeights")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalWeights")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("04447e67-06dc-41bb-98b9-68a2a160593d")]
[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")]
[HarmonyPatch(typeof(NetworkManager))]
internal static class KickIfModNotInstalled
{
	private static readonly string MOD_GUID = "GStar.LethalWeights";

	[HarmonyPostfix]
	[HarmonyPatch("SetSingleton")]
	private static void RegisterPrefab()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(MOD_GUID + " Prefab");
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		Object.DontDestroyOnLoad((Object)(object)val);
		NetworkObject obj = val.AddComponent<NetworkObject>();
		FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
		field.SetValue(obj, GetHash(MOD_GUID));
		NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}
	}
}
namespace LethalWeights
{
	[BepInPlugin("GStar.LethalWeights", "LethalWeights", "1.0.0")]
	public class LethalWeightsBase : BaseUnityPlugin
	{
		private const string modGUID = "GStar.LethalWeights";

		private const string modName = "LethalWeights";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("GStar.LethalWeights");

		private static LethalWeightsBase Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("GStar.LethalWeights");
			mls.LogInfo((object)"LethalWeights is running...");
			harmony.PatchAll(typeof(LethalWeightsBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(KickIfModNotInstalled));
		}
	}
}
namespace LethalWeights.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void LethalWeightsPatch(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (Object)(object)__instance.currentlyHeldObjectServer != (Object)null)
			{
				float num = (__instance.carryWeight - 1f) * 105f;
				float num2 = num / 2.20462f;
				float num3 = 70f + num2;
				float num4 = 5f;
				float num5 = num3 * 0.03f;
				float fallValue = Mathf.Max(0.5f, num4 - num5);
				__instance.fallValue = fallValue;
			}
		}
	}
}