Decompiled source of VanillaSkillsModifier v1.0.0

MGDev.VanillaSkillsModifier.dll

Decompiled 7 hours 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(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("MGDev.VanillaSkillsModifier")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MGDev.VanillaSkillsModifier")]
[assembly: AssemblyTitle("MGDev.VanillaSkillsModifier")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 MGDev.VanillaSkillsModifier
{
	[BepInPlugin("mgdev.vanillaskillsmodifier", "Vanilla Skills Modifier", "1.0.0")]
	public class VanillaSkillsModifierPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "mgdev.vanillaskillsmodifier";

		public const string PluginName = "Vanilla Skills Modifier";

		public const string PluginVersion = "1.0.0";

		private static readonly Dictionary<SkillType, SkillConfig> SkillSettings = new Dictionary<SkillType, SkillConfig>();

		private Harmony _harmony;

		private const string RecommendedRange = "Recommended range: 0.1 to 10.";

		private const string GlobalStackingNote = "Stacks with each skill's own multiplier. Example: global 1.5 and Swords 1.5 = 2.25 total.";

		internal static ConfigEntry<float> GlobalXpMultiplier;

		internal static ConfigEntry<float> GlobalEffectMultiplier;

		internal static ConfigEntry<float> GlobalWeaponDamageAt100;

		internal static ConfigEntry<float> BackstabDamageAt100;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			BindConfig();
			_harmony = new Harmony("mgdev.vanillaskillsmodifier");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Vanilla Skills Modifier 1.0.0 loaded.");
		}

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

		private void BindConfig()
		{
			GlobalXpMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("01 - Global", "AllSkillsXpMultiplier", 1f, "Changes how fast every skill levels.\nStacks with each skill's own multiplier. Example: global 1.5 and Swords 1.5 = 2.25 total.\nRecommended range: 0.1 to 10.");
			GlobalEffectMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("01 - Global", "AllSkillsEffectMultiplier", 1f, "Changes the normal benefit from every skill.\nThis affects whatever that skill already does in the game.\nStacks with each skill's own multiplier. Example: global 1.5 and Swords 1.5 = 2.25 total.\nRecommended range: 0.1 to 10.");
			GlobalWeaponDamageAt100 = ((BaseUnityPlugin)this).Config.Bind<float>("01 - Global", "WeaponDamage", 1f, "Extra damage for weapon, tool, and magic skills. The full value is reached at skill level 100.\nAffects swords, knives, clubs, polearms, spears, axes, bows, crossbows, unarmed, pickaxes, wood cutting, elemental magic, and blood magic.\nRecommended range: 0.1 to 10.");
			BackstabDamageAt100 = ((BaseUnityPlugin)this).Config.Bind<float>("02 - Smart Tweaks", "SneakBackstabDamageAtLevel100", 1f, "Sneak helps stamina and stealth only.\nChange this to also make Sneak increase backstab damage. 1 means no extra damage.\nRecommended range: 0.1 to 10.");
			BindSkill("03 - Swords", (SkillType)1, "Swords");
			BindSkill("04 - Knives", (SkillType)2, "Knives");
			BindSkill("05 - Clubs", (SkillType)3, "Clubs");
			BindSkill("06 - Polearms", (SkillType)4, "Polearms");
			BindSkill("07 - Spears", (SkillType)5, "Spears");
			BindSkill("08 - Blocking", (SkillType)6, "Blocking");
			BindSkill("09 - Axes", (SkillType)7, "Axes");
			BindSkill("10 - Bows", (SkillType)8, "Bows");
			BindSkill("11 - Elemental Magic", (SkillType)9, "Elemental Magic");
			BindSkill("12 - Blood Magic", (SkillType)10, "Blood Magic");
			BindSkill("13 - Unarmed", (SkillType)11, "Unarmed");
			BindSkill("14 - Pickaxes", (SkillType)12, "Pickaxes");
			BindSkill("15 - Wood Cutting", (SkillType)13, "Wood Cutting");
			BindSkill("16 - Crossbows", (SkillType)14, "Crossbows");
			BindSkill("17 - Jump", (SkillType)100, "Jump");
			BindSkill("18 - Sneak", (SkillType)101, "Sneak");
			BindSkill("19 - Run", (SkillType)102, "Run");
			BindSkill("20 - Swim", (SkillType)103, "Swim");
			BindSkill("21 - Fishing", (SkillType)104, "Fishing");
			BindSkill("22 - Cooking", (SkillType)105, "Cooking");
			BindSkill("23 - Farming", (SkillType)106, "Farming");
			BindSkill("24 - Crafting", (SkillType)107, "Crafting");
			BindSkill("25 - Dodge", (SkillType)108, "Dodge");
			BindSkill("26 - Ride", (SkillType)110, "Ride");
		}

		private void BindSkill(string section, SkillType skill, string displayName)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			SkillSettings[skill] = new SkillConfig
			{
				XpMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(section, displayName.Replace(" ", "") + "XpMultiplier", 1f, "Multiplies XP gain for " + displayName + ".\nExample: 3 means this skill levels three times faster.\nRecommended range: 0.1 to 10."),
				EffectMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(section, displayName.Replace(" ", "") + "EffectMultiplier", 1f, GetEffectDescription(displayName, skill))
			};
		}

		private string GetEffectDescription(string displayName, SkillType skill)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected I4, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected I4, but got Unknown
			switch (skill - 1)
			{
			default:
				return (skill - 100) switch
				{
					0 => AddRange("Changes the normal Jump skill benefit.\nEffect: higher jump force."), 
					1 => AddRange("Changes the normal Sneak skill benefit.\nEffect: lower sneak stamina use and better stealth."), 
					2 => AddRange("Changes the normal Run skill benefit.\nEffect: faster running and lower run stamina drain."), 
					3 => AddRange("Changes the normal Swim skill benefit.\nEffect: lower swim stamina drain."), 
					4 => AddRange("Changes the normal Fishing skill benefit.\nEffect: easier reeling, lower stamina use, and faster line pull."), 
					5 => AddRange("Changes the normal Cooking skill benefit.\nEffect: bonus food chance when taking cooked food, plus faster crafting and bonus output at stations that use Cooking."), 
					6 => AddRange("Changes the normal Farming skill benefit.\nEffect: larger harvest radius, plus bonus yield chance for pickables that use Farming."), 
					7 => AddRange("Changes the normal Crafting skill benefit.\nEffect: faster crafting and bonus output for stackable items at stations that use Crafting."), 
					8 => AddRange("Changes the normal Dodge skill benefit.\nEffect: lower dodge stamina cost."), 
					10 => AddRange("Changes the normal Ride skill benefit.\nEffect: lower mounted stamina drain while riding."), 
					_ => AddRange("Changes the normal " + displayName + " skill benefit."), 
				};
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
			case 6:
			case 10:
				return AddRange("Changes the normal " + displayName + " skill benefit.\nEffect: more damage and lower attack stamina use.");
			case 7:
				return AddRange("Changes the normal Bows skill benefit.\nEffect: more damage, faster draw, better accuracy, and lower draw stamina use.");
			case 13:
				return AddRange("Changes the normal Crossbows skill benefit.\nEffect: more damage, faster reload, better accuracy, and lower stamina use where the weapon uses stamina.");
			case 8:
				return AddRange("Changes the normal Elemental Magic skill benefit.\nEffect: stronger elemental magic and lower eitr use.");
			case 9:
				return AddRange("Changes the normal Blood Magic skill benefit.\nEffect: stronger blood magic and lower health/eitr cost.");
			case 5:
				return AddRange("Changes the normal Blocking skill benefit.\nEffect: more block power, which can reduce block stamina pressure.");
			case 11:
			case 12:
				return AddRange("Changes the normal " + displayName + " skill benefit.\nEffect: more tool damage and lower stamina use.");
			}
		}

		private static string AddRange(string description)
		{
			return description + "\nRecommended range: 0.1 to 10.";
		}

		internal static float GetXpMultiplier(SkillType skill)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			SkillConfig value;
			return Mathf.Max(0f, GlobalXpMultiplier.Value) * (SkillSettings.TryGetValue(skill, out value) ? Mathf.Max(0f, value.XpMultiplier.Value) : 1f);
		}

		internal static float GetEffectMultiplier(SkillType skill)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			SkillConfig value;
			return Mathf.Max(0f, GlobalEffectMultiplier.Value) * (SkillSettings.TryGetValue(skill, out value) ? Mathf.Max(0f, value.EffectMultiplier.Value) : 1f);
		}

		internal static float GetDamageAt100(SkillType skill)
		{
			return Mathf.Max(0f, GlobalWeaponDamageAt100.Value);
		}

		internal static bool IsCombatSkill(SkillType skill)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			if (skill - 1 <= 4 || skill - 7 <= 7)
			{
				return true;
			}
			return false;
		}

		internal static float ScaleBySkill(float level, float multiplierAt100)
		{
			return Mathf.Lerp(1f, Mathf.Max(0f, multiplierAt100), Mathf.Clamp01(level / 100f));
		}
	}
	internal class SkillConfig
	{
		public ConfigEntry<float> XpMultiplier;

		public ConfigEntry<float> EffectMultiplier;
	}
	[HarmonyPatch(typeof(Player), "RaiseSkill")]
	internal static class PlayerRaiseSkillPatch
	{
		private static void Prefix(SkillType skill, ref float value)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			value *= VanillaSkillsModifierPlugin.GetXpMultiplier(skill);
		}
	}
	[HarmonyPatch(typeof(Skills), "GetSkillFactor")]
	internal static class SkillsGetSkillFactorPatch
	{
		private static void Postfix(SkillType skillType, ref float __result)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			__result *= VanillaSkillsModifierPlugin.GetEffectMultiplier(skillType);
		}
	}
	[HarmonyPatch(typeof(Skills), "GetRandomSkillFactor")]
	internal static class SkillsGetRandomSkillFactorPatch
	{
		private static void Postfix(SkillType skillType, ref float __result)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			__result *= VanillaSkillsModifierPlugin.GetEffectMultiplier(skillType);
		}
	}
	[HarmonyPatch(typeof(Character), "Damage")]
	internal static class CharacterDamagePatch
	{
		private static void Prefix(HitData hit)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Character attacker = hit.GetAttacker();
			if (!((Object)(object)attacker == (Object)null) && attacker.IsPlayer())
			{
				if (VanillaSkillsModifierPlugin.IsCombatSkill(hit.m_skill))
				{
					float num = VanillaSkillsModifierPlugin.ScaleBySkill(hit.m_skillLevel, VanillaSkillsModifierPlugin.GetDamageAt100(hit.m_skill));
					hit.ApplyModifier(num);
				}
				if (hit.m_backstabBonus > 1f)
				{
					float skillLevel = attacker.GetSkillLevel((SkillType)101);
					hit.m_backstabBonus *= VanillaSkillsModifierPlugin.ScaleBySkill(skillLevel, VanillaSkillsModifierPlugin.BackstabDamageAt100.Value);
				}
			}
		}
	}
}