Decompiled source of Gundustrial Revolution v0.1.0

GunRev.dll

Decompiled 6 days ago
#define DEBUG
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Alexandria.BreakableAPI;
using Alexandria.DungeonAPI;
using Alexandria.ItemAPI;
using Alexandria.Misc;
using Alexandria.VisualAPI;
using BepInEx;
using Brave.BulletScript;
using Dungeonator;
using FullSerializer;
using Gungeon;
using HarmonyLib;
using InControl;
using LZ4;
using LZ4.Services;
using LZ4ps;
using Microsoft.CodeAnalysis;
using Microsoft.Win32;
using MonoMod.RuntimeDetour;
using Pathfinding;
using SevenZip;
using SevenZip.Compression.LZ;
using SevenZip.Compression.LZMA;
using SevenZip.Compression.RangeCoder;
using SoundAPI;
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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public class AIBeamShooter2 : BraveBehaviour
{
	[CompilerGenerated]
	private sealed class <FireBeam>d__26 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Projectile projectile;

		public AIBeamShooter2 <>4__this;

		private GameObject <beamObject>5__1;

		private bool <facingNorth>5__2;

		private bool <firstFrame>5__3;

		private float <clampedAngle>5__4;

		private Vector2 <dirVec>5__5;

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

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

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

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

		private bool MoveNext()
		{
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<beamObject>5__1 = Object.Instantiate<GameObject>(((Component)projectile).gameObject);
				<>4__this.m_laserBeam = <beamObject>5__1.GetComponent<BasicBeamController>();
				((BeamController)<>4__this.m_laserBeam).Owner = (GameActor)(object)((BraveBehaviour)<>4__this).aiActor;
				((BeamController)<>4__this.m_laserBeam).HitsPlayers = projectile.collidesWithPlayer || (!<>4__this.IgnoreAiActorPlayerChecks && Object.op_Implicit((Object)(object)((BraveBehaviour)<>4__this).aiActor) && ((BraveBehaviour)<>4__this).aiActor.CanTargetPlayers);
				((BeamController)<>4__this.m_laserBeam).HitsEnemies = projectile.collidesWithEnemies || (Object.op_Implicit((Object)(object)((BraveBehaviour)<>4__this).aiActor) && ((BraveBehaviour)<>4__this).aiActor.CanTargetEnemies);
				<facingNorth>5__2 = BraveMathCollege.AbsAngleBetween(<>4__this.LaserAngle, 90f) < <>4__this.northAngleTolerance;
				<>4__this.m_laserBeam.HeightOffset = <>4__this.heightOffset;
				<>4__this.m_laserBeam.RampHeightOffset = ((!<facingNorth>5__2) ? <>4__this.otherRampHeight : <>4__this.northRampHeight);
				<>4__this.m_laserBeam.ContinueBeamArtToWall = !<>4__this.PreventBeamContinuation;
				<firstFrame>5__3 = true;
				goto IL_031c;
			case 1:
				<>1__state = -1;
				<firstFrame>5__3 = false;
				goto IL_031c;
			case 2:
				<>1__state = -1;
				goto IL_030a;
			case 3:
				<>1__state = -1;
				goto IL_030a;
			case 4:
				{
					<>1__state = -1;
					goto IL_03f3;
				}
				IL_030a:
				if (Time.timeScale == 0f)
				{
					<>2__current = null;
					<>1__state = 3;
					return true;
				}
				goto IL_031c;
				IL_031c:
				if ((Object)(object)<>4__this.m_laserBeam != (Object)null && <>4__this.m_firingLaser)
				{
					<clampedAngle>5__4 = BraveMathCollege.ClampAngle360(<>4__this.LaserAngle);
					<dirVec>5__5 = Vector2.op_Implicit(new Vector3(Mathf.Cos(<clampedAngle>5__4 * ((float)Math.PI / 180f)), Mathf.Sin(<clampedAngle>5__4 * ((float)Math.PI / 180f))) * 10f);
					((BeamController)<>4__this.m_laserBeam).Origin = Vector2.op_Implicit(<>4__this.GetTrueLaserOrigin());
					((BeamController)<>4__this.m_laserBeam).Direction = <dirVec>5__5;
					if (<firstFrame>5__3)
					{
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					<facingNorth>5__2 = BraveMathCollege.AbsAngleBetween(<>4__this.LaserAngle, 90f) < <>4__this.northAngleTolerance;
					<>4__this.m_laserBeam.RampHeightOffset = ((!<facingNorth>5__2) ? <>4__this.otherRampHeight : <>4__this.northRampHeight);
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				if (!<>4__this.m_firingLaser && (Object)(object)<>4__this.m_laserBeam != (Object)null)
				{
					((BeamController)<>4__this.m_laserBeam).CeaseAttack();
				}
				if (!<>4__this.TurnDuringDissipation || !Object.op_Implicit((Object)(object)<>4__this.m_laserBeam))
				{
					break;
				}
				<>4__this.m_laserBeam.SelfUpdate = false;
				goto IL_03f3;
				IL_03f3:
				if (Object.op_Implicit((Object)(object)<>4__this.m_laserBeam))
				{
					((BeamController)<>4__this.m_laserBeam).Origin = Vector2.op_Implicit(<>4__this.GetTrueLaserOrigin());
					<>2__current = null;
					<>1__state = 4;
					return true;
				}
				break;
			}
			<>4__this.m_laserBeam = null;
			return false;
		}

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

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

	public string shootAnim;

	public AIAnimator specifyAnimator;

	public Transform beamTransform;

	public VFXPool chargeVfx;

	public Projectile beamProjectile;

	public ProjectileModule beamModule;

	public bool TurnDuringDissipation = true;

	public bool PreventBeamContinuation;

	[Header("Depth")]
	public float heightOffset = 1.9f;

	public float northAngleTolerance = 90f;

	public float northRampHeight;

	public float otherRampHeight = 5f;

	public Vector2 firingEllipseCenter;

	public float firingEllipseA;

	public float firingEllipseB;

	public float eyeballFudgeAngle;

	private bool m_firingLaser;

	private float m_laserAngle;

	private BasicBeamController m_laserBeam;

	private BodyPartController m_bodyPart;

	public float LaserAngle => m_laserAngle;

	public bool IsFiringLaser => m_firingLaser;

	public Vector2 LaserFiringCenter => Vector3Extensions.XY(beamTransform.position) + firingEllipseCenter;

	public AIAnimator CurrentAiAnimator => (!Object.op_Implicit((Object)(object)specifyAnimator)) ? ((BraveBehaviour)this).aiAnimator : specifyAnimator;

	public float MaxBeamLength { get; set; }

	public BeamController LaserBeam => (BeamController)(object)m_laserBeam;

	public bool IgnoreAiActorPlayerChecks { get; set; }

	public void SetLaserAngle(float alaserAngle)
	{
		m_laserAngle = alaserAngle;
		if (m_firingLaser)
		{
			((BraveBehaviour)this).aiAnimator.FacingDirection = alaserAngle;
		}
	}

	public void Start()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		((BraveBehaviour)this).healthHaver.OnDamaged += new OnDamagedEvent(OnDamaged);
		if (Object.op_Implicit((Object)(object)specifyAnimator))
		{
			m_bodyPart = ((Component)specifyAnimator).GetComponent<BodyPartController>();
		}
	}

	public void Update()
	{
	}

	public void LateUpdate()
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Invalid comparison between Unknown and I4
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)m_laserBeam) && MaxBeamLength > 0f)
		{
			((BraveBehaviour)m_laserBeam).projectile.baseData.range = MaxBeamLength;
			m_laserBeam.ShowImpactOnMaxDistanceEnd = true;
		}
		if (m_firingLaser && Object.op_Implicit((Object)(object)m_laserBeam))
		{
			((BeamController)m_laserBeam).LateUpdatePosition(GetTrueLaserOrigin());
		}
		else if (Object.op_Implicit((Object)(object)m_laserBeam) && (int)m_laserBeam.State == 3)
		{
			((BeamController)m_laserBeam).LateUpdatePosition(GetTrueLaserOrigin());
		}
		else if (m_firingLaser && !Object.op_Implicit((Object)(object)m_laserBeam))
		{
			StopFiringLaser();
		}
	}

	public override void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)m_laserBeam))
		{
			((BeamController)m_laserBeam).CeaseAttack();
		}
		((BraveBehaviour)this).OnDestroy();
	}

	public void OnDamaged(float resultValue, float maxValue, CoreDamageTypes damageTypes, DamageCategory damageCategory, Vector2 damageDirection)
	{
		if (resultValue <= 0f)
		{
			if (m_firingLaser)
			{
				chargeVfx.DestroyAll();
				StopFiringLaser();
			}
			if (Object.op_Implicit((Object)(object)m_laserBeam))
			{
				((BeamController)m_laserBeam).DestroyBeam();
				m_laserBeam = null;
			}
		}
	}

	public void StartFiringLaser(float laserAngle)
	{
		m_firingLaser = true;
		SetLaserAngle(laserAngle);
		if (Object.op_Implicit((Object)(object)m_bodyPart))
		{
			m_bodyPart.OverrideFacingDirection = true;
		}
		if (!string.IsNullOrEmpty(shootAnim))
		{
			CurrentAiAnimator.LockFacingDirection = true;
			CurrentAiAnimator.PlayUntilCancelled(shootAnim, true, (string)null, -1f, false);
		}
		chargeVfx.DestroyAll();
		((MonoBehaviour)this).StartCoroutine(FireBeam((!Object.op_Implicit((Object)(object)beamProjectile)) ? beamModule.GetCurrentProjectile() : beamProjectile));
	}

	public void StopFiringLaser()
	{
		m_firingLaser = false;
		if (Object.op_Implicit((Object)(object)m_bodyPart))
		{
			m_bodyPart.OverrideFacingDirection = false;
		}
		if (!string.IsNullOrEmpty(shootAnim))
		{
			CurrentAiAnimator.LockFacingDirection = false;
			CurrentAiAnimator.EndAnimationIf(shootAnim);
		}
	}

	protected IEnumerator FireBeam(Projectile projectile)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <FireBeam>d__26(0)
		{
			<>4__this = this,
			projectile = projectile
		};
	}

	private Vector3 GetTrueLaserOrigin()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_0078: 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)
		Vector2 val = LaserFiringCenter;
		if (firingEllipseA != 0f && firingEllipseB != 0f)
		{
			float num = Mathf.Lerp(eyeballFudgeAngle, 0f, BraveMathCollege.AbsAngleBetween(90f, Mathf.Abs(BraveMathCollege.ClampAngle180(LaserAngle))) / 90f);
			val = BraveMathCollege.GetEllipsePoint(val, firingEllipseA, firingEllipseB, LaserAngle + num);
		}
		return Vector2.op_Implicit(val);
	}
}
public class CustomBeholsterLaserBehavior : BasicAttackBehavior
{
	private enum State
	{
		PreCharging,
		Charging,
		Firing
	}

