Decompiled source of LandDrakkar v1.0.0

LandDrakkar.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using MyMods;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Rendering;

[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("LandDrakkar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0bd1a83dbfd4c46c0de3fdcfa7893c366ec1a377")]
[assembly: AssemblyProduct("LandDrakkar")]
[assembly: AssemblyTitle("LandDrakkar")]
[assembly: AssemblyVersion("1.0.0.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
{
	public static class HallClient
	{
		private struct Pending
		{
			public string Id;

			public string Title;

			public int Order;

			public Action<Rect> Draw;
		}

		private static readonly List<Pending> s_pending = new List<Pending>();

		private static Type s_type;

		private static bool s_miss;

		private static MethodInfo s_register;

		private static MethodInfo s_open;

		private static MethodInfo s_close;

		private static MethodInfo s_hosting;

		private static MethodInfo s_yield;

		private static MethodInfo s_hold;

		private static PropertyInfo s_ready;

		private static PropertyInfo s_openProp;

		private static Type HallType
		{
			get
			{
				if (s_type != null || s_miss)
				{
					return s_type;
				}
				s_type = Type.GetType("DFGHub.HallBoard, DFGHub");
				s_miss = s_type == null;
				return s_type;
			}
		}

		public static bool Ready
		{
			get
			{
				if (s_ready == null && HallType != null)
				{
					s_ready = HallType.GetProperty("Ready", BindingFlags.Static | BindingFlags.Public);
				}
				if (s_ready == null)
				{
					return false;
				}
				object value = s_ready.GetValue(null, null);
				bool flag = default(bool);
				int num;
				if (value is bool)
				{
					flag = (bool)value;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
		}

		public static bool IsOpen
		{
			get
			{
				if (s_openProp == null && HallType != null)
				{
					s_openProp = HallType.GetProperty("IsOpen", BindingFlags.Static | BindingFlags.Public);
				}
				if (s_openProp == null)
				{
					return false;
				}
				object value = s_openProp.GetValue(null, null);
				bool flag = default(bool);
				int num;
				if (value is bool)
				{
					flag = (bool)value;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
		}

		public static void Bind(string id, string title, int order, Action<Rect> draw)
		{
			if (string.IsNullOrEmpty(id) || draw == null)
			{
				return;
			}
			for (int num = s_pending.Count - 1; num >= 0; num--)
			{
				if (string.Equals(s_pending[num].Id, id, StringComparison.OrdinalIgnoreCase))
				{
					s_pending.RemoveAt(num);
				}
			}
			s_pending.Add(new Pending
			{
				Id = id,
				Title = title,
				Order = order,
				Draw = draw
			});
			Flush();
		}

		public static void Flush()
		{
			if (s_pending.Count != 0 && Ready)
			{
				for (int i = 0; i < s_pending.Count; i++)
				{
					Pending pending = s_pending[i];
					TryRegister(pending.Id, pending.Title, pending.Order, pending.Draw);
				}
				s_pending.Clear();
			}
		}

		public static bool TryOpen(string tabId)
		{
			if (!Ready)
			{
				return false;
			}
			if (s_open == null)
			{
				s_open = HallType.GetMethod("Open", BindingFlags.Static | BindingFlags.Public);
			}
			if (s_open == null)
			{
				return false;
			}
			try
			{
				object obj = s_open.Invoke(null, new object[1] { tabId });
				bool flag = default(bool);
				int num;
				if (obj is bool)
				{
					flag = (bool)obj;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
			catch (Exception)
			{
				return false;
			}
		}

		public static void Close()
		{
			if (HallType == null)
			{
				return;
			}
			if (s_close == null)
			{
				s_close = HallType.GetMethod("Close", BindingFlags.Static | BindingFlags.Public);
			}
			try
			{
				s_close?.Invoke(null, null);
			}
			catch (Exception)
			{
			}
		}

		public static bool IsHosting(string id)
		{
			if (HallType == null || string.IsNullOrEmpty(id))
			{
				return false;
			}
			if (s_hosting == null)
			{
				s_hosting = HallType.GetMethod("IsHosting", BindingFlags.Static | BindingFlags.Public);
			}
			if (s_hosting == null)
			{
				return false;
			}
			try
			{
				object obj = s_hosting.Invoke(null, new object[1] { id });
				bool flag = default(bool);
				int num;
				if (obj is bool)
				{
					flag = (bool)obj;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
			catch (Exception)
			{
				return false;
			}
		}

		public static void SetYield(bool yieldScreen)
		{
			if (HallType == null)
			{
				return;
			}
			if (s_yield == null)
			{
				s_yield = HallType.GetMethod("SetYield", BindingFlags.Static | BindingFlags.Public);
			}
			try
			{
				s_yield?.Invoke(null, new object[1] { yieldScreen });
			}
			catch (Exception)
			{
			}
		}

		public static void HoldEscape()
		{
			if (HallType == null)
			{
				return;
			}
			if (s_hold == null)
			{
				s_hold = HallType.GetMethod("HoldEscape", BindingFlags.Static | BindingFlags.Public);
			}
			try
			{
				s_hold?.Invoke(null, null);
			}
			catch (Exception)
			{
			}
		}

		private static void TryRegister(string id, string title, int order, Action<Rect> draw)
		{
			if (s_register == null)
			{
				s_register = HallType.GetMethod("Register", BindingFlags.Static | BindingFlags.Public);
			}
			s_register?.Invoke(null, new object[4] { id, title, order, draw });
		}
	}
}
namespace LandDrakkar
{
	public static class DrakkarBoard
	{
		public static DrakkarVehicle Target;

		private const float BoardRange = 50f;

		private static readonly Color ColCard = new Color(0.09f, 0.11f, 0.16f, 0.96f);

		private static readonly Color ColLine = new Color(0.22f, 0.28f, 0.38f, 0.85f);

		private static readonly Color ColGold = new Color(1f, 0.84f, 0.38f, 1f);

		private static readonly Color ColWhite = new Color(0.92f, 0.95f, 0.98f, 1f);

		private static readonly Color ColMuted = new Color(0.6f, 0.66f, 0.75f, 1f);

		private static readonly Color ColCyan = new Color(0.4f, 0.8f, 1f, 1f);

		private static readonly Color ColGreen = new Color(0.38f, 0.88f, 0.44f, 1f);

		private static readonly Color ColRed = new Color(0.97f, 0.45f, 0.42f, 1f);

		private static readonly Color BtnGo = new Color(0.18f, 0.45f, 0.25f, 0.95f);

		private static readonly Color BtnPlain = new Color(0.16f, 0.2f, 0.27f, 0.95f);

		private static readonly Color BtnOff = new Color(0.14f, 0.16f, 0.2f, 0.7f);

		private static readonly Dictionary<string, GUIStyle> s_styles = new Dictionary<string, GUIStyle>();

		private static Texture2D s_white;

		private static Vector2 s_scroll;

		private static string s_note = "";

		public static void Draw(Rect area)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			EnsureTexture();
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				GUI.Label(area, "No viking is standing here.", Style(13, bold: false, (TextAnchor)0, ColMuted, wrap: false));
				return;
			}
			DrakkarVehicle drakkarVehicle = ResolveTarget(localPlayer);
			if ((Object)(object)drakkarVehicle == (Object)null)
			{
				GUI.Label(new Rect(((Rect)(ref area)).x, ((Rect)(ref area)).y, ((Rect)(ref area)).width, 60f), "No Land-Drakkar within " + 50f + " m.\nBuild one from the Hammer's DFG tab, then press E on it.", Style(13, bold: false, (TextAnchor)0, ColMuted, wrap: true));
				return;
			}
			bool num = ((Rect)(ref area)).width >= 760f;
			float num2 = 330f;
			float num3 = 112f;
			float num4 = 34f + (float)DrakkarUpgrades.All.Length * (num3 + 6f);
			float num5 = (num ? Mathf.Max(num2, num4) : (num2 + 10f + num4));
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(0f, 0f, ((Rect)(ref area)).width - 18f, num5);
			s_scroll = GUI.BeginScrollView(area, s_scroll, val);
			Rect r = (num ? new Rect(0f, 0f, ((Rect)(ref val)).width * 0.36f, num2) : new Rect(0f, 0f, ((Rect)(ref val)).width, num2));
			DrawStatus(r, localPlayer, drakkarVehicle);
			DrawUpgrades(num ? new Rect(((Rect)(ref r)).xMax + 10f, 0f, ((Rect)(ref val)).width - ((Rect)(ref r)).width - 10f, num4) : new Rect(0f, ((Rect)(ref r)).yMax + 10f, ((Rect)(ref val)).width, num4), localPlayer, drakkarVehicle, num3);
			GUI.EndScrollView();
		}

		private static DrakkarVehicle ResolveTarget(Player player)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)player).transform.position;
			if (!((Object)(object)Target == (Object)null) && Target.IsValid)
			{
				Vector3 val = ((Component)Target).transform.position - position;
				if (!(((Vector3)(ref val)).sqrMagnitude > 2500f))
				{
					goto IL_0059;
				}
			}
			Target = DrakkarVehicle.Nearest(position, 50f);
			goto IL_0059;
			IL_0059:
			return Target;
		}

		private static void DrawStatus(Rect r, Player player, DrakkarVehicle v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: 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_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			Box(r, ColCard, ColLine);
			float num = ((Rect)(ref r)).x + 12f;
			float num2 = ((Rect)(ref r)).width - 24f;
			float num3 = ((Rect)(ref r)).y + 8f;
			GUI.Label(new Rect(num, num3, num2, 22f), "Dvergr Land-Drakkar", Style(15, bold: true, (TextAnchor)3, ColGold, wrap: false));
			num3 += 24f;
			bool flag = v.IsFollowing();
			GUI.Label(new Rect(num, num3, num2, 20f), flag ? "Following" : "Anchored", Style(12, bold: true, (TextAnchor)3, flag ? ColGreen : ColGold, wrap: false));
			num3 += 24f;
			WearNTear component = ((Component)v).GetComponent<WearNTear>();
			Inventory val = (((Object)(object)v.Cargo != (Object)null) ? v.Cargo.GetInventory() : null);
			Line(num, ref num3, num2, "Hull", ((Object)(object)component != (Object)null) ? ((component.GetHealthPercentage() * 100f).ToString("0") + "%") : "?");
			if (val != null)
			{
				Line(num, ref num3, num2, "Hold", val.NrOfItems() + " / " + val.GetWidth() * val.GetHeight() + " slots, " + val.GetTotalWeight().ToString("0") + " kg");
			}
			Line(num, ref num3, num2, "Distance", Vector3.Distance(((Component)player).transform.position, ((Component)v).transform.position).ToString("0") + " m");
			if (v.GetTier(Track.Defense) > 0)
			{
				int num4 = v.AmmoCount();
				Line(num, ref num3, num2, "Bolts loaded", num4.ToString(), (num4 > 0) ? ColWhite : ColRed);
			}
			num3 += 8f;
			float num5 = (num2 - 8f) * 0.5f;
			if (Button(new Rect(num, num3, num5, 30f), flag ? "Stay here" : "Follow me", BtnGo, ColWhite))
			{
				v.ToggleFollow(player);
			}
			if (Button(new Rect(num + num5 + 8f, num3, num5, 30f), "Open hold", BtnPlain, ColWhite))
			{
				HallClient.Close();
				v.OpenCargo((Humanoid)(object)player);
			}
			num3 += 36f;
			bool flag2 = v.GetTier(Track.Defense) > 0;
			if (Button(new Rect(num, num3, num2, 30f), flag2 ? "Open ammo hold" : "Ammo hold (needs ballista)", flag2 ? BtnPlain : BtnOff, flag2 ? ColWhite : ColMuted) && flag2)
			{
				HallClient.Close();
				v.OpenAmmo((Humanoid)(object)player);
			}
			num3 += 40f;
			Toggle(num, ref num3, num2, v, Track.Lights, "drakkar_lights_on", "Lanterns");
			Toggle(num, ref num3, num2, v, Track.Collector, "drakkar_collector_on", "Collector turret");
			Toggle(num, ref num3, num2, v, Track.Defense, "drakkar_defense_on", "Defense ballista");
			num3 += 4f;
			GUI.Label(new Rect(num, num3, num2, 32f), "Hotkey " + ((object)LandDrakkarPlugin.CommandHotkey.Value/*cast due to .constrained prefix*/).ToString() + " toggles follow. Use bolts on the drakkar to load the ballista.", Style(10, bold: false, (TextAnchor)0, ColMuted, wrap: true));
		}

		private static void Toggle(float x, ref float y, float w, DrakkarVehicle v, Track track, string key, string label)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0097: 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)
			bool flag = v.GetTier(track) > 0;
			bool flag2 = v.GetSwitch(key);
			GUI.Label(new Rect(x, y, w - 90f, 26f), label, Style(12, bold: false, (TextAnchor)3, flag ? ColWhite : ColMuted, wrap: false));
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(x + w - 84f, y, 84f, 24f);
			if (!flag)
			{
				GUI.Label(val, "not built", Style(11, bold: false, (TextAnchor)4, ColMuted, wrap: false));
			}
			else if (Button(val, flag2 ? "On" : "Off", flag2 ? BtnGo : BtnOff, ColWhite))
			{
				v.RequestSwitch(key, !flag2);
			}
			y += 28f;
		}

		private static void DrawUpgrades(Rect r, Player player, DrakkarVehicle v, float rowH)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_00c0: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width * 0.4f, 22f), "Upgrades", Style(14, bold: true, (TextAnchor)3, ColGold, wrap: false));
			GUI.Label(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.3f, ((Rect)(ref r)).y, ((Rect)(ref r)).width * 0.7f, 22f), s_note, Style(11, bold: false, (TextAnchor)5, ColGold, wrap: false));
			float num = ((Rect)(ref r)).y + 30f;
			Track[] all = DrakkarUpgrades.All;
			Rect rect = default(Rect);
			Rect val = default(Rect);
			foreach (Track track in all)
			{
				((Rect)(ref rect))..ctor(((Rect)(ref r)).x, num, ((Rect)(ref r)).width, rowH);
				Box(rect, ColCard, ColLine);
				int tier = v.GetTier(track);
				int num2 = DrakkarUpgrades.MaxTier(track);
				float num3 = ((Rect)(ref rect)).width - 200f;
				GUI.Label(new Rect(((Rect)(ref rect)).x + 10f, ((Rect)(ref rect)).y + 6f, num3, 18f), DrakkarUpgrades.Title(track) + "   tier " + tier + "/" + num2, Style(13, bold: true, (TextAnchor)3, ColGold, wrap: false));
				GUI.Label(new Rect(((Rect)(ref rect)).x + 10f, ((Rect)(ref rect)).y + 25f, num3, 30f), "Now: " + DrakkarUpgrades.Describe(track, tier), Style(11, bold: false, (TextAnchor)0, ColWhite, wrap: true));
				((Rect)(ref val))..ctor(((Rect)(ref rect)).xMax - 184f, ((Rect)(ref rect)).y + 12f, 172f, 30f);
				if (tier >= num2)
				{
					GUI.Label(val, "Fully upgraded", Style(12, bold: true, (TextAnchor)4, ColCyan, wrap: false));
				}
				else
				{
					int tier2 = tier + 1;
					GUI.Label(new Rect(((Rect)(ref rect)).x + 10f, ((Rect)(ref rect)).y + 55f, num3, 30f), "Next: " + DrakkarUpgrades.Describe(track, tier2), Style(11, bold: false, (TextAnchor)0, ColMuted, wrap: true));
					List<Cost> cost = DrakkarUpgrades.CostOf(track, tier2);
					DrawCost(new Rect(((Rect)(ref rect)).x + 10f, ((Rect)(ref rect)).y + 86f, ((Rect)(ref rect)).width - 20f, 18f), player, cost);
					string text = DrakkarUpgrades.CannotAfford(player, cost);
					bool flag = text == null;
					if (Button(val, flag ? ("Upgrade to tier " + tier2) : "Missing materials", flag ? BtnGo : BtnOff, flag ? ColWhite : ColMuted))
					{
						if (flag)
						{
							DrakkarUpgrades.Pay(player, cost);
							v.RequestTier(track, tier2);
							s_note = DrakkarUpgrades.Title(track) + " upgraded to tier " + tier2 + ".";
						}
						else
						{
							s_note = text;
						}
					}
				}
				num += rowH + 6f;
			}
		}

		private static void DrawCost(Rect r, Player player, List<Cost> cost)
		{
			//IL_0081: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref r)).x;
			foreach (Cost item in cost)
			{
				int num2 = DrakkarUpgrades.Carried(player, item.Prefab);
				string text = DrakkarUpgrades.DisplayName(item.Prefab) + " " + num2 + "/" + item.Amount;
				GUIStyle val = Style(11, bold: true, (TextAnchor)3, (num2 >= item.Amount) ? ColGreen : ColRed, wrap: false);
				float num3 = val.CalcSize(new GUIContent(text)).x + 16f;
				GUI.Label(new Rect(num, ((Rect)(ref r)).y, num3, ((Rect)(ref r)).height), text, val);
				num += num3;
			}
		}

		private static void Line(float x, ref float y, float w, string label, string value)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Line(x, ref y, w, label, value, ColWhite);
		}

		private static void Line(float x, ref float y, float w, string label, string value, Color valueColor)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			GUI.Label(new Rect(x, y, w * 0.4f, 18f), label, Style(11, bold: false, (TextAnchor)3, ColMuted, wrap: false));
			GUI.Label(new Rect(x + w * 0.4f, y, w * 0.6f, 18f), value, Style(11, bold: true, (TextAnchor)3, valueColor, wrap: false));
			y += 18f;
		}

		private static void EnsureTexture()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)s_white != (Object)null))
			{
				s_white = new Texture2D(1, 1);
				s_white.SetPixel(0, 0, Color.white);
				s_white.Apply();
			}
		}

		private static void Box(Rect rect, Color background, Color border)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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)
			Color color = GUI.color;
			GUI.color = background;
			GUI.DrawTexture(rect, (Texture)(object)s_white);
			GUI.color = border;
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, 1f), (Texture)(object)s_white);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - 1f, ((Rect)(ref rect)).width, 1f), (Texture)(object)s_white);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)s_white);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).xMax - 1f, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)s_white);
			GUI.color = color;
		}

		private static bool Button(Rect rect, string text, Color background, Color textColor)
		{
			//IL_0015: 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_0020: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			bool flag = ((Rect)(ref rect)).Contains((Event.current != null) ? Event.current.mousePosition : Vector2.zero);
			Box(rect, flag ? (background * 1.15f) : background, flag ? ColGold : ColLine);
			GUI.Label(rect, text, Style(12, bold: true, (TextAnchor)4, textColor, wrap: false));
			return GUI.Button(rect, GUIContent.none, GUIStyle.none);
		}

		private static GUIStyle Style(int size, bool bold, TextAnchor anchor, Color color, bool wrap)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected I4, but got Unknown
			//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_00c5: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			string key = size + ":" + (bold ? 1 : 0) + ":" + (int)anchor + ":" + (wrap ? 1 : 0) + ":" + color.r.ToString("F2") + color.g.ToString("F2") + color.b.ToString("F2");
			if (!s_styles.TryGetValue(key, out var value))
			{
				value = new GUIStyle(GUI.skin.label)
				{
					fontSize = size,
					fontStyle = (FontStyle)(bold ? 1 : 0),
					alignment = anchor,
					clipping = (TextClipping)1,
					wordWrap = wrap
				};
				value.normal.textColor = color;
				value.hover.textColor = color;
				value.active.textColor = color;
				s_styles[key] = value;
			}
			return value;
		}
	}
	public static class DrakkarGlb
	{
		[Serializable]
		private class GLTFRoot
		{
			public GLTFScene[] scenes;

			public GLTFNode[] nodes;

			public GLTFSkin[] skins;

			public GLTFMesh[] meshes;

			public GLTFMaterial[] materials;

			public GLTFAccessor[] accessors;

			public GLTFBufferView[] bufferViews;

			public GLTFTexture[] textures;

			public GLTFImage[] images;
		}

		[Serializable]
		private class GLTFSkin
		{
			public int inverseBindMatrices = -1;

			public int[] joints;
		}

		[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;

			public int JOINTS_0 = -1;

			public int WEIGHTS_0 = -1;
		}

		[Serializable]
		private class GLTFNode
		{
			public string name;

			public int mesh = -1;

			public int skin = -1;

			public float[] translation;

			public float[] rotation;

			public float[] scale;

			public int[] children;
		}

		[Serializable]
		private class GLTFMaterial
		{
			public string name;

			public GLTFPBR pbrMetallicRoughness;
		}

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

			public float? metallicFactor;

			public float? roughnessFactor;

			public GLTFTextureInfo baseColorTexture;
		}

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

		[Serializable]
		private class GLTFImage
		{
			public string mimeType;

			public int bufferView = -1;

			public string name;

			public string uri;
		}

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

		[Serializable]
		private class GLTFAccessor
		{
			public int bufferView;

			public int byteOffset;

			public int componentType;

			public int count;

			public string type;
		}

		[Serializable]
		private class GLTFBufferView
		{
			public int buffer;

			public int byteOffset;

			public int byteLength;

			public int byteStride;
		}

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

		private static readonly Dictionary<string, GameObject> s_cachedPrefabs = new Dictionary<string, GameObject>();

		public static GameObject LoadGlb(string path, Material sourceMaterialTemplate = null)
		{
			if (string.IsNullOrEmpty(path) || !File.Exists(path))
			{
				LandDrakkarPlugin.Log.LogError((object)("DrakkarGlb: Model file not found: " + path));
				return null;
			}
			if (s_cachedPrefabs.TryGetValue(path, out var value) && (Object)(object)value != (Object)null)
			{
				GameObject obj = Object.Instantiate<GameObject>(value);
				obj.SetActive(true);
				return obj;
			}
			try
			{
				byte[] array = File.ReadAllBytes(path);
				if (array.Length < 20 || BitConverter.ToUInt32(array, 0) != 1179937895)
				{
					LandDrakkarPlugin.Log.LogError((object)("DrakkarGlb: File is not a valid GLB: " + path));
					return null;
				}
				int num = 12;
				string text = null;
				byte[] array2 = null;
				while (num < array.Length && num + 8 <= array.Length)
				{
					uint num2 = BitConverter.ToUInt32(array, num);
					uint num3 = BitConverter.ToUInt32(array, num + 4);
					num += 8;
					switch (num3)
					{
					case 1313821514u:
						text = Encoding.UTF8.GetString(array, num, (int)num2);
						break;
					case 5130562u:
						array2 = new byte[num2];
						Buffer.BlockCopy(array, num, array2, 0, (int)num2);
						break;
					}
					num += (int)num2;
					num = (num + 3) & -4;
				}
				if (string.IsNullOrEmpty(text) || array2 == null)
				{
					LandDrakkarPlugin.Log.LogError((object)("DrakkarGlb: Failed to extract JSON or BIN chunk from " + path));
					return null;
				}
				Shader shader = (((Object)(object)sourceMaterialTemplate != (Object)null) ? sourceMaterialTemplate.shader : FindValidShader());
				GameObject val = ParseGLTF(text, array2, shader, Path.GetFileNameWithoutExtension(path));
				if ((Object)(object)val != (Object)null)
				{
					val.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)val);
					s_cachedPrefabs[path] = val;
					GameObject obj2 = Object.Instantiate<GameObject>(val);
					obj2.SetActive(true);
					return obj2;
				}
			}
			catch (Exception ex)
			{
				LandDrakkarPlugin.Log.LogError((object)("DrakkarGlb: Exception loading GLB " + path + ": " + ex));
			}
			return null;
		}

		public static Shader FindValidShader()
		{
			Shader val = Shader.Find("Custom/Creature") ?? Shader.Find("Custom/Piece") ?? Shader.Find("Custom/StaticObject") ?? Shader.Find("Standard");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			try
			{
				Shader[] array = Resources.FindObjectsOfTypeAll<Shader>();
				foreach (Shader val2 in array)
				{
					if (((Object)val2).name == "Custom/Creature" || ((Object)val2).name == "Custom/Piece" || ((Object)val2).name == "Custom/StaticObject" || ((Object)val2).name == "Standard")
					{
						return val2;
					}
				}
			}
			catch
			{
			}
			return Shader.Find("Diffuse") ?? Shader.Find("Unlit/Texture");
		}

		private static GameObject ParseGLTF(string json, byte[] binData, Shader shader, string rootName)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f1: Expected O, but got Unknown
			//IL_0536: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_074c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0796: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			//IL_0559: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0570: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: Unknown result type (might be due to invalid IL or missing references)
			//IL_0587: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a30: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a3e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a43: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(rootName);
			try
			{
				GLTFRoot gLTFRoot = JsonConvert.DeserializeObject<GLTFRoot>(json);
				if (gLTFRoot == null)
				{
					LandDrakkarPlugin.Log.LogError((object)"DrakkarGlb: Failed to parse GLTF JSON");
					return null;
				}
				GLTFBufferView[] bufferViews = gLTFRoot.bufferViews ?? new GLTFBufferView[0];
				GLTFAccessor[] array = gLTFRoot.accessors ?? new GLTFAccessor[0];
				GLTFMesh[] array2 = gLTFRoot.meshes ?? new GLTFMesh[0];
				GLTFMaterial[] array3 = gLTFRoot.materials ?? new GLTFMaterial[0];
				GLTFNode[] array4 = gLTFRoot.nodes ?? new GLTFNode[0];
				GLTFSkin[] array5 = gLTFRoot.skins ?? new GLTFSkin[0];
				GLTFTexture[] array6 = gLTFRoot.textures ?? new GLTFTexture[0];
				GLTFImage[] images = gLTFRoot.images ?? new GLTFImage[0];
				Dictionary<int, Texture2D> texCache = new Dictionary<int, Texture2D>();
				Func<int, Texture2D> func = delegate(int imageIndex)
				{
					//IL_0097: Unknown result type (might be due to invalid IL or missing references)
					//IL_009e: Expected O, but got Unknown
					if (imageIndex < 0 || imageIndex >= images.Length)
					{
						return (Texture2D)null;
					}
					if (texCache.TryGetValue(imageIndex, out var value))
					{
						return value;
					}
					GLTFImage gLTFImage = images[imageIndex];
					if (gLTFImage.bufferView < 0 || gLTFImage.bufferView >= bufferViews.Length)
					{
						return (Texture2D)null;
					}
					GLTFBufferView gLTFBufferView = bufferViews[gLTFImage.bufferView];
					if (gLTFBufferView.byteOffset + gLTFBufferView.byteLength > binData.Length)
					{
						return (Texture2D)null;
					}
					byte[] array21 = new byte[gLTFBufferView.byteLength];
					Buffer.BlockCopy(binData, gLTFBufferView.byteOffset, array21, 0, gLTFBufferView.byteLength);
					Texture2D val11 = new Texture2D(2, 2, (TextureFormat)4, false);
					if (!ImageConversion.LoadImage(val11, array21))
					{
						Object.Destroy((Object)(object)val11);
						return (Texture2D)null;
					}
					((Object)val11).name = gLTFImage.name ?? $"img_{imageIndex}";
					((Texture)val11).wrapMode = (TextureWrapMode)0;
					((Texture)val11).filterMode = (FilterMode)1;
					texCache[imageIndex] = val11;
					return val11;
				};
				Mesh[] array7 = (Mesh[])(object)new Mesh[array2.Length];
				Material[][] array8 = new Material[array2.Length][];
				Vector3[] array9 = (Vector3[])(object)new Vector3[array2.Length];
				for (int num = 0; num < array2.Length; num++)
				{
					GLTFMesh gLTFMesh = array2[num];
					Mesh val2 = new Mesh();
					((Object)val2).name = gLTFMesh.name ?? $"Mesh_{num}";
					if (gLTFMesh.primitives != null && gLTFMesh.primitives.Length != 0)
					{
						List<Vector3> list = new List<Vector3>();
						List<Vector3> list2 = new List<Vector3>();
						List<Vector2> list3 = new List<Vector2>();
						List<Vector4> list4 = new List<Vector4>();
						List<Vector4> list5 = new List<Vector4>();
						List<int[]> list6 = new List<int[]>();
						List<Material> list7 = new List<Material>();
						bool flag = false;
						for (int num2 = 0; num2 < gLTFMesh.primitives.Length; num2++)
						{
							GLTFPrimitive gLTFPrimitive = gLTFMesh.primitives[num2];
							int count = list.Count;
							GLTFAttributes attributes = gLTFPrimitive.attributes;
							Vector3[] array10 = ((attributes != null && attributes.POSITION >= 0 && gLTFPrimitive.attributes.POSITION < array.Length) ? ReadVec3Accessor(array[gLTFPrimitive.attributes.POSITION], bufferViews, binData) : null);
							GLTFAttributes attributes2 = gLTFPrimitive.attributes;
							Vector3[] array11 = ((attributes2 != null && attributes2.NORMAL >= 0 && gLTFPrimitive.attributes.NORMAL < array.Length) ? ReadVec3Accessor(array[gLTFPrimitive.attributes.NORMAL], bufferViews, binData) : null);
							GLTFAttributes attributes3 = gLTFPrimitive.attributes;
							Vector2[] array12 = ((attributes3 != null && attributes3.TEXCOORD_0 >= 0 && gLTFPrimitive.attributes.TEXCOORD_0 < array.Length) ? ReadVec2Accessor(array[gLTFPrimitive.attributes.TEXCOORD_0], bufferViews, binData) : null);
							GLTFAttributes attributes4 = gLTFPrimitive.attributes;
							Vector4[] array13 = ((attributes4 != null && attributes4.JOINTS_0 >= 0 && gLTFPrimitive.attributes.JOINTS_0 < array.Length) ? ReadVec4Accessor(array[gLTFPrimitive.attributes.JOINTS_0], bufferViews, binData) : null);
							GLTFAttributes attributes5 = gLTFPrimitive.attributes;
							Vector4[] array14 = ((attributes5 != null && attributes5.WEIGHTS_0 >= 0 && gLTFPrimitive.attributes.WEIGHTS_0 < array.Length) ? ReadVec4Accessor(array[gLTFPrimitive.attributes.WEIGHTS_0], bufferViews, binData) : null);
							if (array13 != null && array14 != null)
							{
								flag = true;
							}
							if (array10 != null)
							{
								list.AddRange(array10);
								if (array11 != null && array11.Length == array10.Length)
								{
									list2.AddRange(array11);
								}
								else
								{
									for (int num3 = 0; num3 < array10.Length; num3++)
									{
										list2.Add(Vector3.up);
									}
								}
								if (array12 != null && array12.Length == array10.Length)
								{
									list3.AddRange(array12);
								}
								else
								{
									for (int num4 = 0; num4 < array10.Length; num4++)
									{
										list3.Add(Vector2.zero);
									}
								}
								if (array13 != null && array13.Length == array10.Length)
								{
									list4.AddRange(array13);
								}
								if (array14 != null && array14.Length == array10.Length)
								{
									list5.AddRange(array14);
								}
							}
							if (gLTFPrimitive.indices >= 0 && gLTFPrimitive.indices < array.Length)
							{
								int[] array15 = ReadIndicesAccessor(array[gLTFPrimitive.indices], bufferViews, binData);
								if (array15 != null)
								{
									int[] array16 = new int[array15.Length];
									for (int num5 = 0; num5 < array15.Length; num5++)
									{
										array16[num5] = array15[num5] + count;
									}
									list6.Add(array16);
								}
							}
							if (gLTFPrimitive.material >= 0 && gLTFPrimitive.material < array3.Length)
							{
								GLTFMaterial gLTFMaterial = array3[gLTFPrimitive.material];
								Texture2D baseTexture = null;
								int num6 = gLTFMaterial.pbrMetallicRoughness?.baseColorTexture?.index ?? (-1);
								if (num6 >= 0 && num6 < array6.Length)
								{
									baseTexture = func(array6[num6].source);
								}
								list7.Add(CreateMaterial(gLTFMaterial, shader, baseTexture));
							}
							else
							{
								list7.Add(CreateFallbackMaterial(shader));
							}
						}
						if (list.Count > 65535)
						{
							val2.indexFormat = (IndexFormat)1;
						}
						Vector3 val3 = Vector3.zero;
						if (!flag && list.Count > 0)
						{
							Vector3 val4 = list[0];
							Vector3 val5 = list[0];
							for (int num7 = 1; num7 < list.Count; num7++)
							{
								val4 = Vector3.Min(val4, list[num7]);
								val5 = Vector3.Max(val5, list[num7]);
							}
							val3 = (val4 + val5) * 0.5f;
							for (int num8 = 0; num8 < list.Count; num8++)
							{
								List<Vector3> list8 = list;
								int index = num8;
								list8[index] -= val3;
							}
						}
						array9[num] = val3;
						val2.SetVertices(list);
						val2.SetNormals(list2);
						val2.SetUVs(0, list3);
						if (flag && list4.Count == list.Count && list5.Count == list.Count)
						{
							val2.boneWeights = ConvertToBoneWeights(list4.ToArray(), list5.ToArray());
						}
						val2.subMeshCount = list6.Count;
						for (int num9 = 0; num9 < list6.Count; num9++)
						{
							val2.SetTriangles(list6[num9], num9);
						}
						array8[num] = list7.ToArray();
					}
					val2.RecalculateNormals();
					val2.RecalculateBounds();
					array7[num] = val2;
				}
				GameObject[] array17 = (GameObject[])(object)new GameObject[array4.Length];
				for (int num10 = 0; num10 < array4.Length; num10++)
				{
					array17[num10] = new GameObject(array4[num10].name ?? $"Node_{num10}");
				}
				for (int num11 = 0; num11 < array4.Length; num11++)
				{
					GLTFNode gLTFNode = array4[num11];
					GameObject val6 = array17[num11];
					if (gLTFNode.translation != null && gLTFNode.translation.Length == 3)
					{
						val6.transform.localPosition = new Vector3(gLTFNode.translation[0], gLTFNode.translation[1], gLTFNode.translation[2]);
					}
					if (gLTFNode.rotation != null && gLTFNode.rotation.Length == 4)
					{
						val6.transform.localRotation = new Quaternion(gLTFNode.rotation[0], gLTFNode.rotation[1], gLTFNode.rotation[2], gLTFNode.rotation[3]);
					}
					if (gLTFNode.scale != null && gLTFNode.scale.Length == 3)
					{
						val6.transform.localScale = new Vector3(gLTFNode.scale[0], gLTFNode.scale[1], gLTFNode.scale[2]);
					}
				}
				for (int num12 = 0; num12 < array4.Length; num12++)
				{
					GLTFNode gLTFNode2 = array4[num12];
					GameObject val7 = array17[num12];
					if (gLTFNode2.children == null)
					{
						continue;
					}
					int[] children = gLTFNode2.children;
					foreach (int num13 in children)
					{
						if (num13 >= 0 && num13 < array17.Length)
						{
							array17[num13].transform.SetParent(val7.transform, false);
						}
					}
				}
				for (int num14 = 0; num14 < array4.Length; num14++)
				{
					GLTFNode gLTFNode3 = array4[num14];
					GameObject val8 = array17[num14];
					if (gLTFNode3.mesh < 0 || gLTFNode3.mesh >= array7.Length)
					{
						continue;
					}
					Mesh val9 = array7[gLTFNode3.mesh];
					Material[] sharedMaterials = (Material[])(((object)array8[gLTFNode3.mesh]) ?? ((object)new Material[1] { CreateFallbackMaterial(shader) }));
					if (gLTFNode3.skin >= 0 && gLTFNode3.skin < array5.Length && array5[gLTFNode3.skin].joints != null && array5[gLTFNode3.skin].joints.Length != 0 && val9.boneWeights != null && val9.boneWeights.Length != 0)
					{
						GLTFSkin gLTFSkin = array5[gLTFNode3.skin];
						Transform[] array18 = (Transform[])(object)new Transform[gLTFSkin.joints.Length];
						for (int num15 = 0; num15 < gLTFSkin.joints.Length; num15++)
						{
							int num16 = gLTFSkin.joints[num15];
							if (num16 >= 0 && num16 < array17.Length)
							{
								array18[num15] = array17[num16].transform;
							}
						}
						if (gLTFSkin.inverseBindMatrices >= 0 && gLTFSkin.inverseBindMatrices < array.Length)
						{
							Matrix4x4[] array19 = ReadMat4Accessor(array[gLTFSkin.inverseBindMatrices], bufferViews, binData);
							if (array19 != null && array19.Length == gLTFSkin.joints.Length)
							{
								val9.bindposes = array19;
							}
						}
						SkinnedMeshRenderer val10 = val8.AddComponent<SkinnedMeshRenderer>();
						val10.sharedMesh = val9;
						val10.bones = array18;
						if (array18.Length != 0 && (Object)(object)array18[0] != (Object)null)
						{
							val10.rootBone = array18[0];
						}
						((Renderer)val10).sharedMaterials = sharedMaterials;
						val10.updateWhenOffscreen = true;
						val10.quality = (SkinQuality)4;
					}
					else
					{
						if (gLTFNode3.translation == null || gLTFNode3.translation.Length < 3)
						{
							Transform transform = val8.transform;
							transform.localPosition += array9[gLTFNode3.mesh];
						}
						val8.AddComponent<MeshFilter>().sharedMesh = val9;
						((Renderer)val8.AddComponent<MeshRenderer>()).sharedMaterials = sharedMaterials;
					}
				}
				bool flag2 = false;
				GLTFScene[] array20 = gLTFRoot.scenes ?? new GLTFScene[0];
				foreach (GLTFScene gLTFScene in array20)
				{
					if (gLTFScene.nodes == null)
					{
						continue;
					}
					int[] children = gLTFScene.nodes;
					foreach (int num18 in children)
					{
						if (num18 >= 0 && num18 < array17.Length)
						{
							array17[num18].transform.SetParent(val.transform, false);
							flag2 = true;
						}
					}
				}
				if (!flag2)
				{
					for (int num19 = 0; num19 < array17.Length; num19++)
					{
						if ((Object)(object)array17[num19].transform.parent == (Object)null)
						{
							array17[num19].transform.SetParent(val.transform, false);
						}
					}
				}
				return val;
			}
			catch (Exception arg)
			{
				LandDrakkarPlugin.Log.LogError((object)$"DrakkarGlb: Error parsing GLTF: {arg}");
				return null;
			}
		}

		private static Vector3[] ReadVec3Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData)
		{
			//IL_008a: 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)
			if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length)
			{
				return null;
			}
			GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView];
			int num = gLTFBufferView.byteOffset + accessor.byteOffset;
			int count = accessor.count;
			int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 12);
			Vector3[] array = (Vector3[])(object)new Vector3[count];
			for (int i = 0; i < count; i++)
			{
				int num3 = num + i * num2;
				if (num3 + 12 <= binData.Length)
				{
					array[i] = new Vector3(BitConverter.ToSingle(binData, num3), BitConverter.ToSingle(binData, num3 + 4), BitConverter.ToSingle(binData, num3 + 8));
				}
			}
			return array;
		}

		private static Vector2[] ReadVec2Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData)
		{
			//IL_008c: 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)
			if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length)
			{
				return null;
			}
			GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView];
			int num = gLTFBufferView.byteOffset + accessor.byteOffset;
			int count = accessor.count;
			int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 8);
			Vector2[] array = (Vector2[])(object)new Vector2[count];
			for (int i = 0; i < count; i++)
			{
				int num3 = num + i * num2;
				if (num3 + 8 <= binData.Length)
				{
					float num4 = BitConverter.ToSingle(binData, num3);
					float num5 = BitConverter.ToSingle(binData, num3 + 4);
					array[i] = new Vector2(num4, 1f - num5);
				}
			}
			return array;
		}

		private static Vector4[] ReadVec4Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length)
			{
				return null;
			}
			GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView];
			int num = gLTFBufferView.byteOffset + accessor.byteOffset;
			int count = accessor.count;
			Vector4[] array = (Vector4[])(object)new Vector4[count];
			if (accessor.componentType == 5126)
			{
				int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 16);
				for (int i = 0; i < count; i++)
				{
					int num3 = num + i * num2;
					if (num3 + 16 <= binData.Length)
					{
						array[i] = new Vector4(BitConverter.ToSingle(binData, num3), BitConverter.ToSingle(binData, num3 + 4), BitConverter.ToSingle(binData, num3 + 8), BitConverter.ToSingle(binData, num3 + 12));
					}
				}
			}
			else if (accessor.componentType == 5121)
			{
				int num4 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 4);
				for (int j = 0; j < count; j++)
				{
					int num5 = num + j * num4;
					if (num5 + 4 <= binData.Length)
					{
						array[j] = new Vector4((float)(int)binData[num5], (float)(int)binData[num5 + 1], (float)(int)binData[num5 + 2], (float)(int)binData[num5 + 3]);
					}
				}
			}
			else if (accessor.componentType == 5123)
			{
				int num6 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 8);
				for (int k = 0; k < count; k++)
				{
					int num7 = num + k * num6;
					if (num7 + 8 <= binData.Length)
					{
						array[k] = new Vector4((float)(int)BitConverter.ToUInt16(binData, num7), (float)(int)BitConverter.ToUInt16(binData, num7 + 2), (float)(int)BitConverter.ToUInt16(binData, num7 + 4), (float)(int)BitConverter.ToUInt16(binData, num7 + 6));
					}
				}
			}
			return array;
		}

		private static Matrix4x4[] ReadMat4Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData)
		{
			//IL_006a: 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_00b2: 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)
			if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length)
			{
				return null;
			}
			GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView];
			int num = gLTFBufferView.byteOffset + accessor.byteOffset;
			int count = accessor.count;
			int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 64);
			Matrix4x4[] array = (Matrix4x4[])(object)new Matrix4x4[count];
			for (int i = 0; i < count; i++)
			{
				int num3 = num + i * num2;
				if (num3 + 64 > binData.Length)
				{
					continue;
				}
				Matrix4x4 identity = Matrix4x4.identity;
				for (int j = 0; j < 4; j++)
				{
					for (int k = 0; k < 4; k++)
					{
						((Matrix4x4)(ref identity))[k, j] = BitConverter.ToSingle(binData, num3 + (j * 4 + k) * 4);
					}
				}
				array[i] = identity;
			}
			return array;
		}

		private static BoneWeight[] ConvertToBoneWeights(Vector4[] joints, Vector4[] weights)
		{
			//IL_0024: 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_002c: 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_003a: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (joints == null || weights == null)
			{
				return null;
			}
			int num = Mathf.Min(joints.Length, weights.Length);
			BoneWeight[] array = (BoneWeight[])(object)new BoneWeight[num];
			for (int i = 0; i < num; i++)
			{
				Vector4 val = joints[i];
				Vector4 val2 = weights[i];
				((BoneWeight)(ref array[i])).boneIndex0 = Mathf.RoundToInt(val.x);
				((BoneWeight)(ref array[i])).boneIndex1 = Mathf.RoundToInt(val.y);
				((BoneWeight)(ref array[i])).boneIndex2 = Mathf.RoundToInt(val.z);
				((BoneWeight)(ref array[i])).boneIndex3 = Mathf.RoundToInt(val.w);
				((BoneWeight)(ref array[i])).weight0 = val2.x;
				((BoneWeight)(ref array[i])).weight1 = val2.y;
				((BoneWeight)(ref array[i])).weight2 = val2.z;
				((BoneWeight)(ref array[i])).weight3 = val2.w;
			}
			return array;
		}

		private static int[] ReadIndicesAccessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData)
		{
			if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length)
			{
				return null;
			}
			GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView];
			int num = gLTFBufferView.byteOffset + accessor.byteOffset;
			int count = accessor.count;
			int[] array = new int[count];
			if (accessor.componentType == 5123)
			{
				int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 2);
				for (int i = 0; i < count; i++)
				{
					int num3 = num + i * num2;
					if (num3 + 2 <= binData.Length)
					{
						array[i] = BitConverter.ToUInt16(binData, num3);
					}
				}
			}
			else if (accessor.componentType == 5125)
			{
				int num4 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 4);
				for (int j = 0; j < count; j++)
				{
					int num5 = num + j * num4;
					if (num5 + 4 <= binData.Length)
					{
						array[j] = BitConverter.ToInt32(binData, num5);
					}
				}
			}
			else if (accessor.componentType == 5121)
			{
				for (int k = 0; k < count; k++)
				{
					int num6 = num + k;
					if (num6 < binData.Length)
					{
						array[k] = binData[num6];
					}
				}
			}
			return array;
		}

		private static Material CreateMaterial(GLTFMaterial mat, Shader shader, Texture2D baseTexture)
		{
			//IL_0077: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			Material val = CreateBaseMaterial(shader);
			((Object)val).name = mat.name ?? "GLTFMaterial";
			if ((Object)(object)baseTexture != (Object)null)
			{
				val.mainTexture = (Texture)(object)baseTexture;
				if (val.HasProperty("_MainTex"))
				{
					val.SetTexture("_MainTex", (Texture)(object)baseTexture);
				}
				if (val.HasProperty("_BaseMap"))
				{
					val.SetTexture("_BaseMap", (Texture)(object)baseTexture);
				}
				if (val.HasProperty("_Albedo"))
				{
					val.SetTexture("_Albedo", (Texture)(object)baseTexture);
				}
			}
			Color val2 = Color.white;
			if (mat.pbrMetallicRoughness != null)
			{
				GLTFPBR pbrMetallicRoughness = mat.pbrMetallicRoughness;
				if (pbrMetallicRoughness.baseColorFactor != null && pbrMetallicRoughness.baseColorFactor.Length == 4)
				{
					Color white = default(Color);
					((Color)(ref white))..ctor(pbrMetallicRoughness.baseColorFactor[0], pbrMetallicRoughness.baseColorFactor[1], pbrMetallicRoughness.baseColorFactor[2], pbrMetallicRoughness.baseColorFactor[3]);
					if (white.a <= 0.01f || ((Object)(object)baseTexture != (Object)null && white.r <= 0.08f && white.g <= 0.08f && white.b <= 0.08f))
					{
						white = Color.white;
					}
					val2 = white;
				}
				if (pbrMetallicRoughness.metallicFactor.HasValue && val.HasProperty("_Metallic"))
				{
					val.SetFloat("_Metallic", Mathf.Clamp01(pbrMetallicRoughness.metallicFactor.Value));
				}
				if (pbrMetallicRoughness.roughnessFactor.HasValue)
				{
					float num = Mathf.Clamp01(1f - pbrMetallicRoughness.roughnessFactor.Value);
					if (val.HasProperty("_Glossiness"))
					{
						val.SetFloat("_Glossiness", num);
					}
					if (val.HasProperty("_Smoothness"))
					{
						val.SetFloat("_Smoothness", num);
					}
				}
			}
			val.color = val2;
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", val2);
			}
			if (val.HasProperty("_BaseColor"))
			{
				val.SetColor("_BaseColor", val2);
			}
			if (val.HasProperty("_Cull"))
			{
				val.SetInt("_Cull", 0);
			}
			val.renderQueue = 2000;
			return val;
		}

		private static Material CreateFallbackMaterial(Shader shader)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			Material obj = CreateBaseMaterial(shader);
			((Object)obj).name = "Drakkar_FallbackMat";
			obj.color = Color.white;
			return obj;
		}

		private static Material CreateBaseMaterial(Shader shader)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if ((Object)(object)shader == (Object)null)
			{
				shader = FindValidShader();
			}
			return new Material(shader);
		}
	}
	public static class DrakkarHud
	{
		private static readonly Color ColHeaderBg = new Color(0.12f, 0.16f, 0.22f, 1f);

		private static readonly Color ColBorder = new Color(0.74f, 0.58f, 0.28f, 1f);

		private static readonly Color ColCardBg = new Color(0.08f, 0.1f, 0.14f, 0.96f);

		private static readonly Color ColCardBorder = new Color(0.2f, 0.26f, 0.36f, 0.85f);

		private static readonly Color ColBarBg = new Color(0.04f, 0.06f, 0.08f, 0.9f);

		private static readonly Color ColBar = new Color(0.24f, 0.7f, 0.44f, 0.9f);

		private static readonly Color ColBarLow = new Color(0.88f, 0.32f, 0.28f, 0.9f);

		private static readonly Color ColGold = new Color(1f, 0.84f, 0.38f, 1f);

		private static readonly Color ColWhite = new Color(0.92f, 0.95f, 0.98f, 1f);

		private static readonly Color ColDim = new Color(0.65f, 0.72f, 0.82f, 1f);

		private static readonly Color ColGreen = new Color(0.4f, 0.92f, 0.5f, 1f);

		private static readonly Color ColRed = new Color(0.98f, 0.4f, 0.4f, 1f);

		private static readonly List<DrakkarVehicle> s_near = new List<DrakkarVehicle>();

		private static Texture2D s_white;

		private static GUIStyle s_header;

		private static GUIStyle s_title;

		private static GUIStyle s_badge;

		private static GUIStyle s_line;

		private static GUIStyle s_dim;

		private static GUIStyle s_button;

		private static GUIStyle s_name;

		public static void Render()
		{
			//IL_0050: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			if (LandDrakkarPlugin.HudVisible == null || !LandDrakkarPlugin.HudVisible.Value)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || Busy())
			{
				return;
			}
			float num = Mathf.Max(8f, LandDrakkarPlugin.HudRange.Value);
			float num2 = num * num;
			Vector3 position = ((Component)localPlayer).transform.position;
			s_near.Clear();
			for (int i = 0; i < DrakkarVehicle.All.Count; i++)
			{
				DrakkarVehicle drakkarVehicle = DrakkarVehicle.All[i];
				if ((Object)(object)drakkarVehicle != (Object)null && drakkarVehicle.IsValid)
				{
					Vector3 val = ((Component)drakkarVehicle).transform.position - position;
					if (((Vector3)(ref val)).sqrMagnitude <= num2)
					{
						s_near.Add(drakkarVehicle);
					}
				}
			}
			if (s_near.Count != 0)
			{
				Init();
				float num3 = 34f + (float)s_near.Count * 138f + 6f;
				float num4 = Mathf.Clamp01(LandDrakkarPlugin.HudScreenX.Value) * ((float)Screen.width - 340f);
				float num5 = Mathf.Clamp01(LandDrakkarPlugin.HudScreenY.Value) * ((float)Screen.height - num3);
				Rect rect = new Rect(num4, num5, 340f, num3);
				Fill(rect, new Color(0.06f, 0.08f, 0.11f, 0.92f));
				Border(rect, ColBorder, 1.5f);
				Fill(new Rect(num4, num5, 340f, 28f), ColHeaderBg);
				GUI.Label(new Rect(num4 + 8f, num5 + 3f, 324f, 22f), "LAND-DRAKKAR", s_header);
				float num6 = num5 + 34f;
				for (int j = 0; j < s_near.Count; j++)
				{
					DrawCard(new Rect(num4 + 6f, num6, 328f, 132f), s_near[j], localPlayer);
					num6 += 138f;
				}
			}
		}

		public static void RenderNames()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00ce: 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)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_00fb: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			Camera main = Camera.main;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || (Object)(object)main == (Object)null || Minimap.IsOpen() || HallClient.IsOpen)
			{
				return;
			}
			Init();
			float num = ((LandDrakkarPlugin.HudRange != null) ? Mathf.Max(8f, LandDrakkarPlugin.HudRange.Value) : 40f);
			float num2 = num * num;
			Vector3 position = ((Component)localPlayer).transform.position;
			Rect val4 = default(Rect);
			for (int i = 0; i < DrakkarVehicle.All.Count; i++)
			{
				DrakkarVehicle drakkarVehicle = DrakkarVehicle.All[i];
				if ((Object)(object)drakkarVehicle == (Object)null || !drakkarVehicle.IsValid)
				{
					continue;
				}
				Vector3 val = ((Component)drakkarVehicle).transform.position - position;
				if (!(((Vector3)(ref val)).sqrMagnitude > num2))
				{
					Vector3 position2 = ((Component)drakkarVehicle).transform.position;
					Vector3 up = Vector3.up;
					Bounds localBounds = drakkarVehicle.LocalBounds;
					Vector3 val2 = position2 + up * (((Bounds)(ref localBounds)).max.y + 1.2f);
					Vector3 val3 = main.WorldToScreenPoint(val2);
					if (!(val3.z <= 0.1f))
					{
						string text = ((object)LandDrakkarPlugin.CommandHotkey.Value/*cast due to .constrained prefix*/).ToString();
						string text2 = (drakkarVehicle.IsFollowing() ? ("Land-Drakkar  ·  Following  [" + text + "]") : ("Land-Drakkar  ·  Anchored  [" + text + "]"));
						((Rect)(ref val4))..ctor(val3.x - 160f, (float)Screen.height - val3.y - 16f, 320f, 22f);
						Color color = GUI.color;
						GUI.color = new Color(0f, 0f, 0f, 0.9f);
						GUI.Label(new Rect(((Rect)(ref val4)).x + 1f, ((Rect)(ref val4)).y + 1f, ((Rect)(ref val4)).width, ((Rect)(ref val4)).height), text2, s_name);
						GUI.color = Color.white;
						GUI.Label(val4, text2, s_name);
						GUI.color = color;
					}
				}
			}
		}

		private static void DrawCard(Rect r, DrakkarVehicle v, Player player)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: 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)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			Fill(r, ColCardBg);
			Border(r, ColCardBorder, 1f);
			bool flag = v.IsFollowing();
			GUI.Label(new Rect(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 4f, ((Rect)(ref r)).width * 0.55f, 18f), "Dvergr Land-Drakkar", s_title);
			s_badge.normal.textColor = (flag ? ColGreen : ColGold);
			GUI.Label(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.5f, ((Rect)(ref r)).y + 4f, ((Rect)(ref r)).width * 0.5f - 8f, 18f), flag ? "FOLLOWING" : "ANCHORED", s_badge);
			float healthFraction = v.HealthFraction;
			float healthMax = v.HealthMax;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 26f, ((Rect)(ref r)).width - 16f, 14f);
			Fill(val, ColBarBg);
			if (healthFraction > 0f)
			{
				Fill(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width * healthFraction, ((Rect)(ref val)).height), (healthFraction < 0.3f) ? ColBarLow : ColBar);
			}
			Border(val, ColCardBorder, 1f);
			GUI.Label(val, $"Hull  {healthFraction * healthMax:0} / {healthMax:0}", s_dim);
			string text = ((object)LandDrakkarPlugin.CommandHotkey.Value/*cast due to .constrained prefix*/).ToString();
			string text2 = (flag ? $"Order: follow   {v.CurrentSpeed:0.0} m/s    [{text}] stay" : ("Order: stay    [" + text + "] follow"));
			GUI.Label(new Rect(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 44f, ((Rect)(ref r)).width - 16f, 16f), text2, s_line);
			GUI.Label(new Rect(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 60f, ((Rect)(ref r)).width - 16f, 16f), TrackLine("Collector", v.GetTier(Track.Collector), v.CollectorActivity), s_line);
			GUI.Label(new Rect(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 76f, ((Rect)(ref r)).width - 16f, 16f), TrackLine("Ballista", v.GetTier(Track.Defense), v.DefenseActivity), s_line);
			if (GUI.Button(new Rect(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 98f, ((Rect)(ref r)).width - 16f, 26f), (flag ? "Command: Stay  [" : "Command: Follow  [") + text + "]", s_button))
			{
				v.ToggleFollow(player);
			}
		}

		private static string TrackLine(string name, int tier, string activity)
		{
			if (tier <= 0)
			{
				return name + ": not built";
			}
			if (!string.IsNullOrEmpty(activity))
			{
				return name + ": " + activity;
			}
			return name + ": tier " + tier;
		}

		private static bool Busy()
		{
			if ((!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible() && !TextInput.IsVisible() && !Minimap.IsOpen())
			{
				return HallClient.IsOpen;
			}
			return true;
		}

		private static void Init()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0020: 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_0053: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00e2: 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)
			if ((Object)(object)s_white == (Object)null)
			{
				s_white = new Texture2D(1, 1);
				s_white.SetPixel(0, 0, Color.white);
				s_white.Apply();
			}
			if (s_header == null)
			{
				s_header = Label(13, bold: true, (TextAnchor)3, ColGold);
				s_title = Label(12, bold: true, (TextAnchor)3, ColWhite);
				s_badge = Label(11, bold: true, (TextAnchor)5, ColGreen);
				s_line = Label(11, bold: false, (TextAnchor)3, ColWhite);
				s_dim = Label(10, bold: true, (TextAnchor)4, ColWhite);
				s_name = Label(14, bold: true, (TextAnchor)4, ColGold);
				s_button = new GUIStyle(GUI.skin.button)
				{
					fontSize = 12,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				s_button.normal.textColor = ColGold;
				s_button.hover.textColor = Color.white;
			}
		}

		private static GUIStyle Label(int size, bool bold, TextAnchor anchor, Color color)
		{
			//IL_000a: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_003e: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = size,
				fontStyle = (FontStyle)(bold ? 1 : 0),
				alignment = anchor,
				clipping = (TextClipping)1
			};
			val.normal.textColor = color;
			return val;
		}

		private static void Fill(Rect rect, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Color color2 = GUI.color;
			GUI.color = color;
			GUI.DrawTexture(rect, (Texture)(object)s_white);
			GUI.color = color2;
		}

		private static void Border(Rect rect, Color color, float t)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			Fill(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, t), color);
			Fill(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - t, ((Rect)(ref rect)).width, t), color);
			Fill(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, t, ((Rect)(ref rect)).height), color);
			Fill(new Rect(((Rect)(ref rect)).xMax - t, ((Rect)(ref rect)).y, t, ((Rect)(ref rect)).height), color);
		}
	}
	public class DrakkarLights
	{
		private static readonly Color Warm = new Color(1f, 0.66f, 0.32f);

		private static readonly Color Head = new Color(1f, 0.93f, 0.8f);

		private static readonly Color Eitr = new Color(0.62f, 0.85f, 1f);

		private readonly DrakkarVehicle m_vehicle;

		private GameObject m_root;

		private readonly List<Light> m_lights = new List<Light>();

		private readonly List<float> m_baseIntensity = new List<float>();

		private readonly List<Renderer> m_orbs = new List<Renderer>();

		private Material m_material;

		public DrakkarLights(DrakkarVehicle vehicle)
		{
			m_vehicle = vehicle;
		}

		public void Destroy()
		{
			if ((Object)(object)m_root != (Object)null)
			{
				Object.Destroy((Object)(object)m_root);
			}
			m_root = null;
			m_lights.Clear();
			m_baseIntensity.Clear();
			m_orbs.Clear();
		}

		public void Rebuild(int tier)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//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_0065: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_00aa: 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_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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			Destroy();
			if (tier > 0)
			{
				m_root = new GameObject("LandDrakkar_Lights");
				m_root.transform.SetParent(((Component)m_vehicle).transform, false);
				Bounds localBounds = m_vehicle.LocalBounds;
				bool flag = tier >= 3;
				float num = (flag ? 2f : 1f);
				Color color = (flag ? Eitr : Warm);
				float num2 = ((Bounds)(ref localBounds)).max.y + 0.15f;
				float num3 = ((Bounds)(ref localBounds)).extents.x * 0.85f;
				float num4 = ((Bounds)(ref localBounds)).extents.z * 0.8f;
				AddLamp(new Vector3(((Bounds)(ref localBounds)).center.x - num3, num2, ((Bounds)(ref localBounds)).center.z + num4), Quaternion.identity, spot: false, color, 9f * num, 1.3f);
				AddLamp(new Vector3(((Bounds)(ref localBounds)).center.x + num3, num2, ((Bounds)(ref localBounds)).center.z + num4), Quaternion.identity, spot: false, color, 9f * num, 1.3f);
				AddLamp(new Vector3(((Bounds)(ref localBounds)).center.x - num3, num2, ((Bounds)(ref localBounds)).center.z - num4), Quaternion.identity, spot: false, color, 9f * num, 1.3f);
				AddLamp(new Vector3(((Bounds)(ref localBounds)).center.x + num3, num2, ((Bounds)(ref localBounds)).center.z - num4), Quaternion.identity, spot: false, color, 9f * num, 1.3f);
				if (tier >= 2)
				{
					float num5 = ((Bounds)(ref localBounds)).min.y + ((Bounds)(ref localBounds)).size.y * 0.55f;
					float num6 = ((Bounds)(ref localBounds)).max.z + 0.2f;
					Quaternion localRot = Quaternion.Euler(14f, 0f, 0f);
					Color color2 = (flag ? Eitr : Head);
					AddLamp(new Vector3(((Bounds)(ref localBounds)).center.x - ((Bounds)(ref localBounds)).extents.x * 0.5f, num5, num6), localRot, spot: true, color2, 24f * num, 2.4f);
					AddLamp(new Vector3(((Bounds)(ref localBounds)).center.x + ((Bounds)(ref localBounds)).extents.x * 0.5f, num5, num6), localRot, spot: true, color2, 24f * num, 2.4f);
				}
			}
		}

		public void Tick(bool on)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Invalid comparison between Unknown and I4
			if ((Object)(object)m_root == (Object)null)
			{
				return;
			}
			float num = 0.92f + Mathf.PerlinNoise(Time.time * 4.5f, 2.3f) * 0.14f;
			for (int i = 0; i < m_lights.Count; i++)
			{
				Light val = m_lights[i];
				if (!((Object)(object)val == (Object)null))
				{
					((Behaviour)val).enabled = on;
					val.intensity = m_baseIntensity[i] * (((int)val.type == 2) ? num : 1f);
				}
			}
			for (int j = 0; j < m_orbs.Count; j++)
			{
				if ((Object)(object)m_orbs[j] != (Object)null)
				{
					m_orbs[j].enabled = on;
				}
			}
		}

		private void AddLamp(Vector3 localPos, Quaternion localRot, bool spot, Color color, float range, float intensity)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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)
			GameObject val = new GameObject(spot ? "Headlamp" : "Lantern");
			val.transform.SetParent(m_root.transform, false);
			val.transform.localPosition = localPos;
			val.transform.localRotation = localRot;
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)obj).name = "Glass";
			obj.transform.SetParent(val.transform, false);
			obj.transform.localScale = Vector3.one * (spot ? 0.22f : 0.28f);
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			Renderer component = obj.GetComponent<Renderer>();
			Material val2 = LampMaterial(color);
			if ((Object)(object)component != (Object)null && (Object)(object)val2 != (Object)null)
			{
				component.sharedMaterial = val2;
				m_orbs.Add(component);
			}
			else if ((Object)(object)component != (Object)null)
			{
				component.enabled = false;
			}
			Light val3 = val.AddComponent<Light>();
			val3.type = (LightType)((!spot) ? 2 : 0);
			val3.color = color;
			val3.range = range;
			val3.intensity = intensity;
			val3.spotAngle = 55f;
			val3.shadows = (LightShadows)0;
			val3.renderMode = (LightRenderMode)1;
			m_lights.Add(val3);
			m_baseIntensity.Add(intensity);
		}

		private Material LampMaterial(Color color)
		{
			//IL_000f: 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_00c4: Expected O, but got Unknown
			//IL_00d4: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_material != (Object)null)
			{
				return Tinted(color);
			}
			Shader val = null;
			Renderer[] componentsInChildren = ((Component)m_vehicle).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				Material val3 = (((Object)(object)val2 != (Object)null) ? val2.sharedMaterial : null);
				if ((Object)(object)val3 != (Object)null && (Object)(object)val3.shader != (Object)null && !((Object)val3.shader).name.StartsWith("Hidden/"))
				{
					val = val3.shader;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = DrakkarGlb.FindValidShader();
			}
			if ((Object)(object)val == (Object)null || ((Object)val).name == "Hidden/InternalErrorShader")
			{
				return null;
			}
			Texture2D val4 = new Texture2D(4, 4, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[16];
			for (int j = 0; j < array.Length; j++)
			{
				array[j] = Color.white;
			}
			val4.SetPixels(array);
			val4.Apply(false, true);
			m_material = new Material(val)
			{
				name = "LandDrakkar_Lamp",
				mainTexture = (Texture)(object)val4
			};
			m_material.shaderKeywords = Array.Empty<string>();
			if (m_material.HasProperty("_Value"))
			{
				m_material.SetFloat("_Value", 1.6f);
			}
			return Tinted(color);
		}

		private Material Tinted(Color color)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(m_material)
			{
				color = color
			};
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", color);
			}
			return val;
		}
	}
	public static class DrakkarPiece
	{
		public const string PrefabName = "DFG_LandDrakkar";

		public const string ModelName = "LandDrakkar_Model";

		private const string BaseSourcePrefab = "piece_chest_wood";

		private const string DisplayName = "Dvergr Land-Drakkar";

		private const string Description = "A dwarven land-longship that follows you and hauls cargo. Upgrade its hold, lanterns, a collector turret and a defense ballista. E opens the upgrade board, Shift+E opens the hold.";

		private static bool s_prefabRegistered;

		private static bool s_pieceManagerAdded;

		private static bool s_pieceTableRegistered;

		private static bool s_pieceRegistered;

		private static bool s_warned;

		private static float s_timer;

		private static MethodInfo s_addKnownPiece;

		private static MethodInfo s_updateAvailable;

		public static void Initialize()
		{
			PrefabManager.OnVanillaPrefabsAvailable += OnVanillaPrefabsAvailable;
		}

		public static void Shutdown()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= OnVanillaPrefabsAvailable;
			s_prefabRegistered = false;
			s_pieceManagerAdded = false;
			s_pieceTableRegistered = false;
			s_pieceRegistered = false;
		}

		public static void Update()
		{
			TryRegisterContent();
			EnsureKnown();
		}

		private static void OnVanillaPrefabsAvailable()
		{
			s_timer = 0f;
			TryRegisterPrefab();
		}

		private static void TryRegisterPrefab()
		{
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			if (s_prefabRegistered)
			{
				return;
			}
			try
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab("piece_chest_wood");
				if ((Object)(object)prefab == (Object)null && (Object)(object)ZNetScene.instance != (Object)null)
				{
					prefab = ZNetScene.instance.GetPrefab("piece_chest_wood");
				}
				if ((Object)(object)prefab == (Object)null)
				{
					if (!s_warned)
					{
						LandDrakkarPlugin.Log.LogWarning((object)"Land-Drakkar: piece_chest_wood is not loaded yet.");
						s_warned = true;
					}
					return;
				}
				bool activeSelf = prefab.activeSelf;
				if (activeSelf)
				{
					prefab.SetActive(false);
				}
				GameObject val = PrefabManager.Instance.CreateClonedPrefab("DFG_LandDrakkar", prefab);
				if (activeSelf)
				{
					prefab.SetActive(true);
				}
				if ((Object)(object)val == (Object)null)
				{
					LandDrakkarPlugin.Log.LogError((object)"Land-Drakkar: failed to clone piece_chest_wood");
					return;
				}
				val.SetActive(true);
				Piece component = val.GetComponent<Piece>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_name = "Dvergr Land-Drakkar";
					component.m_description = "A dwarven land-longship that follows you and hauls cargo. Upgrade its hold, lanterns, a collector turret and a defense ballista. E opens the upgrade board, Shift+E opens the hold.";
					component.m_canBeRemoved = true;
					component.m_groundPiece = false;
					component.m_clipGround = false;
					component.m_groundOnly = false;
					component.m_waterPiece = false;
					component.m_noInWater = false;
					component.m_craftingStation = null;
				}
				Container obj = val.GetComponent<Container>() ?? val.AddComponent<Container>();
				Vector2i val2 = DrakkarUpgrades.StorageSizes[0];
				obj.m_name = "Land-Drakkar Hold";
				obj.m_width = val2.x;
				obj.m_height = val2.y;
				obj.m_autoDestroyEmpty = false;
				obj.m_checkGuardStone = true;
				obj.m_open = null;
				obj.m_closed = null;
				ConfigureWear(val.GetComponent<WearNTear>() ?? val.AddComponent<WearNTear>());
				Rigidbody obj2 = val.GetComponent<Rigidbody>() ?? val.AddComponent<Rigidbody>();
				obj2.mass = 900f;
				obj2.interpolation = (RigidbodyInterpolation)1;
				obj2.isKinematic = true;
				obj2.useGravity = false;
				HideVanillaVisuals(val);
				string text = LandDrakkarPlugin.PluginFile("landdrakkar.glb");
				GameObject val3 = DrakkarGlb.LoadGlb(text);
				if ((Object)(object)val3 != (Object)null)
				{
					((Object)val3).name = "LandDrakkar_Model";
					val3.transform.SetParent(val.transform, false);
					val3.SetActive(true);
					int layer = val.layer;
					Transform[] componentsInChildren = val3.GetComponentsInChildren<Transform>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						((Component)componentsInChildren[i]).gameObject.layer = layer;
					}
					DrakkarVehicle.ApplyModelTransform(val.transform, val3.transform);
				}
				else
				{
					LandDrakkarPlugin.Log.LogError((object)("Land-Drakkar: could not load " + text));
				}
				if ((Object)(object)val.GetComponent<DrakkarVehicle>() == (Object)null)
				{
					val.AddComponent<DrakkarVehicle>();
				}
				PrefabManager.Instance.AddPrefab(val);
				s_prefabRegistered = true;
				LandDrakkarPlugin.Log.LogInfo((object)"Land-Drakkar: registered prefab DFG_LandDrakkar");
			}
			catch (Exception ex)
			{
				LandDrakkarPlugin.Log.LogError((object)("Land-Drakkar: prefab registration failed: " + ex));
			}
		}

		internal static void ConfigureWear(WearNTear wnt)
		{
			if (!((Object)(object)wnt == (Object)null))
			{
				wnt.m_noSupportWear = true;
				wnt.m_noRoofWear = true;
				wnt.m_staticPosition = false;
				wnt.m_supports = false;
				wnt.m_health = Mathf.Max(100f, LandDrakkarPlugin.HullHealth.Value);
				wnt.m_new = null;
				wnt.m_worn = null;
				wnt.m_broken = null;
				wnt.m_wet = null;
				wnt.m_snow = null;
				wnt.m_snowWorn = null;
				wnt.m_snowBroken = null;
			}
		}

		private static void TryRegisterContent()
		{
			//IL_0092: 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_009f: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected I4, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			if (s_pieceRegistered)
			{
				return;
			}
			s_timer -= Time.deltaTime;
			if (s_timer > 0f)
			{
				return;
			}
			s_timer = 1f;
			TryRegisterPrefab();
			ZNetScene instance = ZNetScene.instance;
			if (!s_prefabRegistered || (Object)(object)instance == (Object)null || instance.m_prefabs == null || instance.m_prefabs.Count == 0 || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab("DFG_LandDrakkar");
			if ((Object)(object)prefab == (Object)null)
			{
				return;
			}
			try
			{
				PieceCategory val = PieceManager.Instance.AddPieceCategory("DFG");
				if (!s_pieceManagerAdded)
				{
					PieceConfig val2 = new PieceConfig
					{
						Name = "Dvergr Land-Drakkar",
						Description = "A dwarven land-longship that follows you and hauls cargo. Upgrade its hold, lanterns, a collector turret and a defense ballista. E opens the upgrade board, Shift+E opens the hold.",
						PieceTable = "Hammer",
						Category = "DFG",
						Enabled = true
					};
					PieceManager.Instance.AddPiece(new CustomPiece(prefab, false, val2));
					s_pieceManagerAdded = true;
				}
				if (!s_pieceTableRegistered)
				{
					PieceManager.Instance.RegisterPieceInPieceTable(prefab, "Hammer", "DFG");
					s_pieceTableRegistered = true;
				}
				Piece component = prefab.GetComponent<Piece>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_name = "Dvergr Land-Drakkar";
					component.m_description = "A dwarven land-longship that follows you and hauls cargo. Upgrade its hold, lanterns, a collector turret and a defense ballista. E opens the upgrade board, Shift+E opens the hold.";
					component.m_category = val;
					component.m_craftingStation = null;
					component.m_canBeRemoved = true;
					component.m_resources = BuildRequirements();
					Sprite val3 = LoadIcon();
					if ((Object)(object)val3 != (Object)null)
					{
						component.m_icon = val3;
					}
				}
				ConfigureWear(prefab.GetComponent<WearNTear>());
				s_pieceRegistered = true;
				LandDrakkarPlugin.Log.LogInfo((object)("Land-Drakkar: added to the Hammer in category DFG (id " + (int)val + ")."));
				RefreshCategories();
				EnsureKnown();
			}
			catch (Exception ex)
			{
				LandDrakkarPlugin.Log.LogError((object)("Land-Drakkar: piece registration failed: " + ex));
			}
		}

		private static Requirement[] BuildRequirements()
		{
			//IL_005c: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to inval