using System;
using Cpp2IlInjected;
using UnityEngine;

namespace Obi
{
	// Token: 0x020004EA RID: 1258
	[Token(Token = "0x20004EA")]
	[ExecuteInEditMode]
	[RequireComponent(typeof(ObiSolver))]
	public class ObiParticleBaker : MonoBehaviour
	{
		// Token: 0x1700030F RID: 783
		// (get) Token: 0x06002C11 RID: 11281 RVA: 0x0005F678 File Offset: 0x0005D878
		// (set) Token: 0x06002C12 RID: 11282 RVA: 0x0005F68C File Offset: 0x0005D88C
		[Token(Token = "0x1700030F")]
		public bool Baking
		{
			[Token(Token = "0x6002C11")]
			[Address(RVA = "0x434D40", Offset = "0x433B40", VA = "0x180434D40")]
			get
			{
				return this.baking;
			}
			[Token(Token = "0x6002C12")]
			[Address(RVA = "0xD22DF0", Offset = "0xD21BF0", VA = "0x180D22DF0")]
			set
			{
				this.baking = value;
				if (!value)
				{
					this.framesToSkip = (int)((ulong)0L);
					Time.captureFramerate = 0;
					ObiSolver obiSolver = this.solver;
					int renderablePositionsClients = obiSolver.renderablePositionsClients;
					if (renderablePositionsClients > 0)
					{
						obiSolver.renderablePositionsClients = renderablePositionsClients;
					}
					return;
				}
				int num = this.fixedBakeFramerate;
				Time.captureFramerate = Mathf.Max(0, num);
				ObiSolver obiSolver2 = this.solver;
				this.playing = false;
				obiSolver2.simulate = true;
				ObiSolver obiSolver3 = this.solver;
			}
		}

		// Token: 0x17000310 RID: 784
		// (get) Token: 0x06002C13 RID: 11283 RVA: 0x0005F704 File Offset: 0x0005D904
		// (set) Token: 0x06002C14 RID: 11284 RVA: 0x0005F718 File Offset: 0x0005D918
		[Token(Token = "0x17000310")]
		public bool Playing
		{
			[Token(Token = "0x6002C13")]
			[Address(RVA = "0x434D50", Offset = "0x433B50", VA = "0x180434D50")]
			get
			{
				return this.playing;
			}
			[Token(Token = "0x6002C14")]
			[Address(RVA = "0xD22E80", Offset = "0xD21C80", VA = "0x180D22E80")]
			set
			{
				ObiSolver obiSolver = this.solver;
				this.playing = value;
				obiSolver.simulate = value;
				if (this.playing)
				{
					this.baking = false;
				}
			}
		}

		// Token: 0x17000311 RID: 785
		// (get) Token: 0x06002C15 RID: 11285 RVA: 0x0005F750 File Offset: 0x0005D950
		// (set) Token: 0x06002C16 RID: 11286 RVA: 0x0005F764 File Offset: 0x0005D964
		[Token(Token = "0x17000311")]
		public bool Paused
		{
			[Token(Token = "0x6002C15")]
			[Address(RVA = "0x815040", Offset = "0x813E40", VA = "0x180815040")]
			get
			{
				return this.paused;
			}
			[Token(Token = "0x6002C16")]
			[Address(RVA = "0x815050", Offset = "0x813E50", VA = "0x180815050")]
			set
			{
				this.paused = value;
			}
		}

		// Token: 0x06002C17 RID: 11287 RVA: 0x0005F778 File Offset: 0x0005D978
		[Token(Token = "0x6002C17")]
		[Address(RVA = "0xD22030", Offset = "0xD20E30", VA = "0x180D22030")]
		private void Awake()
		{
			ObiSolver component = base.GetComponent<ObiSolver>();
			this.solver = component;
			if (Application.isPlaying)
			{
				if (this.bakeOnAwake)
				{
					int num = this.fixedBakeFramerate;
					int num2 = 0;
					this.playhead = 0f;
					this.baking = true;
					Time.captureFramerate = Mathf.Max(num2, num);
					ObiSolver obiSolver = this.solver;
					this.playing = false;
					obiSolver.simulate = true;
					ObiSolver obiSolver2 = this.solver;
					return;
				}
				if (this.playOnAwake)
				{
					ObiSolver obiSolver3 = this.solver;
					this.playhead = 0f;
					this.playing = true;
					obiSolver3.simulate = false;
					if (this.playing)
					{
						this.baking = false;
					}
				}
			}
		}

		// Token: 0x06002C18 RID: 11288 RVA: 0x0005F830 File Offset: 0x0005DA30
		[Token(Token = "0x6002C18")]
		[Address(RVA = "0xD22610", Offset = "0xD21410", VA = "0x180D22610")]
		private void OnEnable()
		{
			ObiSolver obiSolver = this.solver;
			EventHandler eventHandler = new EventHandler(this.Solver_OnFrameEnd);
			obiSolver.OnFrameEnd += eventHandler;
			ObiSolver obiSolver2 = this.solver;
			EventHandler eventHandler2 = new EventHandler(this.Solver_OnBeforeActorsFrameEnd);
			EventHandler onBeforeActorsFrameEnd = obiSolver2.OnBeforeActorsFrameEnd;
			Delegate @delegate = Delegate.Combine(onBeforeActorsFrameEnd, eventHandler2);
			if (@delegate == 0 || @delegate != 0)
			{
				while (@delegate != onBeforeActorsFrameEnd)
				{
				}
				return;
			}
			throw new InvalidCastException();
		}