	public enum TrackingType
	{
		Follow,
		ConstantTurn
	}

	[CompilerGenerated]
	private sealed class <>c__DisplayClass30_0
	{
		public AIBeamShooter2 aibeamShooter2;

		public CustomBeholsterLaserBehavior <>4__this;

		public float enemyTickCooldown;

		internal void <FireBeam>b__0(SpeculativeRigidbody hitRigidbody, Vector2 dirVec)
		{
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			Projectile val = aibeamShooter2.beamModule.GetCurrentProjectile();
			if (<>4__this.UsesBeamProjectileWithoutModule)
			{
				val = aibeamShooter2.beamProjectile;
			}
			HealthHaver val2 = ((!Object.op_Implicit((Object)(object)hitRigidbody)) ? null : ((BraveBehaviour)hitRigidbody).healthHaver);
			if (Object.op_Implicit((Object)(object)hitRigidbody) && Object.op_Implicit((Object)(object)((BraveBehaviour)hitRigidbody).projectile) && Object.op_Implicit((Object)(object)((Component)hitRigidbody).GetComponent<BeholsterBounceRocket>()))
			{
				BounceProjModifier component = ((Component)hitRigidbody).GetComponent<BounceProjModifier>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.numberOfBounces = 0;
				}
				((BraveBehaviour)hitRigidbody).projectile.DieInAir(false, true, true, false);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				if (Object.op_Implicit((Object)(object)((BraveBehaviour)val2).aiActor))
				{
					if (enemyTickCooldown <= 0f)
					{
						val2.ApplyDamage(ProjectileData.FixedFallbackDamageToEnemies, dirVec, ((BehaviorBase)<>4__this).m_aiActor.GetActorName(), val.damageTypes, (DamageCategory)0, false, (PixelCollider)null, false);
						enemyTickCooldown = 0.1f;
					}
				}
				else
				{
					val2.ApplyDamage(val.baseData.damage, dirVec, ((BehaviorBase)<>4__this).m_aiActor.GetActorName(), val.damageTypes, (DamageCategory)0, false, (PixelCollider)null, false);
				}
			}
			if (Object.op_Implicit((Object)(object)((BraveBehaviour)hitRigidbody).majorBreakable))
			{
				((BraveBehaviour)hitRigidbody).majorBreakable.ApplyDamage(26f * BraveTime.DeltaTime, dirVec, false, false, false);
			}
		}
	}

	[CompilerGenerated]
	private sealed class <FireBeam>d__30 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public AIBeamShooter2 aibeamShooter2;

		public CustomBeholsterLaserBehavior <>4__this;

		private <>c__DisplayClass30_0 <>8__1;

		private GameObject <beamObject>5__2;

		private BasicBeamController <beamCont>5__3;

		private List<AIActor> <activeEnemies>5__4;

		private bool <firstFrame>5__5;

		private int <i>5__6;

		private AIActor <aiactor>5__7;

		private bool <flag4>5__8;

		private float <clampedAngle>5__9;

		private Vector3 <dirVec2>5__10;

		private Vector2 <startingPoint>5__11;

		private bool <flag5>5__12;

		private bool <usesCustomAngle>5__13;

		private bool <firesDirectlyTowardsPlayer>5__14;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>8__1 = null;
			<beamObject>5__2 = null;
			<beamCont>5__3 = null;
			<activeEnemies>5__4 = null;
			<aiactor>5__7 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_03a5: 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_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: 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_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>8__1 = new <>c__DisplayClass30_0();
				<>8__1.aibeamShooter2 = aibeamShooter2;
				<>8__1.<>4__this = <>4__this;
				<beamObject>5__2 = Object.Instantiate<GameObject>(((Component)<>8__1.aibeamShooter2.beamModule.GetCurrentProjectile()).gameObject);
				if (<>4__this.UsesBeamProjectileWithoutModule)
				{
					<beamObject>5__2 = Object.Instantiate<GameObject>(((Component)<>8__1.aibeamShooter2.beamProjectile).gameObject);
				}
				<beamCont>5__3 = <beamObject>5__2.GetComponent<BasicBeamController>();
				<activeEnemies>5__4 = ((BehaviorBase)<>4__this).m_aiActor.ParentRoom.GetActiveEnemies((ActiveEnemyType)0);
				<i>5__6 = 0;
				while (<i>5__6 < <activeEnemies>5__4.Count)
				{
					<aiactor>5__7 = <activeEnemies>5__4[<i>5__6];
					if (Object.op_Implicit((Object)(object)<aiactor>5__7) && (Object)(object)<aiactor>5__7 != (Object)(object)((BehaviorBase)<>4__this).m_aiActor && Object.op_Implicit((Object)(object)((BraveBehaviour)<aiactor>5__7).healthHaver))
					{
						((BeamController)<beamCont>5__3).IgnoreRigidbodes.Add(((BraveBehaviour)<aiactor>5__7).specRigidbody);
					}
					<aiactor>5__7 = null;
					<i>5__6++;
				}
				((BeamController)<beamCont>5__3).Owner = (GameActor)(object)((BehaviorBase)<>4__this).m_aiActor;
				((BeamController)<beamCont>5__3).HitsPlayers = true;
				((BeamController)<beamCont>5__3).HitsEnemies = true;
				<beamCont>5__3.HeightOffset = 0f;
				<beamCont>5__3.RampHeightOffset = 0f;
				<beamCont>5__3.ContinueBeamArtToWall = true;
				<>8__1.enemyTickCooldown = 0f;
				<beamCont>5__3.OverrideHitChecks = delegate(SpeculativeRigidbody hitRigidbody, Vector2 dirVec)
				{
					//IL_015c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0116: Unknown result type (might be due to invalid IL or missing references)
					//IL_0128: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
					//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
					Projectile val = <>8__1.aibeamShooter2.beamModule.GetCurrentProjectile();
					if (<>8__1.<>4__this.UsesBeamProjectileWithoutModule)
					{
						val = <>8__1.aibeamShooter2.beamProjectile;
					}
					HealthHaver val2 = ((!Object.op_Implicit((Object)(object)hitRigidbody)) ? null : ((BraveBehaviour)hitRigidbody).healthHaver);
					if (Object.op_Implicit((Object)(object)hitRigidbody) && Object.op_Implicit((Object)(object)((BraveBehaviour)hitRigidbody).projectile) && Object.op_Implicit((Object)(object)((Component)hitRigidbody).GetComponent<BeholsterBounceRocket>()))
					{
						BounceProjModifier component = ((Component)hitRigidbody).GetComponent<BounceProjModifier>();
						if (Object.op_Implicit((Object)(object)component))
						{
							component.numberOfBounces = 0;
						}
						((BraveBehaviour)hitRigidbody).projectile.DieInAir(false, true, true, false);
					}
					if ((Object)(object)val2 != (Object)null)
					{
						if (Object.op_Implicit((Object)(object)((BraveBehaviour)val2).aiActor))
						{
							if (<>8__1.enemyTickCooldown <= 0f)
							{
								val2.ApplyDamage(ProjectileData.FixedFallbackDamageToEnemies, dirVec, ((BehaviorBase)<>8__1.<>4__this).m_aiActor.GetActorName(), val.damageTypes, (DamageCategory)0, false, (PixelCollider)null, false);
								<>8__1.enemyTickCooldown = 0.1f;
							}
						}
						else
						{
							val2.ApplyDamage(val.baseData.damage, dirVec, ((BehaviorBase)<>8__1.<>4__this).m_aiActor.GetActorName(), val.damageTypes, (DamageCategory)0, false, (PixelCollider)null, false);
						}
					}
					if (Object.op_Implicit((Object)(object)((BraveBehaviour)hitRigidbody).majorBreakable))
					{
						((BraveBehaviour)hitRigidbody).majorBreakable.ApplyDamage(26f * BraveTime.DeltaTime, dirVec, false, false, false);
					}
				};
				<firstFrame>5__5 = true;
				goto IL_04eb;
			case 1:
				<>1__state = -1;
				<firstFrame>5__5 = false;
				goto IL_04eb;
			case 2:
				<>1__state = -1;
				if (<>4__this.IsfiringLaser && !Object.op_Implicit((Object)(object)<beamCont>5__3))
				{
					<>4__this.StopFiringLaser();
					break;
				}
				goto IL_04d7;
			case 3:
				{
					<>1__state = -1;
					goto IL_04d7;
				}
				IL_04d7:
				if (Time.timeScale == 0f)
				{
					<>2__current = null;
					<>1__state = 3;
					return true;
				}
				goto IL_04eb;
				IL_04eb:
				if (!((Object)(object)<beamCont>5__3 != (Object)null) || !<>4__this.IsfiringLaser)
				{
					break;
				}
				<>8__1.enemyTickCooldown = Mathf.Max(<>8__1.enemyTickCooldown - BraveTime.DeltaTime, 0f);
				<flag4>5__8 = <>4__this.UsesCustomAngle && <>4__this.FiresDirectlyTowardsPlayer;
				if (<flag4>5__8)
				{
					<clampedAngle>5__9 = BraveMathCollege.ClampAngle360(<>8__1.aibeamShooter2.northAngleTolerance + ((BraveBehaviour)((BehaviorBase)<>4__this).m_aiActor).aiAnimator.FacingDirection + <>4__this.AlaserAngle);
				}
				else
				{
					<usesCustomAngle>5__13 = <>4__this.UsesCustomAngle;
					if (<usesCustomAngle>5__13)
					{
						<clampedAngle>5__9 = BraveMathCollege.ClampAngle360(<>8__1.aibeamShooter2.northAngleTolerance + <>4__this.AlaserAngle);
					}
					else
					{
						<firesDirectlyTowardsPlayer>5__14 = <>4__this.FiresDirectlyTowardsPlayer;
						if (<firesDirectlyTowardsPlayer>5__14)
						{
							<clampedAngle>5__9 = BraveMathCollege.ClampAngle360(((BraveBehaviour)((BehaviorBase)<>4__this).m_aiActor).aiAnimator.FacingDirection + <>4__this.AlaserAngle);
						}
						else
						{
							<clampedAngle>5__9 = BraveMathCollege.ClampAngle360(<>4__this.LaserAngle);
						}
					}
				}
				<dirVec2>5__10 = new Vector3(Mathf.Cos(<clampedAngle>5__9 * ((float)Math.PI / 180f)), Mathf.Sin(<clampedAngle>5__9 * ((float)Math.PI / 180f)), 0f) * 10f;
				<startingPoint>5__11 = Vector2.op_Implicit(<>8__1.aibeamShooter2.beamTransform.position);
				((BraveBehaviour)<>8__1.aibeamShooter2).sprite.HeightOffGround = -20f;
				((BeamController)<beamCont>5__3).Origin = <startingPoint>5__11;
				((BeamController)<beamCont>5__3).Direction = Vector2.op_Implicit(<dirVec2>5__10);
				<flag5>5__12 = <firstFrame>5__5;
				if (<flag5>5__12)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				((BeamController)<beamCont>5__3).LateUpdatePosition(Vector2.op_Implicit(<startingPoint>5__11));
				<>2__current = null;
				<>1__state = 2;
				return true;
			}
			if (!<>4__this.IsfiringLaser && (Object)(object)<beamCont>5__3 != (Object)null)
			{
				((BeamController)<beamCont>5__3).DestroyBeam();
				<beamCont>5__3 = null;
			}
			return false;
		}

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

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

	public bool m_laserActive;

	public bool IsfiringLaser;

	public float AlaserAngle;

	public BasicBeamController m_laserBeam;

	public VFXPool chargeUpVfx;

	public VFXPool chargeDownVfx;

	public ProjectileModule beamModule;

	public Transform beamTransform;

	public TrackingType trackingType;

	public float initialAimOffset;

	public float chargeTime;

	public float firingTime;

	public float maxTurnRate;

	public float turnRateAcceleration;

	public bool useDegreeCatchUp;

	public float minDegreesForCatchUp;

	public float degreeCatchUpSpeed;

	public bool useUnitCatchUp;

	public float minUnitForCatchUp;

	public float maxUnitForCatchUp;

	public float unitCatchUpSpeed;

	public bool useUnitOvershoot;

	public float minUnitForOvershoot;

	public float unitOvershootTime;

	public float unitOvershootSpeed;

	private State m_state;

	private float m_timer;

	private Vector2 m_targetPosition;

	private float m_currentUnitTurnRate;

	private float m_unitOvershootFixedDirection;

	private float m_unitOvershootTimer;

	private SpeculativeRigidbody m_backupTarget;

	private BulletScriptSource m_bulletSource;

	public bool HasTriggeredScript;

	public BulletScriptSelector BulletScript;

	public Transform ShootPoint;

	public bool FiresDirectlyTowardsPlayer;

	public bool UsesCustomAngle;

	public float CustomAngleValue;

	public string ChargeAnimation;

	public string FireAnimation;

	public string PostFireAnimation;

	public BeamSelection beamSelection;

	public AIBeamShooter2 specificBeamShooter;

	private List<AIBeamShooter2> m_allBeamShooters;

	private readonly List<AIBeamShooter2> m_currentBeamShooters = new List<AIBeamShooter2>();

	public string LaserFiringSound;

	public string StopLaserFiringSound;

	public string EnemyChargeSound;

	public string BeamChargingSound;

	public bool UsesBaseSounds;

	public bool LockInPlaceWhileAttacking;

	public bool UsesBeamProjectileWithoutModule;

	public Vector2 LaserFiringCenter => Vector3Extensions.XY(((BraveBehaviour)((BehaviorBase)this).m_aiActor).transform.position);

	public bool FiringLaser => IsfiringLaser;

	public bool LaserActive => m_laserActive;

	public float LaserAngle => AlaserAngle;

	public BasicBeamController LaserBeam => m_laserBeam;

	public override void Start()
	{
		((BasicAttackBehavior)this).Start();
		((BraveBehaviour)((BehaviorBase)this).m_aiActor).healthHaver.OnDeath += delegate
		{
			if ((Object)(object)m_laserBeam != (Object)null)
			{
				((BeamController)m_laserBeam).DestroyBeam();
				m_laserBeam = null;
			}
		};
	}

	private bool ShowSpecificBeamShooter()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		return (int)beamSelection == 2;
	}

	public void SetLaserAngle(float alaserAngle)
	{
		AlaserAngle = alaserAngle;
		if (IsfiringLaser)
		{
			((BraveBehaviour)((BehaviorBase)this).m_aiActor).aiAnimator.FacingDirection = alaserAngle;
		}
	}

	public override void Upkeep()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		((BasicAttackBehavior)this).Upkeep();
		if (Object.op_Implicit((Object)(object)((BehaviorBase)this).m_aiActor.TargetRigidbody))
		{
			m_targetPosition = ((BehaviorBase)this).m_aiActor.TargetRigidbody.GetUnitCenter((ColliderType)2);
			m_backupTarget = ((BehaviorBase)this).m_aiActor.TargetRigidbody;
		}
		else if (Object.op_Implicit((Object)(object)m_backupTarget))
		{
			m_targetPosition = m_backupTarget.GetUnitCenter((ColliderType)2);
		}
	}

	public override BehaviorResult Update()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Invalid comparison between Unknown and I4
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: 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_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Invalid comparison between Unknown and I4
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Invalid comparison between Unknown and I4
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Invalid comparison between Unknown and I4
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		((BasicAttackBehavior)this).Update();
		BehaviorResult val = ((BasicAttackBehavior)this).Update();
		if ((int)val > 0)
		{
			return val;
		}
		if (!((AttackBehaviorBase)this).IsReady())
		{
			return (BehaviorResult)0;
		}
		PrechargeFiringLaser();
		HasTriggeredScript = false;
		m_state = State.PreCharging;
		if (LockInPlaceWhileAttacking)
		{
			((BehaviorBase)this).m_aiActor.SuppressTargetSwitch = true;
			((BehaviorBase)this).m_aiActor.ClearPath();
		}
		((BehaviorBase)this).m_updateEveryFrame = true;
		m_allBeamShooters = new List<AIBeamShooter2>(((Component)((BehaviorBase)this).m_aiActor).GetComponents<AIBeamShooter2>());
		if ((int)beamSelection == 0)
		{
			List<AIBeamShooter2> list = new List<AIBeamShooter2>();
			Component[] components = ((Component)((BehaviorBase)this).m_aiActor).gameObject.GetComponents(typeof(AIBeamShooter2));
			for (int i = 0; i < components.Length; i++)
			{
				AIBeamShooter2 item = (AIBeamShooter2)(object)components[i];
				list.Add(item);
				m_currentBeamShooters.Add(item);
			}
		}
		else if ((int)beamSelection == 1)
		{
			m_currentBeamShooters.Add(BraveUtility.RandomElement<AIBeamShooter2>(m_allBeamShooters));
		}
		else if ((int)beamSelection == 2)
		{
			m_currentBeamShooters.Add(specificBeamShooter);
		}
		if (!string.IsNullOrEmpty(ChargeAnimation))
		{
			((BehaviorBase)this).m_aiAnimator.PlayUntilCancelled(ChargeAnimation, true, (string)null, -1f, false);
		}
		return (BehaviorResult)4;
	}

	public override ContinuousBehaviorResult ContinuousUpdate()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_043a: Unknown result type (might be due to invalid IL or missing references)
		((BehaviorBase)this).ContinuousUpdate();
		if (m_state == State.PreCharging)
		{
			if (!LaserActive)
			{
				ChargeFiringLaser(chargeTime);
				m_timer = chargeTime;
				m_state = State.Charging;
			}
		}
		else
		{
			if (m_state == State.Charging)
			{
				m_timer -= ((BehaviorBase)this).m_deltaTime;
				if (m_timer <= 0f)
				{
					m_state = State.Firing;
					StartFiringTheLaser();
					m_timer = firingTime;
				}
				return (ContinuousBehaviorResult)0;
			}
			if (m_state == State.Firing)
			{
				if (!HasTriggeredScript)
				{
					HasTriggeredScript = true;
					if (BulletScript != null && !BulletScript.IsNull)
					{
						if (!Object.op_Implicit((Object)(object)m_bulletSource))
						{
							m_bulletSource = GameObjectExtensions.GetOrAddComponent<BulletScriptSource>(((Component)ShootPoint).gameObject);
						}
						m_bulletSource.BulletManager = ((BraveBehaviour)((BehaviorBase)this).m_aiActor).bulletBank;
						m_bulletSource.BulletScript = BulletScript;
						m_bulletSource.Initialize();
					}
				}
				m_timer -= ((BehaviorBase)this).m_deltaTime;
				if (m_timer <= 0f || !FiringLaser)
				{
					if ((Object)(object)m_bulletSource != (Object)null)
					{
						m_bulletSource.ForceStop();
					}
					return (ContinuousBehaviorResult)1;
				}
				for (int i = 0; i < m_currentBeamShooters.Count; i++)
				{
					if (m_currentBeamShooters[0].IsFiringLaser)
					{
						continue;
					}
					AIBeamShooter2 aIBeamShooter = m_currentBeamShooters[i];
					Vector2 val = Vector2.op_Implicit(((BraveBehaviour)aIBeamShooter).transform.position);
					float alaserAngle;
					if (trackingType == TrackingType.Follow)
					{
						float num = Vector2.Distance(m_targetPosition, val);
						float num2 = Vector2Extensions.ToAngle(m_targetPosition - val);
						float num3 = BraveMathCollege.ClampAngle180(num2 - AlaserAngle);
						float num4 = num3 * num * ((float)Math.PI / 180f);
						float num5 = maxTurnRate;
						float num6 = Mathf.Sign(num3);
						if (m_unitOvershootTimer > 0f)
						{
							num6 = m_unitOvershootFixedDirection;
							m_unitOvershootTimer -= ((BehaviorBase)this).m_deltaTime;
							num5 = unitOvershootSpeed;
						}
						m_currentUnitTurnRate = Mathf.Clamp(m_currentUnitTurnRate + num6 * turnRateAcceleration * ((BehaviorBase)this).m_deltaTime, 0f - num5, num5);
						float num7 = m_currentUnitTurnRate / num * 57.29578f;
						float num8 = 0f;
						if (useDegreeCatchUp && Mathf.Abs(num3) > minDegreesForCatchUp)
						{
							float num9 = Mathf.InverseLerp(minDegreesForCatchUp, 180f, Mathf.Abs(num3)) * degreeCatchUpSpeed;
							num8 = Mathf.Max(num8, num9);
						}
						if (useUnitCatchUp && Mathf.Abs(num4) > minUnitForCatchUp)
						{
							float num10 = Mathf.InverseLerp(minUnitForCatchUp, maxUnitForCatchUp, Mathf.Abs(num4)) * unitCatchUpSpeed;
							float num11 = num10 / num * 57.29578f;
							num8 = Mathf.Max(num8, num11);
						}
						if (useUnitOvershoot && Mathf.Abs(num4) < minUnitForOvershoot)
						{
							m_unitOvershootFixedDirection = ((!(m_currentUnitTurnRate <= 0f)) ? 1 : (-1));
							m_unitOvershootTimer = unitOvershootTime;
						}
						num8 *= Mathf.Sign(num3);
						alaserAngle = BraveMathCollege.ClampAngle360(AlaserAngle + (num7 + num8) * ((BehaviorBase)this).m_deltaTime);
					}
					else
					{
						alaserAngle = BraveMathCollege.ClampAngle360(AlaserAngle + maxTurnRate * ((BehaviorBase)this).m_deltaTime);
					}
					if (IsfiringLaser)
					{
						AlaserAngle = alaserAngle;
					}
					return (ContinuousBehaviorResult)0;
				}
			}
		}
		return (ContinuousBehaviorResult)0;
	}

	public override void EndContinuousUpdate()
	{
		((BehaviorBase)this).EndContinuousUpdate();
		if (!string.IsNullOrEmpty(FireAnimation))
		{
			((BehaviorBase)this).m_aiAnimator.EndAnimationIf(FireAnimation);
		}
		StopFiringLaser();
		((BehaviorBase)this).m_aiAnimator.LockFacingDirection = false;
		((BehaviorBase)this).m_aiActor.SuppressTargetSwitch = false;
		((BehaviorBase)this).m_updateEveryFrame = false;
		((BasicAttackBehavior)this).UpdateCooldowns();
	}

	public override bool IsOverridable()
	{
		return false;
	}

	public void PrechargeFiringLaser()
	{
		((BraveBehaviour)((BehaviorBase)this).m_aiActor).aiAnimator.LockFacingDirection = true;
		if (EnemyChargeSound != null)
		{
			AkSoundEngine.PostEvent(EnemyChargeSound, ((Component)((BehaviorBase)this).m_aiActor).gameObject);
		}
		else if (UsesBaseSounds)
		{
			AkSoundEngine.PostEvent("Play_ENM_beholster_charging_01", ((Component)((BehaviorBase)this).m_aiActor).gameObject);
		}
	}

	public void ChargeFiringLaser(float time)
	{
		if (BeamChargingSound != null)
		{
			AkSoundEngine.PostEvent(BeamChargingSound, ((Component)((BehaviorBase)this).m_aiActor).gameObject);
		}
		else if (UsesBaseSounds)
		{
			AkSoundEngine.PostEvent("Play_ENM_beholster_charging_01", ((Component)((BehaviorBase)this).m_aiActor).gameObject);
		}
		m_laserActive = true;
	}

	public void StartFiringTheLaser()
	{
		float facingDirection = ((BraveBehaviour)((BehaviorBase)this).m_aiActor).aiAnimator.FacingDirection;
		IsfiringLaser = true;
		SetLaserAngle(facingDirection);
		((BraveBehaviour)((BehaviorBase)this).m_aiActor).aiAnimator.LockFacingDirection = true;
		AkSoundEngine.PostEvent("Play_ENM_deathray_shot_01", ((Component)((BehaviorBase)this).m_aiActor).gameObject);
		IsfiringLaser = true;
		((BraveBehaviour)((BehaviorBase)this).m_aiActor).aiAnimator.LockFacingDirection = true;
		MonoBehaviour component = ((Component)((BehaviorBase)this).m_aiActor).GetComponent<MonoBehaviour>();
		for (int i = 0; i < m_currentBeamShooters.Count; i++)
		{
			AIBeamShooter2 aibeamShooter = m_currentBeamShooters[i];
			component.StartCoroutine(FireBeam(aibeamShooter));
		}
	}

	public void StopFiringLaser()
	{
		if (IsfiringLaser)
		{
			if (!string.IsNullOrEmpty(PostFireAnimation))
			{
				((BehaviorBase)this).m_aiAnimator.PlayUntilFinished(PostFireAnimation, true, (string)null, -1f, false);
			}
			if (StopLaserFiringSound != null)
			{
				AkSoundEngine.PostEvent(StopLaserFiringSound, ((Component)((BehaviorBase)this).m_aiActor).gameObject);
			}
			else if (UsesBaseSounds)
			{
				AkSoundEngine.PostEvent("Stop_ENM_deathray_loop_01", ((Component)((BehaviorBase)this).m_aiActor).gameObject);
			}
			m_laserActive = false;
			IsfiringLaser = false;
			((BraveBehaviour)((BehaviorBase)this).m_aiActor).aiAnimator.LockFacingDirection = false;
			m_currentBeamShooters.Clear();
		}
	}

	protected IEnumerator FireBeam(AIBeamShooter2 aibeamShooter2)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <FireBeam>d__30(0)
		{
			<>4__this = this,
			aibeamShooter2 = aibeamShooter2
		};
	}
}
namespace SoundAPI
{
	public class CustomSwitchData
	{
		public string OriginalEventName;

