Decompiled source of GoldBiter v1.0.35

GoldBiter.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using MyMods.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SoftReferenceableAssets;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GoldBiter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.35.0")]
[assembly: AssemblyInformationalVersion("1.0.35+87e84a94b300f123eefe72327dff44bcec700b51")]
[assembly: AssemblyProduct("GoldBiter")]
[assembly: AssemblyTitle("GoldBiter")]
[assembly: AssemblyVersion("1.0.35.0")]
[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 MyMods.Web
{
	public static class WebNav
	{
		public sealed class Link
		{
			public readonly string Id;

			public readonly string Label;

			public readonly int Port;

			public string Url => "http://127.0.0.1:" + Port + "/";

			public Link(string id, string label, int port)
			{
				Id = id;
				Label = label;
				Port = port;
			}
		}

		public static readonly Link[] Links = new Link[26]
		{
			new Link("monsters", "Monsters", 8777),
			new Link("searoute", "SeaRoute", 8778),
			new Link("longboat", "Harpoon Longboat", 8779),
			new Link("tradewind", "TradeWind", 8780),
			new Link("safeharbor", "Safe Harbor", 8781),
			new Link("hub", "DFG Hub", 8782),
			new Link("vault", "Viking Vault", 8783),
			new Link("qolvault", "QoL Vault Buttons", 8784),
			new Link("qolinventory", "QoL Inventory Buttons", 8785),
			new Link("cacophony", "Cacophony", 8787),
			new Link("ominous", "Ominous", 8788),
			new Link("pebble", "Pebble", 8789),
			new Link("trolls", "Trolls", 8790),
			new Link("transporter", "Transporter", 8791),
			new Link("skytram", "Sky-Tram", 8792),
			new Link("dockfortress", "Dock Fortress", 8793),
			new Link("odinseye", "Odin's Eye", 8794),
			new Link("skyherd", "Skyherd", 8795),
			new Link("lawspeaker", "Lawspeaker", 8796),
			new Link("ymirsmarrow", "Ymir's Marrow", 8797),
			new Link("fogwarden", "Fogwarden", 8798),
			new Link("raiders", "DFG Raiders", 8799),
			new Link("scoutcopter", "Scout Copter", 8800),
			new Link("sanctuary", "Sanctuary", 8801),
			new Link("goldbiter", "Gold-Biter", 8802),
			new Link("vending", "Vending Machines", 8803)
		};

		public const string LogoSvg = "<svg width='22' height='26' viewBox='0 0 22 26' fill='none' xmlns='http://www.w3.org/2000/svg' style='vertical-align:middle;margin-right:6px'><path d='M11 0L22 5V13C22 19.0751 17.3025 24.3125 11 26C4.6975 24.3125 0 19.0751 0 13V5L11 0Z' fill='#161a20' stroke='#ffd760' stroke-width='1.2'/><path d='M11 3L19 6.5V13C19 17.5 15.5 21.5 11 23C6.5 21.5 3 17.5 3 13V6.5L11 3Z' fill='#1d222a'/><text x='11' y='17' text-anchor='middle' fill='#ffd760' font-size='10' font-weight='bold' font-family='serif'>DFG</text></svg>";

		public const string Style = "nav.top{position:sticky;top:0;z-index:20;width:100%;box-sizing:border-box;flex:0 0 auto;font-family:'Segoe UI',Arial,sans-serif;background:#0d1219;border-bottom:1px solid #2b3b4c;padding:6px 14px;display:flex;align-items:center;gap:6px;flex-wrap:wrap}\nnav.top .brand{color:#ffd760;font-size:12px;text-transform:uppercase;letter-spacing:.8px;margin-right:10px;display:inline-flex;align-items:center;font-weight:600;text-shadow:0 1px 2px rgba(0,0,0,0.5)}\nnav.top a{color:#9fc3dd;text-decoration:none;font-size:13px;padding:4px 9px;border-radius:5px;transition:background .15s}\nnav.top a:hover{background:#1a2530}\nnav.top a.here{background:#3a2b4c;border:1px solid #55406b;color:#efe0ff}\n";

		public static string Html(string currentId)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("<nav class='top'><span class='brand'>").Append("<svg width='22' height='26' viewBox='0 0 22 26' fill='none' xmlns='http://www.w3.org/2000/svg' style='vertical-align:middle;margin-right:6px'><path d='M11 0L22 5V13C22 19.0751 17.3025 24.3125 11 26C4.6975 24.3125 0 19.0751 0 13V5L11 0Z' fill='#161a20' stroke='#ffd760' stroke-width='1.2'/><path d='M11 3L19 6.5V13C19 17.5 15.5 21.5 11 23C6.5 21.5 3 17.5 3 13V6.5L11 3Z' fill='#1d222a'/><text x='11' y='17' text-anchor='middle' fill='#ffd760' font-size='10' font-weight='bold' font-family='serif'>DFG</text></svg>").Append("DFG</span>");
			Link[] links = Links;
			foreach (Link link in links)
			{
				stringBuilder.Append("<a class='");
				if (link.Id == currentId)
				{
					stringBuilder.Append("here");
				}
				stringBuilder.Append("' href='").Append(link.Url).Append("'>")
					.Append(link.Label)
					.Append("</a>");
			}
			stringBuilder.Append("</nav>");
			return stringBuilder.ToString();
		}

		public static Link Find(string id)
		{
			Link[] links = Links;
			foreach (Link link in links)
			{
				if (link.Id == id)
				{
					return link;
				}
			}
			return null;
		}
	}
}
namespace GoldBiter
{
	internal class GoldBiterCrate : MonoBehaviour
	{
		[HarmonyPatch(typeof(Humanoid), "UseItem")]
		private static class UsePatch
		{
			private static bool Prefix(Humanoid __instance, Inventory inventory, ItemData item)
			{
				if (!IsLoot(item))
				{
					return true;
				}
				Open(__instance, inventory, item);
				return false;
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(int) })]
		private static class TipPatch
		{
			private static void Postfix(ItemData __instance, ref string __result)
			{
				if (IsLoot(__instance))
				{
					__result = __result + "\n" + Blurb(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(ItemDrop), "GetHoverText")]
		private static class HoverPatch
		{
			private static void Postfix(ItemDrop __instance, ref string __result)
			{
				if (!((Object)(object)__instance == (Object)null) && IsLoot(__instance.m_itemData))
				{
					__result = __result + "\n" + Blurb(__instance.m_itemData);
				}
			}
		}

		internal const string ItemName = "GoldBiter_Loot";

		private const string PrizeKey = "gb_item";

		private const string CountKey = "gb_n";

		private static bool s_ready;

		private static GameObject s_art;

		private static GameObject s_opener;

		private static int s_rocket;

		private static readonly string[] Rockets = new string[7] { "FireworksRocket_White", "FireworksRocket_Blue", "FireworksRocket_Cyan", "FireworksRocket_Green", "FireworksRocket_Purple", "FireworksRocket_Red", "FireworksRocket_Yellow" };

		private static float LootHeight => 0.45f * Mathf.Max(0.25f, GoldBiterTune.LootScale);

		internal static float LootTop => LootHeight;

		internal static void TryRegister()
		{
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Expected O, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Expected O, but got Unknown
			if (s_ready || (Object)(object)ObjectDB.instance == (Object)null || ItemManager.Instance == null)
			{
				return;
			}
			if ((Object)(object)ObjectDB.instance.GetItemPrefab("GoldBiter_Loot") != (Object)null)
			{
				s_ready = true;
				return;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Coins");
			if ((Object)(object)itemPrefab == (Object)null)
			{
				itemPrefab = ObjectDB.instance.GetItemPrefab("Amber");
			}
			if ((Object)(object)itemPrefab == (Object)null)
			{
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(itemPrefab);
			val.SetActive(false);
			((Object)val).name = "GoldBiter_Loot";
			ItemDrop component = val.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null || component.m_itemData == null || component.m_itemData.m_shared == null)
			{
				Object.Destroy((Object)(object)val);
				return;
			}
			component.m_autoPickup = false;
			ItemDrop component2 = itemPrefab.GetComponent<ItemDrop>();
			if (component2 != null && component2.m_itemData != null && component.m_itemData.m_shared == component2.m_itemData.m_shared)
			{
				component.m_itemData.m_shared = CopyShared(component.m_itemData.m_shared);
			}
			SharedData shared = component.m_itemData.m_shared;
			shared.m_name = "Gold-Biter loot";
			shared.m_description = "A prize from the machine. Right-click it in your pack to open it.";
			shared.m_itemType = (ItemType)1;
			shared.m_maxStackSize = 1;
			shared.m_weight = 0.2f;
			shared.m_questItem = false;
			shared.m_teleportable = true;
			Sprite val2 = GoldBiterPlugin.LoadSprite("loot_icon.png");
			if ((Object)(object)val2 != (Object)null)
			{
				shared.m_icons = (Sprite[])(object)new Sprite[1] { val2 };
			}
			component.m_itemData.m_dropPrefab = val;
			HideVanilla(val);
			Dress(val);
			val.AddComponent<GoldBiterLootDrop>();
			bool num = ItemManager.Instance.AddItem(new CustomItem(val, false, new ItemConfig
			{
				Name = shared.m_name,
				Description = shared.m_description
			}));
			GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab("GoldBiter_Loot");
			if ((Object)(object)itemPrefab2 != (Object)null)
			{
				ItemDrop component3 = itemPrefab2.GetComponent<ItemDrop>();
				if ((Object)(object)component3 != (Object)null && component3.m_itemData != null)
				{
					component3.m_itemData.m_dropPrefab = itemPrefab2;
				}
				if ((Object)(object)itemPrefab2.transform.Find("loot_art") == (Object)null)
				{
					HideVanilla(itemPrefab2);
					Dress(itemPrefab2);
				}
				if ((Object)(object)itemPrefab2.transform.parent != (Object)null)
				{
					itemPrefab2.SetActive(true);
				}
			}
			s_ready = num || (Object)(object)itemPrefab2 != (Object)null;
			if (s_ready)
			{
				GoldBiterPlugin.Log.LogInfo((object)"Gold-Biter: loot token registered.");
			}
			else
			{
				GoldBiterPlugin.Log.LogWarning((object)"Gold-Biter: the loot token did not register. Wins fall on the ground.");
			}
		}

		public static bool Spawn(GoldBiterMachine machine, string item, int amount)
		{
			//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_0047: 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_0058: 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_0068: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_006f: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_00b6: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)machine == (Object)null || amount <= 0 || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return false;
			}
			TryRegister();
			if ((Object)(object)ObjectDB.instance.GetItemPrefab(item) == (Object)null)
			{
				return false;
			}
			GameObject val = new GameObject("GoldBiterLoot");
			val.transform.position = machine.Mouth();
			val.transform.rotation = machine.ChestFacing();
			Dress(val);
			int num = ShowLoot(val);
			GoldBiterLootHold goldBiterLootHold = val.AddComponent<GoldBiterLootHold>();
			goldBiterLootHold.Prize = item;
			goldBiterLootHold.Amount = amount;
			val.AddComponent<GoldBiterLootDrop>().Kick(machine.Mouth(), machine.Landing(), machine.ChestFacing());
			Renderer componentInChildren = val.GetComponentInChildren<Renderer>();
			object obj;
			if (!((Object)(object)componentInChildren != (Object)null))
			{
				obj = "no mesh";
			}
			else
			{
				Bounds bounds = componentInChildren.bounds;
				Vector3 size = ((Bounds)(ref bounds)).size;
				obj = ((Vector3)(ref size)).ToString("0.00");
			}
			string text = (string)obj;
			GoldBiterPlugin.Log.LogInfo((object)("Gold-Biter: loot box " + amount + " " + item + ", renderers " + num + ", size " + text + "."));
			return true;
		}

		internal static bool Pocket(Humanoid who, string prize, int amount)
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			Player val = (Player)(object)((who is Player) ? who : null);
			if ((Object)(object)val == (Object)null || ((Humanoid)val).GetInventory() == null || amount <= 0)
			{
				return false;
			}
			TryRegister();
			GameObject val2 = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("GoldBiter_Loot") : null);
			ItemDrop val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val3 == (Object)null || val3.m_itemData == null)
			{
				return false;
			}
			ItemData val4 = val3.m_itemData.Clone();
			if (val4.m_shared == null || val4.m_shared == val3.m_itemData.m_shared)
			{
				val4.m_shared = CopyShared(val4.m_shared ?? val3.m_itemData.m_shared);
			}
			val4.m_shared.m_name = "Gold-Biter loot";
			val4.m_shared.m_description = "Right-click it in your pack to open it.";
			val4.m_shared.m_maxStackSize = 1;
			val4.m_shared.m_itemType = (ItemType)1;
			if (val4.m_customData == null)
			{
				val4.m_customData = new Dictionary<string, string>();
			}
			val4.m_customData["gb_item"] = prize;
			val4.m_customData["gb_n"] = amount.ToString(CultureInfo.InvariantCulture);
			val4.m_stack = 1;
			val4.m_dropPrefab = val2;
			if (!((Humanoid)val).GetInventory().AddItem(val4))
			{
				((Character)val).Message((MessageType)2, "No room for the loot.", 0, (Sprite)null, false);
				return false;
			}
			((Character)val).Message((MessageType)2, "Loot. Right-click it to open.", 0, (Sprite)null, false);
			return true;
		}

		private static SharedData CopyShared(SharedData src)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			if (src != null)
			{
				return (SharedData)typeof(object).GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(src, null);
			}
			return new SharedData();
		}

		private static int ShowLoot(GameObject item)
		{
			if ((Object)(object)item.transform.Find("loot_art") == (Object)null)
			{
				Dress(item);
			}
			Transform val = item.transform.Find("loot_art");
			if ((Object)(object)val != (Object)null)
			{
				((Component)val).gameObject.SetActive(true);
			}
			int num = 0;
			Renderer[] componentsInChildren = item.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				if (!((Object)(object)val2 == (Object)null) && (val2.enabled = (Object)(object)val != (Object)null && ((Component)val2).transform.IsChildOf(val)))
				{
					num++;
				}
			}
			return num;
		}

		internal static void Open(Humanoid who, Inventory inventory, ItemData item)
		{
			//IL_00eb: 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_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)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			Player val = (Player)(object)((who is Player) ? who : null);
			if ((Object)(object)val == (Object)null || inventory == null || !IsLoot(item) || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			if (!item.m_customData.TryGetValue("gb_item", out var value) || string.IsNullOrEmpty(value))
			{
				((Character)val).Message((MessageType)2, "The loot is empty.", 0, (Sprite)null, false);
				return;
			}
			if (!item.m_customData.TryGetValue("gb_n", out var value2) || !int.TryParse(value2, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || result <= 0)
			{
				((Character)val).Message((MessageType)2, "The loot is empty.", 0, (Sprite)null, false);
				return;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(value);
			if ((Object)(object)itemPrefab == (Object)null)
			{
				((Character)val).Message((MessageType)2, "The prize is not in this world.", 0, (Sprite)null, false);
				return;
			}
			if (!((Humanoid)val).GetInventory().AddItem(itemPrefab, result))
			{
				((Character)val).Message((MessageType)2, "No room for the prize.", 0, (Sprite)null, false);
				return;
			}
			string text = PrizeLine(item);
			inventory.RemoveItem(item, 1);
			Vector3 pos = ((Component)val).transform.position + ((Component)val).transform.forward * 0.7f + Vector3.up * 1.15f;
			ShowOpener(pos, ((Component)val).transform.rotation);
			Fireworks(pos);
			((Character)val).Message((MessageType)2, text + ". " + GoldLine() + ".", 0, (Sprite)null, false);
		}

		internal static void Fireworks(Vector3 pos)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			string name = Rockets[Random.Range(0, Rockets.Length)];
			LaunchRocket(pos, name);
		}

		internal static string NextRocket()
		{
			string result = Rockets[s_rocket % Rockets.Length];
			s_rocket++;
			return result;
		}

		internal static bool LaunchRocket(Vector3 pos, string name)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0042: 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_0092: 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_00a8: Expected O, but got Unknown
			string text = RocketVfx(name);
			GameObject val = GoldBiterPrefabs.Find(text);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			bool activeSelf = val.activeSelf;
			val.SetActive(false);
			GameObject val2 = Object.Instantiate<GameObject>(val, pos + Vector3.up * 0.6f, Quaternion.LookRotation(Vector3.up));
			val.SetActive(activeSelf);
			ItemDrop component = val2.GetComponent<ItemDrop>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			val2.SetActive(true);
			IProjectile componentInChildren = val2.GetComponentInChildren<IProjectile>(true);
			if (componentInChildren != null)
			{
				componentInChildren.Setup((Character)(object)Player.m_localPlayer, Vector3.up * 16f, 0f, new HitData(), (ItemData)null, (ItemData)null);
			}
			else
			{
				Object.Destroy((Object)(object)val2, 8f);
			}
			GoldBiterPlugin.Log.LogInfo((object)("Gold-Biter: launched " + text + "."));
			return true;
		}

		private static string RocketVfx(string item)
		{
			return item switch
			{
				"FireworksRocket_Blue" => "vfx_Firework_Rocket_Blue", 
				"FireworksRocket_Cyan" => "vfx_Firework_Rocket_Cyan", 
				"FireworksRocket_Green" => "vfx_Firework_Rocket_Green", 
				"FireworksRocket_Purple" => "vfx_Firework_Rocket_Purple", 
				"FireworksRocket_Red" => "vfx_Firework_Rocket_Red", 
				"FireworksRocket_Yellow" => "vfx_Firework_Rocket_Yellow", 
				_ => "vfx_Firework_Rocket", 
			};
		}

		internal static void ResizeLoose()
		{
			GoldBiterLootHold[] array = Object.FindObjectsByType<GoldBiterLootHold>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				if (!((Object)(object)array[i] == (Object)null))
				{
					Fit(((Component)array[i]).gameObject);
				}
			}
		}

		internal static bool IsLoot(ItemData data)
		{
			if (data != null && data.m_customData != null)
			{
				return data.m_customData.ContainsKey("gb_item");
			}
			return false;
		}

		internal static string PrizeLine(string prefab, int amount)
		{
			if (amount <= 0)
			{
				amount = 1;
			}
			string text = (string.IsNullOrEmpty(prefab) ? "Loot" : prefab);
			if ((Object)(object)ObjectDB.instance != (Object)null && !string.IsNullOrEmpty(prefab))
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab);
				ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val != (Object)null && val.m_itemData != null && val.m_itemData.m_shared != null)
				{
					string name = val.m_itemData.m_shared.m_name;
					text = ((Localization.instance != null) ? Localization.instance.Localize(name) : name);
				}
			}
			return amount + " " + text;
		}

		internal static string PrizeLine(ItemData data)
		{
			if (!IsLoot(data))
			{
				return "Loot";
			}
			data.m_customData.TryGetValue("gb_item", out var value);
			data.m_customData.TryGetValue("gb_n", out var value2);
			int.TryParse(value2, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result);
			return PrizeLine(value, result);
		}

		internal static string GoldLine()
		{
			return "You have " + Gold() + " gold";
		}

		internal static string Blurb(ItemData data)
		{
			return PrizeLine(data) + "\n" + GoldLine() + "\nRight-click in your pack to open.";
		}

		private static int Gold()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Humanoid)localPlayer).GetInventory() == null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return 0;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Coins");
			ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
			string text = (((Object)(object)val != (Object)null && val.m_itemData != null && val.m_itemData.m_shared != null) ? val.m_itemData.m_shared.m_name : "$item_coins");
			return ((Humanoid)localPlayer).GetInventory().CountItems(text, -1, true);
		}

		private static void ShowOpener(Vector3 pos, Quaternion facing)
		{
			//IL_0011: 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_0031: 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_0046: 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)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			GameObject val = Opener();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, pos, facing);
			((Object)val2).name = "loot_opener";
			val2.SetActive(true);
			val2.transform.localScale = Vector3.one;
			Bounds val3 = WorldBounds(val2.transform);
			float num = Mathf.Max(((Bounds)(ref val3)).size.x, Mathf.Max(((Bounds)(ref val3)).size.y, ((Bounds)(ref val3)).size.z));
			float num2 = 0.42f / Mathf.Max(0.05f, num);
			val2.transform.localScale = Vector3.one * num2;
			Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] != (Object)null)
				{
					Object.Destroy((Object)(object)componentsInChildren[i]);
				}
			}
			val2.AddComponent<GoldBiterOpenerFlash>().Begin();
		}

		private static void HideVanilla(GameObject item)
		{
			Renderer[] componentsInChildren = item.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] != (Object)null)
				{
					componentsInChildren[i].enabled = false;
				}
			}
		}

		private static void Dress(GameObject item)
		{
			//IL_0035: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Art();
			if (!((Object)(object)val == (Object)null))
			{
				GameObject obj = Object.Instantiate<GameObject>(val, item.transform, false);
				obj.SetActive(true);
				((Object)obj).name = "loot_art";
				obj.transform.localRotation = Quaternion.identity;
				obj.transform.localPosition = Vector3.zero;
				obj.transform.localScale = Vector3.one;
				Fit(item);
			}
		}

		private static void Fit(GameObject item)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0073: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			Transform val = item.transform.Find("loot_art");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			val.localScale = Vector3.one;
			val.localPosition = Vector3.zero;
			Bounds val2 = BoundsOf(val, item.transform);
			float num = LootHeight / Mathf.Max(0.05f, ((Bounds)(ref val2)).size.y);
			val.localScale = Vector3.one * num;
			Bounds val3 = BoundsOf(val, item.transform);
			val.localPosition = new Vector3(0f - ((Bounds)(ref val3)).center.x, 0f - ((Bounds)(ref val3)).min.y, 0f - ((Bounds)(ref val3)).center.z);
			val3 = BoundsOf(val, item.transform);
			BoxCollider val4 = item.GetComponent<BoxCollider>();
			if ((Object)(object)val4 == (Object)null)
			{
				Collider[] components = item.GetComponents<Collider>();
				for (int i = 0; i < components.Length; i++)
				{
					if ((Object)(object)components[i] != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)components[i]);
					}
				}
				val4 = item.AddComponent<BoxCollider>();
			}
			val4.center = ((Bounds)(ref val3)).center;
			val4.size = ((Bounds)(ref val3)).size;
		}

		private static GameObject Art()
		{
			if ((Object)(object)s_art != (Object)null)
			{
				return s_art;
			}
			s_art = Load("loot.glb", "loot_template");
			if ((Object)(object)s_art == (Object)null)
			{
				GoldBiterPlugin.Log.LogWarning((object)"Gold-Biter: loot.glb did not load. The token keeps the coin shape.");
			}
			return s_art;
		}

		private static GameObject Opener()
		{
			if ((Object)(object)s_opener != (Object)null)
			{
				return s_opener;
			}
			s_opener = Load("loot_opener.glb", "loot_opener_template");
			if ((Object)(object)s_opener == (Object)null)
			{
				GoldBiterPlugin.Log.LogWarning((object)"Gold-Biter: loot_opener.glb did not load. Opening still pays.");
			}
			return s_opener;
		}

		private static GameObject Load(string file, string name)
		{
			string pluginDir = GoldBiterPlugin.PluginDir;
			if (string.IsNullOrEmpty(pluginDir))
			{
				return null;
			}
			string path = Path.Combine(pluginDir, file);
			if (!File.Exists(path))
			{
				return null;
			}
			GameObject val = GoldBiterGlb.Load(path);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			((Object)val).name = name;
			val.SetActive(false);
			return val;
		}

		private static Bounds BoundsOf(Transform art, Transform space)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0135: 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)
			//IL_004e: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(Vector3.zero, Vector3.zero);
			bool flag = false;
			MeshFilter[] componentsInChildren = ((Component)art).GetComponentsInChildren<MeshFilter>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Mesh val = (((Object)(object)componentsInChildren[i] != (Object)null) ? componentsInChildren[i].sharedMesh : null);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Bounds bounds = val.bounds;
				Vector3 center = ((Bounds)(ref bounds)).center;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val2 = center + new Vector3(((j & 1) == 0) ? (0f - extents.x) : extents.x, ((j & 2) == 0) ? (0f - extents.y) : extents.y, ((j & 4) == 0) ? (0f - extents.z) : extents.z);
					Vector3 val3 = space.InverseTransformPoint(((Component)componentsInChildren[i]).transform.TransformPoint(val2));
					if (!flag)
					{
						((Bounds)(ref result))..ctor(val3, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(val3);
					}
				}
			}
			if (!flag)
			{
				((Bounds)(ref result))..ctor(new Vector3(0f, 0.2f, 0f), new Vector3(0.4f, 0.4f, 0.4f));
			}
			return result;
		}

		private static Bounds WorldBounds(Transform art)
		{
			//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_0054: 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_0031: 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)
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(art.position, Vector3.zero);
			bool flag = false;
			Renderer[] componentsInChildren = ((Component)art).GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (!((Object)(object)componentsInChildren[i] == (Object)null))
				{
					if (!flag)
					{
						bounds = componentsInChildren[i].bounds;
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds);
					}
				}
			}
			return bounds;
		}
	}
	internal class GoldBiterLootHold : MonoBehaviour, Hoverable, Interactable
	{
		internal string Prize;

		internal int Amount;

		private static readonly List<GoldBiterLootHold> s_boxes = new List<GoldBiterLootHold>();

		private void OnEnable()
		{
			if (!s_boxes.Contains(this))
			{
				s_boxes.Add(this);
			}
		}

		private void OnDisable()
		{
			s_boxes.Remove(this);
		}

		internal static GoldBiterLootHold LookingAt(Player player)
		{
			//IL_0049: 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_0032: 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_0041: 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_0066: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || s_boxes.Count == 0)
			{
				return null;
			}
			Transform eye = ((Character)player).m_eye;
			Vector3 val = (((Object)(object)eye != (Object)null) ? eye.position : (((Component)player).transform.position + Vector3.up * 1.6f));
			Vector3 val2 = (((Object)(object)eye != (Object)null) ? eye.forward : ((Component)player).transform.forward);
			GoldBiterLootHold result = null;
			float num = 3.6f;
			for (int i = 0; i < s_boxes.Count; i++)
			{
				GoldBiterLootHold goldBiterLootHold = s_boxes[i];
				if (!((Object)(object)goldBiterLootHold == (Object)null))
				{
					Vector3 val3 = ((Component)goldBiterLootHold).transform.position + Vector3.up * 0.25f - val;
					float magnitude = ((Vector3)(ref val3)).magnitude;
					if (!(magnitude > num) && !(magnitude < 0.05f) && !(Vector3.Dot(val2, val3 / magnitude) < 0.45f))
					{
						num = magnitude;
						result = goldBiterLootHold;
					}
				}
			}
			return result;
		}

		public string GetHoverName()
		{
			return "Gold-Biter loot";
		}

		public float GetHoverOffset()
		{
			return 1.5f;
		}

		public string GetHoverText()
		{
			return Amount + " inside\n" + GoldBiterCrate.GoldLine() + "\n[<color=yellow><b>E</b></color>] Pick up";
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (hold)
			{
				return false;
			}
			if (!GoldBiterCrate.Pocket(user, Prize, Amount))
			{
				return false;
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}
	}
	internal class GoldBiterLootDrop : MonoBehaviour
	{
		private const float Flight = 0.45f;

		private Vector3 m_from;

		private Vector3 m_land;

		private Quaternion m_facing;

		private Vector3 m_axis;

		private float m_roll;

		private float m_time;

		private bool m_flying;

		private TextMesh m_label;

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("loot_label");
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localPosition = new Vector3(0f, 0.42f, 0f);
			m_label = val.AddComponent<TextMesh>();
			m_label.fontSize = 48;
			m_label.characterSize = 0.018f;
			m_label.anchor = (TextAnchor)4;
			m_label.alignment = (TextAlignment)1;
			m_label.color = new Color(1f, 0.86f, 0.35f);
			m_label.text = "";
			Font builtinResource = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			if ((Object)(object)builtinResource == (Object)null)
			{
				builtinResource = Resources.GetBuiltinResource<Font>("Arial.ttf");
			}
			if ((Object)(object)builtinResource != (Object)null)
			{
				m_label.font = builtinResource;
			}
		}

		internal void Kick(Vector3 from, Vector3 land, Quaternion facing)
		{
			//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_0008: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0017: 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_0046: 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)
			//IL_004d: 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_003f: 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_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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			m_from = from;
			m_land = land;
			m_facing = facing;
			Vector3 val = land - from;
			val.y = 0f;
			float magnitude = ((Vector3)(ref val)).magnitude;
			Vector3 val2 = ((magnitude > 0.02f) ? Vector3.Cross(Vector3.up, val / magnitude) : ((Component)this).transform.right);
			if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
			{
				val2 = Vector3.right;
			}
			m_axis = ((Vector3)(ref val2)).normalized;
			m_roll = magnitude / 0.08f * 57.29578f;
			m_time = 0f;
			m_flying = true;
			((Component)this).transform.position = from;
			((Component)this).transform.rotation = facing;
		}

		private void Update()
		{
			//IL_007a: 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_0086: 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_0091: 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)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			if (!m_flying)
			{
				return;
			}
			ZNetView component = ((Component)this).GetComponent<ZNetView>();
			if (!((Object)(object)component != (Object)null) || component.GetZDO() == null || component.IsOwner())
			{
				m_time += Time.deltaTime;
				float num = Mathf.Clamp01(m_time / 0.45f);
				float num2 = num * num * (3f - 2f * num);
				float num3 = Mathf.Sin(num * MathF.PI) * 0.12f;
				((Component)this).transform.position = Vector3.Lerp(m_from, m_land, num2) + Vector3.up * num3;
				Quaternion val = Quaternion.AngleAxis(m_roll * num2, m_axis) * m_facing;
				float num4 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.75f, 1f, num));
				((Component)this).transform.rotation = Quaternion.Slerp(val, m_facing, num4);
				if (!(num < 1f))
				{
					((Component)this).transform.position = m_land;
					((Component)this).transform.rotation = m_facing;
					m_flying = false;
				}
			}
		}

		private void LateUpdate()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)m_label == (Object)null))
			{
				GoldBiterLootHold component = ((Component)this).GetComponent<GoldBiterLootHold>();
				if ((Object)(object)component != (Object)null)
				{
					m_label.text = GoldBiterCrate.PrizeLine(component.Prize, component.Amount) + "\n" + GoldBiterCrate.GoldLine();
				}
				((Component)m_label).transform.localPosition = new Vector3(0f, GoldBiterCrate.LootTop + 0.08f, 0f);
				Camera main = Camera.main;
				if (!((Object)(object)main == (Object)null))
				{
					((Component)m_label).transform.rotation = Quaternion.LookRotation(((Component)m_label).transform.position - ((Component)main).transform.position);
				}
			}
		}
	}
	internal class GoldBiterOpenerFlash : MonoBehaviour
	{
		private float m_time;

		internal void Begin()
		{
			m_time = 0f;
		}

		private void Update()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			m_time += Time.deltaTime;
			((Component)this).transform.Rotate(Vector3.up, 140f * Time.deltaTime, (Space)0);
			if (!(m_time < 1.8f))
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "FindHoverObject")]
	internal static class GoldBiterLootHover
	{
		private static void Postfix(Player __instance, ref GameObject hover)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && (!((Object)(object)hover != (Object)null) || !((Object)(object)hover.GetComponentInParent<GoldBiterLootHold>() != (Object)null)))
			{
				GoldBiterLootHold goldBiterLootHold = GoldBiterLootHold.LookingAt(__instance);
				if ((Object)(object)goldBiterLootHold != (Object)null)
				{
					hover = ((Component)goldBiterLootHold).gameObject;
				}
			}
		}
	}
	internal static class GoldBiterGlb
	{
		[Serializable]
		private class Gltf
		{
			public GltfScene[] scenes;

			public GltfNode[] nodes;

			public GltfMesh[] meshes;

			public GltfMaterial[] materials;

			public GltfAccessor[] accessors;

			public GltfBufferView[] bufferViews;

			public GltfTexture[] textures;

			public GltfImage[] images;
		}

		[Serializable]
		private class GltfScene
		{
			public int[] nodes;
		}

		[Serializable]
		private class GltfNode
		{
			public string name;

			public int mesh = -1;

			public float[] translation;

			public float[] rotation;

			public float[] scale;

			public float[] matrix;

			public int[] children;
		}

		[Serializable]
		private class GltfMesh
		{
			public string name;

			public GltfPrimitive[] primitives;
		}

		[Serializable]
		private class GltfPrimitive
		{
			public GltfAttributes attributes;

			public int indices = -1;

			public int material = -1;
		}

		[Serializable]
		private class GltfAttributes
		{
			public int POSITION = -1;

			public int NORMAL = -1;

			public int TEXCOORD_0 = -1;
		}

		[Serializable]
		private class GltfMaterial
		{
			public string name;

			public GltfPbr pbrMetallicRoughness;
		}

		[Serializable]
		private class GltfPbr
		{
			public float[] baseColorFactor;

			public GltfTextureInfo baseColorTexture;
		}

		[Serializable]
		private class GltfTextureInfo
		{
			public int index = -1;
		}

		[Serializable]
		private class GltfTexture
		{
			public int source = -1;
		}

		[Serializable]
		private class GltfImage
		{
			public int bufferView = -1;
		}

		[Serializable]
		private class GltfAccessor
		{
			public int bufferView;

			public int byteOffset;

			public int componentType;

			public int count;
		}

		[Serializable]
		private class GltfBufferView
		{
			public int byteOffset;

			public int byteLength;

			public int byteStride;
		}

		internal static GameObject Load(string path)
		{
			if (string.IsNullOrEmpty(path) || !File.Exists(path))
			{
				return null;
			}
			try
			{
				return Parse(File.ReadAllBytes(path), Path.GetFileName(path));
			}
			catch (Exception ex)
			{
				GoldBiterPlugin.Log.LogWarning((object)("Gold-Biter: GLB failed " + Path.GetFileName(path) + ": " + ex.Message));
				return null;
			}
		}

		private static GameObject Parse(byte[] data, string fileName)
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Expected O, but got Unknown
			if (data.Length < 20 || BitConverter.ToUInt32(data, 0) != 1179937895)
			{
				GoldBiterPlugin.Log.LogWarning((object)("Gold-Biter: " + fileName + " is not a binary glTF."));
				return null;
			}
			string text = null;
			byte[] array = null;
			int num = 12;
			while (num + 8 <= data.Length)
			{
				uint num2 = BitConverter.ToUInt32(data, num);
				uint num3 = BitConverter.ToUInt32(data, num + 4);
				num += 8;
				if (num + num2 > data.Length)
				{
					break;
				}
				switch (num3)
				{
				case 1313821514u:
					text = Encoding.UTF8.GetString(data, num, (int)num2);
					break;
				case 5130562u:
					array = new byte[num2];
					Array.Copy(data, num, array, 0, (int)num2);
					break;
				}
				num += (int)num2;
				num = (num + 3) & -4;
			}
			if (text == null || array == null)
			{
				GoldBiterPlugin.Log.LogWarning((object)("Gold-Biter: " + fileName + " has no JSON or BIN chunk."));
				return null;
			}
			Gltf gltf = JsonConvert.DeserializeObject<Gltf>(text);
			if (gltf == null || gltf.nodes == null || gltf.meshes == null)
			{
				GoldBiterPlugin.Log.LogWarning((object)("Gold-Biter: " + fileName + " has no mesh."));
				return null;
			}
			GameObject val = new GameObject(Path.GetFileNameWithoutExtension(fileName));
			Shader val2 = FindShader();
			if ((Object)(object)val2 == (Object)null)
			{
				GoldBiterPlugin.Log.LogWarning((object)("Gold-Biter: no shader for " + fileName + "."));
				Object.Destroy((Object)(object)val);
				return null;
			}
			Material[] materials = BuildMaterials(gltf, array, val2);
			Mesh[] array2 = BuildMeshes(gltf, array);
			Material[][] array3 = new Material[array2.Length][];
			for (int i = 0; i < gltf.meshes.Length && i < array2.Length; i++)
			{
				array3[i] = MaterialsForMesh(gltf.meshes[i], materials, val2);
			}
			GameObject[] array4 = (GameObject[])(object)new GameObject[gltf.nodes.Length];
			for (int j = 0; j < gltf.nodes.Length; j++)
			{
				GltfNode gltfNode = gltf.nodes[j];
				array4[j] = new GameObject(string.IsNullOrEmpty(gltfNode.name) ? ("node" + j) : gltfNode.name);
				ApplyTransform(array4[j].transform, gltfNode);
				if (gltfNode.mesh >= 0 && gltfNode.mesh < array2.Length && (Object)(object)array2[gltfNode.mesh] != (Object)null)
				{
					array4[j].AddComponent<MeshFilter>().sharedMesh = array2[gltfNode.mesh];
					MeshRenderer obj = array4[j].AddComponent<MeshRenderer>();
					((Renderer)obj).sharedMaterials = array3[gltfNode.mesh];
					((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				}
			}
			bool[] array5 = new bool[array4.Length];
			for (int k = 0; k < gltf.nodes.Length; k++)
			{
				if (gltf.nodes[k].children == null)
				{
					continue;
				}
				for (int l = 0; l < gltf.nodes[k].children.Length; l++)
				{
					int num4 = gltf.nodes[k].children[l];
					if (num4 >= 0 && num4 < array4.Length)
					{
						array4[num4].transform.SetParent(array4[k].transform, false);
						array5[num4] = true;
					}
				}
			}
			if (gltf.scenes != null && gltf.scenes.Length != 0 && gltf.scenes[0].nodes != null)
			{
				for (int m = 0; m < gltf.scenes[0].nodes.Length; m++)
				{
					int num5 = gltf.scenes[0].nodes[m];
					if (num5 >= 0 && num5 < array4.Length)
					{
						array4[num5].transform.SetParent(val.transform, false);
					}
				}
			}
			else
			{
				for (int n = 0; n < array4.Length; n++)
				{
					if (!array5[n])
					{
						array4[n].transform.SetParent(val.transform, false);
					}
				}
			}
			return val;
		}

		private static void ApplyTransform(Transform transform, GltfNode node)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_008e: 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_009e: 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_00ae: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			if (node.matrix != null && node.matrix.Length == 16)
			{
				Matrix4x4 val = default(Matrix4x4);
				for (int i = 0; i < 16; i++)
				{
					((Matrix4x4)(ref val))[i] = node.matrix[i];
				}
				transform.localPosition = new Vector3(0f - val.m03, val.m13, val.m23);
				Quaternion rotation = ((Matrix4x4)(ref val)).rotation;
				transform.localRotation = new Quaternion(rotation.x, 0f - rotation.y, 0f - rotation.z, rotation.w);
				Vector4 column = ((Matrix4x4)(ref val)).GetColumn(0);
				float magnitude = ((Vector4)(ref column)).magnitude;
				column = ((Matrix4x4)(ref val)).GetColumn(1);
				float magnitude2 = ((Vector4)(ref column)).magnitude;
				column = ((Matrix4x4)(ref val)).GetColumn(2);
				transform.localScale = new Vector3(magnitude, magnitude2, ((Vector4)(ref column)).magnitude);
			}
			else
			{
				if (node.translation != null && node.translation.Length == 3)
				{
					transform.localPosition = new Vector3(0f - node.translation[0], node.translation[1], node.translation[2]);
				}
				if (node.rotation != null && node.rotation.Length == 4)
				{
					transform.localRotation = new Quaternion(node.rotation[0], 0f - node.rotation[1], 0f - node.rotation[2], node.rotation[3]);
				}
				if (node.scale != null && node.scale.Length == 3)
				{
					transform.localScale = new Vector3(node.scale[0], node.scale[1], node.scale[2]);
				}
			}
		}

		private static Shader FindShader()
		{
			Shader val = Shader.Find("Custom/Piece") ?? Shader.Find("Custom/Creature") ?? Shader.Find("Custom/StaticObject") ?? Shader.Find("Standard");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Shader[] array = Resources.FindObjectsOfTypeAll<Shader>();
			for (int i = 0; i < array.Length; i++)
			{
				switch (((Object)(object)array[i] != (Object)null) ? ((Object)array[i]).name : "")
				{
				case "Custom/Piece":
				case "Custom/Creature":
				case "Custom/StaticObject":
				case "Standard":
					return array[i];
				}
			}
			return Shader.Find("Diffuse") ?? Shader.Find("Unlit/Texture");
		}

		private static Material[] BuildMaterials(Gltf gltf, byte[] bin, Shader shader)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			Texture2D[] array = (Texture2D[])(object)new Texture2D[(gltf.images != null) ? gltf.images.Length : 0];
			int num = ((gltf.materials != null) ? gltf.materials.Length : 0);
			Material[] array2 = (Material[])(object)new Material[num];
			for (int i = 0; i < num; i++)
			{
				GltfMaterial gltfMaterial = gltf.materials[i];
				Material val = new Material(shader);
				((Object)val).name = ((gltfMaterial != null && !string.IsNullOrEmpty(gltfMaterial.name)) ? gltfMaterial.name : ("glb_material_" + i));
				val.color = Color.white;
				GltfPbr gltfPbr = gltfMaterial?.pbrMetallicRoughness;
				if (gltfPbr != null)
				{
					if (gltfPbr.baseColorFactor != null && gltfPbr.baseColorFactor.Length >= 3)
					{
						float num2 = ((gltfPbr.baseColorFactor.Length > 3) ? gltfPbr.baseColorFactor[3] : 1f);
						val.color = new Color(gltfPbr.baseColorFactor[0], gltfPbr.baseColorFactor[1], gltfPbr.baseColorFactor[2], num2);
					}
					if (gltfPbr.baseColorTexture != null && gltf.textures != null && gltfPbr.baseColorTexture.index >= 0 && gltfPbr.baseColorTexture.index < gltf.textures.Length)
					{
						int source = gltf.textures[gltfPbr.baseColorTexture.index].source;
						if (source >= 0 && source < array.Length)
						{
							if ((Object)(object)array[source] == (Object)null)
							{
								array[source] = LoadTexture(gltf, bin, source);
							}
							if ((Object)(object)array[source] != (Object)null)
							{
								val.mainTexture = (Texture)(object)array[source];
								if (val.HasProperty("_MainTex"))
								{
									val.SetTexture("_MainTex", (Texture)(object)array[source]);
								}
							}
						}
					}
				}
				if ((Object)(object)val.mainTexture == (Object)null)
				{
					Texture2D val2 = (Texture2D)(object)(val.mainTexture = (Texture)(object)SolidColor(val.color));
					if (val.HasProperty("_MainTex"))
					{
						val.SetTexture("_MainTex", (Texture)(object)val2);
					}
					val.color = Color.white;
				}
				array2[i] = val;
			}
			return array2;
		}

		private static Texture2D LoadTexture(Gltf gltf, byte[] bin, int image)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			GltfImage gltfImage = gltf.images[image];
			if (gltfImage == null || gltfImage.bufferView < 0 || gltf.bufferViews == null || gltfImage.bufferView >= gltf.bufferViews.Length)
			{
				return null;
			}
			GltfBufferView gltfBufferView = gltf.bufferViews[gltfImage.bufferView];
			if (gltfBufferView == null || gltfBufferView.byteLength <= 0)
			{
				return null;
			}
			int byteOffset = gltfBufferView.byteOffset;
			if (byteOffset < 0 || byteOffset + gltfBufferView.byteLength > bin.Length)
			{
				return null;
			}
			byte[] array = new byte[gltfBufferView.byteLength];
			Array.Copy(bin, byteOffset, array, 0, gltfBufferView.byteLength);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
			if (!ImageConversion.LoadImage(val, array))
			{
				Object.Destroy((Object)(object)val);
				return null;
			}
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			val.Apply(true, true);
			return val;
		}

		private static Texture2D SolidColor(Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0017: 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)
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[4];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = color;
			}
			val.SetPixels(array);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)0;
			val.Apply(false, true);
			return val;
		}

		private static Material[] MaterialsForMesh(GltfMesh mesh, Material[] materials, Shader shader)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			//IL_005b: Expected O, but got Unknown
			int num = ((mesh.primitives != null) ? mesh.primitives.Length : 0);
			Material[] array = (Material[])(object)new Material[num];
			for (int i = 0; i < num; i++)
			{
				int material = mesh.primitives[i].material;
				array[i] = (Material)((material >= 0 && material < materials.Length && (Object)(object)materials[material] != (Object)null) ? ((object)materials[material]) : ((object)new Material(shader)
				{
					color = Color.white
				}));
			}
			return array;
		}

		private static Mesh[] BuildMeshes(Gltf gltf, byte[] bin)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_015a: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			Mesh[] array = (Mesh[])(object)new Mesh[gltf.meshes.Length];
			for (int i = 0; i < array.Length; i++)
			{
				GltfMesh gltfMesh = gltf.meshes[i];
				if (gltfMesh == null || gltfMesh.primitives == null)
				{
					continue;
				}
				Mesh val = new Mesh();
				((Object)val).name = (string.IsNullOrEmpty(gltfMesh.name) ? ("glb_mesh_" + i) : gltfMesh.name);
				List<Vector3> list = new List<Vector3>();
				List<Vector3> list2 = new List<Vector3>();
				List<Vector2> list3 = new List<Vector2>();
				List<int[]> list4 = new List<int[]>();
				bool flag = true;
				for (int j = 0; j < gltfMesh.primitives.Length; j++)
				{
					GltfPrimitive gltfPrimitive = gltfMesh.primitives[j];
					if (gltfPrimitive == null || gltfPrimitive.attributes == null || gltfPrimitive.attributes.POSITION < 0)
					{
						continue;
					}
					int count = list.Count;
					float[] array2 = ReadFloats(gltf, bin, gltfPrimitive.attributes.POSITION, 3);
					if (array2 == null)
					{
						continue;
					}
					float[] array3 = ((gltfPrimitive.attributes.NORMAL >= 0) ? ReadFloats(gltf, bin, gltfPrimitive.attributes.NORMAL, 3) : null);
					float[] array4 = ((gltfPrimitive.attributes.TEXCOORD_0 >= 0) ? ReadFloats(gltf, bin, gltfPrimitive.attributes.TEXCOORD_0, 2) : null);
					int num = array2.Length / 3;
					for (int k = 0; k < num; k++)
					{
						list.Add(new Vector3(0f - array2[k * 3], array2[k * 3 + 1], array2[k * 3 + 2]));
						if (array3 != null && array3.Length == array2.Length)
						{
							list2.Add(new Vector3(0f - array3[k * 3], array3[k * 3 + 1], array3[k * 3 + 2]));
						}
						else
						{
							flag = false;
						}
						list3.Add((Vector2)((array4 != null && array4.Length == num * 2) ? new Vector2(array4[k * 2], 1f - array4[k * 2 + 1]) : Vector2.zero));
					}
					int[] array5;
					if (gltfPrimitive.indices >= 0)
					{
						array5 = ReadIndices(gltf, bin, gltfPrimitive.indices);
						if (array5 == null)
						{
							continue;
						}
					}
					else
					{
						array5 = new int[num];
						for (int l = 0; l < num; l++)
						{
							array5[l] = l;
						}
					}
					for (int m = 0; m + 2 < array5.Length; m += 3)
					{
						int num2 = array5[m];
						array5[m] = array5[m + 2] + count;
						array5[m + 2] = num2 + count;
						array5[m + 1] += count;
					}
					list4.Add(array5);
				}
				if (list.Count != 0 && list4.Count != 0)
				{
					if (list.Count > 65535)
					{
						val.indexFormat = (IndexFormat)1;
					}
					val.SetVertices(list);
					val.SetUVs(0, list3);
					if (flag && list2.Count == list.Count)
					{
						val.SetNormals(list2);
					}
					val.subMeshCount = list4.Count;
					for (int n = 0; n < list4.Count; n++)
					{
						val.SetTriangles(list4[n], n);
					}
					if (!flag)
					{
						val.RecalculateNormals();
					}
					val.RecalculateBounds();
					array[i] = val;
				}
			}
			return array;
		}

		private static float[] ReadFloats(Gltf gltf, byte[] bin, int accessorIndex, int components)
		{
			if (gltf.accessors == null || accessorIndex < 0 || accessorIndex >= gltf.accessors.Length)
			{
				return null;
			}
			GltfAccessor gltfAccessor = gltf.accessors[accessorIndex];
			if (gltfAccessor == null || gltfAccessor.componentType != 5126)
			{
				return null;
			}
			GltfBufferView gltfBufferView = View(gltf, gltfAccessor.bufferView);
			if (gltfBufferView == null)
			{
				return null;
			}
			int num = ((gltfBufferView.byteStride > 0) ? gltfBufferView.byteStride : (components * 4));
			int num2 = gltfBufferView.byteOffset + gltfAccessor.byteOffset;
			float[] array = new float[gltfAccessor.count * components];
			for (int i = 0; i < gltfAccessor.count; i++)
			{
				int num3 = num2 + i * num;
				if (num3 + components * 4 > bin.Length)
				{
					return null;
				}
				for (int j = 0; j < components; j++)
				{
					array[i * components + j] = BitConverter.ToSingle(bin, num3 + j * 4);
				}
			}
			return array;
		}

		private static int[] ReadIndices(Gltf gltf, byte[] bin, int accessorIndex)
		{
			if (gltf.accessors == null || accessorIndex < 0 || accessorIndex >= gltf.accessors.Length)
			{
				return null;
			}
			GltfAccessor gltfAccessor = gltf.accessors[accessorIndex];
			if (gltfAccessor == null)
			{
				return null;
			}
			GltfBufferView gltfBufferView = View(gltf, gltfAccessor.bufferView);
			if (gltfBufferView == null)
			{
				return null;
			}
			int num = ((gltfAccessor.componentType == 5121) ? 1 : ((gltfAccessor.componentType == 5123) ? 2 : 4));
			int num2 = ((gltfBufferView.byteStride > 0) ? gltfBufferView.byteStride : num);
			int num3 = gltfBufferView.byteOffset + gltfAccessor.byteOffset;
			int[] array = new int[gltfAccessor.count];
			for (int i = 0; i < gltfAccessor.count; i++)
			{
				int num4 = num3 + i * num2;
				if (num4 + num > bin.Length)
				{
					return null;
				}
				array[i] = num switch
				{
					2 => BitConverter.ToUInt16(bin, num4), 
					1 => bin[num4], 
					_ => BitConverter.ToInt32(bin, num4), 
				};
			}
			return array;
		}

		private static GltfBufferView View(Gltf gltf, int index)
		{
			if (gltf.bufferViews == null || index < 0 || index >= gltf.bufferViews.Length)
			{
				return null;
			}
			return gltf.bufferViews[index];
		}
	}
	internal static class GoldBiterLedger
	{
		private sealed class Board
		{
			public int Pot = 100;

			public readonly List<string> Recent = new List<string>();

			public bool Loaded;
		}

		public const int Seed = 100;

		public const int Stake = 5;

		public const int Odds = 200;

		private const int RecentCount = 4;

		private const string KeyPrefix = "GoldBiter_Pot_";

		private static readonly Dictionary<string, Board> s_boards = new Dictionary<string, Board>();

		public static int PotOf(string type)
		{
			return BoardFor(type).Pot;
		}

		public static string SignText(string type)
		{
			Board board = BoardFor(type);
			string text = "JACKPOT  " + board.Pot.ToString(CultureInfo.InvariantCulture);
			if (board.Recent.Count == 0)
			{
				return text + "\nno payouts yet";
			}
			for (int i = 0; i < board.Recent.Count; i++)
			{
				text = text + "\n" + board.Recent[i];
			}
			return text;
		}

		public static int Pull(string type, string payout)
		{
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return 0;
			}
			if (string.IsNullOrEmpty(type))
			{
				type = "moxxi";
			}
			if (type.Length > 24)
			{
				type = type.Substring(0, 24);
			}
			payout = Clean(payout);
			Board board = BoardFor(type);
			board.Pot += 5;
			int num = 0;
			if (Random.Range(0, 200) == 0)
			{
				num = board.Pot;
				board.Pot = 100;
			}
			if (num > 0)
			{
				Remember(board, "JACKPOT " + num.ToString(CultureInfo.InvariantCulture));
			}
			if (!string.IsNullOrEmpty(payout))
			{
				Remember(board, payout);
			}
			Save(type, board);
			GoldBiterSign.RefreshAll();
			GoldBiterPlugin.Log.LogInfo((object)("Gold-Biter: " + type + " jackpot " + board.Pot + ((num > 0) ? (", paid " + num) : "") + "."));
			return num;
		}

		public static int Commit(string type, string payout, ZNetView view)
		{
			if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
			{
				return Pull(type, payout);
			}
			ZNetPeer val = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetServerPeer() : null);
			if ((Object)(object)view != (Object)null && view.IsValid() && val != null)
			{
				view.InvokeRPC(val.m_uid, "GoldBiter_Ledger", new object[2]
				{
					type ?? "",
					payout ?? ""
				});
			}
			return 0;
		}

		private static void Remember(Board board, string line)
		{
			board.Recent.Insert(0, line);
			while (board.Recent.Count > 4)
			{
				board.Recent.RemoveAt(board.Recent.Count - 1);
			}
		}

		private static Board BoardFor(string type)
		{
			if (string.IsNullOrEmpty(type))
			{
				type = "moxxi";
			}
			if (!s_boards.TryGetValue(type, out var value))
			{
				value = new Board();
				s_boards[type] = value;
			}
			if (!value.Loaded)
			{
				value.Loaded = true;
				Read(type, value);
			}
			else if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				Read(type, value);
			}
			return value;
		}

		private static void Read(string type, Board board)
		{
			if ((Object)(object)ZoneSystem.instance == (Object)null)
			{
				return;
			}
			string text = default(string);
			try
			{
				if (!ZoneSystem.instance.GetGlobalKey("GoldBiter_Pot_" + type, ref text) || string.IsNullOrEmpty(text))
				{
					return;
				}
			}
			catch
			{
				return;
			}
			string[] array = text.Split('|');
			if (array.Length == 0 || !int.TryParse(array[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return;
			}
			board.Pot = Mathf.Max(100, result);
			board.Recent.Clear();
			for (int i = 1; i < array.Length; i++)
			{
				if (board.Recent.Count >= 4)
				{
					break;
				}
				if (!string.IsNullOrEmpty(array[i]))
				{
					board.Recent.Add(array[i]);
				}
			}
		}

		private static void Save(string type, Board board)
		{
			if ((Object)(object)ZoneSystem.instance == (Object)null)
			{
				return;
			}
			string text = board.Pot.ToString(CultureInfo.InvariantCulture);
			for (int i = 0; i < board.Recent.Count; i++)
			{
				text = text + "|" + board.Recent[i];
			}
			try
			{
				ZoneSystem.instance.RemoveGlobalKey("GoldBiter_Pot_" + type);
				ZoneSystem.instance.SetGlobalKey("GoldBiter_Pot_" + type + " " + text);
			}
			catch (Exception ex)
			{
				GoldBiterPlugin.Log.LogWarning((object)("Gold-Biter: could not store the " + type + " jackpot: " + ex.Message));
			}
		}

		private static string Clean(string payout)
		{
			if (string.IsNullOrEmpty(payout))
			{
				return "";
			}
			payout = payout.Replace("|", " ").Trim();
			if (payout.Length > 40)
			{
				payout = payout.Substring(0, 40);
			}
			return payout;
		}
	}
	public class GoldBiterMachine : MonoBehaviour, Hoverable, Interactable
	{
		private struct Cabinet
		{
			public string Type;

			public string Prefab;

			public string Title;

			public string File;

			public string Metal;

			public string Boss;

			public string Lock;
		}

		public const string PrefabName = "Piece_SanctuarySlotMachine";

		public const string DisplayName = "Moxxi's Gold-Biter";

		public const string TypeId = "moxxi";

		private static readonly Cabinet MoxxiCab = new Cabinet
		{
			Type = "moxxi",
			Prefab = "Piece_SanctuarySlotMachine",
			Title = "Moxxi's Gold-Biter",
			File = "moxxi.glb",
			Metal = "",
			Boss = ""
		};

		private static readonly Cabinet EikthyrCab = new Cabinet
		{
			Type = "eikthyr",
			Prefab = "Piece_EikthyrMachine",
			Title = "Eikthyr's Gold-Biter",
			File = "EIKTHYR_machine.glb",
			Metal = "Copper",
			Boss = "defeated_eikthyr",
			Lock = "Eikthyr still stands. This machine stays dark."
		};

		private static readonly Cabinet ElderCab = new Cabinet
		{
			Type = "elder",
			Prefab = "Piece_ElderMachine",
			Title = "The Elder's Gold-Biter",
			File = "elder_machine.glb",
			Metal = "Iron",
			Boss = "defeated_gdking",
			Lock = "The Elder still stands. This machine stays dark."
		};

		private static readonly Cabinet BonemassCab = new Cabinet
		{
			Type = "bonemass",
			Prefab = "Piece_BonemassMachine",
			Title = "Bonemass's Gold-Biter",
			File = "bonemass_machine.glb",
			Metal = "Silver",
			Boss = "defeated_bonemass",
			Lock = "Bonemass still stands. This machine stays dark."
		};

		private static readonly Cabinet ModerCab = new Cabinet
		{
			Type = "moder",
			Prefab = "Piece_ModerMachine",
			Title = "Moder's Gold-Biter",
			File = "moder_machine.glb",
			Metal = "BlackMetal",
			Boss = "defeated_dragon",
			Lock = "Moder still stands. This machine stays dark."
		};

		private static readonly Cabinet YagluthCab = new Cabinet
		{
			Type = "yagluth",
			Prefab = "Piece_YagluthMachine",
			Title = "Yagluth's Gold-Biter",
			File = "yagluth_machine.glb",
			Metal = "Sap",
			Boss = "defeated_goblinking",
			Lock = "Yagluth still stands. This machine stays dark."
		};

		private static readonly Cabinet QueenCab = new Cabinet
		{
			Type = "queen",
			Prefab = "Piece_QueenMachine",
			Title = "The Queen's Gold-Biter",
			File = "queen_machine.glb",
			Metal = "Flametal",
			Boss = "defeated_queen",
			Lock = "The Queen still stands. This machine stays dark."
		};

		private static readonly Cabinet FaderCab = new Cabinet
		{
			Type = "fader",
			Prefab = "Piece_FaderMachine",
			Title = "Fader's Gold-Biter",
			File = "fader_machine.glb",
			Metal = "FlametalNew",
			Boss = "defeated_fader",
			Lock = "Fader still stands. This machine stays dark."
		};

		public const int PullCost = 25;

		public const float SpinSeconds = 3.5f;

		private const string SpinKey = "Sanctuary_SlotSpin";

		private const string IdKey = "Sanctuary_SlotId";

		private const string OutcomeKey = "Sanctuary_SlotFace";

		private const string PayerKey = "Sanctuary_SlotPayer";

		private const string RpcSpin = "RPC_PlaySpinEffects";

		private const string RpcRefund = "Sanctuary_SlotRefund";

		private const int Skulls = 0;

		private const int Eitr = 1;

		private const int Munitions = 2;

		private const int Ingots = 3;

		private const int Mead = 4;

		private const int Coins = 5;

		private const int Loss = -1;

		private const int FaceCount = 6;

		private const int PackBase = 1000;

		private static readonly float[] StopAt = new float[3] { 1.5f, 2.4f, 3.5f };

		private static readonly Color[] FaceColor = (Color[])(object)new Color[6]
		{
			new Color(0.15f, 0.02f, 0.02f),
			new Color(0.55f, 0.25f, 0.85f),
			new Color(0.85f, 0.35f, 0.1f),
			new Color(0.75f, 0.78f, 0.82f),
			new Color(0.7f, 0.05f, 0.12f),
			new Color(0.92f, 0.75f, 0.2f)
		};

		private static bool s_moxxiReady;

		private static bool s_eikthyrReady;

		private static bool s_elderReady;

		private static bool s_bonemassReady;

		private static bool s_moderReady;

		private static bool s_yagluthReady;

		private static bool s_queenReady;

		private static bool s_faderReady;

		private static bool s_registerWarned;

		private static readonly bool BossCabinets = false;

		private static float s_havenTold;

		private static Func<Vector3, bool> s_inside;

		private ZNetView m_nview;

		private Transform[] m_reels = (Transform[])(object)new Transform[3];

		private readonly bool[] m_locked = new bool[3];

		private Transform m_lever;

		private Coroutine m_spin;

		private int m_seen = -1;

		private bool m_ready;

		private bool m_hubWarned;

		private string m_type = "moxxi";

		private string m_title = "Moxxi's Gold-Biter";

		private string m_metal = "";

		private string m_boss = "";

		private string m_lock = "";

		private const string DryKey = "Sanctuary_SlotDry";

		private static GameObject s_bomb;

		public string MachineType
		{
			get
			{
				if (!string.IsNullOrEmpty(m_type))
				{
					return m_type;
				}
				return "moxxi";
			}
		}

		public static void Restrict(Func<Vector3, bool> inside)
		{
			s_inside = inside;
		}

		public static void Place(Transform parent, Vector3 localPos, Quaternion rot)
		{
			//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)
			Build(parent, localPos, rot, MoxxiCab, networked: true, piece: false);
		}

		public static void PlaceEikthyr(Transform parent, Vector3 localPos, Quaternion rot)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (BossCabinets)
			{
				Build(parent, localPos, rot, EikthyrCab, networked: true, piece: false);
			}
		}

		public static void PlaceElder(Transform parent, Vector3 localPos, Quaternion rot)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (BossCabinets)
			{
				Build(parent, localPos, rot, ElderCab, networked: true, piece: false);
			}
		}

		public static void PlaceBonemass(Transform parent, Vector3 localPos, Quaternion rot)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (BossCabinets)
			{
				Build(parent, localPos, rot, BonemassCab, networked: true, piece: false);
			}
		}

		public static void PlaceModer(Transform parent, Vector3 localPos, Quaternion rot)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (BossCabinets)
			{
				Build(parent, localPos, rot, ModerCab, networked: true, piece: false);
			}
		}

		public static void PlaceYagluth(Transform parent, Vector3 localPos, Quaternion rot)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (BossCabinets)
			{
				Build(parent, localPos, rot, YagluthCab, networked: true, piece: false);
			}
		}

		public static void PlaceQueen(Transform parent, Vector3 localPos, Quaternion rot)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (BossCabinets)
			{
				Build(parent, localPos, rot, QueenCab, networked: true, piece: false);
			}
		}

		public static void PlaceFader(Transform parent, Vector3 localPos, Quaternion rot)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (BossCabinets)
			{
				Build(parent, localPos, rot, FaderCab, networked: true, piece: false);
			}
		}

		public static void TryRegister()
		{
			GoldBiterCrate.TryRegister();
			if ((s_moxxiReady && !BossCabinets) || (s_moxxiReady && s_eikthyrReady && s_elderReady && s_bonemassReady && s_moderReady && s_yagluthReady && s_queenReady && s_faderReady) || PrefabManager.Instance == null || PieceManager.Instance == null || (Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			try
			{
				if (!s_moxxiReady)
				{
					s_moxxiReady = RegisterPiece(MoxxiCab);
				}
				if (BossCabinets)
				{
					if (!s_eikthyrReady)
					{
						s_eikthyrReady = RegisterPiece(EikthyrCab);
					}
					if (!s_elderReady)
					{
						s_elderReady = RegisterPiece(ElderCab);
					}
					if (!s_bonemassReady)
					{
						s_bonemassReady = RegisterPiece(BonemassCab);
					}
					if (!s_moderReady)
					{
						s_moderReady = RegisterPiece(ModerCab);
					}
					if (!s_yagluthReady)
					{
						s_yagluthReady = RegisterPiece(YagluthCab);
					}
					if (!s_queenReady)
					{
						s_queenReady = RegisterPiece(QueenCab);
					}
					if (!s_faderReady)
					{
						s_faderReady = RegisterPiece(FaderCab);
					}
				}
			}
			catch (Exception ex)
			{
				if ((ex.Message == null || ex.Message.IndexOf("Could not find PieceTable", StringComparison.Ordinal) < 0) && !s_registerWarned)
				{
					s_registerWarned = true;
					GoldBiterPlugin.Log.LogWarning((object)("Gold-Biter: registration failed: " + ex.Message));
				}
			}
		}

		private static bool RegisterPiece(Cabinet cab)
		{
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			string description = Blurb(cab);
			GameObject prefab = PrefabManager.Instance.GetPrefab(cab.Prefab);
			if ((Object)(object)prefab == (Object)null)
			{
				prefab = PrefabManager.Instance.CreateEmptyPrefab(cab.Prefab, false);
				if ((Object)(object)prefab == (Object)null)
				{
					return false;
				}
				prefab.SetActive(false);
				Dress(prefab.transform, cab);
				if ((Object)(object)prefab.GetComponent<ZNetView>() == (Object)null)
				{
					prefab.AddComponent<ZNetView>();
				}
				ZNetView component = prefab.GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_persistent = true;
				}
				Wear(prefab);
				Stamp(prefab, cab);
				Piece val = prefab.GetComponent<Piece>();
				if ((Object)(object)val == (Object)null)
				{
					val = prefab.AddComponent<Piece>();
				}
				val.m_name = cab.Title;
				val.m_description = description;
				val.m_category = PieceManager.Instance.AddPieceCategory("DFG");
				val.m_craftingStation = null;
				val.m_groundPiece = true;
				val.m_groundOnly = false;
				val.m_cultivatedGroundOnly = false;
				val.m_canBeRemoved = true;
				val.m_clipGround = true;
				val.m_resources = Requirements();
				Sprite icon = (val.m_icon = Icon());
				PieceConfig val2 = new PieceConfig
				{
					Name = cab.Title,
					Description = description,
					PieceTable = "Hammer",
					Category = "DFG",
					Enabled = true,
					Icon = icon
				};
				PieceManager.Instance.AddPiece(new CustomPiece(prefab, false, val2));
				PieceManager.Instance.RegisterPieceInPieceTable(prefab, "Hammer", "DFG");
			}
			else
			{
				Stamp(prefab, cab);
				Piece val3 = prefab.GetComponent<Piece>();
				if ((Object)(object)val3 == (Object)null)
				{
					val3 = prefab.AddComponent<Piece>();
				}
				val3.m_name = cab.Title;
				val3.m_description = description;
				val3.m_category = PieceManager.Instance.AddPieceCategory("DFG");
				val3.m_craftingStation = null;
				val3.m_canBeRemoved = true;
				if (val3.m_resources == null || val3.m_resources.Length == 0)
				{
					val3.m_resources = Requirements();
				}
				val3.m_icon = Icon();
				PieceManager.Instance.RegisterPieceInPieceTable(prefab, "Hammer", "DFG");
			}
			GoldBiterPlugin.Log.LogInfo((object)(cab.Title + " is on the Hammer."));
			return true;
		}

		private static GameObject Build(Transform parent, Vector3 localPos, Quaternion rot, Cabinet cab, bool networked, bool piece)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001f: 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)
			GameObject val = new GameObject(cab.Prefab);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPos;
			val.transform.localRotation = rot;
			Dress(val.transform, cab);
			if (networked)
			{
				val.AddComponent<ZNetView>().m_persistent = true;
			}
			Wear(val);
			Stamp(val, cab);
			if (piece)
			{
				Piece obj = val.AddComponent<Piece>();
				obj.m_name = cab.Title;
				obj.m_canBeRemoved = true;
			}
			return val;
		}

		private static void Stamp(GameObject root, Cabinet cab)
		{
			GoldBiterMachine goldBiterMachine = root.GetComponent<GoldBiterMachine>();
			if ((Object)(object)goldBiterMachine == (Object)null)
			{
				goldBiterMachine = root.AddComponent<GoldBiterMachine>();
			}
			goldBiterMachine.m_type = (string.IsNullOrEmpty(cab.Type) ? "moxxi" : cab.Type);
			goldBiterMachine.m_title = (string.IsNullOrEmpty(cab.Title) ? "Moxxi's Gold-Biter" : cab.Title);
			goldBiterMachine.m_metal = cab.Metal ?? "";
			goldBiterMachine.m_boss = cab.Boss ?? "";
			goldBiterMachine.m_lock = cab.Lock ?? "";
		}

		private static string Blurb(Cabinet cab)
		{
			if (string.IsNullOrEmpty(cab.Boss))
			{
				return "Twenty-five coins a pull.";
			}
			string text = (string.IsNullOrEmpty(cab.Metal) ? "coins" : MetalName(cab.Metal));
			string text2 = "the boss";
			if (cab.Boss == "defeated_eikthyr")
			{
				text2 = "Eikthyr";
			}
			else if (cab.Boss == "defeated_gdking")
			{
				text2 = "the Elder";
			}
			else if (cab.Boss == "defeated_bonemass")
			{
				text2 = "Bonemass";
			}
			else if (cab.Boss == "defeated_dragon")
			{
				text2 = "Moder";
			}
			else if (cab.Boss == "defeated_goblinking")
			{
				text2 = "Yagluth";
			}
			else if (cab.Boss == "defeated_queen")
			{
				text2 = "the Queen";
			}
			else if (cab.Boss == "defeated_fader")
			{
				text2 = "Fader";
			}
			return "Twenty-five coins a pull. " + text + ", once " + text2 + " has fallen.";
		}

		private static void Dress(Transform root, Cabinet cab)
		{
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: 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_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: 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_02c6: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			Material val = Borrow("piece_sharpstakes", "piece_workbench");
			GameObject val2 = TryArt(cab);
			if ((Object)(object)val2 != (Object)null)
			{
				Transform transform = new GameObject("slot_visual").transform;
				transform.SetParent(root, false);
				((Object)val2).name = "slot_art";
				val2.transform.SetParent(transform, false);
				Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)null)
					{
						Object.Destroy((Object)(object)componentsInChildren[i]);
					}
				}
				Bounds fitted = FitArt(transform);
				PlaceReels(transform, fitted, val, cab.Type);
				ApplySize(root, transform, fitted);
				GoldBiterSign.Attach(root, fitted);
				GoldBiterPlugin.Log.LogInfo((object)("Gold-Biter: cabinet " + ((Bounds)(ref fitted)).size.x.ToString("0.00") + " x " + ((Bounds)(ref fitted)).size.y.ToString("0.00") + " x " + ((Bounds)(ref fitted)).size.z.ToString("0.00") + " m at size " + GoldBiterTune.Machine.ToString("0.00") + "."));
				return;
			}
			Material mat = Borrow("piece_wood_floor", "piece_workbench");
			Primitive(root, "ph_cabinet", (PrimitiveType)3, new Vector3(0f, 0.85f, 0f), new Vector3(1.35f, 1.5f, 0.7f), mat);
			Bounds fitted2 = default(Bounds);
			((Bounds)(ref fitted2))..ctor(new Vector3(0f, 0.85f, 0f), new Vector3(1.4f, 1.7f, 0.85f));
			BoxCollider obj = ((Component)root).gameObject.AddComponent<BoxCollider>();
			obj.center = ((Bounds)(ref fitted2)).center;
			obj.size = ((Bounds)(ref fitted2)).size + new Vector3(0.2f, 0.08f, 0.16f);
			for (int j = 0; j < 3; j++)
			{
				Transform obj2 = Primitive(root, "reel_" + j, (PrimitiveType)2, new Vector3(-0.38f + (float)j * 0.38f, 1.05f, -0.28f), new Vector3(0.28f, 0.08f, 0.28f), val);
				obj2.localRotation = Quaternion.Euler(0f, 0f, 90f);
				Collider component = ((Component)obj2).GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
			}
			EnsureLever(root, fitted2, val);
			GoldBiterSign.Attach(root, fitted2);
		}

		private static void PlaceReels(Transform root, Bounds fitted, Material iron, string type)
		{
			//IL_00b3: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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)
			//IL_0158: 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)
			GameObject val = LoadDrum();
			for (int i = 0; i < 3; i++)
			{
				Transform val2;
				if ((Object)(object)val == (Object)null)
				{
					Mathf.Max(0.16f, ((Bounds)(ref fitted)).size.x * 0.28f);
					float num = Mathf.Clamp(((Bounds)(ref fitted)).size.x * 0.22f, 0.12f, 0.34f);
					val2 = Primitive(root, "reel_" + i, (PrimitiveType)2, Vector3.zero, new Vector3(num, 0.045f, num), iron);
					val2.localRotation = Quaternion.Euler(0f, 0f, 90f);
				}
				else
				{
					val2 = new GameObject("reel_" + i).transform;
					val2.SetParent(root, false);
					Transform transform = new GameObject("aim").transform;
					transform.SetParent(val2, false);
					Transform transform2 = new GameObject("spin").transform;
					transform2.SetParent(transform, false);
					((Object)Object.Instantiate<GameObject>(val, transform2, false)).name = "drum";
				}
				Collider[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Collider>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					if ((Object)(object)componentsInChildren[j] != (Object)null)
					{
						Object.Destroy((Object)(object)componentsInChildren[j]);
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
			EnsureLever(root, fitted, iron);
			PoseReels(root, fitted, type);
		}

		private static GameObject LoadDrum()
		{
			string pluginDir = GoldBiterPlugin.PluginDir;
			if (string.IsNullOrEmpty(pluginDir))
			{
				return null;
			}
			string path = Path.Combine(pluginDir, "drum_reel.glb");
			if (!File.Exists(path))
			{
				return null;
			}
			GameObject obj = GoldBiterGlb.Load(path);
			if ((Object)(object)obj == (Object)null)
			{
				GoldBiterPlugin.Log.LogWarning((object)"Gold-Biter: drum_reel.glb did not load. The reels stay cylinders.");
				return obj;
			}
			GoldBiterPlugin.Log.LogInfo((object)"Gold-Biter: three drums from drum_reel.glb.");
			return obj;
		}

		public void Relayout()
		{
			//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_0049: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			Transform val = ((Component)this).transform.Find("slot_visual");
			Transform obj = (((Object)(object)val != (Object)null) ? val : ((Component)this).transform);
			if ((Object)(object)val != (Object)null)
			{
				val.localScale = Vector3.one;
				val.localPosition = Vector3.zero;
			}
			Bounds fitted = FitArt(obj);
			PoseReels(obj, fitted, MachineType);
			if ((Object)(object)val != (Object)null)
			{
				ApplySize(((Component)this).transform, val, fitted);
			}
			GoldBiterSign.Move(((Component)this).transform, fitted);
			PoseLever(GoldBiterTune.LeverHeld ? 1f : 0f);
			PlaceChestMark(GoldBiterTune.ChestShown);
		}

		private static void PoseReels(Transform root, Bounds fitted, string type)
		{
			//IL_0010: 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_0037: 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_00a4: 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)
			//IL_00e7: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			GoldBiterTune.Drum drum = GoldBiterTune.For(type);
			float gap = drum.Gap;
			float num = ((Bounds)(ref fitted)).min.y + ((Bounds)(ref fitted)).size.y * 0.62f + drum.Y;
			float num2 = ((Bounds)(ref fitted)).min.z - 0.03f + drum.Z;
			float num3 = ((Bounds)(ref fitted)).center.x + drum.X;
			Vector3 localScale = default(Vector3);
			((Vector3)(ref localScale))..ctor(Mathf.Max(0.01f, drum.Scale * drum.Thickness), Mathf.Max(0.01f, drum.Scale), Mathf.Max(0.01f, drum.Scale));
			Quaternion alignment = drum.Alignment;
			for (int i = 0; i < 3; i++)
			{
				Transform val = root.Find("reel_" + i);
				if (!((Object)(object)val == (Object)null))
				{
					val.localPosition = new Vector3(num3 + (float)(i - 1) * gap, num, num2);
					Transform val2 = val.Find("aim");
					Transform val3 = (((Object)(object)val2 != (Object)null) ? val2.Find("spin/drum") : val.Find("drum"));
					if ((Object)(object)val2 != (Object)null)
					{
						val2.localRotation = alignment;
					}
					if (!((Object)(object)val3 == (Object)null))
					{
						val3.localPosition = Vector3.zero;
						val3.localScale = localScale;
						val3.localRotation = Quaternion.identity;
					}
				}
			}
			Transform val4 = root.Find("ph_lever_slot");
			if ((Object)(object)val4 != (Object)null)
			{
				FitLever(val4, fitted);
			}
		}

		private static void EnsureLever(Transform root, Bounds fitted, Material iron)
		{
			//IL_0029: 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)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = root.Find("ph_lever_slot");
			if ((Object)(object)val != (Object)null && (Object)(object)val.Find("lever_art") != (Object)null)
			{
				FitLever(val, fitted);
				return;
			}
			GameObject val2 = LoadLever();
			if ((Object)(object)val2 == (Object)null)
			{
				if ((Object)(object)val == (Object)null)
				{
					val = Primitive(root, "ph_lever_slot", (PrimitiveType)3, Vector3.zero, new Vector3(0.08f, Mathf.Min(0.55f, ((Bounds)(ref fitted)).size.y * 0.28f), 0.08f), iron);
					Collider component = ((Component)val).GetComponent<Collider>();
					if ((Object)(object)component != (Object)null)
					{
						Object.Destroy((Object)(object)component);
					}
				}
				FitLever(val, fitted);
				return;
			}
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			val = new GameObject("ph_lever_slot").transform;
			val.SetParent(root, false);
			((Object)val2).name = "lever_art";
			val2.SetActive(true);
			val2.transform.SetParent(val, false);
			val2.transform.localRotation = GoldBiterTune.LeverAlignment;
			Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] != (Object)null)
				{
					Object.Destroy((Object)(object)componentsInChildren[i]);
				}
			}
			SeparateHandle(val2.transform);
			FitLever(val, fitted);
		}

		private static void FitLever(Transform lever, Bounds fitted)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)