Decompiled source of The Ordinary Magician v1.0.6

plugins/OrdinaryMagicianItems/OrdinaryMagicianItems.dll

Decompiled 5 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.Text;
using BepInEx;
using Dungeonator;
using Gungeon;
using ItemAPI;
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("NerfedWitchPistol")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NerfedWitchPistol")]
[assembly: AssemblyCopyright("Copyright ©  2020")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2bbd6f4e-5b13-4f7b-96c7-bac6fe1d355a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ItemAPI
{
	public static class CompanionBuilder
	{
		public enum AnimationType
		{
			Move,
			Idle,
			Fidget,
			Flight,
			Hit,
			Talk,
			Other
		}

		private static GameObject behaviorSpeculatorPrefab;

		public static Dictionary<string, GameObject> companionDictionary = new Dictionary<string, GameObject>();

		public static void Init()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			string companionGuid = ((Component)Game.Items["dog"]).GetComponent<CompanionItem>().CompanionGuid;
			AIActor orLoadByGuid = EnemyDatabase.GetOrLoadByGuid(companionGuid);
			behaviorSpeculatorPrefab = Object.Instantiate<GameObject>(((Component)orLoadByGuid).gameObject);
			foreach (Transform item in behaviorSpeculatorPrefab.transform)
			{
				Transform val = item;
				if ((Object)(object)val != (Object)(object)behaviorSpeculatorPrefab.transform)
				{
					Object.DestroyImmediate((Object)(object)val);
				}
			}
			Component[] components = behaviorSpeculatorPrefab.GetComponents<Component>();
			foreach (Component val2 in components)
			{
				if ((object)((object)val2).GetType() != typeof(BehaviorSpeculator))
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
			Object.DontDestroyOnLoad((Object)(object)behaviorSpeculatorPrefab);
			FakePrefab.MarkAsFakePrefab(behaviorSpeculatorPrefab);
			behaviorSpeculatorPrefab.SetActive(false);
			Hook val3 = new Hook((MethodBase)typeof(EnemyDatabase).GetMethod("GetOrLoadByGuid", BindingFlags.Static | BindingFlags.Public), typeof(CompanionBuilder).GetMethod("GetOrLoadByGuid"));
		}

		public static AIActor GetOrLoadByGuid(Func<string, AIActor> orig, string guid)
		{
			foreach (string key in companionDictionary.Keys)
			{
				if (key == guid)
				{
					return companionDictionary[key].GetComponent<AIActor>();
				}
			}
			return orig(guid);
		}

		public static GameObject BuildPrefab(string name, string guid, string defaultSpritePath, IntVector2 hitboxOffset, IntVector2 hitBoxSize)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			if (companionDictionary.ContainsKey(guid))
			{
				ETGModConsole.Log((object)"CompanionBuilder: Tried to create two companion prefabs with the same GUID!", false);
				return null;
			}
			GameObject val = Object.Instantiate<GameObject>(behaviorSpeculatorPrefab);
			((Object)val).name = name;
			tk2dSprite component = SpriteBuilder.SpriteFromResource(defaultSpritePath, val).GetComponent<tk2dSprite>();
			component.SetUpSpeculativeRigidbody(hitboxOffset, hitBoxSize).CollideWithOthers = false;
			val.AddComponent<tk2dSpriteAnimator>();
			val.AddComponent<AIAnimator>();
			HealthHaver val2 = val.AddComponent<HealthHaver>();
			val2.RegisterBodySprite((tk2dBaseSprite)(object)component, false, 0);
			val2.PreventAllDamage = true;
			val2.SetHealthMaximum(15000f, (float?)null, false);
			val2.FullHeal();
			AIActor val3 = val.AddComponent<AIActor>();
			val3.State = (ActorState)2;
			val3.EnemyGuid = guid;
			BehaviorSpeculator component2 = val.GetComponent<BehaviorSpeculator>();
			component2.MovementBehaviors = new List<MovementBehaviorBase>();
			component2.AttackBehaviors = new List<AttackBehaviorBase>();
			component2.TargetBehaviors = new List<TargetBehaviorBase>();
			component2.OverrideBehaviors = new List<OverrideBehaviorBase>();
			component2.OtherBehaviors = new List<BehaviorBase>();
			EnemyDatabaseEntry item = new EnemyDatabaseEntry
			{
				myGuid = guid,
				placeableWidth = 2,
				placeableHeight = 2,
				isNormalEnemy = false
			};
			((AssetBundleDatabase<AIActor, EnemyDatabaseEntry>)(object)EnemyDatabase.Instance).Entries.Add(item);
			companionDictionary.Add(guid, val);
			Object.DontDestroyOnLoad((Object)(object)val);
			FakePrefab.MarkAsFakePrefab(val);
			val.SetActive(false);
			return val;
		}

		public static tk2dSpriteAnimationClip AddAnimation(this GameObject obj, string name, string spriteDirectory, int fps, AnimationType type, DirectionType directionType = 0, FlipType flipType = 0, bool assign = true)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected I4, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			AIAnimator orAddComponent = GameObjectExtensions.GetOrAddComponent<AIAnimator>(obj);
			DirectionalAnimation val = orAddComponent.GetDirectionalAnimation(name, directionType, type);
			if (val == null)
			{
				DirectionalAnimation val2 = new DirectionalAnimation();
				val2.AnimNames = new string[0];
				val2.Flipped = (FlipType[])(object)new FlipType[0];
				val2.Type = directionType;
				val2.Prefix = string.Empty;
				val = val2;
			}
			val.AnimNames = val.AnimNames.Concat(new string[1] { name }).ToArray();
			val.Flipped = val.Flipped.Concat((IEnumerable<FlipType>)(object)new FlipType[1] { (FlipType)(int)flipType }).ToArray();
			if (assign)
			{
				orAddComponent.AssignDirectionalAnimation(name, val, type);
			}
			return BuildAnimation(orAddComponent, name, spriteDirectory, fps);
		}

		public static tk2dSpriteAnimationClip BuildAnimation(AIAnimator aiAnimator, string name, string spriteDirectory, int fps)
		{
			tk2dSpriteCollectionData val = ((Component)aiAnimator).GetComponent<tk2dSpriteCollectionData>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = SpriteBuilder.ConstructCollection(((Component)aiAnimator).gameObject, ((Object)aiAnimator).name + "_collection");
			}
			string[] resourceNames = ResourceExtractor.GetResourceNames();
			List<int> list = new List<int>();
			for (int i = 0; i < resourceNames.Length; i++)
			{
				if (resourceNames[i].StartsWith(spriteDirectory.Replace('/', '.'), StringComparison.OrdinalIgnoreCase))
				{
					list.Add(SpriteBuilder.AddSpriteToCollection(resourceNames[i], val));
				}
			}
			tk2dSpriteAnimationClip val2 = SpriteBuilder.AddAnimation(((BraveBehaviour)aiAnimator).spriteAnimator, val, list, name, (WrapMode)0);
			val2.fps = fps;
			return val2;
		}

		public static DirectionalAnimation GetDirectionalAnimation(this AIAnimator aiAnimator, string name, DirectionType directionType, AnimationType type)
		{
			DirectionalAnimation val = null;
			switch (type)
			{
			case AnimationType.Idle:
				val = aiAnimator.IdleAnimation;
				break;
			case AnimationType.Move:
				val = aiAnimator.MoveAnimation;
				break;
			case AnimationType.Flight:
				val = aiAnimator.FlightAnimation;
				break;
			case AnimationType.Hit:
				val = aiAnimator.HitAnimation;
				break;
			case AnimationType.Talk:
				val = aiAnimator.TalkAnimation;
				break;
			}
			if (val != null)
			{
				return val;
			}
			return null;
		}

		public static void AssignDirectionalAnimation(this AIAnimator aiAnimator, string name, DirectionalAnimation animation, AnimationType type)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			switch (type)
			{
			case AnimationType.Idle:
				aiAnimator.IdleAnimation = animation;
				return;
			case AnimationType.Move:
				aiAnimator.MoveAnimation = animation;
				return;
			case AnimationType.Flight:
				aiAnimator.FlightAnimation = animation;
				return;
			case AnimationType.Hit:
				aiAnimator.HitAnimation = animation;
				return;
			case AnimationType.Talk:
				aiAnimator.TalkAnimation = animation;
				return;
			case AnimationType.Fidget:
				aiAnimator.IdleFidgetAnimations.Add(animation);
				return;
			}
			if (aiAnimator.OtherAnimations == null)
			{
				aiAnimator.OtherAnimations = new List<NamedDirectionalAnimation>();
			}
			aiAnimator.OtherAnimations.Add(new NamedDirectionalAnimation
			{
				anim = animation,
				name = name
			});
		}
	}
	public static class CustomSynergies
	{
		public static Hook synergyHook = new Hook((MethodBase)typeof(StringTableManager).GetMethod("GetSynergyString", BindingFlags.Static | BindingFlags.Public), typeof(CustomSynergies).GetMethod("SynergyStringHook"));

		public static AdvancedSynergyEntry Add(string name, List<string> mandatoryConsoleIDs, List<string> optionalConsoleIDs = null, bool ignoreLichEyeBullets = true)
		{
			//IL_01bb: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			if (mandatoryConsoleIDs == null || mandatoryConsoleIDs.Count == 0)
			{
				ETGModConsole.Log((object)("Synergy " + name + " has no mandatory items/guns."), false);
				return null;
			}
			List<int> list = new List<int>();
			List<int> list2 = new List<int>();
			List<int> list3 = new List<int>();
			List<int> list4 = new List<int>();
			foreach (string mandatoryConsoleID in mandatoryConsoleIDs)
			{
				PickupObject val = Game.Items[mandatoryConsoleID];
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)((Component)val).GetComponent<Gun>()))
				{
					list2.Add(val.PickupObjectId);
				}
				else if (Object.op_Implicit((Object)(object)val) && (Object.op_Implicit((Object)(object)((Component)val).GetComponent<PlayerItem>()) || Object.op_Implicit((Object)(object)((Component)val).GetComponent<PassiveItem>())))
				{
					list.Add(val.PickupObjectId);
				}
			}
			if (optionalConsoleIDs != null)
			{
				foreach (string optionalConsoleID in optionalConsoleIDs)
				{
					PickupObject val = Game.Items[optionalConsoleID];
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)((Component)val).GetComponent<Gun>()))
					{
						list4.Add(val.PickupObjectId);
					}
					else if (Object.op_Implicit((Object)(object)val) && (Object.op_Implicit((Object)(object)((Component)val).GetComponent<PlayerItem>()) || Object.op_Implicit((Object)(object)((Component)val).GetComponent<PassiveItem>())))
					{
						list3.Add(val.PickupObjectId);
					}
				}
			}
			AdvancedSynergyEntry val2 = new AdvancedSynergyEntry
			{
				NameKey = name,
				MandatoryItemIDs = list,
				MandatoryGunIDs = list2,
				OptionalItemIDs = list3,
				OptionalGunIDs = list4,
				bonusSynergies = new List<CustomSynergyType>(),
				statModifiers = new List<StatModifier>()
			};
			Add(val2);
			return val2;
		}

		public static bool OwnerHasSynergy(this Gun self, string synergyToCheck)
		{
			return Object.op_Implicit((Object)(object)self.CurrentOwner) && self.CurrentOwner is PlayerController && ((PlayerController)/*isinst with value type is only supported in some contexts*/).PlayerHasActiveSynergy(synergyToCheck);
		}

		public static bool PlayerHasActiveSynergy(this PlayerController player, string synergyNameToCheck)
		{
			foreach (int activeExtraSynergy in player.ActiveExtraSynergies)
			{
				AdvancedSynergyEntry val = GameManager.Instance.SynergyManager.synergies[activeExtraSynergy];
				if (val.NameKey == synergyNameToCheck)
				{
					return true;
				}
			}
			return false;
		}

		public static void Add(AdvancedSynergyEntry synergyEntry)
		{
			AdvancedSynergyEntry[] second = (AdvancedSynergyEntry[])(object)new AdvancedSynergyEntry[1] { synergyEntry };
			GameManager.Instance.SynergyManager.synergies = GameManager.Instance.SynergyManager.synergies.Concat(second).ToArray();
		}

		public static string SynergyStringHook(Func<string, int, string> orig, string key, int index = -1)
		{
			string text = orig(key, index);
			if (string.IsNullOrEmpty(text))
			{
				text = key;
			}
			return text;
		}

		public static bool HasMTGConsoleID(this PlayerController player, string consoleID)
		{
			if (!Game.Items.ContainsID(consoleID))
			{
				return false;
			}
			return player.HasPickupID(Game.Items[consoleID].PickupObjectId);
		}
	}
	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();
			CompanionBuilder.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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			string text = resourceName;
			text = text.Replace("/", ".");
			text = text.Replace("\\", ".");
			byte[] array = ExtractEmbeddedResource(text);
			if (array == null)
			{
				ETGModConsole.Log((object)("No bytes found in " + text), false);
				return null;
			}
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, array);
			((Texture)val).filterMode = (FilterMode)0;
			string text2 = text.Substring(0, text.LastIndexOf('.'));
			if (text2.LastIndexOf('.') >= 0)
			{
				text2 = text2.Substring(text2.LastIndexOf('.') + 1);
			}
			((Object)val).name = text2;
			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
	{
		private static tk2dSpriteCollectionData itemCollection = ((BraveBehaviour)PickupObjectDatabase.GetById(155)).sprite.Collection;

		private static tk2dSpriteCollectionData ammonomiconCollection = AmmonomiconController.ForceInstance.EncounterIconCollection;

		private 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 text = ((!resourcePath.EndsWith(".png")) ? ".png" : "");
			resourcePath += text;
			Texture2D textureFromResource = ResourceExtractor.GetTextureFromResource(resourcePath);
			tk2dSpriteDefinition val = ConstructDefinition(textureFromResource);
			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)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00b1: 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_00cc: 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_00fa: 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_011a: 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_013a: 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_015a: 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_0176: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: 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_01f3: 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_020b: 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_0226: 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_026c: 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_0281: 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_02a2: 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_02b7: 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)
			RuntimeAtlasSegment val = Assets.Packer.Pack(texture, false);
			Material val2 = new Material(ShaderCache.Acquire(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);
		}
	}
}
namespace OrdinaryMagicianItems
{
	public class Broom : PlayerItem
	{
		public GameObject prefabToAttachToPlayer;

