Decompiled source of TruckEnergyInShop v1.0.0

TruckEnergyInShop.dll

Decompiled 36 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TruckEnergyInShop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TruckEnergyInShop")]
[assembly: AssemblyTitle("TruckEnergyInShop")]
[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 TruckEnergyInShop
{
	internal static class ChargeBar
	{
		private const string BarName = "Charge";

		private const string HiddenName = "Charge (TruckEnergyInShop)";

		private static Transform _hidden;

		internal static void Install(Harmony harmony)
		{
			//IL_003e: 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_0060: Expected O, but got Unknown
			//IL_0060: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(Game.StationType, "Start", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				Plugin.Log.LogWarning((object)"ChargingStation.Start not found (game update?) - the mod does nothing.");
				return;
			}
			try
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(ChargeBar), "StartPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ChargeBar), "StartFinalizer", (Type[])null), (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not patch ChargingStation.Start: " + ex.Message));
				return;
			}
			if (!Game.CanCountPurchases)
			{
				return;
			}
			MethodInfo methodInfo2 = ((Game.ItemAttributesType != null) ? AccessTools.Method(Game.ItemAttributesType, "OnDestroy", (Type[])null, (Type[])null) : null);
			if (methodInfo2 == null)
			{
				Plugin.Log.LogWarning((object)"ItemAttributes.OnDestroy not found (game update?) - crystals bought as non-host are not counted.");
				return;
			}
			try
			{
				harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(ChargeBar), "ItemDestroyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("Could not patch ItemAttributes.OnDestroy: " + ex2.Message));
			}
		}

		private static void StartPrefix(MonoBehaviour __instance)
		{
			_hidden = null;
			try
			{
				if (!((Object)(object)__instance == (Object)null) && Game.InShop())
				{
					Transform val = ((Component)__instance).transform.Find("Charge");
					if ((Object)(object)val == (Object)null)
					{
						Plugin.Log.LogWarning((object)"Charge bar not found (game update?).");
						return;
					}
					((Object)val).name = "Charge (TruckEnergyInShop)";
					_hidden = val;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Keeping the charge bar failed: " + ex.Message));
			}
		}

		private static Exception StartFinalizer(MonoBehaviour __instance, Exception __exception)
		{
			Transform hidden = _hidden;
			_hidden = null;
			try
			{
				if ((Object)(object)hidden != (Object)null)
				{
					((Object)hidden).name = "Charge";
					if (__exception == null && (Object)(object)__instance != (Object)null)
					{
						ShopChargeBar.Attach(__instance, hidden);
					}
				}
				else if (__exception == null && (Object)(object)__instance != (Object)null && !Game.InShop())
				{
					LevelChargeMarks.Attach(__instance);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Showing the charge bar failed: " + ex.Message));
			}
			return __exception;
		}

		private static void ItemDestroyPrefix(MonoBehaviour __instance)
		{
			ShopChargeBar current = ShopChargeBar.Current;
			if ((Object)(object)current == (Object)null || !current.CountsPurchases)
			{
				return;
			}
			try
			{
				if (Game.IsPowerCrystal((Object)(object)__instance))
				{
					current.CrystalBought();
				}
			}
			catch
			{
			}
		}
	}
	internal class ShopChargeBar : MonoBehaviour
	{
		internal static ShopChargeBar Current;

		private const int PerCrystal = 17;

		private const float ExtractWindow = 3f;

		private Transform _bar;

		private Vector3 _maxScale;

		private int _segments;

		private int _energyPerCrystal;

		private int _maxCrystals;

		private AnimationCurve _curve;

		private float _scale;

		private float _target;

		private float _curveTime;

		private int _shown;

		private int _stat;

		private int _owned;

		private int _bonusCharge;

		private int _bonusCrystals;

		private bool _host;

		private CrystalMarks _marks;

		private MarkStyle _usedStyle;

		private int _usedSize = -1;

		private int _usedTextSize = -1;

		private string _shownLabel = "-";

		private NewCrystalBar _fresh;

		private readonly List<MonoBehaviour> _extractionPoints = new List<MonoBehaviour>();

		private float _nextSearch;

		private float _lastExtracting = -100f;

		private bool _extractionSeen;

		private float _entryFill;

		internal bool CountsPurchases
		{
			get
			{
				if (!_host)
				{
					return Time.time - _lastExtracting <= 3f;
				}
				return false;
			}
		}

		private bool HasLimit
		{
			get
			{
				if (_owned >= 0 && _energyPerCrystal > 0)
				{
					return _maxCrystals > 0;
				}
				return false;
			}
		}

		internal static void Attach(MonoBehaviour station, Transform bar)
		{
			ShopChargeBar shopChargeBar = ((Component)station).gameObject.GetComponent<ShopChargeBar>();
			if ((Object)(object)shopChargeBar == (Object)null)
			{
				shopChargeBar = ((Component)station).gameObject.AddComponent<ShopChargeBar>();
			}
			shopChargeBar.Setup(station, bar);
		}

		private void Setup(MonoBehaviour station, Transform bar)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			_bar = bar;
			_maxScale = bar.localScale;
			_segments = ReadInt(Game.StationSegments, station);
			_energyPerCrystal = ReadInt(Game.StationEnergyPerCrystal, station);
			_maxCrystals = ReadInt(Game.StationMaxCrystals, station);
			try
			{
				ref AnimationCurve curve = ref _curve;
				object? obj = Game.StationCurve?.GetValue(station);
				curve = (AnimationCurve)((obj is AnimationCurve) ? obj : null);
			}
			catch
			{
				_curve = null;
			}
			try
			{
				Game.StationBar?.SetValue(station, bar);
				Game.StationBarMaxScale?.SetValue(station, _maxScale);
			}
			catch
			{
			}
			_host = Game.IsHost();
			_stat = Game.RunCharge();
			_owned = Game.PowerCrystals();
			_bonusCharge = 0;
			_bonusCrystals = 0;
			_shown = Value();
			if (_marks == null)
			{
				_marks = CrystalMarks.Create(((Component)station).transform, bar, _segments, Boundaries());
			}
			if (_fresh == null)
			{
				_fresh = NewCrystalBar.Create(bar);
			}
			_scale = (_target = Fill(_shown));
			_entryFill = _target;
			Apply();
			Current = this;
			Plugin.Log.LogInfo((object)$"Truck energy in the shop: {_shown} % ({_owned} crystals)");
		}

		private static int ReadInt(FieldInfo field, object obj)
		{
			try
			{
				return (field != null && field.GetValue(obj) is int num) ? num : 0;
			}
			catch
			{
				return 0;
			}
		}

		private void Update()
		{
			if ((Object)(object)_bar == (Object)null)
			{
				return;
			}
			_host = Game.IsHost();
			int num = Game.RunCharge();
			int num2 = Game.PowerCrystals();
			if (num != _stat || num2 != _owned)
			{
				_stat = num;
				_owned = num2;
				_bonusCharge = 0;
				_bonusCrystals = 0;
			}
			WatchExtraction();
			int num3 = Value();
			if (num3 != _shown)
			{
				_shown = num3;
				float num4 = Fill(num3);
				if (!Mathf.Approximately(num4, _target))
				{
					_target = num4;
					_curveTime = 0f;
				}
			}
			if (!Mathf.Approximately(_scale, _target))
			{
				Animate();
			}
			if (!_extractionSeen)
			{
				_entryFill = _target;
			}
			Apply();
			UpdateMarks();
		}

		private void LateUpdate()
		{
			try
			{
				_marks?.UpdateView();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Crystal marks failed: " + ex.Message));
				_marks?.Destroy();
				_marks = null;
			}
		}

		private void UpdateMarks()
		{
			if (_marks == null)
			{
				return;
			}
			try
			{
				if (Plugin.Style.Value != _usedStyle || Plugin.Size.Value != _usedSize)
				{
					_usedStyle = Plugin.Style.Value;
					_usedSize = Plugin.Size.Value;
					_marks.Build(_usedStyle, _usedSize);
				}
				string text = (Plugin.ShowCount.Value ? Label() : null);
				if (text != _shownLabel)
				{
					_shownLabel = text;
					_marks.SetLabel(text);
					_usedTextSize = -1;
				}
				if (Plugin.TextSize.Value != _usedTextSize)
				{
					_usedTextSize = Plugin.TextSize.Value;
					_marks.SetTextSize(_usedTextSize);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Crystal marks failed: " + ex.Message));
				_marks.Destroy();
				_marks = null;
			}
		}

		internal void CrystalBought()
		{
			_bonusCharge += 17;
			_bonusCrystals++;
			Plugin.Log.LogInfo((object)$"Power Crystal bought: truck energy in the next level {Value()} %");
		}

		private int Limit(int crystals)
		{
			return Mathf.RoundToInt((float)(crystals * _energyPerCrystal / _maxCrystals) * (float)_energyPerCrystal);
		}

		private int Value(int extra = 0)
		{
			int num = Mathf.Max(_stat, 0) + _bonusCharge + extra * 17;
			if (HasLimit)
			{
				num = Mathf.Min(num, Limit(_owned + _bonusCrystals + extra));
			}
			return Mathf.Clamp(num, 0, 100);
		}

		private int CrystalsFor(int energy)
		{
			if (!HasLimit)
			{
				return -1;
			}
			for (int i = 0; i <= 100; i++)
			{
				if (Limit(i) >= energy)
				{
					return i;
				}
			}
			return -1;
		}

		private string Label()
		{
			int num = CrystalsFor(Value());
			int num2 = CrystalsFor(100);
			if (num < 0 || num2 <= 0)
			{
				return null;
			}
			if (num >= num2)
			{
				return $"<color=#FF8C00>{num2}/{num2} crystals</color>";
			}
			return $"{num}/{num2} <color=#C8CDDC>crystals</color>";
		}

		private List<float> Boundaries()
		{
			List<float> list = new List<float>();
			if (!HasLimit)
			{
				return list;
			}
			for (int i = 1; i <= 100; i++)
			{
				int num = Limit(i);
				if (num >= 100)
				{
					break;
				}
				float num2 = Fill(num);
				if (!(num2 <= 0f) && !(num2 >= 1f) && (list.Count <= 0 || !Mathf.Approximately(list[list.Count - 1], num2)))
				{
					list.Add(num2);
				}
			}
			return list;
		}

		private float Fill(int value)
		{
			float num = (float)value / 100f;
			if (_segments > 0)
			{
				num = (float)Mathf.RoundToInt(num * (float)_segments) / (float)_segments;
			}
			return Mathf.Clamp01(num);
		}

		private void Animate()
		{
			_curveTime += Time.deltaTime;
			float num = ((_curve != null) ? _curve.Evaluate(_curveTime) : (_curveTime * 2f));
			if (_curveTime >= 2f)
			{
				num = 1f;
			}
			_scale = Mathf.Lerp(_scale, _target, Mathf.Clamp01(num));
			if (Mathf.Abs(_scale - _target) < 0.001f)
			{
				_scale = _target;
			}
		}

		private void Apply()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			float num = _scale;
			if (_fresh != null)
			{
				num = _fresh.Show(_entryFill, _scale, Plugin.ColorOf(Plugin.NewColor.Value));
			}
			if ((Object)(object)_bar != (Object)null)
			{
				_bar.localScale = new Vector3(num * _maxScale.x, _maxScale.y, _maxScale.z);
			}
		}

		private void WatchExtraction()
		{
			if (!Game.CanCountPurchases || Game.ExtractionPointType == null)
			{
				return;
			}
			if (_extractionPoints.Count == 0 && Time.time >= _nextSearch)
			{
				_nextSearch = Time.time + 1f;
				try
				{
					Object[] array = Object.FindObjectsByType(Game.ExtractionPointType, (FindObjectsSortMode)0);
					foreach (Object obj in array)
					{
						MonoBehaviour val = (MonoBehaviour)(object)((obj is MonoBehaviour) ? obj : null);
						if (val != null && Game.IsShopExtractionPoint((Object)(object)val))
						{
							_extractionPoints.Add(val);
						}
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Finding the shop extraction point failed: " + ex.Message));
					_nextSearch = Time.time + 10f;
				}
			}
			foreach (MonoBehaviour extractionPoint in _extractionPoints)
			{
				if ((Object)(object)extractionPoint != (Object)null && Game.IsExtracting((Object)(object)extractionPoint))
				{
					_lastExtracting = Time.time;
					_extractionSeen = true;
					break;
				}
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)Current == (Object)(object)this)
			{
				Current = null;
			}
			_marks?.Destroy();
			_marks = null;
			_fresh?.Destroy();
			_fresh = null;
		}
	}
	internal static class Game
	{
		private const BindingFlags AllInst = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private const BindingFlags AllStatic = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private const string ChargeStat = "chargingStationChargeTotal";

		private const string CrystalItem = "Item Power Crystal";

		internal static Type StationType;

		internal static Type ExtractionPointType;

		internal static Type ItemAttributesType;

		internal static FieldInfo StationBar;

		internal static FieldInfo StationBarMaxScale;

		internal static FieldInfo StationSegments;

		internal static FieldInfo StationCurve;

		internal static FieldInfo StationEnergyPerCrystal;

		internal static FieldInfo StationMaxCrystals;

		internal static FieldInfo StationChargeTotal;

		private static Func<string, int> _itemsPurchased;

		private static FieldInfo _epState;

		private static FieldInfo _epIsShop;

		private static FieldInfo _itemField;

		private static FieldInfo _itemTypeField;

		internal static bool CanCountPurchases;

		private static FieldInfo _statsInstance;

		private static FieldInfo _runStats;

		private static Func<bool> _runIsShop;

		private static Func<bool> _isHost;

		internal static bool Init()
		{
			StationType = AccessTools.TypeByName("ChargingStation");
			ExtractionPointType = AccessTools.TypeByName("ExtractionPoint");
			ItemAttributesType = AccessTools.TypeByName("ItemAttributes");
			Type type = AccessTools.TypeByName("SemiFunc");
			Type type2 = AccessTools.TypeByName("StatsManager");
			Type type3 = AccessTools.TypeByName("Item");
			if (StationType == null || type == null || type2 == null)
			{
				Plugin.Log.LogWarning((object)"ChargingStation / SemiFunc / StatsManager not found (game update?).");
				return false;
			}
			StationBar = StationType.GetField("chargeBar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			StationBarMaxScale = StationType.GetField("chargeBarMaxScale", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			StationSegments = StationType.GetField("chargeSegments", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			StationCurve = StationType.GetField("chargeCurve", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_statsInstance = type2.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			_runStats = type2.GetField("runStats", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_runIsShop = StaticBool(type, "RunIsShop");
			_isHost = StaticBool(type, "IsMasterClientOrSingleplayer");
			if (_statsInstance == null || _runStats == null || _runIsShop == null || _isHost == null)
			{
				Plugin.Log.LogWarning((object)"StatsManager.runStats / SemiFunc.RunIsShop / SemiFunc.IsMasterClientOrSingleplayer not found (game update?).");
				return false;
			}
			if (StationSegments == null || StationCurve == null)
			{
				Plugin.Log.LogWarning((object)"ChargingStation.chargeSegments / chargeCurve not found (game update?) - the bar is shown without steps and animation.");
			}
			StationEnergyPerCrystal = StationType.GetField("energyPerCrystal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			StationMaxCrystals = StationType.GetField("maxCrystals", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			StationChargeTotal = StationType.GetField("chargeTotal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (StationChargeTotal == null)
			{
				Plugin.Log.LogWarning((object)"ChargingStation.chargeTotal not found (game update?) - nothing is shown outside the shop.");
			}
			MethodInfo methodInfo = AccessTools.Method(type, "StatGetItemsPurchased", new Type[1] { typeof(string) }, (Type[])null);
			if (methodInfo != null && methodInfo.IsStatic && methodInfo.ReturnType == typeof(int))
			{
				try
				{
					_itemsPurchased = (Func<string, int>)Delegate.CreateDelegate(typeof(Func<string, int>), methodInfo);
				}
				catch
				{
					_itemsPurchased = null;
				}
			}
			if (StationEnergyPerCrystal == null || StationMaxCrystals == null || _itemsPurchased == null)
			{
				Plugin.Log.LogWarning((object)"Crystal limit not found (game update?) - the energy is shown without the crystal limit.");
			}
			_epState = ExtractionPointType?.GetField("currentState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_epIsShop = ExtractionPointType?.GetField("isShop", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_itemField = ItemAttributesType?.GetField("item", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_itemTypeField = type3?.GetField("itemType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			CanCountPurchases = _epState != null && _epIsShop != null && _itemField != null && _itemTypeField != null;
			if (!CanCountPurchases)
			{
				Plugin.Log.LogWarning((object)"ExtractionPoint / ItemAttributes fields not found (game update?) - crystals bought as non-host are not counted.");
			}
			return true;
		}

		private static Func<bool> StaticBool(Type type, string name)
		{
			MethodInfo methodInfo = AccessTools.Method(type, name, Type.EmptyTypes, (Type[])null);
			if (methodInfo == null || !methodInfo.IsStatic || methodInfo.ReturnType != typeof(bool))
			{
				return null;
			}
			try
			{
				return (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), methodInfo);
			}
			catch
			{
				return null;
			}
		}

		internal static bool InShop()
		{
			try
			{
				return _runIsShop();
			}
			catch
			{
				return false;
			}
		}

		internal static bool IsHost()
		{
			try
			{
				return _isHost();
			}
			catch
			{
				return true;
			}
		}

		internal static int RunCharge()
		{
			try
			{
				object value = _statsInstance.GetValue(null);
				if (value != null && _runStats.GetValue(value) is Dictionary<string, int> dictionary && dictionary.TryGetValue("chargingStationChargeTotal", out var value2))
				{
					return value2;
				}
			}
			catch
			{
			}
			return -1;
		}

		internal static int PowerCrystals()
		{
			if (_itemsPurchased == null)
			{
				return -1;
			}
			try
			{
				return _itemsPurchased("Item Power Crystal");
			}
			catch
			{
				return -1;
			}
		}

		internal static bool IsShopExtractionPoint(Object ep)
		{
			try
			{
				object value = _epIsShop.GetValue(ep);
				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;
			}
			catch
			{
				return false;
			}
		}

		internal static bool IsExtracting(Object ep)
		{
			try
			{
				return _epState.GetValue(ep)?.ToString() == "Extracting";
			}
			catch
			{
				return false;
			}
		}

		internal static bool IsPowerCrystal(Object itemAttributes)
		{
			try
			{
				object? value = _itemField.GetValue(itemAttributes);
				Object val = (Object)((value is Object) ? value : null);
				return val != (Object)null && _itemTypeField.GetValue(val)?.ToString() == "power_crystal";
			}
			catch
			{
				return false;
			}
		}
	}
	internal class LevelChargeMarks : MonoBehaviour
	{
		private MonoBehaviour _station;

		private Transform _bar;

		private Vector3 _maxScale;

		private int _segments;

		private int _energyPerCrystal;

		private int _maxCrystals;

		private CrystalMarks _marks;

		private bool _failed;

		private bool HasLimit
		{
			get
			{
				if (_energyPerCrystal > 0)
				{
					return _maxCrystals > 0;
				}
				return false;
			}
		}

		internal static void Attach(MonoBehaviour station)
		{
			LevelChargeMarks levelChargeMarks = ((Component)station).gameObject.GetComponent<LevelChargeMarks>();
			if ((Object)(object)levelChargeMarks == (Object)null)
			{
				levelChargeMarks = ((Component)station).gameObject.AddComponent<LevelChargeMarks>();
			}
			levelChargeMarks._station = station;
		}

		private void Update()
		{
			if (_failed || (Object)(object)_station == (Object)null)
			{
				return;
			}
			if (!Plugin.ShowOutside.Value)
			{
				_marks?.SetVisible(visible: false);
				return;
			}
			try
			{
				if (_marks != null || Make())
				{
					_marks.SetVisible(visible: true);
					int num = ReadInt(Game.StationChargeTotal, -1);
					_marks.ApplyConfig((Plugin.ShowCount.Value && num >= 0) ? Label(num) : null);
				}
			}
			catch (Exception ex)
			{
				Fail("Crystal marks outside the shop failed: " + ex.Message);
			}
		}

		private void LateUpdate()
		{
			if (_failed || _marks == null || !Plugin.ShowOutside.Value)
			{
				return;
			}
			try
			{
				_marks.UpdateView();
			}
			catch (Exception ex)
			{
				Fail("Crystal marks outside the shop failed: " + ex.Message);
			}
		}

		private bool Make()
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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)
			ref Transform bar = ref _bar;
			object? obj = Game.StationBar?.GetValue(_station);
			bar = (Transform)((obj is Transform) ? obj : null);
			if ((Object)(object)_bar == (Object)null || Game.StationChargeTotal == null)
			{
				Fail("Charge bar not found (game update?) - nothing is shown outside the shop.");
				return false;
			}
			_maxScale = ((Game.StationBarMaxScale?.GetValue(_station) is Vector3 val && ((Vector3)(ref val)).sqrMagnitude > 0f) ? val : _bar.localScale);
			_segments = ReadInt(Game.StationSegments, 0);
			_energyPerCrystal = ReadInt(Game.StationEnergyPerCrystal, 0);
			_maxCrystals = ReadInt(Game.StationMaxCrystals, 0);
			Vector3 localScale = _bar.localScale;
			_bar.localScale = _maxScale;
			try
			{
				_marks = CrystalMarks.Create(((Component)_station).transform, _bar, _segments, Borders());
			}
			finally
			{
				_bar.localScale = localScale;
			}
			if (_marks == null)
			{
				_failed = true;
				return false;
			}
			Plugin.Log.LogInfo((object)"Crystal marks shown outside the shop.");
			return true;
		}

		private void Fail(string message)
		{
			_failed = true;
			Plugin.Log.LogWarning((object)message);
			_marks?.Destroy();
			_marks = null;
		}

		private int ReadInt(FieldInfo field, int fallback)
		{
			try
			{
				return (field != null && field.GetValue(_station) is int num) ? num : fallback;
			}
			catch
			{
				return fallback;
			}
		}

		private int Limit(int crystals)
		{
			return Mathf.RoundToInt((float)(crystals * _energyPerCrystal / _maxCrystals) * (float)_energyPerCrystal);
		}

		private float Fill(int value)
		{
			float num = (float)value / 100f;
			if (_segments > 0)
			{
				num = (float)Mathf.RoundToInt(num * (float)_segments) / (float)_segments;
			}
			return Mathf.Clamp01(num);
		}

		private int CrystalsFor(int energy)
		{
			if (!HasLimit)
			{
				return -1;
			}
			for (int i = 0; i <= 100; i++)
			{
				if (Limit(i) >= energy)
				{
					return i;
				}
			}
			return -1;
		}

		private List<float> Borders()
		{
			List<float> list = new List<float>();
			if (!HasLimit)
			{
				return list;
			}
			for (int i = 1; i <= 100; i++)
			{
				int num = Limit(i);
				if (num >= 100)
				{
					break;
				}
				float num2 = Fill(num);
				if (!(num2 <= 0f) && !(num2 >= 1f) && (list.Count <= 0 || !Mathf.Approximately(list[list.Count - 1], num2)))
				{
					list.Add(num2);
				}
			}
			return list;
		}

		private string Label(int energy)
		{
			int num = CrystalsFor(Mathf.Clamp(energy, 0, 100));
			int num2 = CrystalsFor(100);
			if (num < 0 || num2 <= 0)
			{
				return null;
			}
			if (num >= num2)
			{
				return $"<color=#FF8C00>{num2}/{num2} crystals</color>";
			}
			return $"{num}/{num2} <color=#C8CDDC>crystals</color>";
		}

		private void OnDestroy()
		{
			_marks?.Destroy();
			_marks = null;
		}
	}
	internal class CrystalMarks
	{
		private const float LineWidth = 0.228f;

		private const float LineHeight = 1.62f;

		private const float ArrowWidth = 1.08f;

		private const float ArrowHeight = 0.84f;

		private const float ArrowTip = 0.9f;

		private const float TextHeight = 1.35f;

		private const float TextGap = 0.35f;

		private static readonly Color Orange = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)140, (byte)0, byte.MaxValue));

		private static readonly RaycastHit[] Hits = (RaycastHit[])(object)new RaycastHit[16];

		private static Mesh _quad;

		private static Mesh _triangle;

		private static Material _material;

		private readonly Transform _station;

		private readonly Transform _root;

		private readonly float _length;

		private readonly float _height;

		private readonly float _segment;

		private readonly List<float> _borders;

		private readonly List<GameObject> _marks = new List<GameObject>();

		private readonly Vector3 _basePos;

		private readonly Vector3 _baseScale;

		private readonly Vector3 _dir;

		private readonly Vector3 _forward;

		private float _offset;

		private bool _measured;

		private MarkStyle _style = MarkStyle.Both;

		private int _markSize = 100;

		private int _textSize = 100;

		private TextMeshPro _text;

		private float _textRawHeight;

		private bool _textFailed;

		private bool _flipped;

		private MarkStyle _cfgStyle;

		private int _cfgSize = -1;

		private int _cfgTextSize = -1;

		private string _cfgLabel = "-";

		private float MarkScale => (float)Mathf.Clamp(_markSize, 50, 200) / 100f;

		private bool HasLines
		{
			get
			{
				if (_style != MarkStyle.Lines)
				{
					return _style == MarkStyle.Both;
				}
				return true;
			}
		}

		private bool HasArrows
		{
			get
			{
				if (_style != MarkStyle.Arrows)
				{
					return _style == MarkStyle.Both;
				}
				return true;
			}
		}

		private CrystalMarks(Transform station, Transform root, float length, float height, float depth, float segment, List<float> borders)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0088: 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_0094: 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)
			_station = station;
			_root = root;
			_length = length;
			_height = height;
			_segment = segment;
			_borders = borders;
			_basePos = root.position;
			_baseScale = root.localScale;
			_dir = root.right;
			_forward = root.forward;
			_offset = depth / 2f + Mathf.Clamp(0.6f * height, 0.02f, 0.06f);
		}

		internal static CrystalMarks Create(Transform station, Transform bar, int segments, List<float> borders)
		{
			//IL_0055: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: 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_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: 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_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00ae: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(float.MaxValue, float.MaxValue, float.MaxValue);
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(float.MinValue, float.MinValue, float.MinValue);
				bool flag = false;
				Renderer[] componentsInChildren = ((Component)bar).GetComponentsInChildren<Renderer>(true);
				Vector3 val4 = default(Vector3);
				foreach (Renderer val3 in componentsInChildren)
				{
					if (!((Object)(object)val3 == (Object)null))
					{
						Bounds localBounds = val3.localBounds;
						for (int j = 0; j < 8; j++)
						{
							((Vector3)(ref val4))..ctor(((j & 1) == 0) ? ((Bounds)(ref localBounds)).min.x : ((Bounds)(ref localBounds)).max.x, ((j & 2) == 0) ? ((Bounds)(ref localBounds)).min.y : ((Bounds)(ref localBounds)).max.y, ((j & 4) == 0) ? ((Bounds)(ref localBounds)).min.z : ((Bounds)(ref localBounds)).max.z);
							Vector3 val5 = bar.InverseTransformPoint(((Component)val3).transform.TransformPoint(val4));
							val = Vector3.Min(val, val5);
							val2 = Vector3.Max(val2, val5);
							flag = true;
						}
					}
				}
				if (!flag)
				{
					Plugin.Log.LogWarning((object)"Charge bar has no renderer (game update?) - no crystal marks.");
					return null;
				}
				float num = ((Mathf.Abs(val2.x) >= Mathf.Abs(val.x)) ? val2.x : val.x);
				float num2 = (val.y + val2.y) / 2f;
				float num3 = (val.z + val2.z) / 2f;
				Vector3 val6 = bar.TransformPoint(new Vector3(0f, num2, num3));
				Vector3 val7 = bar.TransformPoint(new Vector3(num, num2, num3));
				float num4 = Vector3.Distance(val6, val7);
				if (num4 < 0.001f)
				{
					Plugin.Log.LogWarning((object)"Charge bar size not found (game update?) - no crystal marks.");
					return null;
				}
				Vector3 val8 = (val7 - val6) / num4;
				Vector3 val9 = Vector3.up - val8 * Vector3.Dot(Vector3.up, val8);
				if (((Vector3)(ref val9)).sqrMagnitude < 0.0001f)
				{
					val9 = bar.up;
				}
				((Vector3)(ref val9)).Normalize();
				Vector3 val10 = bar.TransformVector(new Vector3(0f, val2.y - val.y, 0f));
				Vector3 val11 = bar.TransformVector(new Vector3(0f, 0f, val2.z - val.z));
				bool num5 = Mathf.Abs(Vector3.Dot(((Vector3)(ref val10)).normalized, val9)) >= Mathf.Abs(Vector3.Dot(((Vector3)(ref val11)).normalized, val9));
				float num6 = (num5 ? ((Vector3)(ref val10)).magnitude : ((Vector3)(ref val11)).magnitude);
				float depth = (num5 ? ((Vector3)(ref val11)).magnitude : ((Vector3)(ref val10)).magnitude);
				if (num6 < 0.0001f)
				{
					num6 = num4 / 16f;
				}
				Transform transform = new GameObject("TruckEnergyInShop Marks")
				{
					layer = ((Component)bar).gameObject.layer
				}.transform;
				transform.SetParent(station, false);
				transform.SetPositionAndRotation(val6, Quaternion.LookRotation(Vector3.Cross(val8, val9), val9));
				Vector3 lossyScale = station.lossyScale;
				transform.localScale = new Vector3(Inverse(lossyScale.x), Inverse(lossyScale.y), Inverse(lossyScale.z));
				float segment = num4 / (float)((segments > 0) ? segments : 40);
				return new CrystalMarks(station, transform, num4, num6, depth, segment, borders);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Crystal marks could not be made: " + ex.Message));
				return null;
			}
		}

		private static float Inverse(float v)
		{
			if (!(Mathf.Abs(v) > 0.0001f))
			{
				return 1f;
			}
			return 1f / v;
		}

		internal void Build(MarkStyle style, int markSize)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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)
			_style = style;
			_markSize = markSize;
			foreach (GameObject mark in _marks)
			{
				if ((Object)(object)mark != (Object)null)
				{
					Object.Destroy((Object)(object)mark);
				}
			}
			_marks.Clear();
			Material material = GetMaterial();
			if ((Object)(object)material != (Object)null && (Object)(object)_root != (Object)null)
			{
				float markScale = MarkScale;
				foreach (float border in _borders)
				{
					float num = border * _length;
					if (HasLines)
					{
						Add(Quad(), material, new Vector3(num, 0f, 0f), new Vector3(0.228f * _segment * markScale, 1.62f * _height * markScale, 1f));
					}
					if (HasArrows)
					{
						float num2 = 1.08f * _segment * markScale;
						float num3 = 0.84f * _segment * markScale;
						float num4 = 0.9f * _height + num3 / 2f;
						Add(Triangle(), material, new Vector3(num, num4, 0f), new Vector3(num2, num3, 1f));
						Add(Triangle(), material, new Vector3(num, 0f - num4, 0f), new Vector3(num2, 0f - num3, 1f));
					}
				}
			}
			PlaceText();
		}

		private void Add(Mesh mesh, Material material, Vector3 position, Vector3 scale)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Mark")
			{
				layer = ((Component)_root).gameObject.layer
			};
			val.transform.SetParent(_root, false);
			val.transform.localPosition = position;
			val.transform.localScale = scale;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			NoShadows((Renderer)(object)obj);
			_marks.Add(val);
		}

		private static void NoShadows(Renderer r)
		{
			r.shadowCastingMode = (ShadowCastingMode)0;
			r.receiveShadows = false;
			r.lightProbeUsage = (LightProbeUsage)0;
			r.reflectionProbeUsage = (ReflectionProbeUsage)0;
		}

		private static Material GetMaterial()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			if ((Object)(object)_material != (Object)null)
			{
				return _material;
			}
			Shader val = Shader.Find("UI/Default");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Sprites/Default");
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"No shader for the crystal marks found (game update?).");
				return null;
			}
			_material = new Material(val)
			{
				name = "TruckEnergyInShop Marks",
				hideFlags = (HideFlags)61,
				color = Orange,
				renderQueue = 3100
			};
			NormalDepth(_material);
			return _material;
		}

		private static void NormalDepth(Material m)
		{
			if ((Object)(object)m != (Object)null)
			{
				m.SetFloat("unity_GUIZTestMode", 4f);
			}
		}

		private static Mesh Quad()
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_quad != (Object)null)
			{
				return _quad;
			}
			_quad = NewMesh("TruckEnergyInShop Line", (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.5f, -0.5f, 0f),
				new Vector3(-0.5f, 0.5f, 0f),
				new Vector3(0.5f, 0.5f, 0f),
				new Vector3(0.5f, -0.5f, 0f)
			}, new int[6] { 0, 1, 2, 0, 2, 3 });
			return _quad;
		}

		private static Mesh Triangle()
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if ((Object)(object)_triangle != (Object)null)
			{
				return _triangle;
			}
			_triangle = NewMesh("TruckEnergyInShop Arrow", (Vector3[])(object)new Vector3[3]
			{
				new Vector3(-0.5f, 0.5f, 0f),
				new Vector3(0.5f, 0.5f, 0f),
				new Vector3(0f, -0.5f, 0f)
			}, new int[3] { 0, 1, 2 });
			return _triangle;
		}

		private static Mesh NewMesh(string name, Vector3[] vertices, int[] triangles)
		{
			//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_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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_008b: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			Color32[] array = (Color32[])(object)new Color32[vertices.Length];
			Vector2[] array2 = (Vector2[])(object)new Vector2[vertices.Length];
			for (int i = 0; i < vertices.Length; i++)
			{
				array[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
				array2[i] = new Vector2(vertices[i].x + 0.5f, vertices[i].y + 0.5f);
			}
			Mesh val = new Mesh
			{
				name = name,
				hideFlags = (HideFlags)61,
				vertices = vertices,
				uv = array2,
				colors32 = array,
				triangles = triangles
			};
			val.RecalculateBounds();
			return val;
		}

		internal void SetLabel(string label)
		{
			if (label == null)
			{
				if ((Object)(object)_text != (Object)null)
				{
					((Component)_text).gameObject.SetActive(false);
				}
			}
			else if (EnsureText())
			{
				((Component)_text).gameObject.SetActive(true);
				((TMP_Text)_text).text = label;
			}
		}

		internal void SetTextSize(int textSize)
		{
			_textSize = textSize;
			PlaceText();
		}

		private bool EnsureText()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00ca: 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_0110: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_text != (Object)null)
			{
				return true;
			}
			if (_textFailed || (Object)(object)_root == (Object)null)
			{
				return false;
			}
			_textFailed = true;
			try
			{
				TMP_FontAsset val = FindFont();
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)"No TextMeshPro font found - the crystal count is not shown.");
					return false;
				}
				Plugin.Log.LogInfo((object)("Crystal count font: " + ((Object)val).name));
				GameObject val2 = new GameObject("TruckEnergyInShop Count")
				{
					layer = ((Component)_root).gameObject.layer
				};
				TextMeshPro val3 = val2.AddComponent<TextMeshPro>();
				val2.transform.SetParent(_root, false);
				((TMP_Text)val3).font = val;
				((TMP_Text)val3).fontSize = 10f;
				((TMP_Text)val3).enableAutoSizing = false;
				((TMP_Text)val3).richText = true;
				((Graphic)val3).color = Color.white;
				((TMP_Text)val3).overflowMode = (TextOverflowModes)0;
				((TMP_Text)val3).alignment = (TextAlignmentOptions)1026;
				((TMP_Text)val3).rectTransform.pivot = new Vector2(0.5f, 0f);
				((TMP_Text)val3).rectTransform.sizeDelta = new Vector2(200f, 40f);
				NormalDepth(((TMP_Text)val3).fontMaterial);
				MeshRenderer component = val2.GetComponent<MeshRenderer>();
				if ((Object)(object)component != (Object)null)
				{
					NoShadows((Renderer)(object)component);
				}
				((TMP_Text)val3).text = "10/10 crystals";
				((TMP_Text)val3).ForceMeshUpdate(false, false);
				Bounds textBounds = ((TMP_Text)val3).textBounds;
				_textRawHeight = ((Bounds)(ref textBounds)).size.y;
				if (_textRawHeight < 0.0001f)
				{
					Object.Destroy((Object)(object)val2);
					Plugin.Log.LogWarning((object)"Crystal count text has no size - it is not shown.");
					return false;
				}
				_text = val3;
				_textFailed = false;
				PlaceText();
				SetFlipped(_flipped);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Crystal count could not be made: " + ex.Message));
				return false;
			}
		}

		private void PlaceText()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_text == (Object)null))
			{
				float num = 1.35f * _height * ((float)Mathf.Clamp(_textSize, 50, 200) / 100f) / _textRawHeight;
				_text.transform.localScale = new Vector3(num, num, num);
				float num2 = (HasArrows ? (0.9f * _height + 0.84f * _segment * MarkScale) : (0.9f * _height));
				_text.transform.localPosition = new Vector3(_length / 2f, num2 + 0.35f * _height, 0f);
			}
		}

		private static TMP_FontAsset FindFont()
		{
			try
			{
				Dictionary<TMP_FontAsset, int> dictionary = new Dictionary<TMP_FontAsset, int>();
				TextMeshPro[] array = Object.FindObjectsByType<TextMeshPro>((FindObjectsInactive)1, (FindObjectsSortMode)0);
				foreach (TextMeshPro val in array)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)((TMP_Text)val).font == (Object)null) && !((Object)val).name.StartsWith("TruckEnergyInShop"))
					{
						dictionary.TryGetValue(((TMP_Text)val).font, out var value);
						dictionary[((TMP_Text)val).font] = value + 1;
					}
				}
				TMP_FontAsset val2 = null;
				int num = 0;
				foreach (KeyValuePair<TMP_FontAsset, int> item in dictionary)
				{
					bool num2 = item.Value > num;
					bool flag = item.Value == num && (Object)(object)val2 != (Object)null && string.CompareOrdinal(((Object)item.Key).name, ((Object)val2).name) < 0;
					if (num2 || flag)
					{
						val2 = item.Key;
						num = item.Value;
					}
				}
				if ((Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
			catch
			{
			}
			try
			{
				TMP_FontAsset defaultFontAsset = TMP_Settings.defaultFontAsset;
				if ((Object)(object)defaultFontAsset != (Object)null)
				{
					return defaultFontAsset;
				}
			}
			catch
			{
			}
			try
			{
				TMP_FontAsset[] array2 = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				if (array2 != null && array2.Length != 0)
				{
					return array2[0];
				}
			}
			catch
			{
			}
			return null;
		}

		private void SetFlipped(bool flipped)
		{
			//IL_0039: 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)
			_flipped = flipped;
			if ((Object)(object)_text != (Object)null)
			{
				_text.transform.localRotation = (flipped ? Quaternion.Euler(0f, 180f, 0f) : Quaternion.identity);
			}
		}

		internal void UpdateView()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00f2: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root == (Object)null)
			{
				return;
			}
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				_root.position = _basePos;
				_root.localScale = _baseScale;
				return;
			}
			Vector3 position = ((Component)main).transform.position;
			Vector3 val = _basePos + _dir * (_length / 2f);
			bool flag = Vector3.Dot(position - val, _forward) > 0f;
			if (flag != _flipped)
			{
				SetFlipped(flag);
			}
			if (!_measured)
			{
				MeasureGrill(flag ? _forward : (-_forward));
			}
			float num = Vector3.Distance(position, val);
			float num2 = ((num > 2f * _offset) ? ((num - _offset) / num) : 0.5f);
			_root.position = position + (_basePos - position) * num2;
			_root.localScale = _baseScale * num2;
		}

		private void MeasureGrill(Vector3 front)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0064: 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)
			_measured = true;
			float num = -1f;
			foreach (float item in new List<float>(_borders) { 0.5f })
			{
				int num2 = Physics.RaycastNonAlloc(_basePos + _dir * (item * _length) + front * 0.25f, -front, Hits, 0.25f, -1, (QueryTriggerInteraction)1);
				float num3 = float.MaxValue;
				Collider val = null;
				for (int i = 0; i < num2; i++)
				{
					Collider collider = ((RaycastHit)(ref Hits[i])).collider;
					if (!((Object)(object)collider == (Object)null) && !((Object)(object)collider.attachedRigidbody != (Object)null) && ((Component)collider).transform.IsChildOf(_station) && ((RaycastHit)(ref Hits[i])).distance < num3)
					{
						num3 = ((RaycastHit)(ref Hits[i])).distance;
						val = collider;
					}
				}
				if (val is MeshCollider)
				{
					num = Mathf.Max(num, 0.25f - num3);
				}
			}
			if (num > 0f && num < 0.1f)
			{
				_offset = num + 0.01f;
				Plugin.Log.LogInfo((object)$"Crystal marks: grill is {num * 100f:0.0} cm in front of the bar.");
			}
		}

		internal void SetVisible(bool visible)
		{
			if ((Object)(object)_root != (Object)null && ((Component)_root).gameObject.activeSelf != visible)
			{
				((Component)_root).gameObject.SetActive(visible);
			}
		}

		internal void ApplyConfig(string label)
		{
			if (Plugin.Style.Value != _cfgStyle || Plugin.Size.Value != _cfgSize)
			{
				_cfgStyle = Plugin.Style.Value;
				_cfgSize = Plugin.Size.Value;
				Build(_cfgStyle, _cfgSize);
			}
			if (label != _cfgLabel)
			{
				_cfgLabel = label;
				SetLabel(label);
				_cfgTextSize = -1;
			}
			if (Plugin.TextSize.Value != _cfgTextSize)
			{
				_cfgTextSize = Plugin.TextSize.Value;
				SetTextSize(_cfgTextSize);
			}
		}

		internal void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_root).gameObject);
			}
		}
	}
	internal class NewCrystalBar
	{
		private static readonly string[] ColorNames = new string[4] { "_Color", "_BaseColor", "_MainColor", "_TintColor" };

		private static readonly string[] TextureNames = new string[2] { "_MainTex", "_BaseMap" };

		private const string Emission = "_EmissionColor";

		private readonly Transform _bar;

		private readonly Vector3 _pos;

		private readonly Vector3 _maxScale;

		private readonly Quaternion _rot;

		private readonly float _far;

		private GameObject _copy;

		private readonly List<Material> _materials = new List<Material>();

		private readonly Dictionary<Material, Dictionary<string, Color>> _original = new Dictionary<Material, Dictionary<string, Color>>();

		private Color? _color;

		private bool _failed;

		private NewCrystalBar(Transform bar, float far)
		{
			//IL_0025: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			_bar = bar;
			_pos = bar.localPosition;
			_rot = bar.localRotation;
			_maxScale = bar.localScale;
			_far = far;
		}

		internal static NewCrystalBar Create(Transform bar)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				float num = float.MaxValue;
				float num2 = float.MinValue;
				Renderer[] componentsInChildren = ((Component)bar).GetComponentsInChildren<Renderer>(true);
				Vector3 val2 = default(Vector3);
				foreach (Renderer val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null))
					{
						Bounds localBounds = val.localBounds;
						for (int j = 0; j < 8; j++)
						{
							((Vector3)(ref val2))..ctor(((j & 1) == 0) ? ((Bounds)(ref localBounds)).min.x : ((Bounds)(ref localBounds)).max.x, ((j & 2) == 0) ? ((Bounds)(ref localBounds)).min.y : ((Bounds)(ref localBounds)).max.y, ((j & 4) == 0) ? ((Bounds)(ref localBounds)).min.z : ((Bounds)(ref localBounds)).max.z);
							float x = bar.InverseTransformPoint(((Component)val).transform.TransformPoint(val2)).x;
							num = Mathf.Min(num, x);
							num2 = Mathf.Max(num2, x);
						}
					}
				}
				if (num > num2)
				{
					Plugin.Log.LogWarning((object)"Charge bar has no renderer (game update?) - no color for new crystals.");
					return null;
				}
				float num3 = ((Mathf.Abs(num2) >= Mathf.Abs(num)) ? num2 : num);
				if (Mathf.Abs(num3) < 0.0001f)
				{
					return null;
				}
				return new NewCrystalBar(bar, num3);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Color for new crystals could not be made: " + ex.Message));
				return null;
			}
		}

		internal float Show(float from, float to, Color? color)
		{
			//IL_0091: 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_00bd: 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_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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (_failed || !color.HasValue || to - from <= 0.0005f || (Object)(object)_bar == (Object)null)
			{
				if ((Object)(object)_copy != (Object)null && _copy.activeSelf)
				{
					_copy.SetActive(false);
				}
				return to;
			}
			try
			{
				if ((Object)(object)_copy == (Object)null)
				{
					Make();
				}
				Color? color2 = _color;
				Color? val = color;
				if (color2.HasValue != val.HasValue || (color2.HasValue && color2.GetValueOrDefault() != val.GetValueOrDefault()))
				{
					Tint(color.Value);
				}
				_copy.transform.localRotation = _rot;
				_copy.transform.localPosition = _pos + _rot * new Vector3(from * _far * _maxScale.x, 0f, 0f);
				_copy.transform.localScale = new Vector3((to - from) * _maxScale.x, _maxScale.y, _maxScale.z);
				if (!_copy.activeSelf)
				{
					_copy.SetActive(true);
				}
				return from;
			}
			catch (Exception ex)
			{
				_failed = true;
				Plugin.Log.LogWarning((object)("Color for new crystals failed: " + ex.Message));
				Destroy();
				return to;
			}
		}

		private void Make()
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			_copy = Object.Instantiate<GameObject>(((Component)_bar).gameObject, _bar.parent, false);
			((Object)_copy).name = "Charge (TruckEnergyInShop new crystals)";
			Component[] componentsInChildren = _copy.GetComponentsInChildren<Component>(true);
			foreach (Component val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !(val is Transform) && !(val is MeshFilter) && !(val is Renderer))
				{
					Object.Destroy((Object)(object)val);
				}
			}
			List<string> list = new List<string>();
			Renderer[] componentsInChildren2 = _copy.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Material[] materials = val2.materials;
				foreach (Material val3 in materials)
				{
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					_materials.Add(val3);
					Dictionary<string, Color> dictionary = new Dictionary<string, Color>();
					string[] colorNames = ColorNames;
					foreach (string text in colorNames)
					{
						if (val3.HasProperty(text))
						{
							dictionary[text] = val3.GetColor(text);
						}
					}
					if (val3.HasProperty("_EmissionColor"))
					{
						dictionary["_EmissionColor"] = val3.GetColor("_EmissionColor");
					}
					_original[val3] = dictionary;
					list.Add(((Object)val3.shader).name + " [" + string.Join(", ", dictionary.Keys) + "]");
				}
			}
			Plugin.Log.LogInfo((object)("New crystal bar: " + string.Join("; ", list)));
		}

		private void Tint(Color c)
		{
			//IL_0001: 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_0066: 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_006f: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			_color = c;
			foreach (Material material in _materials)
			{
				if ((Object)(object)material == (Object)null || !_original.TryGetValue(material, out var value))
				{
					continue;
				}
				bool flag = false;
				bool flag2 = true;
				foreach (KeyValuePair<string, Color> item in value)
				{
					Color value2 = item.Value;
					float num = Mathf.Max(value2.r, Mathf.Max(value2.g, value2.b));
					if (item.Key != "_EmissionColor")
					{
						flag = true;
						if (Mathf.Min(value2.r, Mathf.Min(value2.g, value2.b)) < 0.85f)
						{
							flag2 = false;
						}
					}
					material.SetColor(item.Key, new Color(c.r * num, c.g * num, c.b * num, value2.a));
				}
				if (!(flag && flag2))
				{
					continue;
				}
				string[] textureNames = TextureNames;
				foreach (string text in textureNames)
				{
					if (material.HasProperty(text) && (Object)(object)material.GetTexture(text) != (Object)null)
					{
						material.SetTexture(text, (Texture)(object)Texture2D.whiteTexture);
					}
				}
			}
		}

		internal void Destroy()
		{
			if ((Object)(object)_copy != (Object)null)
			{
				Object.Destroy((Object)(object)_copy);
			}
			foreach (Material material in _materials)
			{
				if ((Object)(object)material != (Object)null)
				{
					Object.Destroy((Object)(object)material);
				}
			}
			_materials.Clear();
			_original.Clear();
			_copy = null;
		}
	}
	public enum MarkStyle
	{
		Off,
		Lines,
		Arrows,
		Both
	}
	public enum CrystalColor
	{
		Default,
		Orange,
		Pink,
		Green,
		Brown,
		Red,
		LightGreen,
		Turquoise,
		LightBlue,
		DarkBlue,
		Purple,
		Magenta,
		LightPink
	}
	[BepInPlugin("purtzel_hd.truckenergyinshop", "TruckEnergyInShop", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<MarkStyle> Style;

		internal static ConfigEntry<bool> ShowCount;

		internal static ConfigEntry<CrystalColor> NewColor;

		internal static ConfigEntry<int> Size;

		internal static ConfigEntry<int> TextSize;

		internal static ConfigEntry<bool> ShowOutside;

		private void Awake()
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Style = ((BaseUnityPlugin)this).Config.Bind<MarkStyle>("General", "Mark Style", MarkStyle.Both, "Crystal marks on the truck energy bar in the shop. Lines = lines through the bar, Arrows = arrows above and below the bar, Both = lines and arrows, Off = no marks.");
			ShowCount = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Show Crystal Count", true, "Show over the bar how many Power Crystals are in the truck after the shop, out of a full bar (\"4/10 crystals\").");
			NewColor = ((BaseUnityPlugin)this).Config.Bind<CrystalColor>("General", "Purchased Crystal Color", CrystalColor.Orange, "Color of the bar for the Power Crystals you buy in this shop. Default = no own color (yellow like the rest).");
			Size = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Mark Size", 100, new ConfigDescription("Size of the lines and arrows in percent (50 - 200).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 200), Array.Empty<object>()));
			TextSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Text Size", 100, new ConfigDescription("Size of the crystal count text over the bar in percent (50 - 200).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 200), Array.Empty<object>()));
			ShowOutside = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Show Outside Shop", false, "Also show the crystal marks and the crystal count on the truck outside the shop (for example in a level).");
			RemoveOldConfigEntries();
			if (!Game.Init())
			{
				Log.LogWarning((object)"TruckEnergyInShop does nothing: game parts not found (game update?).");
				return;
			}
			ChargeBar.Install(new Harmony("purtzel_hd.truckenergyinshop"));
			Log.LogInfo((object)"TruckEnergyInShop loaded. Shows the truck energy and crystal marks in the shop.");
		}

		internal static Color? ColorOf(CrystalColor c)
		{
			//IL_009b: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_00c9: 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_00f4: 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_0121: 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)
			return c switch
			{
				CrystalColor.Pink => Rgb(byte.MaxValue, 46, 154), 
				CrystalColor.Green => Rgb(46, 204, 64), 
				CrystalColor.Brown => Rgb(139, 90, 43), 
				CrystalColor.Red => Rgb(byte.MaxValue, 32, 32), 
				CrystalColor.Orange => Rgb(byte.MaxValue, 140, 0), 
				CrystalColor.LightGreen => Rgb(140, 240, 96), 
				CrystalColor.Turquoise => Rgb(48, 213, 200), 
				CrystalColor.LightBlue => Rgb(110, 198, byte.MaxValue), 
				CrystalColor.DarkBlue => Rgb(31, 63, 191), 
				CrystalColor.Purple => Rgb(138, 43, 226), 
				CrystalColor.Magenta => Rgb(byte.MaxValue, 0, byte.MaxValue), 
				CrystalColor.LightPink => Rgb(byte.MaxValue, 176, 204), 
				_ => null, 
			};
		}

		private static Color Rgb(byte r, byte g, byte b)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return Color32.op_Implicit(new Color32(r, g, b, byte.MaxValue));
		}

		private void RemoveOldConfigEntries()
		{
			try
			{
				if (AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(((BaseUnityPlugin)this).Config) is IDictionary { Count: >0 } dictionary)
				{
					dictionary.Clear();
					((BaseUnityPlugin)this).Config.Save();
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Cleaning the config failed: " + ex.Message));
			}
		}
	}
}