Decompiled source of Level Carry Weight v1.0.0

plugins/LevelCarryWeight.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("BenjSammy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Level Carry Weight")]
[assembly: AssemblyTitle("LevelCarryWeight")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BenjSammy.LevelCarryWeight;

[BepInPlugin("benjsammy.levelcarryweight", "Level Carry Weight", "1.0.0")]
public sealed class LevelCarryWeightPlugin : BaseUnityPlugin
{
	public const string Id = "benjsammy.levelcarryweight";

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		_harmony = new Harmony("benjsammy.levelcarryweight");
		MethodInfo methodInfo = AccessTools.Method(typeof(Player), "GetMaxCarryWeight", Type.EmptyTypes, (Type[])null);
		if (methodInfo == null || methodInfo.ReturnType != typeof(float))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Could not find Valheim's carry weight calculation.");
			return;
		}
		HarmonyMethod val = new HarmonyMethod(typeof(LevelCarryWeightPlugin), "AddCarryBonus", (Type[])null)
		{
			priority = 0
		};
		_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	private static void AddCarryBonus(Player __instance, ref float __result)
	{
		if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
		{
			float num = __result;
			Skills skills = ((Character)__instance).GetSkills();
			__result = num + (float)BonusFor((skills != null) ? skills.GetSkillList() : null);
		}
	}

	internal static int BonusFor(List<Skill> skills)
	{
		if (skills == null)
		{
			return 0;
		}
		int num = 0;
		int num2 = 0;
		foreach (Skill skill in skills)
		{
			if (skill != null)
			{
				float level = skill.m_level;
				if (++num > 512 || !(level >= 0f) || !(level <= 10000f))
				{
					return 0;
				}
				num2 += (int)level;
				if (num2 > 1000000)
				{
					return 0;
				}
			}
		}
		return num2 / 2;
	}
}