Decompiled source of AALUND13 Extra Picks Cards v1.0.0

plugins/AALUND13_Extra_Picks_Cards.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AALUND13Cards.Core;
using AALUND13Cards.Core.Cards;
using AALUND13Cards.Core.Cards.Effects;
using AALUND13Cards.Core.Extensions;
using AALUND13Cards.Core.Handlers;
using AALUND13Cards.Core.Utils;
using AALUND13Cards.ExtraCards.Cards;
using AALUND13Cards.ExtraCards.Handlers.ExtraPickHandlers;
using BepInEx;
using CorruptedCardsManager;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModdingUtils.GameModes;
using ModdingUtils.Utils;
using ModsPlus;
using Photon.Pun;
using RandomCardsGenerators;
using RandomCardsGenerators.Cards;
using RandomCardsGenerators.StatsGroup;
using TabInfo.Utils;
using UnboundLib;
using UnboundLib.GameModes;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 AALUND13Cards.Core.VisualEffect
{
	public class CorruptedCardVisualEffect : MonoBehaviour
	{
		private const float ROTATE_CARD_CHANCE = 5f;

		private const float ROTATE_CARD_ANGLE_LIMIT = 180f;

		private float oldRotationZ;

		private bool init;

		private void Awake()
		{
			//IL_0007: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			Quaternion rotation = ((Component)this).transform.rotation;
			oldRotationZ = ((Quaternion)(ref rotation)).eulerAngles.z;
			init = true;
		}

		private void Update()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			Quaternion rotation;
			if (!init)
			{
				rotation = ((Component)this).transform.rotation;
				oldRotationZ = ((Quaternion)(ref rotation)).eulerAngles.z;
				init = true;
			}
			if (Random.Range(0f, 100f) < 5f)
			{
				((Component)this).transform.Rotate(0f, 0f, Random.Range(-180f, 180f));
				return;
			}
			rotation = ((Component)this).transform.rotation;
			Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
			eulerAngles.z = oldRotationZ;
			((Component)this).transform.rotation = Quaternion.Euler(eulerAngles);
		}

		private void OnDisable()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (init)
			{
				Quaternion rotation = ((Component)this).transform.rotation;
				Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
				eulerAngles.z = oldRotationZ;
				((Component)this).transform.rotation = Quaternion.Euler(eulerAngles);
			}
		}

		private void OnDestroy()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (init)
			{
				Quaternion rotation = ((Component)this).transform.rotation;
				Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
				eulerAngles.z = oldRotationZ;
				((Component)this).transform.rotation = Quaternion.Euler(eulerAngles);
			}
		}
	}
}
namespace AALUND13Cards.Core.Patches
{
	[HarmonyPatch(typeof(CardChoice))]
	public class CardChoicePatch
	{
		[HarmonyPatch("IDoEndPick")]
		private static void Postfix(GameObject pickedCard, int theInt, int pickId)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			Player playerWithID = ExtensionMethods.GetPlayerWithID(PlayerManager.instance, pickId);
			if ((Object)(object)playerWithID == (Object)null)
			{
				return;
			}
			ExtraCardsStats orCreate = CharacterDataExtensions.GetCustomStatsRegistry(playerWithID.data).GetOrCreate<ExtraCardsStats>();
			if (orCreate.DuplicatesAsCorrupted == 0 || (!((Object)(object)pickedCard.GetComponent<RandomCard>() == (Object)null) && pickedCard.GetComponent<RandomCard>().StatGenName.StartsWith("CCM_CorruptedCardsGenerator")) || (!PhotonNetwork.IsMasterClient && !PhotonNetwork.OfflineMode))
			{
				return;
			}
			Rarity rarity = pickedCard.GetComponent<CardInfo>().rarity;
			if (Enum.IsDefined(typeof(CorruptedCardRarity), ((object)(Rarity)(ref rarity)).ToString()))
			{
				CorruptedCardRarity val = (CorruptedCardRarity)Enum.Parse(typeof(CorruptedCardRarity), ((object)(Rarity)(ref rarity)).ToString());
				for (int i = 0; i < orCreate.DuplicatesAsCorrupted; i++)
				{
					CorruptedCardsManager.CorruptedCardsGenerators.CreateRandomCard(val, playerWithID);
				}
			}
		}
	}
}
namespace AALUND13Cards.ExtraCards
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("AALUND13.Cards.Extra_Cards", "AALUND13 Extra Picks Cards", "1.0.0")]
	[BepInProcess("Rounds.exe")]
	internal class AAC_ExtraCards : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <OnPickStart>d__6 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public IGameModeHandler gameModeHandler;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <OnPickStart>d__6(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				if (<>1__state != 0)
				{
					return false;
				}
				<>1__state = -1;
				foreach (Player player in PlayerManager.instance.players)
				{
					if (PhotonNetwork.IsMasterClient || PhotonNetwork.OfflineMode)
					{
						bool flag = gameModeHandler.GetRoundWinners().Contains(player.teamID);
						if (CharacterDataExtensions.GetAdditionalData(player.data).CustomStatsRegistry.GetOrCreate<ExtraCardsStats>().ExtraCardPicksPerPickPhase > 0 && !flag)
						{
							ExtraCardPickHandler.AddExtraPick<ExtraPickHandler>(player, CharacterDataExtensions.GetAdditionalData(player.data).CustomStatsRegistry.GetOrCreate<ExtraCardsStats>().ExtraCardPicksPerPickPhase, (ExtraPickPhaseTrigger)0);
						}
					}
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		internal const string ModId = "AALUND13.Cards.Extra_Cards";

		internal const string ModName = "AALUND13 Extra Picks Cards";

		internal const string Version = "1.0.0";

		private static AssetBundle assets;

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			assets = AssetsUtils.LoadAssetBundle("aac_extra_cards_assets", typeof(AAC_ExtraCards).Assembly);
			if ((Object)(object)assets != (Object)null)
			{
				new Harmony("AALUND13.Cards.Extra_Cards").PatchAll();
				CardsGenerators.RegisterGenerators();
			}
		}

		private void Start()
		{
			if ((Object)(object)assets == (Object)null)
			{
				Unbound.BuildModal("AALUND13 Cards Error", "The mod \"AALUND13 Extra Picks Cards\" assets failled to load, All the cards will be disable in this mod");
				throw new NullReferenceException("Failled to load \"AALUND13 Extra Picks Cards\" assets");
			}
			GameModeManager.AddHook("PickStart", (Func<IGameModeHandler, IEnumerator>)OnPickStart);
			if (AAC_Core.Plugins.Exists((BaseUnityPlugin plugin) => plugin.Info.Metadata.GUID == "com.willuwontu.rounds.tabinfo"))
			{
				TabinfoInterface.Setup();
			}
			CardResgester cardResgester = assets.LoadAsset<GameObject>("ExtraPicksModCards").GetComponent<CardResgester>();
			cardResgester.RegisterCards();
			AACMenu.OnMenuRegister = (Action)Delegate.Combine(AACMenu.OnMenuRegister, (Action)delegate
			{
				AACMenu.CreateModuleMenuWithReadmeGenerator("AALUND13 Extra Picks Cards", "1.0.0", cardResgester);
			});
		}

		[IteratorStateMachine(typeof(<OnPickStart>d__6))]
		private IEnumerator OnPickStart(IGameModeHandler gameModeHandler)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <OnPickStart>d__6(0)
			{
				gameModeHandler = gameModeHandler
			};
		}
	}
	internal class TabinfoInterface
	{
		public static void Setup()
		{
			StatCategory orCreateCategory = TabinfoInterface.GetOrCreateCategory("AA Stats", 6);
			TabInfoManager.RegisterStat(orCreateCategory, "Extra Card Picks", (Func<Player, bool>)((Player p) => GetExtraCaedStatsFromPlayer(p).ExtraCardPicksPerPickPhase != 0), (Func<Player, string>)((Player p) => $"{GetExtraCaedStatsFromPlayer(p).ExtraCardPicksPerPickPhase}"));
			TabInfoManager.RegisterStat(orCreateCategory, "Duplicates As Corrupted", (Func<Player, bool>)((Player p) => GetExtraCaedStatsFromPlayer(p).DuplicatesAsCorrupted != 0), (Func<Player, string>)((Player p) => $"{GetExtraCaedStatsFromPlayer(p).DuplicatesAsCorrupted}"));
		}

		private static ExtraCardsStats GetExtraCaedStatsFromPlayer(Player player)
		{
			return CharacterDataExtensions.GetCustomStatsRegistry(player.data).GetOrCreate<ExtraCardsStats>();
		}
	}
}
namespace AALUND13Cards.ExtraCards.MonoBehaviours.CardsEffects
{
	public class CardFactoryMono : MonoBehaviour, IPickEndHookHandler
	{
		public int RandomCardsAtStart = 1;

