Decompiled source of The Banker Custom Character v1.2.3

plugins/Bankeritems/BankerItems.dll

Decompiled 2 months 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.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BankerItems.ItemAPI;
using BankerItems.SoundAPI;
using BepInEx;
using Gungeon;
using HarmonyLib;
using MonoMod.RuntimeDetour;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BankerItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BankerItems")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("755d112a-ed8f-4c10-8f8d-a7df96ecd86a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BankerItems
{
	public class BankerGun : GunBehaviour
	{
		public float damageMultPerCasing;

		private PlayerController owner;

		private float damageMult = 1f;

		public static void Init()
		{
			//IL_00a4: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Expected O, but got Unknown
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Expected O, but got Unknown
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Expected O, but got Unknown
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Expected O, but got Unknown
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Expected O, but got Unknown
			Gun val = Databases.Items.NewGun("Interest Gun", "interest_gun");
			Game.Items.Rename("outdated_gun_mods:interest_gun", "spapi:interest_gun");
			((Component)val).gameObject.AddComponent<BankerGun>().damageMultPerCasing = 0.1f;
			GunExt.SetShortDescription((PickupObject)(object)val, "High-Interest Loan");
			GunExt.SetLongDescription((PickupObject)(object)val, "A gun designed to incentivise loan-sharks, they originally only featured a bright display to indicate how good their wielders were at their job. This gun, however, has itself run afoul of the banks after it developed a gambling addiction, and will desperately reward the collection of casings to pay off its room-based debt.\n\nCollect casings before clearing a room to increase the gun's stats. Stats reset when entering a new room.");
			GunExt.SetupSprite(val, (tk2dSpriteCollectionData)null, "interest_gun_idle_001", 8);
			GunExt.SetAnimationFPS(val, val.shootAnimation, 14);
			GunExt.SetAnimationFPS(val, val.reloadAnimation, 8);
			GunExt.AddProjectileModuleFrom(val, "ak-47", true, false);
			val.DefaultModule.ammoCost = 1;
			val.DefaultModule.shootStyle = (ShootStyle)1;
			val.DefaultModule.sequenceStyle = (ProjectileSequenceStyle)0;
			val.reloadTime = 1.5f;
			val.DefaultModule.cooldownTime = 0.2f;
			val.DefaultModule.numberOfShotsInClip = 8;
			val.SetBaseMaxAmmo(250);
			((PickupObject)val).PreventStartingOwnerFromDropping = true;
			val.StarterGunForAchievement = true;
			val.InfiniteAmmo = true;
			val.gunSwitchGroup = "Interest";
			tk2dSpriteAnimationFrame[] frames = ((BraveBehaviour)val).spriteAnimator.GetClipByName(val.reloadAnimation).frames;
			MakeOffset(frames[1].spriteCollection.spriteDefinitions[frames[1].spriteId], new Vector3(0f, 0.125f));
			MakeOffset(frames[2].spriteCollection.spriteDefinitions[frames[2].spriteId], new Vector3(0f, -0.1875f));
			SoundManager.AddCustomSwitchData("WPN_Guns", "Interest", "Play_WPN_Gun_Shot_01", new SwitchedEvent("Play_WPN_Gun_Shot_01", "WPN_Guns", "Cash"));
			SoundManager.AddCustomSwitchData("WPN_Guns", "Interest", "Play_WPN_Gun_Reload_01", new SwitchedEvent("Play_WPN_Gun_Reload_01", "WPN_Guns", "Origami"));
			val.barrelOffset.position = new Vector3(1.1875f, 0.6875f);
			((PickupObject)val).quality = (ItemQuality)(-50);
			val.muzzleFlashEffects = ((Component)PickupObjectDatabase.GetById(95)).GetComponent<Gun>().muzzleFlashEffects;
			Projectile val2 = Object.Instantiate<Projectile>(val.DefaultModule.projectiles[0]);
			((Component)val2).gameObject.SetActive(false);
			FakePrefab.MarkAsFakePrefab(((Component)val2).gameObject);
			Object.DontDestroyOnLoad((Object)(object)val2);
			val2.shouldRotate = true;
			val.DefaultModule.projectiles[0] = val2;
			val2.baseData.damage = 6f;
			val2.baseData.speed = 23f;
			val.DefaultModule.ammoType = (AmmoType)14;
			val.DefaultModule.customAmmoType = CustomAmmoUtility.AddCustomAmmoType("interest", "InterestFG", "InterestBG", "BankerItems/Resources/interest_clip.png", "BankerItems/Resources/interest_clip_empty.png");
			tk2dSpriteAnimator val3 = ((Component)ETGMod.GetAnySprite((BraveBehaviour)(object)val2)).gameObject.AddComponent<tk2dSpriteAnimator>();
			val3.Library = ((Component)ETGMod.GetAnySprite((BraveBehaviour)(object)val2)).gameObject.AddComponent<tk2dSpriteAnimation>();
			tk2dSpriteAnimation library = val3.Library;
			tk2dSpriteAnimationClip[] array = new tk2dSpriteAnimationClip[1];
			tk2dSpriteAnimationClip val4 = new tk2dSpriteAnimationClip();
			val4.name = "coin_projectile";
			val4.fps = 10f;
			val4.frames = (tk2dSpriteAnimationFrame[])(object)new tk2dSpriteAnimationFrame[4]
			{
				new tk2dSpriteAnimationFrame
				{
					spriteCollection = ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection,
					spriteId = ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection.GetSpriteIdByName("coin_projectile_001")
				},
				new tk2dSpriteAnimationFrame
				{
					spriteCollection = ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection,
					spriteId = ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection.GetSpriteIdByName("coin_projectile_002")
				},
				new tk2dSpriteAnimationFrame
				{
					spriteCollection = ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection,
					spriteId = ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection.GetSpriteIdByName("coin_projectile_003")
				},
				new tk2dSpriteAnimationFrame
				{
					spriteCollection = ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection,
					spriteId = ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection.GetSpriteIdByName("coin_projectile_004")
				}
			};
			array[0] = val4;
			library.clips = (tk2dSpriteAnimationClip[])(object)array;
			val3.playAutomatically = true;
			val3.defaultClipId = 0;
			ETGMod.GetAnySprite((BraveBehaviour)(object)val2).SetSprite(ETGMod.GetAnySprite((BraveBehaviour)(object)val2).Collection.GetSpriteIdByName("coin_projectile_001"));
			Databases.Items.Add(val, (tk2dSpriteCollectionData)null, "ANY");
		}

		public static void MakeOffset(tk2dSpriteDefinition def, Vector3 offset, bool changesCollider = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			float x = offset.x;
			float y = offset.y;
			def.position0 += new Vector3(x, y, 0f);
			def.position1 += new Vector3(x, y, 0f);
			def.position2 += new Vector3(x, y, 0f);
			def.position3 += new Vector3(x, y, 0f);
			def.boundsDataCenter += new Vector3(x, y, 0f);
			def.boundsDataExtents += new Vector3(x, y, 0f);
			def.untrimmedBoundsDataCenter += new Vector3(x, y, 0f);
			def.untrimmedBoundsDataExtents += new Vector3(x, y, 0f);
			if (def.colliderVertices != null && def.colliderVertices.Length != 0 && changesCollider)
			{
				ref Vector3 reference = ref def.colliderVertices[0];
				reference += new Vector3(x, y, 0f);
			}
		}

		public override void OnInitializedWithOwner(GameActor actor)
		{
			((GunBehaviour)this).OnInitializedWithOwner(actor);
			PlayerController val = (PlayerController)(object)((actor is PlayerController) ? actor : null);
			if (val != null)
			{
				owner = val;
				PlayerController obj = owner;
				obj.OnEnteredCombat = (Action)Delegate.Combine(obj.OnEnteredCombat, new Action(ResetDamageMult));
			}
		}

		public override void PostProcessProjectile(Projectile projectile)
		{
			((GunBehaviour)this).PostProcessProjectile(projectile);
			ProjectileData baseData = projectile.baseData;
			baseData.damage *= damageMult;
		}

		public void ResetDamageMult()
		{
			damageMult = 1f;
		}

		public override void OnDropped()
		{
			damageMult = 1f;
			((GunBehaviour)this).OnDropped();
			if ((Object)(object)owner != (Object)null)
			{
				PlayerController obj = owner;
				obj.OnEnteredCombat = (Action)Delegate.Remove(obj.OnEnteredCombat, new Action(ResetDamageMult));
				owner = null;
			}
		}

		[HarmonyPatch(typeof(CurrencyPickup), "Pickup")]
		[HarmonyPostfix]
		public static void DamageUp(CurrencyPickup __instance, PlayerController player)
		{
			if (__instance.IsMetaCurrency || !((Object)(object)player != (Object)null) || (!((Object)(object)((Component)__instance).GetComponent<PickupMover>() == (Object)null) && ((Component)__instance).GetComponent<PickupMover>().m_shouldPath))
			{
				return;
			}
			if (player.inventory != null && player.inventory.AllGuns != null)
			{
				foreach (Gun allGun in player.inventory.AllGuns)
				{
					if ((Object)(object)allGun != (Object)null && (Object)(object)((Component)allGun).GetComponent<BankerGun>() != (Object)null)
					{
						((Component)allGun).GetComponent<BankerGun>().damageMult += ((Component)allGun).GetComponent<BankerGun>().damageMultPerCasing * (float)__instance.currencyValue;
					}
				}
			}
			if (player.passiveItems == null)
			{
				return;
			}
			foreach (PassiveItem passiveItem in player.passiveItems)
			{
				if ((Object)(object)passiveItem != (Object)null && passiveItem is InterestRounds interestRounds)
				{
					interestRounds.damageMult += interestRounds.damageMultPerCasing * (float)__instance.currencyValue;
				}
			}
		}
	}
	[HarmonyPatch]
	public class BankerItem : PassiveItem
	{
		public const int MONEY_PER_HALF_HEART = 40;

		public const float MONEY_DROPPED_ON_HIT = 0.3f;

		public const int MONEY_GIVEN_ON_START = 120;

		public StatModifier mod;

		private bool ignoreNextShot;

		private int lastCoins = -1;

		public bool gaveMoney;

		public static void Init()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			string text = "Golden Heart";
			string resourcePath = "BankerItems/Resources/heart_of_gold_002";
			GameObject val = new GameObject(text);
			BankerItem bankerItem = val.AddComponent<BankerItem>();
			ItemBuilder.AddSpriteToObject(text, resourcePath, val);
			string shortDesc = "A bit too literal";
			string longDesc = "A heart made of pure gold, animated by some unseen force. Few know of its actual origin, yet many are the myths and legends written after it. Some believe it to be the result of a supernatural curse, replacing the live hearts of those who accumulate too much wealth; some say it is the result of a cruel operation by the Hegemony of Man's banking conglomerates, replacing the hearts of their most generous bankers so that they become physically unable to do unprofitable deeds of kindness during their work.\n\nOne thing, however, is certain: to all those whose chests beat with these hearts, money truly becomes their life.";
			((PickupObject)(object)bankerItem).SetupItem(shortDesc, longDesc, "spapi");
			((PickupObject)bankerItem).quality = (ItemQuality)(-50);
			((PickupObject)bankerItem).CanBeDropped = false;
		}

		public override void Pickup(PlayerController player)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (mod == null)
			{
				mod = StatModifier.Create((StatType)3, (ModifyMethod)0, 0f);
			}
			mod.statToBoost = (StatType)3;
			player.ownerlessStatModifiers.Add(mod);
			((PassiveItem)this).Pickup(player);
			player.OnReceivedDamage += LoseMoney;
			player.LostArmor = (Action)Delegate.Combine(player.LostArmor, new Action(DoIgnoreNextShot));
			HealthHaver healthHaver = ((BraveBehaviour)player).healthHaver;
			healthHaver.ModifyHealing = (Action<HealthHaver, ModifyHealingEventArgs>)Delegate.Combine(healthHaver.ModifyHealing, new Action<HealthHaver, ModifyHealingEventArgs>(CoinsForHealth));
			player.AllowZeroHealthState = true;
			PassiveItem.IncrementFlag(player, typeof(BankerItem));
		}

		public void CoinsForHealth(HealthHaver hh, ModifyHealingEventArgs args)
		{
			if (args != EventArgs.Empty)
			{
				PlayerConsumables carriedConsumables = ((PassiveItem)this).Owner.carriedConsumables;
				carriedConsumables.Currency += Mathf.FloorToInt(args.InitialHealing * 40f * 2f);
			}
		}

		public void DoIgnoreNextShot()
		{
			ignoreNextShot = true;
		}

		public void LoseMoney(PlayerController player)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (ignoreNextShot)
			{
				ignoreNextShot = false;
				return;
			}
			int currency = player.carriedConsumables.Currency;
			player.carriedConsumables.Currency = Mathf.Max(0, currency - 40);
			int num = currency - player.carriedConsumables.Currency;
			if ((float)num * 0.3f >= 1f)
			{
				int num2 = Mathf.FloorToInt((float)num * 0.3f);
				LootEngine.SpawnCurrencyManual(((GameActor)player).CenterPosition, num2);
			}
			if (((PassiveItem)this).Owner.carriedConsumables.Currency > 0)
			{
				mod.amount = Mathf.Max(Mathf.Floor((float)(((PassiveItem)this).Owner.carriedConsumables.Currency / 40)) / 2f, (((PassiveItem)this).Owner.carriedConsumables.m_currency > 40) ? 1f : 0.5f) - (((PassiveItem)this).Owner.stats.GetStatValue((StatType)3) - mod.amount);
				((PassiveItem)this).Owner.stats.RecalculateStats(((PassiveItem)this).Owner, false, false);
				((BraveBehaviour)((PassiveItem)this).Owner).healthHaver.currentHealth = ((BraveBehaviour)((PassiveItem)this).Owner).healthHaver.maximumHealth;
			}
			lastCoins = ((PassiveItem)this).Owner.carriedConsumables.Currency;
		}

		public override void Update()
		{
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			((PassiveItem)this).Update();
			ignoreNextShot = false;
			if (!((PassiveItem)this).PickedUp || !((Object)(object)((PassiveItem)this).Owner != (Object)null) || ((PassiveItem)this).Owner.carriedConsumables == null)
			{
				return;
			}
			if (!gaveMoney)
			{
				PlayerConsumables carriedConsumables = ((PassiveItem)this).Owner.carriedConsumables;
				carriedConsumables.Currency += 120;
				gaveMoney = true;
			}
			if (lastCoins != ((PassiveItem)this).Owner.carriedConsumables.Currency)
			{
				mod.amount = Mathf.Max(Mathf.Floor((float)(((PassiveItem)this).Owner.carriedConsumables.Currency / 40)) / 2f, (((PassiveItem)this).Owner.carriedConsumables.m_currency > 40) ? 1f : 0.5f) - (((PassiveItem)this).Owner.stats.GetStatValue((StatType)3) - mod.amount);
				((PassiveItem)this).Owner.stats.RecalculateStats(((PassiveItem)this).Owner, false, false);
				if (((PassiveItem)this).Owner.carriedConsumables.Currency <= 0)
				{
					((BraveBehaviour)((PassiveItem)this).Owner).healthHaver.Armor = 0f;
					((BraveBehaviour)((PassiveItem)this).Owner).healthHaver.minimumHealth = 0f;
					((BraveBehaviour)((PassiveItem)this).Owner).healthHaver.IsVulnerable = true;
					((BraveBehaviour)((PassiveItem)this).Owner).healthHaver.ApplyDamage(0.5f, Vector2.zero, "Bankruptcy", (CoreDamageTypes)0, (DamageCategory)0, true, (PixelCollider)null, true);
				}
			}
			if (((PassiveItem)this).Owner.carriedConsumables.Currency > 0)
			{
				((BraveBehaviour)((PassiveItem)this).Owner).healthHaver.currentHealth = ((BraveBehaviour)((PassiveItem)this).Owner).healthHaver.maximumHealth;
			}
			lastCoins = ((PassiveItem)this).Owner.carriedConsumables.Currency;
		}

		public override void DisableEffect(PlayerController player)
		{
			PassiveItem.DecrementFlag(player, typeof(BankerItem));
			player.ownerlessStatModifiers.Remove(mod);
			player.OnReceivedDamage -= LoseMoney;
			player.LostArmor = (Action)Delegate.Remove(player.LostArmor, new Action(DoIgnoreNextShot));
			HealthHaver healthHaver = ((BraveBehaviour)player).healthHaver;
			healthHaver.ModifyHealing = (Action<HealthHaver, ModifyHealingEventArgs>)Delegate.Remove(healthHaver.ModifyHealing, new Action<HealthHaver, ModifyHealingEventArgs>(CoinsForHealth));
			player.AllowZeroHealthState = false;
			((PassiveItem)this).DisableEffect(player);
		}

		[HarmonyPatch(typeof(HealthHaver), "FullHeal")]
		[HarmonyPostfix]
		public static void CoinsForFullHeal(HealthHaver __instance)
		{
			if (__instance.isPlayerCharacter && PassiveItem.IsFlagSetForCharacter(__instance.m_player, typeof(BankerItem)))
			{
				PlayerConsumables carriedConsumables = __instance.m_player.carriedConsumables;
				carriedConsumables.Currency += 160;
			}
		}

		[HarmonyPatch(typeof(HealthHaver), "SetHealthMaximum")]
		[HarmonyPostfix]
		public static void CoinsForMaxHealth(HealthHaver __instance, float? amountOfHealthToGain)
		{
			if (amountOfHealthToGain.HasValue && __instance.isPlayerCharacter && PassiveItem.IsFlagSetForCharacter(__instance.m_player, typeof(BankerItem)))
			{
				PlayerConsumables carriedConsumables = __instance.m_player.carriedConsumables;
				carriedConsumables.Currency += Mathf.FloorToInt(amountOfHealthToGain.GetValueOrDefault() * 40f * 2f);
			}
		}

		[HarmonyPatch(typeof(PlayerStats), "RecalculateStatsInternal")]
		[HarmonyPrefix]
		public static void RecalculateBankerHealth(PlayerController owner)
		{
			if (!PassiveItem.IsFlagSetForCharacter(owner, typeof(BankerItem)))
			{
				return;
			}
			foreach (PassiveItem passiveItem in owner.passiveItems)
			{
				if (passiveItem is BankerItem bankerItem)
				{
					bankerItem.mod.amount = Mathf.Max(Mathf.Floor((float)(owner.carriedConsumables.Currency / 40)) / 2f, (owner.carriedConsumables.m_currency > 40) ? 1f : 0.5f) - (owner.stats.GetStatValue((StatType)3) - bankerItem.mod.amount);
				}
			}
		}
	}
	[HarmonyPatch]
	public static class CustomAmmoUtility
	{
		public static List<GameUIAmmoType> addedAmmoTypes = new List<GameUIAmmoType>();

		public static string AddCustomAmmoType(string name, string fgSpriteObject, string bgSpriteObject, string fgTexture, string bgTexture)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			GameObject val = new GameObject(fgSpriteObject);
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			FakePrefab.MarkAsFakePrefab(val);
			GameObject val2 = new GameObject(bgSpriteObject);
			val2.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val2);
			FakePrefab.MarkAsFakePrefab(val2);
			dfTiledSprite val3 = val.SetupDfSpriteFromTexture<dfTiledSprite>(ResourceExtractor.GetTextureFromResource(fgTexture), ShaderCache.Acquire("Daikon Forge/Default UI Shader"));
			dfTiledSprite val4 = val2.SetupDfSpriteFromTexture<dfTiledSprite>(ResourceExtractor.GetTextureFromResource(bgTexture), ShaderCache.Acquire("Daikon Forge/Default UI Shader"));
			((dfControl)val3).zindex = 7;
			((dfControl)val4).zindex = 5;
			GameUIAmmoType val5 = new GameUIAmmoType
			{
				ammoBarBG = val4,
				ammoBarFG = val3,
				ammoType = (AmmoType)14,
				customAmmoType = name
			};
			addedAmmoTypes.Add(val5);
			if (GameUIRoot.HasInstance)
			{
				foreach (GameUIAmmoController ammoController in GameUIRoot.Instance.ammoControllers)
				{
					if (ammoController.m_initialized)
					{
						ammoController.ammoTypes = CollectionExtensions.AddToArray<GameUIAmmoType>(ammoController.ammoTypes, val5);
					}
				}
			}
			return name;
		}

		public static T SetupDfSpriteFromTexture<T>(this GameObject obj, Texture2D texture, Shader shader) where T : dfSprite
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0035: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			T orAddComponent = GameObjectExtensions.GetOrAddComponent<T>(obj);
			dfAtlas orAddComponent2 = GameObjectExtensions.GetOrAddComponent<dfAtlas>(obj);
			orAddComponent2.Material = new Material(shader);
			orAddComponent2.Material.mainTexture = (Texture)(object)texture;
			orAddComponent2.Items.Clear();
			ItemInfo val = new ItemInfo
			{
				border = new RectOffset(),
				deleted = false,
				name = "main_sprite",
				region = new Rect(Vector2.zero, new Vector2(1f, 1f)),
				rotated = false,
				sizeInPixels = new Vector2((float)((Texture)texture).width, (float)((Texture)texture).height),
				texture = null,
				textureGUID = "main_sprite"
			};
			orAddComponent2.AddItem(val);
			((dfSprite)orAddComponent).Atlas = orAddComponent2;
			((dfSprite)orAddComponent).SpriteName = "main_sprite";
			((dfControl)(object)orAddComponent).zindex = 0;
			return orAddComponent;
		}

		[HarmonyPatch(typeof(GameUIAmmoController), "Initialize")]
		[HarmonyPostfix]
		public static void AddMissingAmmotypes(GameUIAmmoController __instance)
		{
			__instance.ammoTypes = __instance.ammoTypes.Concat(addedAmmoTypes).ToArray();
		}
	}
	public class InterestRounds : PassiveItem
	{
		public float damageMultPerCasing;

		[NonSerialized]
		public float damageMult = 1f;

		public static void Init()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			string text = "Interest Bullets";
			string resourcePath = "BankerItems/Resources/interest_rounds_idle_001";
			GameObject val = new GameObject(text);
			InterestRounds interestRounds = val.AddComponent<InterestRounds>();
			ItemBuilder.AddSpriteToObject(text, resourcePath, val);
			string shortDesc = "Loan and Gun";
			string longDesc = "A type of ammunition appreciated by usurers and economists alike, the Interest Bullets are the go-to tool for slowing down economies, diminishing inflation, and putting your enemies beneath the soil. That is, of course, as long as you have the money to make use of the high interest rates.\n\nCollect casings before clearing a room to increase the stats of all your guns. Stats reset when entering a new room.";
			((PickupObject)(object)interestRounds).SetupItem(shortDesc, longDesc, "spapi");
			((PickupObject)interestRounds).quality = (ItemQuality)3;
			interestRounds.damageMultPerCasing = 0.1f;
			((PickupObject)(object)interestRounds).SetupUnlockOnFlag(Plugin.interestRoundsUnlocked, requiredFlagValue: true);
		}

		public override void Pickup(PlayerController player)
		{
			((PassiveItem)this).Pickup(player);
			player.PostProcessProjectile += DamageUp;
			player.OnEnteredCombat = (Action)Delegate.Combine(player.OnEnteredCombat, new Action(ResetDamageMult));
		}

		public void ResetDamageMult()
		{
			damageMult = 1f;
		}

		public void DamageUp(Projectile proj, float f)
		{
			ProjectileData baseData = proj.baseData;
			baseData.damage *= damageMult;
		}

		public override void DisableEffect(PlayerController player)
		{
			player.PostProcessProjectile -= DamageUp;
			player.OnEnteredCombat = (Action)Delegate.Remove(player.OnEnteredCombat, new Action(ResetDamageMult));
			damageMult = 1f;
			((PassiveItem)this).DisableEffect(player);
		}
	}
	public class InterestRoundsUnlock : BraveBehaviour
	{
		public void Start()
		{
			if ((Object)(object)((BraveBehaviour)this).healthHaver != (Object)null)
			{
				((BraveBehaviour)this).healthHaver.OnDeath += Unlock;
			}
		}

		public void Unlock(Vector2 v)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (GameManager.HasInstance && (Object)(object)GameManager.Instance.PrimaryPlayer != (Object)null && ((Object)GameManager.Instance.PrimaryPlayer).name.ToLowerInvariant().Replace("(clone)", "").Trim() == "playerbanker")
			{
				GameStatsManager.Instance.SetFlag(Plugin.interestRoundsUnlocked, true);
			}
		}
	}
	[BepInPlugin("spapi.etg.bankeritems", "Banker Items", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "spapi.etg.bankeritems";

		public const string NAME = "Banker Items";

		public const string VERSION = "1.0.0";

		public static GungeonFlags interestRoundsUnlocked;

		public static GameObject banker;

		public static GameObject monocle;

		public void Awake()
		{
			ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
		}

		public void GMStart(GameManager man)
		{
			//IL_0011: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Expected O, but got Unknown
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Expected O, but got Unknown
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			interestRoundsUnlocked = ETGModCompatibility.ExtendEnum<GungeonFlags>("spapi.etg.bankeritems", "InterestRoundsUnlocked");
			SoundManager.Init();
			ItemBuilder.Init();
			new Harmony("spapi.etg.bankeritems").PatchAll();
			BankerItem.Init();
			BankerGun.Init();
			InterestRounds.Init();
			((Component)EnemyDatabase.GetOrLoadByGuid("465da2bb086a4a88a803f79fe3a27677")).gameObject.AddComponent<InterestRoundsUnlock>();
			((Component)EnemyDatabase.GetOrLoadByGuid("05b8afe0b6cc4fffa9dc6036fa24c8ec")).gameObject.AddComponent<InterestRoundsUnlock>();
			monocle = new GameObject("monocle vfx");
			FakePrefab.MarkAsFakePrefab(monocle);
			monocle.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)monocle);
			string helmetShader = "tk2d/CutoutVertexColorTilted";
			List<int> list = new List<string>
			{
				"001", "002", "003", "004", "005", "006", "007", "008", "009", "010",
				"011", "012", "011", "blank", "011", "blank", "011", "blank"
			}.Select((string x) => SpriteBuilder.AddSpriteToCollection("BankerItems/Resources/Monocle/banker_monocle_" + x, SpriteBuilder.itemCollection, helmetShader)).ToList();
			tk2dSprite.AddComponent(monocle, SpriteBuilder.itemCollection, list[0]);
			tk2dSpriteAnimator val = monocle.AddComponent<tk2dSpriteAnimator>();
			val.Library = monocle.AddComponent<tk2dSpriteAnimation>();
			val.Library.clips = (tk2dSpriteAnimationClip[])(object)new tk2dSpriteAnimationClip[1]
			{
				new tk2dSpriteAnimationClip
				{
					frames = ((IEnumerable<int>)list).Select((Func<int, tk2dSpriteAnimationFrame>)((int x) => new tk2dSpriteAnimationFrame
					{
						spriteId = x,
						spriteCollection = SpriteBuilder.itemCollection
					})).ToArray(),
					fps = 15f,
					loopStart = 0,
					maxFidgetDuration = 0f,
					minFidgetDuration = 0f,
					name = "monocle",
					wrapMode = (WrapMode)2
				}
			};
			val.playAutomatically = true;
			val.DefaultClipId = 0;
			DebrisObject val2 = monocle.AddComponent<DebrisObject>();
			val2.ACCURATE_DEBRIS_THRESHOLD = 0.25f;
			val2.accurateDebris = false;
			val2.additionalBounceEnglish = 0f;
			val2.additionalHeightBoost = 0f;
			val2.angularVelocity = 0f;
			val2.angularVelocityVariance = 20f;
			val2.animatePitFall = false;
			val2.AssignedGoop = null;
			val2.audioEventName = "";
			val2.bounceCount = 1;
			val2.breakOnFallChance = 1f;
			val2.breaksOnFall = true;
			val2.canRotate = true;
			val2.changesCollisionLayer = false;
			val2.collisionStopsBullets = false;
			val2.decayOnBounce = 0.5f;
			val2.detachedParticleSystems = new List<ParticleSystem>();
			val2.directionalAnimationData = new DebrisDirectionalAnimationInfo
			{
				fallDown = "",
				fallLeft = "",
				fallRight = "",
				fallUp = ""
			};
			val2.doesDecay = false;
			val2.DoesGoopOnRest = false;
			val2.followupBehavior = (DebrisFollowupAction)0;
			val2.followupIdentifier = "";
			val2.ForceUpdateIfDisabled = false;
			val2.GoopRadius = 1f;
			val2.groundedCollisionLayer = (CollisionLayer)5;
			val2.groupManager = null;
			val2.inertialMass = 1f;
			val2.IsCorpse = false;
			val2.isFalling = false;
			val2.isPitFalling = false;
			val2.isStatic = true;
			val2.killTranslationOnBounce = false;
			val2.lifespanMax = 1f;
			val2.lifespanMin = 1f;
			val2.motionMultiplier = 1f;
			val2.onGround = false;
			val2.pitFallSplash = false;
			val2.placementOptions = new DebrisPlacementOptions
			{
				canBeFlippedHorizontally = false,
				canBeFlippedVertically = false,
				canBeRotated = false
			};
			val2.playAnimationOnTrigger = false;
			val2.PreventAbsorption = false;
			val2.PreventFallingInPits = false;
			val2.removeSRBOnGrounded = false;
			val2.shadowSprite = null;
			val2.shouldUseSRBMotion = false;
			val2.usesDirectionalFallAnimations = false;
			val2.usesLifespan = false;
			((EphemeralObject)val2).Priority = (EphemeralPriority)2;
			((MonoBehaviour)this).StartCoroutine(DelayedBankerEdit());
		}

		public IEnumerator DelayedBankerEdit()
		{
			yield return null;
			GameObject val = (GameObject)BraveResources.Load("PlayerBanker", ".prefab");
			banker = val;
			PlayerController bank = val.GetComponent<PlayerController>();
			bank.lostAllArmorVFX = monocle;
		}
	}
	public static class UnlockTools
	{
		public static DungeonPrerequisite SetupUnlockOnFlag(this PickupObject self, GungeonFlags flag, bool requiredFlagValue)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((BraveBehaviour)self).encounterTrackable == (Object)null)
			{
				return null;
			}
			return ((BraveBehaviour)self).encounterTrackable.SetupUnlockOnFlag(flag, requiredFlagValue);
		}

		public static DungeonPrerequisite SetupUnlockOnFlag(this EncounterTrackable self, GungeonFlags flag, bool requiredFlagValue)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			return self.AddPrerequisite(new DungeonPrerequisite
			{
				prerequisiteType = (PrerequisiteType)4,
				saveFlagToCheck = flag,
				requireFlag = requiredFlagValue
			});
		}

		public static DungeonPrerequisite AddPrerequisite(this PickupObject self, DungeonPrerequisite prereq)
		{
			return ((BraveBehaviour)self).encounterTrackable.AddPrerequisite(prereq);
		}

		public static DungeonPrerequisite AddPrerequisite(this EncounterTrackable self, DungeonPrerequisite prereq)
		{
			if (!string.IsNullOrEmpty(self.ProxyEncounterGuid))
			{
				self.ProxyEncounterGuid = "";
			}
			if (self.prerequisites == null)
			{
				self.prerequisites = (DungeonPrerequisite[])(object)new DungeonPrerequisite[1] { prereq };
			}
			else
			{
				DungeonPrerequisite[] prerequisites = self.prerequisites;
				prerequisites = CollectionExtensions.AddToArray<DungeonPrerequisite>(prerequisites, prereq);
				self.prerequisites = prerequisites;
			}
			EncounterDatabaseEntry entry = EncounterDatabase.GetEntry(self.EncounterGuid);
			if (!string.IsNullOrEmpty(entry.ProxyEncounterGuid))
			{
				entry.ProxyEncounterGuid = "";
			}
			if (entry.prerequisites == null)
			{
				entry.prerequisites = (DungeonPrerequisite[])(object)new DungeonPrerequisite[1] { prereq };
			}
			else
			{
				DungeonPrerequisite[] prerequisites2 = entry.prerequisites;
				prerequisites2 = CollectionExtensions.AddToArray<DungeonPrerequisite>(prerequisites2, prereq);
				entry.prerequisites = prerequisites2;
			}
			return prereq;
		}
	}
}
namespace BankerItems.SoundAPI
{
	public class CustomSwitchData
	{
		public string OriginalEventName;

