Decompiled source of Magni v1.0.3

Magni.dll

Decompiled 11 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Magni")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Crystal")]
[assembly: AssemblyProduct("Magni")]
[assembly: AssemblyCopyright("Copyright © 2023 Crystal Ferrai")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("32a6e5cb-3899-484c-8146-4cb67131cbf9")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.3.0")]
namespace Magni;

[BepInPlugin("dev.crystal.magni", "Magni", "1.0.3.0")]
[BepInProcess("valheim.exe")]
[BepInProcess("valheim_server.exe")]
public class MagniPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player))]
	private static class Player_Patches
	{
		[HarmonyPatch("GetMaxCarryWeight")]
		[HarmonyPostfix]
		private static void GetMaxCarryWeight_Postfix(Player __instance, ref float __result)
		{
			__result *= CarryCapacityMultiplier.Value;
		}
	}

	public const string ModId = "dev.crystal.magni";

	public static ConfigEntry<float> CarryCapacityMultiplier;

	private static Harmony sPlayerHarmony;

	private void Awake()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		CarryCapacityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Weight", "CarryCapacityMultiplier", 2f, "Multiplier to apply to max carry weight capacity. Game default = 1.0. Mod default = 2.0.");
		CarryCapacityMultiplier.SettingChanged += CarryCapacity_SettingChanged;
		ClampConfig();
		sPlayerHarmony = new Harmony("dev.crystal.magni_Player");
		sPlayerHarmony.PatchAll(typeof(Player_Patches));
	}

	private void OnDestroy()
	{
		sPlayerHarmony.UnpatchSelf();
	}

	private static void ClampConfig()
	{
		if (CarryCapacityMultiplier.Value < 0f)
		{
			CarryCapacityMultiplier.Value = 0f;
		}
		if (CarryCapacityMultiplier.Value > 1000f)
		{
			CarryCapacityMultiplier.Value = 1000f;
		}
	}

	private void CarryCapacity_SettingChanged(object sender, EventArgs e)
	{
		ClampConfig();
	}
}