		public float DefectiveCardChance = 0.7f;

		private Player Player;

		private Gun Gun;

		private GunAmmo GunAmmo;

		private CharacterData Data;

		private HealthHandler Health;

		private Gravity Gravity;

		private Block Block;

		private CharacterStatModifiers CharacterStats;

		public void Start()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			Player = ((Component)this).GetComponentInParent<Player>();
			Gun = Player.data.weaponHandler.gun;
			GunAmmo = (GunAmmo)ExtensionMethods.GetFieldValue((object)Gun, "gunAmmo");
			Data = Player.data;
			Health = Player.data.healthHandler;
			Gravity = ((Component)Player).GetComponent<Gravity>();
			Block = Player.data.block;
			CharacterStats = Player.data.stats;
			InterfaceGameModeHooksManager.instance.RegisterHooks((object)this);
		}

		public void OnDestroy()
		{
			InterfaceGameModeHooksManager.instance.RemoveHooks((object)this);
		}

		public void OnPickEnd()
		{
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			for (int i = 0; i < RandomCardsAtStart; i++)
			{
				if (Random.Range(0f, 1f) < DefectiveCardChance)
				{
					CardInfo val = Cards.instance.NORARITY_GetRandomCardWithCondition(Player, Gun, GunAmmo, Data, Health, Gravity, Block, CharacterStats, (Func<CardInfo, Player, Gun, GunAmmo, CharacterData, HealthHandler, Gravity, Block, CharacterStatModifiers, bool>)condition, 1000);
					Cards.instance.AddCardToPlayer(Player, val, false, "", 0f, 0f, true);
				}
				else
				{
					CardsGenerators.Generators.CreateRandomCard(AACardsGeneratorType.CardFactoryGenerator, Player);
				}
			}
		}

