Decompiled source of BlockTweaks v1.0.0

BlockTweaks.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BlockTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BlockTweaks")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("463862b2-698f-44fd-8a9e-f600655ba681")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace mennowar.mods;

[BepInPlugin("mennowar.mods.BlockTweaks", "BlockTweaks", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BlockTweaks : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ItemData), "GetDeflectionForce", new Type[] { typeof(int) })]
	public class BlockheimPatch1
	{
		private static void Postfix(ref ItemData __instance, ref float __result)
		{
			if (RemoveDeflectionForce.Value)
			{
				Debug("Removing Deflection Force");
				__result = 0f;
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid))]
	[HarmonyPatch("BlockAttack")]
	private class BlockPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			if (!IgnoreBlockArmorExceedingDamage.Value)
			{
				Debug("Not patching block attack");
				return list.AsEnumerable();
			}
			int num = 0;
			try
			{
				int num2 = list.FindIndex((CodeInstruction p) => p.opcode == OpCodes.Call && p.operand.ToString().Contains("AddStaggerDamage"));
				LocalBuilder localBuilder = (LocalBuilder)list[num2 + 1].operand;
				int num3 = list.FindIndex((CodeInstruction p) => p.opcode == OpCodes.Callvirt && p.operand.ToString().Contains("BlockDamage"));
				if (num3 > -1)
				{
					for (int num4 = num3; num4 > num2; num4--)
					{
						if (CodeInstructionExtensions.IsLdloc(list[num4], localBuilder) && (list[num4 + 1].opcode == OpCodes.Brtrue || list[num4 + 1].opcode == OpCodes.Brtrue_S))
						{
							num = num4;
							break;
						}
					}
					if (num > 0)
					{
						list.RemoveRange(num, 2);
						Debug("Patching block attack successful");
					}
				}
			}
			catch (Exception arg)
			{
				Debug($"Block attack Exception\n{arg}", forceOutput: true);
			}
			if (num == 0)
			{
				Debug("Patching block attack failed.", forceOutput: true);
			}
			return list.AsEnumerable();
		}
	}

	public const string PluginGUID = "mennowar.mods.BlockTweaks";

	public const string SharedName = "BlockTweaks";

	private Harmony harmony = new Harmony("mennowar.mods.BlockTweaks");

	private static ManualLogSource DebugLogSource;

	public static ConfigEntry<bool> WriteDebugOutput;

	public static ConfigEntry<bool> RemoveDeflectionForce;

	public static ConfigEntry<bool> IgnoreBlockArmorExceedingDamage;

	private void Awake()
	{
		try
		{
			CreateConfigValues();
			harmony.PatchAll();
			Debug("Harmony patch finished");
		}
		catch (Exception)
		{
			Debug("Error running Harmony Patch:\n{ex}", forceOutput: true);
		}
	}

	private void CreateConfigValues()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		WriteDebugOutput = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "writeDebug", true, new ConfigDescription("Write Debug Informations to the console?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		RemoveDeflectionForce = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Remove Deflection force", true, new ConfigDescription("Remove the push-back of enemies when successfully deflecting", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		IgnoreBlockArmorExceedingDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Ignore BlockArmor exceeding Damage", true, new ConfigDescription("Block even when the damage exceeds your block armor and the exceeding damage fills your stagger threshold", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		Debug("Debug-Messages enabled");
		Debug($"Pushback tweak: {RemoveDeflectionForce.Value}");
		Debug($"Block armor tweak: {IgnoreBlockArmorExceedingDamage.Value}");
	}

	public static void Debug(string value, bool forceOutput = false)
	{
		if (WriteDebugOutput.Value || forceOutput)
		{
			if (DebugLogSource == null)
			{
				DebugLogSource = Logger.CreateLogSource("BlockTweaks");
			}
			if (DebugLogSource != null)
			{
				DebugLogSource.LogMessage((object)value);
			}
		}
	}
}