Decompiled source of Tablet Display v1.1.0

Tablet_Display.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OtherLoader;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace Packer.Tablet_Display
{
	[BepInPlugin("Packer.Tablet_Display", "Tablet_Display", "1.1.0")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class Tablet_DisplayPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadAssets();
		}

		private void LoadAssets()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Packer.Tablet_Display");
			OtherLoader.RegisterDirectLoad(BasePath, "Packer.Tablet_Display", "", "", "packer.tabletdisplay", "");
		}
	}
}
namespace Packer
{
	public class CameraDisplay : MonoBehaviour
	{
		public List<Camera> cameras = new List<Camera>();

		public int index = 0;

		private Material renderMaterial;

		private FVRPhysicalObject physObject;

		[SerializeField]
		private Transform offset;

		[SerializeField]
		private MeshRenderer meshRenderer;

		private Quaternion offsetDefault;

		private bool quickbeltUpdate = false;

		public FVRPointableButton[] buttons;

		public Text cameraName;

		public GameObject crosshair;

		private bool preState = true;

		private void OnEnable()
		{
			//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)
			physObject = ((Component)this).GetComponent<FVRPhysicalObject>();
			renderMaterial = ((Renderer)meshRenderer).materials[1];
			offsetDefault = offset.localRotation;
		}

		private void FixedUpdate()
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)physObject.QuickbeltSlot != (Object)null && !((FVRInteractiveObject)physObject).IsHeld)
			{
				offset.LookAt(GM.CurrentPlayerBody.Head, Vector3.up);
				if (quickbeltUpdate)
				{
					preState = ((Component)buttons[0]).gameObject.activeSelf;
					for (int i = 0; i < buttons.Length; i++)
					{
						((Component)buttons[i]).gameObject.SetActive(false);
					}
					quickbeltUpdate = false;
				}
			}
			else if (!quickbeltUpdate)
			{
				offset.localRotation = offsetDefault;
				quickbeltUpdate = true;
				for (int j = 0; j < buttons.Length; j++)
				{
					((Component)buttons[j]).gameObject.SetActive(preState);
				}
				if (offset.localScale.x < 0.2f)
				{
					ResetScale();
				}
			}
		}

		public void AdjustScale(float amount)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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)
			//IL_007b: 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)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (amount < 0f && offset.localScale.x > 0.2f)
			{
				Transform obj = offset;
				obj.localScale += new Vector3(amount, amount, amount);
			}
			else
			{
				if (!(amount > 0f) || !(offset.localScale.x < 2f))
				{
					SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
					return;
				}
				Transform obj2 = offset;
				obj2.localScale += new Vector3(amount, amount, amount);
			}
			SM.PlayGlobalUISound((GlobalUISound)0, ((Component)GM.CurrentPlayerBody).transform.position);
		}

		public void AdjustWidth(float amount)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			if (amount < 0f && offset.localScale.x > 0.3f)
			{
				Transform obj = offset;
				obj.localScale += new Vector3(amount, 0f, 0f);
			}
			else
			{
				if (!(amount > 0f) || !(offset.localScale.x < 1.9f))
				{
					SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
					return;
				}
				Transform obj2 = offset;
				obj2.localScale += new Vector3(amount, 0f, 0f);
			}
			SM.PlayGlobalUISound((GlobalUISound)0, ((Component)GM.CurrentPlayerBody).transform.position);
		}

		public void ToggleCrosshair()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			crosshair.SetActive(!crosshair.activeSelf);
			SM.PlayGlobalUISound((GlobalUISound)0, ((Component)GM.CurrentPlayerBody).transform.position);
		}

		public void ToggleUI()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < buttons.Length; i++)
			{
				((Component)buttons[i]).gameObject.SetActive(!((Component)buttons[i]).gameObject.activeSelf);
			}
			SM.PlayGlobalUISound((GlobalUISound)0, ((Component)GM.CurrentPlayerBody).transform.position);
		}

		public void ResetScale()
		{
			//IL_0007: 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)
			offset.localScale = Vector3.one;
			SM.PlayGlobalUISound((GlobalUISound)0, ((Component)GM.CurrentPlayerBody).transform.position);
		}

		public void ToggleOnCamera()
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if (cameras.Count > 0 && index < cameras.Count && Object.op_Implicit((Object)(object)cameras[index]))
			{
				((Behaviour)cameras[index]).enabled = !((Behaviour)cameras[index]).enabled;
				SM.PlayGlobalUISound((GlobalUISound)0, ((Component)GM.CurrentPlayerBody).transform.position);
			}
			else
			{
				SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
			}
		}

		public void RemoveCurrentCamera()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if (cameras.Count == 0 || index >= cameras.Count)
			{
				SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
				return;
			}
			cameras.RemoveAt(index);
			if (cameras.Count == 0)
			{
				cameraName.text = "Awaiting Cameras";
				SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
				return;
			}
			if (index > 0)
			{
				index--;
			}
			else
			{
				index = 0;
			}
			SetCameraAtIndex();
		}

		private void SetCameraAtIndex()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			renderMaterial.SetTexture("_MainTex", (Texture)(object)cameras[index].activeTexture);
			((Renderer)meshRenderer).materials[1] = renderMaterial;
			cameraName.text = ((Object)((Component)cameras[index]).transform).name + " " + index;
			SM.PlayGlobalUISound((GlobalUISound)0, ((Component)GM.CurrentPlayerBody).transform.position);
		}

		public void NextCamera()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (cameras.Count == 0)
			{
				SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
				return;
			}
			if (index + 1 >= cameras.Count)
			{
				index = 0;
			}
			else
			{
				index++;
			}
			if ((Object)(object)cameras[index] == (Object)null)
			{
				SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
			}
			else
			{
				SetCameraAtIndex();
			}
		}

		public void PrevCamera()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (cameras.Count == 0)
			{
				SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
				return;
			}
			if (index - 1 < 0)
			{
				index = cameras.Count - 1;
			}
			else
			{
				index--;
			}
			if ((Object)(object)cameras[index] == (Object)null)
			{
				SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
			}
			else
			{
				SetCameraAtIndex();
			}
		}

		public void RefreshCameras()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			Camera[] array = Object.FindObjectsOfType<Camera>();
			cameras.Clear();
			index = 0;
			for (int i = 0; i < array.Length; i++)
			{
				if ((Object)(object)array[i].activeTexture != (Object)null)
				{
					cameras.Add(array[i]);
				}
			}
			if (cameras.Count > 0)
			{
				SetCameraAtIndex();
				return;
			}
			cameraName.text = "Awaiting Cameras";
			SM.PlayGlobalUISound((GlobalUISound)1, ((Component)GM.CurrentPlayerBody).transform.position);
		}
	}
}
namespace Packer.Packers_Vending_Machines
{
	public class AmmoBoxVendor : VendingMachine
	{
		[Header("-Ammo Box Vendor-")]
		public bool prefilled = true;

