Decompiled source of MyLittleRebalance v0.3.0

plugins/MyLittleRebalance.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using ShinyShoe.Audio;
using TrainworksReloaded.Base.Localization;
using TrainworksReloaded.Core;
using TrainworksReloaded.Core.Extensions;
using UnityEngine;

[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("MyLittleRebalance")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+ca6586e40ae03b0ecbe39d981e3a2691331689c3")]
[assembly: AssemblyProduct("MyLittleRebalance")]
[assembly: AssemblyTitle("MyLittleRebalance")]
[assembly: AssemblyVersion("0.3.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 MyLittleRebalance
{
	[HarmonyPatch(typeof(CardManager), "OnCardPlayedVfx")]
	internal static class TrainWhistleFirstPatch
	{
		internal static string? blownCue;

		internal static CoreSoundEffectData? blown;

		private static void Prefix(CardState playCard, SoundManager ___soundManager)
		{
			CoreSoundEffectData coreSoundEffectData = playCard.GetCoreSoundEffectData();
			if (!(playCard.GetAssetName() != "RailforgedChampionConductorStewardAbility") && !((Object)(object)coreSoundEffectData == (Object)null))
			{
				string text = (coreSoundEffectData.HasCue("Play") ? "Play" : (coreSoundEffectData.HasCue("UnitAbility") ? "UnitAbility" : null));
				if (text != null)
				{
					blown = null;
					___soundManager.PlaySfx(text, coreSoundEffectData, 0f);
					blownCue = text;
					blown = coreSoundEffectData;
				}
			}
		}
	}
	[HarmonyPatch(typeof(SoundManager), "PlaySfx", new Type[]
	{
		typeof(string),
		typeof(CoreSoundEffectData),
		typeof(float)
	})]
	internal static class TrainWhistleOncePatch
	{
		private static bool Prefix(string cueName, CoreSoundEffectData soundData)
		{
			if ((Object)(object)soundData == (Object)null || (Object)(object)soundData != (Object)(object)TrainWhistleFirstPatch.blown || cueName != TrainWhistleFirstPatch.blownCue)
			{
				return true;
			}
			TrainWhistleFirstPatch.blown = null;
			return false;
		}
	}
	[HarmonyPatch(typeof(CardEffectAttackWithUnit), "ApplyEffect")]
	internal static class TrainWhistleDelayPatch
	{
		private static void Postfix(ref IEnumerator __result, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers)
		{
			CardState playedCard = cardEffectParams.playedCard;
			if (!(((playedCard != null) ? playedCard.GetAssetName() : null) != "RailforgedChampionConductorStewardAbility") && !coreGameManagers.GetSaveManager().PreviewMode)
			{
				__result = Run(__result);
			}
		}

		private static IEnumerator Run(IEnumerator original)
		{
			yield return CoreUtil.WaitForSecondsOrBreak(Plugin.TrainWhistleDelay.Value, "/home/amaury/Documents/MT2Mods/mods/MT2-MyLittleRebalance/MyLittleRebalance/patches/Conductor Steward.cs", 54);
			yield return original;
		}
	}
	[HarmonyPatch(typeof(RoomStateModifierBase), "OnRoomModifierAttachedToOwner")]
	internal static class RememberStatusBonusOwnerPatch
	{
		internal static readonly ConditionalWeakTable<RoomStateAddStatusEffectOnStatusApplied, CharacterState> Owners = new ConditionalWeakTable<RoomStateAddStatusEffectOnStatusApplied, CharacterState>();

		private static void Postfix(RoomStateModifierBase __instance, CharacterState ownerCharacterState)
		{
			RoomStateAddStatusEffectOnStatusApplied val = (RoomStateAddStatusEffectOnStatusApplied)(object)((__instance is RoomStateAddStatusEffectOnStatusApplied) ? __instance : null);
			if (val != null)
			{
				Owners.Remove(val);
				Owners.Add(val, ownerCharacterState);
			}
		}
	}
	[HarmonyPatch(typeof(RoomStateAddStatusEffectOnStatusApplied), "ApplyCharacterTriggerModification")]
	internal static class StatusBonusDualismPatch
	{
		private static bool Prefix(RoomStateAddStatusEffectOnStatusApplied __instance, ref IEnumerator __result, int ___thisInstTrackingId, AddStatusEffectParams ___addStatusEffectParams, Trigger trigger, CharacterState affectedCharacter, FireTriggersData? fireTriggersData)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!RememberStatusBonusOwnerPatch.Owners.TryGetValue(__instance, out CharacterState value))
			{
				return true;
			}
			__result = Apply(value, ___thisInstTrackingId, ___addStatusEffectParams, trigger, affectedCharacter, fireTriggersData);
			return false;
		}

		private static IEnumerator Apply(CharacterState owner, int trackingId, AddStatusEffectParams addStatusEffectParams, Trigger trigger, CharacterState affectedCharacter, FireTriggersData? fireTriggersData)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if ((int)trigger == 57 && fireTriggersData != null && fireTriggersData.paramInt2 == trackingId)
			{
				addStatusEffectParams.fromRoomModifier = true;
				affectedCharacter.AddStatusEffect(fireTriggersData.paramString, fireTriggersData.paramInt, addStatusEffectParams, owner, true, false, true, false, false);
			}
			yield break;
		}
	}
	[HarmonyPatch(typeof(StatusEffectManager), "Start")]
	internal static class UnhideFixedAttackPatch
	{
		private static void Postfix(StatusEffectManager __instance, StatusEffectsDisplayData ___displayData)
		{
			StatusEffectData statusEffectDataById = __instance.GetStatusEffectDataById("fixedattack", true);
			AccessTools.Field(typeof(StatusEffectData), "hidden").SetValue(statusEffectDataById, false);
			AccessTools.Field(typeof(StatusEffectData), "showStackCount").SetValue(statusEffectDataById, true);
			AccessTools.Field(typeof(StatusEffectData), "icon").SetValue(statusEffectDataById, AccessTools.Field(typeof(StatusEffectsDisplayData), "defaultRoomModifierIcon").GetValue(___displayData));
		}
	}
	[HarmonyPatch(typeof(CardData), "GetOverrideDescriptionKey")]
	internal static class IrontongueDescriptionPatch
	{
		private static void Postfix(CardData __instance, ref string __result)
		{
			if (((Object)__instance).name == "Irontongue")
			{
				__result = string.Empty;
			}
		}
	}
	public sealed class RelicEffectGainGoldPercentEndOfBattle : RelicEffectBase, ITurnPhaseEndOfBattleRelicEffect, IRelicEffect
	{
		private int percent;

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0024: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			PropDescriptions val = new PropDescriptions { };
			string fieldName;
			((Dictionary<string, PropDescription>)val)[fieldName] = new PropDescription("Gold Percent", "", (Type)null, false);
			return val;
		}

		public override void Initialize(RelicState relicState, RelicData srcRelicData, RelicEffectData relicEffectData)
		{
			((RelicEffectBase)this).Initialize(relicState, srcRelicData, relicEffectData);
			percent = relicEffectData.GetParamInt();
		}

		public void ApplyEffectEndOfBattle(ScenarioData? completedScenario, RelicEffectParams relicEffectParams, ICoreGameManagers coreGameManagers)
		{
			SaveManager saveManager = coreGameManagers.GetSaveManager();
			int num = saveManager.GetGold() * percent / 100;
			if (num > 0)
			{
				saveManager.AdjustGold(num, true, false);
			}
		}
	}
	[HarmonyPatch(typeof(HeroManager), "RemoveCharacter")]
	internal static class ReturnEquipmentOnEnemyDeathPatch
	{
		private static readonly MethodInfo CheckStandByConditions = AccessTools.Method(typeof(CardManager), "CheckStandByConditions", (Type[])null, (Type[])null);

		private static void Postfix(ref IEnumerator __result, CharacterState removeCharacter, CardManager ___cardManager, SaveManager ___saveManager)
		{
			if (!___saveManager.PreviewMode)
			{
				__result = Run(__result, removeCharacter, ___cardManager);
			}
		}

		private static IEnumerator Run(IEnumerator original, CharacterState character, CardManager cardManager)
		{
			yield return original;
			List<CardState> list = (from card in character.GetEquipment()
				where card.HasTrait<CardTraitReturnToHandEquipment>()
				select card).ToList();
			if (list.Count == 0)
			{
				yield break;
			}
			character.SetAllowDestroyedAccess(true);
			foreach (CardState item in list)
			{
				yield return (IEnumerator)CheckStandByConditions.Invoke(cardManager, new object[2] { null, item });
			}
			character.SetAllowDestroyedAccess(false);
		}
	}
	public sealed class RoomStateSelfMaxHpPerStatusEffectStack : RoomStateModifierBase, IRoomStateOnCharacterTriggerModifier, IRoomStateModifier, ILocalizationParamInt, ILocalizationParameterContext
	{
		private const string UpgradeId = "RoomStateSelfMaxHpPerStatusEffectStackUpgrade";

		private string statusId = string.Empty;

		private CharacterState? owner;

		public override void Initialize(RoomModifierData roomModifierData, SaveManager saveManager)
		{
			((RoomStateModifierBase)this).Initialize(roomModifierData, saveManager);
			StatusEffectStackData[] paramStatusEffects = roomModifierData.GetParamStatusEffects();
			if (paramStatusEffects.Length != 0)
			{
				statusId = paramStatusEffects[0].statusId;
			}
		}

		public override void OnRoomModifierAttachedToOwner(CharacterState ownerCharacterState)
		{
			owner = ownerCharacterState;
		}

		public IEnumerator ApplyCharacterTriggerModification(Trigger trigger, CharacterState affectedCharacter, FireTriggersData? fireTriggersData, ICoreGameManagers coreGameManagers)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)owner == (Object)null) && !((Object)(object)affectedCharacter != (Object)(object)owner) && (int)trigger == 65 && !(fireTriggersData?.paramString != statusId) && !owner.IsDestroyed && !owner.IsDeadAndUnrevivable)
			{
				CardUpgradeState upgrade = ((IEnumerable<CardUpgradeState>)owner.GetAppliedCardUpgrades()).FirstOrDefault((Func<CardUpgradeState, bool>)((CardUpgradeState u) => u.GetCardUpgradeDataId() == "RoomStateSelfMaxHpPerStatusEffectStackUpgrade"));
				if (upgrade == null)
				{
					upgrade = new CardUpgradeState();
					upgrade.Setup();
					upgrade.SetCardUpgradeDataId("RoomStateSelfMaxHpPerStatusEffectStackUpgrade");
					upgrade.SetIsUnique(true);
					yield return owner.ApplyCardUpgrade(upgrade, false, "", true, false, (CardState)null, (Action<UpgradeApplicationResult>)null, (TrainRoomAttachmentState)null, false);
				}
				int target = owner.GetStatusEffectStacks(statusId) * ((RoomStateModifierBase)this).GetParamInt();
				int num = target - upgrade.GetAdditionalHP();
				if (num > 0)
				{
					yield return owner.BuffMaxHP(num, false, (RelicState)null, true);
				}
				else if (num < 0)
				{
					yield return owner.DebuffMaxHP(-num, 1, false);
				}
				upgrade.SetAdditionalHP(target);
			}
		}
	}
	public sealed class CardEffectPlayUnitTriggerPerApplication : CardEffectBase
	{
		private static readonly CardEffectPlayUnitTrigger Inner = new CardEffectPlayUnitTrigger();

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			return ((CardEffectBase)Inner).CreateEditorInspectorDescriptions();
		}

		public override IEnumerator ApplyEffect(CardEffectState cardEffectState, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers, ISystemManagers sysManagers)
		{
			return ((CardEffectBase)Inner).ApplyEffect(cardEffectState, cardEffectParams, coreGameManagers, sysManagers);
		}

		public override int GetEffectApplicationCount(CardEffectState cardEffectState, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers, ISystemManagers sysManagers)
		{
			return GameEffectHelper.GetDamageEffectApplicationCount(cardEffectState, coreGameManagers);
		}
	}
	[HarmonyPatch(typeof(CustomLocalizationTermRegistry), "LoadData")]
	internal static class PierceCardTooltipPatch
	{
		private static void Prefix(CustomLocalizationTermRegistry __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			__instance.Register("StatusEffect_conductor_pierce_CardTooltipText", new LocalizationTerm
			{
				Key = "StatusEffect_conductor_pierce_CardTooltipText",
				English = "Attacks also hit one unit behind the attacked unit per stack."
			});
		}
	}
	public sealed class RelicEffectDiscardAfterConsume : RelicEffectBase, IOnPostDiscardRelicEffect, IRelicEffect
	{
		private static readonly FieldRef<CardManager, List<CardState>> DiscardPile = AccessTools.FieldRefAccess<CardManager, List<CardState>>("pileDiscard");

		private int percentageChance;

		private CardType cardType;

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0044: Expected O, but got Unknown
			//IL_0045: Expected O, but got Unknown
			PropDescriptions val = new PropDescriptions { };
			string fieldName;
			((Dictionary<string, PropDescription>)val)[fieldName] = new PropDescription("% Chance", "", (Type)null, false);
			string fieldName2 = RelicEffectFieldNamesHelper.GetFieldName((RelicEffectFieldNames)13);
			((Dictionary<string, PropDescription>)val)[fieldName2] = new PropDescription("Card Type", "", (Type)null, false);
			return val;
		}

		public override void Initialize(RelicState relicState, RelicData relicData, RelicEffectData relicEffectData)
		{
			//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)
			((RelicEffectBase)this).Initialize(relicState, relicData, relicEffectData);
			percentageChance = Math.Clamp(relicEffectData.GetParamInt(), 0, 100);
			cardType = relicEffectData.GetParamCardType();
		}

		public bool TestOnCardDiscarded(CardPostDiscardRelicEffectParams relicEffectParams, ICoreGameManagers coreGameManagers)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			CardState cardState = relicEffectParams.cardState;
			if (cardState.GetCardType() != cardType || !coreGameManagers.GetCardManager().IsCardInExhaustPile(cardState))
			{
				return false;
			}
			CardTraitExhaustState val = default(CardTraitExhaustState);
			if (!cardState.TryGetTraitState<CardTraitExhaustState>(ref val) || !val.IsExhausted())
			{
				return false;
			}
			if (cardState.HasTrait<CardTraitInfusion>() || cardState.HasTrait<CardTraitPersistent>())
			{
				return false;
			}
			return RandomManager.Range(0, 100, (RngId)6) < percentageChance;
		}

		public void OnCardDiscarded(CardPostDiscardRelicEffectParams relicEffectParams, ICoreGameManagers coreGameManagers)
		{
			((RelicEffectBase)this).NotifyRoomRelicTriggered(coreGameManagers);
			CardManager cardManager = coreGameManagers.GetCardManager();
			cardManager.RestoreExhaustedOrEatenCard(relicEffectParams.cardState, false);
			DiscardPile.Invoke(cardManager).Add(relicEffectParams.cardState);
		}
	}
	[BepInPlugin("SpecialCircumstances.MyLittleRebalance", "MyLittleRebalance", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger = new ManualLogSource("SpecialCircumstances.MyLittleRebalance");

		internal static ConfigEntry<float> TrainWhistleDelay = null;

		public void Awake()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			TrainWhistleDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Conductor Steward", "TrainWhistleDelay", 0.5f, "Seconds between Train Whistle's whistle and the first attack.");
			string dir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			List<string> files = (from f in Directory.GetFiles(Path.Combine(dir, "json"), "*.json", SearchOption.AllDirectories)
				select Path.GetRelativePath(dir, f)).OrderBy<string, string>((string f) => f, StringComparer.Ordinal).ToList();
			Railhead.GetBuilder().Configure("SpecialCircumstances.MyLittleRebalance", (Action<IConfigurationBuilder>)delegate(IConfigurationBuilder c)
			{
				ConfigurationExtensions.AddMergedJsonFile(c, files);
			});
			new Harmony("SpecialCircumstances.MyLittleRebalance").PatchAll();
			Logger.LogInfo((object)"Plugin SpecialCircumstances.MyLittleRebalance is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SpecialCircumstances.MyLittleRebalance";

		public const string PLUGIN_NAME = "MyLittleRebalance";

		public const string PLUGIN_VERSION = "0.3.0";
	}
}