Decompiled source of Make Tower Shields Great Again v0.0.3

plugins/Factoria-TowerShieldOP/ShieldIsOP.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MrDiap")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShieldIsOP")]
[assembly: AssemblyTitle("ShieldIsOP")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 ShieldIsOP
{
	[BepInPlugin("org.bepinex.plugins.shieldisop", "ShieldIsOP", "1.0.0")]
	[BepInProcess("Valheim.exe")]
	public class ShieldIsOPPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Humanoid))]
		[HarmonyPatch("BlockAttack")]
		private class BlockPatch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Expected O, but got Unknown
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Expected O, but got Unknown
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				try
				{
					int num = list.FindLastIndex((CodeInstruction p) => p.opcode == OpCodes.Callvirt && p.operand.ToString().Contains("Damage(HitData)"));
					if (num > 0)
					{
						list.Insert(num, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
						list.Insert(num + 1, new CodeInstruction(OpCodes.Ldloc_0, (object)null));
						list.Insert(num + 2, new CodeInstruction(OpCodes.Ldarg_1, (object)null));
						list[num + 3] = CodeInstruction.Call((LambdaExpression)(Expression<Action<Humanoid, Character, HitData, ItemData, HitData>>)((Humanoid humanoid, Character c, HitData h, ItemData currentBlocker, HitData incomingHit) => UpdateHitDataOnBlockKnochback(c, h, humanoid, currentBlocker, incomingHit)));
						Debug.Log((object)"Patch successful! shieldisop!!!");
						return list;
					}
					Debug.Log((object)$"Pathching failed. damageCallIndex: {num}");
				}
				catch (Exception ex)
				{
					Debug.LogError((object)ex.Message);
				}
				return instructions;
			}
		}

		private readonly Harmony _harmony = new Harmony("org.bepinex.plugins.shieldisop");

		private void Awake()
		{
			_harmony.PatchAll();
		}

		public static void UpdateHitDataOnBlockKnochback(Character __character, HitData __hitData, Humanoid __humanoid, ItemData __currentBlocker, HitData __originalHit)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (__currentBlocker != null && !((Object)(object)__character == (Object)null) && __hitData != null)
			{
				float deflectionForce = __currentBlocker.GetDeflectionForce();
				Debug.Log((object)$"UpdateHitData() call. deflection force: {deflectionForce}");
				if (!(deflectionForce < 100f))
				{
					float skillFactor = ((Character)__humanoid).GetSkillFactor((SkillType)6);
					float blockPower = __currentBlocker.GetBlockPower(skillFactor);
					float num = (__hitData.m_damage.m_pierce = blockPower * skillFactor);
					Debug.Log((object)$"UpdateHitData() call. skillFactor: {skillFactor}, blockPower: {blockPower}, knockbackDamage: {num}");
					__character.Damage(__hitData);
					DamageText.instance.ShowText((TextType)1, __originalHit.m_point + Vector3.up * 0.5f, num, false);
				}
			}
		}
	}
}