Decompiled source of FroggosTacoBell v1.0.1

Mods/Froggos-TacoBell.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using FroggosTacoBell;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.Interaction;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.UI;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(TacoBellMod), "Froggos-TacoBell", "1.0.0", "froggonater", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Froggos-TacoBell")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Froggos-TacoBell")]
[assembly: AssemblyTitle("Froggos-TacoBell")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FroggosTacoBell
{
	internal static class Game
	{
		public static Transform Camera
		{
			get
			{
				try
				{
					if (PlayerSingleton<PlayerCamera>.InstanceExists)
					{
						Camera camera = PlayerSingleton<PlayerCamera>.Instance.Camera;
						if ((Object)(object)camera != (Object)null)
						{
							return ((Component)camera).transform;
						}
					}
				}
				catch
				{
				}
				Camera main = Camera.main;
				if (!((Object)(object)main != (Object)null))
				{
					return null;
				}
				return ((Component)main).transform;
			}
		}

		public static void Notify(string title, string subtitle, float seconds = 4f)
		{
			try
			{
				if (Singleton<NotificationsManager>.InstanceExists)
				{
					Singleton<NotificationsManager>.Instance.SendNotification(title, subtitle, ModelLoader.Icon("taco_icon"), seconds, true);
				}
			}
			catch (Exception ex)
			{
				TacoBellMod.Verbose("Notification failed: " + ex.Message);
			}
		}
	}
	internal static class Sfx
	{
		private const int Rate = 44100;

		private static AudioClip s_crunch;

		private static AudioClip s_ding;

		private static AudioSource s_source;

		private static AudioSource Source
		{
			get
			{
				//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_001d: Expected O, but got Unknown
				if ((Object)(object)s_source == (Object)null)
				{
					GameObject val = new GameObject("FroggosTacoBell_Audio");
					Object.DontDestroyOnLoad((Object)val);
					s_source = val.AddComponent<AudioSource>();
					s_source.spatialBlend = 0f;
					s_source.playOnAwake = false;
				}
				return s_source;
			}
		}

		private static AudioClip Make(string name, float[] data)
		{
			AudioClip obj = AudioClip.Create(name, data.Length, 1, 44100, false);
			obj.SetData(Il2CppStructArray<float>.op_Implicit(data), 0);
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}

		private static AudioClip CrunchClip()
		{
			Random random = new Random(11);
			int num = 14112;
			float[] array = new float[num];
			float num2 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)i / 44100f;
				float num4 = (float)(random.NextDouble() * 2.0 - 1.0);
				num2 += (num4 - num2) * 0.35f;
				float num5 = (num4 - num2) * Mathf.Exp((0f - num3) * 14f) * 0.55f;
				array[i] = num5;
			}
			for (int j = 0; j < 26; j++)
			{
				int num6 = (int)(44100.0 * (0.004 + random.NextDouble() * 0.24));
				float num7 = (float)(0.25 + random.NextDouble() * 0.5) * Mathf.Exp((float)(-num6) / 44100f * 6f);
				for (int k = 0; k < 260 && num6 + k < num; k++)
				{
					array[num6 + k] += (float)(random.NextDouble() * 2.0 - 1.0) * num7 * Mathf.Exp((float)(-k) / 45f);
				}
			}
			for (int l = 0; l < num; l++)
			{
				array[l] = Mathf.Clamp(array[l], -0.95f, 0.95f);
			}
			return Make("TB_crunch", array);
		}

		private static AudioClip DingClip()
		{
			int num = 39690;
			float[] array = new float[num];
			float[] array2 = new float[2] { 1318.5f, 1046.5f };
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / 44100f;
				float num3 = ((num2 < 0.35f) ? (Mathf.Sin((float)Math.PI * 2f * array2[0] * num2) * Mathf.Exp((0f - num2) * 7f)) : 0f);
				float num4 = num2 - 0.18f;
				float num5 = ((num4 > 0f) ? (Mathf.Sin((float)Math.PI * 2f * array2[1] * num4) * Mathf.Exp((0f - num4) * 5f)) : 0f);
				array[i] = (num3 + num5) * 0.25f;
			}
			return Make("TB_ding", array);
		}

		private static void Play(AudioClip clip, float volume)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Transform camera = Game.Camera;
				AudioSource source = Source;
				if ((Object)(object)camera != (Object)null)
				{
					((Component)source).transform.position = camera.position;
				}
				source.pitch = Random.Range(0.92f, 1.08f);
				source.PlayOneShot(clip, volume);
			}
			catch (Exception ex)
			{
				TacoBellMod.Verbose("Sound failed: " + ex.Message);
			}
		}

		public static void Crunch()
		{
			if ((Object)(object)s_crunch == (Object)null)
			{
				s_crunch = CrunchClip();
			}
			Play(s_crunch, 0.8f);
		}

		public static void Ding()
		{
			if ((Object)(object)s_ding == (Object)null)
			{
				s_ding = DingClip();
			}
			Play(s_ding, 0.5f);
		}
	}
	internal static class ModelLoader
	{
		public sealed class Model
		{
			public Mesh Mesh;

			public Material[] Materials;
		}

		private static readonly Dictionary<string, Model> Models = new Dictionary<string, Model>();

		private static readonly Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();

		private static readonly Dictionary<string, Sprite> Sprites = new Dictionary<string, Sprite>();

		private static byte[] Resource(string name)
		{
			using Stream stream = typeof(ModelLoader).Assembly.GetManifestResourceStream("FroggosTacoBell." + name);
			if (stream == null)
			{
				throw new FileNotFoundException("Embedded resource missing: " + name);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		public static Model Get(string name)
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			if (Models.TryGetValue(name, out var value) && (Object)(object)value.Mesh != (Object)null)
			{
				return value;
			}
			using BinaryReader binaryReader = new BinaryReader(new MemoryStream(Resource(name + ".mesh")));
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "TBMS")
			{
				throw new InvalidDataException(name + ".mesh is not a TBMS model");
			}
			int num = binaryReader.ReadInt32();
			Model model = new Model
			{
				Materials = (Material[])(object)new Material[num]
			};
			for (int i = 0; i < num; i++)
			{
				string name2 = Encoding.UTF8.GetString(binaryReader.ReadBytes(binaryReader.ReadInt32()));
				Color val = new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				Color gamma = ((Color)(ref val)).gamma;
				float metal = binaryReader.ReadSingle();
				float smooth = binaryReader.ReadSingle();
				byte b = binaryReader.ReadByte();
				string text = Encoding.UTF8.GetString(binaryReader.ReadBytes(binaryReader.ReadInt32()));
				Texture2D tex = ((text.Length > 0) ? Texture(text) : null);
				if ((b & 1) != 0)
				{
					model.Materials[i] = Mats.Glow(name2, tex, Color.white, TacoBellMod.Cfg.SignBrightness.Value);
				}
				else if ((b & 2) != 0)
				{
					model.Materials[i] = Mats.Cutout(name2, tex, 0.5f);
				}
				else
				{
					model.Materials[i] = Mats.Lit(name2, gamma, smooth, metal, tex);
				}
			}
			int num2 = binaryReader.ReadInt32();
			Vector3[] array = (Vector3[])(object)new Vector3[num2];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num2];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num2];
			for (int j = 0; j < num2; j++)
			{
				array[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array2[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array3[j] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			Mesh val2 = new Mesh
			{
				name = "TB_" + name
			};
			if (num2 > 65000)
			{
				val2.indexFormat = (IndexFormat)1;
			}
			val2.vertices = Il2CppStructArray<Vector3>.op_Implicit(array);
			val2.normals = Il2CppStructArray<Vector3>.op_Implicit(array2);
			val2.uv = Il2CppStructArray<Vector2>.op_Implicit(array3);
			val2.subMeshCount = num;
			for (int k = 0; k < num; k++)
			{
				int num3 = binaryReader.ReadInt32();
				int[] array4 = new int[num3];
				for (int l = 0; l < num3; l++)
				{
					array4[l] = binaryReader.ReadInt32();
				}
				val2.SetTriangles(Il2CppStructArray<int>.op_Implicit(array4), k);
			}
			val2.RecalculateBounds();
			((Object)val2).hideFlags = (HideFlags)32;
			model.Mesh = val2;
			Models[name] = model;
			return model;
		}

		public static GameObject Spawn(string name, Transform parent, bool shadows = true)
		{
			//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_0024: 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_0059: Expected O, but got Unknown
			Model model = Get(name);
			GameObject val = new GameObject("TB_" + name);
			val.transform.SetParent(parent, false);
			val.AddComponent<MeshFilter>().sharedMesh = model.Mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterials = new Il2CppReferenceArray<Material>(model.Materials);
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)(shadows ? 1 : 0);
			return val;
		}

		private static bool HasResource(string name)
		{
			return typeof(ModelLoader).Assembly.GetManifestResourceInfo("FroggosTacoBell." + name) != null;
		}

		public static Texture2D Texture(string name)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			if (Textures.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string text = (HasResource("ref_" + name + ".png") ? ("ref_" + name) : name);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
			ImageConversion.LoadImage(val, new Il2CppStructArray<byte>(Resource(text + ".png")), false);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).anisoLevel = 4;
			((Object)val).hideFlags = (HideFlags)32;
			((Object)val).name = "TB_" + name;
			Textures[name] = val;
			return val;
		}

		public static Sprite Icon(string name)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (Sprites.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Texture2D val = Texture(name);
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			((Object)val2).hideFlags = (HideFlags)32;
			((Object)val2).name = "TB_" + name;
			Sprites[name] = val2;
			return val2;
		}
	}
	internal static class Mats
	{
		private static Shader s_lit;

		private static Shader s_unlit;

		private static readonly Dictionary<string, Material> Cache = new Dictionary<string, Material>();

		public static Shader LitShader
		{
			get
			{
				if (!((Object)(object)s_lit != (Object)null))
				{
					return s_lit = Find(lit: true);
				}
				return s_lit;
			}
		}

		private static Shader Find(bool lit)
		{
			string[] array = ((!lit) ? new string[3] { "Universal Render Pipeline/Unlit", "Unlit/Texture", "Sprites/Default" } : new string[3] { "Universal Render Pipeline/Lit", "Universal Render Pipeline/Simple Lit", "Standard" });
			for (int i = 0; i < array.Length; i++)
			{
				Shader val = Shader.Find(array[i]);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			try
			{
				foreach (MeshRenderer item in Object.FindObjectsOfType<MeshRenderer>())
				{
					Material sharedMaterial = ((Renderer)item).sharedMaterial;
					if ((Object)(object)sharedMaterial == (Object)null || (Object)(object)sharedMaterial.shader == (Object)null)
					{
						continue;
					}
					string name = ((Object)sharedMaterial.shader).name;
					bool num;
					if (!lit)
					{
						num = name.Contains("Unlit");
					}
					else
					{
						if (!name.Contains("Lit"))
						{
							continue;
						}
						num = !name.Contains("Unlit");
					}
					if (num)
					{
						return sharedMaterial.shader;
					}
				}
			}
			catch
			{
			}
			return null;
		}

		public static Material Lit(string name, Color c, float smooth, float metal, Texture2D tex = null)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (Cache.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Material val = new Material(LitShader)
			{
				name = "TB_" + name
			};
			SetColor(val, ((Object)(object)tex != (Object)null) ? Color.white : c);
			SetTexture(val, tex);
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", smooth);
			}
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", smooth);
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", metal);
			}
			return Keep(name, val);
		}

		public static Material Glow(string name, Texture2D tex, Color c, float intensity)
		{
			//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_0057: Expected O, but got Unknown
			//IL_0058: 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)
			if (Cache.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			if ((Object)(object)s_unlit == (Object)null)
			{
				s_unlit = Find(lit: false) ?? LitShader;
			}
			Material m = new Material(s_unlit)
			{
				name = "TB_" + name
			};
			SetColor(m, c * intensity);
			SetTexture(m, tex);
			return Keep(name, m);
		}

		public static Material Cutout(string name, Texture2D tex, float cutoff)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (Cache.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Material val = new Material(LitShader)
			{
				name = "TB_" + name
			};
			SetTexture(val, tex);
			SetColor(val, Color.white);
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", 0.2f);
			}
			if (val.HasProperty("_AlphaClip"))
			{
				val.SetFloat("_AlphaClip", 1f);
			}
			if (val.HasProperty("_Cutoff"))
			{
				val.SetFloat("_Cutoff", cutoff);
			}
			val.EnableKeyword("_ALPHATEST_ON");
			val.SetOverrideTag("RenderType", "TransparentCutout");
			val.renderQueue = 2450;
			return Keep(name, val);
		}

		public static Material Tinted(Material source, Color tint)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			string key = "tint:" + ((Object)source).name + ":" + ColorUtility.ToHtmlStringRGB(tint);
			if (Cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Material m = new Material(source)
			{
				name = "TB_" + ((Object)source).name + "_tinted"
			};
			SetColor(m, tint);
			return Keep(key, m);
		}

		private static Material Keep(string key, Material m)
		{
			m.enableInstancing = true;
			((Object)m).hideFlags = (HideFlags)32;
			Cache[key] = m;
			return m;
		}

		private static void SetTexture(Material m, Texture2D tex)
		{
			if (!((Object)(object)tex == (Object)null))
			{
				m.mainTexture = (Texture)(object)tex;
				if (m.HasProperty("_BaseMap"))
				{
					m.SetTexture("_BaseMap", (Texture)(object)tex);
				}
			}
		}

		public static void SetColor(Material m, Color c)
		{
			//IL_0001: 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)
			m.color = c;
			if (m.HasProperty("_BaseColor"))
			{
				m.SetColor("_BaseColor", c);
			}
		}

		public static Color Hex(string hex)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			ColorUtility.TryParseHtmlString("#" + hex, ref result);
			return result;
		}
	}
	internal sealed class Restaurant
	{
		private const string BusinessPath = "@Businesses/Taco Ticklers";

		private static readonly Color Stucco = Mats.Hex("EDEBE6");

		private static readonly Color Purple = Mats.Hex("3D2B78");

		private static readonly Color Base = Mats.Hex("2E2638");

		private static readonly Color Black = Mats.Hex("1C1C1F");

		private static readonly Color InsideWhite = Mats.Hex("F3F0EA");

		private static readonly Color TileTint = Mats.Hex("C4A0A6");

		private static readonly Color QuarryTint = Mats.Hex("A8584C");

		private static readonly Vector3[] Registers = (Vector3[])(object)new Vector3[3]
		{
			new Vector3(-32.4f, 1.2f, 73.8f),
			new Vector3(-30.7f, 1.2f, 73.9f),
			new Vector3(-28.9f, 1.2f, 73.9f)
		};

		private static readonly (Vector3 c, Vector3 s)[] Solids = new(Vector3, Vector3)[6]
		{
			(new Vector3(-35.23f, 3.8f, 64.49f), new Vector3(2f, 7.4f, 2f)),
			(new Vector3(-27.47f, 0.27f, 58.51f), new Vector3(0.64f, 0.55f, 0.64f)),
			(new Vector3(-34.98f, 0.93f, 72.8f), new Vector3(0.6f, 1.65f, 1f)),
			(new Vector3(-26.125f, 0.6f, 79.65f), new Vector3(0.75f, 1f, 6.5f)),
			(new Vector3(-30.225f, 0.7f, 79.9f), new Vector3(0.75f, 1.2f, 1.4f)),
			(new Vector3(-28.8f, 0.5f, 76.45f), new Vector3(1.6f, 0.8f, 0.7f))
		};

		private GameObject _world;

		private IntPtr _business;

		private int _swapped;

		private int _hidden;

		public void OnSceneChange()
		{
			if ((Object)(object)_world == (Object)null)
			{
				_business = IntPtr.Zero;
			}
		}

		public void Tick()
		{
			if ((Object)(object)_world != (Object)null)
			{
				return;
			}
			GameObject val = GameObject.Find("@Businesses/Taco Ticklers");
			if ((Object)(object)val == (Object)null || ((Il2CppObjectBase)val).Pointer == _business)
			{
				return;
			}
			_business = ((Il2CppObjectBase)val).Pointer;
			try
			{
				Build(val);
			}
			catch (Exception ex)
			{
				TacoBellMod.Log.Error("Building the Taco Bell failed: " + ex);
			}
		}

		private void Build(GameObject business)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			_world = new GameObject("FroggosTacoBell_World");
			_swapped = (_hidden = 0);
			TacoBellConfig cfg = TacoBellMod.Cfg;
			if (cfg.Restyle.Value)
			{
				bool value = cfg.RetroDiningRoom.Value;
				Restyle(business.transform, value);
				Transform transform = _world.transform;
				ModelLoader.Spawn("tb_facade", transform);
				ModelLoader.Spawn("tb_pylon", transform);
				ModelLoader.Spawn("tb_menuboard", transform, shadows: false);
				if (value)
				{
					ModelLoader.Spawn("tb_interior", transform, shadows: false);
					ModelLoader.Spawn("tb_kitchen", transform);
				}
				(Vector3, Vector3)[] solids = Solids;
				for (int i = 0; i < solids.Length; i++)
				{
					var (val, size) = solids[i];
					if (value || val.y > 3f || val.z < 60f)
					{
						AddBox(transform, "TB_Solid", val, size);
					}
				}
			}
			Vector3[] registers = Registers;
			foreach (Vector3 at in registers)
			{
				OrderCounter.Attach(_world.transform, at);
			}
			TacoBellMod.Log.Msg($"Taco Ticklers is now a Taco Bell ({_swapped} surfaces repainted, {_hidden} old pieces hidden). " + "Order a Crunchy Taco at the registers.");
		}

		private static void AddBox(Transform root, string name, Vector3 center, Vector3 size)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(root, false);
			val.transform.position = center;
			val.AddComponent<BoxCollider>().size = size;
		}

		private static string RelPath(Transform t, Transform root)
		{
			StringBuilder stringBuilder = new StringBuilder(((Object)t).name);
			Transform parent = t.parent;
			while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)root)
			{
				stringBuilder.Insert(0, ((Object)parent).name + "/");
				parent = parent.parent;
			}
			return stringBuilder.ToString();
		}

		private static string BaseName(Material m)
		{
			if ((Object)(object)m == (Object)null)
			{
				return "";
			}
			string name = ((Object)m).name;
			int num = name.IndexOf(" (Instance)", StringComparison.Ordinal);
			if (num < 0)
			{
				return name;
			}
			return name.Substring(0, num);
		}

		private void Restyle(Transform business, bool inside)
		{
			foreach (MeshRenderer componentsInChild in ((Component)business).GetComponentsInChildren<MeshRenderer>(true))
			{
				if ((Object)(object)componentsInChild == (Object)null)
				{
					continue;
				}
				string[] array = RelPath(((Component)componentsInChild).transform, business).Split('/');
				Func<string, Material> func = null;
				bool flag = false;
				if (array[0] == "fastfoodrestaurant" && array.Length >= 2)
				{
					string text = array[1];
					string text2 = ((array.Length > 2) ? array[2] : null);
					if (text == "Sign" || text == "Pole")
					{
						flag = true;
					}
					else if (text2 == "Quad" && HasMaterial((Renderer)(object)componentsInChild, "billboard"))
					{
						flag = true;
					}
					else if (text == "Rack")
					{
						flag = true;
					}
					else if (text.StartsWith("SideRoof"))
					{
						func = (string m) => (!(m == "fast food door mat")) ? null : Lit("Awning", Purple, 0.25f);
					}
					else if (text.StartsWith("Column") || text.StartsWith("SideColumn"))
					{
						func = ColumnPaint;
					}
					else if ((text2 != null && (text2.StartsWith("BigWindow") || text2.StartsWith("SmallWindow"))) || text.StartsWith("BigWindow") || text.StartsWith("SmallWindow"))
					{
						func = (string m) => (!(m == "fast food door mat")) ? null : Lit("Frames", Black, 0.5f);
					}
					else if (text2 == null && (text.StartsWith("DoorWall") || text == "WindowWall" || text.StartsWith("BlankWall") || text == "RearWall"))
					{
						func = (string m) => WallPaint(m, inside);
					}
					else if (text2 == null && text == "InnerWalls" && inside)
					{
						func = (string m) => (Material)(m switch
						{
							"concrete_browngrey light" => Lit("Trim", Purple, 0.2f), 
							"brick reddish salmon" => Lit("Base", Base, 0.2f), 
							"wood washed yellow" => Lit("InsideWall", InsideWhite, 0.15f), 
							_ => null, 
						});
					}
					else if (text2 == null && text == "Bench")
					{
						func = (string m) => (!(m == "brick reddish salmon")) ? ((!(m == "fast food door mat")) ? null : Lit("CounterTop", Black, 0.6f)) : Lit("Counter", Purple, 0.35f);
					}
					else if (text2 == null && text == "Foundation" && inside)
					{
						Material tile = FindMaterial((Renderer)(object)componentsInChild, "small tile dirty white");
						func = (string m) => (!(m == "small tile dirty white") || !((Object)(object)tile != (Object)null)) ? ((!(m == "wood planks light brown mat")) ? null : Lit("QuarryTile", QuarryTint, 0.25f)) : Mats.Tinted(tile, TileTint);
					}
				}
				else if (array[0].StartsWith("TV"))
				{
					flag = true;
				}
				else if (inside && array[0].StartsWith("Fast Food Booth"))
				{
					flag = true;
				}
				if (flag)
				{
					if (((Renderer)componentsInChild).enabled)
					{
						((Renderer)componentsInChild).enabled = false;
						_hidden++;
					}
				}
				else
				{
					if (func == null)
					{
						continue;
					}
					Il2CppReferenceArray<Material> sharedMaterials = ((Renderer)componentsInChild).sharedMaterials;
					bool flag2 = false;
					for (int num = 0; num < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length; num++)
					{
						Material val = func(BaseName(((Il2CppArrayBase<Material>)(object)sharedMaterials)[num]));
						if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)((Il2CppArrayBase<Material>)(object)sharedMaterials)[num]))
						{
							((Il2CppArrayBase<Material>)(object)sharedMaterials)[num] = val;
							flag2 = true;
						}
					}
					if (flag2)
					{
						((Renderer)componentsInChild).sharedMaterials = sharedMaterials;
						_swapped++;
					}
				}
			}
			if (inside)
			{
				foreach (Transform componentsInChild2 in ((Component)business).GetComponentsInChildren<Transform>(true))
				{
					if (!((Object)(object)componentsInChild2.parent != (Object)(object)business) && ((Object)componentsInChild2).name.StartsWith("Fast Food Booth"))
					{
						ModelLoader.Spawn("tb_booth", componentsInChild2);
					}
				}
			}
			foreach (LODGroup componentsInChild3 in ((Component)business).GetComponentsInChildren<LODGroup>(true))
			{
				if (!((Object)(object)componentsInChild3 == (Object)null) && RelPath(((Component)componentsInChild3).transform, business).StartsWith("fastfoodrestaurant"))
				{
					try
					{
						componentsInChild3.ForceLOD(0);
					}
					catch
					{
					}
				}
			}
		}

		private static Material ColumnPaint(string m)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			switch (m)
			{
			case "brick reddish salmon":
			case "fast food door mat":
			case "concrete_grey7":
				return Lit("Pillar", Purple, 0.2f);
			case "concrete_browngrey light":
				return Lit("Trim", Purple, 0.2f);
			default:
				return null;
			}
		}

		private static Material WallPaint(string m, bool inside)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			switch (m)
			{
			case "concrete washed yellow":
				return Lit("Stucco", Stucco, 0.1f);
			case "concrete_browngrey light":
				return Lit("Trim", Purple, 0.2f);
			case "brick reddish salmon":
				return Lit("Base", Base, 0.2f);
			case "wood washed yellow":
				if (!inside)
				{
					return null;
				}
				return Lit("InsideWall", InsideWhite, 0.15f);
			default:
				return null;
			}
		}

		private static Material Lit(string name, Color c, float smooth)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return Mats.Lit(name, c, smooth, 0f);
		}

		private static bool HasMaterial(Renderer r, string contains)
		{
			foreach (Material item in (Il2CppArrayBase<Material>)(object)r.sharedMaterials)
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name.Contains(contains))
				{
					return true;
				}
			}
			return false;
		}

		private static Material FindMaterial(Renderer r, string baseName)
		{
			foreach (Material item in (Il2CppArrayBase<Material>)(object)r.sharedMaterials)
			{
				if (BaseName(item) == baseName)
				{
					return item;
				}
			}
			return null;
		}
	}
	internal static class OrderCounter
	{
		private static int s_layer = -1;

		public static void Attach(Transform root, Vector3 at)
		{
			//IL_002f: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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)
			try
			{
				if (s_layer < 0)
				{
					InteractableObject val = Object.FindObjectOfType<InteractableObject>();
					s_layer = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject.layer : 0);
				}
				GameObject val2 = new GameObject("TB_OrderCounter");
				val2.transform.SetParent(root, false);
				val2.transform.position = at;
				val2.layer = s_layer;
				val2.AddComponent<BoxCollider>().size = new Vector3(0.75f, 0.6f, 0.75f);
				InteractableObject obj = val2.AddComponent<InteractableObject>();
				obj.SetMessage($"Order a Crunchy Taco (${TacoBellMod.Cfg.TacoPrice.Value})");
				obj.MaxInteractionRange = 3f;
				obj.onInteractStart.AddListener(DelegateSupport.ConvertDelegate<UnityAction>((Delegate)new Action(TacoItem.Order)));
			}
			catch (Exception ex)
			{
				TacoBellMod.Log.Warning("Making a register an order counter failed: " + ex.Message);
			}
		}
	}
	internal sealed class TacoBellConfig
	{
		public readonly MelonPreferences_Entry<bool> Restyle;

		public readonly MelonPreferences_Entry<bool> RetroDiningRoom;

		public readonly MelonPreferences_Entry<float> SignBrightness;

		public readonly MelonPreferences_Entry<int> TacoPrice;

		public readonly MelonPreferences_Entry<float> HealthPerTaco;

		public readonly MelonPreferences_Entry<float> StaminaPerTaco;

		public readonly MelonPreferences_Entry<bool> VerboseLogging;

		public TacoBellConfig()
		{
			MelonPreferences_Category val = MelonPreferences.CreateCategory("FroggosTacoBell", "Froggos Taco Bell");
			Restyle = val.CreateEntry<bool>("Restyle", true, "Restyle Taco Ticklers", "Turn Taco Ticklers into a Taco Bell: paint, tower, signs, pylon and menu boards. The ordering counter works either way.", false, false, (ValueValidator)null, (string)null);
			RetroDiningRoom = val.CreateEntry<bool>("RetroDiningRoom", true, "Taco Bell interior", "The inside: white walls with pink, teal and purple bands, retro booths, a drink station, mauve tiles and a kitchen in the back. The laundering station and anything you placed are never touched.", false, false, (ValueValidator)null, (string)null);
			SignBrightness = val.CreateEntry<float>("SignBrightness", 1f, "Sign brightness", "Brightness of the lit signs and menu boards (0.6 - 2).", false, false, (ValueValidator)null, (string)null);
			TacoPrice = val.CreateEntry<int>("TacoPrice", 2, "Crunchy Taco price", "Cash price of a Crunchy Taco at the register.", false, false, (ValueValidator)null, (string)null);
			HealthPerTaco = val.CreateEntry<float>("HealthPerTaco", 15f, "Health per taco", "Health a taco restores when you finish eating it.", false, false, (ValueValidator)null, (string)null);
			StaminaPerTaco = val.CreateEntry<float>("StaminaPerTaco", 40f, "Stamina per taco", "Sprint stamina a taco gives back.", false, false, (ValueValidator)null, (string)null);
			VerboseLogging = val.CreateEntry<bool>("VerboseLogging", false, "Verbose logging", "Extra log lines for troubleshooting.", false, false, (ValueValidator)null, (string)null);
		}
	}
	public class TacoBellMod : MelonMod
	{
		internal static Instance Log;

		internal static TacoBellConfig Cfg;

		private readonly Restaurant _restaurant = new Restaurant();

		private bool _inWorld;

		public override void OnInitializeMelon()
		{
			Log = ((MelonBase)this).LoggerInstance;
			Cfg = new TacoBellConfig();
			Log.Msg("Froggos-TacoBell loaded. Taco Ticklers is a Taco Bell now: order a Crunchy Taco at the registers (or: give crunchytaco).");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			TacoItem.EnsureRegistered();
			_restaurant.OnSceneChange();
			_inWorld = false;
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			TacoItem.EnsureRegistered();
			_inWorld = sceneName != "Menu";
		}

		public override void OnUpdate()
		{
			if (!_inWorld)
			{
				return;
			}
			try
			{
				_restaurant.Tick();
				TacoEating.Tick();
			}
			catch (Exception ex)
			{
				Verbose("Update failed: " + ex.Message);
			}
		}

		internal static void Verbose(string msg)
		{
			if (Cfg != null && Cfg.VerboseLogging.Value)
			{
				Log.Msg("[verbose] " + msg);
			}
		}
	}
	internal static class TacoItem
	{
		public const string Id = "crunchytaco";

		private static readonly string[] BaseCandidates = new string[5] { "goldbar", "rdx", "cash", "flashlight", "gasoline" };

		public static StorableItemDefinition Def;

		private static GameObject s_templateRoot;

		private static Registry s_registry;

		private static Registry Reg
		{
			get
			{
				if ((Object)(object)s_registry == (Object)null)
				{
					try
					{
						s_registry = Object.FindObjectOfType<Registry>();
					}
					catch
					{
					}
				}
				return s_registry;
			}
		}

		public static void OnRegistryReady(Registry reg)
		{
			s_registry = reg;
			EnsureRegistered();
		}

		public static void EnsureRegistered()
		{
			Registry reg = Reg;
			if ((Object)(object)reg == (Object)null)
			{
				return;
			}
			try
			{
				if ((Object)(object)Def == (Object)null)
				{
					Build(reg);
				}
				if ((Object)(object)Def != (Object)null && !Registry.ItemExists("crunchytaco"))
				{
					reg.AddToRegistry((ItemDefinition)(object)Def);
				}
			}
			catch (Exception ex)
			{
				TacoBellMod.Log.Error("Registering the Crunchy Taco failed: " + ex);
			}
		}

		private static StorableItemDefinition FindBase(Registry reg)
		{
			string[] baseCandidates = BaseCandidates;
			foreach (string text in baseCandidates)
			{
				ItemDefinition val = reg._GetItem(text, false);
				StorableItemDefinition val2 = (((Object)(object)val != (Object)null) ? ((Il2CppObjectBase)val).TryCast<StorableItemDefinition>() : null);
				if ((Object)(object)val2 != (Object)null && IsPlain(val2))
				{
					return val2;
				}
			}
			Enumerator<ItemDefinition> enumerator = reg.GetAllItems().GetEnumerator();
			while (enumerator.MoveNext())
			{
				ItemDefinition current = enumerator.Current;
				StorableItemDefinition val3 = (((Object)(object)current != (Object)null) ? ((Il2CppObjectBase)current).TryCast<StorableItemDefinition>() : null);
				if ((Object)(object)val3 != (Object)null && IsPlain(val3) && (Object)(object)((ItemDefinition)val3).Equippable != (Object)null && (Object)(object)val3.StoredItem != (Object)null)
				{
					return val3;
				}
			}
			return null;
		}

		private static bool IsPlain(StorableItemDefinition s)
		{
			return ((Object)s).GetIl2CppType().FullName == "ScheduleOne.ItemFramework.StorableItemDefinition";
		}

		private static void Build(Registry reg)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			StorableItemDefinition val = FindBase(reg);
			if ((Object)(object)val == (Object)null)
			{
				TacoBellMod.Log.Error("No plain vanilla item to base the taco on; the Crunchy Taco can't be registered.");
				return;
			}
			TacoBellMod.Verbose("Building the Crunchy Taco from '" + ((BaseItemDefinition)val).ID + "'.");
			if ((Object)(object)s_templateRoot == (Object)null)
			{
				s_templateRoot = new GameObject("FroggosTacoBell_Templates");
				s_templateRoot.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)s_templateRoot);
				((Object)s_templateRoot).hideFlags = (HideFlags)61;
			}
			StorableItemDefinition val2 = Object.Instantiate<StorableItemDefinition>(val);
			((Object)val2).name = "crunchytaco";
			((BaseItemDefinition)val2).ID = "crunchytaco";
			((BaseItemDefinition)val2).Name = "Crunchy Taco";
			((BaseItemDefinition)val2).Description = "A Taco Bell Crunchy Taco: seasoned beef, lettuce and cheese in a crunchy corn shell. Hold it and click to eat. Restores a little health and stamina.";
			((BaseItemDefinition)val2).Icon = ModelLoader.Icon("taco_icon");
			((BaseItemDefinition)val2).Category = (EItemCategory)7;
			((BaseItemDefinition)val2).StackLimit = 10;
			((BaseItemDefinition)val2).legalStatus = (ELegalStatus)0;
			val2.BasePurchasePrice = TacoBellMod.Cfg.TacoPrice.Value;
			val2.ResellMultiplier = 0.5f;
			val2.RequiresLevelToPurchase = false;
			val2.StationItem = null;
			((Object)val2).hideFlags = (HideFlags)32;
			try
			{
				if ((Object)(object)((ItemDefinition)val).Equippable != (Object)null)
				{
					((ItemDefinition)val2).Equippable = Reskin(((Component)((ItemDefinition)val).Equippable).gameObject, "crunchytaco_Equippable", 0.12f).GetComponent<Equippable>();
				}
			}
			catch (Exception ex)
			{
				TacoBellMod.Log.Warning("Taco: held model swap failed: " + ex.Message);
			}
			try
			{
				if ((Object)(object)val.StoredItem != (Object)null)
				{
					val2.StoredItem = Reskin(((Component)val.StoredItem).gameObject, "crunchytaco_Stored", 0f).GetComponent<StoredItem>();
				}
			}
			catch (Exception ex2)
			{
				TacoBellMod.Log.Warning("Taco: storage model swap failed: " + ex2.Message);
			}
			Def = val2;
		}

		private static GameObject Reskin(GameObject prefab, string name, float realSize)
		{
			//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_0075: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: 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_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(prefab, s_templateRoot.transform, false);
			((Object)val).name = name;
			Transform transform = val.transform;
			Matrix4x4 worldToLocalMatrix = transform.worldToLocalMatrix;
			bool flag = false;
			Bounds val2 = default(Bounds);
			foreach (MeshFilter componentsInChild in val.GetComponentsInChildren<MeshFilter>(true))
			{
				Renderer component = ((Component)componentsInChild).GetComponent<Renderer>();
				if ((Object)(object)componentsInChild.sharedMesh == (Object)null || (Object)(object)component == (Object)null)
				{
					continue;
				}
				Matrix4x4 val3 = worldToLocalMatrix * ((Component)componentsInChild).transform.localToWorldMatrix;
				Bounds bounds = componentsInChild.sharedMesh.bounds;
				for (int i = 0; i < 8; i++)
				{
					Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))));
					Vector3 val5 = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(val4);
					if (!flag)
					{
						val2 = new Bounds(val5, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref val2)).Encapsulate(val5);
					}
				}
				component.enabled = false;
			}
			foreach (SkinnedMeshRenderer componentsInChild2 in val.GetComponentsInChildren<SkinnedMeshRenderer>(true))
			{
				((Renderer)componentsInChild2).enabled = false;
			}
			GameObject obj = ModelLoader.Spawn("taco", transform);
			Bounds bounds2 = ModelLoader.Get("taco").Mesh.bounds;
			float num = Mathf.Max(((Bounds)(ref bounds2)).size.x, Mathf.Max(((Bounds)(ref bounds2)).size.y, ((Bounds)(ref bounds2)).size.z));
			float num2 = ((realSize > 0f) ? realSize : (flag ? Mathf.Max(((Bounds)(ref val2)).size.x, Mathf.Max(((Bounds)(ref val2)).size.y, ((Bounds)(ref val2)).size.z)) : 0.17f));
			float num3 = ((num > 0f) ? (num2 / num) : 1f);
			obj.transform.localScale = Vector3.one * num3;
			Vector3 val6 = (Vector3)(flag ? new Vector3(((Bounds)(ref val2)).center.x, ((Bounds)(ref val2)).min.y, ((Bounds)(ref val2)).center.z) : Vector3.zero);
			obj.transform.localPosition = val6 - new Vector3(((Bounds)(ref bounds2)).center.x, ((Bounds)(ref bounds2)).min.y, ((Bounds)(ref bounds2)).center.z) * num3;
			obj.layer = val.layer;
			return val;
		}

		public static void Order()
		{
			try
			{
				EnsureRegistered();
				if ((Object)(object)Def == (Object)null || !NetworkSingleton<MoneyManager>.InstanceExists || !PlayerSingleton<PlayerInventory>.InstanceExists)
				{
					return;
				}
				MoneyManager instance = NetworkSingleton<MoneyManager>.Instance;
				PlayerInventory instance2 = PlayerSingleton<PlayerInventory>.Instance;
				int num = Mathf.Max(0, TacoBellMod.Cfg.TacoPrice.Value);
				if (instance.cashBalance < (float)num)
				{
					Game.Notify("Not enough cash", $"A Crunchy Taco is ${num} cash.");
					return;
				}
				ItemInstance defaultInstance = ((ItemDefinition)Def).GetDefaultInstance(1);
				if (!instance2.CanItemFitInInventory(defaultInstance, 1))
				{
					Game.Notify("Inventory full", "Make room for your taco.");
					return;
				}
				if (num > 0)
				{
					instance.ChangeCashBalance((float)(-num), true, true);
				}
				instance2.AddItemToInventory(defaultInstance);
				Sfx.Ding();
				Game.Notify("Crunchy Taco", "Thanks for choosing Taco Bell! Hold it and click to eat.");
			}
			catch (Exception ex)
			{
				TacoBellMod.Log.Error("Ordering failed: " + ex);
			}
		}
	}
	internal static class TacoEating
	{
		private static bool s_eating;

		public static void Tick()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			if (s_eating)
			{
				return;
			}
			try
			{
				if (PlayerSingleton<PlayerInventory>.InstanceExists)
				{
					PlayerInventory instance = PlayerSingleton<PlayerInventory>.Instance;
					ItemInstance equippedItem = instance.EquippedItem;
					if (equippedItem != null && !(((BaseItemInstance)equippedItem).ID != "crunchytaco") && (int)Cursor.lockState == 1 && GameInput.GetButtonDown((ButtonCode)0))
					{
						MelonCoroutines.Start(Eat(instance));
					}
				}
			}
			catch (Exception ex)
			{
				TacoBellMod.Verbose("Eat check failed: " + ex.Message);
			}
		}

		private static MeshFilter HeldTaco(PlayerInventory inv)
		{
			Equippable equippable = inv.Equippable;
			if ((Object)(object)equippable == (Object)null)
			{
				return null;
			}
			foreach (MeshFilter componentsInChild in ((Component)equippable).GetComponentsInChildren<MeshFilter>(true))
			{
				if (((Object)(object)componentsInChild.sharedMesh != (Object)null && ((Object)componentsInChild.sharedMesh).name == "TB_taco") || ((Object)componentsInChild).name == "TB_taco")
				{
					return componentsInChild;
				}
			}
			return null;
		}

		private static bool StillHolding(PlayerInventory inv)
		{
			ItemInstance equippedItem = inv.EquippedItem;
			if (equippedItem != null)
			{
				return ((BaseItemInstance)equippedItem).ID == "crunchytaco";
			}
			return false;
		}

		private static IEnumerator Eat(PlayerInventory inv)
		{
			s_eating = true;
			MeshFilter taco = HeldTaco(inv);
			Transform t = (((Object)(object)taco != (Object)null) ? ((Component)taco).transform : null);
			Vector3 restPos = (((Object)(object)t != (Object)null) ? t.localPosition : Vector3.zero);
			Quaternion restRot = (((Object)(object)t != (Object)null) ? t.localRotation : Quaternion.identity);
			string[] stages = new string[3] { "taco_bite1", "taco_bite2", null };
			bool finished = false;
			int bite = 0;
			while (true)
			{
				if (bite < 3)
				{
					for (float k = 0f; k < 1f; k += Time.deltaTime / 0.22f)
					{
						if (!StillHolding(inv))
						{
							goto end_IL_0294;
						}
						Pose(t, restPos, restRot, Mathf.SmoothStep(0f, 1f, k));
						yield return null;
					}
					Sfx.Crunch();
					if ((Object)(object)taco != (Object)null)
					{
						if (stages[bite] != null)
						{
							taco.sharedMesh = ModelLoader.Get(stages[bite]).Mesh;
						}
						else
						{
							((Component)taco).GetComponent<Renderer>().enabled = false;
						}
					}
					for (float k = 0f; k < 1f; k += Time.deltaTime / 0.25f)
					{
						if (!StillHolding(inv))
						{
							goto end_IL_0294;
						}
						Pose(t, restPos, restRot, 1f - Mathf.SmoothStep(0f, 1f, k));
						yield return null;
					}
					for (float k = 0f; k < 0.3f; k += Time.deltaTime)
					{
						yield return null;
					}
					bite++;
					continue;
				}
				finished = true;
				break;
				continue;
				end_IL_0294:
				break;
			}
			if (finished)
			{
				try
				{
					HotbarSlot equippedSlot = inv.equippedSlot;
					if (equippedSlot != null && ((ItemSlot)equippedSlot).ItemInstance != null && ((BaseItemInstance)((ItemSlot)equippedSlot).ItemInstance).ID == "crunchytaco")
					{
						((ItemSlot)equippedSlot).ChangeQuantity(-1, false);
					}
					Player local = Player.Local;
					if ((Object)(object)local != (Object)null && (Object)(object)local.Health != (Object)null)
					{
						local.Health.RecoverHealth(TacoBellMod.Cfg.HealthPerTaco.Value);
					}
					if (PlayerSingleton<PlayerMovement>.InstanceExists)
					{
						PlayerSingleton<PlayerMovement>.Instance.ChangeStamina(TacoBellMod.Cfg.StaminaPerTaco.Value, true);
					}
					TacoBellMod.Verbose("Ate a Crunchy Taco.");
				}
				catch (Exception ex)
				{
					TacoBellMod.Log.Warning("Finishing the taco failed: " + ex.Message);
				}
			}
			try
			{
				if ((Object)(object)taco != (Object)null)
				{
					taco.sharedMesh = ModelLoader.Get("taco").Mesh;
					((Component)taco).GetComponent<Renderer>().enabled = true;
					((Component)taco).transform.localPosition = restPos;
					((Component)taco).transform.localRotation = restRot;
				}
			}
			catch
			{
			}
			s_eating = false;
		}

		private static void Pose(Transform t, Vector3 restPos, Quaternion restRot, float k)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)t == (Object)null) && !((Object)(object)t.parent == (Object)null))
			{
				Transform camera = Game.Camera;
				if (!((Object)(object)camera == (Object)null))
				{
					Vector3 val = t.parent.TransformPoint(restPos);
					float num = Mathf.Max(camera.InverseTransformPoint(val).z * 0.7f, 0.02f);
					Vector3 val2 = default(Vector3);
					((Vector3)(ref val2))..ctor(0f, (0f - num) * 0.35f, num);
					Vector3 val3 = t.parent.InverseTransformPoint(camera.TransformPoint(val2));
					t.localPosition = Vector3.Lerp(restPos, val3, k);
					t.localRotation = Quaternion.Slerp(restRot, restRot * Quaternion.Euler(-20f, 0f, 0f), k);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Registry), "Start")]
	internal static class RegistryStartPatch
	{
		private static void Postfix(Registry __instance)
		{
			TacoItem.OnRegistryReady(__instance);
		}
	}
	[HarmonyPatch(typeof(Registry), "RemoveRuntimeItems")]
	internal static class RegistryRemoveRuntimeItemsPatch
	{
		private static void Postfix()
		{
			TacoItem.EnsureRegistered();
		}
	}
}