using System;
using Cpp2IlInjected;
using UnityEngine;

namespace Obi
{
	// Token: 0x02000542 RID: 1346
	[Token(Token = "0x2000542")]
	[ExecuteInEditMode]
	[RequireComponent(typeof(ObiSolver))]
	public class ObiParticleBaker : MonoBehaviour
	{
		// Token: 0x17000334 RID: 820
		// (get) Token: 0x06002EDA RID: 11994 RVA: 0x0006690C File Offset: 0x00064B0C
		// (set) Token: 0x06002EDB RID: 11995 RVA: 0x00066920 File Offset: 0x00064B20
		[Token(Token = "0x17000334")]
		public bool Baking
		{
			[Token(Token = "0x6002EDA")]
			[Address(RVA = "0x4920D0", Offset = "0x4910D0", VA = "0x1804920D0")]
			get
			{
				return this.baking;
			}
			[Token(Token = "0x6002EDB")]
			[Address(RVA = "0xE53F60", Offset = "0xE52F60", VA = "0x180E53F60")]
			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: 0x17000335 RID: 821
		// (get) Token: 0x06002EDC RID: 11996 RVA: 0x00066998 File Offset: 0x00064B98
		// (set) Token: 0x06002EDD RID: 11997 RVA: 0x000669AC File Offset: 0x00064BAC
		[Token(Token = "0x17000335")]
		public bool Playing
		{
			[Token(Token = "0x6002EDC")]
			[Address(RVA = "0x50F1F0", Offset = "0x50E1F0", VA = "0x18050F1F0")]
			get
			{
				return this.playing;
			}
			[Token(Token = "0x6002EDD")]
			[Address(RVA = "0xE53FF0", Offset = "0xE52FF0", VA = "0x180E53FF0")]
			set
			{
				ObiSolver obiSolver = this.solver;
				this.playing = value;
				obiSolver.simulate = value;
				if (this.playing)
				{
					this.baking = false;
				}
			}
		}

		// Token: 0x17000336 RID: 822
		// (get) Token: 0x06002EDE RID: 11998 RVA: 0x000669E4 File Offset: 0x00064BE4
		// (set) Token: 0x06002EDF RID: 11999 RVA: 0x000669F8 File Offset: 0x00064BF8
		[Token(Token = "0x17000336")]
		public bool Paused
		{
			[Token(Token = "0x6002EDE")]
			[Address(RVA = "0x892870", Offset = "0x891870", VA = "0x180892870")]
			get
			{
				return this.paused;
			}
			[Token(Token = "0x6002EDF")]
			[Address(RVA = "0x892880", Offset = "0x891880", VA = "0x180892880")]
			set
			{
				this.paused = value;
			}
		}

		// Token: 0x06002EE0 RID: 12000 RVA: 0x00066A0C File Offset: 0x00064C0C
		[Token(Token = "0x6002EE0")]
		[Address(RVA = "0xE531A0", Offset = "0xE521A0", VA = "0x180E531A0")]
		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: 0x06002EE1 RID: 12001 RVA: 0x00066AC4 File Offset: 0x00064CC4
		[Token(Token = "0x6002EE1")]
		[Address(RVA = "0xE53780", Offset = "0xE52780", VA = "0x180E53780")]
		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: 0x06002EE2 RID: 12002 RVA: 0x00066B30 File Offset: 0x00064D30
		[Token(Token = "0x6002EE2")]
		[Address(RVA = "0xE53600", Offset = "0xE52600", VA = "0x180E53600")]
		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: 0x06002EE3 RID: 12003 RVA: 0x00066BC4 File Offset: 0x00064DC4
		[Token(Token = "0x6002EE3")]
		[Address(RVA = "0xE53E20", Offset = "0xE52E20", VA = "0x180E53E20")]
		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: 0x06002EE4 RID: 12004 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002EE4")]
		[Address(RVA = "0xE53D20", Offset = "0xE52D20", VA = "0x180E53D20")]
		private void Solver_OnBeforeActorsFrameEnd(object sender, EventArgs e)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002EE5 RID: 12005 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002EE5")]
		[Address(RVA = "0xE53280", Offset = "0xE52280", VA = "0x180E53280")]
		public void BakeFrame(float time)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002EE6 RID: 12006 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002EE6")]
		[Address(RVA = "0xE538D0", Offset = "0xE528D0", VA = "0x180E538D0")]
		private void PlaybackFrame(float time)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002EE7 RID: 12007 RVA: 0x00066C34 File Offset: 0x00064E34
		[Token(Token = "0x6002EE7")]
		[Address(RVA = "0xE53EE0", Offset = "0xE52EE0", VA = "0x180E53EE0")]
		public ObiParticleBaker()
		{
			ObiParticleCache.Frame frame = new ObiParticleCache.Frame();
			this.frame = frame;
			base..ctor();
		}

		// Token: 0x04003766 RID: 14182
		[FieldOffset(Offset = "0x18")]
		[Token(Token = "0x4003766")]
		public ObiParticleCache cache;

		// Token: 0x04003767 RID: 14183
		[FieldOffset(Offset = "0x20")]
		[Token(Token = "0x4003767")]
		public float playhead;

		// Token: 0x04003768 RID: 14184
		[FieldOffset(Offset = "0x24")]
		[Token(Token = "0x4003768")]
		public int frameSkip = (int)((ulong)8L);

		// Token: 0x04003769 RID: 14185
		[FieldOffset(Offset = "0x28")]
		[Token(Token = "0x4003769")]
		public int fixedBakeFramerate = (int)((ulong)60L);

		// Token: 0x0400376A RID: 14186
		[FieldOffset(Offset = "0x2C")]
		[Token(Token = "0x400376A")]
		public bool interpolate = true;

		// Token: 0x0400376B RID: 14187
		[FieldOffset(Offset = "0x2D")]
		[Token(Token = "0x400376B")]
		public bool loopPlayback;

		// Token: 0x0400376C RID: 14188
		[FieldOffset(Offset = "0x2E")]
		[Token(Token = "0x400376C")]
		public bool bakeOnAwake;

		// Token: 0x0400376D RID: 14189
		[FieldOffset(Offset = "0x2F")]
		[Token(Token = "0x400376D")]
		public bool playOnAwake;

		// Token: 0x0400376E RID: 14190
		[FieldOffset(Offset = "0x30")]
		[Token(Token = "0x400376E")]
		private bool baking;

		// Token: 0x0400376F RID: 14191
		[FieldOffset(Offset = "0x31")]
		[Token(Token = "0x400376F")]
		private bool playing;

		// Token: 0x04003770 RID: 14192
		[FieldOffset(Offset = "0x32")]
		[Token(Token = "0x4003770")]
		private bool paused;

		// Token: 0x04003771 RID: 14193
		[FieldOffset(Offset = "0x34")]
		[Token(Token = "0x4003771")]
		private int framesToSkip;

		// Token: 0x04003772 RID: 14194
		[FieldOffset(Offset = "0x38")]
		[Token(Token = "0x4003772")]
		private ObiSolver solver;

		// Token: 0x04003773 RID: 14195
		[FieldOffset(Offset = "0x40")]
		[Token(Token = "0x4003773")]
		private ObiParticleCache.Frame frame;
	}
}