		public string SwitchGroup;

		public string RequiredSwitch;

		public List<SwitchedEvent> ReplacementEvents;

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

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

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

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

		public static List<CustomSwitchData> CustomSwitchDatas;

		public static List<string> StopEvents;

		public static List<string> StopEventsMusic;

		public static List<string> StopEventsObjects;

		public static List<string> StopEventsWeapons;

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

		private static Hook SetSwitchHook;

		private static Hook PostEventPlayingIdHook;

		private static Hook PostEventExternalSourcesHook;

		private static Hook PostEventExternalsHook;

		private static Hook PostEventCallbackCookieHook;

		private static Hook PostEventFlagsHook;

		private static Hook PostEventHook;

		private static bool m_initialized;

		private static bool origSetSwitch;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		public string switchGroup;

		public string switchValue;

		public SwitchedEvent()
		{
		}

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

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

		public static implicit operator SwitchedEvent(string s)
		{
			return new SwitchedEvent(s);
		}
	}
}
namespace SaveAPI
{
	[fsObject]
	public class AdvancedGameStats
	{
		[fsProperty]
		private Dictionary<CustomTrackedStats, float> stats;

		[fsProperty]
		private Dictionary<CustomTrackedMaximums, float> maxima;

		[fsProperty]
		public HashSet<CustomCharacterSpecificGungeonFlags> m_flags;

