Decompiled source of BackShieldMod v1.0.0

JotunnModStub.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 BackShieldMod
{
	[BepInPlugin("com.oma.backshield", "BackShieldMod", "1.0.0")]
	public class BackShieldPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.oma.backshield";

		public const string PluginName = "BackShieldMod";

		public const string PluginVersion = "1.0.0";

		private Harmony harmony;

		public static ConfigEntry<float> RoundShieldEfficiency;

		public static ConfigEntry<float> TowerShieldEfficiency;

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			RoundShieldEfficiency = ((BaseUnityPlugin)this).Config.Bind<float>("Efficiency", "RoundShieldEfficiency", 0.85f, new ConfigDescription("Pyöreiden kilpien ja bucklerien torjuntateho selässä (0.0 = 0%, 1.0 = 100%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			TowerShieldEfficiency = ((BaseUnityPlugin)this).Config.Bind<float>("Efficiency", "TowerShieldEfficiency", 0.65f, new ConfigDescription("Tornikilpien torjuntateho selässä (0.0 = 0%, 1.0 = 100%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			harmony = new Harmony("com.oma.backshield");
			harmony.PatchAll();
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ApplyDamage")]
	public static class ApplyDamage_Patch
	{
		[HarmonyPrefix]
		public static void Prefix(Character __instance, HitData hit)
		{
			//IL_001c: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Invalid comparison between Unknown and I4
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val == null)
			{
				return;
			}
			float totalDamage = hit.GetTotalDamage();
			if (totalDamage <= 0f)
			{
				return;
			}
			Vector3 val2 = -hit.m_dir;
			if (!(Vector3.Angle(-((Component)val).transform.forward, val2) < 60f))
			{
				return;
			}
			float num = hit.m_point.y - ((Component)val).transform.position.y;
			if (!(num >= 0.5f) || !(num <= 2f))
			{
				return;
			}
			object? obj = AccessTools.Field(typeof(Humanoid), "m_hiddenLeftItem")?.GetValue(val);
			ItemData val3 = (ItemData)((obj is ItemData) ? obj : null);
			if (val3 != null && (int)val3.m_shared.m_itemType == 5)
			{
				float skillFactor = ((Character)val).GetSkillFactor((SkillType)6);
				float blockPower = val3.GetBlockPower(skillFactor);
				float num2 = ((val3.m_shared.m_timedBlockBonus <= 1f) ? BackShieldPlugin.TowerShieldEfficiency.Value : BackShieldPlugin.RoundShieldEfficiency.Value);
				float num3 = blockPower * num2;
				float num4 = 10f;
				if (((Character)val).HaveStamina(num4))
				{
					((Character)val).UseStamina(num4);
				}
				float num5 = Mathf.Max(0f, totalDamage - num3);
				float bodyArmor = ((Character)val).GetBodyArmor();
				float num6 = 0f;
				if (num5 > 0f)
				{
					num6 = ((!(num5 < bodyArmor * 0.5f)) ? (num5 - bodyArmor * 0.5f) : (num5 * num5 / (bodyArmor * 2f)));
					num6 = Mathf.Max(0f, num6);
				}
				hit.ApplyModifier(num6 / totalDamage);
				if (val3.m_shared.m_blockEffect != null)
				{
					val3.m_shared.m_blockEffect.Create(hit.m_point, Quaternion.identity, (Transform)null, 1f, -1);
				}
				if ((Object)(object)DamageText.instance != (Object)null)
				{
					DamageText.instance.ShowText((TextType)6, hit.m_point, num6, false);
				}
				((Character)val).RaiseSkill((SkillType)6, 0.5f);
			}
		}
	}
}