Decompiled source of PhysicalProgression v1.0.1

BepInEx/plugins/PhysicalProgression/PhysicalProgression.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("PhysicalProgression")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+92a8ca74ab5986fa5a570847c9625610e7b3dbf4")]
[assembly: AssemblyProduct("PhysicalProgression")]
[assembly: AssemblyTitle("PhysicalProgression")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 PhysicalProgression
{
	public static class BonusCalculation
	{
		public static int Contribution(float level, int at100)
		{
			if (float.IsNaN(level))
			{
				return 0;
			}
			return (int)((long)(int)Math.Floor(Math.Max(0.0, Math.Min(100.0, level)) / 5.0) * (long)Math.Max(0, at100) / 20);
		}
	}
	[BepInPlugin("physicalprogression.valheim", "Physical Progression", "1.0.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class SkillBonuses
		{
			public ConfigEntry<int> Health;

			public ConfigEntry<int> Stamina;
		}

		[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
		private static class FoodTotalsPatch
		{
			[HarmonyPostfix]
			private static void Postfix(Player __instance, ref float __0, ref float __1)
			{
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
				{
					return;
				}
				Skills skills = ((Character)__instance).GetSkills();
				if ((Object)(object)skills == (Object)null)
				{
					return;
				}
				int num = baseHealth.Value;
				int num2 = baseStamina.Value;
				foreach (Skill skill in skills.GetSkillList())
				{
					if (bonuses.TryGetValue(skill.m_info.m_skill, out var value))
					{
						num += BonusCalculation.Contribution(skill.m_level, value.Health.Value);
						num2 += BonusCalculation.Contribution(skill.m_level, value.Stamina.Value);
					}
				}
				__0 += num;
				__1 += num2;
			}
		}

		public const string Id = "physicalprogression.valheim";

		private static ConfigEntry<int> baseHealth;

		private static ConfigEntry<int> baseStamina;

		private static readonly Dictionary<SkillType, SkillBonuses> bonuses = new Dictionary<SkillType, SkillBonuses>();

		private Harmony harmony;

		private ConfigEntry<int> Bind(string section, string key, int value, string description)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<int>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>()));
		}

		private unsafe void Awake()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			baseHealth = Bind("General", "BaseHealthBonus", 15, "Flat maximum health bonus. Restart after editing config.");
			baseStamina = Bind("General", "BaseStaminaBonus", 15, "Flat maximum stamina bonus. Restart after editing config.");
			bonuses.Clear();
			SkillType[] array = new SkillType[4];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			SkillType[] array2 = (SkillType[])(object)array;
			for (int i = 0; i < array2.Length; i++)
			{
				SkillType key = array2[i];
				bonuses.Add(key, new SkillBonuses
				{
					Health = Bind(((object)(*(SkillType*)(&key))/*cast due to .constrained prefix*/).ToString(), "HealthAt100", 20, "Health at level 100. Awarded in five-level steps, rounded down to whole points."),
					Stamina = Bind(((object)(*(SkillType*)(&key))/*cast due to .constrained prefix*/).ToString(), "StaminaAt100", 20, "Stamina at level 100. Awarded in five-level steps, rounded down to whole points.")
				});
			}
			harmony = new Harmony("physicalprogression.valheim");
			harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Physical Progression loaded: whole-point bonuses every five trained skill levels.");
		}

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