		public AdvancedGameStats()
		{
			m_flags = new HashSet<CustomCharacterSpecificGungeonFlags>();
			stats = new Dictionary<CustomTrackedStats, float>(new CustomTrackedStatsComparer());
			maxima = new Dictionary<CustomTrackedMaximums, float>(new CustomTrackedMaximumsComparer());
		}

		public float GetStatValue(CustomTrackedStats statToCheck)
		{
			if (!stats.ContainsKey(statToCheck))
			{
				return 0f;
			}
			return stats[statToCheck];
		}

		public float GetMaximumValue(CustomTrackedMaximums maxToCheck)
		{
			if (!maxima.ContainsKey(maxToCheck))
			{
				return 0f;
			}
			return maxima[maxToCheck];
		}

		public bool GetFlag(CustomCharacterSpecificGungeonFlags flag)
		{
			if (flag == CustomCharacterSpecificGungeonFlags.NONE)
			{
				Debug.LogError((object)"Something is attempting to get a NONE character-specific save flag!");
				return false;
			}
			return m_flags.Contains(flag);
		}

		public void SetStat(CustomTrackedStats stat, float val)
		{
			if (stats.ContainsKey(stat))
			{
				stats[stat] = val;
			}
			else
			{
				stats.Add(stat, val);
			}
		}

		public void SetMax(CustomTrackedMaximums max, float val)
		{
			if (maxima.ContainsKey(max))
			{
				maxima[max] = Mathf.Max(maxima[max], val);
			}
			else
			{
				maxima.Add(max, val);
			}
		}

		public void SetFlag(CustomCharacterSpecificGungeonFlags flag, bool value)
		{
			if (flag == CustomCharacterSpecificGungeonFlags.NONE)
			{
				Debug.LogError((object)"Something is attempting to set a NONE character-specific save flag!");
			}
			else if (value)
			{
				m_flags.Add(flag);
			}
			else
			{
				m_flags.Remove(flag);
			}
		}

		public void IncrementStat(CustomTrackedStats stat, float val)
		{
			if (stats.ContainsKey(stat))
			{
				stats[stat] += val;
			}
			else
			{
				stats.Add(stat, val);
			}
		}

