Decompiled source of The Judge WIP v1.9.2

TheJudgeMod.dll

Decompiled 2 years 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 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("Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Mod")]
[assembly: AssemblyCopyright("Copyright ©  2020")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d6d7a494-722e-4763-959b-c2d6b6a42b01")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
public class CelestialFedora : PassiveItem
{
	private static Hook healthHaverStartHook;

	public static void Init()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		string text = "Celestial Fedora";
		string resourcePath = "TheJudgeModule/Resources/Celestial_Fedora_sprite";
		GameObject val = new GameObject(text);
		CelestialFedora celestialFedora = val.AddComponent<CelestialFedora>();
		ItemBuilder.AddSpriteToObject(text, resourcePath, val);
		string shortDesc = "Smooth Judgement";
		string longDesc = "This celestial fedora breaks the boundaries of mortal constraints, allowing you to deal unlimited damage to bosses.";
		((PickupObject)(object)celestialFedora).SetupItem(shortDesc, longDesc, "cpt");
		((PickupObject)celestialFedora).quality = (ItemQuality)5;
	}

	public override void Pickup(PlayerController player)
	{
		((PassiveItem)this).Pickup(player);
		EnableBossDpsCapModification();
	}

	public override DebrisObject Drop(PlayerController player)
	{
		DisableBossDpsCapModification();
		return ((PassiveItem)this).Drop(player);
	}

	public override void OnDestroy()
	{
		DisableBossDpsCapModification();
		((PassiveItem)this).OnDestroy();
	}

	private static void EnableBossDpsCapModification()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		if (healthHaverStartHook == null)
		{
			healthHaverStartHook = new Hook((MethodBase)typeof(HealthHaver).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic), typeof(CelestialFedora).GetMethod("ModifiedHealthHaverStart"));
		}
	}

	private static void DisableBossDpsCapModification()
	{
		if (healthHaverStartHook != null)
		{
			healthHaverStartHook.Dispose();
			healthHaverStartHook = null;
		}
	}

	public static void ModifiedHealthHaverStart(Action<HealthHaver> orig, HealthHaver self)
	{
		orig(self);
		if (self.IsBoss)
		{
			FieldInfo field = typeof(HealthHaver).GetField("m_damageCap", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(HealthHaver).GetField("m_bossDpsCap", BindingFlags.Instance | BindingFlags.NonPublic);
			field?.SetValue(self, -1f);
			field2?.SetValue(self, -1f);
		}
	}
}
namespace TheJudgeModule
{
	[BepInPlugin("creator.etg.Judge", "The Judge", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class TheJudgeModule : BaseUnityPlugin
	{
		public const string GUID = "creator.etg.TheJudge";

		public const string NAME = "The Judge";

		public const string VERSION = "1.0.0";

		public const string TEXT_COLOR = "#00FFFF";

		public void Awake()
		{
			ItemBuilder.Init();
			CelestialFedora.Init();
			Log("The Judge v1.0.0 started successfully.", "#00FFFF");
		}

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

		public void GMStart(GameManager gameManager)
		{
			Log("The Judge v1.0.0 started successfully.", "#00FFFF");
		}

		public static void Log(string text, string color = "#FFFFFF")
		{
			ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
		}
	}
}
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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			if (companionDictionary.ContainsKey(guid))
			{
				Tools.PrintError("CompanionBuilder: Tried to create two companion prefabs with the same GUID!");
				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)
		{
			//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();
			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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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;
			}
			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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: 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_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: 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_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			if (mandatoryConsoleIDs == null || mandatoryConsoleIDs.Count == 0)
			{
				Tools.PrintError("Synergy " + name + " has no mandatory items/guns.");
				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 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);
			Object.DontDestroyOnLoad((Object)(object)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);
			Object.DontDestroyOnLoad((Object)(object)val);
			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("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();
			Tools.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 Tools.sharedAuto1.LoadAsset<GenericLootTable>(assetName);
		}

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

		public static void SetupItem(this PickupObject item, string shortDesc, string longDesc, string idPool = "customItems")
		{
			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");
				FakePrefab.MarkAsFakePrefab(((Component)item).gameObject);
				((Component)item).gameObject.SetActive(false);
			}
			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)
		{
			//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 Tools
	{
		public static bool verbose = false;

		private static string defaultLog = Path.Combine(ETGMod.ResourcesDirectory, "exampleMod.txt");

		public static string modID = "EX";

		public static AssetBundle sharedAuto1 = ResourceManager.LoadAssetBundle("shared_auto_001");

		public static AssetBundle sharedAuto2 = ResourceManager.LoadAssetBundle("shared_auto_002");

		public static void Init()
		{
			if (File.Exists(defaultLog))
			{
				File.Delete(defaultLog);
			}
		}

		public static void Print<T>(T obj, string color = "FFFFFF", bool force = false)
		{
			if (verbose || force)
			{
				ETGModConsole.Log((object)("<color=#" + color + ">" + modID + ": " + obj.ToString() + "</color>"), false);
			}
			Log(obj.ToString());
		}

		public static void PrintRaw<T>(T obj, bool force = false)
		{
			if (verbose || force)
			{
				ETGModConsole.Log((object)obj.ToString(), false);
			}
			Log(obj.ToString());
		}

		public static void PrintError<T>(T obj, string color = "FF0000")
		{
			ETGModConsole.Log((object)("<color=#" + color + ">" + modID + ": " + obj.ToString() + "</color>"), false);
			Log(obj.ToString());
		}

		public static void PrintException(Exception e, string color = "FF0000")
		{
			ETGModConsole.Log((object)("<color=#" + color + ">" + modID + ": " + e.Message + "</color>"), false);
			ETGModConsole.Log((object)e.StackTrace, false);
			Log(e.Message);
			Log("\t" + e.StackTrace);
		}

		public static void Log<T>(T obj)
		{
			using StreamWriter streamWriter = new StreamWriter(Path.Combine(ETGMod.ResourcesDirectory, defaultLog), append: true);
			streamWriter.WriteLine(obj.ToString());
		}

		public static void Log<T>(T obj, string fileName)
		{
			if (!verbose)
			{
				return;
			}
			using StreamWriter streamWriter = new StreamWriter(Path.Combine(ETGMod.ResourcesDirectory, fileName), append: true);
			streamWriter.WriteLine(obj.ToString());
		}

		public static void Dissect(this GameObject obj)
		{
			Print(((Object)obj).name + " Components:");
			Component[] components = obj.GetComponents<Component>();
			foreach (Component val in components)
			{
				Print("    " + ((object)val).GetType());
			}
		}

		public static void ShowHitBox(this SpeculativeRigidbody body)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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)
			PixelCollider hitboxPixelCollider = body.HitboxPixelCollider;
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val).name = "HitboxDisplay";
			val.transform.SetParent(((BraveBehaviour)body).transform);
			Print(((Object)body).name ?? "");
			Print($"    Offset: {hitboxPixelCollider.Offset}, Dimesions: {hitboxPixelCollider.Dimensions}");
			val.transform.localScale = new Vector3((float)hitboxPixelCollider.Dimensions.x / 16f, (float)hitboxPixelCollider.Dimensions.y / 16f, 1f);
			Vector3 localPosition = new Vector3((float)hitboxPixelCollider.Offset.x + (float)hitboxPixelCollider.Dimensions.x * 0.5f, (float)hitboxPixelCollider.Offset.y + (float)hitboxPixelCollider.Dimensions.y * 0.5f, -16f) / 16f;
			val.transform.localPosition = localPosition;
		}

		public static void HideHitBox(this SpeculativeRigidbody body)
		{
			Transform val = ((BraveBehaviour)body).transform.Find("HitboxDisplay");
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)val);
			}
		}

		public static void ExportTexture(Texture texture)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			File.WriteAllBytes(Path.Combine(ETGMod.ResourcesDirectory, ((Object)texture).name + ".png"), ImageConversion.EncodeToPNG((Texture2D)texture));
		}

		public static void LogPropertiesAndFields<T>(this T obj, string header = "")
		{
			Log(header);
			Log("=======================");
			if (obj == null)
			{
				Log("LogPropertiesAndFields: Null object");
				return;
			}
			Type type = obj.GetType();
			Log($"Type: {type}");
			PropertyInfo[] properties = type.GetProperties();
			Log($"{typeof(T)} Properties: ");
			PropertyInfo[] array = properties;
			foreach (PropertyInfo propertyInfo in array)
			{
				try
				{
					object value = propertyInfo.GetValue(obj, null);
					string text = value.ToString();
					if ((object)obj?.GetType().GetGenericTypeDefinition() == typeof(List<>))
					{
						List<object> list = value as List<object>;
						text = $"List[{list.Count}]";
						foreach (object item in list)
						{
							text = text + "\n\t\t" + item.ToString();
						}
					}
					Log("\t" + propertyInfo.Name + ": " + text);
				}
				catch
				{
				}
			}
			Log($"{typeof(T)} Fields: ");
			FieldInfo[] fields = type.GetFields();
			FieldInfo[] array2 = fields;
			foreach (FieldInfo fieldInfo in array2)
			{
				Log($"\t{fieldInfo.Name}: {fieldInfo.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))
			{
				Tools.PrintError(directoryPath + " not found.");
				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))
			{
				Tools.PrintError(text + " not found.");
				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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			byte[] array = ExtractEmbeddedResource(resourceName);
			if (array == null)
			{
				Tools.PrintError("No bytes found in " + resourceName);
				return null;
			}
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, array);
			((Texture)val).filterMode = (FilterMode)0;
			string text = resourceName.Substring(0, resourceName.LastIndexOf('.'));
			if (text.LastIndexOf('.') >= 0)
			{
				text = text.Substring(text.LastIndexOf('.') + 1);
			}
			((Object)val).name = text;
			return val;
		}

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

		private static tk2dSpriteCollectionData ammonomiconCollection = AmmonomiconController.ForceInstance.EncounterIconCollection;

		private static tk2dSprite baseSprite = ((Component)PickupObjectDatabase.GetByEncounterName("singularity")).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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//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
			{
				name = clipName,
				fps = 15f,
				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);
		}
	}
}