		// Token: 0x06002C19 RID: 11289 RVA: 0x0005F89C File Offset: 0x0005DA9C
		[Token(Token = "0x6002C19")]
		[Address(RVA = "0xD22490", Offset = "0xD21290", VA = "0x180D22490")]
		private void OnDisable()
		{
			this.baking = false;
			this.framesToSkip = (int)((ulong)0L);
			Time.captureFramerate = 0;
			ObiSolver obiSolver = this.solver;
			int renderablePositionsClients = obiSolver.renderablePositionsClients;
			if (renderablePositionsClients > 0)
			{
				obiSolver.renderablePositionsClients = renderablePositionsClients;
			}
			EventHandler eventHandler = new EventHandler(this.Solver_OnFrameEnd);
			obiSolver.OnFrameEnd -= eventHandler;
			ObiSolver obiSolver2 = this.solver;
			EventHandler eventHandler2 = new EventHandler(this.Solver_OnBeforeActorsFrameEnd);
			EventHandler onBeforeActorsFrameEnd = obiSolver2.OnBeforeActorsFrameEnd;
			Delegate @delegate = Delegate.Remove(onBeforeActorsFrameEnd, eventHandler2);
			if (@delegate == 0 || @delegate != 0)
			{
				while (@delegate != onBeforeActorsFrameEnd)
				{
				}
				return;
			}
			throw new InvalidCastException();
		}

		// Token: 0x06002C1A RID: 11290 RVA: 0x0005F930 File Offset: 0x0005DB30
		[Token(Token = "0x6002C1A")]
		[Address(RVA = "0xD22CB0", Offset = "0xD21AB0", VA = "0x180D22CB0")]
		private void Solver_OnFrameEnd(object sender, EventArgs e)
		{
			ObiParticleCache obiParticleCache = this.cache;
			int num = 0;
			if (obiParticleCache != num && !this.playing && this.baking)
			{
				float deltaTime = Time.deltaTime;
				int num2 = this.framesToSkip;
				this.playhead = deltaTime;
				if (num2 > 0)
				{
					this.framesToSkip = num2;
					return;
				}
				this.BakeFrame(deltaTime);
				int num3 = this.frameSkip;
				this.framesToSkip = num3;
			}
		}

		// Token: 0x06002C1B RID: 11291 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002C1B")]
		[Address(RVA = "0xD22BB0", Offset = "0xD219B0", VA = "0x180D22BB0")]
		private void Solver_OnBeforeActorsFrameEnd(object sender, EventArgs e)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002C1C RID: 11292 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002C1C")]
		[Address(RVA = "0xD22110", Offset = "0xD20F10", VA = "0x180D22110")]
		public void BakeFrame(float time)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002C1D RID: 11293 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002C1D")]
		[Address(RVA = "0xD22760", Offset = "0xD21560", VA = "0x180D22760")]
		private void PlaybackFrame(float time)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002C1E RID: 11294 RVA: 0x0005F9A0 File Offset: 0x0005DBA0
		[Token(Token = "0x6002C1E")]
		[Address(RVA = "0xD22D70", Offset = "0xD21B70", VA = "0x180D22D70")]
		public ObiParticleBaker()
		{
			ObiParticleCache.Frame frame = new ObiParticleCache.Frame();
			this.frame = frame;
			base..ctor();
		}

		// Token: 0x0400347C RID: 13436
		[FieldOffset(Offset = "0x18")]
		[Token(Token = "0x400347C")]
		public ObiParticleCache cache;

		// Token: 0x0400347D RID: 13437
		[FieldOffset(Offset = "0x20")]
		[Token(Token = "0x400347D")]
		public float playhead;

		// Token: 0x0400347E RID: 13438
		[FieldOffset(Offset = "0x24")]
		[Token(Token = "0x400347E")]
		public int frameSkip = (int)((ulong)8L);

		// Token: 0x0400347F RID: 13439
		[FieldOffset(Offset = "0x28")]
		[Token(Token = "0x400347F")]
		public int fixedBakeFramerate = (int)((ulong)60L);

		// Token: 0x04003480 RID: 13440
		[FieldOffset(Offset = "0x2C")]
		[Token(Token = "0x4003480")]
		public bool interpolate = true;

		// Token: 0x04003481 RID: 13441
		[FieldOffset(Offset = "0x2D")]
		[Token(Token = "0x4003481")]
		public bool loopPlayback;

		// Token: 0x04003482 RID: 13442
		[FieldOffset(Offset = "0x2E")]
		[Token(Token = "0x4003482")]
		public bool bakeOnAwake;

		// Token: 0x04003483 RID: 13443
		[FieldOffset(Offset = "0x2F")]
		[Token(Token = "0x4003483")]
		public bool playOnAwake;

		// Token: 0x04003484 RID: 13444
		[FieldOffset(Offset = "0x30")]
		[Token(Token = "0x4003484")]
		private bool baking;

		// Token: 0x04003485 RID: 13445
		[FieldOffset(Offset = "0x31")]
		[Token(Token = "0x4003485")]
		private bool playing;

		// Token: 0x04003486 RID: 13446
		[FieldOffset(Offset = "0x32")]
		[Token(Token = "0x4003486")]
		private bool paused;

		// Token: 0x04003487 RID: 13447
		[FieldOffset(Offset = "0x34")]
		[Token(Token = "0x4003487")]
		private int framesToSkip;

		// Token: 0x04003488 RID: 13448
		[FieldOffset(Offset = "0x38")]
		[Token(Token = "0x4003488")]
		private ObiSolver solver;

		// Token: 0x04003489 RID: 13449
		[FieldOffset(Offset = "0x40")]
		[Token(Token = "0x4003489")]
		private ObiParticleCache.Frame frame;
	}
}
