Decompiled source of Better Staff Of Protection v1.0.0

Belphegor_BetterStaffOfProtection.dll

Decompiled 3 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Belphegor_BetterStaffOfProtection.Configuration;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BetterStaffOfProtection")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterStaffOfProtection")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ea52ad2f-fc04-402d-86fd-0197379cb28b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Belphegor_BetterStaffOfProtection
{
	[BepInPlugin("Belphegor.BetterStaffOfProtection", "Better Staff Of Protection", "1.0.0")]
	public class BetterStaffOfProtection : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(SE_Shield), "OnDamaged")]
		public static class BarrierComponent_TakeDamage_Patch
		{
			private static void Prefix(SE_Shield __instance, ref Character ___m_character, ref HitData hit)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				if (config.IsIgnoreChopAndPickaxe)
				{
					DamageModifier val = default(DamageModifier);
					hit.ApplyResistance(new DamageModifiers
					{
						m_chop = (DamageModifier)4,
						m_pickaxe = (DamageModifier)4
					}, ref val);
				}
				if (config.IsOnHitExperience)
				{
					Skills skills = ___m_character.GetSkills();
					if (skills != null && Object.op_Implicit((Object)(object)skills))
					{
						skills.RaiseSkill(__instance.m_levelUpSkillOnBreak, config.OnHitExperienceFactor);
					}
				}
			}
		}

		[HarmonyPatch(typeof(SE_Shield), "SetLevel")]
		public static class StaffOfProtection_CreateBarrier_Patch
		{
			private static void Prefix(SE_Shield __instance, ref Character ___m_character, ref float ___m_damage, ref float ___m_totalAbsorbDamage, int itemLevel, float skillLevel)
			{
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				if (config.IsRecastFullRefresh && config.IsRecastExperience && (Object)(object)___m_character != (Object)null)
				{
					Skills skills = ___m_character.GetSkills();
					float num = ((___m_totalAbsorbDamage <= 0f && ___m_damage <= 0f) ? 0f : ((___m_damage >= ___m_totalAbsorbDamage) ? 1f : ((float)(Mathf.RoundToInt(10f * ___m_damage / ___m_totalAbsorbDamage) / 10))));
					if (skills != null && Object.op_Implicit((Object)(object)skills) && num > 0f)
					{
						skills.RaiseSkill(__instance.m_levelUpSkillOnBreak, config.RecastExperienceFactor * num);
					}
				}
				if (config.IsRecastFullRefresh)
				{
					___m_damage = ((___m_totalAbsorbDamage > ___m_damage) ? (___m_totalAbsorbDamage - ___m_damage) : 0f);
				}
			}

			private static void Postfix(SE_Shield __instance, ref float ___m_damage, ref float ___m_totalAbsorbDamage, int itemLevel, float skillLevel)
			{
				if (config.IsRecastFullRefresh)
				{
					___m_totalAbsorbDamage = ((___m_totalAbsorbDamage > ___m_damage) ? ___m_totalAbsorbDamage : ___m_damage);
					___m_damage = 0f;
				}
			}
		}

		[HarmonyPatch(typeof(Attack), "GetAttackHealth")]
		public static class BloodWeapon_HealthDrain_Patch
		{
			private static readonly int s_statusEffectShield = StringExtensionMethods.GetStableHashCode("Staff_shield");

			private static void Prefix(Attack __instance, ref Character ___m_character)
			{
				if (!config.IsWarlockWeapons || !(__instance.m_damageMultiplierPerMissingHP > 0f))
				{
					return;
				}
				if (___m_character.GetSEMan().HaveStatusEffect(s_statusEffectShield))
				{
					if (__instance.m_requiresReload)
					{
						__instance.m_attackHealth = __instance.m_reloadStaminaDrain * config.WarlockReloadWeaponsDrainFactor;
					}
					else if (__instance.m_bowDraw)
					{
						__instance.m_attackHealth = __instance.m_drawStaminaDrain * config.WarlockDrawWeaponsDrainFactor;
					}
					else
					{
						__instance.m_attackHealth = __instance.m_attackStamina * config.WarlockSimpleWeaponsDrainFactor;
					}
				}
				else
				{
					__instance.m_attackHealth = 0f;
				}
			}
		}

		public const string PluginID = "Belphegor.BetterStaffOfProtection";

		public const string PluginName = "Better Staff Of Protection";

		public const string Version = "1.0.0";

		internal static ManualLogSource ModLogger = new ManualLogSource(" Better Staff Of Protection");

		private readonly Harmony harmony = new Harmony("Belphegor.BetterStaffOfProtection");

		private static ModConfig config;

		private void Awake()
		{
			Logger.Sources.Add((ILogSource)(object)ModLogger);
			config = new ModConfig(((BaseUnityPlugin)this).Config);
			harmony.PatchAll();
		}
	}
}
namespace Belphegor_BetterStaffOfProtection.Configuration
{
	internal class ModConfig
	{
		private readonly ConfigFile ConfigFile;