		public int cost = 1;

		[Header("Item Checker")]
		public FVRQuickBeltSlot itemSlot;

		private FireArmRoundType roundType;

		private FVRInteractiveObject lastItem;

		private FVRPhysicalObject physicalObject;

		protected List<FVRObject> fvrObjects = new List<FVRObject>();

		public override void Start()
		{
			displayLogo.SetActive(true);
			ItemScan();
			UpdateMoneyDisplay();
			base.LoadConfig();
		}

		public override void SetupCosts()
		{
			prefilled = VendingMachine.config.ammoBoxVendor.prefilled;
			cost = VendingMachine.config.ammoBoxVendor.costs[0];
			if (itemTables.Count == 0)
			{
				itemTables.Add(new ItemTable());
			}
		}

		protected override void Update()
		{
			base.Update();
			if ((Object)(object)itemSlot.HeldObject != (Object)null)
			{
				ItemScan();
			}
			else if ((Object)(object)itemSlot.HeldObject == (Object)null && buttonList.Count > 0)
			{
				for (int i = 0; i < buttonList.Count; i++)
				{
					Object.Destroy((Object)(object)((Component)buttonList[i]).gameObject);
				}
				buttonList.Clear();
				displayLogo.SetActive(true);
				lastItem = null;
			}
		}

		private void ItemScan()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Invalid comparison between Unknown and I4
			if ((Object)(object)itemSlot.HeldObject == (Object)null || (Object)(object)itemSlot.HeldObject == (Object)(object)lastItem)
			{
				return;
			}
			lastItem = itemSlot.HeldObject;
			physicalObject = ((Component)itemSlot.HeldObject).gameObject.GetComponent<FVRPhysicalObject>();
			if ((Object)(object)physicalObject == (Object)null)
			{
				return;
			}
			roundType = physicalObject.ObjectWrapper.RoundType;
			fvrObjects = new List<FVRObject>();
			fvrObjects.AddRange(ManagerSingleton<IM>.Instance.ObjectDic.Values);
			for (int num = fvrObjects.Count - 1; num >= 0; num--)
			{
				if (fvrObjects[num].RoundType != roundType || (int)fvrObjects[num].MagazineType != 0 || (int)fvrObjects[num].Category != 40 || !fvrObjects[num].UsesRoundTypeFlag)
				{
					fvrObjects.RemoveAt(num);
				}
			}
			if (fvrObjects.Count == 0)
			{
				SFXFailed();
			}
			itemTables[0].collected.Clear();
			itemTables[0].collected = fvrObjects;
			itemTables[0].cost = cost;
			GenerateButtons(itemTables[0]);
		}

		public override GameObject PurchaseItemID(FVRObject fvrObject, int cost)
		{
			GameObject val = base.PurchaseItemID(fvrObject, cost);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			FVRFireArmMagazine component = val.GetComponent<FVRFireArmMagazine>();
			if ((Object)(object)component != (Object)null)
			{
				SetMagazinePrefilled(component, prefilled);
			}
			return val;
		}
	}
	[Serializable]
	public class ItemTable
	{
		public string name = "Table";

		public int cost = 2;

		public Sprite thumbnail;

		public List<FVRObject> collected;

		public bool objectIDsOnly = false;

		public List<string> objectIDs = new List<string>();

		public ObjectCategory category = (ObjectCategory)0;

		public List<OTagSet> set = new List<OTagSet>();

		public List<OTagEra> eras = new List<OTagEra>();

		public List<OTagFirearmSize> sizes = new List<OTagFirearmSize>();

		public List<OTagFirearmAction> actions = new List<OTagFirearmAction>();

		public List<OTagFirearmFiringMode> modes = new List<OTagFirearmFiringMode>();

		public List<OTagFirearmFiringMode> excludeModes = new List<OTagFirearmFiringMode>();

		public List<OTagFirearmFeedOption> feedoptions = new List<OTagFirearmFeedOption>();

		public List<OTagFirearmMount> mounts = new List<OTagFirearmMount>();

		public List<OTagFirearmRoundPower> roundPowers = new List<OTagFirearmRoundPower>();

		public List<OTagAttachmentFeature> features = new List<OTagAttachmentFeature>();

		public List<OTagMeleeStyle> meleeStyles = new List<OTagMeleeStyle>();

		public List<OTagMeleeHandedness> meleeHandedness = new List<OTagMeleeHandedness>();

		public List<OTagPowerupType> powerupTypes = new List<OTagPowerupType>();

		public List<OTagThrownType> thrownTypes = new List<OTagThrownType>();

		public List<OTagThrownDamageType> thrownDamage = new List<OTagThrownDamageType>();

		public List<OTagFirearmCountryOfOrigin> countryOfOrigins = new List<OTagFirearmCountryOfOrigin>();

		public ItemTable SetupTable()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: 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_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: 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_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			if (objectIDsOnly)
			{
				collected.Clear();
				FVRObject value = null;
				for (int i = 0; i < objectIDs.Count; i++)
				{
					if (IM.OD.TryGetValue(objectIDs[i], out value))
					{
						collected.Add(value);
					}
				}
				return this;
			}
			collected = new List<FVRObject>();
			collected.AddRange(ManagerSingleton<IM>.Instance.ObjectDic.Values);
			for (int num = collected.Count - 1; num >= 0; num--)
			{
				if (objectIDs.Contains(collected[num].ItemID))
				{
					continue;
				}
				if ((int)category != 0 && collected[num].Category != category)
				{
					collected.RemoveAt(num);
					continue;
				}
				if (set.Count > 0 && !set.Contains(collected[num].TagSet))
				{
					collected.RemoveAt(num);
					continue;
				}
				if (eras.Count > 0 && !eras.Contains(collected[num].TagEra))
				{
					collected.RemoveAt(num);
					continue;
				}
				if (sizes.Count > 0 && !sizes.Contains(collected[num].TagFirearmSize))
				{
					collected.RemoveAt(num);
					continue;
				}
				if (actions.Count > 0 && !actions.Contains(collected[num].TagFirearmAction))
				{
					collected.RemoveAt(num);
					continue;
				}
				if (roundPowers.Count > 0 && !roundPowers.Contains(collected[num].TagFirearmRoundPower))
				{
					collected.RemoveAt(num);
					continue;
				}
				if (modes.Count > 0)
				{
					bool flag = false;
					for (int j = 0; j < modes.Count; j++)
					{
						if (!collected[num].TagFirearmFiringModes.Contains(modes[j]))
						{
							flag = true;
							break;
						}
					}
					if (flag)
					{
						collected.RemoveAt(num);
						continue;
					}
				}
				if (excludeModes.Count > 0)
				{
					bool flag2 = false;
					for (int k = 0; k < excludeModes.Count; k++)
					{
						if (collected[num].TagFirearmFiringModes.Contains(excludeModes[k]))
						{
							flag2 = true;
							break;
						}
					}
					if (flag2)
					{
						collected.RemoveAt(num);
						continue;
					}
				}
				if (feedoptions.Count > 0)
				{
					bool flag3 = false;
					for (int l = 0; l < feedoptions.Count; l++)
					{
						if (!collected[num].TagFirearmFeedOption.Contains(feedoptions[l]))
						{
							flag3 = true;
							break;
						}
					}
					if (flag3)
					{
						collected.RemoveAt(num);
						continue;
					}
				}
				if (mounts.Count > 0)
				{
					bool flag4 = false;
					for (int m = 0; m < mounts.Count; m++)
					{
						if (!collected[num].TagFirearmMounts.Contains(mounts[m]))
						{
							flag4 = true;
							break;
						}
					}
					if (flag4)
					{
						collected.RemoveAt(num);
					}
				}
				if (features.Count > 0 && !features.Contains(collected[num].TagAttachmentFeature))
				{
					collected.RemoveAt(num);
				}
				if (meleeStyles.Count > 0 && !meleeStyles.Contains(collected[num].TagMeleeStyle))
				{
					collected.RemoveAt(num);
				}
				if (meleeHandedness.Count > 0 && !meleeHandedness.Contains(collected[num].TagMeleeHandedness))
				{
					collected.RemoveAt(num);
				}
				if (powerupTypes.Count > 0 && !powerupTypes.Contains(collected[num].TagPowerupType))
				{
					collected.RemoveAt(num);
				}
				if (thrownTypes.Count > 0 && !thrownTypes.Contains(collected[num].TagThrownType))
				{
					collected.RemoveAt(num);
				}
				if (thrownDamage.Count > 0 && !thrownDamage.Contains(collected[num].TagThrownDamageType))
				{
					collected.RemoveAt(num);
				}
				if (countryOfOrigins.Count > 0 && !countryOfOrigins.Contains(collected[num].TagFirearmCountryOfOrigin))
				{
					collected.RemoveAt(num);
				}
			}
			return this;
		}
	}
	public class ModConfig
	{
		[Serializable]
		public class Config
		{
			[Serializable]
			public class VendorConfig
			{
				public string name;

				public bool prefilled = true;

				public int[] costs;
			}

			public VendorConfig ammoBoxVendor = new VendorConfig
			{
				name = "Ammo Box Vendor",
				prefilled = true,
				costs = new int[1] { 1 }
			};

			public VendorConfig ordnanceVendor = new VendorConfig
			{
				name = "Ordnance Vendor",
				prefilled = true,
				costs = new int[5] { 2, 5, 3, 1, 2 }
			};
		}

		public static Config LoadConfig()
		{
			string path = Paths.PluginPath + "/Packer-Packers_Vending_Machines/config.json";
			if (!File.Exists(path))
			{
				string contents = JsonUtility.ToJson((object)new Config());
				File.WriteAllText(path, contents);
			}
			Config result = new Config();
			using (StreamReader streamReader = new StreamReader(path))
			{
				string text = streamReader.ReadToEnd();
				try
				{
					result = JsonUtility.FromJson<Config>(text);
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex.Message);
					return result;
				}
			}
			return result;
		}
	}
	public class OriOrdnanceVendor : VendingMachine
	{
		private enum VendorType
		{
			Grenade,
			Airstrike,
			Ordnance,
			Zippo,
			Other
		}

		protected FVRObject fvrZippo = null;

		public override void Start()
		{
			base.LoadConfig();
			PopulateCategoryButtons();
			UpdateMoneyDisplay();
		}

		public override void SetupCosts()
		{
			for (int i = 0; i < itemTables.Count; i++)
			{
				switch (itemTables[i].name)
				{
				case "Grenade":
					itemTables[i].cost = VendingMachine.config.ordnanceVendor.costs[0];
					break;
				case "Airstrike":
					itemTables[i].cost = VendingMachine.config.ordnanceVendor.costs[1];
					break;
				case "Ordnance":
					itemTables[i].cost = VendingMachine.config.ordnanceVendor.costs[2];
					break;
				case "Zippo":
					itemTables[i].cost = VendingMachine.config.ordnanceVendor.costs[3];
					break;
				default:
					itemTables[i].cost = VendingMachine.config.ordnanceVendor.costs[4];
					break;
				}
			}
		}
	}
	public class VendingMachine : FVRFireArmMagazine
	{
		public static ModConfig.Config config;

		[Header("-Vending Machine-")]
		[Header("Currency")]
		public int money = 0;

		private int prevNumRounds = 0;

		[Header("Dispenser")]
		public Transform itemSpawn;

		public Transform refundSpawn;

		[Header("UI")]
		public Sprite defaultSprite;

		public Text moneyText;

		public GameObject displayLogo;

		public GameObject buttonPrefab;

		protected List<FVRPointableButton> buttonList = new List<FVRPointableButton>();

		[Header("Audio")]
		public AudioSource audioSource;

		public AudioClip addMoneyClip;

		public AudioClip purchaseClip;

		public AudioClip failedClip;

		[Header("Category Item Tables")]
		[SerializeField]
		protected List<ItemTable> itemTables = new List<ItemTable>();

		[Header("Category Selector")]
		[SerializeField]
		protected Transform categoryParent;

		[SerializeField]
		protected GameObject categoryButtonPrefab;

		protected List<GameObject> categoryButtons = new List<GameObject>();

		[Header("Category Content")]
		[SerializeField]
		protected Transform categoryContentParent;

		[SerializeField]
		protected GameObject categoryContentPrefab;

		protected List<GameObject> categoryContents = new List<GameObject>();

		public void OpenCategory(GameObject content)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < categoryContents.Count; i++)
			{
				categoryContents[i].SetActive(false);
			}
			SM.PlayGlobalUISound((GlobalUISound)0, ((Component)this).transform.position);
			if ((Object)(object)content != (Object)null)
			{
				content.SetActive(true);
			}
		}

		protected void PopulateCategoryButtons()
		{
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Expected O, but got Unknown
			for (int i = 0; i < itemTables.Count; i++)
			{
				if (itemTables[i].collected.Count == 0)
				{
					itemTables[i].SetupTable();
				}
				if (itemTables[i].collected.Count != 0)
				{
					FVRPointableButton component = Object.Instantiate<GameObject>(categoryButtonPrefab, categoryParent).GetComponent<FVRPointableButton>();
					component.Text.text = itemTables[i].name;
					((Component)component).gameObject.SetActive(true);
					component.Image.sprite = itemTables[i].thumbnail;
					categoryButtons.Add(((Component)component).gameObject);
					GameObject content = Object.Instantiate<GameObject>(categoryContentPrefab, categoryContentParent);
					categoryContents.Add(content);
					PopulateCategoryContent(content.transform, itemTables[i]);
					((UnityEvent)((Component)component).gameObject.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
					{
						OpenCategory(content);
					});
				}
			}
		}

		protected void PopulateCategoryContent(Transform parent, ItemTable itemTable)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			for (int i = 0; i < itemTable.collected.Count; i++)
			{
				if (!((Object)(object)itemTable.collected[i] == (Object)null))
				{
					FVRObject item = itemTable.collected[i];
					int num = i;
					FVRPointable val = GenerateButton(item, itemTable.cost);
					((Component)val).transform.SetParent(parent);
					((UnityEvent)((Component)val).gameObject.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
					{
						PurchaseItemID(item, itemTable.cost);
					});
				}
			}
		}

		protected virtual void Update()
		{
			if (prevNumRounds != base.m_numRounds)
			{
				UpdateMoneyDisplay();
				prevNumRounds = base.m_numRounds;
			}
		}

		public virtual void LoadConfig()
		{
			config = ModConfig.LoadConfig();
			SetupCosts();
		}

		public virtual void SetupCosts()
		{
		}

		public virtual void UpdateMoneyDisplay()
		{
			money = 0;
			for (int i = 0; i < base.LoadedRounds.Length; i++)
			{
				if (base.LoadedRounds[i] != null && !((Object)(object)base.LoadedRounds[i].LR_ObjectWrapper == (Object)null))
				{
					money += GetRoundValue(base.LoadedRounds[i].LR_ObjectWrapper.ItemID);
				}
			}
			moneyText.text = money.ToString();
		}

		public virtual bool SpendMoney(int amount)
		{
			UpdateMoneyDisplay();
			if (money < amount)
			{
				SFXFailed();
				return false;
			}
			money -= amount;
			UpdateLoadedRoundMoney(money);
			return true;
		}

		protected void ClearAllRounds()
		{
			for (int i = 0; i < base.LoadedRounds.Length; i++)
			{
				base.LoadedRounds[i] = null;
			}
			base.m_numRounds = 0;
		}

		public void UpdateLoadedRoundMoney(int amount)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			ClearAllRounds();
			int num = 0;
			while (amount > 0 && num < base.LoadedRounds.Length)
			{
				string highestValueCashMoney = GetHighestValueCashMoney(amount);
				if (highestValueCashMoney == "")
				{
					break;
				}
				FVRObject value = null;
				IM.OD.TryGetValue(highestValueCashMoney, out value);
				if (!((Object)(object)value == (Object)null))
				{
					base.LoadedRounds[num] = new FVRLoadedRound();
					base.LoadedRounds[num].LR_ObjectWrapper = value;
					amount -= GetRoundValue(highestValueCashMoney);
					num++;
				}
			}
			UpdateMoneyDisplay();
		}

		public virtual void RefundButton()
		{
			int num = 0;
			while (money > 0)
			{
				string highestValueCashMoney = GetHighestValueCashMoney(money);
				if (highestValueCashMoney == "")
				{
					break;
				}
				money -= GetRoundValue(highestValueCashMoney);
				FVRObject value = null;
				IM.OD.TryGetValue(highestValueCashMoney, out value);
				((MonoBehaviour)this).StartCoroutine(WaitandCreate(((AnvilAsset)value).GetGameObject(), (float)num * 0.25f));
				num++;
			}
			ClearAllRounds();
			UpdateMoneyDisplay();
		}

		protected IEnumerator WaitandCreate(GameObject prefab, float waitTime)
		{
			yield return (object)new WaitForSeconds(waitTime);
			Object.Instantiate<GameObject>(prefab, refundSpawn.position + Vector3.up * 0.05f, refundSpawn.rotation);
		}

		protected void RemoveAllButtons()
		{
			for (int i = 0; i < buttonList.Count; i++)
			{
				Object.Destroy((Object)(object)((Component)buttonList[i]).gameObject);
			}
			buttonList.Clear();
		}

		protected virtual void GenerateButtons(ItemTable itemTable)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			if (itemTable.collected.Count == 0)
			{
				itemTable.SetupTable();
			}
			displayLogo.SetActive(false);
			for (int i = 0; i < itemTable.collected.Count; i++)
			{
				if (!((Object)(object)itemTable.collected[i] == (Object)null))
				{
					FVRObject item = itemTable.collected[i];
					int num = i;
					FVRPointable val = GenerateButton(item, itemTable.cost);
					((UnityEvent)((Component)val).gameObject.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
					{
						PurchaseItemID(item, itemTable.cost);
					});
				}
			}
		}

		protected virtual FVRPointable GenerateButton(FVRObject itemObject, int itemCost)
		{
			if ((Object)(object)itemObject == (Object)null)
			{
				Debug.LogError((object)"Could not generate button with missing FVRObject");
				return null;
			}
			FVRPointableButton component = Object.Instantiate<GameObject>(buttonPrefab, buttonPrefab.transform.parent).GetComponent<FVRPointableButton>();
			((Component)component).gameObject.SetActive(true);
			if ((Object)(object)component.Text != (Object)null)
			{
				component.Text.text = itemObject.DisplayName;
			}
			ManagerSingleton<IM>.Instance.SpawnerIDDic.TryGetValue(itemObject.SpawnedFromId, out var value);
			if ((Object)(object)value != (Object)null && (Object)(object)value.Sprite != (Object)null)
			{
				component.Image.sprite = value.Sprite;
			}
			else
			{
				component.Image.sprite = defaultSprite;
			}
			buttonList.Add(component);
			for (int i = 0; i < ((Component)component).transform.childCount; i++)
			{
				if (((Object)((Component)component).transform.GetChild(i)).name == "Cost")
				{
					((Component)((Component)component).transform.GetChild(i)).GetComponent<Text>().text = itemCost.ToString();
					break;
				}
			}
			return (FVRPointable)(object)component;
		}

		protected virtual void GenerateButtons(List<FVRObject> itemsObjects)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			displayLogo.SetActive(false);
			RemoveAllButtons();
			for (int i = 0; i < itemsObjects.Count; i++)
			{
				int num = i;
				int newCost = 1;
				((UnityEvent)((Component)GenerateButton(itemsObjects[i], newCost)).gameObject.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					PurchaseItemID(itemsObjects[i], newCost);
				});
			}
		}

		protected virtual void GenerateButtons(List<FVRObject> itemsObjects, int newCost)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			displayLogo.SetActive(false);
			for (int i = 0; i < itemsObjects.Count; i++)
			{
				if (!((Object)(object)itemsObjects[i] == (Object)null))
				{
					FVRObject item = itemsObjects[i];
					int num = i;
					FVRPointable val = GenerateButton(item, newCost);
					((UnityEvent)((Component)val).gameObject.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
					{
						PurchaseItemID(item, newCost);
					});
				}
			}
		}

		public virtual GameObject PurchaseItemID(FVRObject fvrObject, int cost)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)fvrObject == (Object)null || !SpendMoney(cost))
			{
				SFXFailed();
				return null;
			}
			SFXPurchase();
			UpdateLoadedRoundMoney(money);
			GameObject gameObject = ((AnvilAsset)fvrObject).GetGameObject();
			return Object.Instantiate<GameObject>(gameObject, itemSpawn.position, itemSpawn.rotation);
		}

		public void SetMagazinePrefilled(FVRFireArmMagazine mag, bool prefilled)
		{
			if (!prefilled && (Object)(object)mag != (Object)null)
			{
				for (int i = 0; i < mag.LoadedRounds.Length; i++)
				{
					mag.LoadedRounds[i] = null;
				}
				mag.m_numRounds = 0;
			}
		}

		protected virtual int GetRoundValue(string itemID)
		{
			return itemID switch
			{
				"Cartridge69CashMoneyD1" => 1, 
				"Cartridge69CashMoneyD5" => 5, 
				"Cartridge69CashMoneyD10" => 10, 
				"Cartridge69CashMoneyD25" => 25, 
				"Cartridge69CashMoneyD100" => 100, 
				"Cartridge69CashMoneyD1000" => 1000, 
				_ => 0, 
			};
		}

		protected virtual string GetHighestValueCashMoney(int cash)
		{
			if (cash >= 1000)
			{
				return "Cartridge69CashMoneyD1000";
			}
			if (cash >= 100)
			{
				return "Cartridge69CashMoneyD100";
			}
			if (cash >= 25)
			{
				return "Cartridge69CashMoneyD25";
			}
			if (cash >= 10)
			{
				return "Cartridge69CashMoneyD10";
			}
			if (cash >= 5)
			{
				return "Cartridge69CashMoneyD5";
			}
			if (cash >= 1)
			{
				return "Cartridge69CashMoneyD1";
			}
			return "";
		}

		protected virtual FVRLoadedRound GetLoadedRound(string itemID)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			FVRLoadedRound result = new FVRLoadedRound();
			string highestValueCashMoney = GetHighestValueCashMoney(money);
			IM.OD.TryGetValue(itemID, out var _);
			return result;
		}

		public void SFXAddMoney()
		{
			audioSource.PlayOneShot(addMoneyClip);
		}

		public void SFXPurchase()
		{
			audioSource.PlayOneShot(purchaseClip);
		}

		public void SFXFailed()
		{
			audioSource.PlayOneShot(failedClip);
		}
	}
}
public class CuttableMesh
{
	private MeshRenderer inputMeshRenderer;

	private bool hasUvs;

	private bool hasUv1s;

	private bool hasColours;

	private List<CuttableSubMesh> subMeshes;

	public CuttableMesh(Mesh inputMesh)
	{
		Init(inputMesh, ((Object)inputMesh).name);
	}

	public CuttableMesh(MeshRenderer input)
	{
		inputMeshRenderer = input;
		MeshFilter component = ((Component)input).GetComponent<MeshFilter>();
		Mesh sharedMesh = component.sharedMesh;
		Init(sharedMesh, ((Object)input).name);
	}

	public CuttableMesh(CuttableMesh inputMesh, List<CuttableSubMesh> newSubMeshes)
	{
		inputMeshRenderer = inputMesh.inputMeshRenderer;
		hasUvs = inputMesh.hasUvs;
		hasUv1s = inputMesh.hasUv1s;
		hasColours = inputMesh.hasColours;
		subMeshes = new List<CuttableSubMesh>();
		subMeshes.AddRange(newSubMeshes);
	}

	private void Init(Mesh inputMesh, string debugName)
	{
		subMeshes = new List<CuttableSubMesh>();
		if (inputMesh.isReadable)
		{
			Vector3[] vertices = inputMesh.vertices;
			Vector3[] normals = inputMesh.normals;
			Vector2[] uv = inputMesh.uv;
			Vector2[] uv2 = inputMesh.uv2;
			Color32[] colors = inputMesh.colors32;
			hasUvs = uv != null && uv.Length > 0;
			hasUv1s = uv2 != null && uv2.Length > 0;
			hasColours = colors != null && colors.Length > 0;
			for (int i = 0; i < inputMesh.subMeshCount; i++)
			{
				int[] indices = inputMesh.GetIndices(i);
				CuttableSubMesh item = new CuttableSubMesh(indices, vertices, normals, colors, uv, uv2);
				subMeshes.Add(item);
			}
		}
		else
		{
			Debug.LogError((object)("CuttableMesh's input mesh is not readable: " + debugName), (Object)(object)inputMesh);
		}
	}

	public void Add(CuttableMesh other)
	{
		if (subMeshes.Count != other.subMeshes.Count)
		{
			throw new Exception("Mismatched submesh count");
		}
		for (int i = 0; i < subMeshes.Count; i++)
		{
			subMeshes[i].Add(other.subMeshes[i]);
		}
	}

	public int NumSubMeshes()
	{
		return subMeshes.Count;
	}

	public bool HasUvs()
	{
		return hasUvs;
	}

	public bool HasColours()
	{
		return hasColours;
	}

	public List<CuttableSubMesh> GetSubMeshes()
	{
		return subMeshes;
	}

	public CuttableSubMesh GetSubMesh(int index)
	{
		return subMeshes[index];
	}

	public Transform GetTransform()
	{
		if ((Object)(object)inputMeshRenderer != (Object)null)
		{
			return ((Component)inputMeshRenderer).transform;
		}
		return null;
	}

	public MeshRenderer ConvertToRenderer(string newObjectName)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: 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)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		Mesh val = CreateMesh();
		if (val.vertexCount == 0)
		{
			return null;
		}
		GameObject val2 = new GameObject(newObjectName);
		val2.transform.SetParent(((Component)inputMeshRenderer).transform);
		val2.transform.localPosition = Vector3.zero;
		val2.transform.localRotation = Quaternion.identity;
		val2.transform.localScale = Vector3.one;
		MeshFilter val3 = val2.AddComponent<MeshFilter>();
		val3.mesh = val;
		MeshRenderer val4 = val2.AddComponent<MeshRenderer>();
		((Renderer)val4).shadowCastingMode = ((Renderer)inputMeshRenderer).shadowCastingMode;
		((Renderer)val4).reflectionProbeUsage = ((Renderer)inputMeshRenderer).reflectionProbeUsage;
		((Renderer)val4).lightProbeUsage = ((Renderer)inputMeshRenderer).lightProbeUsage;
		((Renderer)val4).sharedMaterials = ((Renderer)inputMeshRenderer).sharedMaterials;
		return val4;
	}

	public Mesh CreateMesh()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		Mesh val = new Mesh();
		int num = 0;
		for (int i = 0; i < subMeshes.Count; i++)
		{
			num += subMeshes[i].NumIndices();
		}
		List<Vector3> list = new List<Vector3>();
		List<Vector3> list2 = new List<Vector3>();
		List<Color32> list3 = ((!hasColours) ? null : new List<Color32>());
		List<Vector2> list4 = ((!hasUvs) ? null : new List<Vector2>());
		List<Vector2> list5 = ((!hasUv1s) ? null : new List<Vector2>());
		List<int> list6 = new List<int>();
		foreach (CuttableSubMesh subMesh in subMeshes)
		{
			list6.Add(list.Count);
			subMesh.AddTo(list, list2, list3, list4, list5);
		}
		val.vertices = list.ToArray();
		val.normals = list2.ToArray();
		val.colors32 = ((!hasColours) ? null : list3.ToArray());
		val.uv = ((!hasUvs) ? null : list4.ToArray());
		val.uv2 = ((!hasUv1s) ? null : list5.ToArray());
		val.subMeshCount = subMeshes.Count;
		for (int j = 0; j < subMeshes.Count; j++)
		{
			CuttableSubMesh cuttableSubMesh = subMeshes[j];
			int num2 = list6[j];
			int[] array = cuttableSubMesh.GenIndices();
			for (int k = 0; k < array.Length; k++)
			{
				array[k] += num2;
			}
			val.SetTriangles(array, j, true);
		}
		return val;
	}
}
public class CuttableSubMesh
{
	private List<Vector3> vertices;

	private List<Vector3> normals;

	private List<Color32> colours;

	private List<Vector2> uvs;

	private List<Vector2> uv1s;

	public CuttableSubMesh(bool hasNormals, bool hasColours, bool hasUvs, bool hasUv1)
	{
		vertices = new List<Vector3>();
		if (hasNormals)
		{
			normals = new List<Vector3>();
		}
		if (hasColours)
		{
			colours = new List<Color32>();
		}
		if (hasUvs)
		{
			uvs = new List<Vector2>();
		}
		if (hasUv1)
		{
			uv1s = new List<Vector2>();
		}
	}

	public CuttableSubMesh(int[] indices, Vector3[] inputVertices, Vector3[] inputNormals, Color32[] inputColours, Vector2[] inputUvs, Vector2[] inputUv1)
	{
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		vertices = new List<Vector3>();
		if (inputNormals != null && inputNormals.Length > 0)
		{
			normals = new List<Vector3>();
		}
		if (inputColours != null && inputColours.Length > 0)
		{
			colours = new List<Color32>();
		}
		if (inputUvs != null && inputUvs.Length > 0)
		{
			uvs = new List<Vector2>();
		}
		if (inputUv1 != null && inputUv1.Length > 0)
		{
			uv1s = new List<Vector2>();
		}
		foreach (int num in indices)
		{
			vertices.Add(inputVertices[num]);
			if (normals != null)
			{
				normals.Add(inputNormals[num]);
			}
			if (colours != null)
			{
				colours.Add(inputColours[num]);
			}
			if (uvs != null)
			{
				uvs.Add(inputUvs[num]);
			}
			if (uv1s != null)
			{
				uv1s.Add(inputUv1[num]);
			}
		}
	}

	public void Add(CuttableSubMesh other)
	{
		for (int i = 0; i < other.vertices.Count; i++)
		{
			CopyVertex(i, other);
		}
	}

	public int NumVertices()
	{
		return vertices.Count;
	}

	public Vector3 GetVertex(int index)
	{
		//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_0013: Unknown result type (might be due to invalid IL or missing references)
		return vertices[index];
	}

	public bool HasNormals()
	{
		return normals != null;
	}

	public bool HasColours()
	{
		return colours != null;
	}

	public bool HasUvs()
	{
		return uvs != null;
	}

	public bool HasUv1()
	{
		return uv1s != null;
	}

	public void CopyVertex(int srcIndex, CuttableSubMesh srcMesh)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		vertices.Add(srcMesh.vertices[srcIndex]);
		if (normals != null)
		{
			normals.Add(srcMesh.normals[srcIndex]);
		}
		if (colours != null)
		{
			colours.Add(srcMesh.colours[srcIndex]);
		}
		if (uvs != null)
		{
			uvs.Add(srcMesh.uvs[srcIndex]);
		}
		if (uv1s != null)
		{
			uv1s.Add(srcMesh.uv1s[srcIndex]);
		}
	}

	public void AddInterpolatedVertex(int i0, int i1, float weight, CuttableSubMesh srcMesh)
	{
		//IL_0004: 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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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_001a: 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_003f: 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_0052: 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)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		Vector3 vertex = srcMesh.GetVertex(i0);
		Vector3 vertex2 = srcMesh.GetVertex(i1);
		vertices.Add(Vector3.Lerp(vertex, vertex2, weight));
		if (normals != null)
		{
			List<Vector3> list = normals;
			Vector3 val = Vector3.Lerp(srcMesh.normals[i0], srcMesh.normals[i1], weight);
			list.Add(((Vector3)(ref val)).normalized);
		}
		if (colours != null)
		{
			colours.Add(Color32.Lerp(srcMesh.colours[i0], srcMesh.colours[i1], weight));
		}
		if (uvs != null)
		{
			uvs.Add(Vector2.Lerp(srcMesh.uvs[i0], srcMesh.uvs[i1], weight));
		}
		if (uv1s != null)
		{
			uv1s.Add(Vector2.Lerp(srcMesh.uv1s[i0], srcMesh.uv1s[i1], weight));
		}
	}

	public void AddTo(List<Vector3> destVertices, List<Vector3> destNormals, List<Color32> destColours, List<Vector2> destUvs, List<Vector2> destUv1s)
	{
		destVertices.AddRange(vertices);
		if (normals != null)
		{
			destNormals.AddRange(normals);
		}
		if (colours != null)
		{
			destColours.AddRange(colours);
		}
		if (uvs != null)
		{
			destUvs.AddRange(uvs);
		}
		if (uv1s != null)
		{
			destUv1s.AddRange(uv1s);
		}
	}

	public int NumIndices()
	{
		return vertices.Count;
	}

	public int[] GenIndices()
	{
		int[] array = new int[vertices.Count];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = i;
		}
		return array;
	}
}
public enum VertexClassification
{
	Front = 1,
	Back = 2,
	OnPlane = 4
}
public class MeshCutter
{
	private CuttableMesh inputMesh;

	private List<CuttableSubMesh> outputFrontSubMeshes;

	private List<CuttableSubMesh> outputBackSubMeshes;

	public void Cut(CuttableMesh input, Plane worldCutPlane)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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_0051: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		inputMesh = input;
		outputFrontSubMeshes = new List<CuttableSubMesh>();
		outputBackSubMeshes = new List<CuttableSubMesh>();
		Transform transform = inputMesh.GetTransform();
		Plane cutPlane = default(Plane);
		if ((Object)(object)transform != (Object)null)
		{
			Vector3 val = transform.InverseTransformPoint(ClosestPointOnPlane(worldCutPlane, Vector3.zero));
			Vector3 val2 = transform.InverseTransformDirection(((Plane)(ref worldCutPlane)).normal);
			((Plane)(ref cutPlane))..ctor(val2, val);
		}
		else
		{
			cutPlane = worldCutPlane;
		}
		foreach (CuttableSubMesh subMesh in input.GetSubMeshes())
		{
			Cut(subMesh, cutPlane);
		}
	}

	private static Vector3 ClosestPointOnPlane(Plane plane, Vector3 point)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: 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_0035: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		float distanceToPoint = ((Plane)(ref plane)).GetDistanceToPoint(point);
		if (((Plane)(ref plane)).GetSide(point))
		{
			return point - ((Plane)(ref plane)).normal * distanceToPoint;
		}
		return point + ((Plane)(ref plane)).normal * distanceToPoint;
	}

	public CuttableMesh GetFrontOutput()
	{
		return new CuttableMesh(inputMesh, outputFrontSubMeshes);
	}

	public CuttableMesh GetBackOutput()
	{
		return new CuttableMesh(inputMesh, outputBackSubMeshes);
	}

	private void Cut(CuttableSubMesh inputSubMesh, Plane cutPlane)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_0081: 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)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		bool hasNormals = inputSubMesh.HasNormals();
		bool hasColours = inputSubMesh.HasColours();
		bool hasUvs = inputSubMesh.HasUvs();
		bool hasUv = inputSubMesh.HasUv1();
		CuttableSubMesh cuttableSubMesh = new CuttableSubMesh(hasNormals, hasColours, hasUvs, hasUv);
		CuttableSubMesh cuttableSubMesh2 = new CuttableSubMesh(hasNormals, hasColours, hasUvs, hasUv);
		for (int i = 0; i < inputSubMesh.NumVertices(); i += 3)
		{
			int num = i;
			int num2 = i + 1;
			int num3 = i + 2;
			Vector3 vertex = inputSubMesh.GetVertex(num);
			Vector3 vertex2 = inputSubMesh.GetVertex(num2);
			Vector3 vertex3 = inputSubMesh.GetVertex(num3);
			VertexClassification vertexClassification = Classify(vertex, cutPlane);
			VertexClassification vertexClassification2 = Classify(vertex2, cutPlane);
			VertexClassification vertexClassification3 = Classify(vertex3, cutPlane);
			int numFront = 0;
			int numBehind = 0;
			CountSides(vertexClassification, ref numFront, ref numBehind);
			CountSides(vertexClassification2, ref numFront, ref numBehind);
			CountSides(vertexClassification3, ref numFront, ref numBehind);
			if (numFront > 0 && numBehind == 0)
			{
				KeepTriangle(num, num2, num3, inputSubMesh, cuttableSubMesh);
			}
			else if (numFront == 0 && numBehind > 0)
			{
				KeepTriangle(num, num2, num3, inputSubMesh, cuttableSubMesh2);
			}
			else if (numFront == 2 && numBehind == 1)
			{
				if (vertexClassification == VertexClassification.Back)
				{
					SplitA(num, num2, num3, inputSubMesh, cutPlane, cuttableSubMesh2, cuttableSubMesh);
				}
				else if (vertexClassification2 == VertexClassification.Back)
				{
					SplitA(num2, num3, num, inputSubMesh, cutPlane, cuttableSubMesh2, cuttableSubMesh);
				}
				else
				{
					SplitA(num3, num, num2, inputSubMesh, cutPlane, cuttableSubMesh2, cuttableSubMesh);
				}
			}
			else if (numFront == 1 && numBehind == 2)
			{
				if (vertexClassification == VertexClassification.Front)
				{
					SplitA(num, num2, num3, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
				}
				else if (vertexClassification2 == VertexClassification.Front)
				{
					SplitA(num2, num3, num, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
				}
				else
				{
					SplitA(num3, num, num2, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
				}
			}
			else if (numFront == 1 && numBehind == 1)
			{
				if (vertexClassification == VertexClassification.OnPlane)
				{
					if (vertexClassification3 == VertexClassification.Front)
					{
						SplitB(num3, num, num2, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
					}
					else
					{
						SplitBFlipped(num2, num3, num, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
					}
					continue;
				}
				switch (vertexClassification2)
				{
				case VertexClassification.OnPlane:
					if (vertexClassification == VertexClassification.Front)
					{
						SplitB(num, num2, num3, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
					}
					else
					{
						SplitBFlipped(num3, num, num2, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
					}
					break;
				case VertexClassification.Front:
					SplitB(num2, num3, num, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
					break;
				default:
					SplitBFlipped(num, num2, num3, inputSubMesh, cutPlane, cuttableSubMesh, cuttableSubMesh2);
					break;
				}
			}
			else if (numFront == 0 && numBehind == 0)
			{
				Vector3 val = vertex2 - vertex;
				Vector3 val2 = vertex3 - vertex;
				Vector3 val3 = Vector3.Cross(val, val2);
				if (Vector3.Dot(val3, ((Plane)(ref cutPlane)).normal) > 0f)
				{
					KeepTriangle(num, num2, num3, inputSubMesh, cuttableSubMesh2);
				}
				else
				{
					KeepTriangle(num, num2, num3, inputSubMesh, cuttableSubMesh);
				}
			}
		}
		outputFrontSubMeshes.Add(cuttableSubMesh);
		outputBackSubMeshes.Add(cuttableSubMesh2);
	}

	private VertexClassification Classify(Vector3 vertex, Plane cutPlane)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(vertex.x, vertex.y, vertex.z);
		float distanceToPoint = ((Plane)(ref cutPlane)).GetDistanceToPoint(val);
		double num = 9.999999747378752E-06;
		if ((double)distanceToPoint > 0.0 - num && (double)distanceToPoint < num)
		{
			return VertexClassification.OnPlane;
		}
		if (distanceToPoint > 0f)
		{
			return VertexClassification.Front;
		}
		return VertexClassification.Back;
	}

	private void CountSides(VertexClassification c, ref int numFront, ref int numBehind)
	{
		switch (c)
		{
		case VertexClassification.Front:
			numFront++;
			break;
		case VertexClassification.Back:
			numBehind++;
			break;
		}
	}

	private void KeepTriangle(int i0, int i1, int i2, CuttableSubMesh inputSubMesh, CuttableSubMesh destSubMesh)
	{
		destSubMesh.CopyVertex(i0, inputSubMesh);
		destSubMesh.CopyVertex(i1, inputSubMesh);
		destSubMesh.CopyVertex(i2, inputSubMesh);
	}

	private void SplitA(int i0, int i1, int i2, CuttableSubMesh inputSubMesh, Plane cutPlane, CuttableSubMesh frontSubMesh, CuttableSubMesh backSubMesh)
	{
		//IL_0004: 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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: 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_002b: 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)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		Vector3 vertex = inputSubMesh.GetVertex(i0);
		Vector3 vertex2 = inputSubMesh.GetVertex(i1);
		Vector3 vertex3 = inputSubMesh.GetVertex(i2);
		CalcIntersection(vertex, vertex2, cutPlane, out var weight);
		CalcIntersection(vertex3, vertex, cutPlane, out var weight2);
		frontSubMesh.CopyVertex(i0, inputSubMesh);
		frontSubMesh.AddInterpolatedVertex(i0, i1, weight, inputSubMesh);
		frontSubMesh.AddInterpolatedVertex(i2, i0, weight2, inputSubMesh);
		backSubMesh.AddInterpolatedVertex(i0, i1, weight, inputSubMesh);
		backSubMesh.CopyVertex(i1, inputSubMesh);
		backSubMesh.CopyVertex(i2, inputSubMesh);
		backSubMesh.CopyVertex(i2, inputSubMesh);
		backSubMesh.AddInterpolatedVertex(i2, i0, weight2, inputSubMesh);
		backSubMesh.AddInterpolatedVertex(i0, i1, weight, inputSubMesh);
	}

	private void SplitB(int i0, int i1, int i2, CuttableSubMesh inputSubMesh, Plane cutPlane, CuttableSubMesh frontSubMesh, CuttableSubMesh backSubMesh)
	{
		//IL_0004: 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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		Vector3 vertex = inputSubMesh.GetVertex(i0);
		Vector3 vertex2 = inputSubMesh.GetVertex(i2);
		CalcIntersection(vertex2, vertex, cutPlane, out var weight);
		frontSubMesh.CopyVertex(i0, inputSubMesh);
		frontSubMesh.CopyVertex(i1, inputSubMesh);
		frontSubMesh.AddInterpolatedVertex(i2, i0, weight, inputSubMesh);
		backSubMesh.CopyVertex(i1, inputSubMesh);
		backSubMesh.CopyVertex(i2, inputSubMesh);
		backSubMesh.AddInterpolatedVertex(i2, i0, weight, inputSubMesh);
	}

	private void SplitBFlipped(int i0, int i1, int i2, CuttableSubMesh inputSubMesh, Plane cutPlane, CuttableSubMesh frontSubMesh, CuttableSubMesh backSubMesh)
	{
		//IL_0004: 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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		Vector3 vertex = inputSubMesh.GetVertex(i0);
		Vector3 vertex2 = inputSubMesh.GetVertex(i1);
		CalcIntersection(vertex, vertex2, cutPlane, out var weight);
		frontSubMesh.CopyVertex(i0, inputSubMesh);
		frontSubMesh.AddInterpolatedVertex(i0, i1, weight, inputSubMesh);
		frontSubMesh.CopyVertex(i2, inputSubMesh);
		backSubMesh.CopyVertex(i1, inputSubMesh);
		backSubMesh.CopyVertex(i2, inputSubMesh);
		backSubMesh.AddInterpolatedVertex(i0, i1, weight, inputSubMesh);
	}

	private Vector3 CalcIntersection(Vector3 v0, Vector3 v1, Plane plane, out float weight)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: 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)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: 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_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_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)
		Vector3 val = v1 - v0;
		float magnitude = ((Vector3)(ref val)).magnitude;
		Ray val2 = default(Ray);
		((Ray)(ref val2))..ctor(v0, val / magnitude);
		float num = default(float);
		((Plane)(ref plane)).Raycast(val2, ref num);
		Vector3 result = ((Ray)(ref val2)).origin + ((Ray)(ref val2)).direction * num;
		weight = num / magnitude;
		return result;
	}
}