		public void AddStats(AdvancedGameStats otherStats)
		{
			foreach (KeyValuePair<CustomTrackedStats, float> stat in otherStats.stats)
			{
				IncrementStat(stat.Key, stat.Value);
			}
			foreach (KeyValuePair<CustomTrackedMaximums, float> item in otherStats.maxima)
			{
				SetMax(item.Key, item.Value);
			}
			foreach (CustomCharacterSpecificGungeonFlags flag in otherStats.m_flags)
			{
				m_flags.Add(flag);
			}
		}

		public void ClearAllState()
		{
			List<CustomTrackedStats> list = new List<CustomTrackedStats>();
			foreach (KeyValuePair<CustomTrackedStats, float> stat in stats)
			{
				list.Add(stat.Key);
			}
			foreach (CustomTrackedStats item in list)
			{
				stats[item] = 0f;
			}
			List<CustomTrackedMaximums> list2 = new List<CustomTrackedMaximums>();
			foreach (KeyValuePair<CustomTrackedMaximums, float> item2 in maxima)
			{
				list2.Add(item2.Key);
			}
			foreach (CustomTrackedMaximums item3 in list2)
			{
				maxima[item3] = 0f;
			}
		}
	}
	[fsObject]
	internal class AdvancedGameStatsManager
	{
		private static AdvancedGameStatsManager m_instance;

		[fsProperty]
		public HashSet<CustomDungeonFlags> m_flags;

		[fsProperty]
		public string midGameSaveGuid;

		[fsProperty]
		public Dictionary<PlayableCharacters, AdvancedGameStats> m_characterStats;

		private AdvancedGameStats m_sessionStats;

		private AdvancedGameStats m_savedSessionStats;

		private PlayableCharacters m_sessionCharacter;

		private int m_numCharacters;

		[fsIgnore]
		public int cachedHuntIndex;

		[fsIgnore]
		public SaveSlot cachedSaveSlot;

		[fsIgnore]
		public bool IsInSession => m_sessionStats != null;

		public static bool HasInstance => m_instance != null;

		public static AdvancedGameStatsManager Instance => m_instance;

		public AdvancedGameStatsManager()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			m_flags = new HashSet<CustomDungeonFlags>(new CustomDungeonFlagsComparer());
			m_characterStats = new Dictionary<PlayableCharacters, AdvancedGameStats>((IEqualityComparer<PlayableCharacters>?)new PlayableCharactersComparer());
			m_numCharacters = -1;
			cachedHuntIndex = -1;
		}

		public static void Unload()
		{
			m_instance = null;
		}

		public void SetCharacterSpecificFlag(PlayableCharacters character, CustomCharacterSpecificGungeonFlags flag, bool value)
		{
			//IL_001d: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (flag == CustomCharacterSpecificGungeonFlags.NONE)
			{
				Debug.LogError((object)"Something is attempting to set a NONE character-specific save flag!");
				return;
			}
			if (!m_characterStats.ContainsKey(character))
			{
				m_characterStats.Add(character, new AdvancedGameStats());
			}
			if (m_sessionStats != null && m_sessionCharacter == character)
			{
				m_sessionStats.SetFlag(flag, value);
			}
			else
			{
				m_characterStats[character].SetFlag(flag, value);
			}
		}

		public void SetStat(CustomTrackedStats stat, float value)
		{
			if (!float.IsNaN(value) && !float.IsInfinity(value) && m_sessionStats != null)
			{
				m_sessionStats.SetStat(stat, value);
			}
		}

		public void UpdateMaximum(CustomTrackedMaximums maximum, float val)
		{
			if (!float.IsNaN(val) && !float.IsInfinity(val) && m_sessionStats != null)
			{
				m_sessionStats.SetMax(maximum, val);
			}
		}