		private static ConfigEntry<bool> configIgnoreChopAndPickaxe;

		private static ConfigEntry<bool> configRecastFullRefresh;

		private static ConfigEntry<bool> configWarlockWeapons;

		private static ConfigEntry<float> configWarlockSimpleWeaponsDrainFactor;

		private static ConfigEntry<float> configWarlockReloadWeaponsDrainFactor;

		private static ConfigEntry<float> configWarlockDrawWeaponsDrainFactor;

		private static ConfigEntry<bool> configRecastExperience;

		private static ConfigEntry<float> configRecastExperienceFactor;

		private static ConfigEntry<bool> configOnHitExperience;

		private static ConfigEntry<float> configOnHitExperienceFactor;

		internal bool IsIgnoreChopAndPickaxe => configIgnoreChopAndPickaxe.Value;

		internal bool IsRecastFullRefresh => configRecastFullRefresh.Value;

		internal bool IsWarlockWeapons => configWarlockWeapons.Value;

		internal float WarlockSimpleWeaponsDrainFactor => configWarlockSimpleWeaponsDrainFactor.Value;

		internal float WarlockReloadWeaponsDrainFactor => configWarlockReloadWeaponsDrainFactor.Value;

		internal float WarlockDrawWeaponsDrainFactor => configWarlockDrawWeaponsDrainFactor.Value;

		internal bool IsRecastExperience => configRecastExperience.Value;

		internal float RecastExperienceFactor => configRecastExperienceFactor.Value;

		internal bool IsOnHitExperience => configOnHitExperience.Value;

		internal float OnHitExperienceFactor => configOnHitExperienceFactor.Value;

		private ConfigEntry<T> Config<T>(string group, string name, T value, string description)
		{
			return ConfigFile.Bind<T>(group, name, value, description);
		}

		internal ModConfig(ConfigFile configFile)
		{
			ConfigFile = configFile;
			configIgnoreChopAndPickaxe = Config("General", "IgnoreChopAndPickaxe", value: true, "Whether or not barrier will ignore Chop and Pickaxe damage types");
			configRecastFullRefresh = Config("General", "RecastFullRefresh", value: true, "Whether or not barrier hitpoints will be refreshed on recast when previous barrier is still on");
			configWarlockWeapons = Config("Warlock", "WarlockWeapons", value: false, "Whether or not 'Blood' weapon versions drain health when barrier is on");
			configWarlockSimpleWeaponsDrainFactor = Config("Warlock", "WarlockSimpleWeaponsDrainFactor", 0.25f, "For weapons not needed to reload nor draw (aka. not Crossbows nor Bows) it represents what part of Stamina attack cost that will be drained on each attack when WarlockWeapons is on and conditions are met. [HP drain per attack] = [Stamina attack cost] * [this Value]");
			configWarlockReloadWeaponsDrainFactor = Config("Warlock", "WarlockReloadWeaponsDrainFactor", 8f, "For weapons that need to reload (aka. Crossbows) it represents what part of Stamina relod cost in second that will be drained on each attack when WarlockWeapons is on and conditions are met. [HP drain per attack] = [Stamina reload cost per sec] * [this Value]");
			configWarlockDrawWeaponsDrainFactor = Config("Warlock", "WarlockDrawWeaponsDrainFactor", 0.3f, "For weapons that need to draw (aka. Bows) it represents what part of Stamina draw cost in second that will be drained on each attack when WarlockWeapons is on and conditions are met. [HP drain per attack] = [Stamina draw cost per sec] * [this Value]");
			configRecastExperience = Config("Experience", "RecastExperience", value: true, "Whether or not experience points will be granted on recast from used part of barrier hitpoints");
			configRecastExperienceFactor = Config("Experience", "RecastExperienceFactor", 1f, "Value of experience beeing awarded when RecastExperience is on");
			configOnHitExperience = Config("Experience", "OnHitExperience", value: true, "Whether or not experience points will be granted on being hit while barier is on");
			configOnHitExperienceFactor = Config("Experience", "OnHitExperienceFactor", 0.25f, "Value of experience beeing awarded when OnHitExperience is on");
		}
	}
}