Decompiled source of DadsSkills v1.0.0

DadsSkills.dll

Decompiled 2 weeks 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 Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DadsSkills")]
[assembly: AssemblyDescription("Five-level skill checkpoints through level 75 for Valheim")]
[assembly: AssemblyCompany("Dad_Is_Bored")]
[assembly: AssemblyProduct("DadsSkills")]
[assembly: AssemblyCopyright("Copyright 2026 Dad_Is_Bored")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 DadsSkills
{
	[BepInPlugin("com.dadisbored.dadsskills", "DadsSkills", "1.0.0")]
	[BepInProcess("valheim.exe")]
	public sealed class DadsSkillsPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.dadisbored.dadsskills";

		public const string PluginName = "DadsSkills";

		public const string PluginVersion = "1.0.0";

		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
			_harmony = new Harmony("com.dadisbored.dadsskills");
			_harmony.PatchAll(typeof(DadsSkillsPlugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"DadsSkills 1.0.0 loaded. Skill checkpoints are protected every five levels through level 75.");
		}

		private void OnDestroy()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(Skills), "OnDeath")]
	internal static class SkillDeathCheckpointPatch
	{
		private const float CheckpointInterval = 5f;

		private const float MaximumProtectedLevel = 75f;

		private static void Prefix(Skills __instance, out Dictionary<Skill, float> __state)
		{
			__state = new Dictionary<Skill, float>();
			foreach (Skill skill in __instance.GetSkillList())
			{
				if (skill != null && !float.IsNaN(skill.m_level))
				{
					__state[skill] = GetProtectedFloor(skill.m_level);
				}
			}
		}

		private static void Postfix(Dictionary<Skill, float> __state)
		{
			if (__state == null)
			{
				return;
			}
			foreach (KeyValuePair<Skill, float> item in __state)
			{
				Skill key = item.Key;
				if (key != null && key.m_level < item.Value)
				{
					key.m_level = item.Value;
				}
			}
		}

		internal static float GetProtectedFloor(float level)
		{
			if (float.IsNaN(level) || level <= 0f)
			{
				return 0f;
			}
			if (level >= 75f)
			{
				return 75f;
			}
			return (float)Math.Floor(level / 5f) * 5f;
		}
	}
}