		public string SwitchGroup;

		public string RequiredSwitch;

		public List<SwitchedEvent> ReplacementEvents;

		public uint Play(GameObject go, Func<SwitchedEvent, GameObject, uint> playFunc)
		{
			try
			{
				if (ReplacementEvents != null)
				{
					uint? num = null;
					foreach (SwitchedEvent replacementEvent in ReplacementEvents)
					{
						uint num2 = playFunc(replacementEvent, go);
						num = num ?? num2;
					}
					if (!num.HasValue)
					{
						num = 0u;
					}
					return num.GetValueOrDefault();
				}
				return 0u;
			}
			catch
			{
				return 0u;
			}
		}
	}
	public static class SoundManager
	{
		private delegate TResult Func<T1, T2, T3, T4, T5, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);

		private delegate TResult Func<T1, T2, T3, T4, T5, T6, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);

		private delegate TResult Func<T1, T2, T3, T4, T5, T6, T7, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);

		private delegate TResult Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);

		public static List<CustomSwitchData> CustomSwitchDatas;

		public static List<string> StopEvents;

		public static List<string> StopEventsMusic;

		public static List<string> StopEventsObjects;

		public static List<string> StopEventsWeapons;

		private static Dictionary<GameObject, Dictionary<string, string>> Switches;

		private static Hook SetSwitchHook;

		private static Hook PostEventPlayingIdHook;

		private static Hook PostEventExternalSourcesHook;

		private static Hook PostEventExternalsHook;

		private static Hook PostEventCallbackCookieHook;

		private static Hook PostEventFlagsHook;

		private static Hook PostEventHook;

		private static bool m_initialized;

		private static bool origSetSwitch;

		public static void Init()
		{
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Expected O, but got Unknown
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Expected O, but got Unknown
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Expected O, but got Unknown
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			if (!m_initialized)
			{
				CustomSwitchDatas = new List<CustomSwitchData>();
				Switches = new Dictionary<GameObject, Dictionary<string, string>>();
				StopEvents = new List<string>();
				StopEventsMusic = new List<string>();
				StopEventsObjects = new List<string>();
				StopEventsWeapons = new List<string>();
				if (SetSwitchHook == null)
				{
					SetSwitchHook = new Hook((MethodBase)typeof(AkSoundEngine).GetMethod("SetSwitch", new Type[3]
					{
						typeof(string),
						typeof(string),
						typeof(GameObject)
					}), typeof(SoundManager).GetMethod("SetSwitch", BindingFlags.Static | BindingFlags.NonPublic));
				}
				PostEventPlayingIdHook = new Hook((MethodBase)typeof(AkSoundEngine).GetMethod("PostEvent", new Type[8]
				{
					typeof(string),
					typeof(GameObject),
					typeof(uint),
					typeof(EventCallback),
					typeof(object),
					typeof(uint),
					typeof(AkExternalSourceInfo),
					typeof(uint)
				}), typeof(SoundManager).GetMethod("PostEventPlayingId", BindingFlags.Static | BindingFlags.NonPublic));
				PostEventExternalSourcesHook = new Hook((MethodBase)typeof(AkSoundEngine).GetMethod("PostEvent", new Type[7]
				{
					typeof(string),
					typeof(GameObject),
					typeof(uint),
					typeof(EventCallback),
					typeof(object),
					typeof(uint),
					typeof(AkExternalSourceInfo)
				}), typeof(SoundManager).GetMethod("PostEventExternalSources", BindingFlags.Static | BindingFlags.NonPublic));
				PostEventExternalsHook = new Hook((MethodBase)typeof(AkSoundEngine).GetMethod("PostEvent", new Type[6]
				{
					typeof(string),
					typeof(GameObject),
					typeof(uint),
					typeof(EventCallback),
					typeof(object),
					typeof(uint)
				}), typeof(SoundManager).GetMethod("PostEventExternals", BindingFlags.Static | BindingFlags.NonPublic));
				PostEventCallbackCookieHook = new Hook((MethodBase)typeof(AkSoundEngine).GetMethod("PostEvent", new Type[5]
				{
					typeof(string),
					typeof(GameObject),
					typeof(uint),
					typeof(EventCallback),
					typeof(object)
				}), typeof(SoundManager).GetMethod("PostEventCallbackCookie", BindingFlags.Static | BindingFlags.NonPublic));
				PostEventFlagsHook = new Hook((MethodBase)typeof(AkSoundEngine).GetMethod("PostEvent", new Type[3]
				{
					typeof(string),
					typeof(GameObject),
					typeof(uint)
				}), typeof(SoundManager).GetMethod("PostEventFlags", BindingFlags.Static | BindingFlags.NonPublic));
				PostEventHook = new Hook((MethodBase)typeof(AkSoundEngine).GetMethod("PostEvent", new Type[2]
				{
					typeof(string),
					typeof(GameObject)
				}), typeof(SoundManager).GetMethod("PostEvent", BindingFlags.Static | BindingFlags.NonPublic));
				m_initialized = true;
			}
		}

		public static void Unload()
		{
			if (m_initialized)
			{
				CustomSwitchDatas?.Clear();
				CustomSwitchDatas = null;
				StopEvents?.Clear();
				StopEventsMusic?.Clear();
				StopEventsObjects?.Clear();
				StopEventsWeapons?.Clear();
				StopEvents = null;
				StopEventsMusic = null;
				StopEventsObjects = null;
				StopEventsWeapons = null;
				Hook postEventPlayingIdHook = PostEventPlayingIdHook;
				if (postEventPlayingIdHook != null)
				{
					postEventPlayingIdHook.Dispose();
				}
				Hook postEventExternalSourcesHook = PostEventExternalSourcesHook;
				if (postEventExternalSourcesHook != null)
				{
					postEventExternalSourcesHook.Dispose();
				}
				Hook postEventExternalsHook = PostEventExternalsHook;
				if (postEventExternalsHook != null)
				{
					postEventExternalsHook.Dispose();
				}
				Hook postEventCallbackCookieHook = PostEventCallbackCookieHook;
				if (postEventCallbackCookieHook != null)
				{
					postEventCallbackCookieHook.Dispose();
				}
				Hook postEventFlagsHook = PostEventFlagsHook;
				if (postEventFlagsHook != null)
				{
					postEventFlagsHook.Dispose();
				}
				Hook postEventHook = PostEventHook;
				if (postEventHook != null)
				{
					postEventHook.Dispose();
				}
				m_initialized = false;
			}
		}

		public static void LoadBankFromModFolderOrZip(this BaseUnityPlugin mod, string fileName)
		{
			if (!fileName.EndsWith(".bnk"))
			{
				fileName += ".bnk";
			}
			LoadFromPath(ETGMod.FolderPath(mod), fileName);
		}

		public static void LoadBanksFromModFolderOrZip(this BaseUnityPlugin mod)
		{
			AutoloadFromPath(ETGMod.FolderPath(mod));
		}

		public static void LoadBankFromModProject(string path)
		{
			path = path.Replace("/", ".").Replace("\\", ".");
			if (!path.EndsWith(".bnk"))
			{
				path += ".bnk";
			}
			Assembly callingAssembly = Assembly.GetCallingAssembly();
			using Stream stream = callingAssembly.GetManifestResourceStream(path);
			if (stream != null)
			{
				string text = path.Substring(0, path.LastIndexOf('.'));
				string name = path;
				if (text.LastIndexOf('.') >= 0)
				{
					name = text.Substring(text.LastIndexOf('.') + 1);
				}
				LoadSoundbankFromStream(stream, name);
			}
		}

		public static void LoadBanksFromModProject()
		{
			Assembly callingAssembly = Assembly.GetCallingAssembly();
			string[] manifestResourceNames = callingAssembly.GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				using Stream stream = callingAssembly.GetManifestResourceStream(text);
				if (stream != null && text.EndsWith(".bnk"))
				{
					string text2 = text.Substring(0, text.LastIndexOf('.'));
					string name = text;
					if (text2.LastIndexOf('.') >= 0)
					{
						name = text2.Substring(text2.LastIndexOf('.') + 1);
					}
					LoadSoundbankFromStream(stream, name);
				}
			}
		}

		private static void LoadFromPath(string path, string filename)
		{
			if (string.IsNullOrEmpty(path))
			{
				return;
			}
			path = path.Replace('/', Path.DirectorySeparatorChar);
			path = path.Replace('\\', Path.DirectorySeparatorChar);
			if (!Directory.Exists(path))
			{
				return;
			}
			List<string> list = new List<string>(Directory.GetFiles(path, "*.bnk", SearchOption.AllDirectories));
			for (int i = 0; i < list.Count; i++)
			{
				string path2 = list[i];
				using FileStream stream = File.OpenRead(path2);
				string fileName = Path.GetFileName(path);
				if (fileName == filename)
				{
					LoadSoundbankFromStream(stream, fileName);
					break;
				}
			}
		}

		private static void AutoloadFromPath(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return;
			}
			path = path.Replace('/', Path.DirectorySeparatorChar);
			path = path.Replace('\\', Path.DirectorySeparatorChar);
			if (!Directory.Exists(path))
			{
				return;
			}
			List<string> list = new List<string>(Directory.GetFiles(path, "*.bnk", SearchOption.AllDirectories));
			for (int i = 0; i < list.Count; i++)
			{
				string path2 = list[i];
				using FileStream stream = File.OpenRead(path2);
				string fileName = Path.GetFileName(path);
				LoadSoundbankFromStream(stream, fileName);
			}
		}

		private static byte[] StreamToByteArray(Stream input)
		{
			byte[] array = new byte[16384];
			using MemoryStream memoryStream = new MemoryStream();
			int count;
			while ((count = input.Read(array, 0, array.Length)) > 0)
			{
				memoryStream.Write(array, 0, count);
			}
			return memoryStream.ToArray();
		}

		private static void LoadSoundbankFromStream(Stream stream, string name)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			byte[] array = StreamToByteArray(stream);
			IntPtr intPtr = Marshal.AllocHGlobal(array.Length);
			try
			{
				Marshal.Copy(array, 0, intPtr, array.Length);
				uint num = default(uint);
				AKRESULT val = AkSoundEngine.LoadAndDecodeBankFromMemory(intPtr, (uint)array.Length, false, name, false, ref num);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
			}
		}

		public static CustomSwitchData AddCustomSwitchData(string switchGroup, string switchValue, string originalEventName, params SwitchedEvent[] replacementEvents)
		{
			if (CustomSwitchDatas == null)
			{
				Init();
			}
			CustomSwitchData customSwitchData = new CustomSwitchData
			{
				OriginalEventName = originalEventName,
				ReplacementEvents = new List<SwitchedEvent>(replacementEvents),
				RequiredSwitch = switchValue,
				SwitchGroup = switchGroup
			};
			CustomSwitchDatas.Add(customSwitchData);
			return customSwitchData;
		}

		public static void RegisterStopEvent(string eventName, params StopEventType[] types)
		{
			if (StopEvents == null)
			{
				Init();
			}
			StopEvents.Add(eventName);
			for (int i = 0; i < types.Length; i++)
			{
				switch (types[i])
				{
				case StopEventType.Music:
					StopEventsMusic.Add(eventName);
					break;
				case StopEventType.Weapon:
					StopEventsWeapons.Add(eventName);
					break;
				case StopEventType.Object:
					StopEventsObjects.Add(eventName);
					break;
				}
			}
		}

		private static uint PostEventPlayingId(Func<string, GameObject, uint, EventCallback, object, uint, AkExternalSourceInfo, uint, uint> orig, string eventName, GameObject gameObject, uint flags, EventCallback callback, object cookie, uint externals, AkExternalSourceInfo externalSources, uint playingId)
		{
			return ProcessEvent(eventName, gameObject, (string s, GameObject g) => orig(s, g, flags, callback, cookie, externals, externalSources, playingId));
		}

		private static uint PostEventExternalSources(Func<string, GameObject, uint, EventCallback, object, uint, AkExternalSourceInfo, uint> orig, string eventName, GameObject gameObject, uint flags, EventCallback callback, object cookie, uint externals, AkExternalSourceInfo externalSources)
		{
			return ProcessEvent(eventName, gameObject, (string s, GameObject g) => orig(s, g, flags, callback, cookie, externals, externalSources));
		}

		private static uint PostEventExternals(Func<string, GameObject, uint, EventCallback, object, uint, uint> orig, string eventName, GameObject gameObject, uint flags, EventCallback callback, object cookie, uint externals)
		{
			return ProcessEvent(eventName, gameObject, (string s, GameObject g) => orig(s, g, flags, callback, cookie, externals));
		}

		private static uint PostEventCallbackCookie(Func<string, GameObject, uint, EventCallback, object, uint> orig, string eventName, GameObject gameObject, uint flags, EventCallback callback, object cookie)
		{
			return ProcessEvent(eventName, gameObject, (string s, GameObject g) => orig(s, g, flags, callback, cookie));
		}

		private static uint PostEventFlags(Func<string, GameObject, uint, uint> orig, string eventName, GameObject gameObject, uint flags)
		{
			return ProcessEvent(eventName, gameObject, (string s, GameObject g) => orig(s, g, flags));
		}

		private static uint PostEvent(Func<string, GameObject, uint> orig, string eventName, GameObject gameObject)
		{
			return ProcessEvent(eventName, gameObject, (string s, GameObject g) => orig(s, g));
		}

		private static uint ProcessEvent(string eventName, GameObject go, Func<string, GameObject, uint> orig)
		{
			try
			{
				if ((Object)(object)go != (Object)null && !string.IsNullOrEmpty(eventName))
				{
					CustomSwitchData customSwitchData = GetCustomSwitchData(go, eventName);
					if (customSwitchData != null)
					{
						Func<SwitchedEvent, GameObject, uint> playFunc = delegate(SwitchedEvent switched, GameObject go2)
						{
							if (!string.IsNullOrEmpty(switched.eventName))
							{
								bool flag = false;
								if (!string.IsNullOrEmpty(switched.switchGroup) && switched.switchValue != null)
								{
									SetSwitchOrig(switched.switchGroup, switched.switchValue, go2);
									flag = true;
								}
								uint result = orig(switched.eventName, go2);
								if (flag)
								{
									ReturnSwitch(switched.switchGroup, go2);
								}
								return result;
							}
							return 0u;
						};
						return customSwitchData.Play(go, playFunc);
					}
					if (eventName.ToLowerInvariant() == "stop_snd_all")
					{
						foreach (string stopEvent in StopEvents)
						{
							if (!string.IsNullOrEmpty(stopEvent))
							{
								orig(stopEvent, go);
							}
						}
					}
					if (eventName.ToLowerInvariant() == "stop_mus_all")
					{
						foreach (string item in StopEventsMusic)
						{
							if (!string.IsNullOrEmpty(item))
							{
								orig(item, go);
							}
						}
					}
					if (eventName.ToLowerInvariant() == "stop_wpn_all")
					{
						foreach (string stopEventsWeapon in StopEventsWeapons)
						{
							if (!string.IsNullOrEmpty(stopEventsWeapon))
							{
								orig(stopEventsWeapon, go);
							}
						}
					}
					if (eventName.ToLowerInvariant() == "stop_snd_obj")
					{
						foreach (string stopEventsObject in StopEventsObjects)
						{
							if (!string.IsNullOrEmpty(stopEventsObject))
							{
								orig(stopEventsObject, go);
							}
						}
					}
				}
				if (eventName == null)
				{
					return 0u;
				}
				return orig(eventName, go);
			}
			catch
			{
				return 0u;
			}
		}

		private static CustomSwitchData GetCustomSwitchData(GameObject go, string eventName)
		{
			try
			{
				if (string.IsNullOrEmpty(eventName))
				{
					return null;
				}
				if ((Object)(object)go != (Object)null && Switches.ContainsKey(go) && Switches[go] != null)
				{
					foreach (CustomSwitchData customSwitchData in CustomSwitchDatas)
					{
						if (!string.IsNullOrEmpty(customSwitchData.OriginalEventName) && customSwitchData.OriginalEventName.ToLowerInvariant() == eventName.ToLowerInvariant() && !string.IsNullOrEmpty(customSwitchData.SwitchGroup) && Switches != null && Switches.ContainsKey(go) && Switches[go].ContainsKey(customSwitchData.SwitchGroup.ToLowerInvariant()) && !string.IsNullOrEmpty(customSwitchData.RequiredSwitch) && Switches[go][customSwitchData.SwitchGroup.ToLowerInvariant()] == customSwitchData.RequiredSwitch.ToLowerInvariant())
						{
							return customSwitchData;
						}
					}
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		private static AKRESULT SetSwitch(Func<string, string, GameObject, AKRESULT> orig, string switchGroup, string switchValue, GameObject gameObject)
		{
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)gameObject != (Object)null && Switches != null && !origSetSwitch)
			{
				if (!Switches.ContainsKey(gameObject))
				{
					Switches.Add(gameObject, new Dictionary<string, string> { 
					{
						switchGroup.ToLower(),
						switchValue.ToLower()
					} });
				}
				else if (Switches[gameObject] == null)
				{
					Switches[gameObject] = new Dictionary<string, string> { 
					{
						switchGroup.ToLower(),
						switchValue.ToLower()
					} };
				}
				else if (!Switches[gameObject].ContainsKey(switchGroup.ToLower()))
				{
					Switches[gameObject].Add(switchGroup.ToLower(), switchValue.ToLower());
				}
				else
				{
					Switches[gameObject][switchGroup.ToLower()] = switchValue.ToLower();
				}
			}
			return orig(switchGroup, switchValue, gameObject);
		}

		private static void SetSwitchOrig(string switchGroup, string switchValue, GameObject go)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			origSetSwitch = true;
			AkSoundEngine.SetSwitch(switchGroup, switchValue, go);
			origSetSwitch = false;
		}

		private static void ReturnSwitch(string switchGroup, GameObject go)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if (Switches != null && Switches.ContainsKey(go) && Switches[go] != null && Switches[go].ContainsKey(switchGroup))
			{
				origSetSwitch = true;
				AkSoundEngine.SetSwitch(switchGroup, Switches[go][switchGroup], go);
				origSetSwitch = false;
			}
		}
	}
	public enum StopEventType
	{
		None,
		Music,
		Weapon,
		Object
	}
	public class SwitchedEvent
	{
		public string eventName;

		public string switchGroup;

		public string switchValue;

		public SwitchedEvent()
		{
		}

		public SwitchedEvent(string s)
		{
			eventName = s;
			switchGroup = null;
			switchValue = null;
		}

		public SwitchedEvent(string eventName, string switchGroup, string switchValue)
		{
			this.eventName = eventName;
			this.switchGroup = switchGroup;
			this.switchValue = switchValue;
		}

		public static implicit operator SwitchedEvent(string s)
		{
			return new SwitchedEvent(s);
		}
	}
}
namespace BankerItems.ItemAPI
{
	public class FakePrefab : Component
	{
		internal static HashSet<GameObject> ExistingFakePrefabs = new HashSet<GameObject>();