		public bool GetCharacterSpecificFlag(CustomCharacterSpecificGungeonFlags flag)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return GetCharacterSpecificFlag(m_sessionCharacter, flag);
		}

		public bool GetCharacterSpecificFlag(PlayableCharacters character, CustomCharacterSpecificGungeonFlags flag)
		{
			//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_0067: Unknown result type (might be due to invalid IL or missing references)
			if (flag == CustomCharacterSpecificGungeonFlags.NONE)
			{
				Debug.LogError((object)"Something is attempting to get a NONE character-specific save flag!");
				return false;
			}
			if (m_sessionStats != null && m_sessionCharacter == character)
			{
				if (m_sessionStats.GetFlag(flag))
				{
					return true;
				}
				if (m_savedSessionStats.GetFlag(flag))
				{
					return true;
				}
			}
			AdvancedGameStats value;
			return m_characterStats.TryGetValue(character, out value) && value.GetFlag(flag);
		}

		public static void DoMidgameSave()
		{
			string text = Guid.NewGuid().ToString();
			AdvancedMidGameSaveData advancedMidGameSaveData = new AdvancedMidGameSaveData(text);
			SaveManager.Save<AdvancedMidGameSaveData>(advancedMidGameSaveData, SaveAPIManager.AdvancedMidGameSave, GameStatsManager.Instance.PlaytimeMin, 0u, (SaveSlot?)null);
			Instance.midGameSaveGuid = text;
			Save();
		}

		public void RegisterStatChange(CustomTrackedStats stat, float value)
		{
			if (m_sessionStats == null)
			{
				Debug.LogError((object)"No session stats active and we're registering a stat change!");
			}
			else if (!float.IsNaN(value) && !float.IsInfinity(value) && !(Mathf.Abs(value) > 10000f))
			{
				m_sessionStats.IncrementStat(stat, value);
			}
		}

		public static void InvalidateMidgameSave(bool saveStats)
		{
			AdvancedMidGameSaveData midgameSave = null;
			if (VerifyAndLoadMidgameSave(out midgameSave, checkValidity: false))
			{
				midgameSave.Invalidate();
				SaveManager.Save<AdvancedMidGameSaveData>(midgameSave, SaveAPIManager.AdvancedMidGameSave, GameStatsManager.Instance.PlaytimeMin, 0u, (SaveSlot?)null);
				GameStatsManager.Instance.midGameSaveGuid = midgameSave.midGameSaveGuid;
				if (saveStats)
				{
					GameStatsManager.Save();
				}
			}
		}

		public static void RevalidateMidgameSave(bool saveStats)
		{
			AdvancedMidGameSaveData midgameSave = null;
			if (VerifyAndLoadMidgameSave(out midgameSave, checkValidity: false))
			{
				midgameSave.Revalidate();
				SaveManager.Save<AdvancedMidGameSaveData>(midgameSave, SaveAPIManager.AdvancedMidGameSave, GameStatsManager.Instance.PlaytimeMin, 0u, (SaveSlot?)null);
				GameStatsManager.Instance.midGameSaveGuid = midgameSave.midGameSaveGuid;
				if (saveStats)
				{
					GameStatsManager.Save();
				}
			}
		}

		public static bool VerifyAndLoadMidgameSave(out AdvancedMidGameSaveData midgameSave, bool checkValidity = true)
		{
			if (!SaveManager.Load<AdvancedMidGameSaveData>(SaveAPIManager.AdvancedGameSave, ref midgameSave, true, 0u, (Func<string, uint, string>)null, (SaveSlot?)null))
			{
				Debug.LogError((object)"No mid game save found");
				return false;
			}
			if (midgameSave == null)
			{
				Debug.LogError((object)"Failed to load mid game save (0)");
				return false;
			}
			if (checkValidity && !midgameSave.IsValid())
			{
				return false;
			}
			if (GameStatsManager.Instance.midGameSaveGuid == null || GameStatsManager.Instance.midGameSaveGuid != midgameSave.midGameSaveGuid)
			{
				Debug.LogError((object)"Failed to load mid game save (1)");
				return false;
			}
			return true;
		}

		public void ClearAllStatsGlobal()
		{
			m_sessionStats.ClearAllState();
			m_savedSessionStats.ClearAllState();
			if (m_numCharacters <= 0)
			{
				m_numCharacters = Enum.GetValues(typeof(PlayableCharacters)).Length;
			}
			for (int i = 0; i < m_numCharacters; i++)
			{
				if (m_characterStats.TryGetValue((PlayableCharacters)i, out var value))
				{
					value.ClearAllState();
				}
			}
		}

		public void ClearStatValueGlobal(CustomTrackedStats stat)
		{
			m_sessionStats.SetStat(stat, 0f);
			m_savedSessionStats.SetStat(stat, 0f);
			if (m_numCharacters <= 0)
			{
				m_numCharacters = Enum.GetValues(typeof(PlayableCharacters)).Length;
			}
			for (int i = 0; i < m_numCharacters; i++)
			{
				if (m_characterStats.TryGetValue((PlayableCharacters)i, out var value))
				{
					value.SetStat(stat, 0f);
				}
			}
		}

		private PlayableCharacters GetCurrentCharacter()
		{
			//IL_000b: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			return GameManager.Instance.PrimaryPlayer.characterIdentity;
		}

		public float GetPlayerMaximum(CustomTrackedMaximums maximum)
		{
			if (m_numCharacters <= 0)
			{
				m_numCharacters = Enum.GetValues(typeof(PlayableCharacters)).Length;
			}
			float num = 0f;
			if (m_sessionStats != null)
			{
				num = Mathf.Max(new float[3]
				{
					num,
					m_sessionStats.GetMaximumValue(maximum),
					m_savedSessionStats.GetMaximumValue(maximum)
				});
			}
			for (int i = 0; i < m_numCharacters; i++)
			{
				if (m_characterStats.TryGetValue((PlayableCharacters)i, out var value))
				{
					num = Mathf.Max(num, value.GetMaximumValue(maximum));
				}
			}
			return num;
		}

		public float GetPlayerStatValue(CustomTrackedStats stat)
		{
			if (m_numCharacters <= 0)
			{
				m_numCharacters = Enum.GetValues(typeof(PlayableCharacters)).Length;
			}
			float num = 0f;
			if (m_sessionStats != null)
			{
				num += m_sessionStats.GetStatValue(stat);
			}
			for (int i = 0; i < m_numCharacters; i++)
			{
				if (m_characterStats.TryGetValue((PlayableCharacters)i, out var value))
				{
					num += value.GetStatValue(stat);
				}
			}
			return num;
		}

		public void SetCharacterSpecificFlag(CustomCharacterSpecificGungeonFlags flag, bool value)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			SetCharacterSpecificFlag(m_sessionCharacter, flag, value);
		}

		public float GetSessionStatValue(CustomTrackedStats stat)
		{
			return m_sessionStats.GetStatValue(stat) + m_savedSessionStats.GetStatValue(stat);
		}

		public float GetCharacterStatValue(CustomTrackedStats stat)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return GetCharacterStatValue(GetCurrentCharacter(), stat);
		}

		public AdvancedGameStats MoveSessionStatsToSavedSessionStats()
		{
			//IL_0028: 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)
			if (!IsInSession)
			{
				return null;
			}
			if (m_sessionStats != null)
			{
				if (m_characterStats.ContainsKey(m_sessionCharacter))
				{
					m_characterStats[m_sessionCharacter].AddStats(m_sessionStats);
				}
				m_savedSessionStats.AddStats(m_sessionStats);
				m_sessionStats.ClearAllState();
			}
			return m_savedSessionStats;
		}

		public float GetCharacterStatValue(PlayableCharacters character, CustomTrackedStats stat)
		{
			//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)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			if (m_sessionCharacter == character)
			{
				num += m_sessionStats.GetStatValue(stat);
			}
			if (m_characterStats.ContainsKey(character))
			{
				num += m_characterStats[character].GetStatValue(stat);
			}
			return num;
		}

		public void BeginNewSession(PlayerController player)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			//IL_00ae: 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 (m_characterStats == null)
			{
				m_characterStats = new Dictionary<PlayableCharacters, AdvancedGameStats>((IEqualityComparer<PlayableCharacters>?)new PlayableCharactersComparer());
			}
			if (IsInSession)
			{
				m_sessionCharacter = player.characterIdentity;
				if (!m_characterStats.ContainsKey(player.characterIdentity))
				{
					m_characterStats.Add(player.characterIdentity, new AdvancedGameStats());
				}
				return;
			}
			m_sessionCharacter = player.characterIdentity;
			m_sessionStats = new AdvancedGameStats();
			m_savedSessionStats = new AdvancedGameStats();
			if (!m_characterStats.ContainsKey(player.characterIdentity))
			{
				m_characterStats.Add(player.characterIdentity, new AdvancedGameStats());
			}
		}

		public void EndSession(bool recordSessionStats)
		{
			//IL_002c: 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)
			if (IsInSession && m_sessionStats != null)
			{
				if (recordSessionStats && m_characterStats.ContainsKey(m_sessionCharacter))
				{
					m_characterStats[m_sessionCharacter].AddStats(m_sessionStats);
				}
				m_sessionStats = null;
				m_savedSessionStats = null;
			}
		}

		public static void Load()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			SaveManager.Init();
			bool flag = false;
			SaveSlot? val = null;
			int num = -1;
			if (m_instance != null)
			{
				flag = true;
				val = m_instance.cachedSaveSlot;
				num = m_instance.cachedHuntIndex;
			}
			if (!SaveManager.Load<AdvancedGameStatsManager>(SaveAPIManager.AdvancedGameSave, ref m_instance, true, 0u, (Func<string, uint, string>)null, (SaveSlot?)null))
			{
				m_instance = new AdvancedGameStatsManager();
			}
			m_instance.cachedSaveSlot = SaveManager.CurrentSaveSlot;
			if (flag && val.HasValue && m_instance.cachedSaveSlot == val.Value)
			{
				m_instance.cachedHuntIndex = num;
			}
			else
			{
				m_instance.cachedHuntIndex = -1;
			}
		}

		public static void DANGEROUS_ResetAllStats()
		{
			m_instance = new AdvancedGameStatsManager();
			SaveManager.DeleteAllBackups(SaveAPIManager.AdvancedGameSave, (SaveSlot?)null);
		}

		public bool GetFlag(CustomDungeonFlags flag)
		{
			if (flag == CustomDungeonFlags.NONE)
			{
				Debug.LogError((object)"Something is attempting to get a NONE save flag!");
				return false;
			}
			return m_flags.Contains(flag);
		}

		public void SetFlag(CustomDungeonFlags flag, bool value)
		{
			if (flag == CustomDungeonFlags.NONE)
			{
				Debug.LogError((object)"Something is attempting to set a NONE save flag!");
			}
			else if (value)
			{
				m_flags.Add(flag);
			}
			else
			{
				m_flags.Remove(flag);
			}
		}

		public static bool Save()
		{
			bool result = false;
			try
			{
				result = SaveManager.Save<AdvancedGameStatsManager>(m_instance, SaveAPIManager.AdvancedGameSave, GameStatsManager.Instance.PlaytimeMin, 0u, (SaveSlot?)null);
			}
			catch (Exception ex)
			{
				Debug.LogErrorFormat("SAVE FAILED: {0}", new object[1] { ex });
			}
			return result;
		}

		public void AssignMidGameSavedSessionStats(AdvancedGameStats source)
		{
			if (IsInSession && m_savedSessionStats != null)
			{
				m_savedSessionStats.AddStats(source);
			}
		}
	}
	public class AdvancedMidGameSaveData
	{
		[fsProperty]
		public AdvancedGameStats PriorSessionStats;

		[fsProperty]
		public string midGameSaveGuid;

		[fsProperty]
		public bool invalidated;

		public AdvancedMidGameSaveData(string midGameSaveGuid)
		{
			this.midGameSaveGuid = midGameSaveGuid;
			PriorSessionStats = AdvancedGameStatsManager.Instance.MoveSessionStatsToSavedSessionStats();
		}

		public bool IsValid()
		{
			return !invalidated;
		}

		public void Invalidate()
		{
			invalidated = true;
		}

		public void Revalidate()
		{
			invalidated = false;
		}

		public void LoadDataFromMidGameSave()
		{
			AdvancedGameStatsManager.Instance.AssignMidGameSavedSessionStats(PriorSessionStats);
		}
	}
	public static class BreachShopTool
	{
		public class DoubleMetaShopTier
		{
			private MetaShopTier m_topTier;

			private MetaShopTier m_bottomTier;

			public DoubleMetaShopTier(MetaShopTier topTier, MetaShopTier bottomTier)
			{
				m_topTier = topTier;
				m_bottomTier = bottomTier;
			}

			public DoubleMetaShopTier(DoubleMetaShopTier other)
			{
				m_topTier = other.m_topTier;
				m_bottomTier = other.m_bottomTier;
			}

			public MetaShopTier GetTopTier()
			{
				return m_topTier;
			}

			public MetaShopTier GetBottomTier()
			{
				return m_topTier;
			}

			public List<MetaShopTier> GetTierList()
			{
				return new List<MetaShopTier> { m_topTier, m_bottomTier };
			}
		}

		public static MetaShopController BaseMetaShopController;

		public static GenericLootTable TrorcMetaShopItems;

		public static GenericLootTable GooptonMetaShopItems;

		public static GenericLootTable DougMetaShopItems;

		private static FieldInfo ItemControllersInfo = typeof(ShopController).GetField("m_itemControllers", BindingFlags.Instance | BindingFlags.NonPublic);

		private static FieldInfo BaseItemControllersInfo = typeof(BaseShopController).GetField("m_itemControllers", BindingFlags.Instance | BindingFlags.NonPublic);

		private static Hook pickupObjectEncounterableHook;

		private static Hook baseShopSetupHook;

		private static Hook metaShopSetupHook;

		private static Hook metaShopCurrentTierHook;

		private static Hook metaShopProximateTierHook;

		public static Dictionary<WeightedGameObjectCollection, List<WeightedGameObject>> baseShopAddedItems;

		public static List<MetaShopTier> metaShopAddedTiers;

		private static bool m_loaded;

		public static void DoSetup()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			if (!m_loaded)
			{
				BaseMetaShopController = SaveTools.LoadAssetFromAnywhere<GameObject>("Foyer_MetaShop").GetComponent<MetaShopController>();
				TrorcMetaShopItems = SaveTools.LoadAssetFromAnywhere<GenericLootTable>("Shop_Truck_Meta");
				GooptonMetaShopItems = SaveTools.LoadAssetFromAnywhere<GenericLootTable>("Shop_Goop_Meta");
				DougMetaShopItems = SaveTools.LoadAssetFromAnywhere<GenericLootTable>("Shop_Beetle_Meta");
				pickupObjectEncounterableHook = new Hook((MethodBase)typeof(PickupObject).GetMethod("HandleEncounterable", BindingFlags.Instance | BindingFlags.NonPublic), typeof(BreachShopTool).GetMethod("HandleEncounterableHook"));
				baseShopSetupHook = new Hook((MethodBase)typeof(BaseShopController).GetMethod("DoSetup", BindingFlags.Instance | BindingFlags.NonPublic), typeof(BreachShopTool).GetMethod("BaseShopSetupHook"));
				metaShopSetupHook = new Hook((MethodBase)typeof(MetaShopController).GetMethod("DoSetup", BindingFlags.Instance | BindingFlags.NonPublic), typeof(BreachShopTool).GetMethod("MetaSetupHook"));
				metaShopCurrentTierHook = new Hook((MethodBase)typeof(MetaShopController).GetMethod("GetCurrentTier", BindingFlags.Instance | BindingFlags.NonPublic), typeof(BreachShopTool).GetMethod("MetaShopCurrentTierHook"));
				metaShopProximateTierHook = new Hook((MethodBase)typeof(MetaShopController).GetMethod("GetProximateTier", BindingFlags.Instance | BindingFlags.NonPublic), typeof(BreachShopTool).GetMethod("MetaShopProximateTierHook"));
				m_loaded = true;
			}
		}

		public static void Unload()
		{
			if (!m_loaded)
			{
				return;
			}
			if (baseShopAddedItems != null)
			{
				for (int i = 0; i < baseShopAddedItems.Keys.Count; i++)
				{
					WeightedGameObjectCollection val = baseShopAddedItems.Keys.ToList()[i];
					if (val == null || baseShopAddedItems[val] == null)
					{
						continue;
					}
					for (int j = 0; j < baseShopAddedItems[val].Count; j++)
					{
						WeightedGameObject val2 = baseShopAddedItems[val][j];
						if (val2 != null && val.elements.Contains(val2))
						{
							val.elements.Remove(val2);
						}
					}
				}
				baseShopAddedItems.Clear();
				baseShopAddedItems = null;
			}
			if (metaShopAddedTiers != null)
			{
				for (int k = 0; k < metaShopAddedTiers.Count; k++)
				{
					MetaShopTier val3 = metaShopAddedTiers[k];
					if (val3 != null && BaseMetaShopController.metaShopTiers.Contains(val3))
					{
						BaseMetaShopController.metaShopTiers.Remove(val3);
					}
				}
				metaShopAddedTiers.Clear();
				metaShopAddedTiers = null;
			}
			BaseMetaShopController = null;
			TrorcMetaShopItems = null;
			GooptonMetaShopItems = null;
			DougMetaShopItems = null;
			Hook obj = pickupObjectEncounterableHook;
			if (obj != null)
			{
				obj.Dispose();
			}
			Hook obj2 = baseShopSetupHook;
			if (obj2 != null)
			{
				obj2.Dispose();
			}
			Hook obj3 = metaShopSetupHook;
			if (obj3 != null)
			{
				obj3.Dispose();
			}
			Hook obj4 = metaShopCurrentTierHook;
			if (obj4 != null)
			{
				obj4.Dispose();
			}
			Hook obj5 = metaShopProximateTierHook;
			if (obj5 != null)
			{
				obj5.Dispose();
			}
			m_loaded = false;
		}

		public static void HandleEncounterableHook(Action<PickupObject, PlayerController> orig, PickupObject po, PlayerController player)
		{
			orig(po, player);
			if ((Object)(object)po != (Object)null && (Object)(object)((Component)po).GetComponent<SpecialPickupObject>() != (Object)null && ((Component)po).GetComponent<SpecialPickupObject>().CustomSaveFlagToSetOnAcquisition != 0)
			{
				AdvancedGameStatsManager.Instance.SetFlag(((Component)po).GetComponent<SpecialPickupObject>().CustomSaveFlagToSetOnAcquisition, value: true);
			}
		}

		public static void BaseShopSetupHook(Action<BaseShopController> orig, BaseShopController self)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			orig(self);
			if ((int)self.baseShopType != 6 || !((Object)(object)self.ExampleBlueprintPrefab != (Object)null))
			{
				return;
			}
			List<ShopItemController> list = (List<ShopItemController>)BaseItemControllersInfo.GetValue(self);
			if (list == null)
			{
				return;
			}
			foreach (ShopItemController item in list)
			{
				if (!((Object)(object)item != (Object)null) || !((Object)(object)item.item != (Object)null) || !((Object)(object)((BraveBehaviour)item.item).encounterTrackable != (Object)null) || ((BraveBehaviour)item.item).encounterTrackable.journalData == null)
				{
					continue;
				}
				PickupObject blueprintUnlockedItem = GetBlueprintUnlockedItem(((BraveBehaviour)item.item).encounterTrackable);
				if (!((Object)(object)blueprintUnlockedItem != (Object)null) || !((Object)(object)((BraveBehaviour)blueprintUnlockedItem).encounterTrackable != (Object)null) || ((BraveBehaviour)blueprintUnlockedItem).encounterTrackable.prerequisites == null)
				{
					continue;
				}
				CustomDungeonFlags customDungeonFlags = CustomDungeonFlags.NONE;
				for (int i = 0; i < ((BraveBehaviour)blueprintUnlockedItem).encounterTrackable.prerequisites.Length; i++)
				{
					if (((BraveBehaviour)blueprintUnlockedItem).encounterTrackable.prerequisites[i] is CustomDungeonPrerequisite && (((BraveBehaviour)blueprintUnlockedItem).encounterTrackable.prerequisites[i] as CustomDungeonPrerequisite).advancedPrerequisiteType == CustomDungeonPrerequisite.AdvancedPrerequisiteType.CUSTOM_FLAG)
					{
						customDungeonFlags = (((BraveBehaviour)blueprintUnlockedItem).encounterTrackable.prerequisites[i] as CustomDungeonPrerequisite).customFlagToCheck;
					}
				}
				if (customDungeonFlags != 0)
				{
					((Component)item.item).gameObject.AddComponent<SpecialPickupObject>().CustomSaveFlagToSetOnAcquisition = customDungeonFlags;
				}
			}
		}

		public static void MetaSetupHook(Action<MetaShopController> orig, MetaShopController meta)
		{
			orig(meta);
			List<ShopItemController> list = (List<ShopItemController>)ItemControllersInfo.GetValue(meta);
			if (list == null)
			{
				return;
			}
			foreach (ShopItemController item in list)
			{
				if (!((Object)(object)item != (Object)null) || !((Object)(object)item.item != (Object)null) || !((Object)(object)((BraveBehaviour)item.item).encounterTrackable != (Object)null) || ((BraveBehaviour)item.item).encounterTrackable.journalData == null)
				{
					continue;
				}
				PickupObject blueprintUnlockedItem = GetBlueprintUnlockedItem(((BraveBehaviour)item.item).encounterTrackable);
				if (!((Object)(object)blueprintUnlockedItem != (Object)null) || !((Object)(object)((BraveBehaviour)blueprintUnlockedItem).encounterTrackable != (Object)null) || ((BraveBehaviour)blueprintUnlockedItem).encounterTrackable.prerequisites == null)
				{
					continue;
				}
				CustomDungeonFlags customFlagFromTargetItem = GetCustomFlagFromTargetItem(blueprintUnlockedItem.PickupObjectId);
				if (customFlagFromTargetItem != 0)
				{
					((Component)item.item).gameObject.AddComponent<SpecialPickupObject>().CustomSaveFlagToSetOnAcquisition = customFlagFromTargetItem;
					if (AdvancedGameStatsManager.Instance.GetFlag(customFlagFromTargetItem))
					{
						item.ForceOutOfStock();
					}
				}
			}
		}

		private static bool GetMetaItemUnlockedAdvanced(int pickupObjectId)
		{
			CustomDungeonFlags customFlagFromTargetItem = GetCustomFlagFromTargetItem(pickupObjectId);
			if (customFlagFromTargetItem == CustomDungeonFlags.NONE)
			{
				return true;
			}
			return AdvancedGameStatsManager.Instance.GetFlag(customFlagFromTargetItem);
		}

		public static MetaShopTier MetaShopCurrentTierHook(Func<MetaShopController, MetaShopTier> orig, MetaShopController self)
		{
			MetaShopTier val = null;
			for (int i = 0; i < self.metaShopTiers.Count; i++)
			{
				if (!GetMetaItemUnlockedAdvanced(self.metaShopTiers[i].itemId1) || !GetMetaItemUnlockedAdvanced(self.metaShopTiers[i].itemId2) || !GetMetaItemUnlockedAdvanced(self.metaShopTiers[i].itemId3))
				{
					val = self.metaShopTiers[i];
					break;
				}
			}
			List<MetaShopTier> metaShopTiers = self.metaShopTiers;
			List<MetaShopTier> list = new List<MetaShopTier>();
			for (int j = 0; j < metaShopTiers.Count; j++)
			{
				if (metaShopTiers[j] != null && (!ItemConditionsFulfilled(metaShopTiers[j].itemId1) || !ItemConditionsFulfilled(metaShopTiers[j].itemId2) || !ItemConditionsFulfilled(metaShopTiers[j].itemId3) || j == metaShopTiers.Count - 1))
				{
					list.Add(metaShopTiers[j]);
				}
			}
			self.metaShopTiers = list;
			MetaShopTier val2 = orig(self);
			self.metaShopTiers = metaShopTiers;
			if (val == null)
			{
				return val2;
			}
			if (val2 == null)
			{
				return val;
			}
			return (self.metaShopTiers.IndexOf(val) < self.metaShopTiers.IndexOf(val2)) ? val : val2;
		}

		public static MetaShopTier MetaShopProximateTierHook(Func<MetaShopController, MetaShopTier> orig, MetaShopController self)
		{
			MetaShopTier val = null;
			for (int i = 0; i < self.metaShopTiers.Count - 1; i++)
			{
				if (!GetMetaItemUnlockedAdvanced(self.metaShopTiers[i].itemId1) || !GetMetaItemUnlockedAdvanced(self.metaShopTiers[i].itemId2) || !GetMetaItemUnlockedAdvanced(self.metaShopTiers[i].itemId3))
				{
					val = self.metaShopTiers[i + 1];
					break;
				}
			}
			List<MetaShopTier> metaShopTiers = self.metaShopTiers;
			List<MetaShopTier> list = new List<MetaShopTier>();
			for (int j = 0; j < metaShopTiers.Count; j++)
			{
				if (metaShopTiers[j] != null && (!ItemConditionsFulfilled(metaShopTiers[j].itemId1) || !ItemConditionsFulfilled(metaShopTiers[j].itemId2) || !ItemConditionsFulfilled(metaShopTiers[j].itemId3)))
				{
					list.Add(metaShopTiers[j]);
				}
			}
			self.metaShopTiers = list;
			MetaShopTier val2 = orig(self);
			self.metaShopTiers = metaShopTiers;
			if (val == null)
			{
				return val2;
			}
			if (val2 == null)
			{
				return val;
			}
			return (self.metaShopTiers.IndexOf(val) < self.metaShopTiers.IndexOf(val2)) ? val : val2;
		}

		public static CustomDungeonFlags GetCustomFlagFromTargetItem(int shopItemId)
		{
			CustomDungeonFlags result = CustomDungeonFlags.NONE;
			PickupObject byId = PickupObjectDatabase.GetById(shopItemId);
			for (int i = 0; i < ((BraveBehaviour)byId).encounterTrackable.prerequisites.Length; i++)
			{
				if (((BraveBehaviour)byId).encounterTrackable.prerequisites[i] is CustomDungeonPrerequisite && (((BraveBehaviour)byId).encounterTrackable.prerequisites[i] as CustomDungeonPrerequisite).advancedPrerequisiteType == CustomDungeonPrerequisite.AdvancedPrerequisiteType.CUSTOM_FLAG)
				{
					result = (((BraveBehaviour)byId).encounterTrackable.prerequisites[i] as CustomDungeonPrerequisite).customFlagToCheck;
				}
			}
			return result;
		}

		public static GungeonFlags GetFlagFromTargetItem(int shopItemId)
		{
			//IL_0002: 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: Invalid comparison between Unknown and I4
			//IL_0058: 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_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_005d: Unknown result type (might be due to invalid IL or missing references)
			GungeonFlags result = (GungeonFlags)0;
			PickupObject byId = PickupObjectDatabase.GetById(shopItemId);
			for (int i = 0; i < ((BraveBehaviour)byId).encounterTrackable.prerequisites.Length; i++)
			{
				if ((int)((BraveBehaviour)byId).encounterTrackable.prerequisites[i].prerequisiteType == 4)
				{
					result = ((BraveBehaviour)byId).encounterTrackable.prerequisites[i].saveFlagToCheck;
				}
			}
			return result;
		}

		public static bool ItemConditionsFulfilled(int shopItemId)
		{
			return (Object)(object)PickupObjectDatabase.GetById(shopItemId) != (Object)null && PickupObjectDatabase.GetById(shopItemId).PrerequisitesMet();
		}

		public static PickupObject GetBlueprintUnlockedItem(EncounterTrackable blueprintTrackable)
		{
			for (int i = 0; i < ((ObjectDatabase<PickupObject>)(object)PickupObjectDatabase.Instance).Objects.Count; i++)
			{
				PickupObject val = ((ObjectDatabase<PickupObject>)(object)PickupObjectDatabase.Instance).Objects[i];
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				EncounterTrackable encounterTrackable = ((BraveBehaviour)val).encounterTrackable;
				if (!Object.op_Implicit((Object)(object)encounterTrackable))
				{
					continue;
				}
				string primaryDisplayName = encounterTrackable.journalData.PrimaryDisplayName;
				if (!primaryDisplayName.Equals(blueprintTrackable.journalData.PrimaryDisplayName, StringComparison.OrdinalIgnoreCase))
				{
					continue;
				}
				string notificationPanelDescription = encounterTrackable.journalData.NotificationPanelDescription;
				if (!notificationPanelDescription.Equals(blueprintTrackable.journalData.NotificationPanelDescription, StringComparison.OrdinalIgnoreCase))
				{
					continue;
				}
				string ammonomiconFullEntry = encounterTrackable.journalData.AmmonomiconFullEntry;
				if (ammonomiconFullEntry.Equals(blueprintTrackable.journalData.AmmonomiconFullEntry, StringComparison.OrdinalIgnoreCase))
				{
					string ammonomiconSprite = encounterTrackable.journalData.AmmonomiconSprite;
					if (ammonomiconSprite.Equals(blueprintTrackable.journalData.AmmonomiconSprite, StringComparison.OrdinalIgnoreCase))
					{
						return val;
					}
				}
			}
			return null;
		}

		public static WeightedGameObject AddItemToTrorcMetaShop(this PickupObject po, int cost, int? index = null)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if ((Object)(object)TrorcMetaShopItems == (Object)null)
			{
				DoSetup();
			}
			WeightedGameObject val = new WeightedGameObject();
			val.rawGameObject = null;
			val.pickupId = po.PickupObjectId;
			val.weight = cost;
			val.forceDuplicatesPossible = false;
			val.additionalPrerequisites = (DungeonPrerequisite[])(object)new DungeonPrerequisite[0];
			WeightedGameObject val2 = val;
			if (!index.HasValue)
			{
				TrorcMetaShopItems.defaultItemDrops.elements.Add(val2);
			}
			else if (index.Value < 0)
			{
				TrorcMetaShopItems.defaultItemDrops.elements.Add(val2);
			}
			else
			{
				TrorcMetaShopItems.defaultItemDrops.elements.InsertOrAdd(index.Value, val2);
			}
			RegisterBaseShopControllerAddedItem(val2, TrorcMetaShopItems.defaultItemDrops);
			return val2;
		}

		public static WeightedGameObject AddItemToGooptonMetaShop(this PickupObject po, int cost, int? index = null)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if ((Object)(object)GooptonMetaShopItems == (Object)null)
			{
				DoSetup();
			}
			WeightedGameObject val = new WeightedGameObject();
			val.rawGameObject = null;
			val.pickupId = po.PickupObjectId;
			val.weight = cost;
			val.forceDuplicatesPossible = false;
			val.additionalPrerequisites = (DungeonPrerequisite[])(object)new DungeonPrerequisite[0];
			WeightedGameObject val2 = val;
			if (!index.HasValue)
			{
				GooptonMetaShopItems.defaultItemDrops.elements.Add(val2);
			}
			else if (index.Value < 0)
			{
				TrorcMetaShopItems.defaultItemDrops.elements.Add(val2);
			}
			else
			{
				GooptonMetaShopItems.defaultItemDrops.elements.InsertOrAdd(index.Value, val2);
			}
			RegisterBaseShopControllerAddedItem(val2, GooptonMetaShopItems.defaultItemDrops);
			return val2;
		}

		public static WeightedGameObject AddItemToDougMetaShop(this PickupObject po, int cost, int? index = null)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if ((Object)(object)DougMetaShopItems == (Object)null)
			{
				DoSetup();
			}
			WeightedGameObject val = new WeightedGameObject();
			val.rawGameObject = null;
			val.pickupId = po.PickupObjectId;
			val.weight = cost;
			val.forceDuplicatesPossible = false;
			val.additionalPrerequisites = (DungeonPrerequisite[])(object)new DungeonPrerequisite[0];
			WeightedGameObject val2 = val;
			if (!index.HasValue)
			{
				DougMetaShopItems.defaultItemDrops.elements.Add(val2);
			}
			else if (index.Value < 0)
			{
				DougMetaShopItems.defaultItemDrops.elements.Add(val2);
			}
			else
			{
				DougMetaShopItems.defaultItemDrops.elements.InsertOrAdd(index.Value, val2);
			}
			RegisterBaseShopControllerAddedItem(val2, DougMetaShopItems.defaultItemDrops);
			return val2;
		}

		private static void RegisterBaseShopControllerAddedItem(WeightedGameObject obj, WeightedGameObjectCollection collection)
		{
			if (baseShopAddedItems == null)
			{
				baseShopAddedItems = new Dictionary<WeightedGameObjectCollection, List<WeightedGameObject>>();
			}
			if (!baseShopAddedItems.ContainsKey(collection))
			{
				baseShopAddedItems.Add(collection, new List<WeightedGameObject>());
			}
			if (baseShopAddedItems[collection] == null)
			{
				baseShopAddedItems[collection] = new List<WeightedGameObject>();
			}
			baseShopAddedItems[collection].Add(obj);
		}

		public static List<MetaShopTier> AddBaseMetaShopDoubleTier(int topLeftItemId, int topLeftItemPrice, int topMiddleItemId, int topMiddleItemPrice, int topRightItemId, int topRightItemPrice, int bottomLeftItemId, int bottomLeftItemPrice, int bottomMiddleItemId, int bottomMiddleItemPrice, int bottomRightItemId, int bottomRightItemPrice, int? index = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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)
			//IL_0046: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_007a: Expected O, but got Unknown
			return AddBaseMetaShopDoubleTier(new DoubleMetaShopTier(new MetaShopTier
			{
				itemId1 = topLeftItemId,
				overrideItem1Cost = topLeftItemPrice,
				itemId2 = topMiddleItemId,
				overrideItem2Cost = topMiddleItemPrice,
				itemId3 = topRightItemId,
				overrideItem3Cost = topRightItemPrice,
				overrideTierCost = topLeftItemId
			}, new MetaShopTier
			{
				itemId1 = bottomLeftItemId,
				overrideItem1Cost = bottomLeftItemPrice,
				itemId2 = bottomMiddleItemId,
				overrideItem2Cost = bottomMiddleItemPrice,
				itemId3 = bottomRightItemId,
				overrideItem3Cost = bottomRightItemPrice,
				overrideTierCost = topLeftItemId
			}), index);
		}

		public static List<MetaShopTier> AddBaseMetaShopDoubleTier(int topLeftItemId, int topLeftItemPrice, int topMiddleItemId, int topMiddleItemPrice, int topRightItemId, int topRightItemPrice, int bottomLeftItemId, int bottomLeftItemPrice, int bottomMiddleItemId, int bottomMiddleItemPrice, int? index = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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)
			//IL_0046: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0078: Expected O, but got Unknown
			//IL_0078: Expected O, but got Unknown
			return AddBaseMetaShopDoubleTier(new DoubleMetaShopTier(new MetaShopTier
			{
				itemId1 = topLeftItemId,
				overrideItem1Cost = topLeftItemPrice,
				itemId2 = topMiddleItemId,
				overrideItem2Cost = topMiddleItemPrice,
				itemId3 = topRightItemId,
				overrideItem3Cost = topRightItemPrice,
				overrideTierCost = topLeftItemId
			}, new MetaShopTier
			{
				itemId1 = bottomLeftItemId,
				overrideItem1Cost = bottomLeftItemPrice,
				itemId2 = bottomMiddleItemId,
				overrideItem2Cost = bottomMiddleItemPrice,
				itemId3 = -1,
				overrideItem3Cost = -1,
				overrideTierCost = topLeftItemId
			}), index);
		}

		public static List<MetaShopTier> AddBaseMetaShopDoubleTier(int topLeftItemId, int topLeftItemPrice, int topMiddleItemId, int topMiddleItemPrice, int topRightItemId, int topRightItemPrice, int bottomLeftItemId, int bottomLeftItemPrice, int? index = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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)
			//IL_0046: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL