using System;
using System.Collections.Generic;
using Cpp2IlInjected;
using UnityEngine;

namespace Obi
{
	// Token: 0x02000495 RID: 1173
	[Token(Token = "0x2000495")]
	[ExecuteInEditMode]
	[AddComponentMenu("Physics/Obi/Obi Stitcher")]
	public class ObiStitcher : MonoBehaviour, IObiSolverClient
	{
		// Token: 0x170002D2 RID: 722
		// (get) Token: 0x060029D7 RID: 10711 RVA: 0x0005B434 File Offset: 0x00059634
		// (set) Token: 0x060029D6 RID: 10710 RVA: 0x0005B310 File Offset: 0x00059510
		[Token(Token = "0x170002D2")]
		public ObiActor Actor1
		{
			[Token(Token = "0x60029D7")]
			[Address(RVA = "0x28C210", Offset = "0x28B010", VA = "0x18028C210")]
			get
			{
				return this.actor1;
			}
			[Token(Token = "0x60029D6")]
			[Address(RVA = "0xD2F340", Offset = "0xD2E140", VA = "0x180D2F340")]
			set
			{
				if (this.actor1 != value)
				{
					ObiActor obiActor = this.actor1;
					int num = 0;
					if (obiActor != num)
					{
						ObiActor obiActor2 = this.actor1;
						EventHandler<ObiActor.ObiActorSolverArgs> eventHandler = new EventHandler(this.Actor_OnAddedToSolver);
						obiActor2.OnAddedToSolver -= eventHandler;
						ObiActor obiActor3 = this.actor1;
						EventHandler<ObiActor.ObiActorSolverArgs> eventHandler2 = new EventHandler(this.Actor_OnRemovedFromSolver);
						obiActor3.OnRemovedFromSolver -= eventHandler2;
						ObiActor obiActor4 = this.actor1;
						if (obiActor4.inSolver)
						{
							ObiActor.ObiActorSolverArgs obiActorSolverArgs = new ObiActor.ObiActorSolverArgs(obiActor4.solver);
							this.Actor_OnRemovedFromSolver(obiActor4, obiActorSolverArgs);
						}
					}
					this.actor1 = value;
					ObiActor obiActor5 = this.actor1;
					int num2 = 0;
					if (obiActor5 != num2)
					{
						ObiActor obiActor6 = this.actor1;
						EventHandler<ObiActor.ObiActorSolverArgs> eventHandler3 = new EventHandler(this.Actor_OnAddedToSolver);
						obiActor6.OnAddedToSolver += eventHandler3;
						ObiActor obiActor7 = this.actor1;
						EventHandler<ObiActor.ObiActorSolverArgs> eventHandler4 = new EventHandler(this.Actor_OnRemovedFromSolver);
						obiActor7.OnRemovedFromSolver += eventHandler4;
						ObiActor obiActor8 = this.actor1;
						if (obiActor8.inSolver)
						{
							ObiActor.ObiActorSolverArgs obiActorSolverArgs2 = new ObiActor.ObiActorSolverArgs(obiActor8.solver);
							this.Actor_OnAddedToSolver(obiActor8, obiActorSolverArgs2);
						}
					}
				}
			}
		}

		// Token: 0x170002D3 RID: 723
		// (get) Token: 0x060029D9 RID: 10713 RVA: 0x0005B56C File Offset: 0x0005976C
		// (set) Token: 0x060029D8 RID: 10712 RVA: 0x0005B448 File Offset: 0x00059648
		[Token(Token = "0x170002D3")]
		public ObiActor Actor2
		{
			[Token(Token = "0x60029D9")]
			[Address(RVA = "0x502B30", Offset = "0x501930", VA = "0x180502B30")]
			get
			{
				return this.actor2;
			}
			[Token(Token = "0x60029D8")]
			[Address(RVA = "0xD2F630", Offset = "0xD2E430", VA = "0x180D2F630")]
			set
			{
				if (this.actor2 != value)
				{
					ObiActor obiActor = this.actor2;
					int num = 0;
					if (obiActor != num)
					{
						ObiActor obiActor2 = this.actor2;
						EventHandler<ObiActor.ObiActorSolverArgs> eventHandler = new EventHandler(this.Actor_OnAddedToSolver);
						obiActor2.OnAddedToSolver -= eventHandler;
						ObiActor obiActor3 = this.actor2;
						EventHandler<ObiActor.ObiActorSolverArgs> eventHandler2 = new EventHandler(this.Actor_OnRemovedFromSolver);
						obiActor3.OnRemovedFromSolver -= eventHandler2;
						ObiActor obiActor4 = this.actor2;
						if (obiActor4.inSolver)
						{
							ObiActor.ObiActorSolverArgs obiActorSolverArgs = new ObiActor.ObiActorSolverArgs(obiActor4.solver);
							this.Actor_OnRemovedFromSolver(obiActor4, obiActorSolverArgs);
						}
					}
					this.actor2 = value;
					ObiActor obiActor5 = this.actor2;
					int num2 = 0;
					if (obiActor5 != num2)
					{
						ObiActor obiActor6 = this.actor2;
						EventHandler<ObiActor.ObiActorSolverArgs> eventHandler3 = new EventHandler(this.Actor_OnAddedToSolver);
						obiActor6.OnAddedToSolver += eventHandler3;
						ObiActor obiActor7 = this.actor2;
						EventHandler<ObiActor.ObiActorSolverArgs> eventHandler4 = new EventHandler(this.Actor_OnRemovedFromSolver);
						obiActor7.OnRemovedFromSolver += eventHandler4;
						ObiActor obiActor8 = this.actor2;
						if (obiActor8.inSolver)
						{
							ObiActor.ObiActorSolverArgs obiActorSolverArgs2 = new ObiActor.ObiActorSolverArgs(obiActor8.solver);
							this.Actor_OnAddedToSolver(obiActor8, obiActorSolverArgs2);
						}
					}
				}
			}
		}

		// Token: 0x170002D4 RID: 724
		// (get) Token: 0x060029DA RID: 10714 RVA: 0x0005B580 File Offset: 0x00059780
		[Token(Token = "0x170002D4")]
		public int StitchCount
		{
			[Token(Token = "0x60029DA")]
			[Address(RVA = "0xD2F2B0", Offset = "0xD2E0B0", VA = "0x180D2F2B0")]
			get
			{
				return this.stitches._size;
			}
		}

		// Token: 0x170002D5 RID: 725
		// (get) Token: 0x060029DB RID: 10715 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x170002D5")]
		public IEnumerable<ObiStitcher.Stitch> Stitches
		{
			[Token(Token = "0x60029DB")]
			[Address(RVA = "0xD2F2F0", Offset = "0xD2E0F0", VA = "0x180D2F2F0")]
			get
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}
		}

		// Token: 0x060029DC RID: 10716 RVA: 0x0005B5A0 File Offset: 0x000597A0
		[Token(Token = "0x60029DC")]
		[Address(RVA = "0xD2EBB0", Offset = "0xD2D9B0", VA = "0x180D2EBB0")]
		public void OnEnable()
		{
			ObiActor obiActor = this.actor1;
			int num = 0;
			if (obiActor != num)
			{
				ObiActor obiActor2 = this.actor1;
				EventHandler<ObiActor.ObiActorSolverArgs> eventHandler = new EventHandler(this.Actor_OnAddedToSolver);
				obiActor2.OnAddedToSolver += eventHandler;
				ObiActor obiActor3 = this.actor1;
				EventHandler<ObiActor.ObiActorSolverArgs> eventHandler2 = new EventHandler(this.Actor_OnRemovedFromSolver);
				obiActor3.OnRemovedFromSolver += eventHandler2;
			}
			ObiActor obiActor4 = this.actor2;
			int num2 = 0;
			if (obiActor4 != num2)
			{
				ObiActor obiActor5 = this.actor2;
				EventHandler<ObiActor.ObiActorSolverArgs> eventHandler3 = new EventHandler(this.Actor_OnAddedToSolver);
				obiActor5.OnAddedToSolver += eventHandler3;
				ObiActor obiActor6 = this.actor2;
				EventHandler<ObiActor.ObiActorSolverArgs> eventHandler4 = new EventHandler(this.Actor_OnRemovedFromSolver);
				obiActor6.OnRemovedFromSolver += eventHandler4;
			}
			ObiActor obiActor7 = this.actor1;
			int num3 = 0;
			if (obiActor7 != num3)
			{
				ObiActor obiActor8 = this.actor2;
				int num4 = 0;
				if (obiActor8 != num4)
				{
					bool flag = Oni.EnableBatch(this.batch, true);
				}
			}
		}

		// Token: 0x060029DD RID: 10717 RVA: 0x0005B694 File Offset: 0x00059894
		[Token(Token = "0x60029DD")]
		[Address(RVA = "0xD2EBA0", Offset = "0xD2D9A0", VA = "0x180D2EBA0")]
		public void OnDisable()
		{
			IntPtr intPtr = this.batch;
			int num = 0;
			bool flag = Oni.EnableBatch(intPtr, num != 0);
		}

		// Token: 0x060029DE RID: 10718 RVA: 0x0005B6B4 File Offset: 0x000598B4
		[Token(Token = "0x60029DE")]
		[Address(RVA = "0xD2E9D0", Offset = "0xD2D7D0", VA = "0x180D2E9D0")]
		public int AddStitch(int particle1, int particle2)
		{
			List<ObiStitcher.Stitch> list = this.stitches;
			ObiStitcher.Stitch stitch = new ObiStitcher.Stitch(particle1, particle2);
			list.Add(stitch);
			return this.stitches._size;
		}

		// Token: 0x060029DF RID: 10719 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x60029DF")]
		[Address(RVA = "0xD2F1C0", Offset = "0xD2DFC0", VA = "0x180D2F1C0")]
		public void RemoveStitch(int index)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x060029E0 RID: 10720 RVA: 0x0005B6E8 File Offset: 0x000598E8
		[Token(Token = "0x60029E0")]
		[Address(RVA = "0xD2EB40", Offset = "0xD2D940", VA = "0x180D2EB40")]
		public void Clear()
		{
			this.stitches.Clear();
			int num = 0;
			this.PushDataToSolver((ParticleData)num);
		}

		// Token: 0x060029E1 RID: 10721 RVA: 0x0005B710 File Offset: 0x00059910
		[Token(Token = "0x60029E1")]
		[Address(RVA = "0xD2E960", Offset = "0xD2D760", VA = "0x180D2E960")]
		private void Actor_OnRemovedFromSolver(object sender, ObiActor.ObiActorSolverArgs e)
		{
			ObiSolver solver = this.actor1.solver;
			IntPtr intPtr = this.batch;
			Oni.RemoveBatch(solver.oniSolver, intPtr);
			this.batch = (IntPtr)((ulong)0L);
			this.inSolver = false;
		}

		// Token: 0x060029E2 RID: 10722 RVA: 0x0005B754 File Offset: 0x00059954
		[Token(Token = "0x60029E2")]
		[Address(RVA = "0xD2E7D0", Offset = "0xD2D5D0", VA = "0x180D2E7D0")]
		private void Actor_OnAddedToSolver(object sender, ObiActor.ObiActorSolverArgs e)
		{
			ObiActor obiActor = this.actor1;
			if (obiActor.inSolver)
			{
				ObiActor obiActor2 = this.actor2;
				if (obiActor2.inSolver)
				{
					ObiSolver solver = obiActor2.solver;
					if (obiActor.solver != solver)
					{
						Debug.LogError("ObiStitcher cannot handle actors in different solvers.");
						return;
					}
					int num = 0;
					IntPtr intPtr = Oni.CreateBatch(10, num != 0);
					ObiActor obiActor3 = this.actor1;
					this.batch = intPtr;
					IntPtr oniSolver = obiActor3.solver.oniSolver;
					int num2 = 0;
					IntPtr intPtr2 = Oni.AddBatch(oniSolver, intPtr, num2 != 0);
					this.inSolver = true;
					int num3 = 0;
					this.PushDataToSolver((ParticleData)num3);
					if (!base.isActiveAndEnabled)
					{
						IntPtr intPtr3 = this.batch;
						int num4 = 0;
						bool flag = Oni.EnableBatch(intPtr3, num4 != 0);
						return;
					}
					this.OnEnable();
					return;
				}
			}
		}