		private GameObject instanceAttachment;

		private tk2dBaseSprite instanceAttachmentSprite;

		private bool m_callbacksInitialized;

		public static PlayerController CurrentBuyingPlayer;

		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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: 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_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Expected O, but got Unknown
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Expected O, but got Unknown
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Expected O, but got Unknown
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			string text = "Ordinary Broom";
			string resourcePath = "OrdinaryMagicianItems/Resources/broom";
			GameObject val = new GameObject(text);
			Broom broom = val.AddComponent<Broom>();
			ItemBuilder.AddSpriteToObject(text, resourcePath, val);
			string shortDesc = "Aesthetics Matter";
			string longDesc = "Grants flight until you hop off.\nAllows to steal in plain sight and run for your life.\n\nThis is a completely normal broom with no special properties whatsoever.\nSweeping dust is a broom's most common use, but this one in particular is used by a certain Ordinary Magician in order to fly.\nAccording to her, though, she doesn't actually need the broom to fly, and simply uses it during flight for aesthetic purposes.";
			((PickupObject)(object)broom).SetupItem(shortDesc, longDesc, "spapi");
			((PlayerItem)(object)broom).SetCooldownType(ItemBuilder.CooldownType.Timed, 1f);
			((PlayerItem)broom).consumable = false;
			((PickupObject)broom).quality = (ItemQuality)(-50);
			Hook val2 = new Hook((MethodBase)typeof(BaseShopController).GetMethod("AttemptToSteal"), typeof(Broom).GetMethod("StealAttemptHook"));
			Hook val3 = new Hook((MethodBase)typeof(ShopItemController).GetMethod("Interact"), typeof(Broom).GetMethod("ShopItemInteractHook"));
			GameObject val4 = new GameObject("BroomAttachment");
			ItemBuilder.AddSpriteToObject(((Object)val4).name, "OrdinaryMagicianItems/Resources/broom_obj/broom_front", val4);
			Object.DontDestroyOnLoad((Object)(object)val4);
			tk2dBaseSprite component = val4.GetComponent<tk2dBaseSprite>();
			tk2dSpriteAnimator val5 = val4.AddComponent<tk2dSpriteAnimator>();
			val5.Library = val4.AddComponent<tk2dSpriteAnimation>();
			List<int> list = new List<int>
			{
				component.spriteId,
				SpriteBuilder.AddSpriteToCollection("OrdinaryMagicianItems/Resources/broom_obj/broom_back", component.Collection),
				SpriteBuilder.AddSpriteToCollection("OrdinaryMagicianItems/Resources/broom_obj/broom_front_left", component.Collection),
				SpriteBuilder.AddSpriteToCollection("OrdinaryMagicianItems/Resources/broom_obj/broom_front_right", component.Collection),
				SpriteBuilder.AddSpriteToCollection("OrdinaryMagicianItems/Resources/broom_obj/broom_back_right", component.Collection),
				SpriteBuilder.AddSpriteToCollection("OrdinaryMagicianItems/Resources/broom_obj/broom_back_left", component.Collection)
			};
			List<tk2dSpriteAnimationClip> list2 = new List<tk2dSpriteAnimationClip>();
			foreach (int item2 in list)
			{
				tk2dSpriteDefinition val6 = component.Collection.spriteDefinitions[item2];
				Vector2 val7 = (Vector2)((val6.name == "broom_back_left") ? new Vector2(0f, -0.0625f) : Vector2.zero);
				MagicianPistol.ConstructOffsetsFromAnchor(val6, (Anchor)4, null, fixesScale: false, changesCollider: false);
				MagicianPistol.MakeOffset(val6, val7);
				int num = SpriteBuilder.AddSpriteToCollection("OrdinaryMagicianItems/Resources/broom_obj/" + val6.name + "2", component.Collection);
				tk2dSpriteDefinition def = component.Collection.spriteDefinitions[num];
				MagicianPistol.ConstructOffsetsFromAnchor(def, (Anchor)4, null, fixesScale: false, changesCollider: false);
				MagicianPistol.MakeOffset(def, val7 + new Vector2(0f, -0.0625f));
				tk2dSpriteAnimationFrame val8 = new tk2dSpriteAnimationFrame
				{
					spriteId = item2,
					spriteCollection = component.Collection
				};
				tk2dSpriteAnimationFrame val9 = new tk2dSpriteAnimationFrame
				{
					spriteId = num,
					spriteCollection = component.Collection
				};
				tk2dSpriteAnimationClip val10 = new tk2dSpriteAnimationClip();
				val10.fps = 6f;
				val10.frames = (tk2dSpriteAnimationFrame[])(object)new tk2dSpriteAnimationFrame[2] { val8, val9 };
				val10.loopStart = 0;
				val10.maxFidgetDuration = 0f;
				val10.minFidgetDuration = 0f;
				val10.name = val6.name;
				val10.wrapMode = (WrapMode)0;
				tk2dSpriteAnimationClip item = val10;
				list2.Add(item);
			}
			val5.Library.clips = list2.ToArray();
			broom.prefabToAttachToPlayer = val4;
		}

