Decompiled source of PowerPersist v1.0.0

BepInEx/plugins/PowerPersist/PowerPersist.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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using LBoL.Core;
using LBoL.Core.Cards;
using LBoL.Core.Units;
using LBoL.Presentation.Units;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PowerPersist")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PowerPersist")]
[assembly: AssemblyTitle("PowerPersist")]
[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 PowerPersist
{
	[HarmonyPatch(typeof(Card), "AfterUseAction")]
	internal class Card_AfterUseAction_Patch
	{
		private static void Postfix(Card __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)__instance.CardType == 4 && ((GameEntity)__instance).GameRun != null)
			{
				Card deckCardByInstanceId = ((GameEntity)__instance).GameRun.GetDeckCardByInstanceId(__instance.InstanceId);
				if (deckCardByInstanceId != null)
				{
					((GameEntity)__instance).GameRun.RemoveDeckCard(deckCardByInstanceId, false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Unit), "LeaveBattle")]
	internal class Unit_LeaveBattle_Patch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (i + 1 < list.Count && list[i].opcode == OpCodes.Ldarg_0 && list[i + 1].opcode == OpCodes.Call)
				{
					MethodInfo methodInfo = list[i + 1].operand as MethodInfo;
					if (methodInfo != null && methodInfo.Name == "ClearStatusEffects")
					{
						list[i].opcode = OpCodes.Nop;
						list[i + 1].opcode = OpCodes.Nop;
					}
				}
			}
			return list.AsEnumerable();
		}
	}
	[HarmonyPatch(typeof(UnitView), "LeaveBattle")]
	internal class UnitView_LeaveBattle_Patch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (i + 2 < list.Count && list[i].opcode == OpCodes.Ldarg_0 && list[i + 1].opcode == OpCodes.Ldfld && list[i + 2].opcode == OpCodes.Callvirt)
				{
					FieldInfo fieldInfo = list[i + 1].operand as FieldInfo;
					MethodInfo methodInfo = list[i + 2].operand as MethodInfo;
					if (fieldInfo != null && fieldInfo.Name == "_statusWidget" && methodInfo != null && methodInfo.Name == "ClearStatusEffects")
					{
						list[i].opcode = OpCodes.Nop;
						list[i + 1].opcode = OpCodes.Nop;
						list[i + 2].opcode = OpCodes.Nop;
					}
				}
			}
			return list.AsEnumerable();
		}
	}
	[BepInPlugin("yourname.powerpersist", "PowerPersist", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PowerPersist loaded!");
		}
	}
}