		private bool condition(CardInfo card, Player player, Gun gun, GunAmmo gunAmmo, CharacterData data, HealthHandler health, Gravity gravity, Block block, CharacterStatModifiers characterStats)
		{
			return !card.categories.Intersect(AAC_Core.NoLotteryCategories).Any();
		}
	}
}
namespace AALUND13Cards.ExtraCards.Handlers.ExtraPickHandlers
{
	public class SteelPickHandler : ExtraPickHandler
	{
		public override bool PickConditions(Player player, CardInfo card)
		{
			if (card.categories.Intersect(AAC_Core.NoSteelCategories).Any())
			{
				return false;
			}
			List<CardInfo> list = new List<CardInfo>();
			foreach (Player enemyPlayer in PlayerStatus.GetEnemyPlayers(player))
			{
				if ((Object)(object)enemyPlayer != (Object)(object)player)
				{
					list.AddRange(enemyPlayer.data.currentCards);
				}
			}
			return list.Contains(card);
		}

		public override void OnPickEnd(Player player, CardInfo card)
		{
			if (!PhotonNetwork.OfflineMode && !PhotonNetwork.IsMasterClient)
			{
				return;
			}
			List<Player> list = new List<Player>();
			foreach (Player enemyPlayer in PlayerStatus.GetEnemyPlayers(player))
			{
				if (enemyPlayer.data.currentCards.Contains(CardChoice.instance.GetSourceCard(card)))
				{
					list.Add(enemyPlayer);
				}
			}
			if (list.Count != 0)
			{
				Player random = ExtensionMethods.GetRandom<Player>((IList)list);
				Cards.instance.RemoveCardFromPlayer(random, CardChoice.instance.GetSourceCard(card), (SelectionType)2);
			}
		}
	}
}
namespace AALUND13Cards.ExtraCards.Cards
{
	public enum AACardsGeneratorType
	{
		CardFactoryGenerator
	}
	internal class CardsGenerators
	{
		public static ModRandomCardsGenerators<AACardsGeneratorType> Generators;

		public static void RegisterGenerators()
		{
			Generators = new ModRandomCardsGenerators<AACardsGeneratorType>(new Dictionary<AACardsGeneratorType, RandomCardsGenerator> { 
			{
				AACardsGeneratorType.CardFactoryGenerator,
				CreateCardFactoryGenerator()
			} });
		}

		private static RandomCardsGenerator CreateCardFactoryGenerator()
		{
			//IL_0024: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			RandomCardOption val = default(RandomCardOption);
			((RandomCardOption)(ref val))..ctor("Defective Card", "AAC", "This card that come out the factory is defective, it has some negative stats.", "Dc", 1, 4, (Rarity)0, (CardThemeColorType)0);
			return new RandomCardsGenerator("DefectiveCardGenerators", val, new List<RandomStatGenerator>
			{
				(RandomStatGenerator)new DamageStatGenerator(-0.5f, 0f, 0.05f),
				(RandomStatGenerator)new ReloadTimeStatGenerator(0f, 0.5f, 0.05f),
				(RandomStatGenerator)new AttackSpeedStatGenerator(0f, 0.5f, 0.05f),
				(RandomStatGenerator)new MovementSpeedStatGenerator(-0.5f, 0f, 0.05f),
				(RandomStatGenerator)new HealthStatGenerator(-0.5f, 0f, 0.05f),
				(RandomStatGenerator)new BlockCooldownStatGenerator(0f, 0.5f, 0.025f),
				(RandomStatGenerator)new BulletSpeedStatGenerator(-0.5f, 0f, 0.05f)
			});
		}
	}
	public class ExtraCardsStats : ICustomStats
	{
		public int DuplicatesAsCorrupted;