		public static bool IsFakePrefab(Object o)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (o is GameObject)
			{
				return ExistingFakePrefabs.Contains((GameObject)o);
			}
			if (o is Component)
			{
				return ExistingFakePrefabs.Contains(((Component)o).gameObject);
			}
			return false;
		}

		public static void MarkAsFakePrefab(GameObject obj)
		{
			ExistingFakePrefabs.Add(obj);
		}

		public static GameObject Clone(GameObject obj)
		{
			bool flag = IsFakePrefab((Object)(object)obj);
			bool activeSelf = obj.activeSelf;
			if (activeSelf)
			{
				obj.SetActive(false);
			}
			GameObject val = Object.Instantiate<GameObject>(obj);
			if (activeSelf)
			{
				obj.SetActive(true);
			}
			ExistingFakePrefabs.Add(val);
			if (flag)
			{
			}
			return val;
		}

		public static Object Instantiate(Object o, Object new_o)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (o is GameObject && ExistingFakePrefabs.Contains((GameObject)o))
			{
				((GameObject)new_o).SetActive(true);
			}
			else if (o is Component && ExistingFakePrefabs.Contains(((Component)o).gameObject))
			{
				((Component)new_o).gameObject.SetActive(true);
			}
			return new_o;
		}
	}
	public static class FakePrefabHooks
	{
		public delegate TResult Func<T1, T2, T3, T4, T5, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);

		public static void Init()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Expected O, but got Unknown
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			Hook val = new Hook((MethodBase)typeof(PlayerController).GetMethod("AcquirePassiveItemPrefabDirectly"), typeof(FakePrefabHooks).GetMethod("AcquirePassiveItemPrefabDirectly"));
			Hook val2 = new Hook((MethodBase)typeof(PlayerItem).GetMethod("Pickup"), typeof(FakePrefabHooks).GetMethod("ActivePickup"));
			Hook val3 = new Hook((MethodBase)typeof(Object).GetMethod("Instantiate", new Type[3]
			{
				typeof(Object),
				typeof(Transform),
				typeof(bool)
			}), typeof(FakePrefabHooks).GetMethod("InstantiateOPI"));
			Hook val4 = new Hook((MethodBase)typeof(Object).GetMethod("Instantiate", new Type[2]
			{
				typeof(Object),
				typeof(Transform)
			}), typeof(FakePrefabHooks).GetMethod("InstantiateOP"));
			Hook val5 = new Hook((MethodBase)typeof(Object).GetMethod("orig_Instantiate", new Type[1] { typeof(Object) }), typeof(FakePrefabHooks).GetMethod("InstantiateO"));
			Hook val6 = new Hook((MethodBase)typeof(Object).GetMethod("Instantiate", new Type[3]
			{
				typeof(Object),
				typeof(Vector3),
				typeof(Quaternion)
			}), typeof(FakePrefabHooks).GetMethod("InstantiateOPR"));
			Hook val7 = new Hook((MethodBase)typeof(Object).GetMethod("Instantiate", new Type[4]
			{
				typeof(Object),
				typeof(Vector3),
				typeof(Quaternion),
				typeof(Transform)
			}), typeof(FakePrefabHooks).GetMethod("InstantiateOPRP"));
		}

		public static void AcquirePassiveItemPrefabDirectly(Action<PlayerController, PassiveItem> orig, PlayerController self, PassiveItem item)
		{
			bool flag = FakePrefab.IsFakePrefab((Object)(object)((Component)item).gameObject);
			if (flag)
			{
				((Component)item).gameObject.SetActive(true);
			}
			orig(self, item);
			if (flag)
			{
				((Component)item).gameObject.SetActive(false);
			}
		}

		public static void ActivePickup(Action<PlayerItem, PlayerController> orig, PlayerItem self, PlayerController player)
		{
			bool flag = FakePrefab.IsFakePrefab((Object)(object)((Component)self).gameObject);
			if (flag)
			{
				((Component)self).gameObject.SetActive(true);
			}
			orig(self, player);
			if (flag)
			{
				((Component)self).gameObject.SetActive(false);
			}
		}

		public static Object InstantiateOPI(Func<Object, Transform, bool, Object> orig, Object original, Transform parent, bool instantiateInWorldSpace)
		{
			return FakePrefab.Instantiate(original, orig(original, parent, instantiateInWorldSpace));
		}

		public static Object InstantiateOP(Func<Object, Transform, Object> orig, Object original, Transform parent)
		{
			return FakePrefab.Instantiate(original, orig(original, parent));
		}

		public static Object InstantiateO(Func<Object, Object> orig, Object original)
		{
			return FakePrefab.Instantiate(original, orig(original));
		}

		public static Object InstantiateOPR(Func<Object, Vector3, Quaternion, Object> orig, Object original, Vector3 position, Quaternion rotation)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return FakePrefab.Instantiate(original, orig(original, position, rotation));
		}

		public static Object InstantiateOPRP(Func<Object, Vector3, Quaternion, Transform, Object> orig, Object original, Vector3 position, Quaternion rotation, Transform parent)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return FakePrefab.Instantiate(original, orig(original, position, rotation, parent));
		}
	}
	public static class ItemBuilder
	{
		public enum CooldownType
		{
			Timed,
			Damage,
			PerRoom,
			None
		}

		public enum ShopType
		{
			Goopton,
			Flynt,
			Cursula,
			Trorc,
			OldRed
		}

		public static Dictionary<ShopType, GenericLootTable> shopInventories;

		public static void Init()
		{
			FakePrefabHooks.Init();
			LoadShopTables();
		}

		private static void LoadShopTables()
		{
			shopInventories = new Dictionary<ShopType, GenericLootTable>();
			shopInventories.Add(ShopType.Flynt, LoadShopTable("Shop_Key_Items_01"));
			shopInventories.Add(ShopType.Trorc, LoadShopTable("Shop_Truck_Items_01"));
			shopInventories.Add(ShopType.Cursula, LoadShopTable("Shop_Curse_Items_01"));
			shopInventories.Add(ShopType.Goopton, LoadShopTable("Shop_Goop_Items_01"));
			shopInventories.Add(ShopType.OldRed, LoadShopTable("Shop_Blank_Items_01"));
		}

		public static GenericLootTable LoadShopTable(string assetName)
		{
			return ResourceManager.LoadAssetBundle("shared_auto_001").LoadAsset<GenericLootTable>(assetName);
		}

		public static GameObject AddSpriteToObject(string name, string resourcePath, GameObject obj = null)
		{
			GameObject val = SpriteBuilder.SpriteFromResource(resourcePath, obj);
			FakePrefab.MarkAsFakePrefab(val);
			obj.SetActive(false);
			((Object)val).name = name;
			return val;
		}

		public static void SetupItem(this PickupObject item, string shortDesc, string longDesc, string idPool = "ItemAPI")
		{
			try
			{
				((BraveBehaviour)item).encounterTrackable = null;
				Databases.Items.SetupItem(item, ((Object)item).name);
				SpriteBuilder.AddToAmmonomicon(((BraveBehaviour)item).sprite.GetCurrentSpriteDef());
				((BraveBehaviour)item).encounterTrackable.journalData.AmmonomiconSprite = ((BraveBehaviour)item).sprite.GetCurrentSpriteDef().name;
				GunExt.SetName(item, ((Object)item).name);
				GunExt.SetShortDescription(item, shortDesc);
				GunExt.SetLongDescription(item, longDesc);
				if (item is PlayerItem)
				{
					((PlayerItem)((item is PlayerItem) ? item : null)).consumable = false;
				}
				Game.Items.Add(idPool + ":" + ((Object)item).name.ToLower().Replace(" ", "_"), item);
				Databases.Items.Add(item, false, "ANY");
			}
			catch (Exception ex)
			{
				ETGModConsole.Log((object)ex.Message, false);
				ETGModConsole.Log((object)ex.StackTrace, false);
			}
		}

		public static void AddToSubShop(this PickupObject po, ShopType type, float weight = 1f)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			WeightedGameObjectCollection defaultItemDrops = shopInventories[type].defaultItemDrops;
			WeightedGameObject val = new WeightedGameObject();
			val.pickupId = po.PickupObjectId;
			val.weight = weight;
			val.rawGameObject = ((Component)po).gameObject;
			val.forceDuplicatesPossible = false;
			val.additionalPrerequisites = (DungeonPrerequisite[])(object)new DungeonPrerequisite[0];
			defaultItemDrops.Add(val);
		}

		public static void SetCooldownType(this PlayerItem item, CooldownType cooldownType, float value)
		{
			item.damageCooldown = -1f;
			item.roomCooldown = -1;
			item.timeCooldown = -1f;
			switch (cooldownType)
			{
			case CooldownType.Timed:
				item.timeCooldown = value;
				break;
			case CooldownType.Damage:
				item.damageCooldown = value;
				break;
			case CooldownType.PerRoom:
				item.roomCooldown = (int)value;
				break;
			}
		}

		public static StatModifier AddPassiveStatModifier(this PickupObject po, StatType statType, float amount, ModifyMethod method = 0)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			StatModifier val = new StatModifier();
			val.amount = amount;
			val.statToBoost = statType;
			val.modifyType = method;
			po.AddPassiveStatModifier(val);
			return val;
		}

		public static void AddPassiveStatModifier(this PickupObject po, StatModifier modifier)
		{
			if (po is PlayerItem)
			{
				PlayerItem val = (PlayerItem)(object)((po is PlayerItem) ? po : null);
				if (val.passiveStatModifiers == null)
				{
					val.passiveStatModifiers = (StatModifier[])(object)new StatModifier[1] { modifier };
				}
				else
				{
					val.passiveStatModifiers = val.passiveStatModifiers.Concat((IEnumerable<StatModifier>)(object)new StatModifier[1] { modifier }).ToArray();
				}
				return;
			}
			if (po is PassiveItem)
			{
				PassiveItem val2 = (PassiveItem)(object)((po is PassiveItem) ? po : null);
				if (val2.passiveStatModifiers == null)
				{
					val2.passiveStatModifiers = (StatModifier[])(object)new StatModifier[1] { modifier };
				}
				else
				{
					val2.passiveStatModifiers = val2.passiveStatModifiers.Concat((IEnumerable<StatModifier>)(object)new StatModifier[1] { modifier }).ToArray();
				}
				return;
			}
			throw new NotSupportedException("Object must be of type PlayerItem or PassiveItem");
		}

		public static bool RemovePassiveStatModifier(this PickupObject po, StatModifier modifier)
		{
			bool flag = false;
			if (po is PlayerItem)
			{
				PlayerItem val = (PlayerItem)(object)((po is PlayerItem) ? po : null);
				if (val.passiveStatModifiers == null)
				{
					return false;
				}
				List<StatModifier> list = val.passiveStatModifiers.ToList();
				flag = list.Remove(modifier);
				val.passiveStatModifiers = list.ToArray();
			}
			else
			{
				if (!(po is PassiveItem))
				{
					throw new NotSupportedException("Object must be of type PlayerItem or PassiveItem");
				}
				PassiveItem val2 = (PassiveItem)(object)((po is PassiveItem) ? po : null);
				if (val2.passiveStatModifiers == null)
				{
					return false;
				}
				List<StatModifier> list2 = val2.passiveStatModifiers.ToList();
				flag = list2.Remove(modifier);
				val2.passiveStatModifiers = list2.ToArray();
			}
			return flag;
		}

		public static IEnumerator HandleDuration(PlayerItem item, float duration, PlayerController user, Action<PlayerController> OnFinish)
		{
			if (!item.IsCurrentlyActive)
			{
				SetPrivateType<PlayerItem>(item, "m_isCurrentlyActive", value: true);
				SetPrivateType<PlayerItem>(item, "m_activeElapsed", 0f);
				SetPrivateType<PlayerItem>(item, "m_activeDuration", duration);
				item.OnActivationStatusChanged?.Invoke(item);
				GetPrivateType<PlayerItem, float>(item, "m_activeElapsed");
				GetPrivateType<PlayerItem, float>(item, "m_activeDuration");
				while (GetPrivateType<PlayerItem, float>(item, "m_activeElapsed") < GetPrivateType<PlayerItem, float>(item, "m_activeDuration") && item.IsCurrentlyActive)
				{
					yield return null;
				}
				SetPrivateType<PlayerItem>(item, "m_isCurrentlyActive", value: false);
				item.OnActivationStatusChanged?.Invoke(item);
				OnFinish?.Invoke(user);
			}
		}

		private static void SetPrivateType<T>(T obj, string field, bool value)
		{
			FieldInfo field2 = typeof(T).GetField(field, BindingFlags.Instance | BindingFlags.NonPublic);
			field2.SetValue(obj, value);
		}

		private static void SetPrivateType<T>(T obj, string field, float value)
		{
			FieldInfo field2 = typeof(T).GetField(field, BindingFlags.Instance | BindingFlags.NonPublic);
			field2.SetValue(obj, value);
		}

		private static T2 GetPrivateType<T, T2>(T obj, string field)
		{
			FieldInfo field2 = typeof(T).GetField(field, BindingFlags.Instance | BindingFlags.NonPublic);
			return (T2)field2.GetValue(obj);
		}
	}
	public static class ResourceExtractor
	{
		private static string spritesDirectory = Path.Combine(ETGMod.ResourcesDirectory, "sprites");

		public static List<Texture2D> GetTexturesFromDirectory(string directoryPath)
		{
			if (!Directory.Exists(directoryPath))
			{
				ETGModConsole.Log((object)(directoryPath + " not found."), false);
				return null;
			}
			List<Texture2D> list = new List<Texture2D>();
			string[] files = Directory.GetFiles(directoryPath);
			foreach (string text in files)
			{
				if (text.EndsWith(".png"))
				{
					Texture2D item = BytesToTexture(File.ReadAllBytes(text), Path.GetFileName(text).Replace(".png", ""));
					list.Add(item);
				}
			}
			return list;
		}

		public static Texture2D GetTextureFromFile(string fileName, string extension = ".png")
		{
			fileName = fileName.Replace(extension, "");
			string text = Path.Combine(spritesDirectory, fileName + extension);
			if (!File.Exists(text))
			{
				ETGModConsole.Log((object)(text + " not found."), false);
				return null;
			}
			return BytesToTexture(File.ReadAllBytes(text), fileName);
		}

		public static List<string> GetCollectionFiles()
		{
			List<string> list = new List<string>();
			string[] files = Directory.GetFiles(spritesDirectory);
			foreach (string text in files)
			{
				if (text.EndsWith(".png"))
				{
					list.Add(Path.GetFileName(text).Replace(".png", ""));
				}
			}
			return list;
		}

		public static Texture2D BytesToTexture(byte[] bytes, string resourceName)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, bytes);
			((Texture)val).filterMode = (FilterMode)0;
			((Object)val).name = resourceName;
			return val;
		}

		public static string[] GetLinesFromEmbeddedResource(string filePath)
		{
			string text = BytesToString(ExtractEmbeddedResource(filePath));
			return text.Split(new char[1] { '\n' });
		}

		public static string[] GetLinesFromFile(string filePath)
		{
			string text = BytesToString(File.ReadAllBytes(filePath));
			return text.Split(new char[1] { '\n' });
		}

		public static string BytesToString(byte[] bytes)
		{
			return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
		}

		public static List<string> GetResourceFolders()
		{
			List<string> list = new List<string>();
			string path = Path.Combine(ETGMod.ResourcesDirectory, "sprites");
			if (Directory.Exists(path))
			{
				string[] directories = Directory.GetDirectories(path);
				foreach (string path2 in directories)
				{
					list.Add(Path.GetFileName(path2));
				}
			}
			return list;
		}

		public static byte[] ExtractEmbeddedResource(string filePath)
		{
			filePath = filePath.Replace("/", ".");
			filePath = filePath.Replace("\\", ".");
			Assembly callingAssembly = Assembly.GetCallingAssembly();
			using Stream stream = callingAssembly.GetManifestResourceStream(filePath);
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return array;
		}

		public static Texture2D GetTextureFromResource(string resourceName)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			byte[] array = ExtractEmbeddedResource(resourceName);
			if (array == null)
			{
				ETGModConsole.Log((object)("No bytes found in " + resourceName), false);
				return null;
			}
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, array);
			((Texture)val).filterMode = (FilterMode)0;
			string text = resourceName.Substring(0, resourceName.LastIndexOf('.'));
			if (text.LastIndexOf('.') >= 0)
			{
				text = text.Substring(text.LastIndexOf('.') + 1);
			}
			((Object)val).name = text;
			return val;
		}

		public static string[] GetResourceNames()
		{
			Assembly callingAssembly = Assembly.GetCallingAssembly();
			string[] manifestResourceNames = callingAssembly.GetManifestResourceNames();
			if (manifestResourceNames == null)
			{
				ETGModConsole.Log((object)"No manifest resources found.", false);
				return null;
			}
			return manifestResourceNames;
		}
	}
	public static class SpriteBuilder
	{
		public static tk2dSpriteCollectionData itemCollection = ((BraveBehaviour)PickupObjectDatabase.GetById(155)).sprite.Collection;

		public static tk2dSpriteCollectionData ammonomiconCollection = AmmonomiconController.ForceInstance.EncounterIconCollection;

		public static tk2dSprite baseSprite = ((Component)PickupObjectDatabase.GetById(155)).GetComponent<tk2dSprite>();

		public static GameObject SpriteFromFile(string spriteName, GameObject obj = null)
		{
			string fileName = spriteName.Replace(".png", "");
			Texture2D textureFromFile = ResourceExtractor.GetTextureFromFile(fileName);
			if ((Object)(object)textureFromFile == (Object)null)
			{
				return null;
			}
			return SpriteFromTexture(textureFromFile, spriteName, obj);
		}

		public static GameObject SpriteFromResource(string spriteName, GameObject obj = null)
		{
			string text = ((!spriteName.EndsWith(".png")) ? ".png" : "");
			string text2 = spriteName + text;
			Texture2D textureFromResource = ResourceExtractor.GetTextureFromResource(text2);
			if ((Object)(object)textureFromResource == (Object)null)
			{
				return null;
			}
			return SpriteFromTexture(textureFromResource, text2, obj);
		}

		public static GameObject SpriteFromTexture(Texture2D texture, string spriteName, GameObject obj = null)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			if ((Object)(object)obj == (Object)null)
			{
				obj = new GameObject();
			}
			tk2dSprite val = obj.AddComponent<tk2dSprite>();
			int num = AddSpriteToCollection(spriteName, itemCollection);
			((tk2dBaseSprite)val).SetSprite(itemCollection, num);
			((tk2dBaseSprite)val).SortingOrder = 0;
			((tk2dBaseSprite)val).IsPerpendicular = true;
			obj.GetComponent<BraveBehaviour>().sprite = (tk2dBaseSprite)(object)val;
			return obj;
		}

		public static int AddSpriteToCollection(string resourcePath, tk2dSpriteCollectionData collection, string shaderName = null)
		{
			string text = ((!resourcePath.EndsWith(".png")) ? ".png" : "");
			resourcePath += text;
			Texture2D textureFromResource = ResourceExtractor.GetTextureFromResource(resourcePath);
			tk2dSpriteDefinition val = ConstructDefinition(textureFromResource, shaderName);
			val.name = ((Object)textureFromResource).name;
			return AddSpriteToCollection(val, collection);
		}

		public static int AddSpriteToCollection(tk2dSpriteDefinition spriteDefinition, tk2dSpriteCollectionData collection)
		{
			tk2dSpriteDefinition[] spriteDefinitions = collection.spriteDefinitions;
			tk2dSpriteDefinition[] array = (collection.spriteDefinitions = spriteDefinitions.Concat((IEnumerable<tk2dSpriteDefinition>)(object)new tk2dSpriteDefinition[1] { spriteDefinition }).ToArray());
			FieldInfo field = typeof(tk2dSpriteCollectionData).GetField("spriteNameLookupDict", BindingFlags.Instance | BindingFlags.NonPublic);
			field.SetValue(collection, null);
			collection.InitDictionary();
			return array.Length - 1;
		}

		public static int AddToAmmonomicon(tk2dSpriteDefinition spriteDefinition)
		{
			return AddSpriteToCollection(spriteDefinition, ammonomiconCollection);
		}

		public static tk2dSpriteAnimationClip AddAnimation(tk2dSpriteAnimator animator, tk2dSpriteCollectionData collection, List<int> spriteIDs, string clipName, WrapMode wrapMode = 0)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			if ((Object)(object)animator.Library == (Object)null)
			{
				animator.Library = ((Component)animator).gameObject.AddComponent<tk2dSpriteAnimation>();
				animator.Library.clips = (tk2dSpriteAnimationClip[])(object)new tk2dSpriteAnimationClip[0];
				((Behaviour)animator.Library).enabled = true;
			}
			List<tk2dSpriteAnimationFrame> list = new List<tk2dSpriteAnimationFrame>();
			for (int i = 0; i < spriteIDs.Count; i++)
			{
				tk2dSpriteDefinition val = collection.spriteDefinitions[spriteIDs[i]];
				if (val.Valid)
				{
					list.Add(new tk2dSpriteAnimationFrame
					{
						spriteCollection = collection,
						spriteId = spriteIDs[i]
					});
				}
			}
			tk2dSpriteAnimationClip val2 = new tk2dSpriteAnimationClip();
			val2.name = clipName;
			val2.fps = 15f;
			val2.wrapMode = wrapMode;
			Array.Resize(ref animator.Library.clips, animator.Library.clips.Length + 1);
			animator.Library.clips[animator.Library.clips.Length - 1] = val2;
			val2.frames = list.ToArray();
			return val2;
		}

		public static SpeculativeRigidbody SetUpSpeculativeRigidbody(this tk2dSprite sprite, IntVector2 offset, IntVector2 dimensions)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0015: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			SpeculativeRigidbody orAddComponent = GameObjectExtensions.GetOrAddComponent<SpeculativeRigidbody>(((Component)sprite).gameObject);
			PixelCollider val = new PixelCollider();
			val.ColliderGenerationMode = (PixelColliderGeneration)0;
			val.CollisionLayer = (CollisionLayer)3;
			val.ManualWidth = dimensions.x;
			val.ManualHeight = dimensions.y;
			val.ManualOffsetX = offset.x;
			val.ManualOffsetY = offset.y;
			orAddComponent.PixelColliders = new List<PixelCollider> { val };
			return orAddComponent;
		}

		public static tk2dSpriteDefinition ConstructDefinition(Texture2D texture, string shaderName = null)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			RuntimeAtlasSegment val = Assets.Packer.Pack(texture, false);
			Material val2 = new Material(ShaderCache.Acquire(shaderName ?? PlayerController.DefaultShaderName));
			val2.mainTexture = (Texture)(object)val.texture;
			int width = ((Texture)texture).width;
			int height = ((Texture)texture).height;
			float num = 0f;
			float num2 = 0f;
			float num3 = (float)width / 16f;
			float num4 = (float)height / 16f;
			tk2dSpriteDefinition val3 = new tk2dSpriteDefinition();
			val3.normals = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(0f, 0f, -1f),
				new Vector3(0f, 0f, -1f),
				new Vector3(0f, 0f, -1f),
				new Vector3(0f, 0f, -1f)
			};
			val3.tangents = (Vector4[])(object)new Vector4[4]
			{
				new Vector4(1f, 0f, 0f, 1f),
				new Vector4(1f, 0f, 0f, 1f),
				new Vector4(1f, 0f, 0f, 1f),
				new Vector4(1f, 0f, 0f, 1f)
			};
			val3.texelSize = new Vector2(0.0625f, 0.0625f);
			val3.extractRegion = false;
			val3.regionX = 0;
			val3.regionY = 0;
			val3.regionW = 0;
			val3.regionH = 0;
			val3.flipped = (FlipMode)0;
			val3.complexGeometry = false;
			val3.physicsEngine = (PhysicsEngine)0;
			val3.colliderType = (ColliderType)1;
			val3.collisionLayer = (CollisionLayer)6;
			val3.position0 = new Vector3(num, num2, 0f);
			val3.position1 = new Vector3(num + num3, num2, 0f);
			val3.position2 = new Vector3(num, num2 + num4, 0f);
			val3.position3 = new Vector3(num + num3, num2 + num4, 0f);
			val3.material = val2;
			val3.materialInst = val2;
			val3.materialId = 0;
			val3.uvs = val.uvs;
			val3.boundsDataCenter = new Vector3(num3 / 2f, num4 / 2f, 0f);
			val3.boundsDataExtents = new Vector3(num3, num4, 0f);
			val3.untrimmedBoundsDataCenter = new Vector3(num3 / 2f, num4 / 2f, 0f);
			val3.untrimmedBoundsDataExtents = new Vector3(num3, num4, 0f);
			tk2dSpriteDefinition val4 = val3;
			val4.name = ((Object)texture).name;
			return val4;
		}

		public static tk2dSpriteCollectionData ConstructCollection(GameObject obj, string name)
		{
			tk2dSpriteCollectionData val = obj.AddComponent<tk2dSpriteCollectionData>();
			Object.DontDestroyOnLoad((Object)(object)val);
			val.assetName = name;
			val.spriteCollectionGUID = name;
			val.spriteCollectionName = name;
			val.spriteDefinitions = (tk2dSpriteDefinition[])(object)new tk2dSpriteDefinition[0];
			return val;
		}

		public static T CopyFrom<T>(this Component comp, T other) where T : Component
		{
			Type type = ((object)comp).GetType();
			if ((object)type != ((object)other).GetType())
			{
				return default(T);
			}
			PropertyInfo[] properties = type.GetProperties();
			PropertyInfo[] array = properties;
			foreach (PropertyInfo propertyInfo in array)
			{
				if (propertyInfo.CanWrite)
				{
					try
					{
						propertyInfo.SetValue(comp, propertyInfo.GetValue(other, null), null);
					}
					catch
					{
					}
				}
			}
			FieldInfo[] fields = type.GetFields();
			FieldInfo[] array2 = fields;
			foreach (FieldInfo fieldInfo in array2)
			{
				fieldInfo.SetValue(comp, fieldInfo.GetValue(other));
			}
			return (T)(object)((comp is T) ? comp : null);
		}

		public static void SetColor(this tk2dSprite sprite, Color color)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			((BraveBehaviour)sprite).renderer.material.SetColor("_OverrideColor", color);
		}

		public static T AddComponent<T>(this GameObject go, T toAdd) where T : Component
		{
			return ((Component)(object)go.AddComponent<T>()).CopyFrom(toAdd);
		}
	}
}