		// Token: 0x060029E3 RID: 10723 RVA: 0x0005B824 File Offset: 0x00059A24
		[Token(Token = "0x60029E3")]
		[Address(RVA = "0xD2EAA0", Offset = "0xD2D8A0", VA = "0x180D2EAA0", Slot = "4")]
		public bool AddToSolver(object info)
		{
			int num = 0;
			IntPtr intPtr = Oni.CreateBatch(10, num != 0);
			ObiActor obiActor = this.actor1;
			this.batch = intPtr;
			IntPtr oniSolver = obiActor.solver.oniSolver;
			int num2 = 0;
			IntPtr intPtr2 = Oni.AddBatch(oniSolver, intPtr, num2 != 0);
			this.inSolver = true;
			int num3 = 0;
			this.PushDataToSolver((ParticleData)num3);
			if (!base.isActiveAndEnabled)
			{
				IntPtr intPtr3 = this.batch;
				int num4 = 0;
				bool flag = Oni.EnableBatch(intPtr3, num4 != 0);
				return true;
			}
			this.OnEnable();
			return true;
		}

		// Token: 0x060029E4 RID: 10724 RVA: 0x0005B8A4 File Offset: 0x00059AA4
		[Token(Token = "0x60029E4")]
		[Address(RVA = "0xD2F150", Offset = "0xD2DF50", VA = "0x180D2F150", Slot = "5")]
		public bool RemoveFromSolver(object info)
		{
			ObiSolver solver = this.actor1.solver;
			IntPtr intPtr = this.batch;
			Oni.RemoveBatch(solver.oniSolver, intPtr);
			this.batch = (IntPtr)((ulong)0L);
			this.inSolver = false;
			return true;
		}

		// Token: 0x060029E5 RID: 10725 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x60029E5")]
		[Address(RVA = "0xD2EE20", Offset = "0xD2DC20", VA = "0x180D2EE20", Slot = "6")]
		public void PushDataToSolver(ParticleData data = ParticleData.NONE)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x060029E6 RID: 10726 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x60029E6")]
		[Address(RVA = "0x297F00", Offset = "0x296D00", VA = "0x180297F00", Slot = "7")]
		public void PullDataFromSolver(ParticleData data = ParticleData.NONE)
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x060029E7 RID: 10727 RVA: 0x0005B8E8 File Offset: 0x00059AE8
		[Token(Token = "0x60029E7")]
		[Address(RVA = "0xD2F230", Offset = "0xD2E030", VA = "0x180D2F230")]
		public ObiStitcher()
		{
			List<ObiStitcher.Stitch> list = new List();
			this.stitches = list;
			base..ctor();
		}

		// Token: 0x040032D9 RID: 13017
		[FieldOffset(Offset = "0x18")]
		[Token(Token = "0x40032D9")]
		[HideInInspector]
		[SerializeField]
		private List<ObiStitcher.Stitch> stitches;

		// Token: 0x040032DA RID: 13018
		[FieldOffset(Offset = "0x20")]
		[Token(Token = "0x40032DA")]
		[SerializeField]
		[HideInInspector]
		private ObiActor actor1;

		// Token: 0x040032DB RID: 13019
		[FieldOffset(Offset = "0x28")]
		[Token(Token = "0x40032DB")]
		[SerializeField]
		[HideInInspector]
		private ObiActor actor2;

		// Token: 0x040032DC RID: 13020
		[FieldOffset(Offset = "0x30")]
		[Token(Token = "0x40032DC")]
		private IntPtr batch;

		// Token: 0x040032DD RID: 13021
		[FieldOffset(Offset = "0x38")]
		[Token(Token = "0x40032DD")]
		private bool inSolver;

		// Token: 0x02000496 RID: 1174
		[Token(Token = "0x2000496")]
		[Serializable]
		public class Stitch
		{
			// Token: 0x060029E8 RID: 10728 RVA: 0x0005B908 File Offset: 0x00059B08
			[Token(Token = "0x60029E8")]
			[Address(RVA = "0x6A1CC0", Offset = "0x6A0AC0", VA = "0x1806A1CC0")]
			public Stitch(int particleIndex1, int particleIndex2)
			{
				this.particleIndex1 = particleIndex1;
				this.particleIndex2 = particleIndex2;
			}

			// Token: 0x040032DE RID: 13022
			[FieldOffset(Offset = "0x10")]
			[Token(Token = "0x40032DE")]
			public int particleIndex1;

			// Token: 0x040032DF RID: 13023
			[FieldOffset(Offset = "0x14")]
			[Token(Token = "0x40032DF")]
			public int particleIndex2;
		}
	}
}