		public int ExtraCardPicksPerPickPhase;

		public void ResetStats()
		{
			DuplicatesAsCorrupted = 0;
			ExtraCardPicksPerPickPhase = 0;
		}
	}
}
namespace AALUND13Cards.ExtraCards.Cards.StatModifers
{
	public enum ExtraPicksType
	{
		None,
		Normal,
		Steel
	}
	public class ExtraCardsStatsModifers : CustomStatModifers
	{
		[Header("Extra Picks")]
		public int ExtraPicks;

		public ExtraPicksType ExtraPicksType;

		public int ExtraPicksForEnemies;

		public ExtraPicksType ExtraPicksTypeForEnemies;

		public ExtraPickPhaseTrigger ExtraPickPhaseTrigger;

		[Header("Extra Cards")]
		public int ExtraCardPicks;

		public int DuplicatesAsCorrupted;

		public override void Apply(Player player)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			CharacterData data = player.data;
			ExtraCardsStats additionalData = CharacterDataExtensions.GetCustomStatsRegistry(data).GetOrCreate<ExtraCardsStats>();
			additionalData.ExtraCardPicksPerPickPhase += ExtraCardPicks;
			ExtraPickHandler extraPickHandler = GetExtraPickHandler(ExtraPicksType);
			if (extraPickHandler != null && ExtraPicks > 0 && player.data.view.IsMine)
			{
				ExtraCardPickHandler.AddExtraPick(extraPickHandler, player, ExtraPicks, ExtraPickPhaseTrigger);
			}
			ExtraPickHandler extraPickHandler2 = GetExtraPickHandler(ExtraPicksTypeForEnemies);
			if (extraPickHandler != null && ExtraPicksForEnemies > 0 && player.data.view.IsMine)
			{
				foreach (Player enemyPlayer in PlayerStatus.GetEnemyPlayers(player))
				{
					ExtraCardPickHandler.AddExtraPick(extraPickHandler2, enemyPlayer, ExtraPicksForEnemies, ExtraPickPhaseTrigger);
				}
			}
			if (DuplicatesAsCorrupted > 0)
			{
				ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)AAC_Core.Instance, 1, (Action)delegate
				{
					additionalData.DuplicatesAsCorrupted += DuplicatesAsCorrupted;
				});
			}
		}

		public override void OnReassign(Player player)
		{
			CharacterDataExtensions.GetAdditionalData(player.data).CustomStatsRegistry.GetOrCreate<ExtraCardsStats>().ExtraCardPicksPerPickPhase += ExtraCardPicks;
		}

		public ExtraPickHandler GetExtraPickHandler(ExtraPicksType type)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			return (ExtraPickHandler)(type switch
			{
				ExtraPicksType.Normal => (object)new ExtraPickHandler(), 
				ExtraPicksType.Steel => new SteelPickHandler(), 
				_ => null, 
			});
		}
	}
}
namespace AALUND13Cards.ExtraCards.Cards.Effects
{
	public class PickCardFromListEffect : OnAddedEffect
	{
		public List<GameObject> randomCardsToChoseFrom = new List<GameObject>();

		public int cardCount = 1;

		public override void OnAdded(Player player, Gun gun, GunAmmo gunAmmo, CharacterData data, HealthHandler health, Gravity gravity, Block block, CharacterStatModifiers characterStats)
		{
			if (!PhotonNetwork.OfflineMode && !PhotonNetwork.IsMasterClient)
			{
				return;
			}
			for (int i = 0; i < cardCount; i++)
			{
				if (randomCardsToChoseFrom.Count == 0)
				{
					LoggerUtils.LogWarn("No cards to choose from. Please add cards to the list.");
					break;
				}
				CardInfo component = ExtensionMethods.GetRandom<GameObject>((IList)randomCardsToChoseFrom).GetComponent<CardInfo>();
				Cards.instance.AddCardToPlayer(player, component, true, "", 2f, 2f, true);
				CardBarUtils.instance.ShowAtEndOfPhase(player, component);
			}
		}
	}
}