Decompiled source of Quota Surplus Energy v0.4.13

BepInEx\plugins\Fan.WarehouseEnergy\Fan.WarehouseEnergy.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[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("Fan.WarehouseEnergy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Fan.WarehouseEnergy")]
[assembly: AssemblyTitle("Fan.WarehouseEnergy")]
[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 Fan.WarehouseEnergy
{
	[BepInPlugin("fan.repo.warehouseenergy", "Quota Surplus Energy", "0.4.13")]
	public sealed class WarehouseEnergyPlugin : BaseUnityPlugin
	{
		internal sealed class PadState
		{
			internal Component ExtractionPoint;

			internal Component TerminalScreenText;

			internal GameObject TerminalDisplayRoot;

			internal Renderer TerminalDisplayRenderer;

			internal Material TerminalDisplayMaterial;

			internal float NextTerminalDisplayAttempt;

			internal float NextTerminalSurplusScan;

			internal bool TerminalDisplayWarningLogged;

			internal int LastTerminalPhase = -1;

			internal int LastLoggedTerminalPhase = -1;

			internal Transform Platform;

			internal Transform SurplusSpawnTransform;

			internal Vector3 SurplusSpawnPosition;

			internal bool HasSurplusSpawnPosition;

			internal int SurplusAmount;

			internal int SourcePhotonViewId;

			internal Bounds PhysicalPrefabBounds;

			internal float DisplayHeight;

			internal bool PhysicalCrystalConfigured;

			internal bool CrystalSpawnAttempted;

			internal GameObject PresentationRoot;

			internal Vector3 PlatformLocalPosition;

			internal Quaternion PlatformLocalRotation;

			internal Vector3 CachedWorldPosition;

			internal Quaternion CachedWorldRotation;

			internal Scene Scene;

			internal GameObject PanelRoot;

			internal Renderer[] SegmentRenderers;

			internal Light CrystalLight;

			internal Light CrystalFillLight;

			internal Transform ChargingBeamOrigin;

			internal Transform ChargingBeamTarget;

			internal LineRenderer ChargingBeamGlow;

			internal LineRenderer ChargingBeamCore;

			internal float ChargingBeamUntil;

			internal Light TerminalMonitorLight;

			internal Vector3[] SegmentBaseScales;

			internal Vector3[] SegmentBasePositions;

			internal float NextChargeLog;

			internal float NextChargeNoProgressLog;

			internal float NextBeamNetworkSync;

			internal int LastBeamNetworkTargetId;

			internal double EnergyFraction;

			internal int LastVisualSegments;

			internal float NextItemScan;

			internal int LastScanBatteryCount = -1;

			internal readonly List<Component> ItemsCharging = new List<Component>();

			internal bool HasRewardedThisExtraction;

			internal bool QuotaReached;

			internal bool CompletionStateSeen;

			internal float ClosureObservedAt;

			internal string PendingRewardSignature;

			internal float PendingRewardSince;

			internal PhotonView PhotonView;

			internal WarehouseEnergyNetwork NetworkRelay;

			internal float NextNetworkEnergySync;
		}

		public const string PluginGuid = "fan.repo.warehouseenergy";

		public const string PluginName = "Quota Surplus Energy";

		public const string PluginVersion = "0.4.13";

		private const int MoneyPerReward = 7000;

		private const int CrystalMaxSegments = 4;

		private const double EnergyFractionPerCrystalCell = 7.0 / 300.0;

		private const double MaxCrystalEnergyFraction = 7.0 / 75.0;

		private const double CrystalEnergyEpsilon = 1E-09;

		private const float OriginalChargeRate = 20f;

		private const float ExtractionScanInterval = 0.25f;

		private const float ItemScanInterval = 0.5f;

		private const float TerminalSurplusScanInterval = 0.35f;

		private const float RewardStabilityDelay = 1.25f;

		private const float ClosureSettleDelay = 0.45f;

		private const float NetworkCrystalScanInterval = 0.25f;

		private const string CrystalInstantiationMarker = "FWE_CRYSTAL_PHYSICAL_V1";

		private readonly Dictionary<int, PadState> _pads = new Dictionary<int, PadState>();

		private readonly List<int> _removeIds = new List<int>();

		private readonly HashSet<int> _processedCrystalViewIds = new HashSet<int>();

		private Type _extractionPointType;

		private Type _chargingStationType;

		private Type _itemBatteryType;

		private FieldInfo _haulSurplusField;

		private FieldInfo _haulGoalField;

		private FieldInfo _haulCurrentField;

		private FieldInfo _currentStateField;

		private object _completeStateValue;

		private FieldInfo _isShopField;

		private FieldInfo _platformField;

		private FieldInfo _rampField;

		private FieldInfo _surplusSpawnTransformField;

		private FieldInfo _emojiScreenField;

		private FieldInfo _batteryLifeField;

		private MethodInfo _receiveChargeMethod;

		private MethodInfo _masterOrSingleplayerMethod;

		private MethodInfo _layerMaskMethod;

		private Type _assetManagerType;

		private Type _valuableObjectType;

		private FieldInfo _assetManagerInstanceField;

		private PropertyInfo _assetManagerInstanceProperty;

		private FieldInfo _surplusValuableSmallField;

		private FieldInfo _surplusValuableMediumField;

		private FieldInfo _surplusValuableBigField;

		private Type _physGrabObjectType;

		private Type _notValuableObjectType;

		private Type _surplusValuableType;

		private Type _physGrabObjectImpactDetectorType;

		private FieldInfo _notValuableHasHealthField;

		private FieldInfo _impactDetectorFragilityField;

		private FieldInfo _impactDetectorIsValuableField;

		private FieldInfo _impactDetectorValuableObjectField;

		private FieldInfo _spawnTorqueField;

		private FieldInfo _dollarValueOriginalField;

		private FieldInfo _dollarValueCurrentField;

		private FieldInfo _dollarValueOverrideField;

		private FieldInfo _dollarValueSetField;

		private double _batteryChargeCost;

		private double _lastLoggedChargeCost = double.NaN;

		private float _nextChargeCostWarning;

		private int _stockItemLayerMask = -1;

		private float _lastLoggedChargeRadius = -1f;

		private float _nextExtractionScan;

		private float _nextStockSettingsScan;

		private float _nextNoExtractionWarning;

		private float _nextCrystalCreationAttempt;

		private float _nextNetworkCrystalScan;

		private bool _typesReady;

		private ConfigEntry<float> _crystalHeight;

		private ConfigEntry<float> _glowRange;

		private ConfigEntry<float> _chargeRadius;

		private ConfigEntry<float> _chargeCenterHeight;

		private ConfigEntry<bool> _debugLogging;

		private Material _crystalMaterial;

		private Material _segmentOffMaterial;

		private Material _segmentOnMaterial;

		private Material _chargingBeamGlowMaterial;

		private Material _chargingBeamCoreMaterial;

		private Texture2D _crystalTexture;

		private readonly Texture2D[] _terminalPhaseTextures = (Texture2D[])(object)new Texture2D[5];

		private readonly Material[] _terminalPhaseMaterials = (Material[])(object)new Material[5];

		private Mesh _crystalMesh;

		private string _resourceDirectory;

		private void Awake()
		{
			BindConfiguration();
			CreateMaterials();
			try
			{
				Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => string.Equals(a.GetName().Name, "Assembly-CSharp", StringComparison.Ordinal));
				if (assembly == null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Assembly-CSharp is not loaded. Warehouse Energy will remain inactive.");
					return;
				}
				_extractionPointType = assembly.GetType("ExtractionPoint", throwOnError: false);
				_chargingStationType = assembly.GetType("ChargingStation", throwOnError: false);
				_itemBatteryType = assembly.GetType("ItemBattery", throwOnError: false);
				_assetManagerType = assembly.GetType("AssetManager", throwOnError: false);
				_valuableObjectType = assembly.GetType("ValuableObject", throwOnError: false);
				if (_extractionPointType == null || _chargingStationType == null || _itemBatteryType == null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Could not locate one or more original game types: ExtractionPoint, ChargingStation, ItemBattery.");
					return;
				}
				_haulSurplusField = _extractionPointType.GetField("haulSurplus", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_haulGoalField = _extractionPointType.GetField("haulGoal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_haulCurrentField = _extractionPointType.GetField("haulCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_currentStateField = _extractionPointType.GetField("currentState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (_currentStateField != null && _currentStateField.FieldType.IsEnum)
				{
					try
					{
						_completeStateValue = Enum.Parse(_currentStateField.FieldType, "Complete", ignoreCase: false);
					}
					catch (Exception ex)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not resolve ExtractionPoint.State.Complete: " + ex.Message));
					}
				}
				_isShopField = _extractionPointType.GetField("isShop", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_platformField = _extractionPointType.GetField("platform", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_rampField = _extractionPointType.GetField("ramp", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_surplusSpawnTransformField = _extractionPointType.GetField("surplusSpawnTransform", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_emojiScreenField = _extractionPointType.GetField("emojiScreen", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (_emojiScreenField == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"ExtractionPoint.emojiScreen was not found. The energy monitor will remain disabled; no guessed world coordinates will be used.");
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Resolved ExtractionPoint.emojiScreen as " + _emojiScreenField.FieldType.FullName + ". The extra monitor will anchor to the original emoji display."));
				}
				_physGrabObjectType = assembly.GetType("PhysGrabObject", throwOnError: false);
				if (_physGrabObjectType != null)
				{
					_spawnTorqueField = _physGrabObjectType.GetField("spawnTorque", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				_notValuableObjectType = assembly.GetType("NotValuableObject", throwOnError: false);
				_surplusValuableType = assembly.GetType("SurplusValuable", throwOnError: false);
				_physGrabObjectImpactDetectorType = assembly.GetType("PhysGrabObjectImpactDetector", throwOnError: false);
				if (_notValuableObjectType != null)
				{
					_notValuableHasHealthField = _notValuableObjectType.GetField("hasHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				if (_physGrabObjectImpactDetectorType != null)
				{
					_impactDetectorFragilityField = _physGrabObjectImpactDetectorType.GetField("fragility", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					_impactDetectorIsValuableField = _physGrabObjectImpactDetectorType.GetField("isValuable", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					_impactDetectorValuableObjectField = _physGrabObjectImpactDetectorType.GetField("valuableObject", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				_batteryLifeField = _itemBatteryType.GetField("batteryLife", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_receiveChargeMethod = _itemBatteryType.GetMethod("ReceiveCharge", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(float) }, null);
				_masterOrSingleplayerMethod = FindStaticMethod(assembly, "IsMasterClientOrSingleplayer", typeof(bool));
				_layerMaskMethod = FindStaticMethod(assembly, "LayerMaskGetPhysGrabObject", null);
				if (_assetManagerType != null)
				{
					_assetManagerInstanceField = _assetManagerType.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					_assetManagerInstanceProperty = _assetManagerType.GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					_surplusValuableSmallField = _assetManagerType.GetField("surplusValuableSmall", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					_surplusValuableMediumField = _assetManagerType.GetField("surplusValuableMedium", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					_surplusValuableBigField = _assetManagerType.GetField("surplusValuableBig", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				if (_valuableObjectType != null)
				{
					_dollarValueOverrideField = _valuableObjectType.GetField("dollarValueOverride", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					_dollarValueSetField = _valuableObjectType.GetField("dollarValueSet", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					_dollarValueOriginalField = _valuableObjectType.GetField("dollarValueOriginal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					_dollarValueCurrentField = _valuableObjectType.GetField("dollarValueCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				if (_haulSurplusField == null || _haulGoalField == null || _haulCurrentField == null || _platformField == null || _currentStateField == null || _completeStateValue == null || _batteryLifeField == null || _receiveChargeMethod == null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"One or more expected game members were not found (including ExtractionPoint.platform/currentState/State.Complete). Check that the game DLL matches this mod version.");
					return;
				}
				_typesReady = true;
				RefreshStockChargingSettings(log: true);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Quota Surplus Energy 0.4.13 initialized. F4 spawns a $100,000 test valuable (host/singleplayer only). Crystal waits for ExtractionPoint.State.Complete and for the collection point/platform to deactivate before appearing. Terminal monitor uses the real Display Square + dirt 11 screen mesh.");
				if (_receiveChargeMethod != null)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Resolved ItemBattery.ReceiveCharge signature: " + _receiveChargeMethod.ReturnType.Name + " ReceiveCharge(" + string.Join(", ", (from p in _receiveChargeMethod.GetParameters()
						select p.ParameterType.Name).ToArray()) + ")."));
				}
				if (_assetManagerType == null || _surplusValuableSmallField == null || _valuableObjectType == null || _dollarValueOverrideField == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"F4 test valuable is unavailable: one or more AssetManager/ValuableObject members were not found.");
				}
				if (_assetManagerType == null || _surplusValuableSmallField == null || _surplusValuableMediumField == null || _surplusValuableBigField == null || _physGrabObjectType == null || _spawnTorqueField == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Physical crystal spawning is unavailable: one or more vanilla surplus prefab/PhysGrabObject members were not found.");
				}
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Initialization failed: " + ex2));
			}
		}

		private void BindConfiguration()
		{
			_crystalHeight = ((BaseUnityPlugin)this).Config.Bind<float>("CrystalV2", "Height", 2.55f, "Target height of the crystal model, in metres (about three times the prototype size).");
			_glowRange = ((BaseUnityPlugin)this).Config.Bind<float>("CrystalV2", "GlowRange", 7f, "Range of the crystal's warm golden light, in metres.");
			_chargeRadius = ((BaseUnityPlugin)this).Config.Bind<float>("ChargingSphere", "Radius", 1.35f, "Spherical charging radius around the crystal, in metres.");
			_chargeCenterHeight = ((BaseUnityPlugin)this).Config.Bind<float>("ChargingSphere", "CenterHeight", 0.55f, "Spherical charging centre height above the crystal base, in metres.");
			_debugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugLogging", false, "Write extra diagnostic information to the BepInEx log.");
		}

		private void CreateMaterials()
		{
			//IL_00b5: 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_00ca: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_0126: 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)
			//IL_015f: 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_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Expected O, but got Unknown
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Expected O, but got Unknown
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				_resourceDirectory = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Resources");
				LoadTerminalPhaseTextures();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not initialize the terminal monitor PNG resources independently: " + ex.GetBaseException()));
			}
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Universal Render Pipeline/Lit");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Unlit/Texture");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Unlit/Color");
			}
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not find a usable Unity shader. The crystal may not render.");
				return;
			}
			_segmentOffMaterial = new Material(val)
			{
				name = "FanWarehouseEnergy_SegmentOff"
			};
			_segmentOffMaterial.color = new Color(0.12f, 0.095f, 0.035f, 1f);
			_segmentOnMaterial = new Material(val)
			{
				name = "FanWarehouseEnergy_SegmentOn"
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(1f, 0.72f, 0.12f, 1f);
			_segmentOnMaterial.color = val2;
			_segmentOnMaterial.EnableKeyword("_EMISSION");
			if (_segmentOnMaterial.HasProperty("_EmissionColor"))
			{
				_segmentOnMaterial.SetColor("_EmissionColor", val2 * 1.8f);
			}
			Shader val3 = Shader.Find("Legacy Shaders/Particles/Additive");
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = Shader.Find("Particles/Standard Unlit");
			}
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = Shader.Find("Sprites/Default");
			}
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = Shader.Find("Unlit/Color");
			}
			if ((Object)(object)val3 != (Object)null)
			{
				_chargingBeamGlowMaterial = CreateBeamMaterial(val3, "FanWarehouseEnergy_ChargingBeam_Glow", new Color(1f, 0.38f, 0.045f, 0.34f));
				_chargingBeamCoreMaterial = CreateBeamMaterial(val3, "FanWarehouseEnergy_ChargingBeam_Core", new Color(1f, 0.88f, 0.32f, 0.95f));
			}
			try
			{
				string path = Path.Combine(_resourceDirectory, "power_crystal.obj");
				string path2 = Path.Combine(_resourceDirectory, "crystal_gold.png");
				if (!File.Exists(path) || !File.Exists(path2))
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Crystal resources are missing. Expected 'Resources/power_crystal.obj' and 'Resources/crystal_gold.png' beside the plugin DLL. OBJ exists=" + File.Exists(path) + ", texture exists=" + File.Exists(path2) + "."));
					return;
				}
				_crystalTexture = new Texture2D(2, 2, (TextureFormat)4, true);
				if (!ImageConversion.LoadImage(_crystalTexture, File.ReadAllBytes(path2)))
				{
					throw new InvalidDataException("Unity could not decode crystal_gold.png.");
				}
				((Object)_crystalTexture).name = "FanWarehouseEnergy_GoldCrystalTexture";
				((Texture)_crystalTexture).filterMode = (FilterMode)2;
				((Texture)_crystalTexture).anisoLevel = 8;
				((Texture)_crystalTexture).wrapMode = (TextureWrapMode)0;
				_crystalMesh = LoadObjMesh(path, Mathf.Clamp(_crystalHeight.Value, 0.5f, 3.5f));
				_crystalMaterial = new Material(val)
				{
					name = "FanWarehouseEnergy_GoldCrystal"
				};
				_crystalMaterial.color = Color.white;
				if (_crystalMaterial.HasProperty("_MainTex"))
				{
					_crystalMaterial.SetTexture("_MainTex", (Texture)(object)_crystalTexture);
				}
				if (_crystalMaterial.HasProperty("_BaseMap"))
				{
					_crystalMaterial.SetTexture("_BaseMap", (Texture)(object)_crystalTexture);
				}
				if (_crystalMaterial.HasProperty("_Cull"))
				{
					_crystalMaterial.SetInt("_Cull", 0);
				}
				_crystalMaterial.EnableKeyword("_EMISSION");
				Color val4 = new Color(1f, 0.62f, 0.1f, 1f) * 0.28f;
				if (_crystalMaterial.HasProperty("_EmissionColor"))
				{
					_crystalMaterial.SetColor("_EmissionColor", val4);
				}
				if (_crystalMaterial.HasProperty("_EmissionMap"))
				{
					_crystalMaterial.SetTexture("_EmissionMap", (Texture)(object)_crystalTexture);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Crystal model loaded: " + _crystalMesh.vertexCount + " mesh vertices, " + ((Texture)_crystalTexture).width + "x" + ((Texture)_crystalTexture).height + " texture, target height=" + _crystalHeight.Value.ToString("0.00", CultureInfo.InvariantCulture) + "m."));
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not load the crystal model or texture: " + ex2.GetBaseException()));
				if ((Object)(object)_crystalMesh != (Object)null)
				{
					Object.Destroy((Object)(object)_crystalMesh);
				}
				_crystalMesh = null;
				if ((Object)(object)_crystalTexture != (Object)null)
				{
					Object.Destroy((Object)(object)_crystalTexture);
				}
				_crystalTexture = null;
				if ((Object)(object)_crystalMaterial != (Object)null)
				{
					Object.Destroy((Object)(object)_crystalMaterial);
				}
				_crystalMaterial = null;
			}
		}

		private static Material CreateBeamMaterial(Shader shader, string materialName, Color tint)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0076: 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_0087: 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 ((Object)(object)shader == (Object)null)
			{
				return null;
			}
			Material val = new Material(shader);
			((Object)val).name = materialName;
			val.color = tint;
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", tint);
			}
			if (val.HasProperty("_TintColor"))
			{
				val.SetColor("_TintColor", tint);
			}
			if (val.HasProperty("_EmissionColor"))
			{
				val.EnableKeyword("_EMISSION");
				val.SetColor("_EmissionColor", new Color(tint.r, tint.g, tint.b, 1f) * 1.6f);
			}
			val.renderQueue = 3000;
			return val;
		}

		private void LoadTerminalPhaseTextures()
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Expected O, but got Unknown
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Expected O, but got Unknown
			string[] array = new string[5] { "terminal_energy_n0.png", "terminal_energy_n1.png", "terminal_energy_n2.png", "terminal_energy_n3.png", "terminal_energy_n4.png" };
			Shader val = Shader.Find("Unlit/Texture");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Universal Render Pipeline/Unlit");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Standard");
			}
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"No supported shader was found for the terminal energy display. The crystal itself will continue to work.");
				return;
			}
			int num = 0;
			for (int i = 0; i < array.Length; i++)
			{
				string text = Path.Combine(_resourceDirectory, array[i]);
				Texture2D val2 = null;
				try
				{
					if (!File.Exists(text))
					{
						((BaseUnityPlugin)this).Logger.LogError((object)("Terminal energy display phase is missing: " + text));
						continue;
					}
					val2 = new Texture2D(2, 2, (TextureFormat)4, true);
					if (!ImageConversion.LoadImage(val2, File.ReadAllBytes(text)))
					{
						Object.Destroy((Object)(object)val2);
						val2 = null;
						((BaseUnityPlugin)this).Logger.LogError((object)("Unity could not decode terminal energy display phase: " + array[i] + ". Other phases will still be loaded."));
						continue;
					}
					((Object)val2).name = "FanWarehouseEnergy_TerminalPhase_N" + i.ToString(CultureInfo.InvariantCulture);
					((Texture)val2).filterMode = (FilterMode)1;
					((Texture)val2).anisoLevel = 8;
					((Texture)val2).wrapMode = (TextureWrapMode)1;
					_terminalPhaseTextures[i] = val2;
					num++;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("[TerminalPNG] Loaded N" + i.ToString(CultureInfo.InvariantCulture) + " " + ((Texture)val2).width + "x" + ((Texture)val2).height + " from " + array[i] + "."));
				}
				catch (Exception ex)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						Object.Destroy((Object)(object)val2);
					}
					((BaseUnityPlugin)this).Logger.LogError((object)("Could not load terminal phase " + array[i] + ": " + ex.GetBaseException().Message + ". Other phases will still be loaded."));
				}
			}
			if (num == 0)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"No terminal PNG phase could be decoded. The terminal monitor cannot display images.");
				return;
			}
			int num2 = 0;
			for (int j = 0; j < _terminalPhaseTextures.Length; j++)
			{
				if ((Object)(object)_terminalPhaseTextures[j] != (Object)null)
				{
					continue;
				}
				int num3 = -1;
				int num4 = int.MaxValue;
				for (int k = 0; k < _terminalPhaseTextures.Length; k++)
				{
					if (!((Object)(object)_terminalPhaseTextures[k] == (Object)null))
					{
						int num5 = Math.Abs(k - j);
						if (num5 < num4)
						{
							num4 = num5;
							num3 = k;
						}
					}
				}
				if (num3 >= 0)
				{
					Texture2D val3 = _terminalPhaseTextures[num3];
					Texture2D val4 = new Texture2D(((Texture)val3).width, ((Texture)val3).height, (TextureFormat)4, true);
					val4.SetPixels32(val3.GetPixels32());
					val4.Apply(false, false);
					((Object)val4).name = "FanWarehouseEnergy_TerminalPhase_N" + j.ToString(CultureInfo.InvariantCulture) + "_FallbackFromN" + num3.ToString(CultureInfo.InvariantCulture);
					((Texture)val4).filterMode = (FilterMode)1;
					((Texture)val4).anisoLevel = 8;
					((Texture)val4).wrapMode = (TextureWrapMode)1;
					_terminalPhaseTextures[j] = val4;
					num2++;
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Terminal phase N" + j.ToString(CultureInfo.InvariantCulture) + " is unavailable; using a temporary copy of N" + num3.ToString(CultureInfo.InvariantCulture) + " so the monitor remains visible."));
				}
			}
			for (int l = 0; l < _terminalPhaseTextures.Length; l++)
			{
				Texture2D val5 = _terminalPhaseTextures[l];
				if (!((Object)(object)val5 == (Object)null))
				{
					Material val6 = new Material(val);
					((Object)val6).name = "FanWarehouseEnergy_TerminalPhaseMaterial_N" + l.ToString(CultureInfo.InvariantCulture);
					val6.color = Color.white;
					if (val6.HasProperty("_MainTex"))
					{
						val6.SetTexture("_MainTex", (Texture)(object)val5);
					}
					if (val6.HasProperty("_BaseMap"))
					{
						val6.SetTexture("_BaseMap", (Texture)(object)val5);
					}
					if (val6.HasProperty("_Cull"))
					{
						val6.SetInt("_Cull", 0);
					}
					_terminalPhaseMaterials[l] = val6;
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Terminal PNG resources ready: " + num.ToString(CultureInfo.InvariantCulture) + "/5 decoded from disk; " + num2.ToString(CultureInfo.InvariantCulture) + " fallback phase(s). All phase slots are available to the monitor."));
		}

		private static Mesh LoadObjMesh(string path, float targetHeight)
		{
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: 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)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Expected O, but got Unknown
			//IL_0210: 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_0235: 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_0253: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<Vector3> list3 = new List<Vector3>();
			List<Vector3> list4 = new List<Vector3>();
			List<Vector2> list5 = new List<Vector2>();
			List<Vector3> list6 = new List<Vector3>();
			List<int> list7 = new List<int>();
			bool flag = true;
			string[] array = File.ReadAllLines(path);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length == 0 || text[0] == '#')
				{
					continue;
				}
				string[] array2 = text.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
				if (array2.Length == 0)
				{
					continue;
				}
				if (array2[0] == "v" && array2.Length >= 4)
				{
					list.Add(new Vector3(ParseObjFloat(array2[1]), ParseObjFloat(array2[2]), ParseObjFloat(array2[3])));
				}
				else if (array2[0] == "vt" && array2.Length >= 3)
				{
					list2.Add(new Vector2(ParseObjFloat(array2[1]), ParseObjFloat(array2[2])));
				}
				else if (array2[0] == "vn" && array2.Length >= 4)
				{
					Vector3 val = new Vector3(ParseObjFloat(array2[1]), ParseObjFloat(array2[2]), ParseObjFloat(array2[3]));
					list3.Add(((Vector3)(ref val)).normalized);
				}
				else
				{
					if (!(array2[0] == "f") || array2.Length < 4)
					{
						continue;
					}
					List<int> list8 = new List<int>();
					for (int j = 1; j < array2.Length; j++)
					{
						string[] array3 = array2[j].Split('/');
						int num = ResolveObjIndex((array3.Length != 0) ? array3[0] : string.Empty, list.Count);
						if (num < 0 || num >= list.Count)
						{
							throw new InvalidDataException("OBJ face references an invalid vertex on line " + (i + 1) + ".");
						}
						int num2 = ((array3.Length > 1) ? ResolveObjIndex(array3[1], list2.Count) : (-1));
						int num3 = ((array3.Length > 2) ? ResolveObjIndex(array3[2], list3.Count) : (-1));
						list8.Add(list4.Count);
						list4.Add(list[num]);
						list5.Add((num2 >= 0 && num2 < list2.Count) ? list2[num2] : Vector2.zero);
						if (num3 >= 0 && num3 < list3.Count)
						{
							list6.Add(list3[num3]);
							continue;
						}
						list6.Add(Vector3.zero);
						flag = false;
					}
					for (int k = 1; k < list8.Count - 1; k++)
					{
						list7.Add(list8[0]);
						list7.Add(list8[k]);
						list7.Add(list8[k + 1]);
					}
				}
			}
			if (list.Count == 0 || list4.Count == 0 || list7.Count == 0)
			{
				throw new InvalidDataException("OBJ contains no usable triangle mesh.");
			}
			Vector3 val2 = list[0];
			Vector3 val3 = list[0];
			for (int l = 1; l < list.Count; l++)
			{
				val2 = Vector3.Min(val2, list[l]);
				val3 = Vector3.Max(val3, list[l]);
			}
			float num4 = Mathf.Max(0.0001f, val3.y - val2.y);
			float num5 = targetHeight / num4;
			float num6 = (val2.x + val3.x) * 0.5f;
			float num7 = (val2.z + val3.z) * 0.5f;
			for (int m = 0; m < list4.Count; m++)
			{
				Vector3 val4 = list4[m];
				list4[m] = new Vector3((val4.x - num6) * num5, (val4.y - val2.y) * num5, (val4.z - num7) * num5);
			}
			Mesh val5 = new Mesh();
			((Object)val5).name = "FanWarehouseEnergy_GoldPowerCrystalMesh";
			val5.SetVertices(list4);
			val5.SetUVs(0, list5);
			val5.SetTriangles(list7, 0, true);
			if (flag && list6.Count == list4.Count)
			{
				val5.SetNormals(list6);
			}
			else
			{
				val5.RecalculateNormals();
			}
			val5.RecalculateBounds();
			return val5;
		}

		private static float ParseObjFloat(string value)
		{
			return float.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
		}

		private static int ResolveObjIndex(string value, int count)
		{
			if (string.IsNullOrEmpty(value))
			{
				return -1;
			}
			if (!int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || result == 0)
			{
				return -1;
			}
			if (result <= 0)
			{
				return count + result;
			}
			return result - 1;
		}

		private void Update()
		{
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: 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_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: 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_023f: 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)
			if (!_typesReady)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)285))
			{
				SpawnTestValuable();
			}
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient && Time.unscaledTime >= _nextNetworkCrystalScan)
			{
				_nextNetworkCrystalScan = Time.unscaledTime + 0.25f;
				ProcessNetworkCrystalSpawns();
			}
			if (Time.unscaledTime >= _nextStockSettingsScan)
			{
				_nextStockSettingsScan = Time.unscaledTime + 5f;
				RefreshStockChargingSettings(log: false);
			}
			if (Time.unscaledTime >= _nextExtractionScan)
			{
				_nextExtractionScan = Time.unscaledTime + 0.25f;
				ScanExtractionPoints();
			}
			_removeIds.Clear();
			foreach (KeyValuePair<int, PadState> pad in _pads)
			{
				PadState value = pad.Value;
				if (value == null)
				{
					_removeIds.Add(pad.Key);
					continue;
				}
				if ((Object)(object)value.PanelRoot != (Object)null)
				{
					UpdateCrystalLighting(value);
				}
				if ((Object)(object)value.TerminalDisplayRoot == (Object)null && Time.unscaledTime >= value.NextTerminalDisplayAttempt)
				{
					value.NextTerminalDisplayAttempt = Time.unscaledTime + 1f;
					if ((Object)(object)value.TerminalScreenText == (Object)null)
					{
						value.TerminalScreenText = FindTerminalScreenTextForPad(value);
					}
					BuildTerminalEnergyMonitor(value);
				}
				if ((Object)(object)value.TerminalDisplayRoot != (Object)null && Time.unscaledTime >= value.NextTerminalSurplusScan)
				{
					value.NextTerminalSurplusScan = Time.unscaledTime + 0.35f;
					UpdateTerminalMonitorFromLiveSurplus(value);
				}
				bool flag = (Object)(object)value.ExtractionPoint != (Object)null && value.ExtractionPoint.gameObject.activeInHierarchy;
				Component extractionPoint = value.ExtractionPoint;
				Behaviour val = (Behaviour)(object)((extractionPoint is Behaviour) ? extractionPoint : null);
				if ((Object)(object)val != (Object)null && !val.enabled)
				{
					flag = false;
				}
				bool flag2 = (Object)(object)value.Platform != (Object)null && ((Component)value.Platform).gameObject.activeInHierarchy;
				if (!value.QuotaReached && !flag && !flag2)
				{
					_removeIds.Add(pad.Key);
					continue;
				}
				if (flag)
				{
					if ((Object)(object)value.SurplusSpawnTransform == (Object)null)
					{
						value.SurplusSpawnTransform = GetTransformField(_surplusSpawnTransformField, value.ExtractionPoint);
					}
					Transform surplusSpawnTransform = value.SurplusSpawnTransform;
					if ((Object)(object)surplusSpawnTransform != (Object)null)
					{
						value.SurplusSpawnPosition = surplusSpawnTransform.position;
						value.HasSurplusSpawnPosition = true;
					}
					int num = ReadInt(_haulGoalField, value.ExtractionPoint, 0);
					int num2 = ReadInt(_haulCurrentField, value.ExtractionPoint, 0);
					if (num > 0 && num2 >= num)
					{
						value.QuotaReached = true;
					}
				}
				if (flag2)
				{
					value.CachedWorldPosition = value.Platform.TransformPoint(value.PlatformLocalPosition);
					value.CachedWorldRotation = value.Platform.rotation * value.PlatformLocalRotation;
					if ((Object)(object)value.PanelRoot != (Object)null)
					{
						value.PanelRoot.transform.SetPositionAndRotation(value.CachedWorldPosition, value.CachedWorldRotation);
					}
				}
				if (flag && !value.CompletionStateSeen && IsExtractionCompleteState(value.ExtractionPoint))
				{
					value.CompletionStateSeen = true;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Warehouse Energy observed ExtractionPoint.State.Complete for '" + ((Object)value.ExtractionPoint).name + "'. Waiting for the point/platform to deactivate before showing the crystal."));
				}
				if (IsAuthority(value) && flag)
				{
					MonitorQuota(value);
				}
				if ((Object)(object)value.PanelRoot == (Object)null)
				{
					bool flag3 = !flag || !flag2;
					if (value.QuotaReached && value.CompletionStateSeen && flag3 && !value.CrystalSpawnAttempted)
					{
						if (value.ClosureObservedAt < 0f)
						{
							value.ClosureObservedAt = Time.unscaledTime;
							((BaseUnityPlugin)this).Logger.LogInfo((object)"Warehouse Energy confirmed collection-point closure for the completed quota. Crystal will appear after the short settle delay.");
						}
						else if (Time.unscaledTime - value.ClosureObservedAt >= 0.45f && IsAuthority(value))
						{
							SpawnCrystalVisual(value);
						}
					}
					else if (!flag3)
					{
						value.ClosureObservedAt = -1f;
					}
					continue;
				}
				if (IsAuthority(value))
				{
					ChargeItems(value);
					if (PhotonNetwork.InRoom && (Object)(object)value.NetworkRelay != (Object)null && Time.unscaledTime >= value.NextNetworkEnergySync)
					{
						value.NextNetworkEnergySync = Time.unscaledTime + 1f;
						value.NetworkRelay.BroadcastEnergy((float)value.EnergyFraction);
					}
				}
				UpdateChargingBeam(value);
			}
			for (int i = 0; i < _removeIds.Count; i++)
			{
				if (_pads.TryGetValue(_removeIds[i], out var value2) && value2 != null)
				{
					if ((Object)(object)value2.PanelRoot != (Object)null)
					{
						Object.Destroy((Object)(object)value2.PanelRoot);
					}
					if ((Object)(object)value2.TerminalDisplayRoot != (Object)null)
					{
						Object.Destroy((Object)(object)value2.TerminalDisplayRoot);
					}
					if ((Object)(object)value2.TerminalDisplayMaterial != (Object)null)
					{
						Object.Destroy((Object)(object)value2.TerminalDisplayMaterial);
					}
				}
				_pads.Remove(_removeIds[i]);
			}
		}

		private void SpawnTestValuable()
		{
			//IL_00dc: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if (!IsMasterClientOrSingleplayer())
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"F4 test spawn is host-only in multiplayer.");
				return;
			}
			if (_assetManagerType == null || _surplusValuableSmallField == null || _valuableObjectType == null || _dollarValueOverrideField == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Cannot spawn the F4 test valuable: required game members are unavailable.");
				return;
			}
			try
			{
				object assetManagerInstance = GetAssetManagerInstance();
				if (assetManagerInstance == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"F4 test spawn skipped: AssetManager.instance is not ready.");
					return;
				}
				object? value = _surplusValuableSmallField.GetValue(assetManagerInstance);
				GameObject val = (GameObject)((value is GameObject) ? value : null);
				if ((Object)(object)val == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"F4 test spawn skipped: AssetManager.surplusValuableSmall is null.");
					return;
				}
				Camera main = Camera.main;
				if ((Object)(object)main == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"F4 test spawn skipped: no MainCamera was found. Enter an active level first.");
					return;
				}
				Vector3 val2 = ((Component)main).transform.position + ((Component)main).transform.forward * 1.6f + Vector3.down * 0.25f;
				GameObject val3 = ((!PhotonNetwork.InRoom) ? Object.Instantiate<GameObject>(val, val2, Quaternion.identity) : PhotonNetwork.InstantiateRoomObject("Valuables/" + ((Object)val).name, val2, Quaternion.identity, (byte)0, (object[])null));
				if ((Object)(object)val3 == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"F4 test spawn failed: the game returned a null object.");
					return;
				}
				Component component = val3.GetComponent(_valuableObjectType);
				if ((Object)(object)component == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"F4 spawned the surplus prefab, but it has no ValuableObject component. Destroying it.");
					Object.Destroy((Object)(object)val3);
					return;
				}
				object value2 = Convert.ChangeType(100000, _dollarValueOverrideField.FieldType);
				_dollarValueOverrideField.SetValue(component, value2);
				if (_dollarValueSetField != null)
				{
					_dollarValueSetField.SetValue(component, false);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("F4 test spawn: created " + ((Object)val).name + " with a $100,000 value. Pick it up and deliver it normally."));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("F4 test spawn failed: " + ex.GetBaseException()));
			}
		}

		private bool IsMasterClientOrSingleplayer()
		{
			if (_masterOrSingleplayerMethod != null)
			{
				try
				{
					object obj = _masterOrSingleplayerMethod.Invoke(null, null);
					if (obj is bool)
					{
						return (bool)obj;
					}
				}
				catch
				{
				}
			}
			if (PhotonNetwork.InRoom)
			{
				return PhotonNetwork.IsMasterClient;
			}
			return true;
		}

		private void ScanExtractionPoints()
		{
			//IL_0057: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_0170: 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_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			Object[] array = Resources.FindObjectsOfTypeAll(_extractionPointType);
			if (array == null || array.Length == 0)
			{
				WarnNoExtractionPoint("ExtractionPoint scan returned no objects.");
				return;
			}
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				WarnNoExtractionPoint("Waiting for the active player camera before selecting the warehouse.");
				return;
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			Component val = null;
			Transform val2 = null;
			Transform ramp = null;
			float num4 = float.MaxValue;
			Vector3 position = ((Component)main).transform.position;
			Object[] array2 = array;
			foreach (Object obj in array2)
			{
				Component val3 = (Component)(object)((obj is Component) ? obj : null);
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				GameObject gameObject = val3.gameObject;
				if ((Object)(object)gameObject == (Object)null || !gameObject.activeInHierarchy)
				{
					continue;
				}
				Scene scene = gameObject.scene;
				if (!((Scene)(ref scene)).IsValid())
				{
					continue;
				}
				Behaviour val4 = (Behaviour)(object)((val3 is Behaviour) ? val3 : null);
				if ((Object)(object)val4 != (Object)null && !val4.enabled)
				{
					continue;
				}
				object obj2 = ((_isShopField != null) ? _isShopField.GetValue(val3) : null);
				if (obj2 is bool && (bool)obj2)
				{
					continue;
				}
				num++;
				Transform transformField = GetTransformField(_platformField, val3);
				if ((Object)(object)transformField == (Object)null)
				{
					continue;
				}
				num2++;
				if (ReadInt(_haulGoalField, val3, 0) <= 0)
				{
					num3++;
					continue;
				}
				Transform transformField2 = GetTransformField(_rampField, val3);
				Vector3 val5 = transformField.position - position;
				float num5 = val5.x * val5.x + val5.z * val5.z + val5.y * val5.y * 0.2f;
				if (num5 < num4)
				{
					num4 = num5;
					val = val3;
					val2 = transformField;
					ramp = transformField2;
				}
			}
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				WarnNoExtractionPoint("Waiting for an active non-shop ExtractionPoint with an assigned haulGoal and a platform Transform. Active points=" + num + ", platforms=" + num2 + ", awaitingQuota=" + num3 + ". No crystal was created yet.");
				return;
			}
			int instanceID = ((Object)val).GetInstanceID();
			if (_pads.ContainsKey(instanceID) || !(Time.unscaledTime >= _nextCrystalCreationAttempt))
			{
				return;
			}
			try
			{
				PadState padState = CreatePad(val, val2, ramp);
				if (padState != null)
				{
					_pads.Add(instanceID, padState);
					_nextCrystalCreationAttempt = 0f;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Warehouse Energy selected the platform for the crystal belonging to ExtractionPoint '" + ((Object)val).name + "' from " + num + " active non-shop point(s); " + num2 + " had a platform Transform. Horizontal camera distance=" + Mathf.Sqrt(num4).ToString("0.00") + " m."));
				}
				else
				{
					_nextCrystalCreationAttempt = Time.unscaledTime + 5f;
				}
			}
			catch (Exception ex)
			{
				_nextCrystalCreationAttempt = Time.unscaledTime + 5f;
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not create a warehouse crystal for ExtractionPoint '" + ((Object)val).name + "': " + ex.GetBaseException()));
			}
		}

		private void WarnNoExtractionPoint(string message)
		{
			if (!(Time.unscaledTime < _nextNoExtractionWarning))
			{
				_nextNoExtractionWarning = Time.unscaledTime + 10f;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Warehouse Energy: " + message));
			}
		}

		private static Transform GetTransformField(FieldInfo field, object instance)
		{
			if (field == null || instance == null)
			{
				return null;
			}
			try
			{
				object? value = field.GetValue(instance);
				return (Transform)((value is Transform) ? value : null);
			}
			catch
			{
				return null;
			}
		}

		private PadState CreatePad(Component extractionPoint, Transform platform, Transform ramp)
		{
			//IL_0154: 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)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: 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_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: 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_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)platform == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("ExtractionPoint '" + ((Object)extractionPoint).name + "' has no platform Transform. Skipping crystal rather than guessing a height."));
				return null;
			}
			if (!TryGetPlatformDeck(platform, out var _, out var _, out var bestBounds, out var sourceName, out var surfaceTransform))
			{
				Renderer[] componentsInChildren = ((Component)platform).GetComponentsInChildren<Renderer>(true);
				Collider[] componentsInChildren2 = ((Component)platform).GetComponentsInChildren<Collider>(true);
				string text = string.Join(", ", componentsInChildren.Where((Renderer r) => (Object)(object)r != (Object)null).Select(delegate(Renderer r)
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					//IL_0014: Unknown result type (might be due to invalid IL or missing references)
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					string name = ((Object)r).name;
					Bounds bounds = r.bounds;
					Vector3 size = ((Bounds)(ref bounds)).size;
					return name + ":" + ((Vector3)(ref size)).ToString("F2");
				}).ToArray());
				string text2 = string.Join(", ", componentsInChildren2.Where((Collider c) => (Object)(object)c != (Object)null).Select(delegate(Collider c)
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					//IL_0014: Unknown result type (might be due to invalid IL or missing references)
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					string name = ((Object)c).name;
					Bounds bounds = c.bounds;
					Vector3 size = ((Bounds)(ref bounds)).size;
					return name + ":" + ((Vector3)(ref size)).ToString("F2");
				}).ToArray());
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not identify a horizontal deck mesh/collider under ExtractionPoint.platform '" + ((Object)platform).name + "'. No guessed crystal position was used. Platform renderers=[" + text + "]; colliders=[" + text2 + "]."));
				return null;
			}
			Vector3 val = Vector3.zero;
			if ((Object)(object)ramp != (Object)null)
			{
				val = Vector3.ProjectOnPlane(platform.InverseTransformPoint(ramp.position) - ((Bounds)(ref bestBounds)).center, Vector3.up);
			}
			Vector3 back = default(Vector3);
			if (((Vector3)(ref val)).sqrMagnitude > 0.04f)
			{
				if (Mathf.Abs(val.x) > Mathf.Abs(val.z))
				{
					((Vector3)(ref back))..ctor((val.x > 0f) ? (-1f) : 1f, 0f, 0f);
				}
				else
				{
					((Vector3)(ref back))..ctor(0f, 0f, (val.z > 0f) ? (-1f) : 1f);
				}
			}
			else
			{
				back = Vector3.back;
			}
			Vector3 center = ((Bounds)(ref bestBounds)).center;
			center.y = ((Bounds)(ref bestBounds)).max.y - 0.05f;
			Quaternion val2 = Quaternion.LookRotation(back, Vector3.up);
			Vector3 val3 = platform.TransformPoint(center);
			Quaternion cachedWorldRotation = platform.rotation * val2;
			PadState padState = new PadState
			{
				ExtractionPoint = extractionPoint,
				TerminalScreenText = GetTerminalScreenText(extractionPoint),
				Platform = platform,
				SurplusSpawnTransform = GetTransformField(_surplusSpawnTransformField, extractionPoint),
				HasSurplusSpawnPosition = ((Object)(object)GetTransformField(_surplusSpawnTransformField, extractionPoint) != (Object)null),
				SurplusSpawnPosition = (((Object)(object)GetTransformField(_surplusSpawnTransformField, extractionPoint) != (Object)null) ? GetTransformField(_surplusSpawnTransformField, extractionPoint).position : val3),
				SurplusAmount = Math.Max(0, ReadInt(_haulCurrentField, extractionPoint, 0) - ReadInt(_haulGoalField, extractionPoint, 0)),
				PlatformLocalPosition = center,
				PlatformLocalRotation = val2,
				CachedWorldPosition = val3,
				CachedWorldRotation = cachedWorldRotation,
				Scene = extractionPoint.gameObject.scene,
				PanelRoot = null,
				EnergyFraction = 0.0,
				LastVisualSegments = -1,
				NextItemScan = 0f,
				HasRewardedThisExtraction = false,
				PendingRewardSignature = string.Empty,
				PendingRewardSince = -1f,
				QuotaReached = (ReadInt(_haulGoalField, extractionPoint, 0) > 0 && ReadInt(_haulCurrentField, extractionPoint, 0) >= ReadInt(_haulGoalField, extractionPoint, 0)),
				CompletionStateSeen = false,
				ClosureObservedAt = -1f
			};
			BindNetworkRelay(padState);
			if ((Object)(object)padState.PhotonView != (Object)null)
			{
				padState.SourcePhotonViewId = padState.PhotonView.ViewID;
			}
			RefreshCrystal(padState, broadcast: false);
			if ((Object)(object)padState.TerminalScreenText != (Object)null)
			{
				LogTerminalAnchorHierarchy(padState.TerminalScreenText);
			}
			BuildTerminalEnergyMonitor(padState);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Warehouse Energy registered an invisible crystal tracker at ExtractionPoint '" + ((Object)extractionPoint).name + "', platform '" + ((Object)platform).name + "', deckSource='" + sourceName + "', deckObject='" + (((Object)(object)surfaceTransform != (Object)null) ? ((Object)surfaceTransform).name : "none") + "'. Crystal will remain hidden until State.Complete has been observed and the collection point/platform is inactive. SavedWorldPosition=" + ((Vector3)(ref val3)).ToString("F3") + ", floorOffset=-0.05m, height=" + _crystalHeight.Value.ToString("0.00") + "m."));
			return padState;
		}

		private bool IsExtractionCompleteState(Component extractionPoint)
		{
			if ((Object)(object)extractionPoint == (Object)null || _currentStateField == null || _completeStateValue == null)
			{
				return false;
			}
			try
			{
				return _currentStateField.GetValue(extractionPoint)?.Equals(_completeStateValue) ?? false;
			}
			catch (Exception ex)
			{
				LogDebug("Could not read ExtractionPoint.currentState: " + ex.GetBaseException().Message);
				return false;
			}
		}

		private GameObject GetSurplusPrefab(object assetManager, int surplusAmount)
		{
			if (assetManager == null)
			{
				return null;
			}
			FieldInfo fieldInfo = ((surplusAmount > 10000) ? _surplusValuableBigField : ((surplusAmount > 5000) ? _surplusValuableMediumField : _surplusValuableSmallField));
			if (!(fieldInfo != null))
			{
				return null;
			}
			object? value = fieldInfo.GetValue(assetManager);
			return (GameObject)((value is GameObject) ? value : null);
		}

		private object GetAssetManagerInstance()
		{
			object obj = ((_assetManagerInstanceField != null) ? _assetManagerInstanceField.GetValue(null) : null);
			if (obj == null && _assetManagerInstanceProperty != null)
			{
				obj = _assetManagerInstanceProperty.GetValue(null, null);
			}
			return obj;
		}

		private void SpawnCrystalVisual(PadState pad)
		{
			//IL_00f2: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: 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_022b: Unknown result type (might be due to invalid IL or missing references)
			if (pad == null || pad.CrystalSpawnAttempted || (Object)(object)pad.PanelRoot != (Object)null || !pad.QuotaReached || !pad.CompletionStateSeen || !IsAuthority(pad))
			{
				return;
			}
			if (_assetManagerType == null || _valuableObjectType == null || _physGrabObjectType == null || _spawnTorqueField == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Cannot create physical crystal: AssetManager, ValuableObject, PhysGrabObject, or spawnTorque was not resolved.");
				return;
			}
			try
			{
				object assetManagerInstance = GetAssetManagerInstance();
				if (assetManagerInstance == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Physical crystal spawn is waiting for AssetManager.instance.");
					return;
				}
				int num = Math.Max(0, pad.SurplusAmount);
				GameObject surplusPrefab = GetSurplusPrefab(assetManagerInstance, num);
				if ((Object)(object)surplusPrefab == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("The vanilla surplus valuable prefab for surplus $" + num + " is null."));
					return;
				}
				Vector3 val = (pad.HasSurplusSpawnPosition ? pad.SurplusSpawnPosition : pad.CachedWorldPosition);
				Vector3 val2 = Random.insideUnitSphere * 0.1f;
				pad.CrystalSpawnAttempted = true;
				GameObject val3;
				if (PhotonNetwork.InRoom)
				{
					object[] array = new object[7]
					{
						surplusPrefab.transform.localScale.x,
						surplusPrefab.transform.localScale.y,
						surplusPrefab.transform.localScale.z,
						"FWE_CRYSTAL_PHYSICAL_V1",
						(float)pad.EnergyFraction,
						num,
						pad.SourcePhotonViewId
					};
					val3 = PhotonNetwork.InstantiateRoomObject("Valuables/" + ((Object)surplusPrefab).name, val, Quaternion.identity, (byte)0, array);
				}
				else
				{
					val3 = Object.Instantiate<GameObject>(surplusPrefab, val, Quaternion.identity);
				}
				if ((Object)(object)val3 == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"The game returned a null object while creating the physical crystal.");
					return;
				}
				Component component = val3.GetComponent(_physGrabObjectType);
				if ((Object)(object)component == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"The selected vanilla surplus prefab has no PhysGrabObject component. The physical crystal cannot be configured safely.");
					if (!PhotonNetwork.InRoom)
					{
						Object.Destroy((Object)(object)val3);
					}
					return;
				}
				_spawnTorqueField.SetValue(component, val2);
				PhotonView component2 = val3.GetComponent<PhotonView>();
				ConfigurePhysicalCrystal(val3, pad, (float)pad.EnergyFraction, num, component2, broadcastInitialState: true);
				if ((Object)(object)component2 != (Object)null)
				{
					_processedCrystalViewIds.Add(component2.ViewID);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Physical energy crystal spawned from the vanilla " + ((Object)surplusPrefab).name + " valuable prefab at " + ((Vector3)(ref val)).ToString("F3") + "; surplus=$" + num + "; tier=" + ((num > 10000) ? "BIG" : ((num > 5000) ? "MEDIUM" : "SMALL")) + "; spawnTorque=" + ((Vector3)(ref val2)).ToString("F3") + ". Original PhysGrabObject, Rigidbody, PhotonView and prefab colliders were retained."));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Physical crystal spawn failed: " + ex.GetBaseException()));
			}
		}

		private void ProcessNetworkCrystalSpawns()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PhotonView[] array = Object.FindObjectsOfType<PhotonView>();
				int num = 0;
				while (array != null && num < array.Length)
				{
					PhotonView val = array[num];
					if (!((Object)(object)val == (Object)null) && val.ViewID != 0 && !_processedCrystalViewIds.Contains(val.ViewID))
					{
						object[] instantiationData = val.InstantiationData;
						if (instantiationData != null && instantiationData.Length >= 7 && instantiationData[3] is string && string.Equals((string)instantiationData[3], "FWE_CRYSTAL_PHYSICAL_V1", StringComparison.Ordinal))
						{
							GameObject gameObject = ((Component)val).gameObject;
							if (!((Object)(object)gameObject == (Object)null) && gameObject.activeInHierarchy)
							{
								Scene scene = gameObject.scene;
								if (((Scene)(ref scene)).IsValid())
								{
									float num2 = Convert.ToSingle(instantiationData[4], CultureInfo.InvariantCulture);
									int num3 = Convert.ToInt32(instantiationData[5], CultureInfo.InvariantCulture);
									int num4 = Convert.ToInt32(instantiationData[6], CultureInfo.InvariantCulture);
									PadState padState = null;
									foreach (PadState value in _pads.Values)
									{
										if (value != null && value.SourcePhotonViewId == num4 && (Object)(object)value.PanelRoot == (Object)null)
										{
											padState = value;
											break;
										}
									}
									if (padState == null)
									{
										Component val2 = FindExtractionPointByPhotonView(num4);
										padState = new PadState
										{
											ExtractionPoint = val2,
											TerminalScreenText = GetTerminalScreenText(val2),
											Platform = GetTransformField(_platformField, val2),
											Scene = (((Object)(object)val2 != (Object)null) ? val2.gameObject.scene : gameObject.scene),
											CachedWorldPosition = gameObject.transform.position,
											CachedWorldRotation = gameObject.transform.rotation,
											EnergyFraction = Math.Max(0.0, Math.Min(7.0 / 75.0, num2)),
											SurplusAmount = num3,
											SourcePhotonViewId = num4,
											CrystalSpawnAttempted = true,
											QuotaReached = true,
											CompletionStateSeen = true,
											ClosureObservedAt = Time.unscaledTime,
											LastVisualSegments = -1,
											NextItemScan = 0f
										};
										int instanceID = ((Object)gameObject).GetInstanceID();
										if (!_pads.ContainsKey(instanceID))
										{
											_pads.Add(instanceID, padState);
										}
									}
									ConfigurePhysicalCrystal(gameObject, padState, num2, num3, val, broadcastInitialState: false);
									_processedCrystalViewIds.Add(val.ViewID);
								}
							}
						}
					}
					num++;
				}
			}
			catch (Exception ex)
			{
				LogDebug("Network crystal discovery failed: " + ex.GetBaseException().Message);
			}
		}

		private void ConfigurePhysicalCrystal(GameObject root, PadState pad, float energy, int surplus, PhotonView view, bool broadcastInitialState)
		{
			//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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)root == (Object)null || pad == null || pad.PhysicalCrystalConfigured)
			{
				return;
			}
			pad.PhysicalCrystalConfigured = true;
			pad.CrystalSpawnAttempted = true;
			pad.PanelRoot = root;
			pad.Scene = root.scene;
			pad.EnergyFraction = Math.Max(0.0, Math.Min(7.0 / 75.0, energy));
			pad.SurplusAmount = Math.Max(0, surplus);
			pad.CachedWorldPosition = root.transform.position;
			pad.CachedWorldRotation = root.transform.rotation;
			PrepareCrystalAsNonValuable(root);
			Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
			Bounds bounds;
			bool flag = TryGetPrefabVisualBounds(root.transform, componentsInChildren, out bounds);
			if (componentsInChildren != null)
			{
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)null)
					{
						componentsInChildren[i].enabled = false;
					}
				}
			}
			pad.PhysicalPrefabBounds = (Bounds)(flag ? bounds : new Bounds(Vector3.zero, new Vector3(0.8f, _crystalHeight.Value, 0.8f)));
			pad.DisplayHeight = Mathf.Max(0.25f, ((Bounds)(ref pad.PhysicalPrefabBounds)).size.y);
			BuildCrystal(pad);
			RefreshCrystal(pad, broadcast: false);
			pad.PhotonView = view;
			if ((Object)(object)view != (Object)null)
			{
				WarehouseEnergyNetwork warehouseEnergyNetwork = root.GetComponent<WarehouseEnergyNetwork>();
				if ((Object)(object)warehouseEnergyNetwork == (Object)null)
				{
					warehouseEnergyNetwork = root.AddComponent<WarehouseEnergyNetwork>();
				}
				warehouseEnergyNetwork.Bind(this, pad, view);
				pad.NetworkRelay = warehouseEnergyNetwork;
				if (broadcastInitialState && PhotonNetwork.InRoom)
				{
					pad.NextNetworkEnergySync = Time.unscaledTime + 0.2f;
				}
			}
			string[] obj = new string[5] { "Configured physical crystal on vanilla surplus physics prefab. RendererBounds=", null, null, null, null };
			Vector3 val = ((Bounds)(ref pad.PhysicalPrefabBounds)).size;
			obj[1] = ((Vector3)(ref val)).ToString("F3");
			obj[2] = "; localCenter=";
			val = ((Bounds)(ref pad.PhysicalPrefabBounds)).center;
			obj[3] = ((Vector3)(ref val)).ToString("F3");
			obj[4] = "; valuable behaviour removed and physics presets retained.";
			LogDebug(string.Concat(obj));
		}

		private void PrepareCrystalAsNonValuable(GameObject root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			Component[] array = (Component[])((_valuableObjectType != null) ? ((Array)root.GetComponentsInChildren(_valuableObjectType, true)) : ((Array)new Component[0]));
			Component val = null;
			for (int i = 0; i < array.Length; i++)
			{
				if ((Object)(object)array[i] != (Object)null)
				{
					val = array[i];
					break;
				}
			}
			if (_notValuableObjectType != null)
			{
				Component val2 = root.GetComponent(_notValuableObjectType);
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = root.AddComponent(_notValuableObjectType);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					if ((Object)(object)val != (Object)null)
					{
						CopyComponentField(val, val2, "physAttributePreset");
						CopyComponentField(val, val2, "durabilityPreset");
						CopyComponentField(val, val2, "particleColors");
						CopyComponentField(val, val2, "audioPreset");
						CopyComponentField(val, val2, "audioPresetPitch");
					}
					if (_notValuableHasHealthField != null)
					{
						try
						{
							_notValuableHasHealthField.SetValue(val2, false);
						}
						catch (Exception ex)
						{
							LogDebug("Could not disable NotValuableObject health: " + ex.GetBaseException().Message);
						}
					}
				}
			}
			foreach (Component val3 in array)
			{
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				SetNumericField(_dollarValueOverrideField, val3, 0);
				SetNumericField(_dollarValueOriginalField, val3, 0);
				SetNumericField(_dollarValueCurrentField, val3, 0);
				if (_dollarValueSetField != null)
				{
					try
					{
						_dollarValueSetField.SetValue(val3, true);
					}
					catch
					{
					}
				}
				Behaviour val4 = (Behaviour)(object)((val3 is Behaviour) ? val3 : null);
				if ((Object)(object)val4 != (Object)null)
				{
					val4.enabled = false;
				}
				Object.Destroy((Object)(object)val3);
			}
			if (_surplusValuableType != null)
			{
				Component[] componentsInChildren = root.GetComponentsInChildren(_surplusValuableType, true);
				int num = 0;
				while (componentsInChildren != null && num < componentsInChildren.Length)
				{
					if ((Object)(object)componentsInChildren[num] != (Object)null)
					{
						Object.Destroy((Object)(object)componentsInChildren[num]);
					}
					num++;
				}
			}
			if (_physGrabObjectImpactDetectorType != null)
			{
				Component[] componentsInChildren2 = root.GetComponentsInChildren(_physGrabObjectImpactDetectorType, true);
				int num2 = 0;
				while (componentsInChildren2 != null && num2 < componentsInChildren2.Length)
				{
					Component val5 = componentsInChildren2[num2];
					if (!((Object)(object)val5 == (Object)null))
					{
						try
						{
							if (_impactDetectorIsValuableField != null)
							{
								_impactDetectorIsValuableField.SetValue(val5, false);
							}
							if (_impactDetectorValuableObjectField != null)
							{
								_impactDetectorValuableObjectField.SetValue(val5, null);
							}
							if (_impactDetectorFragilityField != null)
							{
								_impactDetectorFragilityField.SetValue(val5, 0f);
							}
						}
						catch (Exception ex2)
						{
							LogDebug("Could not fully protect crystal impact detector: " + ex2.GetBaseException().Message);
						}
					}
					num2++;
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Crystal converted to a non-valuable physics object. NonValuable health disabled, copied vanilla physics presets, impact fragility=0; PhysGrabObject, Rigidbody, PhotonView and colliders retained.");
		}

		private static void CopyComponentField(Component source, Component target, string fieldName)
		{
			if ((Object)(object)source == (Object)null || (Object)(object)target == (Object)null || string.IsNullOrEmpty(fieldName))
			{
				return;
			}
			try
			{
				FieldInfo field = ((object)source).GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field2 = ((object)target).GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (!(field == null) && !(field2 == null) && field2.FieldType.IsAssignableFrom(field.FieldType))
				{
					field2.SetValue(target, field.GetValue(source));
				}
			}
			catch
			{
			}
		}

		private static void SetNumericField(FieldInfo field, object target, int value)
		{
			if (field == null || target == null)
			{
				return;
			}
			try
			{
				field.SetValue(target, Convert.ChangeType(value, field.FieldType, CultureInfo.InvariantCulture));
			}
			catch
			{
			}
		}

		private static bool TryGetPrefabVisualBounds(Transform root, Renderer[] renderers, out Bounds bounds)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00d3: 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_00f3: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_013e: 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_0144: 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_014b: 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)
			bounds = new Bounds(Vector3.zero, Vector3.zero);
			if ((Object)(object)root == (Object)null || renderers == null)
			{
				return false;
			}
			bool flag = false;
			Vector3 val2 = default(Vector3);
			foreach (Renderer val in renderers)
			{
				if ((Object)(object)val == (Object)null || (!(val is MeshRenderer) && !(val is SkinnedMeshRenderer)))
				{
					continue;
				}
				string text = ((Object)((Component)val).gameObject).name.ToLowerInvariant();
				if (text.Contains("text") || text.Contains("label") || text.Contains("value") || text.Contains("dollar") || text.Contains("canvas") || text.Contains("icon"))
				{
					continue;
				}
				Bounds localBounds = val.localBounds;
				Vector3 min = ((Bounds)(ref localBounds)).min;
				Vector3 max = ((Bounds)(ref localBounds)).max;
				for (int j = 0; j < 8; j++)
				{
					((Vector3)(ref val2))..ctor(((j & 1) == 0) ? min.x : max.x, ((j & 2) == 0) ? min.y : max.y, ((j & 4) == 0) ? min.z : max.z);
					Vector3 val3 = root.InverseTransformPoint(((Component)val).transform.TransformPoint(val2));
					if (!flag)
					{
						bounds = new Bounds(val3, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(val3);
					}
				}
			}
			if (flag)
			{
				Vector3 size = ((Bounds)(ref bounds)).size;
				return ((Vector3)(ref size)).sqrMagnitude > 0.0001f;
			}
			return false;
		}

		private bool TryGetPlatformDeck(Transform platform, out Renderer bestRenderer, out Collider bestCollider, out Bounds bestBounds, out string sourceName, out Transform surfaceTransform)
		{
			//IL_0008: 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_0079: 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_0084: 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_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_00a8: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: 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_0191: 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_01a4: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			bestRenderer = null;
			bestCollider = null;
			bestBounds = default(Bounds);
			sourceName = "none";
			surfaceTransform = null;
			if ((Object)(object)platform == (Object)null)
			{
				return false;
			}
			float num = 0f;
			Renderer[] componentsInChildren = ((Component)platform).GetComponentsInChildren<Renderer>(true);
			int num2 = 0;
			while (componentsInChildren != null && num2 < componentsInChildren.Length)
			{
				Renderer val = componentsInChildren[num2];
				if (!((Object)(object)val == (Object)null) && val.enabled && ((Component)val).gameObject.activeInHierarchy)
				{
					Vector3 up = ((Component)val).transform.up;
					Vector3 normalized = ((Vector3)(ref up)).normalized;
					up = platform.up;
					if (!(Vector3.Dot(normalized, ((Vector3)(ref up)).normalized) < 0.92f))
					{
						Bounds val2 = TransformRendererBoundsToPlatformLocal(val, platform);
						if (!(((Bounds)(ref val2)).size.y > 0.85f) && !(((Bounds)(ref val2)).size.x < 1.25f) && !(((Bounds)(ref val2)).size.z < 1.25f))
						{
							float num3 = ((Bounds)(ref val2)).size.x * ((Bounds)(ref val2)).size.z;
							if (num3 > num)
							{
								num = num3;
								bestRenderer = val;
								bestCollider = null;
								bestBounds = val2;
								sourceName = "PlatformRendererLocalBounds";
								surfaceTransform = ((Component)val).transform;
							}
						}
					}
				}
				num2++;
			}
			if ((Object)(object)bestRenderer != (Object)null)
			{
				return true;
			}
			Collider[] componentsInChildren2 = ((Component)platform).GetComponentsInChildren<Collider>(true);
			int num4 = 0;
			while (componentsInChildren2 != null && num4 < componentsInChildren2.Length)
			{
				Collider val3 = componentsInChildren2[num4];
				if (!((Object)(object)val3 == (Object)null) && val3.enabled && ((Component)val3).gameObject.activeInHierarchy)
				{
					Bounds val4 = TransformWorldBoundsToPlatformLocal(val3.bounds, platform);
					if (!(((Bounds)(ref val4)).size.y > 0.85f) && !(((Bounds)(ref val4)).size.x < 1.25f) && !(((Bounds)(ref val4)).size.z < 1.25f))
					{
						float num5 = ((Bounds)(ref val4)).size.x * ((Bounds)(ref val4)).size.z;
						if (num5 > num)
						{
							num = num5;
							bestCollider = val3;
							bestBounds = val4;
							sourceName = "PlatformColliderLocalBounds";
							surfaceTransform = ((Component)val3).transform;
						}
					}
				}
				num4++;
			}
			if (!((Object)(object)bestRenderer != (Object)null))
			{
				return (Object)(object)bestCollider != (Object)null;
			}
			return true;
		}

		private static Bounds TransformRendererBoundsToPlatformLocal(Renderer renderer, Transform platform)
		{
			//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_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_0011: 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_001e: 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_0030: 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)
			//IL_003f: 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_0043: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			Bounds localBounds = renderer.localBounds;
			Vector3 min = ((Bounds)(ref localBounds)).min;
			Vector3 max = ((Bounds)(ref localBounds)).max;
			Vector3 val = platform.InverseTransformPoint(((Component)renderer).transform.TransformPoint(new Vector3(min.x, min.y, min.z)));
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(val, Vector3.zero);
			Vector3 val2 = default(Vector3);
			for (int i = 0; i <= 1; i++)
			{
				for (int j = 0; j <= 1; j++)
				{
					for (int k = 0; k <= 1; k++)
					{
						((Vector3)(ref val2))..ctor((i == 0) ? min.x : max.x, (j == 0) ? min.y : max.y, (k == 0) ? min.z : max.z);
						((Bounds)(ref result)).Encapsulate(platform.InverseTransformPoint(((Component)renderer).transform.TransformPoint(val2)));
					}
				}
			}
			return result;
		}

		private static Bounds TransformWorldBoundsToPlatformLocal(Bounds source, Transform platform)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0028: 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_0030: 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_00b7: 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_0050: 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_0062: 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_0074: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 min = ((Bounds)(ref source)).min;
			Vector3 max = ((Bounds)(ref source)).max;
			Vector3 val = platform.InverseTransformPoint(new Vector3(min.x, min.y, min.z));
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(val, Vector3.zero);
			Vector3 val2 = default(Vector3);
			for (int i = 0; i <= 1; i++)
			{
				for (int j = 0; j <= 1; j++)
				{
					for (int k = 0; k <= 1; k++)
					{
						((Vector3)(ref val2))..ctor((i == 0) ? min.x : max.x, (j == 0) ? min.y : max.y, (k == 0) ? min.z : max.z);
						((Bounds)(ref result)).Encapsulate(platform.InverseTransformPoint(val2));
					}
				}
			}
			return result;
		}

		private void BuildCrystal(PadState pad)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Expected O, but got Unknown
			//IL_0242: 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_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: 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_0308: 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_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: 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)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_0515: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: 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)
			if (pad == null || (Object)(object)pad.PanelRoot == (Object)null)
			{
				return;
			}
			if ((Object)(object)pad.PresentationRoot != (Object)null)
			{
				Object.Destroy((Object)(object)pad.PresentationRoot);
			}
			GameObject val = new GameObject("Fan_WarehouseEnergy_Crystal_Presentation");
			val.transform.SetParent(pad.PanelRoot.transform, false);
			pad.PresentationRoot = val;
			Bounds physicalPrefabBounds = pad.PhysicalPrefabBounds;
			Vector3 size = ((Bounds)(ref physicalPrefabBounds)).size;
			if (size.x < 0.05f || size.y < 0.05f || size.z < 0.05f)
			{
				((Vector3)(ref size))..ctor(0.8f, Mathf.Clamp(_crystalHeight.Value, 0.5f, 3.5f), 0.8f);
				((Bounds)(ref physicalPrefabBounds))..ctor(new Vector3(0f, size.y * 0.5f, 0f), size);
			}
			float num = Mathf.Max(0.25f, size.y);
			if ((Object)(object)_crystalMesh != (Object)null && (Object)(object)_crystalMaterial != (Object)null)
			{
				GameObject val2 = new GameObject("Gold_Power_Crystal_Model");
				val2.transform.SetParent(val.transform, false);
				Bounds bounds = _crystalMesh.bounds;
				Vector3 size2 = ((Bounds)(ref bounds)).size;
				val2.transform.localPosition = new Vector3(((Bounds)(ref physicalPrefabBounds)).center.x, ((Bounds)(ref physicalPrefabBounds)).min.y, ((Bounds)(ref physicalPrefabBounds)).center.z);
				val2.transform.localRotation = Quaternion.identity;
				val2.transform.localScale = new Vector3(size.x / Mathf.Max(0.0001f, size2.x), size.y / Mathf.Max(0.0001f, size2.y), size.z / Mathf.Max(0.0001f, size2.z));
				val2.AddComponent<MeshFilter>().sharedMesh = _crystalMesh;
				MeshRenderer obj = val2.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterial = _crystalMaterial;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
				((Renderer)obj).receiveShadows = true;