Decompiled source of NoMoreMetaScaling v0.5.0

NoMetaScaling.dll

Decompiled 16 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AddWatermark;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoL.Core.Units;
using LBoL.Presentation;
using LBoLEntitySideloader;
using LBoLEntitySideloader.Attributes;
using LBoLEntitySideloader.CustomHandlers;
using LBoLEntitySideloader.Entities;
using LBoLEntitySideloader.Resource;
using NoMetaScaling.Core;
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: IgnoresAccessChecksTo("LBoL.Base")]
[assembly: IgnoresAccessChecksTo("LBoL.ConfigData")]
[assembly: IgnoresAccessChecksTo("LBoL.Core")]
[assembly: IgnoresAccessChecksTo("LBoL.EntityLib")]
[assembly: IgnoresAccessChecksTo("LBoL.Presentation")]
[assembly: IgnoresAccessChecksTo("Untitled.ConfigDataBuilder.Base")]
[assembly: AssemblyCompany("NoMetaScaling")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoMetaScaling")]
[assembly: AssemblyTitle("NoMetaScaling")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace NoMetaScaling
{
	internal static class Statics
	{
		internal static IResourceSource embeddedSource = (IResourceSource)new EmbeddedSource(Assembly.GetExecutingAssembly());

		internal static DirectorySource directorySource = new DirectorySource("neo.lbol.modifiers.noMetaScaling", "");

		internal static BatchLocalization seBatchLoc = new BatchLocalization((IResourceSource)(object)directorySource, typeof(StatusEffectTemplate), "fakeSE", (Locale)0, false);
	}
}
namespace NoMetaScaling.Core
{
	public static class ActionCancel
	{
		[HarmonyPatch(typeof(GameRunController), "GainMaxHp")]
		private class GainMaxHp_Patch
		{
			private static bool Prefix(GameRunController __instance)
			{
				return PrefixCancel(__instance, NoMoreMetaScalingLocSE.LocalizeProp("MaxHp"));
			}
		}

		[HarmonyPatch(typeof(GameRunController), "GainMaxHpOnly")]
		private class GainMaxHpOnly_Patch
		{
			private static bool Prefix(GameRunController __instance)
			{
				return PrefixCancel(__instance, NoMoreMetaScalingLocSE.LocalizeProp("MaxHp"));
			}
		}

		[HarmonyPatch(typeof(GameRunController), "GainMoney")]
		private class GainMoney_Patch
		{
			private static bool Prefix(GameRunController __instance)
			{
				return PrefixCancel(__instance, NoMoreMetaScalingLocSE.LocalizeProp("Money"));
			}
		}

		[HarmonyPatch(typeof(GainPowerAction), "PreEventPhase")]
		private class GainPowerAction_Patch
		{
			private static void Postfix(GainPowerAction __instance)
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Expected O, but got Unknown
				PowerEventArgs args = ((EventBattleAction<PowerEventArgs>)(object)__instance).Args;
				GameEntity obj = ((GameEventArgs)args).ActionSource?.TrickleDownActionSource();
				Card val = (Card)(object)((obj is Card) ? obj : null);
				if (val != null && val.ShouldBeBanned())
				{
					((BattleAction)__instance).React(new Reactor(DoChat((GameEntity)(object)val, NoMoreMetaScalingLocSE.LocalizeProp("Power"))), (GameEntity)null, (ActionCause?)null);
					((GameEventArgs)args).CancelBy(((GameEventArgs)args).ActionSource);
				}
			}
		}

		[HarmonyPatch(typeof(GameRunController), "UpgradeDeckCards")]
		private class UpgradeDeckCard_Patch
		{
			private static bool Prefix(GameRunController __instance)
			{
				return PrefixCancel(__instance, NoMoreMetaScalingLocSE.LocalizeProp("UpgradeACard"));
			}
		}

		private static IEnumerable<BattleAction> DoChat(GameEntity source, string cancelTarget)
		{
			GameRunController currentGameRun = Singleton<GameMaster>.Instance.CurrentGameRun;
			PlayerUnit player = ((currentGameRun != null) ? currentGameRun.Player : null);
			if (player != null)
			{
				if (Random.Range(0f, 1f) > 0.96f)
				{
					yield return (BattleAction)(object)PerformAction.Chat((Unit)(object)player, "I'M A DEGENERATE", 1.75f, 0f, 0f, true);
					yield break;
				}
				string chatString = string.Format(NoMoreMetaScalingLocSE.LocalizeProp("CancelExplain", decorate: true), cancelTarget, source.Name);
				yield return (BattleAction)(object)PerformAction.Chat((Unit)(object)player, chatString, 7f, 0f, 0f, true);
			}
		}

		private static void DoYap(Card card, string cancelTarget)
		{
			foreach (BattleAction item in DoChat((GameEntity)(object)card, cancelTarget))
			{
				CardTracker.Battle.RequestDebugAction(item, "Yapping");
			}
		}

		private static bool PrefixCancel(GameRunController gr, string cancelTarget)
		{
			BattleController battle = gr.Battle;
			if (battle == null)
			{
				return true;
			}
			GameEntity obj = ARTracker.lastActionSource?.TrickleDownActionSource();
			Card val = (Card)(object)((obj is Card) ? obj : null);
			if (val != null && val.ShouldBeBanned())
			{
				DoYap(val, cancelTarget);
				return false;
			}
			return true;
		}

		public static void RegisterHandlers()
		{
			CHandlerManager.RegisterBattleEventHandler<HealEventArgs>((EventProvider<HealEventArgs, BattleController>)((BattleController bt) => ((Unit)bt.Player).HealingReceiving), (GameEventHandler<HealEventArgs>)OnPlayerHealing, (Predicate<BattleController>)null, (GameEventPriority)int.MaxValue);
		}

		private static void OnPlayerHealing(HealEventArgs args)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			GameEntity obj = ((GameEventArgs)args).ActionSource?.TrickleDownActionSource();
			Card val = (Card)(object)((obj is Card) ? obj : null);
			if (val != null && val.ShouldBeBanned())
			{
				CardTracker.Battle.React(new Reactor(DoChat((GameEntity)(object)val, NoMoreMetaScalingLocSE.LocalizeProp("Healing"))), (GameEntity)null, (ActionCause)0);
				((GameEventArgs)args).CancelBy(((GameEventArgs)args).ActionSource);
			}
		}
	}
	public static class ARTracker
	{
		[HarmonyPatch(typeof(ActionResolver), "InternalResolve")]
		private class ActionResolver_Patch
		{
			private static void Prefix(BattleAction action)
			{
				lastActionSource = action.Source;
			}
		}

		[HarmonyPatch(typeof(BattleController), "Leave")]
		private class BattleController_Patch
		{
			private static void Postfix()
			{
				lastActionSource = null;
			}
		}

		internal static GameEntity lastActionSource;
	}
	public static class CardTracker
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(0)]
		private class BattleController_Patch
		{
			private static void Prefix(BattleController __instance)
			{
				battle_ref = new WeakReference<BattleController>(__instance);
				cwt_banData.Add(__instance, new BanData());
			}

			private static void Postfix(BattleController __instance)
			{
				startingId = __instance._cardInstanceId;
			}
		}

		private static int startingId = 1000;

		private static ConditionalWeakTable<BattleController, BanData> cwt_banData = new ConditionalWeakTable<BattleController, BanData>();

		private static WeakReference<BattleController> battle_ref;

		public static BattleController Battle
		{
			get
			{
				GameRunController currentGameRun = Singleton<GameMaster>.Instance.CurrentGameRun;
				BattleController target = ((currentGameRun != null) ? currentGameRun.Battle : null);
				if (target == null)
				{
					battle_ref.TryGetTarget(out target);
				}
				return target;
			}
		}

		[return: MaybeNull]
		public static GameEntity TrickleDownActionSource(this GameEntity actionSource)
		{
			GameEntity result = actionSource;
			StatusEffect val = (StatusEffect)(object)((actionSource is StatusEffect) ? actionSource : null);
			if (val != null && val.SourceCard != null)
			{
				result = (GameEntity)(object)val.SourceCard;
			}
			return result;
		}

		public static bool WasGenerated(this Card card)
		{
			return card.InstanceId > startingId;
		}

		public static bool ShouldBeBanned(this Card card)
		{
			return Battle != null && GetBanData(Battle).bannedCards.Contains(card);
		}

		public static BanData GetBanData(BattleController battle)
		{
			return cwt_banData.GetOrCreateValue(battle);
		}

		public static void RegisterHandlers()
		{
			RegisterCommonHandlers(OnCardCreated, (GameEventPriority)10);
			CHandlerManager.RegisterBattleEventHandler<CardMovingEventArgs>((EventProvider<CardMovingEventArgs, BattleController>)((BattleController bt) => bt.CardMoved), (GameEventHandler<CardMovingEventArgs>)OnMovedFromExile, (Predicate<BattleController>)null, (GameEventPriority)10);
		}

		private static void OnMovedFromExile(CardMovingEventArgs args)
		{
			GameEntity obj = ((GameEventArgs)args).ActionSource.TrickleDownActionSource();
			Card val = (Card)(object)((obj is Card) ? obj : null);
			if (val != null)
			{
				GetBanData(val.Battle).bannedCards.Add(args.Card);
			}
		}

		private static void OnCardCreated(Card[] cards, GameEventArgs args)
		{
			GameEntity obj = args.ActionSource.TrickleDownActionSource();
			Card val = (Card)(object)((obj is Card) ? obj : null);
			if (val != null)
			{
				foreach (Card item in cards)
				{
					GetBanData(val.Battle).bannedCards.Add(item);
				}
			}
		}

		private static void RegisterCommonHandlers(Action<Card[], GameEventArgs> handler, GameEventPriority priority = 10)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			GameEventHandler<CardsAddingToDrawZoneEventArgs> val = delegate(CardsAddingToDrawZoneEventArgs args)
			{
				handler(args.Cards, (GameEventArgs)(object)args);
			};
			GameEventHandler<CardsEventArgs> val2 = delegate(CardsEventArgs args)
			{
				handler(args.Cards, (GameEventArgs)(object)args);
			};
			CHandlerManager.RegisterBattleEventHandler<CardsEventArgs>((EventProvider<CardsEventArgs, BattleController>)((BattleController bt) => bt.CardsAddedToExile), val2, (Predicate<BattleController>)null, priority);
			CHandlerManager.RegisterBattleEventHandler<CardsAddingToDrawZoneEventArgs>((EventProvider<CardsAddingToDrawZoneEventArgs, BattleController>)((BattleController bt) => bt.CardsAddedToDrawZone), val, (Predicate<BattleController>)null, priority);
			CHandlerManager.RegisterBattleEventHandler<CardsEventArgs>((EventProvider<CardsEventArgs, BattleController>)((BattleController bt) => bt.CardsAddedToHand), val2, (Predicate<BattleController>)null, priority);
			CHandlerManager.RegisterBattleEventHandler<CardsEventArgs>((EventProvider<CardsEventArgs, BattleController>)((BattleController bt) => bt.CardsAddedToDiscard), val2, (Predicate<BattleController>)null, priority);
		}
	}
	public class BanData
	{
		public HashSet<Card> bannedCards = new HashSet<Card>();
	}
	public sealed class NoMoreMetaScalingLocSEDef : StatusEffectTemplate
	{
		public override IdContainer GetId()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit("NoMoreMetaScalingLocSE");
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)Statics.seBatchLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override Sprite LoadSprite()
		{
			return null;
		}

		public override StatusEffectConfig MakeConfig()
		{
			return ((StatusEffectTemplate)this).DefaultConfig();
		}
	}
	[EntityLogic(typeof(NoMoreMetaScalingLocSEDef))]
	public sealed class NoMoreMetaScalingLocSE : StatusEffect
	{
		private static NoMoreMetaScalingLocSE _instance;

		public static NoMoreMetaScalingLocSE Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = Library.CreateStatusEffect<NoMoreMetaScalingLocSE>();
				}
				return _instance;
			}
		}

		public static string LocalizeProp(string key, bool decorate = false, bool required = true)
		{
			return ((GameEntity)Instance).LocalizeProperty(key, decorate, required);
		}
	}
	public static class PissHandlers
	{
		[HarmonyPatch(typeof(BattleController), "Die")]
		private class BattleController_Patch
		{
			private static void Prefix(BattleController __instance, Unit unit, ref int power)
			{
				if (!(__instance.EnemyGroup.Id != "Clownpiece") && unit.HasStatusEffect<Servant>())
				{
					if (firstSpawns.Contains(unit))
					{
						firstSpawns.Remove(unit);
					}
					else
					{
						power = 0;
					}
				}
			}
		}

		private static HashSet<Unit> firstSpawns = new HashSet<Unit>();

		private static int spawnCount = 0;

		public static void RegisterHandlers()
		{
			CHandlerManager.RegisterBattleEventHandler<UnitEventArgs>((EventProvider<UnitEventArgs, BattleController>)((BattleController bt) => bt.EnemySpawned), (GameEventHandler<UnitEventArgs>)OnFirst3Spawn, (Predicate<BattleController>)FilterGroupAndReset, (GameEventPriority)10);
		}

		private static void OnFirst3Spawn(UnitEventArgs args)
		{
			if (spawnCount++ < 3)
			{
				firstSpawns.Add(args.Unit);
			}
		}

		private static bool FilterGroupAndReset(BattleController battle)
		{
			if (battle.EnemyGroup.Id == "Clownpiece")
			{
				spawnCount = 0;
				firstSpawns.Clear();
				return true;
			}
			return false;
		}
	}
}
namespace NoMetaScalling
{
	[BepInPlugin("neo.lbol.modifiers.noMetaScaling", "No More Meta scaling", "0.5.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("LBoL.exe")]
	public class BepinexPlugin : BaseUnityPlugin
	{
		private static readonly Harmony harmony = PInfo.harmony;

		internal static ManualLogSource log;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			EntityManager.RegisterSelf();
			harmony.PatchAll();
			if (Chainloader.PluginInfos.ContainsKey("neo.lbol.tools.watermark"))
			{
				WatermarkWrapper.ActivateWatermark();
			}
			CardTracker.RegisterHandlers();
			ActionCancel.RegisterHandlers();
			PissHandlers.RegisterHandlers();
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource log = BepinexPlugin.log;

		internal static void LogMessage(object data)
		{
			log.LogMessage(data);
		}

		internal static void LogInfo(object data)
		{
			log.LogInfo(data);
		}

		internal static void LogDebug(object data)
		{
			log.LogDebug(data);
		}

		internal static void LogWarning(object data)
		{
			log.LogWarning(data);
		}

		internal static void LogError(object data)
		{
			log.LogError(data);
		}

		internal static void LogFatal(object data)
		{
			log.LogFatal(data);
		}
	}
	public static class PInfo
	{
		public const string GUID = "neo.lbol.modifiers.noMetaScaling";

		public const string Name = "No More Meta scaling";

		public const string version = "0.5.0";

		public static readonly Harmony harmony = new Harmony("neo.lbol.modifiers.noMetaScaling");
	}
	internal class WatermarkWrapper
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void ActivateWatermark()
		{
			API.ActivateWatermark();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}