Decompiled source of Disable Damage Merge v1.0.6

BepInEx/plugins/com.shazixnar.DisableDamageMerge.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 BepInEx.Logging;
using Cards;
using Damage;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Obeliskial_Essentials;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.shazixnar.DisableDamageMerge")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Disable same-type damage merging, made by Shazixnar")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6")]
[assembly: AssemblyProduct("Disable Damage Merge")]
[assembly: AssemblyTitle("com.shazixnar.DisableDamageMerge")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.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 DisableDamageMerge
{
	[HarmonyPatch(typeof(DamageMechanics), "MergeDamages")]
	public static class MergeDamagesPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(List<DamageEffectData> sourceList, DamageType damageTypeOverride, ref List<DamageEffectData> __result)
		{
			//IL_0029: 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)
			if (sourceList == null)
			{
				__result = new List<DamageEffectData>();
				return false;
			}
			List<DamageEffectData> list = new List<DamageEffectData>(sourceList.Count);
			for (int i = 0; i < sourceList.Count; i++)
			{
				DamageEffectData val = sourceList[i].Clone();
				if ((int)damageTypeOverride != 0)
				{
					val.DamageType = damageTypeOverride;
				}
				list.Add(val);
			}
			__result = list;
			return false;
		}
	}
	[BepInPlugin("com.shazixnar.DisableDamageMerge", "Disable Damage Merge", "1.0.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("AcrossTheObelisk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal const int ModDate = 20261126;

		private readonly Harmony harmony = new Harmony("com.shazixnar.DisableDamageMerge");

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			PreviewDamageSplitPatch.LogWarn = delegate(string m)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)m);
			};
			PreviewDamageSplitPatch.LogInfo = delegate(string m)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)m);
			};
			Log.LogInfo((object)"com.shazixnar.DisableDamageMerge 1.0.6 has loaded!");
			Essentials.RegisterMod("Disable Damage Merge", "Shazixnar", "Keeps same-type damage instances separate instead of merging them into one number.", "1.0.6", 20261126, "https://across-the-obelisk.thunderstore.io/package/Shazixnar/Disable_Damage_Merge/", (string[])null, "", 100, new string[1] { "utility" }, "", true);
			harmony.PatchAll();
		}
	}
	[HarmonyPatch(typeof(MatchManager), "SetDamagePreview", new Type[]
	{
		typeof(bool),
		typeof(CardRealtimeData),
		typeof(int)
	})]
	public static class PreviewDamageSplitPatch
	{
		internal static Action<string> LogWarn;

		internal static Action<string> LogInfo;

		private static bool IsLdloc(CodeInstruction c)
		{
			if (!(c.opcode == OpCodes.Ldloc_S))
			{
				return c.opcode == OpCodes.Ldloc;
			}
			return true;
		}

		private static bool IsStloc(CodeInstruction c)
		{
			if (!(c.opcode == OpCodes.Stloc_S))
			{
				return c.opcode == OpCodes.Stloc;
			}
			return true;
		}

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Expected O, but got Unknown
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			int num = list.FindIndex((CodeInstruction c) => c.opcode == OpCodes.Ldc_I4 && c.operand is int num8 && num8 == 99999999);
			if (num < 0)
			{
				LogWarn?.Invoke("[preview] 99999999 sentinel not found, preview left as vanilla");
				return list;
			}
			int num2 = -1;
			for (int num3 = num; num3 < list.Count; num3++)
			{
				if (list[num3].opcode == OpCodes.Bne_Un || list[num3].opcode == OpCodes.Bne_Un_S)
				{
					num2 = num3;
					break;
				}
			}
			if (num2 < 0)
			{
				LogWarn?.Invoke("[preview] bne.un not found, preview left as vanilla");
				return list;
			}
			int num4 = -1;
			for (int num5 = num2; num5 + 3 < list.Count; num5++)
			{
				CodeInstruction val = list[num5];
				CodeInstruction val2 = list[num5 + 1];
				CodeInstruction val3 = list[num5 + 2];
				CodeInstruction val4 = list[num5 + 3];
				if (IsLdloc(val) && IsLdloc(val2) && val3.opcode == OpCodes.Add && IsStloc(val4) && val.operand == val4.operand && val.operand != val2.operand)
				{
					num4 = num5;
					break;
				}
			}
			if (num4 < 0)
			{
				LogWarn?.Invoke("[preview] damage sum not found, preview left as vanilla");
				return list;
			}
			CodeInstruction val5 = new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
			val5.labels.AddRange(list[num4 + 1].labels);
			list[num4 + 1] = val5;
			int num6 = -1;
			for (int num7 = num4 + 1; num7 < list.Count; num7++)
			{
				if ((list[num7].opcode == OpCodes.Beq || list[num7].opcode == OpCodes.Beq_S) && num7 >= 2 && IsLdloc(list[num7 - 1]) && IsLdloc(list[num7 - 2]))
				{
					num6 = num7;
					break;
				}
			}
			if (num6 < 0)
			{
				LogWarn?.Invoke("[preview] same-type continue not found, preview shows first segment only");
				return list;
			}
			CodeInstruction val6 = new CodeInstruction(OpCodes.Pop, (object)null);
			val6.labels.AddRange(list[num6].labels);
			list[num6] = val6;
			list.Insert(num6, new CodeInstruction(OpCodes.Pop, (object)null));
			LogInfo?.Invoke("[preview] same-type damage preview split enabled");
			return list;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.shazixnar.DisableDamageMerge";

		public const string PLUGIN_NAME = "Disable Damage Merge";

		public const string PLUGIN_VERSION = "1.0.6";
	}
}