Decompiled source of DynamicExperienceGain v1.0.5

ValheimDynamicExperience.dll

Decompiled 3 hours ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
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("ValheimDynamicExperience")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimDynamicExperience")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b3c3dce9-5844-4237-9823-889e2ada93e3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ValheimDynamicExperience;

[BepInPlugin("com.ExperienceMod", "Experience Mod", "1.0.0")]
[BepInProcess("valheim.exe")]
public class ExperienceMod : BaseUnityPlugin
{
	private static class Enemy
	{
		public static float Tier = 1f;

		public static int Level = 1;
	}

	[HarmonyPatch(typeof(Character), "Damage")]
	private static class GetHitEnemyTier
	{
		private static void Postfix(Character __instance)
		{
			string key = ((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "").Trim();
			Enemy.Tier = (EnemyTiers.TryGetValue(key, out var value) ? value : 1f);
			Enemy.Level = __instance.GetLevel();
		}
	}

	[HarmonyPatch(typeof(BaseAI), "InStealthRange")]
	private static class CaptureEnemyTier
	{
		private static void Postfix(Character me, bool __result)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!__result)
			{
				return;
			}
			foreach (BaseAI baseAIInstance in BaseAI.BaseAIInstances)
			{
				if (!baseAIInstance.IsEnemy(me))
				{
					continue;
				}
				float num = Vector3.Distance(((Component)me).transform.position, ((Component)baseAIInstance).transform.position);
				if (!(num > 50f))
				{
					Character value = Traverse.Create((object)baseAIInstance).Field("m_character").GetValue<Character>();
					string key = ((Object)((Component)value).gameObject).name.Replace("(Clone)", "").Trim();
					if (EnemyTiers.TryGetValue(key, out var value2))
					{
						Enemy.Tier = value2;
						Enemy.Level = value.GetLevel();
						break;
					}
				}
			}
		}
	}

	[HarmonyPatch(typeof(MonsterAI), "DoAttack")]
	private static class CaptureAttackerTier
	{
		private static void Prefix(Character target, Character ___m_character)
		{
			if (!((Object)(object)target == (Object)null) && !((Object)(object)___m_character == (Object)null) && target.IsPlayer())
			{
				string key = ((Object)((Component)___m_character).gameObject).name.Replace("(Clone)", "").Trim();
				Enemy.Tier = (EnemyTiers.TryGetValue(key, out var value) ? value : 1f);
				Enemy.Level = ___m_character.GetLevel();
			}
		}
	}

	[HarmonyPatch(typeof(Fish), "GetStaminaUse")]
	private static class GetFishTier
	{
		private static void Prefix(Fish __instance, ItemDrop ___m_itemDrop)
		{
			string key = ((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "").Trim();
			Enemy.Tier = (EnemyTiers.TryGetValue(key, out var value) ? value : 1f);
			Enemy.Level = ___m_itemDrop.m_itemData.m_quality;
		}
	}

	[HarmonyPatch(typeof(Skill), "Raise")]
	private static class ApplyTierMultiplier
	{
		private static void Prefix(ref float factor)
		{
			factor = (factor + factor * (Enemy.Tier - 1f) / 3f) * (float)Enemy.Level;
			Debug.Log((object)factor);
		}

		private static void Postfix(SkillDef ___m_info, ref float factor)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			if ((int)___m_info.m_skill != 108)
			{
				Enemy.Tier = 1f;
				Enemy.Level = 1;
			}
		}
	}

	private readonly Harmony harmony = new Harmony("com.ExperienceMod");

	private static readonly Dictionary<string, float> EnemyTiers = new Dictionary<string, float>
	{
		{ "Eikthyr", 2f },
		{ "gd_king", 3f },
		{ "Bonemass", 4f },
		{ "Dragon", 5f },
		{ "GoblinKing", 6f },
		{ "SeekerQueen", 7f },
		{ "Fader", 8f },
		{ "BogWitchKvastur", 5f },
		{ "Charred_Melee_Dyrnwyn", 7f },
		{ "GoblinBruteBros", 6f },
		{ "GoblinShaman_Hildir", 6f },
		{ "GoblinBrute_Hildir", 6f },
		{ "Fenring_Cultist_Hildir", 6f },
		{ "Skeleton_Hildir", 5f },
		{ "Deer", 1f },
		{ "Boar", 1f },
		{ "Neck", 1f },
		{ "Greyling", 1f },
		{ "Greydwarf", 2f },
		{ "Bjorn", 2f },
		{ "Greydwarf_Elite", 2f },
		{ "Greydwarf_Shaman", 2f },
		{ "Fenring", 4f },
		{ "Fenring_Cultist", 4f },
		{ "Ulv", 4f },
		{ "Bat", 4f },
		{ "TentaRoot", 2f },
		{ "Skeleton", 2f },
		{ "Skeleton_Poison", 2f },
		{ "Ghost", 2f },
		{ "Draugr", 3f },
		{ "Draugr_Elite", 3f },
		{ "Goblin", 5f },
		{ "GoblinShaman", 5f },
		{ "GoblinBrute", 5f },
		{ "Troll", 2f },
		{ "Unbjorn", 5f },
		{ "Surtling", 5f },
		{ "Blob", 3f },
		{ "BlobElite", 3f },
		{ "BlobTar", 5f },
		{ "Leech", 3f },
		{ "Lox", 5f },
		{ "Deathsquito", 5f },
		{ "Wraith", 3f },
		{ "StoneGolem", 4f },
		{ "Hatchling", 4f },
		{ "Wolf", 4f },
		{ "Serpent", 3f },
		{ "Abomination", 3f },
		{ "Seeker", 6f },
		{ "SeekerBrute", 6f },
		{ "SeekerBrood", 6f },
		{ "Dverger", 6f },
		{ "DvergerMage", 6f },
		{ "Gjall", 6f },
		{ "Hare", 6f },
		{ "Tick", 6f },
		{ "BonemawSerpent", 7f },
		{ "FallenValkyrie", 7f },
		{ "Morgen_NonSleeping", 7f },
		{ "Morgen", 7f },
		{ "Asksvin", 7f },
		{ "Volture", 7f },
		{ "Charred_Twitcher", 7f },
		{ "Charred_Archer", 7f },
		{ "Charred_Melee", 7f },
		{ "Charred_Mage", 7f },
		{ "BlobLava", 7f },
		{ "DvergerAshlands", 7f },
		{ "Fish1", 1f },
		{ "Fish2", 1f },
		{ "Fish3", 3f },
		{ "Fish4_cave", 4f },
		{ "Fish5", 2f },
		{ "Fish6", 3f },
		{ "Fish7", 5f },
		{ "Fish8", 3f },
		{ "Fish9", 6f },
		{ "Fish12", 6f },
		{ "Fish10", 8f },
		{ "Fish11", 7f }
	};

	private void Awake()
	{
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Dynamic Experience Mod loaded!");
	}
}