		public void InitializeCallbacks(PlayerController player)
		{
			player.OnEnteredCombat = (Action)Delegate.Combine(player.OnEnteredCombat, new Action(OnCombatEntered));
			player.OnUsedBlank += Shoot;
			m_callbacksInitialized = true;
		}

		public void DeinitializeCallbacks(PlayerController player)
		{
			player.OnEnteredCombat = (Action)Delegate.Remove(player.OnEnteredCombat, new Action(OnCombatEntered));
			player.OnUsedBlank -= Shoot;
			m_callbacksInitialized = false;
		}

		public void Shoot(PlayerController player, int i)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			if (player.PlayerHasActiveSynergy("Incident-Resolver kit"))
			{
				GameObject val = SpawnManager.SpawnProjectile(((Component)((Component)PickupObjectDatabase.GetById(508)).GetComponent<Gun>().DefaultModule.projectiles[0]).gameObject, Vector2.op_Implicit(((BraveBehaviour)player).specRigidbody.UnitCenter), Quaternion.Euler(0f, 0f, ((GameActor)player).FacingDirection), true);
				Projectile component = val.GetComponent<Projectile>();
				if ((Object)(object)component != (Object)null)
				{
					component.Owner = (GameActor)(object)player;
					component.Shooter = ((BraveBehaviour)player).specRigidbody;
				}
			}
		}

		public void OnCombatEntered()
		{
			if (!((PlayerItem)this).PickedUp || !((Object)(object)base.LastOwner != (Object)null) || base.LastOwner.CurrentRoom == null || base.LastOwner.CurrentRoom.GetActiveEnemies((ActiveEnemyType)0) == null || !base.LastOwner.PlayerHasActiveSynergy("Incident-Resolver kit"))
			{
				return;
			}
			foreach (AIActor activeEnemy in base.LastOwner.CurrentRoom.GetActiveEnemies((ActiveEnemyType)1))
			{
				if (!((Object)(object)activeEnemy != (Object)null) || !((Object)(object)((BraveBehaviour)activeEnemy).healthHaver != (Object)null) || !((BraveBehaviour)activeEnemy).healthHaver.IsBoss)
				{
					continue;
				}
				LootEngine.GivePrefabToPlayer(((Component)PickupObjectDatabase.GetById(GlobalItemIds.Blank)).gameObject, base.LastOwner);
				LootEngine.GivePrefabToPlayer(((Component)PickupObjectDatabase.GetById(GlobalItemIds.SmallHeart)).gameObject, base.LastOwner);
				{
					foreach (PlayerItem activeItem in base.LastOwner.activeItems)
					{
						activeItem.DidDamage(base.LastOwner, 100f);
					}
					break;
				}
			}
		}

		public static void ShopItemInteractHook(Action<ShopItemController, PlayerController> orig, ShopItemController self, PlayerController player)
		{
			CurrentBuyingPlayer = player;
			orig(self, player);
			CurrentBuyingPlayer = null;
		}

		public static bool StealAttemptHook(Func<BaseShopController, bool> orig, BaseShopController self)
		{
			if ((Object)(object)CurrentBuyingPlayer != (Object)null && PassiveItem.IsFlagSetForCharacter(CurrentBuyingPlayer, typeof(Broom)))
			{
				self.NotifyStealFailed();
				return true;
			}
			return orig(self);
		}

		public override void DoEffect(PlayerController user)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			if ((int)GameManager.Instance.CurrentLevelOverrideState != 4)
			{
				((PlayerItem)this).IsCurrentlyActive = true;
				((GameActor)user).SetIsFlying(true, "broom", true, false);
				user.AdditionalCanDodgeRollWhileFlying.SetOverride("broom", true, (float?)null);
				user.SetCapableOfStealing(true, "broom", (float?)null);
				PassiveItem.IncrementFlag(user, typeof(Broom));
				instanceAttachment = user.RegisterAttachedObject(prefabToAttachToPlayer, "", 0f);
				instanceAttachmentSprite = (tk2dBaseSprite)(object)instanceAttachment.GetComponent<tk2dSprite>();
			}
		}

		public void LateUpdate()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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)
			if (Object.op_Implicit((Object)(object)instanceAttachment) && ((PlayerItem)this).PickedUp && Object.op_Implicit((Object)(object)base.LastOwner))
			{
				instanceAttachment.transform.position = Vector2.op_Implicit(((BraveBehaviour)base.LastOwner).sprite.WorldCenter + new Vector2(0f, -0.5f));
				instanceAttachmentSprite.UpdateZDepth();
			}
		}

		protected void Deactivate(PlayerController user)
		{
			((PlayerItem)this).IsCurrentlyActive = false;
			((GameActor)user).SetIsFlying(false, "broom", true, false);
			user.AdditionalCanDodgeRollWhileFlying.RemoveOverride("broom");
			user.SetCapableOfStealing(false, "broom", (float?)null);
			PassiveItem.DecrementFlag(user, typeof(Broom));
			user.DeregisterAttachedObject(instanceAttachment, true);
			instanceAttachmentSprite = null;
			user.stats.RecalculateStats(user, false, false);
		}

		public override void Update()
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Invalid comparison between Unknown and I4
			((PlayerItem)this).Update();
			if (((PlayerItem)this).PickedUp && !m_callbacksInitialized)
			{
				InitializeCallbacks(base.LastOwner);
			}
			if (((PlayerItem)this).IsCurrentlyActive)
			{
				string text = base.LastOwner.GetBaseAnimationSuffix(false);
				if (text.EndsWith("_right") && ((BraveBehaviour)base.LastOwner).sprite.FlipX)
				{
					text = text.Substring(0, text.LastIndexOf('_')) + "_left";
				}
				if ((Object)(object)instanceAttachment != (Object)null && (Object)(object)((BraveBehaviour)instanceAttachmentSprite).spriteAnimator != (Object)null && !((BraveBehaviour)instanceAttachmentSprite).spriteAnimator.IsPlaying("broom" + text))
				{
					((BraveBehaviour)instanceAttachmentSprite).spriteAnimator.Play("broom" + text);
				}
				if ((int)GameManager.Instance.CurrentLevelOverrideState == 4 || ((Object)(object)base.LastOwner != (Object)null && base.LastOwner.IsDodgeRolling))
				{
					Deactivate(base.LastOwner);
				}
			}
		}

		public override void OnPreDrop(PlayerController user)
		{
			if (((PlayerItem)this).IsCurrentlyActive)
			{
				Deactivate(user);
			}
			if (m_callbacksInitialized)
			{
				DeinitializeCallbacks(user);
			}
		}

		public override void OnItemSwitched(PlayerController user)
		{
			if (((PlayerItem)this).IsCurrentlyActive)
			{
				Deactivate(user);
			}
		}

		public override void OnDestroy()
		{
			((PlayerItem)this).OnDestroy();
			if ((Object)(object)base.LastOwner != (Object)null && m_callbacksInitialized)
			{
				DeinitializeCallbacks(base.LastOwner);
			}
		}

		public override bool CanBeUsed(PlayerController user)
		{
			return ((PlayerItem)this).CanBeUsed(user) && !user.IsDodgeRolling;
		}
	}
	public class AdvancedAmmoRegenSynergyProcessor : MonoBehaviour
	{
		public string RequiredSynergy;

		public float AmmoPerSecond;

		public bool PreventGainWhileFiring;

		private Gun m_gun;

		private float m_ammoCounter;

		private float m_gameTimeOnDisable;

		public AdvancedAmmoRegenSynergyProcessor()
		{
			AmmoPerSecond = 0.1f;
			PreventGainWhileFiring = true;
		}

		public void Awake()
		{
			m_gun = ((Component)this).GetComponent<Gun>();
		}

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)m_gun.CurrentOwner) && m_gun.OwnerHasSynergy(RequiredSynergy) && (!PreventGainWhileFiring || !m_gun.IsFiring))
			{
				m_ammoCounter += BraveTime.DeltaTime * AmmoPerSecond;
				if (m_ammoCounter > 1f)
				{
					int num = Mathf.FloorToInt(m_ammoCounter);
					m_ammoCounter -= num;
					m_gun.GainAmmo(num);
				}
			}
		}

		public void OnEnable()
		{
			if (m_gameTimeOnDisable > 0f)
			{
				m_ammoCounter += (Time.time - m_gameTimeOnDisable) * AmmoPerSecond;
				m_gameTimeOnDisable = 0f;
			}
		}

		public void OnDisable()
		{
			m_gameTimeOnDisable = Time.time;
		}
	}
	public class AdvancedDualWieldSynergyProcessor : MonoBehaviour
	{
		public string SynergyNameToCheck;

		public int PartnerGunID;

		private Gun m_gun;

		private bool m_isCurrentlyActive;

		private PlayerController m_cachedPlayer;

		public void Awake()
		{
			m_gun = ((Component)this).GetComponent<Gun>();
		}

		private bool EffectValid(PlayerController p)
		{
			if (!Object.op_Implicit((Object)(object)p))
			{
				return false;
			}
			if (!p.HasPickupID(PartnerGunID))
			{
				return false;
			}
			if (m_gun.CurrentAmmo == 0)
			{
				return false;
			}
			if (p.inventory.GunLocked.Value)
			{
				return false;
			}
			if (!m_isCurrentlyActive)
			{
				int indexForGun = GetIndexForGun(p, PartnerGunID);
				if (indexForGun < 0)
				{
					return false;
				}
				if (p.inventory.AllGuns[indexForGun].CurrentAmmo == 0)
				{
					return false;
				}
			}
			else if ((Object)(object)p.CurrentSecondaryGun != (Object)null && ((PickupObject)p.CurrentSecondaryGun).PickupObjectId == PartnerGunID && p.CurrentSecondaryGun.CurrentAmmo == 0)
			{
				return false;
			}
			return true;
		}

		private bool PlayerUsingCorrectGuns()
		{
			return Object.op_Implicit((Object)(object)m_gun) && Object.op_Implicit((Object)(object)m_gun.CurrentOwner) && Object.op_Implicit((Object)(object)m_cachedPlayer) && m_cachedPlayer.inventory.DualWielding && m_cachedPlayer.HasPickupID(PartnerGunID) && (!((Object)(object)((GameActor)m_cachedPlayer).CurrentGun != (Object)(object)m_gun) || ((PickupObject)((GameActor)m_cachedPlayer).CurrentGun).PickupObjectId == PartnerGunID) && (!((Object)(object)m_cachedPlayer.CurrentSecondaryGun != (Object)(object)m_gun) || ((PickupObject)m_cachedPlayer.CurrentSecondaryGun).PickupObjectId == PartnerGunID);
		}

		public void Update()
		{
			CheckStatus();
		}

		private void CheckStatus()
		{
			if (m_isCurrentlyActive)
			{
				if (!PlayerUsingCorrectGuns() || !EffectValid(m_cachedPlayer))
				{
					DisableEffect();
				}
			}
			else if (Object.op_Implicit((Object)(object)m_gun) && m_gun.CurrentOwner is PlayerController)
			{
				GameActor currentOwner = m_gun.CurrentOwner;
				PlayerController val = (PlayerController)(object)((currentOwner is PlayerController) ? currentOwner : null);
				if (val.inventory.DualWielding && ((PickupObject)val.CurrentSecondaryGun).PickupObjectId == ((PickupObject)m_gun).PickupObjectId && ((PickupObject)((GameActor)val).CurrentGun).PickupObjectId == PartnerGunID)
				{
					m_isCurrentlyActive = true;
					m_cachedPlayer = val;
				}
				else
				{
					AttemptActivation(val);
				}
			}
		}

		private void AttemptActivation(PlayerController ownerPlayer)
		{
			if (!EffectValid(ownerPlayer))
			{
				return;
			}
			m_isCurrentlyActive = true;
			m_cachedPlayer = ownerPlayer;
			ownerPlayer.inventory.SetDualWielding(true, "synergy");
			int indexForGun = GetIndexForGun(ownerPlayer, ((PickupObject)m_gun).PickupObjectId);
			int indexForGun2 = GetIndexForGun(ownerPlayer, PartnerGunID);
			ownerPlayer.inventory.SwapDualGuns();
			if (indexForGun >= 0 && indexForGun2 >= 0)
			{
				while (((PickupObject)ownerPlayer.inventory.CurrentGun).PickupObjectId != PartnerGunID)
				{
					ownerPlayer.inventory.ChangeGun(1, false, false);
				}
			}
			ownerPlayer.inventory.SwapDualGuns();
			if (Object.op_Implicit((Object)(object)((GameActor)ownerPlayer).CurrentGun) && !((Component)((GameActor)ownerPlayer).CurrentGun).gameObject.activeSelf)
			{
				((Component)((GameActor)ownerPlayer).CurrentGun).gameObject.SetActive(true);
			}
			if (Object.op_Implicit((Object)(object)ownerPlayer.CurrentSecondaryGun) && !((Component)ownerPlayer.CurrentSecondaryGun).gameObject.activeSelf)
			{
				((Component)ownerPlayer.CurrentSecondaryGun).gameObject.SetActive(true);
			}
			m_cachedPlayer.GunChanged += HandleGunChanged;
		}

		private int GetIndexForGun(PlayerController p, int gunID)
		{
			for (int i = 0; i < p.inventory.AllGuns.Count; i++)
			{
				if (((PickupObject)p.inventory.AllGuns[i]).PickupObjectId == gunID)
				{
					return i;
				}
			}
			return -1;
		}

		private void HandleGunChanged(Gun arg1, Gun newGun, bool arg3)
		{
			CheckStatus();
		}

		private void DisableEffect()
		{
			if (m_isCurrentlyActive)
			{
				m_isCurrentlyActive = false;
				m_cachedPlayer.inventory.SetDualWielding(false, "synergy");
				m_cachedPlayer.GunChanged -= HandleGunChanged;
				m_cachedPlayer.stats.RecalculateStats(m_cachedPlayer, false, false);
				m_cachedPlayer = null;
			}
		}
	}
	public class ChangeReloadSpeedSynergyProcessor : MonoBehaviour
	{
		public float SynergyReloadTime;

		public string RequiredSynergy;

		private bool m_processed;

		private Gun m_gun;

		private float m_cachedReloadTime;

		public void Awake()
		{
			m_gun = ((Component)this).GetComponent<Gun>();
		}

		public void Update()
		{
			bool flag = Object.op_Implicit((Object)(object)m_gun) && m_gun.OwnerHasSynergy(RequiredSynergy);
			if (flag && !m_processed)
			{
				m_processed = true;
				m_cachedReloadTime = m_gun.reloadTime;
				m_gun.reloadTime = SynergyReloadTime;
			}
			else if (!flag && m_processed)
			{
				m_processed = false;
				m_gun.reloadTime = m_cachedReloadTime;
			}
		}
	}
	public class MiniHakkero : GunBehaviour
	{
		public string lastIdleAnimation;

		public string normalIdleAnimation;

		public string idle2Animation;

		public static void Init()
		{
			//IL_00f6: 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)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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)
			Gun val = Databases.Items.NewGun("Mini-Hakkero", "mini_hakkero");
			Game.Items.Rename("outdated_gun_mods:minihakkero", "spapi:mini_hakkero");
			MiniHakkero miniHakkero = ((Component)val).gameObject.AddComponent<MiniHakkero>();
			GunExt.SetShortDescription((PickupObject)(object)val, "It's all about firepower!");
			GunExt.SetLongDescription((PickupObject)(object)val, "Made by a master smith and forged with the mythical hihi'irokane metal, this Magic Furnace takes the form of an octagonal block of wood with the eight Taoist trigrams inscribed on the front.\n\nIt allows its' wielder to channel and amplify their magic energy into a beam of destructive power.");
			GunExt.SetupSprite(val, (tk2dSpriteCollectionData)null, "mini_hakkero_idle2_001", 8);
			GunExt.SetAnimationFPS(val, val.idleAnimation, 8);
			PickupObject byId = PickupObjectDatabase.GetById(508);
			GunExt.AddProjectileModuleFrom(val, (Gun)(object)((byId is Gun) ? byId : null), true, false);
			PickupObject byId2 = PickupObjectDatabase.GetById(508);
			Gun val2 = (Gun)(object)((byId2 is Gun) ? byId2 : null);
			val.UsesRechargeLikeActiveItem = true;
			val.ActiveItemStyleRechargeAmount = val2.ActiveItemStyleRechargeAmount;
			val.reloadTime = 1.6f;
			miniHakkero.idle2Animation = GunExt.UpdateAnimation(val, "idle2", (tk2dSpriteCollectionData)null, false);
			miniHakkero.normalIdleAnimation = GunExt.UpdateAnimation(val, "idle", (tk2dSpriteCollectionData)null, false);
			val.InfiniteAmmo = true;
			val.gunSwitchGroup = "ChargeLaser";
			Transform transform = ((Component)val.barrelOffset).transform;
			transform.localPosition += new Vector3(-0.55f, -0.16f, 0f);
			((PickupObject)val).quality = (ItemQuality)(-50);
			val.gunClass = (GunClass)1;
			Databases.Items.Add(val, (tk2dSpriteCollectionData)null, "ANY");
		}

		public override void Update()
		{
			((GunBehaviour)this).Update();
			if (base.gun.RemainingActiveCooldownAmount <= 0f || base.gun.OwnerHasSynergy("Cheat against the Impossible"))
			{
				base.gun.idleAnimation = normalIdleAnimation;
			}
			else
			{
				base.gun.idleAnimation = idle2Animation;
			}
			if (lastIdleAnimation != base.gun.idleAnimation)
			{
				base.gun.PlayIdleAnimation();
			}
			if (base.gun.OwnerHasSynergy("Cheat against the Impossible"))
			{
				base.gun.RemainingActiveCooldownAmount = Mathf.Max(0f, base.gun.RemainingActiveCooldownAmount - 10f * BraveTime.DeltaTime);
			}
			lastIdleAnimation = base.gun.idleAnimation;
		}

		public void LateUpdate()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			tk2dBaseSprite sprite = base.gun.GetSprite();
			float num = base.gun.CurrentAngle;
			if (base.gun.CurrentOwner is PlayerController)
			{
				GameActor currentOwner = base.gun.CurrentOwner;
				PlayerController val = (PlayerController)(object)((currentOwner is PlayerController) ? currentOwner : null);
				num = BraveMathCollege.Atan2Degrees(Vector3Extensions.XY(val.unadjustedAimPoint) - Vector3Extensions.XY(((BraveBehaviour)base.gun).transform.parent.position));
			}
			int num2 = BraveMathCollege.AngleToOctant(num + 90f);
			if (num2 == 1 || num2 == 2 || num2 == 3)
			{
				sprite.HeightOffGround = 0.075f;
			}
			else
			{
				sprite.HeightOffGround = -0.075f;
			}
			sprite.UpdateZDepth();
		}
	}
	public class Shanghai : PassiveItem
	{
		public string CompanionGuid;

		private Coroutine m_currentTimeSlow;

		public bool UsesAlternatePastPrefab;

		public string CompanionPastGuid;

		public CompanionTransformSynergy[] Synergies;

		public bool PreventRespawnOnFloorLoad;

		public bool HasGunTransformationSacrificeSynergy;

		public CustomSynergyType GunTransformationSacrificeSynergy;

		public int SacrificeGunID;

		public float SacrificeGunDuration;

		public bool BabyGoodMimicOrbitalOverridden;

		public PlayerOrbitalItem OverridePlayerOrbitalItem;

		private int m_lastActiveSynergyTransformation;

		private GameObject m_extantCompanion;

		public static GameObject prefab;

		public GameObject ExtantCompanion => m_extantCompanion;

		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)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			string text = "Shanghai";
			string resourcePath = "OrdinaryMagicianItems/Resources/shanghai_ammonomicon_icon";
			GameObject val = new GameObject(text);
			Shanghai shanghai = val.AddComponent<Shanghai>();
			ItemBuilder.AddSpriteToObject(text, resourcePath, val);
			string shortDesc = "The Precious Thing";
			string longDesc = "A little sentient doll. No, it's not yours.\nWhen in danger, it will start following you around and will attack enemies.\nAlice won't forgive you if you lose it.";
			((PickupObject)(object)shanghai).SetupItem(shortDesc, longDesc, "spapi");
			((PickupObject)shanghai).quality = (ItemQuality)(-50);
			shanghai.CompanionGuid = "shanghai";
			shanghai.Synergies = (CompanionTransformSynergy[])(object)new CompanionTransformSynergy[0];
			shanghai.CompanionPastGuid = "";
			shanghai.UsesAlternatePastPrefab = false;
			shanghai.PreventRespawnOnFloorLoad = false;
			shanghai.HasGunTransformationSacrificeSynergy = false;
			shanghai.GunTransformationSacrificeSynergy = (CustomSynergyType)122;
			shanghai.SacrificeGunID = -1;
			shanghai.SacrificeGunDuration = 0f;
			shanghai.BabyGoodMimicOrbitalOverridden = false;
			shanghai.OverridePlayerOrbitalItem = null;
			BuildPrefab();
		}

		public static void BuildPrefab()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Expected O, but got Unknown
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Expected O, but got Unknown
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: 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_03f5: Expected O, but got Unknown
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Expected O, but got Unknown
			if ((Object)(object)prefab == (Object)null && !CompanionBuilder.companionDictionary.ContainsKey("shanghai"))
			{
				prefab = CompanionBuilder.BuildPrefab("Shanghai", "shanghai", "OrdinaryMagicianItems/Resources/companion/idle_right/shanghai_idle_front_right_001", new IntVector2(9, 3), new IntVector2(8, 12));
				CompanionController val = prefab.AddComponent<CompanionController>();
				PixelCollider item = new PixelCollider
				{
					ColliderGenerationMode = (PixelColliderGeneration)0,
					CollisionLayer = (CollisionLayer)2,
					ManualWidth = 8,
					ManualHeight = 12,
					ManualOffsetX = 9,
					ManualOffsetY = 3
				};
				((BraveBehaviour)val).aiActor.IsNormalEnemy = false;
				val.CanInterceptBullets = false;
				((BraveBehaviour)val).specRigidbody.PixelColliders.Add(item);
				((BraveBehaviour)val).specRigidbody.CollideWithOthers = true;
				((BraveBehaviour)val).aiActor.CollisionDamage = 0f;
				((BraveBehaviour)val).aiActor.MovementSpeed = 7.2f;
				((BraveBehaviour)val).aiActor.HitByEnemyBullets = false;
				((BraveBehaviour)val).aiActor.CanDropCurrency = false;
				prefab.AddAnimation("idle_right", "OrdinaryMagicianItems/Resources/companion/idle_right", 6, CompanionBuilder.AnimationType.Idle, (DirectionType)2, (FlipType)0);
				prefab.AddAnimation("idle_left", "OrdinaryMagicianItems/Resources/companion/idle_left", 6, CompanionBuilder.AnimationType.Idle, (DirectionType)2, (FlipType)0);
				prefab.AddAnimation("run_right", "OrdinaryMagicianItems/Resources/companion/run_right", 6, CompanionBuilder.AnimationType.Move, (DirectionType)2, (FlipType)0);
				prefab.AddAnimation("run_left", "OrdinaryMagicianItems/Resources/companion/run_left", 6, CompanionBuilder.AnimationType.Move, (DirectionType)2, (FlipType)0);
				tk2dSpriteCollectionData val2 = ((Component)val).GetComponent<tk2dSpriteCollectionData>();
				if (!Object.op_Implicit((Object)(object)val2))
				{
					val2 = SpriteBuilder.ConstructCollection(((Component)val).gameObject, ((Object)val).name + "_collection");
				}
				List<string> list = new List<string> { "OrdinaryMagicianItems/Resources/companion/attack_left/shanghai_attack_front_left_001", "OrdinaryMagicianItems/Resources/companion/attack_left/shanghai_attack_front_left_002", "OrdinaryMagicianItems/Resources/companion/attack_left/shanghai_attack_front_left_003", "OrdinaryMagicianItems/Resources/companion/attack_left/shanghai_attack_front_left_004", "OrdinaryMagicianItems/Resources/companion/attack_left/shanghai_attack_front_left_005", "OrdinaryMagicianItems/Resources/companion/attack_left/shanghai_attack_front_left_006" };
				List<int> list2 = new List<int>();
				for (int i = 0; i < list.Count; i++)
				{
					list2.Add(SpriteBuilder.AddSpriteToCollection(list[i], val2));
				}
				tk2dSpriteAnimationClip val3 = SpriteBuilder.AddAnimation(((BraveBehaviour)val).spriteAnimator, val2, list2, "attack_left", (WrapMode)2);
				val3.fps = 6f;
				List<string> list3 = new List<string> { "OrdinaryMagicianItems/Resources/companion/attack_right/shanghai_attack_front_right_001", "OrdinaryMagicianItems/Resources/companion/attack_right/shanghai_attack_front_right_002", "OrdinaryMagicianItems/Resources/companion/attack_right/shanghai_attack_front_right_003", "OrdinaryMagicianItems/Resources/companion/attack_right/shanghai_attack_front_right_004", "OrdinaryMagicianItems/Resources/companion/attack_right/shanghai_attack_front_right_005", "OrdinaryMagicianItems/Resources/companion/attack_right/shanghai_attack_front_right_006" };
				List<int> list4 = new List<int>();
				for (int j = 0; j < list3.Count; j++)
				{
					list4.Add(SpriteBuilder.AddSpriteToCollection(list3[j], val2));
				}
				tk2dSpriteAnimationClip val4 = SpriteBuilder.AddAnimation(((BraveBehaviour)val).spriteAnimator, val2, list4, "attack_right", (WrapMode)2);
				val4.fps = 6f;
				DirectionalAnimation val5 = new DirectionalAnimation();
				val5.AnimNames = new string[2] { "attack_right", "attack_left" };
				val5.Flipped = (FlipType[])(object)new FlipType[2];
				val5.Type = (DirectionType)2;
				val5.Prefix = string.Empty;
				DirectionalAnimation animation = val5;
				((BraveBehaviour)val).aiAnimator.AssignDirectionalAnimation("attack", animation, CompanionBuilder.AnimationType.Other);
				BehaviorSpeculator component = prefab.GetComponent<BehaviorSpeculator>();
				List<MovementBehaviorBase> movementBehaviors = component.MovementBehaviors;
				CompanionFollowPlayerBehavior val6 = new CompanionFollowPlayerBehavior();
				val6.IdleAnimations = new string[1] { "idle" };
				val6.DisableInCombat = true;
				movementBehaviors.Add((MovementBehaviorBase)(object)val6);
				component.MovementBehaviors.Add((MovementBehaviorBase)new SeekTargetBehavior
				{
					StopWhenInRange = false,
					CustomRange = -1f,
					LineOfSight = true,
					ReturnToSpawn = false,
					SpawnTetherDistance = 0f,
					PathInterval = 0.25f,
					ExternalCooldownSource = false,
					SpecifyRange = false,
					MinActiveRange = 0f,
					MaxActiveRange = 0f
				});
				component.TargetBehaviors.Add((TargetBehaviorBase)new TargetPlayerBehavior
				{
					Radius = 35f,
					LineOfSight = true,
					ObjectPermanence = true,
					SearchInterval = 0.25f,
					PauseOnTargetSwitch = false,
					PauseTime = 0.25f
				});
				component.AttackBehaviors.Add((AttackBehaviorBase)(object)new ShanghaiAttackBehavior
				{
					minLeapDistance = 1f,
					leapDistance = 2f,
					maxTravelDistance = 5f,
					leadAmount = 1f,
					leapTime = 0.4f,
					maximumChargeTime = 0.25f,
					chargeAnim = string.Empty,
					leapAnim = "attack"
				});
			}
		}

		private void CreateCompanion(PlayerController owner)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Invalid comparison between Unknown and I4
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Invalid comparison between Unknown and I4
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Invalid comparison between Unknown and I4
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)(object)((BraveBehaviour)owner).healthHaver != (Object)null && ((BraveBehaviour)owner).healthHaver.GetCurrentHealthPercentage() >= 1f) || PreventRespawnOnFloorLoad)
			{
				return;
			}
			if (BabyGoodMimicOrbitalOverridden)
			{
				GameObject extantCompanion = PlayerOrbitalItem.CreateOrbital(owner, (!Object.op_Implicit((Object)(object)OverridePlayerOrbitalItem.OrbitalFollowerPrefab)) ? ((Component)OverridePlayerOrbitalItem.OrbitalPrefab).gameObject : ((Component)OverridePlayerOrbitalItem.OrbitalFollowerPrefab).gameObject, Object.op_Implicit((Object)(object)OverridePlayerOrbitalItem.OrbitalFollowerPrefab), (PlayerOrbitalItem)null);
				m_extantCompanion = extantCompanion;
				return;
			}
			string text = CompanionGuid;
			m_lastActiveSynergyTransformation = -1;
			if (UsesAlternatePastPrefab && (int)GameManager.Instance.CurrentLevelOverrideState == 5)
			{
				text = CompanionPastGuid;
			}
			else if (Synergies.Length != 0)
			{
				for (int i = 0; i < Synergies.Length; i++)
				{
					if (owner.HasActiveBonusSynergy(Synergies[i].RequiredSynergy, false))
					{
						text = Synergies[i].SynergyCompanionGuid;
						m_lastActiveSynergyTransformation = i;
					}
				}
			}
			AIActor orLoadByGuid = EnemyDatabase.GetOrLoadByGuid(text);
			Vector3 val = ((BraveBehaviour)owner).transform.position;
			if ((int)GameManager.Instance.CurrentLevelOverrideState == 1)
			{
				val += new Vector3(1.125f, -0.3125f, 0f);
			}
			GameObject extantCompanion2 = Object.Instantiate<GameObject>(((Component)orLoadByGuid).gameObject, val, Quaternion.identity);
			m_extantCompanion = extantCompanion2;
			CompanionController orAddComponent = GameObjectExtensions.GetOrAddComponent<CompanionController>(m_extantCompanion);
			orAddComponent.Initialize(owner);
			if (Object.op_Implicit((Object)(object)((BraveBehaviour)orAddComponent).specRigidbody))
			{
				PhysicsEngine.Instance.RegisterOverlappingGhostCollisionExceptions(((BraveBehaviour)orAddComponent).specRigidbody, (int?)null, false);
			}
			if ((int)orAddComponent.companionID == 5)
			{
				GameStatsManager.Instance.SetFlag((GungeonFlags)171007, true);
			}
		}

		public void ForceCompanionRegeneration(PlayerController owner, Vector2? overridePosition)
		{
			//IL_0003: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			bool flag = false;
			Vector2 val = Vector2.zero;
			if (Object.op_Implicit((Object)(object)m_extantCompanion))
			{
				flag = true;
				val = Vector3Extensions.XY(m_extantCompanion.transform.position);
			}
			if (overridePosition.HasValue)
			{
				flag = true;
				val = overridePosition.Value;
			}
			DestroyCompanion();
			CreateCompanion(owner);
			if (Object.op_Implicit((Object)(object)m_extantCompanion) && flag)
			{
				m_extantCompanion.transform.position = Vector2Extensions.ToVector3ZisY(val, 0f);
				SpeculativeRigidbody component = m_extantCompanion.GetComponent<SpeculativeRigidbody>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.Reinitialize();
				}
			}
		}

		public void ForceDisconnectCompanion()
		{
			m_extantCompanion = null;
		}

		private void DestroyCompanion()
		{
			if (Object.op_Implicit((Object)(object)m_extantCompanion))
			{
				Object.Destroy((Object)(object)m_extantCompanion);
				m_extantCompanion = null;
			}
		}

		public override void Update()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			((PassiveItem)this).Update();
			if (Dungeon.IsGenerating || !Object.op_Implicit((Object)(object)base.m_owner) || Synergies.Length == 0 || (UsesAlternatePastPrefab && (int)GameManager.Instance.CurrentLevelOverrideState == 5))
			{
				return;
			}
			bool flag = false;
			for (int num = Synergies.Length - 1; num >= 0; num--)
			{
				if (base.m_owner.HasActiveBonusSynergy(Synergies[num].RequiredSynergy, false))
				{
					if (m_lastActiveSynergyTransformation != num)
					{
						DestroyCompanion();
						CreateCompanion(base.m_owner);
					}
					flag = true;
					break;
				}
			}
			if (!flag && m_lastActiveSynergyTransformation != -1)
			{
				DestroyCompanion();
				CreateCompanion(base.m_owner);
			}
		}

		public override void Pickup(PlayerController player)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			((PassiveItem)this).Pickup(player);
			player.OnNewFloorLoaded = (Action<PlayerController>)Delegate.Combine(player.OnNewFloorLoaded, new Action<PlayerController>(HandleNewFloor));
			if ((Object)(object)((BraveBehaviour)player).healthHaver != (Object)null)
			{
				((BraveBehaviour)player).healthHaver.OnHealthChanged += new OnHealthChangedEvent(OnHealthChanged);
				((BraveBehaviour)player).healthHaver.OnPreDeath += MaybeRevive;
			}
			CreateCompanion(player);
		}

		public void MaybeRevive(Vector2 deathDir)
		{
			foreach (PassiveItem passiveItem in base.m_owner.passiveItems)
			{
				if (!new List<int> { 421, 422, 423, 424, 425 }.Contains(((PickupObject)passiveItem).PickupObjectId))
				{
					continue;
				}
				base.m_owner.RemovePassiveItem(((PickupObject)passiveItem).PickupObjectId);
				((BraveBehaviour)base.m_owner).healthHaver.ApplyHealing(1f);
				base.m_owner.ForceBlank(25f, 0.5f, false, true, (Vector2?)null, true, -1f);
				base.m_owner.ClearDeadFlags();
				if ((Object)(object)GameManager.Instance != (Object)null)
				{
					if (m_currentTimeSlow != null)
					{
						((MonoBehaviour)GameManager.Instance).StopCoroutine(m_currentTimeSlow);
					}
					m_currentTimeSlow = ((MonoBehaviour)GameManager.Instance).StartCoroutine(PostReviveTimeSlow());
				}
				break;
			}
		}

		public IEnumerator PostReviveTimeSlow()
		{
			BraveTime.ClearMultiplier(((Component)this).gameObject);
			BraveTime.RegisterTimeScaleMultiplier(0.1f, ((Component)this).gameObject);
			float elapsed = 0f;
			float duration = 2.5f;
			while (elapsed < duration)
			{
				elapsed += GameManager.INVARIANT_DELTA_TIME;
				BraveTime.ClearMultiplier(((Component)this).gameObject);
				BraveTime.RegisterTimeScaleMultiplier(Mathf.Lerp(0.1f, 1f, elapsed - (duration - 1f)), ((Component)this).gameObject);
				yield return null;
			}
			BraveTime.ClearMultiplier(((Component)this).gameObject);
		}

		public void OnHealthChanged(float resultValue, float maxValue)
		{
			if (resultValue >= maxValue)
			{
				DestroyCompanion();
			}
			else if ((Object)(object)ExtantCompanion == (Object)null)
			{
				CreateCompanion(((PassiveItem)this).Owner);
			}
		}

		private void HandleNewFloor(PlayerController obj)
		{
			DestroyCompanion();
			if (!PreventRespawnOnFloorLoad)
			{
				CreateCompanion(obj);
			}
		}

		public override DebrisObject Drop(PlayerController player)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			DestroyCompanion();
			player.OnNewFloorLoaded = (Action<PlayerController>)Delegate.Remove(player.OnNewFloorLoaded, new Action<PlayerController>(HandleNewFloor));
			if ((Object)(object)((BraveBehaviour)player).healthHaver != (Object)null)
			{
				((BraveBehaviour)player).healthHaver.OnHealthChanged -= new OnHealthChangedEvent(OnHealthChanged);
				((BraveBehaviour)player).healthHaver.OnPreDeath -= MaybeRevive;
			}
			return ((PassiveItem)this).Drop(player);
		}

		public override void OnDestroy()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			if ((Object)(object)base.m_owner != (Object)null)
			{
				PlayerController owner = base.m_owner;
				owner.OnNewFloorLoaded = (Action<PlayerController>)Delegate.Remove(owner.OnNewFloorLoaded, new Action<PlayerController>(HandleNewFloor));
				if ((Object)(object)((BraveBehaviour)owner).healthHaver != (Object)null)
				{
					((BraveBehaviour)owner).healthHaver.OnHealthChanged -= new OnHealthChangedEvent(OnHealthChanged);
					((BraveBehaviour)owner).healthHaver.OnPreDeath -= MaybeRevive;
				}
			}
			DestroyCompanion();
			((PassiveItem)this).OnDestroy();
		}
	}
	public class MagicianPistol
	{
		public static List<List<Vector2>> offsets = new List<List<Vector2>>
		{
			new List<Vector2>
			{
				new Vector2(0f, 0f)
			},
			new List<Vector2>
			{
				new Vector2(0f, 0f),
				new Vector2(-0.0625f, 0.0625f),
				new Vector2(0f, -0.0625f),
				new Vector2(0f, 0f)
			},
			new List<Vector2>
			{
				new Vector2(0f, -0.0625f),
				new Vector2(0.125f, 0f),
				new Vector2(0.125f, 0.0625f),
				new Vector2(0.125f, 0.125f),
				new Vector2(0.125f, 0.0625f),
				new Vector2(0.125f, 0.125f),
				new Vector2(0f, 0.0625f),
				new Vector2(0f, -0.0625f)
			}
		};

		public static void Init()
		{
			//IL_00fd: 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_0169: 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_0269: Unknown result type (might be due to invalid IL or missing references)
			Gun val = Databases.Items.NewGun("Magician Pistol", "nerfed_witch_pistol");
			Game.Items.Rename("outdated_gun_mods:magician_pistol", "spapi:magician_pistol");
			GunExt.SetShortDescription((PickupObject)(object)val, "Fancy Schmancy");
			GunExt.SetLongDescription((PickupObject)(object)val, "Well this is just a really messy attempt at a Witch Pistol.\nThe shoddy craftsmanship makes it particularly awkward to reload, but you'll sure as hell look cool doing it!\n\nThe \"Magic\" part of this weapon is purely for cosmetic purposes, it's really just a standard magnum.");
			GunExt.AddProjectileModuleFrom(val, "klobb", true, false);
			? val2 = val;
			PickupObject byId = PickupObjectDatabase.GetById(145);
			((Gun)val2).TransformToTargetGun((Gun)(object)((byId is Gun) ? byId : null));
			GunExt.SetupSprite(val, (tk2dSpriteCollectionData)null, "nerfed_witch_pistol_idle_001", 16);
			PickupObject byId2 = PickupObjectDatabase.GetById(145);
			Projectile val3 = Object.Instantiate<Projectile>(((Gun)((byId2 is Gun) ? byId2 : null)).DefaultModule.projectiles[0]);
			((Component)val3).gameObject.SetActive(false);
			FakePrefab.MarkAsFakePrefab(((Component)val3).gameObject);
			Object.DontDestroyOnLoad((Object)(object)val3);
			val3.CanTransmogrify = false;
			val3.ChanceToTransmogrify = -1f;
			val.reloadTime = 1.6f;
			val.StarterGunForAchievement = true;
			val.DefaultModule.projectiles[0] = val3;
			val.InfiniteAmmo = true;
			((PickupObject)val).quality = (ItemQuality)(-50);
			val.gunClass = (GunClass)1;
			int num = 0;
			tk2dSpriteAnimationFrame[] frames = ((Component)val).GetComponent<tk2dSpriteAnimator>().GetClipByName(val.idleAnimation).frames;
			foreach (tk2dSpriteAnimationFrame val4 in frames)
			{
				tk2dSpriteDefinition val5 = val4.spriteCollection.spriteDefinitions[val4.spriteId];
				if (val5 != null)
				{
					RemoveOffset(val5);
					MakeOffset(val5, offsets[0][num]);
				}
				num++;
			}
			num = 0;
			tk2dSpriteAnimationFrame[] frames2 = ((Component)val).GetComponent<tk2dSpriteAnimator>().GetClipByName(val.shootAnimation).frames;
			foreach (tk2dSpriteAnimationFrame val6 in frames2)
			{
				tk2dSpriteDefinition val7 = val6.spriteCollection.spriteDefinitions[val6.spriteId];
				if (val7 != null)
				{
					RemoveOffset(val7);
					MakeOffset(val7, offsets[1][num]);
				}
				num++;
			}
			num = 0;
			tk2dSpriteAnimationFrame[] frames3 = ((Component)val).GetComponent<tk2dSpriteAnimator>().GetClipByName(val.reloadAnimation).frames;
			foreach (tk2dSpriteAnimationFrame val8 in frames3)
			{
				tk2dSpriteDefinition val9 = val8.spriteCollection.spriteDefinitions[val8.spriteId];
				if (val9 != null)
				{
					RemoveOffset(val9);
					MakeOffset(val9, offsets[2][num]);
				}
				num++;
			}
			ChangeReloadSpeedSynergyProcessor changeReloadSpeedSynergyProcessor = ((Component)val).gameObject.AddComponent<ChangeReloadSpeedSynergyProcessor>();
			changeReloadSpeedSynergyProcessor.SynergyReloadTime = 1.2f;
			changeReloadSpeedSynergyProcessor.RequiredSynergy = "Twelve Shots";
			Databases.Items.Add(val, (tk2dSpriteCollectionData)null, "ANY");
			AddDualWieldSynergyProcessor(((PickupObject)val).PickupObjectId, 145, "Twelve Shots");
		}

		public static void AddDualWieldSynergyProcessor(int id1, int id2, string synergyName)
		{
			AdvancedDualWieldSynergyProcessor advancedDualWieldSynergyProcessor = ((Component)PickupObjectDatabase.GetById(id1)).gameObject.AddComponent<AdvancedDualWieldSynergyProcessor>();
			advancedDualWieldSynergyProcessor.SynergyNameToCheck = synergyName;
			advancedDualWieldSynergyProcessor.PartnerGunID = id2;
			AdvancedDualWieldSynergyProcessor advancedDualWieldSynergyProcessor2 = ((Component)PickupObjectDatabase.GetById(id2)).gameObject.AddComponent<AdvancedDualWieldSynergyProcessor>();
			advancedDualWieldSynergyProcessor2.SynergyNameToCheck = synergyName;
			advancedDualWieldSynergyProcessor2.PartnerGunID = id1;
		}

		public static void RemoveOffset(tk2dSpriteDefinition def)
		{
			//IL_0003: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			MakeOffset(def, Vector2.op_Implicit(-def.position0));
		}

		public static void MakeOffset(tk2dSpriteDefinition def, Vector2 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 static void ConstructOffsetsFromAnchor(tk2dSpriteDefinition def, Anchor anchor, Vector2? scale = null, bool fixesScale = false, bool changesCollider = true)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			//IL_002b: 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)
			//IL_0036: 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_0040: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Invalid comparison between Unknown and I4
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Invalid comparison between Unknown and I4
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Invalid comparison between Unknown and I4
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Invalid