Decompiled source of SISYPHUS 15 v1.0.0

TrackAppearance.dll

Decompiled 3 days ago
using System;
using System.Collections;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Rendering;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
using WKMapLoader;

[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("TrackAppearance")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TrackAppearance")]
[assembly: AssemblyTitle("TrackAppearance")]
[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 TrackAppearance
{
	public sealed class TrackUnlimitedVendor : MonoBehaviour
	{
		private ENV_VendingMachine vm;

		private List<Purchase> enforcedPurchases;

		private MethodInfo updateButtonsMethod;

		public void Initialize(ENV_VendingMachine target, List<Purchase> purchases)
		{
			vm = target;
			enforcedPurchases = purchases;
			updateButtonsMethod = typeof(ENV_VendingMachine).GetMethod("UpdateButtons", BindingFlags.Instance | BindingFlags.NonPublic);
			ApplyNow();
		}

		private void Start()
		{
			ApplyNow();
		}

		private void LateUpdate()
		{
			if ((Object)(object)vm == (Object)null || vm.buttons == null)
			{
				return;
			}
			vm.singlePurchase = false;
			vm.ignoreRequirements = true;
			vm.randomGeneration = false;
			bool flag = false;
			for (int i = 0; i < vm.buttons.Length; i++)
			{
				VendingButton val = vm.buttons[i];
				if (val != null)
				{
					if (!val.available)
					{
						val.available = true;
						flag = true;
					}
					if (enforcedPurchases != null && enforcedPurchases.Count > 0 && val.purchase == null)
					{
						val.purchase = enforcedPurchases[i % enforcedPurchases.Count];
						flag = true;
					}
				}
			}
			if (flag)
			{
				updateButtonsMethod?.Invoke(vm, null);
			}
		}

		public void ApplyNow()
		{
			if ((Object)(object)vm == (Object)null || enforcedPurchases == null || enforcedPurchases.Count == 0)
			{
				return;
			}
			vm.singlePurchase = false;
			vm.randomGeneration = false;
			vm.fillFromPurchaseListInOrder = true;
			vm.ignoreRequirements = true;
			vm.vendorId = "";
			vm.purchaseList = new List<Purchase>(enforcedPurchases);
			FieldInfo field = typeof(ENV_VendingMachine).GetField("hasGenerated", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(vm, true);
			}
			if (vm.buttons != null)
			{
				for (int i = 0; i < vm.buttons.Length; i++)
				{
					if (vm.buttons[i] != null)
					{
						vm.buttons[i].purchase = enforcedPurchases[i % enforcedPurchases.Count];
						vm.buttons[i].available = true;
					}
				}
			}
			updateButtonsMethod?.Invoke(vm, null);
		}
	}
	[BepInPlugin("local.whiteknuckle.trackappearance", "TRACK Visuals, Lighting & Props", "0.9.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Appearance : BaseUnityPlugin
	{
		private sealed class MeshEntry
		{
			public bool HasUv;

			public string[] SubmeshMaterials;

			public Vector2[] UV;

			public Vector3[] Normals;
		}

		private struct PropSpawn
		{
			public Vector3 Position;

			public float YawDeg;

			public Vector3 Size;
		}

		private sealed class SidecarData
		{
			public readonly Dictionary<string, MeshEntry> Meshes = new Dictionary<string, MeshEntry>(StringComparer.Ordinal);

			public readonly List<Vector3> Cube14Offsets = new List<Vector3>();

			public readonly List<PropSpawn> Crates = new List<PropSpawn>();

			public readonly List<PropSpawn> Vendors = new List<PropSpawn>();

			public Vector3 ProjectorPosition = new Vector3(0f, 133f, 0f);
		}

		[HarmonyPatch(typeof(FXManager), "FXRender")]
		private static class FxRenderEnforcePatch
		{
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			private static void Postfix()
			{
				Instance?.EnforceShaderGlobals();
			}
		}

		[HarmonyPatch(typeof(HandItem_Buff), "Activate")]
		private static class InjectorTurboPatch
		{
			[HarmonyPostfix]
			private static void Postfix(HandItem_Buff __instance)
			{
				Instance?.OnHandItemBuffActivated(__instance);
			}
		}

		[HarmonyPatch(typeof(CL_CameraControl), "ShakeCamera", new Type[] { typeof(float) })]
		private static class NoScreenShakeFloatPatch
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				if (!((Object)(object)Instance == (Object)null))
				{
					return !Instance.ShouldSuppressScreenShake;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(CL_CameraControl), "ShakeCamera", new Type[]
		{
			typeof(Vector3),
			typeof(float),
			typeof(float)
		})]
		private static class NoScreenShakePosPatch
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				if (!((Object)(object)Instance == (Object)null))
				{
					return !Instance.ShouldSuppressScreenShake;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(CL_CameraControl), "SetCameraSway", new Type[]
		{
			typeof(float),
			typeof(float)
		})]
		private static class NoCameraSwayPatch
		{
			[HarmonyPrefix]
			private static void Prefix(ref float amount)
			{
				if ((Object)(object)Instance != (Object)null && Instance.ShouldSuppressScreenShake)
				{
					amount = 0f;
				}
			}
		}

		[HarmonyPatch(typeof(CL_CameraControl), "LateUpdate")]
		private static class NoScreenShakeLateUpdatePatch
		{
			[HarmonyPostfix]
			private static void Postfix(CL_CameraControl __instance, ref float ___shakeAmount, ref float ___swayAmount, ref float ___curSway)
			{
				//IL_0053: 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)
				if (!((Object)(object)Instance == (Object)null) && Instance.ShouldSuppressScreenShake && !((Object)(object)__instance == (Object)null))
				{
					___shakeAmount = 0f;
					___swayAmount = 0f;
					___curSway = 0f;
					if (((Component)__instance).transform.childCount > 0)
					{
						Transform child = ((Component)__instance).transform.GetChild(0);
						child.localPosition = Vector3.zero;
						child.localRotation = Quaternion.identity;
					}
				}
			}
		}

		private const string TargetLevelName = "map_TRACK_start_test";

		private const float RowStepX = 3156.93f;

		private const float TowerStepZ = 235.90077f;

		private const float DeckY = 15f;

		private Harmony harmony;

		private M_Level activeLevel;

		private CommandConsole registeredConsole;

		private FXManager boundFxManager;

		private Action<Camera> preRenderDelegate;

		private bool loggedDefaultFx;

		private bool cameraSaved;

		private CameraClearFlags origClearFlags;

		private Color origBgColor;

		private float origFarClip;

		private bool lightDistSaved;

		private float origWorldLightDist;

		private bool ambientPlaying;

		private AudioSource customAmbientSource;

		private GameObject lightingRoot;

		private GameObject playerLightGo;

		private CL_Lamp playerLamp;

		private readonly List<CL_Lamp> dynamicTowerLamps = new List<CL_Lamp>();

		private float nextTowerLightRefresh;

		private GameObject verticalFogRoot;

		private Mesh verticalFogMesh;

		private bool hammerCheckedForEntry;

		private readonly Dictionary<string, Material> fallbackMatCache = new Dictionary<string, Material>(StringComparer.OrdinalIgnoreCase);

		private readonly Dictionary<string, Texture2D> texCache = new Dictionary<string, Texture2D>(StringComparer.OrdinalIgnoreCase);

		private readonly List<(Material mat, bool isTop, float alpha, float depthT, bool isNativeUnlit)> verticalFogMats = new List<(Material, bool, float, float, bool)>();

		private Dictionary<string, (string albedo, string emission)> texManifest;

		private GameObject cachedVendorPrefab;

		private bool vendorLoading;

		private ConfigEntry<bool> fxEnabled;

		private ConfigEntry<bool> lightsEnabled;

		private ConfigEntry<bool> verticalFogEnabled;

		private ConfigEntry<bool> spawnMegastructure;

		private ConfigEntry<bool> spawnInteractiveCrates;

		private ConfigEntry<bool> spawnInteractiveVendor;

		private ConfigEntry<bool> enableAmbientAudio;

		private ConfigEntry<bool> disableScreenShake;

		private ConfigEntry<float> fogMult;

		private ConfigEntry<float> fogTwoToneDist;

		private ConfigEntry<float> fogTwoToneOffset;

		private ConfigEntry<float> fogDitherAmount;

		private ConfigEntry<int> fogDitherLevels;

		private ConfigEntry<int> roundVerts;

		private ConfigEntry<float> lightOffset;

		private ConfigEntry<float> worldBright;

		private ConfigEntry<float> entityBright;

		private ConfigEntry<float> wiggleAmount;

		private ConfigEntry<float> dustMult;

		private ConfigEntry<float> farClip;

		private ConfigEntry<float> fallResetY;

		private ConfigEntry<float> playerLightRange;

		private ConfigEntry<float> playerLightIntensity;

		private ConfigEntry<float> injectorSpeedMult;

		private ConfigEntry<string> fogBottomHex;

		private ConfigEntry<string> fogTopHex;

		private ConfigEntry<string> skyHex;

		private ConfigEntry<string> worldTintHex;

		private ConfigEntry<string> minColHex;

		private readonly List<FXZoneStore> preservedFxZones = new List<FXZoneStore>(8);

		internal static Appearance Instance { get; private set; }

		internal bool IsTrackMapActive
		{
			get
			{
				if (fxEnabled != null && fxEnabled.Value && MapApi.InCustomMap)
				{
					return (Object)(object)activeLevel != (Object)null;
				}
				return false;
			}
		}

		internal bool ShouldSuppressScreenShake
		{
			get
			{
				if (disableScreenShake != null && disableScreenShake.Value && MapApi.InCustomMap)
				{
					return (Object)(object)activeLevel != (Object)null;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Expected O, but got Unknown
			//IL_0482: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Expected O, but got Unknown
			Instance = this;
			preRenderDelegate = OnPreRenderFX;
			fxEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Atmosphere", "Enabled", true, "Enable custom fog/lighting/breathing FX on TRACK.");
			fogMult = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "FogMultiplier", 0.000105f, "Exact SHDR_Base fog multiplier (0.000105 = 5 tower rows visible, 100% dissolved at 13.5km).");
			fogBottomHex = ((BaseUnityPlugin)this).Config.Bind<string>("Atmosphere", "FogBottomColor", "161511", "Deep smoky lower abyss fog color (hex sRGB).");
			fogTopHex = ((BaseUnityPlugin)this).Config.Bind<string>("Atmosphere", "FogTopColor", "302D25", "Upper & horizon haze color matching Blender render (hex sRGB).");
			skyHex = ((BaseUnityPlugin)this).Config.Bind<string>("Atmosphere", "SkyColor", "302D25", "Camera background haze color (matches FogTopColor for seamless dissolve).");
			fogTwoToneDist = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "FogTwoToneDist", 2.4f, "View-direction vertical two-tone gradient steepness.");
			fogTwoToneOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "FogTwoToneOffset", 0.35f, "Shifts two-tone horizon slightly down so sky/horizon stay uniform and abyss deepens below.");
			fogDitherLevels = ((BaseUnityPlugin)this).Config.Bind<int>("Atmosphere", "FogDitherLevels", 8, "Dither bands for distance fog dissolve (1..32).");
			fogDitherAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "FogDitherAmount", 0.42f, "Dithered distance dissolve width (0..1).");
			lightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "LightOffset", 0.08f, "Subtle ambient lift so dark unlit concrete stays textured without glare.");
			worldBright = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "WorldBright", 0.18f, "Restrained moody world base brightness (no blinding glare).");
			entityBright = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "EntityBright", 0.68f, "Entity/hand/prop brightness so hands, hammer, crates and vendor are crisp.");
			worldTintHex = ((BaseUnityPlugin)this).Config.Bind<string>("Atmosphere", "WorldTint", "EFE6CC", "Warm olive/sepia tint matching Blender render.");
			minColHex = ((BaseUnityPlugin)this).Config.Bind<string>("Atmosphere", "MinColor", "100F0C", "Shadow floor color in sRGB (converted to Linear for _WORLDMIN so shadows stay deep & moody).");
			roundVerts = ((BaseUnityPlugin)this).Config.Bind<int>("Atmosphere", "RoundVerts", 160, "PS1 vertex snapping / breathing jitter.");
			wiggleAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "WorldWiggle", 0.015f, "Organic megastructure breathing amplitude (kept active!).");
			dustMult = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "DustMult", 1.5f, "Atmospheric floating dust specks.");
			farClip = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "CameraFarClip", 25000f, "Far clip plane so megastructure never clips before dissolving into fog.");
			fallResetY = ((BaseUnityPlugin)this).Config.Bind<float>("Atmosphere", "FallResetY", -140f, "Safety fall respawn height inside abyss fog.");
			lightsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Lighting", "Enabled", true, "Enable restrained player aura, overhead projector, and subtle deck fill lamps.");
			playerLightRange = ((BaseUnityPlugin)this).Config.Bind<float>("Lighting", "PlayerLightRange", 20f, "Radius of natural soft light around player.");
			playerLightIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Lighting", "PlayerLightIntensity", 0.42f, "Intensity of natural soft light around player.");
			verticalFogEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Atmosphere", "VerticalTopBottomFog", true, "Enable 21-layer double-sided volumetric horizontal fog above (+170..+780m) and below (-42..-540m).");
			spawnMegastructure = ((BaseUnityPlugin)this).Config.Bind<bool>("Scene", "SpawnMegastructure", true, "Instantiate 360-degree shared-mesh megastructure towers (no bounding walls).");
			spawnInteractiveCrates = ((BaseUnityPlugin)this).Config.Bind<bool>("Scene", "SpawnInteractiveCrates", true, "Spawn native interactive crates.");
			spawnInteractiveVendor = ((BaseUnityPlugin)this).Config.Bind<bool>("Scene", "SpawnInteractiveVendor", true, "Spawn native interactive ENV_VendingMachine.");
			enableAmbientAudio = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "EnableWhiteKnuckleAudio", true, "Enable White Knuckle surface materials, cavern reverb, and ambience.");
			injectorSpeedMult = ((BaseUnityPlugin)this).Config.Bind<float>("Gameplay", "InjectorRealSpeedMultiplier", 5f, new ConfigDescription("Real top running speed multiplier per single Injector on TRACK (accounts for quadratic drag v~sqrt(1+addSpeed); 5.0 = 5x true speed!).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
			disableScreenShake = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "DisableScreenShake", true, "Disable all camera screen shake and camera sway on SISYPHUS // 15 so aiming and climbing stay steady.");
			MapApi.Tick += Tick;
			MapApi.MapReset += OnMapReset;
			EnsurePreRenderHookAttached();
			MapApi.RegisterCommand("trackfx", (Action<string[]>)HandleTrackFxCommand);
			harmony = new Harmony("local.whiteknuckle.trackappearance");
			harmony.PatchAll(typeof(FxRenderEnforcePatch));
			harmony.PatchAll(typeof(InjectorTurboPatch));
			harmony.PatchAll(typeof(NoScreenShakeFloatPatch));
			harmony.PatchAll(typeof(NoScreenShakePosPatch));
			harmony.PatchAll(typeof(NoCameraSwayPatch));
			harmony.PatchAll(typeof(NoScreenShakeLateUpdatePatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"TRACK Visuals v0.9.1 loaded (zero screen shake on SISYPHUS // 15, double-sided 12-layer ceiling fog, 3-sail colliders to ±11 towers, 8 dynamic tower lights, 5x real-speed Injector turbo, 1-roach Injectors).");
		}

		private void EnsurePreRenderHookAttached()
		{
			if (preRenderDelegate == null)
			{
				preRenderDelegate = OnPreRenderFX;
			}
			Action<Camera> onPreRenderFX = FXManager.OnPreRenderFX;
			if (onPreRenderFX == null || !onPreRenderFX.GetInvocationList().Contains(preRenderDelegate))
			{
				FXManager.OnPreRenderFX = (Action<Camera>)Delegate.Combine(FXManager.OnPreRenderFX, preRenderDelegate);
			}
			if ((Object)(object)FXManager.fxMan != (Object)null && (Object)(object)FXManager.fxMan != (Object)(object)boundFxManager)
			{
				boundFxManager = FXManager.fxMan;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Bound OnPreRenderFX to active Game-Main FXManager instance.");
			}
		}

		private void OnMapReset()
		{
			hammerCheckedForEntry = false;
			if (!MapApi.InCustomMap)
			{
				CleanupState();
			}
		}

		private void CleanupState()
		{
			activeLevel = null;
			hammerCheckedForEntry = false;
			lightingRoot = null;
			dynamicTowerLamps.Clear();
			nextTowerLightRefresh = 0f;
			verticalFogRoot = null;
			DestroyVerticalFogResources();
			if ((Object)(object)playerLightGo != (Object)null)
			{
				Object.Destroy((Object)(object)playerLightGo);
				playerLightGo = null;
				playerLamp = null;
			}
			RestoreCameraAndLightDistance();
			StopAmbientAudio();
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject != (Object)null && ((GameEntity)playerObject).curBuffs != null)
			{
				if (((GameEntity)playerObject).curBuffs.HasBuffContainer("TRACK_InjectorTurbo_1"))
				{
					((GameEntity)playerObject).curBuffs.RemoveBuffContainer("TRACK_InjectorTurbo_1");
				}
				if (((GameEntity)playerObject).curBuffs.HasBuffContainer("TRACK_InjectorTurbo_2"))
				{
					((GameEntity)playerObject).curBuffs.RemoveBuffContainer("TRACK_InjectorTurbo_2");
				}
			}
		}

		private void DestroyVerticalFogResources()
		{
			for (int i = 0; i < verticalFogMats.Count; i++)
			{
				if ((Object)(object)verticalFogMats[i].mat != (Object)null)
				{
					Object.Destroy((Object)(object)verticalFogMats[i].mat);
				}
			}
			verticalFogMats.Clear();
			if ((Object)(object)verticalFogMesh != (Object)null)
			{
				Object.Destroy((Object)(object)verticalFogMesh);
				verticalFogMesh = null;
			}
		}

		private void Update()
		{
			EnsureConsoleCommandRegistered();
			EnsurePreRenderHookAttached();
			if (!((Object)(object)activeLevel == (Object)null) && MapApi.InCustomMap)
			{
				UpdatePlayerLight();
				UpdateDynamicTowerLights();
				UpdateVerticalFogPosition();
			}
		}

		private void EnsureConsoleCommandRegistered()
		{
			CommandConsole instance = CommandConsole.instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)registeredConsole)
			{
				registeredConsole = instance;
				CommandConsole.AddCommand("trackfx", (Action<string[]>)HandleTrackFxCommand, false);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered 'trackfx' command directly with CommandConsole (cheat=false).");
			}
		}

		private void Tick()
		{
			//IL_0171: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			EnsureConsoleCommandRegistered();
			EnsurePreRenderHookAttached();
			if (!MapApi.InCustomMap || (Object)(object)WorldLoader.instance == (Object)null)
			{
				if ((Object)(object)activeLevel != (Object)null || cameraSaved || lightDistSaved)
				{
					CleanupState();
				}
				return;
			}
			LevelInfo currentLevel = WorldLoader.instance.GetCurrentLevel();
			M_Level val = ((currentLevel != null) ? currentLevel.GetLevel() : null);
			if ((Object)(object)val == (Object)null || val.levelName != "map_TRACK_start_test")
			{
				if ((Object)(object)activeLevel != (Object)null || cameraSaved || lightDistSaved)
				{
					CleanupState();
				}
				return;
			}
			activeLevel = val;
			ApplyCameraAndLightDistance();
			if (!hammerCheckedForEntry && (Object)(object)ENT_Player.playerObject != (Object)null && (Object)(object)Inventory.instance != (Object)null)
			{
				hammerCheckedForEntry = true;
				EnsureHammerInInventory();
			}
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((!((Object)(object)DEN_DeathFloor.instance != (Object)null) || !DEN_DeathFloor.instance.IsActive()) && (Object)(object)playerObject != (Object)null && !((GameEntity)playerObject).IsDead() && (Object)(object)val.spawnPosition != (Object)null && ((Component)playerObject).transform.position.y < fallResetY.Value)
			{
				((GameEntity)playerObject).Teleport(val.spawnPosition.position, val.spawnPosition.rotation, false);
			}
			if (!((Object)(object)((Component)val).transform.Find("TRACK_AppliedMarker") != (Object)null))
			{
				new GameObject("TRACK_AppliedMarker").transform.SetParent(((Component)val).transform, false);
				LogDefaultFxOnce();
				ApplySceneUpgrade(val);
			}
		}

		private string ResolveTrackMapsDir(string requiredFile)
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			if (!string.IsNullOrEmpty(directoryName))
			{
				string text = Path.Combine(directoryName, "maps");
				if (File.Exists(Path.Combine(text, requiredFile)))
				{
					return text;
				}
			}
			string text2 = Path.Combine(Paths.PluginPath, "WKMapLoader", "maps");
			if (File.Exists(Path.Combine(text2, requiredFile)))
			{
				return text2;
			}
			try
			{
				string[] files = Directory.GetFiles(Paths.PluginPath, requiredFile, SearchOption.AllDirectories);
				if (files.Length != 0)
				{
					return Path.GetDirectoryName(files[0]);
				}
			}
			catch
			{
			}
			return text2;
		}

		private void ApplySceneUpgrade(M_Level level)
		{
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			try
			{
				string path = ResolveTrackMapsDir("TRACK_start_test.appearance.bin");
				string path2 = Path.Combine(path, "TRACK_start_test.appearance.bin");
				string texDir = Path.Combine(path, "TRACK_textures");
				LoadTextureManifest(texDir);
				SidecarData sidecarData = ReadSidecar(path2);
				Material template = FindBaseShaderTemplate();
				int num = 0;
				int num2 = 0;
				int num3 = 0;
				int num4 = 0;
				MeshFilter val = null;
				MeshRenderer val2 = null;
				MeshFilter[] componentsInChildren = ((Component)level).GetComponentsInChildren<MeshFilter>(true);
				foreach (MeshFilter val3 in componentsInChildren)
				{
					Mesh sharedMesh = val3.sharedMesh;
					if ((Object)(object)sharedMesh == (Object)null || !sidecarData.Meshes.TryGetValue(((Object)sharedMesh).name, out var value))
					{
						continue;
					}
					if (sharedMesh.vertexCount != value.UV.Length)
					{
						num2++;
						((BaseUnityPlugin)this).Logger.LogError((object)$"Vertex mismatch on '{((Object)sharedMesh).name}': runtime={sharedMesh.vertexCount}, sidecar={value.UV.Length}");
						continue;
					}
					if (value.HasUv)
					{
						sharedMesh.uv = value.UV;
					}
					sharedMesh.normals = value.Normals;
					sharedMesh.RecalculateBounds();
					num++;
					MeshRenderer component = ((Component)val3).GetComponent<MeshRenderer>();
					if ((Object)(object)component != (Object)null && value.SubmeshMaterials != null && value.SubmeshMaterials.Length != 0)
					{
						Material[] sharedMaterials = ((Renderer)component).sharedMaterials;
						bool flag = false;
						for (int j = 0; j < sharedMaterials.Length && j < value.SubmeshMaterials.Length; j++)
						{
							if (IsFallbackMaterial(sharedMaterials[j]))
							{
								Material orCreateTexturedMaterial = GetOrCreateTexturedMaterial(value.SubmeshMaterials[j], template, texDir);
								if ((Object)(object)orCreateTexturedMaterial != (Object)null)
								{
									sharedMaterials[j] = orCreateTexturedMaterial;
									flag = true;
									num4++;
								}
							}
							else
							{
								num3++;
							}
						}
						if (((Object)sharedMesh).name == "Part · L_Light_2x2_01.010" && sharedMaterials.Length != 0 && (Object)(object)sharedMaterials[0] != (Object)null)
						{
							Material val4 = new Material(sharedMaterials[0])
							{
								name = "WKMap_TRACK_ProjectorGlow"
							};
							if (val4.HasProperty("_EmissionMultiplier"))
							{
								val4.SetFloat("_EmissionMultiplier", 1.5f);
							}
							sharedMaterials[0] = val4;
							flag = true;
						}
						if (flag)
						{
							((Renderer)component).sharedMaterials = sharedMaterials;
						}
					}
					if (enableAmbientAudio.Value)
					{
						AssignSurfaceMaterial(((Component)val3).gameObject, ((Object)sharedMesh).name);
					}
					if (((Object)sharedMesh).name == "Cube.014")
					{
						val = val3;
						val2 = component;
					}
					else if (((Object)sharedMesh).name == "TRACK_TheRadar_Body" || ((Object)sharedMesh).name == "TRACK_TheRadar_Button")
					{
						Collider[] components = ((Component)val3).gameObject.GetComponents<Collider>();
						for (int k = 0; k < components.Length; k++)
						{
							Object.Destroy((Object)(object)components[k]);
						}
						((Component)val3).gameObject.SetActive(false);
					}
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Restored UV/normals on {num} meshes (mismatches={num2}); materials native={num3}, PNG-restored={num4}.");
				if (spawnMegastructure.Value && (Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null && sidecarData.Cube14Offsets.Count > 0)
				{
					SpawnMegastructureInstances(((Component)level).transform, val, val2, sidecarData.Cube14Offsets);
				}
				ExpandLevelBounds(level);
				if (lightsEnabled.Value)
				{
					SpawnTrackLighting(((Component)level).transform, sidecarData);
				}
				SpawnVerticalFogDecks(((Component)level).transform, texDir);
				if (spawnInteractiveCrates.Value && sidecarData.Crates.Count > 0)
				{
					SpawnInteractiveCrates(((Component)level).transform, sidecarData.Crates);
				}
				if (spawnInteractiveVendor.Value && sidecarData.Vendors.Count > 0)
				{
					((MonoBehaviour)this).StartCoroutine(SpawnInteractiveVendorRoutine(level, sidecarData.Vendors[0]));
				}
				if (enableAmbientAudio.Value)
				{
					SetupWhiteKnuckleAudio(((Component)level).transform);
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("TRACK scene upgrade failed: " + ex));
			}
		}

		private static void AssignSurfaceMaterial(GameObject go, string meshName)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			ObjectMaterial val = go.GetComponent<ObjectMaterial>() ?? go.AddComponent<ObjectMaterial>();
			if (meshName == "Cube.003" || meshName == "NurbsPath.001")
			{
				val.type = (MaterialType)2;
			}
			else if (meshName.StartsWith("handhold", StringComparison.OrdinalIgnoreCase) || meshName.StartsWith("Part · Door", StringComparison.OrdinalIgnoreCase) || meshName.StartsWith("Part · Prop_EquipmentLocker", StringComparison.OrdinalIgnoreCase) || meshName.StartsWith("Part · L_Light", StringComparison.OrdinalIgnoreCase) || meshName.StartsWith("TRACK_Lift_", StringComparison.OrdinalIgnoreCase) || meshName.StartsWith("TRACK_TheRadar", StringComparison.OrdinalIgnoreCase))
			{
				val.type = (MaterialType)1;
			}
			else
			{
				val.type = (MaterialType)0;
			}
		}

		private void SpawnMegastructureInstances(Transform levelRoot, MeshFilter sourceFilter, MeshRenderer sourceRenderer, List<Vector3> offsets)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_017f: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: 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_01c3: 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_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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0241: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TRACK_Megastructure");
			val.transform.SetParent(levelRoot, false);
			Mesh sharedMesh = sourceFilter.sharedMesh;
			Material[] sharedMaterials = ((Renderer)sourceRenderer).sharedMaterials;
			for (int i = 0; i < sharedMaterials.Length; i++)
			{
				if ((Object)(object)sharedMaterials[i] != (Object)null)
				{
					sharedMaterials[i].enableInstancing = true;
				}
			}
			GameObject gameObject = ((Component)sourceFilter).gameObject;
			Vector3 position = gameObject.transform.position;
			Quaternion rotation = gameObject.transform.rotation;
			Vector3 lossyScale = gameObject.transform.lossyScale;
			int layer = gameObject.layer;
			GameObject val2 = null;
			MeshCollider[] componentsInChildren = ((Component)levelRoot).GetComponentsInChildren<MeshCollider>(true);
			foreach (MeshCollider val3 in componentsInChildren)
			{
				if (!((Object)(object)val3 == (Object)null) && !((Object)(object)((Component)val3).gameObject == (Object)(object)gameObject) && !((Object)(object)val3.sharedMesh == (Object)null) && !((Object)(object)((Component)val3).GetComponent<CL_Handhold>() == (Object)null) && val3.sharedMesh.vertexCount > 200)
				{
					Vector3 val4 = ((Component)val3).transform.position - position;
					if (((Vector3)(ref val4)).sqrMagnitude < 0.25f)
					{
						val2 = ((Component)val3).gameObject;
						break;
					}
				}
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			for (int k = 0; k < offsets.Count; k++)
			{
				Vector3 val5 = offsets[k];
				GameObject val6 = new GameObject($"Cube.014_inst_{k:000}");
				val6.layer = layer;
				val6.transform.SetParent(val.transform, false);
				val6.transform.position = position + val5;
				val6.transform.rotation = rotation;
				val6.transform.localScale = lossyScale;
				val6.AddComponent<MeshFilter>().sharedMesh = sharedMesh;
				((Renderer)val6.AddComponent<MeshRenderer>()).sharedMaterials = sharedMaterials;
				if (Mathf.Abs(val5.x) < 3300f && Mathf.Abs(val5.z) < 2650f)
				{
					val6.AddComponent<MeshCollider>().sharedMesh = sharedMesh;
					if (enableAmbientAudio.Value)
					{
						val6.AddComponent<ObjectMaterial>().type = (MaterialType)0;
					}
					num2++;
					if ((Object)(object)val2 != (Object)null)
					{
						((Object)Object.Instantiate<GameObject>(val2, val2.transform.position + val5, val2.transform.rotation, val.transform)).name = $"grip_inst_{k:000}";
						num3++;
					}
				}
				num++;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Spawned {0} 360-degree shared-mesh megastructure instances ({1} MeshColliders, {2} cloned grabbable ledge meshes; sourceLedge={3}).", num, num2, num3, ((Object)(object)val2 != (Object)null) ? ((Object)val2).name : "none"));
		}

		private void ExpandLevelBounds(M_Level level)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)level == (Object)null)
			{
				return;
			}
			Bounds val = default(Bounds);
			((Bounds)(ref val))..ctor(Vector3.zero, new Vector3(24000f, 4000f, 24000f));
			level.customBounds = true;
			level.levelBounds = val;
			FieldInfo field = typeof(M_Level).GetField("currentBoundsLocal", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(level, val);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Expanded M_Level local bounds to (24000, 4000, 24000) across full 360-degree megastructure.");
			}
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject != (Object)null)
			{
				FieldInfo field2 = typeof(ENT_Player).GetField("oobCounter", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field2 != null)
				{
					field2.SetValue(playerObject, 0f);
				}
			}
		}

		private void SpawnVerticalFogDecks(Transform levelRoot, string texDir)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			DestroyVerticalFogResources();
			verticalFogRoot = new GameObject("TRACK_VerticalFog");
			verticalFogRoot.transform.SetParent(levelRoot, false);
			verticalFogRoot.SetActive(verticalFogEnabled.Value && fxEnabled.Value);
			verticalFogMesh = BuildFogDeckMesh(14500f, 8);
			Texture2D fogTex = LoadPng(Path.Combine(texDir, "fog_sheet.png"), (FilterMode)1, (TextureWrapMode)0) ?? LoadPng(Path.Combine(texDir, "cloud_deck.png"), (FilterMode)1, (TextureWrapMode)0) ?? Texture2D.whiteTexture;
			Material nativeTemplate = ((IEnumerable<Material>)Resources.FindObjectsOfTypeAll<Material>()).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null && ((Object)m.shader).name == "Dark Machine/SHDR_Base_UnlitTransparent"));
			Shader fallbackShader = (((Object)(object)nativeTemplate != (Object)null) ? nativeTemplate.shader : (Shader.Find("Dark Machine/SHDR_Base_UnlitTransparent") ?? ((IEnumerable<Shader>)Resources.FindObjectsOfTypeAll<Shader>()).FirstOrDefault((Func<Shader, bool>)((Shader s) => (Object)(object)s != (Object)null && ((Object)s).name == "Dark Machine/SHDR_Base_UnlitTransparent")) ?? Shader.Find("Sprites/Default")));
			bool isNativeUnlit = (Object)(object)fallbackShader != (Object)null && ((Object)fallbackShader).name == "Dark Machine/SHDR_Base_UnlitTransparent";
			float[] heights = new float[9] { -42f, -68f, -100f, -140f, -190f, -255f, -335f, -430f, -540f };
			float[] layerAlphas = new float[9] { 0.18f, 0.24f, 0.3f, 0.38f, 0.48f, 0.6f, 0.74f, 0.9f, 1f };
			float[] layerUvScales = new float[9] { 22f, 18f, 14f, 11f, 9f, 7f, 5f, 4f, 1f };
			float[] heights2 = new float[12]
			{
				170f, 200f, 235f, 275f, 320f, 370f, 425f, 485f, 550f, 620f,
				700f, 780f
			};
			float[] layerAlphas2 = new float[12]
			{
				0.09f, 0.13f, 0.17f, 0.22f, 0.28f, 0.35f, 0.43f, 0.52f, 0.63f, 0.75f,
				0.88f, 1f
			};
			float[] layerUvScales2 = new float[12]
			{
				26f, 22f, 19f, 16f, 14f, 12f, 10f, 8f, 6f, 5f,
				3f, 1f
			};
			AddStack(heights, layerAlphas, layerUvScales, isTop: false);
			AddStack(heights2, layerAlphas2, layerUvScales2, isTop: true);
			UpdateVerticalFogColors();
			UpdateVerticalFogPosition();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Spawned 21-layer double-sided vertical fog decks (9 abyss [-42..-540m] + 12 ceiling [+170..+780m]) using shader '" + (((Object)(object)fallbackShader != (Object)null) ? ((Object)fallbackShader).name : "null") + "'."));
			void AddStack(float[] array, float[] array3, float[] array2, bool isTop)
			{
				//IL_003e: 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_0044: Expected O, but got Unknown
				//IL_0099: 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_025e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0263: Unknown result type (might be due to invalid IL or missing references)
				//IL_026a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0281: Unknown result type (might be due to invalid IL or missing references)
				//IL_0294: Unknown result type (might be due to invalid IL or missing references)
				//IL_029e: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < array.Length; i++)
				{
					bool flag = i == array.Length - 1;
					float item = (float)i / (float)(array.Length - 1);
					Material val = (((Object)(object)nativeTemplate != (Object)null) ? new Material(nativeTemplate) : new Material(fallbackShader));
					((Object)val).name = string.Format("WKMap_TRACK_FogDeck_{0}_{1:00}", isTop ? "Top" : "Bot", i);
					if (val.HasProperty("_MainTex"))
					{
						val.SetTexture("_MainTex", (Texture)(object)(flag ? Texture2D.whiteTexture : fogTex));
						val.SetTextureScale("_MainTex", Vector2.one * array2[i]);
					}
					if (isNativeUnlit)
					{
						if (val.HasProperty("_IgnoreFog"))
						{
							val.SetFloat("_IgnoreFog", 0f);
						}
						if (val.HasProperty("_Bright"))
						{
							val.SetFloat("_Bright", 0f);
						}
						if (val.HasProperty("_Shading"))
						{
							val.SetFloat("_Shading", 0f);
						}
						if (val.HasProperty("_DitherAmount"))
						{
							val.SetFloat("_DitherAmount", 0.38f);
						}
						if (val.HasProperty("_CorruptDistance"))
						{
							val.SetFloat("_CorruptDistance", 0f);
						}
						if (val.HasProperty("_Wiggle"))
						{
							val.SetFloat("_Wiggle", 0f);
						}
						if (val.HasProperty("_WorldWiggleModifier"))
						{
							val.SetFloat("_WorldWiggleModifier", 0f);
						}
						if (val.HasProperty("_ROUNDMULT"))
						{
							val.SetFloat("_ROUNDMULT", 0f);
						}
						float num = (flag ? 0f : (((i % 2 == 0) ? 1f : (-1f)) * (0.008f - (float)i * 0.0005f)));
						float num2 = (flag ? 0f : (((i % 3 == 0) ? 1f : (-1f)) * (0.004f - (float)i * 0.00025f)));
						if (val.HasProperty("_ScrollX"))
						{
							val.SetFloat("_ScrollX", num);
						}
						if (val.HasProperty("_ScrollY"))
						{
							val.SetFloat("_ScrollY", num2);
						}
					}
					val.renderQueue = 3001 + (array.Length - 1 - i);
					GameObject val2 = new GameObject(string.Format("FogDeck_{0}_{1:00}", isTop ? "Top" : "Bot", i))
					{
						layer = 0
					};
					val2.transform.SetParent(verticalFogRoot.transform, false);
					val2.transform.localPosition = new Vector3(0f, array[i], 0f);
					val2.AddComponent<MeshFilter>().sharedMesh = verticalFogMesh;
					MeshRenderer obj = val2.AddComponent<MeshRenderer>();
					((Renderer)obj).sharedMaterial = val;
					((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
					((Renderer)obj).receiveShadows = false;
					verticalFogMats.Add((val, isTop, array3[i], item, isNativeUnlit));
				}
			}
		}

		private static Mesh BuildFogDeckMesh(float halfSize, int cells)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: 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_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Expected O, but got Unknown
			int num = cells + 1;
			int num2 = num * num;
			Vector3[] array = (Vector3[])(object)new Vector3[num2 * 2];
			Vector2[] array2 = (Vector2[])(object)new Vector2[num2 * 2];
			Vector3[] array3 = (Vector3[])(object)new Vector3[num2 * 2];
			Color[] array4 = (Color[])(object)new Color[num2 * 2];
			int[] array5 = new int[cells * cells * 12];
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)i / (float)cells;
				float num4 = Mathf.Lerp(0f - halfSize, halfSize, num3);
				for (int j = 0; j < num; j++)
				{
					float num5 = (float)j / (float)cells;
					float num6 = Mathf.Lerp(0f - halfSize, halfSize, num5);
					int num7 = i * num + j;
					array[num7] = new Vector3(num6, 0f, num4);
					array2[num7] = new Vector2(num5, num3);
					array3[num7] = Vector3.up;
					array4[num7] = Color.white;
					int num8 = num2 + num7;
					array[num8] = new Vector3(num6, 0f, num4);
					array2[num8] = new Vector2(num5, num3);
					array3[num8] = Vector3.down;
					array4[num8] = Color.white;
				}
			}
			int num9 = 0;
			for (int k = 0; k < cells; k++)
			{
				for (int l = 0; l < cells; l++)
				{
					int num10 = k * num + l;
					int num11 = num10 + 1;
					int num12 = num10 + num;
					int num13 = num12 + 1;
					array5[num9++] = num10;
					array5[num9++] = num12;
					array5[num9++] = num11;
					array5[num9++] = num11;
					array5[num9++] = num12;
					array5[num9++] = num13;
					int num14 = num2 + num10;
					int num15 = num2 + num11;
					int num16 = num2 + num12;
					int num17 = num2 + num13;
					array5[num9++] = num14;
					array5[num9++] = num15;
					array5[num9++] = num16;
					array5[num9++] = num15;
					array5[num9++] = num17;
					array5[num9++] = num16;
				}
			}
			return new Mesh
			{
				name = "TRACK_VerticalFogDeckMesh",
				vertices = array,
				uv = array2,
				normals = array3,
				colors = array4,
				triangles = array5,
				bounds = new Bounds(Vector3.zero, new Vector3(halfSize * 4f, 4000f, halfSize * 4f))
			};
		}

		private void UpdateVerticalFogPosition()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)verticalFogRoot == (Object)null)
			{
				return;
			}
			bool flag = verticalFogEnabled.Value && fxEnabled.Value;
			if (verticalFogRoot.activeSelf != flag)
			{
				verticalFogRoot.SetActive(flag);
			}
			if (flag)
			{
				Camera main = Camera.main;
				if (!((Object)(object)main == (Object)null))
				{
					Vector3 position = ((Component)main).transform.position;
					verticalFogRoot.transform.position = new Vector3(position.x, 0f, position.z);
				}
			}
		}

		private void UpdateVerticalFogColors()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00ee: 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_00fd: Invalid comparison between Unknown and I4
			//IL_01a6: 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_01be: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0196: 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_0104: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			if (verticalFogMats.Count == 0)
			{
				return;
			}
			Color val = ParseHex(fogTopHex.Value, new Color(0.188f, 0.176f, 0.145f, 1f));
			Color val2 = ParseHex(fogBottomHex.Value, new Color(0.086f, 0.082f, 0.067f, 1f));
			Color val3 = ParseHex(worldTintHex.Value, new Color(0.937f, 0.902f, 0.8f, 1f));
			Color val6 = default(Color);
			for (int i = 0; i < verticalFogMats.Count; i++)
			{
				var (val4, flag, num, num2, flag2) = verticalFogMats[i];
				if ((Object)(object)val4 == (Object)null)
				{
					continue;
				}
				Color val5 = (flag ? val : Color.Lerp(Color.Lerp(val, val2, 0.5f), val2, num2));
				if (flag2 && (int)QualitySettings.activeColorSpace == 1)
				{
					Color linear = ((Color)(ref val5)).linear;
					((Color)(ref val6))..ctor(linear.r / Mathf.Max(0.05f, val3.r), linear.g / Mathf.Max(0.05f, val3.g), linear.b / Mathf.Max(0.05f, val3.b), 1f);
					Color gamma = ((Color)(ref val6)).gamma;
					gamma.a = num;
					val4.SetColor("_Color", gamma);
				}
				else
				{
					Color val7 = (flag2 ? new Color(val5.r / Mathf.Max(0.05f, val3.r), val5.g / Mathf.Max(0.05f, val3.g), val5.b / Mathf.Max(0.05f, val3.b), num) : new Color(val5.r, val5.g, val5.b, num));
					if (val4.HasProperty("_Color"))
					{
						val4.SetColor("_Color", val7);
					}
				}
			}
		}

		private void SpawnTrackLighting(Transform levelRoot, SidecarData sidecar)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Expected O, but got Unknown
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			lightingRoot = new GameObject("TRACK_Lighting");
			lightingRoot.transform.SetParent(levelRoot, false);
			Color color = default(Color);
			((Color)(ref color))..ctor(0.95f, 0.87f, 0.68f);
			(float, float, float, float, float)[] array = new(float, float, float, float, float)[4]
			{
				(-11f, 21f, -6f, 28f, 0.34f),
				(-11f, 21f, 6f, 28f, 0.34f),
				(11f, 21f, -6f, 28f, 0.34f),
				(11f, 21f, 6f, 28f, 0.34f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				var (num, num2, num3, range, intensity) = array[i];
				CreateLampChild(lightingRoot.transform, $"DeckLamp_{num}_{num3}", new Vector3(num, num2, num3), color, range, intensity, 1, 1f, prioritize: false);
			}
			Vector3 projectorPosition = sidecar.ProjectorPosition;
			CreateLampChild(lightingRoot.transform, "Projector_Upper", projectorPosition, new Color(0.95f, 0.88f, 0.7f), 62f, 0.52f, 1, 1f, prioritize: false);
			CreateLampChild(lightingRoot.transform, "Projector_RoofArea", new Vector3(-6f, 151f, 3f), new Color(0.92f, 0.85f, 0.68f), 34f, 0.38f, 1, 1f, prioritize: false);
			dynamicTowerLamps.Clear();
			Color color2 = default(Color);
			((Color)(ref color2))..ctor(0.94f, 0.86f, 0.66f);
			for (int j = 0; j < 8; j++)
			{
				CL_Lamp item = CreateLampChild(lightingRoot.transform, $"DynamicTowerLight_{j:00}", new Vector3(0f, 32f, 235.90077f * (float)(j + 1)), color2, 58f, 0.44f, 1, 1f, prioritize: false);
				dynamicTowerLamps.Add(item);
			}
			nextTowerLightRefresh = 0f;
			if ((Object)(object)playerLightGo != (Object)null)
			{
				Object.Destroy((Object)(object)playerLightGo);
			}
			playerLightGo = new GameObject("TRACK_PlayerNaturalLight");
			playerLightGo.transform.SetParent(lightingRoot.transform, false);
			playerLamp = CreateLamp(playerLightGo, new Color(0.95f, 0.9f, 0.78f), playerLightRange.Value, playerLightIntensity.Value, 1, 1f, prioritize: true);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Spawned 15 restrained atmospheric TRACK CL_Lamps (1 player aura + 6 start/projector + 8 dynamic nearest-tower worklights; 16 hardware slots free for active red radar beacons).");
		}

		private void UpdateDynamicTowerLights()
		{
			//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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: 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)
			if (dynamicTowerLamps.Count == 0 || !lightsEnabled.Value || Time.time < nextTowerLightRefresh)
			{
				return;
			}
			nextTowerLightRefresh = Time.time + 0.55f;
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject == (Object)null)
			{
				return;
			}
			Vector3 pPos = ((Component)playerObject).transform.position;
			int num = Mathf.Clamp(Mathf.RoundToInt(pPos.x / 3156.93f), -1, 1);
			int num2 = Mathf.Clamp(Mathf.RoundToInt(pPos.z / 235.90077f), -10, 10);
			List<Vector3> list = new List<Vector3>(16);
			for (int i = -3; i <= 3; i++)
			{
				int num3 = num2 + i;
				if (num3 >= -10 && num3 <= 10 && (num != 0 || num3 != 0))
				{
					list.Add(new Vector3((float)num * 3156.93f, 32f, (float)num3 * 235.90077f));
				}
			}
			if (Mathf.Abs(pPos.x - (float)num * 3156.93f) > 400f)
			{
				int num4 = ((pPos.x > (float)num * 3156.93f) ? Mathf.Min(1, num + 1) : Mathf.Max(-1, num - 1));
				if (num4 != num)
				{
					for (int j = -1; j <= 1; j++)
					{
						int num5 = Mathf.Clamp(num2 + j, -10, 10);
						list.Add(new Vector3((float)num4 * 3156.93f, 32f, (float)num5 * 235.90077f));
					}
				}
			}
			list.Sort(delegate(Vector3 a, Vector3 b)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: 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)
				Vector3 val2 = a - pPos;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				val2 = b - pPos;
				return sqrMagnitude.CompareTo(((Vector3)(ref val2)).sqrMagnitude);
			});
			for (int num6 = 0; num6 < dynamicTowerLamps.Count; num6++)
			{
				CL_Lamp val = dynamicTowerLamps[num6];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				if (num6 < list.Count)
				{
					((Component)val).transform.position = list[num6];
					val.lampActive = true;
					val.intensity = 0.44f;
					val.range = 58f;
					val.curRange = 58f;
					if ((Object)(object)FXManager.fxMan != (Object)null)
					{
						FXManager.fxMan.UpdateLamp(val);
					}
				}
				else
				{
					val.lampActive = false;
					val.intensity = 0f;
					if ((Object)(object)FXManager.fxMan != (Object)null)
					{
						FXManager.fxMan.UpdateLamp(val);
					}
				}
			}
		}

		private static CL_Lamp CreateLampChild(Transform parent, string name, Vector3 worldPos, Color color, float range, float intensity, int attenuation, float fpMult, bool prioritize)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.position = worldPos;
			return CreateLamp(val, color, range, intensity, attenuation, fpMult, prioritize);
		}

		private static CL_Lamp CreateLamp(GameObject go, Color color, float range, float intensity, int attenuation, float fpMult, bool prioritize)
		{
			//IL_001d: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			CL_Lamp val = go.AddComponent<CL_Lamp>();
			val.lampActive = true;
			val.range = range;
			val.curRange = range;
			val.startColor = color;
			val.color = color;
			val.intensity = intensity;
			val.attentuation = attenuation;
			val.emissiveMult = 1f;
			val.bypassLightmap = 1f;
			val.forwardPlusHiddenMult = fpMult;
			val.prioritizeOnEnable = prioritize;
			if ((Object)(object)FXManager.fxMan != (Object)null)
			{
				FXManager.fxMan.UpdateLamp(val);
				if (prioritize)
				{
					FXManager.fxMan.MoveLampToFrontOfQueue(val);
				}
			}
			return val;
		}

		private void UpdatePlayerLight()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)playerLightGo == (Object)null)
			{
				return;
			}
			Transform val = (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform : (((Object)(object)ENT_Player.playerObject != (Object)null) ? ((Component)ENT_Player.playerObject).transform : null));
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			playerLightGo.transform.position = val.position + Vector3.up * 0.4f;
			if ((Object)(object)playerLamp != (Object)null)
			{
				playerLamp.range = playerLightRange.Value;
				playerLamp.curRange = playerLightRange.Value;
				playerLamp.intensity = playerLightIntensity.Value;
				if ((Object)(object)FXManager.fxMan != (Object)null)
				{
					FXManager.fxMan.MoveLampToFrontOfQueue(playerLamp);
				}
			}
		}

		private void SpawnInteractiveCrates(Transform levelRoot, List<PropSpawn> crates)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_009a: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = FindCratePrefab();
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Interactive crate prefab not found; no crates spawned.");
				return;
			}
			GameObject val2 = new GameObject("TRACK_InteractiveCrates");
			val2.transform.SetParent(levelRoot, false);
			List<PropSpawn> list = crates.OrderBy((PropSpawn c) => c.Position.y).ToList();
			int num = 0;
			float height = 0f;
			float bottomOffset = -0.5f;
			bool flag = false;
			for (int num2 = 0; num2 < list.Count; num2++)
			{
				PropSpawn propSpawn = list[num2];
				Quaternion val3 = Quaternion.Euler(0f, propSpawn.YawDeg, 0f);
				GameObject val4 = Object.Instantiate<GameObject>(val, Vector3.zero, val3, val2.transform);
				((Object)val4).name = $"InteractiveCrate_{num2:00}";
				val4.SetActive(true);
				if (!flag)
				{
					flag = TryMeasureInstanceBounds(val4, out bottomOffset, out height);
				}
				float num3 = ((flag && height > 0.05f && propSpawn.Size.y > 0.1f) ? Mathf.Clamp(propSpawn.Size.y / height, 0.35f, 1.6f) : 1f);
				val4.transform.localScale = Vector3.Scale(val4.transform.localScale, Vector3.one * num3);
				float num4 = ((propSpawn.Position.y > 15.2f) ? 0.03f : 0.01f);
				val4.transform.position = new Vector3(propSpawn.Position.x, propSpawn.Position.y - bottomOffset * num3 + num4, propSpawn.Position.z);
				CL_Prop component = val4.GetComponent<CL_Prop>();
				if ((Object)(object)component != (Object)null)
				{
					((GameEntity)component).canSave = false;
				}
				num++;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Spawned {num} real interactive crates using '{((Object)val).name}' (height={height:F3}, scale~{(flag ? (list[0].Size.y / height) : 1f):F2}).");
		}

		private IEnumerator SpawnInteractiveVendorRoutine(M_Level targetLevel, PropSpawn vSpawn)
		{
			if ((Object)(object)cachedVendorPrefab == (Object)null)
			{
				ENV_VendingMachine val = ((IEnumerable<ENV_VendingMachine>)Resources.FindObjectsOfTypeAll<ENV_VendingMachine>()).FirstOrDefault((Func<ENV_VendingMachine, bool>)delegate(ENV_VendingMachine v)
				{
					//IL_000f: 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)
					if ((Object)(object)v != (Object)null)
					{
						Scene scene = ((Component)v).gameObject.scene;
						return ((Scene)(ref scene)).rootCount == 0;
					}
					return false;
				});
				if ((Object)(object)val != (Object)null)
				{
					cachedVendorPrefab = ((Component)val).gameObject;
				}
				else if (!vendorLoading)
				{
					vendorLoading = true;
					List<LevelAssetHolder> list = (from la in CL_AssetManager.GetFullCombinedAssetDatabase()?.levelAssets?.Where((LevelAssetHolder la) => la != null && la.levelAssetReference != null && ((AssetReference)la.levelAssetReference).RuntimeKeyIsValid() && (la.id.IndexOf("SafeArea", StringComparison.OrdinalIgnoreCase) >= 0 || la.id.IndexOf("Interlude", StringComparison.OrdinalIgnoreCase) >= 0))
						orderby (la.id.IndexOf("Silos_SafeArea", StringComparison.OrdinalIgnoreCase) < 0) ? 1 : 0
						select la).Take(6).ToList();
					if (list != null)
					{
						foreach (LevelAssetHolder holder in list)
						{
							AsyncOperationHandle<GameObject> handle = default(AsyncOperationHandle<GameObject>);
							bool flag = false;
							try
							{
								handle = Addressables.LoadAssetAsync<GameObject>((object)holder.levelAssetReference);
								flag = true;
							}
							catch (Exception ex)
							{
								((BaseUnityPlugin)this).Logger.LogWarning((object)("Addressables load failed for " + holder.id + ": " + ex.Message));
							}
							if (!flag)
							{
								continue;
							}
							yield return handle;
							if ((int)handle.Status == 1 && (Object)(object)handle.Result != (Object)null)
							{
								ENV_VendingMachine componentInChildren = handle.Result.GetComponentInChildren<ENV_VendingMachine>(true);
								if ((Object)(object)componentInChildren != (Object)null)
								{
									GameObject val2 = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject);
									((Object)val2).name = "TRACK_VendorTemplate";
									val2.SetActive(false);
									Object.DontDestroyOnLoad((Object)(object)val2);
									cachedVendorPrefab = val2;
									((BaseUnityPlugin)this).Logger.LogInfo((object)("Extracted real interactive ENV_VendingMachine from '" + holder.id + "' (keeping Addressable handle alive)!"));
									break;
								}
							}
							if (handle.IsValid())
							{
								Addressables.Release<GameObject>(handle);
							}
						}
					}
					vendorLoading = false;
				}
				else
				{
					while (vendorLoading)
					{
						yield return null;
					}
				}
			}
			if ((Object)(object)targetLevel == (Object)null || (Object)(object)activeLevel != (Object)(object)targetLevel || (Object)(object)cachedVendorPrefab == (Object)null)
			{
				yield break;
			}
			GameObject val3 = new GameObject("TRACK_InteractiveVendors");
			val3.transform.SetParent(((Component)targetLevel).transform, false);
			ENV_VendingMachine componentInChildren2 = cachedVendorPrefab.GetComponentInChildren<ENV_VendingMachine>(true);
			List<Purchase> list2 = BuildUnlimitedTrackPurchases(componentInChildren2);
			SpawnSingleVendor(val3.transform, "TRACK_Vendor_StartTower", vSpawn.Position, vSpawn.YawDeg, new Vector3(0f, 15f, 0f), list2);
			(float, float, float, string)[] array = new(float, float, float, string)[8]
			{
				(-12.2f, -8f, 45f, "SW"),
				(-12.2f, 8f, 135f, "NW"),
				(12.2f, -8f, -45f, "SE"),
				(12.2f, 8f, -135f, "NE"),
				(-12.2f, -4.6f, 90f, "WS"),
				(-12.2f, 4.6f, 90f, "WN"),
				(12.2f, -4.6f, -90f, "ES"),
				(12.2f, 4.6f, -90f, "EN")
			};
			List<(string, float, float)> list3 = new List<(string, float, float)>();
			for (int num = -10; num <= 10; num += 2)
			{
				if (num != 0)
				{
					list3.Add(($"Center_{num:+00;-00;00}", 0f, 235.90077f * (float)num));
				}
				list3.Add(($"LeftSail_{num:+00;-00;00}", -3156.93f, 235.90077f * (float)num));
				list3.Add(($"RightSail_{num:+00;-00;00}", 3156.93f, 235.90077f * (float)num));
			}
			int num2 = 1;
			int previousIndex = -1;
			foreach (var item4 in list3)
			{
				string item = item4.Item1;
				float item2 = item4.Item2;
				float item3 = item4.Item3;
				int num3 = PickVariedCorner(array.Length, previousIndex);
				previousIndex = num3;
				(float, float, float, string) tuple = array[num3];
				SpawnSingleVendor(val3.transform, "TRACK_Vendor_" + item + "_" + tuple.Item4, new Vector3(item2 + tuple.Item1, 15f, item3 + tuple.Item2), tuple.Item3, new Vector3(item2, 15f, item3), list2);
				num2++;
			}
			string arg = string.Join(", ", list2.Select((Purchase p) => string.Format("{0}(price={1}, sprite={2})", p.name, p.price, ((Object)(object)p.purchaseSprite != (Object)null) ? ((Object)p.purchaseSprite).name : "null")));
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Spawned {num2} grounded unlimited ENV_VendingMachine instances across Start + Center + Left/Right flanking rows! Stock: [{arg}].");
		}

		private static int PickVariedCorner(int count, int previousIndex)
		{
			if (count <= 1)
			{
				return 0;
			}
			int num = Random.Range(0, count);
			if (num == previousIndex)
			{
				num = (num + 1 + Random.Range(0, count - 1)) % count;
			}
			return num;
		}

		private static float MeasureVendorBodyBottomLocalY(GameObject vendorGo)
		{
			//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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			float num = float.PositiveInfinity;
			Matrix4x4 worldToLocalMatrix = vendorGo.transform.worldToLocalMatrix;
			MeshFilter[] componentsInChildren = vendorGo.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)val.sharedMesh == (Object)null)
				{
					continue;
				}
				Bounds bounds = val.sharedMesh.bounds;
				if (((Bounds)(ref bounds)).size.y < 0.8f)
				{
					continue;
				}
				Vector3 center = ((Bounds)(ref bounds)).center;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				for (int j = -1; j <= 1; j += 2)
				{
					for (int k = -1; k <= 1; k += 2)
					{
						for (int l = -1; l <= 1; l += 2)
						{
							Vector3 val2 = ((Component)val).transform.TransformPoint(new Vector3(center.x + (float)j * extents.x, center.y + (float)k * extents.y, center.z + (float)l * extents.z));
							float y = ((Matrix4x4)(ref worldToLocalMatrix)).MultiplyPoint3x4(val2).y;
							if (y < num)
							{
								num = y;
							}
						}
					}
				}
			}
			if (float.IsInfinity(num))
			{
				return 0f;
			}
			return num;
		}

		private static float RaycastConcreteFloorY(Vector3 xzPos, Vector3 towerCenter, out Vector3 safePos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			safePos = xzPos;
			int num = -4194309;
			RaycastHit val2 = default(RaycastHit);
			for (int i = 0; i < 4; i++)
			{
				Vector3 val = Vector3.Lerp(xzPos, new Vector3(towerCenter.x, xzPos.y, towerCenter.z), (float)i * 0.12f);
				if (Physics.Raycast(new Vector3(val.x, xzPos.y + 4f, val.z), Vector3.down, ref val2, 8f, num, (QueryTriggerInteraction)1) && Mathf.Abs(((RaycastHit)(ref val2)).point.y - xzPos.y) <= 0.6f && Vector3.Dot(((RaycastHit)(ref val2)).normal, Vector3.up) > 0.85f)
				{
					safePos = new Vector3(val.x, ((RaycastHit)(ref val2)).point.y, val.z);
					return ((RaycastHit)(ref val2)).point.y;
				}
			}
			return xzPos.y;
		}

		private void SpawnSingleVendor(Transform parent, string objName, Vector3 basePos, float yawDeg, Vector3 towerCenter, List<Purchase> purchases)
		{
			//IL_0006: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00dd: 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_0100: 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_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_0133: 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)
			GameObject val = Object.Instantiate<GameObject>(cachedVendorPrefab, Vector3.zero, Quaternion.Euler(0f, yawDeg, 0f), parent);
			((Object)val).name = objName;
			ENV_VendingMachine componentInChildren = val.GetComponentInChildren<ENV_VendingMachine>(true);
			if ((Object)(object)componentInChildren != (Object)null && purchases != null && purchases.Count > 0)
			{
				(val.GetComponent<TrackUnlimitedVendor>() ?? val.AddComponent<TrackUnlimitedVendor>()).Initialize(componentInChildren, purchases);
			}
			val.SetActive(true);
			Vector3 safePos;
			float num = RaycastConcreteFloorY(basePos, towerCenter, out safePos);
			float num2 = MeasureVendorBodyBottomLocalY(val);
			val.transform.position = new Vector3(safePos.x, num - num2 + 0.01f, safePos.z);
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.spawnSpot != (Object)null)
			{
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(towerCenter.x - val.transform.position.x, 0f, towerCenter.z - val.transform.position.z);
				Vector3 val3 = componentInChildren.spawnSpot.position - val.transform.position;
				val3.y = 0f;
				if (((Vector3)(ref val3)).sqrMagnitude > 0.0001f && Vector3.Dot(((Vector3)(ref val3)).normalized, ((Vector3)(ref val2)).normalized) < 0f)
				{
					val.transform.Rotate(0f, 180f, 0f, (Space)0);
				}
			}
		}

		private List<Purchase> BuildUnlimitedTrackPurchases(ENV_VendingMachine templateVm)
		{
			List<Purchase> list = new List<Purchase>(3);
			Sprite[] allSprites = Resources.FindObjectsOfTypeAll<Sprite>();
			WKAssetDatabase db = CL_AssetManager.GetFullCombinedAssetDatabase() ?? CL_AssetManager.GetBaseAssetDatabase();
			Item_Object[] loadedItems = Resources.FindObjectsOfTypeAll<Item_Object>().Where(delegate(Item_Object io)
			{
				//IL_000f: 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)
				if ((Object)(object)io != (Object)null)
				{
					Scene scene = ((Component)io).gameObject.scene;
					return ((Scene)(ref scene)).rootCount == 0;
				}
				return false;
			}).ToArray();
			Purchase val = MakePurchase("Injector", 1, new string[2] { "Item_Injector", "Spawn_Item_Injector" }, new string[2] { "Vending_Injector", "Icon_Item_Injector" }, new string[2] { "Injector", "Syringe" });
			Purchase val2 = MakePurchase("Blink Eye", 3, new string[2] { "Item_BlinkEye", "Spawn_Item_BlinkEye" }, new string[2] { "Vending_BlinkEye", "Icon_Item_Bleye" }, new string[2] { "BlinkEye", "Blink" });
			Purchase val3 = MakePurchase("Pills", 2, new string[2] { "Item_Pillbottle", "Spawn_Item_Pillbottle" }, new string[2] { "Vending_Pills", "Icon_Item_Pillbottle" }, new string[1] { "Pill" });
			if (val != null)
			{
				list.Add(val);
			}
			if (val2 != null)
			{
				list.Add(val2);
			}
			if (val3 != null)
			{
				list.Add(val3);
			}
			return list;
			GameObject FindItemPrefab(string[] names)
			{
				string[] array = names;
				for (int i = 0; i < array.Length; i++)
				{
					GameObject assetGameObject = CL_AssetManager.GetAssetGameObject(array[i], "");
					if ((Object)(object)assetGameObject != (Object)null)
					{
						return assetGameObject;
					}
				}
				if ((Object)(object)db != (Object)null && db.itemPrefabs != null)
				{
					array = names;
					foreach (string n in array)
					{
						GameObject val4 = ((IEnumerable<GameObject>)db.itemPrefabs).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && string.Equals(((Object)p).name, n, StringComparison.OrdinalIgnoreCase)));
						if ((Object)(object)val4 != (Object)null)
						{
							return val4;
						}
					}
					array = names;
					foreach (string n2 in array)
					{
						GameObject val5 = ((IEnumerable<GameObject>)db.itemPrefabs).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name.IndexOf(n2, StringComparison.OrdinalIgnoreCase) >= 0));
						if ((Object)(object)val5 != (Object)null)
						{
							return val5;
						}
					}
				}
				array = names;
				foreach (string n3 in array)
				{
					Item_Object val6 = ((IEnumerable<Item_Object>)loadedItems).FirstOrDefault((Func<Item_Object, bool>)((Item_Object io) => ((Object)((Component)io).gameObject).name.IndexOf(n3, StringComparison.OrdinalIgnoreCase) >= 0));
					if ((Object)(object)val6 != (Object)null)
					{
						return ((Component)val6).gameObject;
					}
				}
				return null;
			}
			Sprite FindSprite(string[] names)
			{
				string[] array = names;
				foreach (string n in array)
				{
					Sprite val4 = ((IEnumerable<Sprite>)allSprites).FirstOrDefault((Func<Sprite, bool>)((Sprite s) => (Object)(object)s != (Object)null && string.Equals(((Object)s).name, n, StringComparison.OrdinalIgnoreCase)));
					if ((Object)(object)val4 != (Object)null)
					{
						return val4;
					}
				}
				array = names;
				foreach (string n2 in array)
				{
					Sprite val5 = ((IEnumerable<Sprite>)allSprites).FirstOrDefault((Func<Sprite, bool>)((Sprite s) => (Object)(object)s != (Object)null && ((Object)s).name.IndexOf(n2, StringComparison.OrdinalIgnoreCase) >= 0));
					if ((Object)(object)val5 != (Object)null)
					{
						return val5;
					}
				}
				return null;
			}
			Purchase MakePurchase(string label, int price, string[] prefabNames, string[] spriteNames, string[] nativeMatchKeywords)
			{
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_0168: Unknown result type (might be due to invalid IL or missing references)
				//IL_016f: 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_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0189: Unknown result type (might be due to invalid IL or missing references)
				//IL_0191: Expected O, but got Unknown
				Purchase val4 = null;
				if ((Object)(object)templateVm != (Object)null && templateVm.purchaseList != null)
				{
					val4 = ((IEnumerable<Purchase>)templateVm.purchaseList).FirstOrDefault((Func<Purchase, bool>)delegate(Purchase p)
					{
						if (p == null)
						{
							return false;
						}
						string text = p.name ?? "";
						string text2 = (((Object)(object)p.itemObject != (Object)null) ? ((Object)((Component)p.itemObject).gameObject).name : "");
						string[] array = nativeMatchKeywords;
						foreach (string value in array)
						{
							if (text.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
							{
								return true;
							}
						}
						return false;
					});
				}
				GameObject val5 = (((Object)(object)val4?.itemObject != (Object)null) ? ((Component)val4.itemObject).gameObject : FindItemPrefab(prefabNames));
				if ((Object)(object)val5 == (Object)null && val4?.spawnAssets != null && val4.spawnAssets.Count > 0)
				{
					val5 = val4.spawnAssets[0];
				}
				if (!((Object)(object)val5 == (Object)null))
				{
					Item_Object component = val5.GetComponent<Item_Object>();
					Sprite purchaseSprite = FindSprite(spriteNames) ?? val4?.purchaseSprite;
					return new Purchase
					{
						name = label,
						chance = 1f,
						spawnSettings = val4?.spawnSettings,
						itemObject = component,
						spawnAssets = (((Object)(object)component == (Object)null) ? new List<GameObject> { val5 } : new List<GameObject>()),
						price = price,
						purchaseSprite = purchaseSprite,
						requiredItemTag = "",
						competitive = true,
						ignoreUnlocked = true
					};
				}
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not resolve vending item prefab for '" + label + "' (" + string.Join("/", prefabNames) + ")."));
				return null;
			}
		}

		private void EnsureHammerInInventory()
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)Inventory.instance == (Object)null) && !Inventory.instance.HasItemWithTag("hammer", false))
				{
					WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
					GameObject val = CL_AssetManager.GetAssetGameObject("Item_Hammer", "") ?? fullCombinedAssetDatabase?.itemPrefabs?.FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name.IndexOf("Hammer", StringComparison.OrdinalIgnoreCase) >= 0));
					Item_Object val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Item_Object>() : null);
					if ((Object)(object)val2 != (Object)null && val2.itemData != null)
					{
						Inventory.instance.AddItemToInventoryScreen(new Vector3(0f, 0f, 1f), val2.itemData.GetClone((Item)null, false), true, false, true);
						((BaseUnityPlugin)this).Logger.LogInfo((object)("Granted Hammer ('" + ((Object)val).name + "') to player inventory."));
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("EnsureHammerInInventory failed: " + ex.Message));
			}
		}

		private void SetupWhiteKnuckleAudio(Transform levelRoot)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TRACK_CavernReverb");
			val.transform.SetParent(levelRoot, false);
			val.transform.position = new Vector3(0f, 60f, 0f);
			AudioReverbZone obj = val.AddComponent<AudioReverbZone>();
			obj.reverbPreset = (AudioReverbPreset)11;
			obj.minDistance = 4000f;
			obj.maxDistance = 8000f;
			try
			{
				AudioManager instance = AudioManager.instance;
				if (!((Object)(object)instance != (Object)null) || instance.music == null || instance.music.Count <= 0)
				{
					return;
				}
				string[] obj2 = new string[5] { "periphery-delta", "calmbeforestorm", "pipeworks-intro", "habitation-entryway", "pier-entrance" };
				Soundtrack val2 = null;
				string[] array = obj2;
				foreach (string name in array)
				{
					val2 = ((IEnumerable<Soundtrack>)instance.music).FirstOrDefault((Func<Soundtrack, bool>)((Soundtrack m) => m != null && (Object)(object)m.clip != (Object)null && m.name.Equals(name, StringComparison.OrdinalIgnoreCase)));
					if (val2 != null)
					{
						break;
					}
				}
				if (val2 == null)
				{
					val2 = ((IEnumerable<Soundtrack>)instance.music).FirstOrDefault((Func<Soundtrack, bool>)((Soundtrack m) => m != null && (Object)(object)m.clip != (Object)null && !m.name.Equals("title-theme", StringComparison.OrdinalIgnoreCase)));
				}
				if (val2 != null)
				{
					AudioManager.PlayTrack(val2.clip, true, Mathf.Clamp(val2.volume * 0.65f, 0.25f, 0.7f), true, 2f, 0, false);
					ambientPlaying = true;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Started White Knuckle facility ambience track '" + val2.name + "'."));
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("White Knuckle audio setup failed: " + ex.Message));
			}
		}

		private void StopAmbientAudio()
		{
			if (ambientPlaying && (Object)(object)AudioManager.instance != (Object)null)
			{
				try
				{
					AudioManager.FadeOutMusic(1f, 0, 0f);
				}
				catch
				{
				}
				ambientPlaying = false;
			}
			if ((Object)(object)customAmbientSource != (Object)null)
			{
				customAmbientSource.Stop();
				Object.Destroy((Object)(object)((Component)customAmbientSource).gameObject);
				customAmbientSource = null;
			}
		}

		private GameObject FindCratePrefab()
		{
			string[] array = new string[5] { "Prop_Crate_Large_01", "Prop_Crate_Small_01", "Prop_SupplyCrate_01", "Prop_Crate_Metal_Small_01", "Prop_FlareCrate_01" };
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				GameObject assetGameObject = CL_AssetManager.GetAssetGameObject(array2[i], "");
				if ((Object)(object)assetGameObject != (Object)null)
				{
					return assetGameObject;
				}
			}
			WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
			if ((Object)(object)fullCombinedAssetDatabase != (Object)null)
			{
				IEnumerable<GameObject> source = from p in fullCombinedAssetDatabase.entityPrefabs.Concat(fullCombinedAssetDatabase.itemPrefabs)
					where (Object)(object)p != (Object)null
					select p;
				array2 = array;
				foreach (string name in array2)
				{
					GameObject val = source.FirstOrDefault((Func<GameObject, bool>)((GameObject p) => ((Object)p).name.Equals(name, StringComparison.OrdinalIgnoreCase)));
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			CL_Prop? obj = ((IEnumerable<CL_Prop>)Resources.FindObjectsOfTypeAll<CL_Prop>()).FirstOrDefault((Func<CL_Prop, bool>)((CL_Prop x) => (Object)(object)x != (Object)null && ((Object)((Component)x).gameObject).name.IndexOf("Crate", StringComparison.OrdinalIgnoreCase) >= 0));
			if (obj == null)
			{
				return null;
			}
			return ((Component)obj).gameObject;
		}

		private static bool TryMeasureInstanceBounds(GameObject instance, out float bottomOffset, out float height)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			float num = float.PositiveInfinity;
			float num2 = float.NegativeInfinity;
			float y = instance.transform.position.y;
			Renderer[] componentsInChildren = instance.GetComponentsInChildren<Renderer>(true);
			Vector3 size;
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Bounds bounds = componentsInChildren[i].bounds;
				size = ((Bounds)(ref bounds)).size;
				if (((Vector3)(ref size)).sqrMagnitude > 1E-06f)
				{
					num = Mathf.Min(num, ((Bounds)(ref bounds)).min.y - y);
					num2 = Mathf.Max(num2, ((Bounds)(ref bounds)).max.y - y);
				}
			}
			if (float.IsInfinity(num))
			{
				Collider[] componentsInChildren2 = instance.GetComponentsInChildren<Collider>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					Bounds bounds2 = componentsInChildren2[i].bounds;
					size = ((Bounds)(ref bounds2)).size;
					if (((Vector3)(ref size)).sqrMagnitude > 1E-06f)
					{
						num = Mathf.Min(num, ((Bounds)(ref bounds2)).min.y - y);
						num2 = Mathf.Max(num2, ((Bounds)(ref bounds2)).max.y - y);
					}
				}
			}
			if (float.IsInfinity(num) || num2 <= num)
			{
				bottomOffset = -0.5f;
				height = 1f;
				return false;
			}
			bottomOffset = num;
			height = num2 - num;
			return true;
		}

		private void OnPreRenderFX(Camera cam)
		{
			//IL_0053: 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_0063: 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_007c: Expected O, but got Unknown
			if (!IsTrackMapActive || FXManager.fxZones == null)
			{
				return;
			}
			preservedFxZones.Clear();
			while (FXManager.fxZones.Count > 0)
			{
				FXZoneStore val = FXManager.fxZones.Dequeue();
				if (val != null && val.priority >= 15)
				{
					preservedFxZones.Add(val);
				}
			}
			FXManager.fxZones.Enqueue(new FXZoneStore
			{
				blend = 1f,
				priority = 1,
				data = BuildFxData()
			}, (byte)1);
			for (int i = 0; i < preservedFxZones.Count; i++)
			{
				FXZoneStore val2 = preservedFxZones[i];
				FXManager.fxZones.Enqueue(val2, val2.priority);
			}
		}

		internal FXData BuildFxData()
		{
			//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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Invalid comparison between Unknown and I4
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: 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_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: 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_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: 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_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: 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_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Expected O, but got Unknown
			float num = Mathf.Max(0f, wiggleAmount.Value);
			Color fallback = ParseHex(skyHex.Value, new Color(0.188f, 0.176f, 0.145f, 1f));
			Color fog = ParseHex(fogBottomHex.Value, new Color(0.086f, 0.082f, 0.067f, 1f));
			Color fogTop = ParseHex(fogTopHex.Value, fallback);
			Color val = ParseHex(minColHex.Value, new Color(0.063f, 0.059f, 0.047f, 1f));
			Color minCol = (((int)QualitySettings.activeColorSpace == 1) ? ((Color)(ref val)).linear : val);
			FXData val2 = (((Object)(object)FXManager.fxMan != (Object)null) ? FXManager.fxMan.defaultLook : null);
			float gamma = val2?.gamma ?? 0f;
			float offset = val2?.offset ?? 0f;
			Vector3 hsv = (Vector3)(((??)val2?.hsv) ?? new Vector3(0f, 1f, 1f));
			return new FXData
			{
				affectGeneral = true,
				roundVerts = Mathf.Clamp(rou

StationMap.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Audio;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
using WKMapLoader;

[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("StationMap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("StationMap")]
[assembly: AssemblyTitle("StationMap")]
[assembly: AssemblyVersion("0.2.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 StationMap
{
	public sealed class StationMarker : MonoBehaviour
	{
		public int Id;

		public int RowIndex;

		public int TowerIndex;

		public CL_Button Button;

		public Renderer ButtonRenderer;

		public CL_Lamp BeaconLamp;

		public GameObject[] BeaconHalos;

		public MapLabel Label;

		public bool Activated;
	}
	public sealed class PursuerMarker : MonoBehaviour
	{
		public int Threshold;
	}
	public sealed class RoachMarker : MonoBehaviour
	{
		public int Count;
	}
	public sealed class BeaconHaloBillboard : MonoBehaviour
	{
		public Color BaseColor = new Color(1f, 0.16f, 0.05f, 0.92f);

		public float BaseSize = 2.4f;

		public float AngularFactor = 0.009f;

		public float MinSize = 1.1f;

		public float MaxSize = 48f;

		public float PulseSpeed = 2.1f;

		public float PulseDepth = 0.24f;

		public float Phase;

		private MeshRenderer mr;

		private MaterialPropertyBlock mpb;

		private void Awake()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			mr = ((Component)this).GetComponent<MeshRenderer>();
			mpb = new MaterialPropertyBlock();
		}

		private void LateUpdate()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_00f3: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				((Component)this).transform.rotation = ((Component)main).transform.rotation;
				float num = Vector3.Distance(((Component)main).transform.position, ((Component)this).transform.position);
				float num2 = 1f - PulseDepth * 0.5f + Mathf.Sin(Time.time * PulseSpeed + Phase) * (PulseDepth * 0.5f);
				float num3 = Mathf.Clamp(BaseSize + num * AngularFactor, MinSize, MaxSize) * (0.94f + 0.08f * num2);
				((Component)this).transform.localScale = new Vector3(num3, num3, 1f);
				if ((Object)(object)mr != (Object)null)
				{
					float num4 = Mathf.Lerp(1f, 0.52f, Mathf.Clamp01((num - 180f) / 3800f));
					Color baseColor = BaseColor;
					baseColor.a = Mathf.Clamp01(BaseColor.a * num2 * num4);
					((Renderer)mr).GetPropertyBlock(mpb);
					mpb.SetColor("_Color", baseColor);
					((Renderer)mr).SetPropertyBlock(mpb);
				}
			}
		}
	}
	public sealed class RemainsSlowController : MonoBehaviour
	{
		public float SpeedMetersPerSec = 0.35f;

		public float MaxLeashDistance = 150f;

		public float ReleashDistance = 68f;

		public float SightFreezeRange = 55f;

		public float MinStandOffDistance = 8f;

		public float MinDeckY = 16.5f;

		public int WaveThreshold;

		private DEN_Remains_Active remains;

		private Rigidbody rb;

		private Collider[] allColliders;

		private float swaySeed;

		private void Awake()
		{
			remains = ((Component)this).GetComponent<DEN_Remains_Active>();
			rb = ((Component)this).GetComponent<Rigidbody>();
			allColliders = ((Component)this).GetComponentsInChildren<Collider>(true);
			swaySeed = Random.Range(0f, 100f);
			EnforcePhantomPhysics();
		}

		private void EnforcePhantomPhysics()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rb != (Object)null)
			{
				rb.useGravity = false;
				rb.isKinematic = true;
				rb.detectCollisions = false;
				rb.linearVelocity = Vector3.zero;
				rb.angularVelocity = Vector3.zero;
			}
			if (allColliders == null)
			{
				return;
			}
			for (int i = 0; i < allColliders.Length; i++)
			{
				if ((Object)(object)allColliders[i] != (Object)null && allColliders[i].enabled)
				{
					allColliders[i].enabled = false;
				}
			}
		}

		private bool IsActuallySeenByPlayer(ENT_Player player, Vector3 curPos)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_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_0032: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return false;
			}
			Vector3 position = ((Component)main).transform.position;
			Vector3 val = curPos + Vector3.up * 0.6f;
			if (Vector3.Distance(position, val) > SightFreezeRange)
			{
				return false;
			}
			Vector3 val2 = main.WorldToViewportPoint(val);
			if (val2.z <= 0.25f || val2.x < -0.05f || val2.x > 1.05f || val2.y < -0.05f || val2.y > 1.05f)
			{
				return false;
			}
			int num = 0x400004 | (1 << ((Component)this).gameObject.layer) | (1 << ((Component)player).gameObject.layer);
			return !Physics.Linecast(position, val, ~num, (QueryTriggerInteraction)1);
		}

		private void FixedUpdate()
		{
			EnforcePhantomPhysics();
		}

		private void LateUpdate()
		{
			//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_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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: 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_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: 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_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: 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_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)remains == (Object)null || !remains.active)
			{
				return;
			}
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject == (Object)null)
			{
				return;
			}
			remains.moveSpeed = 0f;
			remains.moveSpeedRand = 0f;
			remains.randomWalkMult = 0f;
			remains.scanDistance = 0f;
			remains.scanCount = 0;
			remains.scanLayerMask = LayerMask.op_Implicit(0);
			remains.proximityRadius = 0f;
			remains.proximityHazardBuildRate = 0f;
			remains.proximityKillTime = -9999f;
			EnforcePhantomPhysics();
			if (((GameEntity)playerObject).IsDead())
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				if ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused)
				{
					return;
				}
				float deltaTime = Time.deltaTime;
				if (deltaTime <= 0f)
				{
					return;
				}
				Vector3 position = ((Component)this).transform.position;
				Vector3 val = ((Component)playerObject).transform.position + Vector3.up * 1.15f;
				float num = Vector3.Distance(position, val);
				Vector3 val2 = val - position;
				val2.y = 0f;
				if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
				{
					((Component)this).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up);
				}
				if (num < MinStandOffDistance)
				{
					Vector3 val3 = position - val;
					val3.y = 0f;
					if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
					{
						val3 = (((Object)(object)Camera.main != (Object)null) ? (-((Component)Camera.main).transform.forward) : Vector3.back);
					}
					val3.y = 0f;
					((Vector3)(ref val3)).Normalize();
					Vector3 val4 = val + val3 * (MinStandOffDistance + 1f);
					val4.y = Mathf.Max(MinDeckY, ((Component)playerObject).transform.position.y + 0.8f);
					((Component)this).transform.position = Vector3.MoveTowards(position, val4, 6f * deltaTime);
				}
				else
				{
					if (IsActuallySeenByPlayer(playerObject, position))
					{
						return;
					}
					if (num > MaxLeashDistance && (Object)(object)Camera.main != (Object)null)
					{
						Vector3 val5 = -((Component)Camera.main).transform.forward;
						val5.y = 0f;
						if (((Vector3)(ref val5)).sqrMagnitude < 0.01f)
						{
							val5 = Vector3.forward;
						}
						((Vector3)(ref val5)).Normalize();
						Vector3 position2 = val + val5 * ReleashDistance;
						position2.y = Mathf.Max(MinDeckY + 1f, ((Component)playerObject).transform.position.y + 1.5f);
						((Component)this).transform.position = position2;
						return;
					}
					Vector3 val6 = new Vector3(Mathf.Sin(Time.time * 1.4f + swaySeed), Mathf.Cos(Time.time * 1.1f + swaySeed) * 0.35f, Mathf.Cos(Time.time * 1.3f + swaySeed)) * Mathf.Min(0.8f, num * 0.05f);
					Vector3 val7 = Vector3.MoveTowards(position, val + val6, SpeedMetersPerSec * deltaTime);
					if (!(Vector3.Distance(val7, val) < MinStandOffDistance))
					{
						float num2 = Mathf.Min(MinDeckY, ((Component)playerObject).transform.position.y - 2.5f);
						if (val7.y < num2)
						{
							val7.y = num2;
						}
						((Component)this).transform.position = val7;
					}
				}
			}
		}
	}
	public sealed class TrackFaceController : MonoBehaviour
	{
		public float MaxLeashDistance = 175f;

		public float ReleashDistance = 68f;

		public float MinFlightY = 17.5f;

		public float MaxAggression = 1.15f;

		private DEN_Face face;

		private float nextHuntNudgeTime;

		private void Awake()
		{
			face = ((Component)this).GetComponent<DEN_Face>();
			nextHuntNudgeTime = Time.time + 3f;
		}

		private void LateUpdate()
		{
			//IL_0089: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00ef: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_016c: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)face == (Object)null || !face.active)
			{
				return;
			}
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject == (Object)null || ((GameEntity)playerObject).IsDead() || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused))
			{
				return;
			}
			face.SetTarget(((Component)playerObject).transform);
			if (face.aggression > MaxAggression)
			{
				face.aggression = MaxAggression;
			}
			Vector3 position = ((Component)this).transform.position;
			Vector3 position2 = ((Component)playerObject).transform.position;
			float num = Vector3.Distance(position, position2);
			float num2 = Mathf.Min(MinFlightY, position2.y - 4f);
			if (position.y < num2)
			{
				((Component)this).transform.position = new Vector3(position.x, num2, position.z);
				position = ((Component)this).transform.position;
			}
			if (num > MaxLeashDistance && (Object)(object)Camera.main != (Object)null)
			{
				Vector3 val = -((Component)Camera.main).transform.forward;
				val.y = 0f;
				if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
				{
					val = Vector3.back;
				}
				((Vector3)(ref val)).Normalize();
				Vector3 position3 = position2 + val * ReleashDistance + Vector3.up * 6f;
				position3.y = Mathf.Max(MinFlightY + 2f, position2.y + 4f);
				((Component)this).transform.position = position3;
				DEN_Face.StartHunt();
				nextHuntNudgeTime = Time.time + 12f;
			}
			else if (Time.time >= nextHuntNudgeTime && num < 95f)
			{
				nextHuntNudgeTime = Time.time + 16f;
				DEN_Face.StartHunt();
			}
		}
	}
	public sealed class RoofElevatorController : MonoBehaviour
	{
		public CL_Lamp StatusLamp;

		public CL_Button Button;

		public MapLabel Label;

		public AudioClip ClipChime;

		public AudioClip ClipBeep;

		public Action OnInstantWin;

		public Func<int> GetActivatedCount;

		public bool IsUnlocked { get; private set; }

		public bool IsComplete { get; private set; }

		public string StateLabel
		{
			get
			{
				if (!IsComplete)
				{
					if (!IsUnlocked)
					{
						return "LOCKED";
					}
					return "UNLOCKED";
				}
				return "EVACUATED";
			}
		}

		public void UpdateProgress(int count, int total)
		{
			if (!IsUnlocked && (Object)(object)Label != (Object)null)
			{
				Label.title = $"EVACUATION ELEVATOR [LOCKED {count}/{total}]";
				Label.description = $"Activate all {total} Radars to unlock ({count}/{total})";
			}
		}

		public void Unlock()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			if (IsUnlocked)
			{
				return;
			}
			IsUnlocked = true;
			if ((Object)(object)StatusLamp != (Object)null)
			{
				StatusLamp.color = new Color(0.25f, 0.85f, 0.45f);
				StatusLamp.startColor = StatusLamp.color;
				StatusLamp.range = 16f;
				StatusLamp.curRange = 16f;
				StatusLamp.intensity = 0.4f;
				if ((Object)(object)FXManager.fxMan != (Object)null)
				{
					FXManager.fxMan.UpdateLamp(StatusLamp);
				}
			}
			if ((Object)(object)Label != (Object)null)
			{
				Label.title = "EVACUATION ELEVATOR [UNLOCKED]";
				Label.description = "Press button to evacuate immediately!";
			}
			if ((Object)(object)Button != (Object)null)
			{
				Button.active = true;
			}
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)ClipChime != (Object)null && (Object)(object)playerObject != (Object)null)
			{
				AudioManager.PlaySound(ClipChime, ((Component)playerObject).transform.position, 0.9f, 1f, 0f, false, 1f, (AudioMixerGroup)null, "");
			}
		}

		public void OnButtonPressed()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (IsComplete)
			{
				return;
			}
			if (!IsUnlocked)
			{
				int num = ((GetActivatedCount != null) ? GetActivatedCount() : 0);
				if ((Object)(object)ClipBeep != (Object)null && (Object)(object)ENT_Player.playerObject != (Object)null)
				{
					AudioManager.PlaySound(ClipBeep, ((Component)ENT_Player.playerObject).transform.position, 0.8f, 0.65f, 0f, false, 1f, (AudioMixerGroup)null, "");
				}
				MapApi.ShowTitle($"ELEVATOR LOCKED — ACTIVATE ALL 15 RADARS ({num}/15)");
				if ((Object)(object)Button != (Object)null)
				{
					Button.active = true;
				}
			}
			else
			{
				IsComplete = true;
				if ((Object)(object)Button != (Object)null)
				{
					Button.active = false;
				}
				OnInstantWin?.Invoke();
			}
		}
	}
	[BepInPlugin("local.whiteknuckle.stations", "TRACK Radar Stations, Mass, Roaches, Dead Face & Roof Elevator", "0.6.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private enum MapDisplayMode
		{
			Compact,
			Expanded,
			Hidden
		}

		private const string TargetTrackLevelName = "map_TRACK_start_test";

		private const float RowStepX = 3156.93f;

		private const float TowerStepZ = 235.90077f;

		private const float DeckY = 15f;

		private const int MaxBeaconTowerRange = 10;

		private const int TrackInventoryCapacity = 200;

		private readonly RunState run = new RunState();

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

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

		private readonly List<Texture2D> createdTextures = new List<Texture2D>();

		private readonly List<Mesh> createdMeshes = new List<Mesh>();

		private StationMarker[] stations = Array.Empty<StationMarker>();

		private PursuerMarker[] pursuerPoints = Array.Empty<PursuerMarker>();

		private M_Level level;

		private M_Level attempted;

		private DEN_DeathFloor mass;

		private RoofElevatorController roofElevator;

		private BeaconHaloBillboard startTowerHalo;

		private Mesh sharedHaloQuadMesh;

		private Texture2D sharedHaloTexture;

		private Material sharedHaloMaterial;

		private GameObject radarBodyTemplate;

		private GameObject radarButtonTemplate;

		private Vector3 radarBtnLocalCenter = new Vector3(0.138f, 1.652f, 0.247f);

		private Vector3 elevBtnWorldCenter = new Vector3(-18.138f, 149.047f, 4.959f);

		private Vector3 elevCabWorldPos = new Vector3(-15.781f, 145.07f, 4.92f);

		private GameObject cachedRemainsPrefab;

		private GameObject cachedFacePrefab;

		private GameObject cachedRoachPrefab;

		private GameObject cachedGoldRoachPrefab;

		private GameObject cachedWhiteRoachPrefab;

		private bool loadingRemains;

		private bool loadingFace;

		private bool loadingRoach;

		private bool roachesSpawned;

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

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

		private int[] faceThresholds = new int[4] { 2, 6, 10, 13 };

		private bool massScaled;

		private Vector3 oldMassVisualScale;

		private float oldMassCloseShake;

		private float oldMassRoarShake;

		private float oldSpeed;

		private float oldMult;

		private float height;

		private float floor;

		private float pumpRemaining;

		private float nextSpawnAttempt;

		private float nextLampRefreshTime;

		private bool oldActive;

		private bool running;

		private bool elevatorUnlocked;

		private bool victoryTriggered;

		private Vector3 oldPosition;

		private int readyFrame;

		private int trackWaitFrames;

		private MapDisplayMode mapMode;

		private Texture2D guiPixelTex;

		private GUIStyle guiTitleStyle;

		private GUIStyle guiLabelStyle;

		private GUIStyle guiSmallStyle;

		private bool inventoryExpanded;

		private int savedUnencumbered = 5;

		private int savedMaxEncumbered = 10;

		private int savedPouchCap = 5;

		private AudioClip clipButtonPress;

		private AudioClip clipGeneratorOnline;

		private AudioClip clipVictory;

		private AudioClip clipElevChime;

		private AudioClip clipElevBeep;

		private readonly List<AudioClip> faceScreamClips = new List<AudioClip>();

		private Material matBtnOffline;

		private Material matBtnOnline;

		private CommandConsole registeredConsole;

		private UdpClient hudUdp;

		private IPEndPoint hudEndpoint;

		private float nextHudSendTime;

		private ConfigEntry<bool> gameplayEnabled;

		private ConfigEntry<bool> showMapOnStart;

		private ConfigEntry<KeyCode> mapToggleKey;

		private ConfigEntry<string> faceThresholdsConfig;

		private ConfigEntry<float> rise;

		private ConfigEntry<float> lateRiseMult;

		private ConfigEntry<float> pumpDistance;

		private ConfigEntry<float> pumpSpeed;

		private ConfigEntry<float> startDepth;

		private ConfigEntry<float> floorDepth;

		private ConfigEntry<float> slowSpeed;

		private ConfigEntry<float> mediumSpeed;

		private ConfigEntry<float> fastSpeed;

		private ConfigEntry<float> finalSpeed;

		private ConfigEntry<int> roachesPerStation;

		private ConfigEntry<int> roachesOnActivate;

		private ConfigEntry<int> inventoryLimit;

		private ConfigEntry<float> goldRoachChance;

		private ConfigEntry<float> whiteRoachChance;

		private ConfigEntry<string> remainsPrefabOverride;

		private void Awake()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Expected O, but got Unknown
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Expected O, but got Unknown
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Expected O, but got Unknown
			gameplayEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable 15-radar Mass pumping, Roaches, slow Remains, Dead Face & Roof Elevator gameplay on TRACK.");
			inventoryLimit = ((BaseUnityPlugin)this).Config.Bind<int>("General", "InventoryCapacity", 200, new ConfigDescription("Expanded item/pouch capacity on TRACK so player can carry many Injectors/Eyes/Pills.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 500), Array.Empty<object>()));
			showMapOnStart = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowTacticalMap", true, "Show the 3-sail tactical radar map at run start (press M or run 'wkstations map off' to fully turn it off anytime).");
			mapToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "MapToggleKey", (KeyCode)109, "Hotkey to cycle TRACK 3-sail tactical map (Compact -> Expanded -> OFF).");
			faceThresholdsConfig = ((BaseUnityPlugin)this).Config.Bind<string>("DeadFace", "SpawnAtActivations", "2,6,10,13", "Comma-separated radar activation counts at which new Dead Face instances emerge (escalating phases!).");
			faceThresholds = ParseFaceThresholds(faceThresholdsConfig.Value);
			mapMode = ((!showMapOnStart.Value) ? MapDisplayMode.Hidden : MapDisplayMode.Compact);
			rise = Number("Mass", "RiseSpeed", 0.22f, 0.01f, 20f);
			lateRiseMult = Number("Mass", "RiseMultiplierAfter12", 1.35f, 1f, 5f);
			pumpDistance = Number("Mass", "PumpDistance", 22f, 1f, 500f);
			pumpSpeed = Number("Mass", "PumpSpeed", 6.5f, 0.5f, 100f);
			startDepth = Number("Mass", "StartDepthBelowSpawn", 27f, 5f, 500f);
			floorDepth = Number("Mass", "MaximumDepthBelowSpawn", 72f, 10f, 2000f);
			slowSpeed = Number("Remains", "StartSpeedMps", 0.3f, 0.05f, 500f);
			mediumSpeed = Number("Remains", "AfterTwoSpeedMps", 0.35f, 0.05f, 500f);
			fastSpeed = Number("Remains", "AfterEightSpeedMps", 0.4f, 0.05f, 500f);
			finalSpeed = Number("Remains", "AfterTwelveSpeedMps", 0.45f, 0.05f, 500f);
			remainsPrefabOverride = ((BaseUnityPlugin)this).Config.Bind<string>("Remains", "ExactPrefabName", "", "Optional exact native prefab name override (defaults to Denizen_Remains_Active).");
			roachesPerStation = ((BaseUnityPlugin)this).Config.Bind<int>("Roaches", "RoachesPerStationCluster", 10, new ConfigDescription("Roaches spawned per tower/bridge cluster.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 30), Array.Empty<object>()));
			roachesOnActivate = ((BaseUnityPlugin)this).Config.Bind<int>("Roaches", "RoachesPerGeneratorActivation", 8, new ConfigDescription("Extra roaches emerging when a radar activates.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 40), Array.Empty<object>()));
			goldRoachChance = ((BaseUnityPlugin)this).Config.Bind<float>("Roaches", "GoldRoachChance", 0.15f, new ConfigDescription("Fraction of spawned roaches that are golden (Denizen_Roach_Gold).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			whiteRoachChance = ((BaseUnityPlugin)this).Config.Bind<float>("Roaches", "WhiteRoachChance", 0.1f, new ConfigDescription("Fraction of spawned roaches that are white/platinum (Denizen_Roach_Platinum).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			MapApi.RegisterTag("wkstation", (Action<MapPartInfo>)delegate(MapPartInfo p)
			{
				int num = Arg(p.Args("wkstation"));
				if (num < 1 || num > 15)
				{
					throw new ArgumentException("wkstation expects an ID from 1 to 15");
				}
				p.GameObject.AddComponent<StationMarker>().Id = num;
			});
			MapApi.RegisterTag("wkdeadman", (Action<MapPartInfo>)delegate(MapPartInfo p)
			{
				int num = Arg(p.Args("wkdeadman"));
				if (num != 0 && num != 2 && num != 8 && num != 12)
				{
					throw new ArgumentException("wkdeadman expects 0, 2, 8 or 12");
				}
				p.GameObject.AddComponent<PursuerMarker>().Threshold = num;
			});
			MapApi.RegisterTag("wkroaches", (Action<MapPartInfo>)delegate(MapPartInfo p)
			{
				int num = Arg(p.Args("wkroaches"));
				if (num < 1 || num > 100)
				{
					throw new ArgumentException("wkroaches expects 1..100");
				}
				p.GameObject.AddComponent<RoachMarker>().Count = num;
			});
			MapApi.RegisterAction("wkpump", (Action<string[]>)delegate(string[] args)
			{
				Activate(Arg(args));
			});
			MapApi.RegisterCommand("wkstations", (Action<string[]>)HandleConsoleCommand);
			MapApi.MapReset += Reset;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"TRACK StationMap v0.4.0 loaded (15 grounded TheRadar stations across center+flanking rows, zero cubes, soft red beacons, ultra-slow Remains, real DEN_Face + MFace scream, 200-item inventory, roof Elevator instant clean win).");
		}

		private ConfigEntry<float> Number(string section, string key, float value, float min, float max)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<float>(section, key, value, new ConfigDescription("Gameplay tuning value (metres / metres per second).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), Array.Empty<object>()));
		}

		private static int Arg(string[] args)
		{
			if (args == null || args.Length != 1 || !int.TryParse(args[0], out var result))
			{
				return -1;
			}
			return result;
		}

		private void EnsureConsoleCommandRegistered()
		{
			CommandConsole instance = CommandConsole.instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)registeredConsole)
			{
				registeredConsole = instance;
				CommandConsole.AddCommand("wkstations", (Action<string[]>)HandleConsoleCommand, false);
			}
		}

		private void Update()
		{
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				EnsureConsoleCommandRegistered();
				if (!gameplayEnabled.Value)
				{
					return;
				}
				if (!MapApi.InCustomMap)
				{
					if (running)
					{
						Reset();
					}
				}
				else
				{
					if (Time.frameCount < readyFrame || CL_GameManager.IsLoading())
					{
						return;
					}
					WorldLoader instance = WorldLoader.instance;
					object obj;
					if (!((Object)(object)instance == (Object)null))
					{
						LevelInfo currentLevel = instance.GetCurrentLevel();
						obj = ((currentLevel != null) ? currentLevel.GetLevel() : null);
					}
					else
					{
						obj = null;
					}
					M_Level val = (M_Level)obj;
					if (running && (Object)(object)val != (Object)(object)level)
					{
						Reset();
					}
					ENT_Player playerObject = ENT_Player.playerObject;
					if ((Object)(object)val == (Object)null || (Object)(object)playerObject == (Object)null || ((GameEntity)playerObject).IsDead() || (Object)(object)CL_GameManager.gMan == (Object)null || CL_GameManager.gMan.isPaused)
					{
						return;
					}
					if (!running && (Object)(object)val != (Object)(object)attempted)
					{
						if (val.levelName == "map_TRACK_start_test" && (Object)(object)((Component)val).transform.Find("TRACK_AppliedMarker") == (Object)null && trackWaitFrames < 30)
						{
							trackWaitFrames++;
							return;
						}
						Begin(val);
					}
					if (!running)
					{
						return;
					}
					float deltaTime = Time.deltaTime;
					if (deltaTime <= 0f)
					{
						return;
					}
					if (mapToggleKey != null && !CommandConsole.IsConsoleVisible() && Input.GetKeyDown(mapToggleKey.Value))
					{
						CycleMapMode();
					}
					ApplyExpandedInventoryCapacity();
					UpdateMass(playerObject, deltaTime);
					UpdateNearestRedRadarLamps(playerObject);
					UpdateEsp32HudTelemetry(playerObject);
					if (!(Time.time >= nextSpawnAttempt))
					{
						return;
					}
					nextSpawnAttempt = Time.time + 1.5f;
					if (!roachesSpawned && (Object)(object)cachedRoachPrefab != (Object)null && !loadingRoach)
					{
						roachesSpawned = true;
						SpawnRoaches(((Component)val).GetComponentsInChildren<RoachMarker>(true));
					}
					if (!elevatorUnlocked && !victoryTriggered)
					{
						int[] array = run.PendingPursuers().ToArray();
						foreach (int threshold in array)
						{
							SpawnSlowRemains(threshold);
						}
						SpawnPendingDeadFaces(playerObject);
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Stations disabled for this attempt: " + ex));
				StopRun();
			}
		}

		private void ApplyExpandedInventoryCapacity()
		{
			Inventory instance = Inventory.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			int cap = Mathf.Clamp(inventoryLimit.Value, 20, 500);
			FieldInfo field = typeof(Inventory).GetField("pouches", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(Inventory).GetField("pouchMaxCapacity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!inventoryExpanded)
			{
				savedUnencumbered = instance.unencumberedItems;
				savedMaxEncumbered = instance.maxEncumberedItems;
				if (field2 != null && field2.GetValue(instance) is int num)
				{
					savedPouchCap = num;
				}
				inventoryExpanded = true;
			}
			bool changed = instance.unencumberedItems != cap || instance.maxEncumberedItems != cap + 50;
			instance.unencumberedItems = cap;
			instance.maxEncumberedItems = cap + 50;
			if (field2 != null)
			{
				field2.SetValue(instance, cap);
			}
			List<Pouch> allPouches = instance.GetAllPouches();
			if (allPouches != null)
			{
				foreach (Pouch item in allPouches)
				{
					BumpPouch(item);
				}
			}
			if (field?.GetValue(instance) is List<Pouch> list)
			{
				foreach (Pouch item2 in list)
				{
					BumpPouch(item2);
				}
			}
			if (changed)
			{
				instance.CalculateEncumberance(false);
			}
			void BumpPouch(Pouch p)
			{
				if (p != null && (p.maxCapacity < cap || p.maxLargeCapacity < cap))
				{
					p.maxCapacity = cap;
					p.maxLargeCapacity = cap;
					p.UpdatePouch();
					changed = true;
				}
			}
		}

		private void RestoreInventoryCapacity()
		{
			if (!inventoryExpanded)
			{
				return;
			}
			inventoryExpanded = false;
			Inventory instance = Inventory.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			instance.unencumberedItems = savedUnencumbered;
			instance.maxEncumberedItems = savedMaxEncumbered;
			FieldInfo field = typeof(Inventory).GetField("pouchMaxCapacity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(instance, savedPouchCap);
			}
			FieldInfo field2 = typeof(Inventory).GetField("pouches", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			List<Pouch> allPouches = instance.GetAllPouches();
			if (allPouches != null)
			{
				foreach (Pouch item in allPouches)
				{
					if (item != null)
					{
						item.maxCapacity = savedPouchCap;
						item.maxLargeCapacity = savedPouchCap;
						item.UpdatePouch();
					}
				}
			}
			if (field2?.GetValue(instance) is List<Pouch> list)
			{
				foreach (Pouch item2 in list)
				{
					if (item2 != null)
					{
						item2.maxCapacity = savedPouchCap;
						item2.maxLargeCapacity = savedPouchCap;
						item2.UpdatePouch();
					}
				}
			}
			instance.CalculateEncumberance(false);
		}

		private void UpdateNearestRedRadarLamps(ENT_Player player)
		{
			//IL_004b: 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)
			if (!((Object)(object)FXManager.fxMan == (Object)null) && stations != null && stations.Length != 0 && !(Time.time < nextLampRefreshTime))
			{
				nextLampRefreshTime = Time.time + 0.6f;
				Vector3 pPos = ((Component)player).transform.position;
				List<StationMarker> list = stations.Where((StationMarker s) => (Object)(object)s != (Object)null && !s.Activated && (Object)(object)s.BeaconLamp != (Object)null && s.BeaconLamp.lampActive).OrderByDescending(delegate(StationMarker s)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_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)
					Vector3 val = ((Component)s).transform.position - pPos;
					return ((Vector3)(ref val)).sqrMagnitude;
				}).ToList();
				for (int num = 0; num < list.Count; num++)
				{
					FXManager.fxMan.MoveLampToFrontOfQueue(list[num].BeaconLamp);
				}
			}
		}

		private void UpdateMass(ENT_Player player, float dt)
		{
			//IL_008b: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mass == (Object)null)
			{
				return;
			}
			float num = Mathf.Min(pumpRemaining, pumpSpeed.Value * dt);
			pumpRemaining -= num;
			if (elevatorUnlocked || victoryTriggered)
			{
				height = Mathf.Max(floor - 80f, height - pumpSpeed.Value * 2.5f * dt);
				((Component)mass).transform.position = new Vector3(((Component)player).transform.position.x, height, ((Component)player).transform.position.z);
				if (height <= floor - 75f && mass.IsActive())
				{
					mass.SetActive(false);
				}
				return;
			}
			float num2 = ((run.Count >= 12) ? (rise.Value * lateRiseMult.Value) : rise.Value);
			height = MassStep.Next(height, num2, dt, num, floor);
			Vector3 position = ((Component)player).transform.position;
			((Component)mass).transform.position = new Vector3(position.x, height, position.z);
			if ((Object)(object)mass.deathFloorRenderer != (Object)null && (Object)(object)((Renderer)mass.deathFloorRenderer).material != (Object)null)
			{
				float num3 = Mathf.Max(0.1f, mass.offsetScale);
				((Renderer)mass.deathFloorRenderer).material.SetTextureOffset("_MainTex", new Vector2(position.z, position.x) / num3);
			}
		}

		private void SendEsp32Udp(string line)
		{
			try
			{
				if (hudUdp == null)
				{
					hudUdp = new UdpClient();
					hudEndpoint = new IPEndPoint(IPAddress.Loopback, 42100);
				}
				byte[] bytes = Encoding.UTF8.GetBytes(line);
				hudUdp.Send(bytes, bytes.Length, hudEndpoint);
			}
			catch
			{
			}
		}

		private void UpdateEsp32HudTelemetry(ENT_Player player)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < nextHudSendTime)
			{
				return;
			}
			nextHudSendTime = Time.unscaledTime + 0.2f;
			float num = Mathf.Max(0f, ((Component)player).transform.position.y - height);
			float num2 = 999f;
			for (int i = 0; i < activeFaceObjects.Count; i++)
			{
				GameObject val = activeFaceObjects[i];
				if (!((Object)(object)val == (Object)null))
				{
					float num3 = Vector3.Distance(((Component)player).transform.position, val.transform.position);
					if (num3 < num2)
					{
						num2 = num3;
					}
				}
			}
			for (int j = 0; j < spawned.Count; j++)
			{
				GameObject val2 = spawned[j];
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.GetComponent<DEN_Remains_Active>() == (Object)null))
				{
					float num4 = Vector3.Distance(((Component)player).transform.position, val2.transform.position);
					if (num4 < num2)
					{
						num2 = num4;
					}
				}
			}
			SendEsp32Udp(string.Format(CultureInfo.InvariantCulture, "STATE {0} 15 {1:F1} {2:F1} {3}", run.Count, num, num2, victoryTriggered ? 1 : 0));
		}

		private void Begin(M_Level current)
		{
			//IL_01b2: 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_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			attempted = current;
			elevatorUnlocked = false;
			victoryTriggered = false;
			roachesSpawned = false;
			BanishAllPursuers();
			faceThresholds = ParseFaceThresholds(faceThresholdsConfig.Value);
			mapMode = ((!showMapOnStart.Value) ? MapDisplayMode.Hidden : MapDisplayMode.Compact);
			roofElevator = null;
			radarBodyTemplate = null;
			radarButtonTemplate = null;
			LoadTrackMetaJson();
			ResolveAudioClips();
			BuildButtonMaterials();
			stations = ((Component)current).GetComponentsInChildren<StationMarker>(true);
			if (stations.Length == 0 && current.levelName == "map_TRACK_start_test")
			{
				ExpandLevelBounds(current);
				FindRadarTemplates(current);
				BuildTrackAutoGameplayLayout(current);
				SetupRoofElevator(current, GetInteractLayer());
				stations = ((Component)current).GetComponentsInChildren<StationMarker>(true);
			}
			if (stations.Length == 0)
			{
				return;
			}
			if (stations.Length != 15 || stations.Select((StationMarker s) => s.Id).Distinct().Count() != 15)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Map requires exactly 15 unique station IDs (1..15); found {stations.Length}.");
				return;
			}
			pursuerPoints = ((Component)current).GetComponentsInChildren<PursuerMarker>(true);
			mass = DEN_DeathFloor.instance;
			if ((Object)(object)mass == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Native DEN_DeathFloor (Mass) is unavailable.");
				return;
			}
			oldActive = mass.IsActive();
			oldSpeed = mass.GetCurrentSpeed();
			oldMult = mass.GetCurrentSpeedMult();
			oldPosition = ((Component)mass).transform.position;
			oldMassCloseShake = mass.closeScreenShake;
			oldMassRoarShake = mass.roarShake;
			mass.closeScreenShake = 0f;
			mass.roarShake = 0f;
			if ((Object)(object)mass.visualRoot != (Object)null)
			{
				oldMassVisualScale = mass.visualRoot.transform.localScale;
				mass.visualRoot.transform.localScale = new Vector3(oldMassVisualScale.x * 35f, oldMassVisualScale.y, oldMassVisualScale.z * 35f);
				massScaled = true;
			}
			level = current;
			run.Reset();
			pumpRemaining = 0f;
			float num = (((Object)(object)current.spawnPosition != (Object)null) ? current.spawnPosition.position.y : ((Component)ENT_Player.playerObject).transform.position.y);
			floor = num - Mathf.Max(floorDepth.Value, startDepth.Value);
			height = num - startDepth.Value;
			running = true;
			mass.SetSpeed(0f);
			mass.SetSpeedMultiplier(0f);
			Vector3 position = ((Component)ENT_Player.playerObject).transform.position;
			((Component)mass).transform.position = new Vector3(position.x, height, position.z);
			mass.SetActive(true);
			ApplyExpandedInventoryCapacity();
			TryFindPrefabsInMemory();
			if ((Object)(object)cachedRemainsPrefab == (Object)null && !loadingRemains)
			{
				((MonoBehaviour)this).StartCoroutine(LoadRemainsPrefabRoutine());
			}
			if ((Object)(object)cachedFacePrefab == (Object)null && !loadingFace)
			{
				((MonoBehaviour)this).StartCoroutine(LoadFacePrefabRoutine());
			}
			if (((Object)(object)cachedRoachPrefab == (Object)null || (Object)(object)cachedGoldRoachPrefab == (Object)null || (Object)(object)cachedWhiteRoachPrefab == (Object)null) && !loadingRoach)
			{
				((MonoBehaviour)this).StartCoroutine(LoadRoachPrefabRoutine());
			}
			if ((Object)(object)cachedRoachPrefab != (Object)null && !loadingRoach)
			{
				roachesSpawned = true;
				SpawnRoaches(((Component)current).GetComponentsInChildren<RoachMarker>(true));
			}
			nextSpawnAttempt = Time.time + 0.5f;
			MapApi.SetVar("generators", "0");
			MapApi.ShowTitle("SISYPHUS // 15 — 0/15 BEACONS ([M] MAP)");
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("TRACK v0.6.0 started: 15 radars across 3 sails (±{0}), DeadFace phases=[{1}], MapStart={2}, RoofElevator={3}, InvCap={4}, Remains={5}, DeadFace={6}.", 10, string.Join(",", faceThresholds), mapMode, (Object)(object)roofElevator != (Object)null, inventoryLimit.Value, (Object)(object)cachedRemainsPrefab != (Object)null, (Object)(object)cachedFacePrefab != (Object)null));
		}

		private string ResolveMetaPath()
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			if (!string.IsNullOrEmpty(directoryName))
			{
				string text = Path.Combine(directoryName, "maps", "TRACK_start_test.meta.json");
				if (File.Exists(text))
				{
					return text;
				}
			}
			string text2 = Path.Combine(Paths.PluginPath, "WKMapLoader", "maps", "TRACK_start_test.meta.json");
			if (File.Exists(text2))
			{
				return text2;
			}
			try
			{
				string[] files = Directory.GetFiles(Paths.PluginPath, "TRACK_start_test.meta.json", SearchOption.AllDirectories);
				if (files.Length != 0)
				{
					return files[0];
				}
			}
			catch
			{
			}
			return text2;
		}

		private void LoadTrackMetaJson()
		{
			//IL_002f: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string path = ResolveMetaPath();
				string txt;
				if (File.Exists(path))
				{
					txt = File.ReadAllText(path);
					if (TryReadVec("button_local_center", out var vec))
					{
						radarBtnLocalCenter = vec;
					}
					if (TryReadVec("button_world_center", out var vec2))
					{
						elevBtnWorldCenter = vec2;
					}
					if (TryReadVec("cab_unity_pos", out var vec3))
					{
						elevCabWorldPos = vec3;
					}
				}
				bool TryReadVec(string key, out Vector3 reference)
				{
					//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_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)
					reference = Vector3.zero;
					Match match = Regex.Match(txt, "\"" + Regex.Escape(key) + "\"\\s*:\\s*\\[\\s*([-0-9.eE+]+)\\s*,\\s*([-0-9.eE+]+)\\s*,\\s*([-0-9.eE+]+)\\s*\\]");
					if (!match.Success)
					{
						return false;
					}
					if (float.TryParse(match.Groups[1].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(match.Groups[2].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(match.Groups[3].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
					{
						reference = new Vector3(result, result2, result3);
						return true;
					}
					return false;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to read TRACK_start_test.meta.json (using calibrated defaults): " + ex.Message));
			}
		}

		private void FindRadarTemplates(M_Level current)
		{
			MeshFilter[] componentsInChildren = ((Component)current).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null))
				{
					string text = ((Object)val.sharedMesh).name ?? "";
					if (text == "TRACK_TheRadar_Body" || ((Object)((Component)val).gameObject).name == "TRACK_TheRadar_Body")
					{
						radarBodyTemplate = ((Component)val).gameObject;
					}
					else if (text == "TRACK_TheRadar_Button" || ((Object)((Component)val).gameObject).name == "TRACK_TheRadar_Button")
					{
						radarButtonTemplate = ((Component)val).gameObject;
					}
				}
			}
		}

		private void SetupRoofElevator(M_Level current, int interactLayer)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_01af: Expected O, but got Unknown
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Expected O, but got Unknown
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Expected O, but got Unknown
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TRACK_RoofElevatorLogic");
			val.transform.SetParent(((Component)current).transform, false);
			val.transform.position = elevCabWorldPos;
			spawned.Add(val);
			RoofElevatorController ctrl = val.AddComponent<RoofElevatorController>();
			ctrl.ClipChime = clipElevChime ?? clipVictory;
			ctrl.ClipBeep = clipElevBeep ?? clipButtonPress;
			ctrl.GetActivatedCount = () => run.Count;
			ctrl.OnInstantWin = TriggerCleanInstantVictory;
			GameObject val2 = new GameObject("RoofElevatorLamp");
			val2.transform.SetParent(val.transform, false);
			val2.transform.position = elevCabWorldPos + new Vector3(0f, 3.8f, 0f);
			CL_Lamp val3 = val2.AddComponent<CL_Lamp>();
			val3.lampActive = true;
			val3.range = 14f;
			val3.curRange = 14f;
			val3.startColor = new Color(0.95f, 0.22f, 0.12f);
			val3.color = val3.startColor;
			val3.intensity = 0.35f;
			val3.attentuation = 1;
			val3.emissiveMult = 1f;
			val3.bypassLightmap = 1f;
			val3.forwardPlusHiddenMult = 1f;
			val3.prioritizeOnEnable = false;
			if ((Object)(object)FXManager.fxMan != (Object)null)
			{
				FXManager.fxMan.UpdateLamp(val3);
			}
			ctrl.StatusLamp = val3;
			GameObject val4 = new GameObject("RoofElevatorButton");
			val4.layer = interactLayer;
			val4.transform.SetParent(val.transform, false);
			val4.transform.position = new Vector3(elevBtnWorldCenter.x + 0.3f, elevCabWorldPos.y + 2.85f, elevBtnWorldCenter.z);
			BoxCollider obj = val4.AddComponent<BoxCollider>();
			obj.size = new Vector3(1.15f, 3.2f, 1.8f);
			((Collider)obj).isTrigger = true;
			val4.AddComponent<ObjectTagger>().AddTag("Button");
			CL_Button val5 = val4.AddComponent<CL_Button>();
			val5.active = true;
			val5.maxPresses = 0;
			val5.pressCooldown = 0.35f;
			val5.hammerCanPress = true;
			val5.projectilesCanPress = true;
			val5.pressSound = clipElevBeep ?? clipButtonPress;
			val5.activeEvent = new UnityEvent();
			val5.activeEvent.AddListener((UnityAction)delegate
			{
				ctrl.OnButtonPressed();
			});
			ctrl.Button = val5;
			MapLabel label = val4.AddComponent<MapLabel>();
			ctrl.Label = label;
			ctrl.UpdateProgress(0, 15);
			roofElevator = ctrl;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Roof Elevator_Tether_01 wired at {elevCabWorldPos} (button trigger at {val4.transform.position}, zero blocking colliders, zero cubes).");
		}

		private static void ExpandLevelBounds(M_Level target)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null)
			{
				return;
			}
			Bounds val = default(Bounds);
			((Bounds)(ref val))..ctor(Vector3.zero, new Vector3(24000f, 4000f, 24000f));
			target.customBounds = true;
			target.levelBounds = val;
			FieldInfo field = typeof(M_Level).GetField("currentBoundsLocal", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(target, val);
			}
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject != (Object)null)
			{
				FieldInfo field2 = typeof(ENT_Player).GetField("oobCounter", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field2 != null)
				{
					field2.SetValue(playerObject, 0f);
				}
			}
		}

		private void BuildTrackAutoGameplayLayout(M_Level current)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0051: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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_013b: 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_015f: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: 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_02ef: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TRACK_StationsGameplay");
			val.transform.SetParent(((Component)current).transform, false);
			spawned.Add(val);
			int interactLayer = GetInteractLayer();
			EnsureBeaconHaloAssets();
			startTowerHalo = CreateBeaconHalo(val.transform, "StartTower_LiftHalo", new Vector3(0f, 160f, 0f), new Color(0.96f, 0.78f, 0.34f, 0.78f), 4f, 0.011f, 52f, 0f);
			List<(int id, int row, int j, Vector3 pos, float yaw, Vector3 towerCenter, Vector3 roachBridgePos)> placements = new List<(int, int, int, Vector3, float, Vector3, Vector3)>();
			int nextId = 1;
			AddSailStations(0, PickSailTowers(excludeZero: true, forceNearStart: true));
			AddSailStations(-1, PickSailTowers(excludeZero: false, forceNearStart: false));
			AddSailStations(1, PickSailTowers(excludeZero: false, forceNearStart: false));
			foreach (var (num, rowIndex, towerIndex, val2, num2, towerCenter, pos) in placements)
			{
				BuildRadarStation(val.transform, num, rowIndex, towerIndex, val2, towerCenter, Quaternion.Euler(0f, num2, 0f), interactLayer);
				AddRoachMarker(val.transform, $"Roaches_Tower_{num:00}", val2 + Vector3.up * 0.2f, roachesPerStation.Value);
				AddRoachMarker(val.transform, $"Roaches_Bridge_{num:00}", pos, Mathf.Max(4, roachesPerStation.Value / 2));
			}
			AddRoachMarker(val.transform, "Roaches_StartNorth", new Vector3(0f, 15.2f, 14.5f), 8);
			AddRoachMarker(val.transform, "Roaches_StartSouth", new Vector3(0f, 15.2f, -14.5f), 8);
			AddRoachMarker(val.transform, "Roaches_StartWest", new Vector3(-11.5f, 15.2f, 0f), 8);
			AddRoachMarker(val.transform, "Roaches_StartEast", new Vector3(11.5f, 15.2f, -4f), 6);
			AddPursuerMarker(val.transform, "RemainsSpawn_00", 0, new Vector3(0f, 17.5f, -110f));
			AddPursuerMarker(val.transform, "RemainsSpawn_02", 2, new Vector3(0f, 17.5f, 110f));
			AddPursuerMarker(val.transform, "RemainsSpawn_08", 8, new Vector3(0f, 17.5f, -115f));
			AddPursuerMarker(val.transform, "RemainsSpawn_12", 12, new Vector3(0f, 17.5f, 115f));
			string arg = string.Join(", ", placements.Select(((int id, int row, int j, Vector3 pos, float yaw, Vector3 towerCenter, Vector3 roachBridgePos) p) => string.Format("{0}{1:+0;-0;0}", (p.row < 0) ? "L" : ((p.row > 0) ? "R" : "C"), p.j)));
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Built 15 grounded TheRadar stations strictly on 3 sails (±{10} max): [{arg}] (customModel={(Object)(object)radarBodyTemplate != (Object)null}, soft radial tower halos active, zero cubes).");
			void AddSailStations(int row, List<int> towerIndices)
			{
				//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_0133: Unknown result type (might be due to invalid IL or missing references)
				float num3 = (float)row * 3156.93f;
				Vector3 item = default(Vector3);
				Vector3 item2 = default(Vector3);
				Vector3 item4 = default(Vector3);
				foreach (int towerIndex2 in towerIndices)
				{
					float num4 = (float)towerIndex2 * 235.90077f;
					((Vector3)(ref item))..ctor(num3, 15f, num4);
					float item3;
					if (row == 0)
					{
						bool flag = towerIndex2 > 0;
						((Vector3)(ref item2))..ctor(0f, 15f, num4 + (flag ? (-13.5f) : 13.5f));
						item3 = (flag ? 180f : 0f);
						((Vector3)(ref item4))..ctor(0f, 15.2f, num4 + (flag ? (-117.950386f) : 117.950386f));
					}
					else if (row < 0)
					{
						((Vector3)(ref item2))..ctor(num3 + 12.2f, 15f, num4);
						item3 = 90f;
						((Vector3)(ref item4))..ctor(num3, 15.2f, num4 + ((towerIndex2 >= 0) ? (-117.950386f) : 117.950386f));
					}
					else
					{
						((Vector3)(ref item2))..ctor(num3 - 12.2f, 15f, num4);
						item3 = -90f;
						((Vector3)(ref item4))..ctor(num3, 15.2f, num4 + ((towerIndex2 >= 0) ? (-117.950386f) : 117.950386f));
					}
					placements.Add((nextId++, row, towerIndex2, item2, item3, item, item4));
				}
			}
			static List<int> PickSailTowers(bool excludeZero, bool forceNearStart)
			{
				HashSet<int> hashSet = new HashSet<int>();
				List<int> list = new List<int>();
				List<int> list2 = new List<int>();
				for (int i = 1; i <= 10; i++)
				{
					list.Add(i);
					list2.Add(-i);
				}
				Shuffle(list);
				Shuffle(list2);
				if (forceNearStart)
				{
					int item = ((Random.value < 0.5f) ? 1 : (-1));
					hashSet.Add(item);
				}
				else if (!excludeZero)
				{
					int item2 = Random.Range(-2, 3);
					hashSet.Add(item2);
				}
				int num3 = hashSet.Count((int x) => x > 0);
				foreach (int item5 in list)
				{
					if (hashSet.Count >= 5 || num3 >= 2)
					{
						break;
					}
					if (hashSet.Add(item5))
					{
						num3++;
					}
				}
				int num4 = hashSet.Count((int x) => x < 0);
				foreach (int item6 in list2)
				{
					if (hashSet.Count >= 5 || num4 >= 2)
					{
						break;
					}
					if (hashSet.Add(item6))
					{
						num4++;
					}
				}
				List<int> list3 = new List<int>();
				for (int num5 = -10; num5 <= 10; num5++)
				{
					if ((!excludeZero || num5 != 0) && !hashSet.Contains(num5))
					{
						list3.Add(num5);
					}
				}
				Shuffle(list3);
				foreach (int item7 in list3)
				{
					if (hashSet.Count >= 5)
					{
						break;
					}
					hashSet.Add(item7);
				}
				List<int> list4 = hashSet.ToList();
				list4.Sort((int a, int b) => Math.Abs(a).CompareTo(Math.Abs(b)));
				return list4;
			}
			static void Shuffle(List<int> list)
			{
				for (int num3 = list.Count - 1; num3 > 0; num3--)
				{
					int index = Random.Range(0, num3 + 1);
					int value = list[num3];
					list[num3] = list[index];
					list[index] = value;
				}
			}
		}

		private void BuildRadarStation(Transform parent, int id, int rowIndex, int towerIndex, Vector3 worldPos, Vector3 towerCenter, Quaternion rot, int interactLayer)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0036: 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_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: 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_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_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: 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_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Expected O, but got Unknown
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Expected O, but got Unknown
			//IL_0562: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject($"GeneratorStation_{id:00}");
			val.transform.SetParent(parent, false);
			val.transform.position = worldPos;
			val.transform.rotation = rot;
			StationMarker stationMarker = val.AddComponent<StationMarker>();
			stationMarker.Id = id;
			stationMarker.RowIndex = rowIndex;
			stationMarker.TowerIndex = towerIndex;
			if ((Object)(object)radarBodyTemplate != (Object)null)
			{
				Vector3 position = radarBodyTemplate.transform.position;
				MeshFilter component = radarBodyTemplate.GetComponent<MeshFilter>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
				{
					float y = position.y;
					Bounds bounds = component.sharedMesh.bounds;
					if (Mathf.Abs(y + ((Bounds)(ref bounds)).min.y) > 0.25f)
					{
						bounds = component.sharedMesh.bounds;
						position.y = 0f - ((Bounds)(ref bounds)).min.y - 0.05f;
					}
				}
				GameObject val2 = Object.Instantiate<GameObject>(radarBodyTemplate, val.transform, false);
				((Object)val2).name = "TheRadarBody";
				val2.layer = 0;
				val2.transform.localPosition = position;
				val2.transform.localRotation = Quaternion.identity;
				val2.transform.localScale = Vector3.one;
				val2.SetActive(true);
				if ((Object)(object)val2.GetComponent<ObjectMaterial>() == (Object)null)
				{
					val2.AddComponent<ObjectMaterial>().type = (MaterialType)1;
				}
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.center = new Vector3(0f, 1.85f, 0.05f);
				obj.size = new Vector3(0.45f, 3.7f, 0.45f);
				MeshRenderer val3 = null;
				if ((Object)(object)radarButtonTemplate != (Object)null)
				{
					Vector3 val4 = radarButtonTemplate.transform.position - radarBodyTemplate.transform.position;
					GameObject obj2 = Object.Instantiate<GameObject>(radarButtonTemplate, val.transform, false);
					((Object)obj2).name = "TheRadarButtonVisual";
					obj2.layer = 0;
					obj2.transform.localPosition = position + val4;
					obj2.transform.localRotation = Quaternion.identity;
					obj2.transform.localScale = Vector3.one;
					obj2.SetActive(true);
					val3 = obj2.GetComponent<MeshRenderer>();
					if ((Object)(object)val3 != (Object)null)
					{
						((Renderer)val3).sharedMaterial = matBtnOffline;
					}
				}
				stationMarker.ButtonRenderer = (Renderer)(object)val3;
			}
			GameObject val5 = new GameObject("RedBeaconLamp");
			val5.transform.SetParent(val.transform, false);
			val5.transform.localPosition = new Vector3(0f, 4.4f, 0.6f);
			CL_Lamp val6 = val5.AddComponent<CL_Lamp>();
			val6.lampActive = true;
			val6.range = 34f;
			val6.curRange = 34f;
			val6.startColor = new Color(1f, 0.14f, 0.04f);
			val6.color = val6.startColor;
			val6.intensity = 0.64f;
			val6.attentuation = 1;
			val6.emissiveMult = 1f;
			val6.bypassLightmap = 1f;
			val6.forwardPlusHiddenMult = 1f;
			val6.prioritizeOnEnable = false;
			if ((Object)(object)FXManager.fxMan != (Object)null)
			{
				FXManager.fxMan.UpdateLamp(val6);
			}
			stationMarker.BeaconLamp = val6;
			Color color = default(Color);
			((Color)(ref color))..ctor(1f, 0.16f, 0.05f, 0.92f);
			float num = (float)id * 0.67f;
			BeaconHaloBillboard beaconHaloBillboard = CreateBeaconHalo(parent, $"BeaconHalo_Low_{id:00}", worldPos + new Vector3(0f, 4.25f, 0f), color, 1.4f, 0.0045f, 16f, num);
			BeaconHaloBillboard beaconHaloBillboard2 = CreateBeaconHalo(parent, $"BeaconHalo_Mid_{id:00}", new Vector3(towerCenter.x, 58f, towerCenter.z), color, 2.6f, 0.0085f, 36f, num + 0.5f);
			BeaconHaloBillboard beaconHaloBillboard3 = CreateBeaconHalo(parent, $"BeaconHalo_Top_{id:00}", new Vector3(towerCenter.x, 128f, towerCenter.z), color, 3.6f, 0.0125f, 56f, num + 1f);
			stationMarker.BeaconHalos = (GameObject[])(object)new GameObject[3]
			{
				((Component)beaconHaloBillboard).gameObject,
				((Component)beaconHaloBillboard2).gameObject,
				((Component)beaconHaloBillboard3).gameObject
			};
			GameObject val7 = new GameObject($"GeneratorButton_{id:00}");
			val7.layer = interactLayer;
			val7.transform.SetParent(val.transform, false);
			val7.transform.localPosition = radarBtnLocalCenter;
			BoxCollider obj3 = val7.AddComponent<BoxCollider>();
			obj3.size = new Vector3(0.55f, 0.65f, 0.42f);
			((Collider)obj3).isTrigger = true;
			val7.AddComponent<ObjectTagger>().AddTag("Button");
			CL_Button val8 = val7.AddComponent<CL_Button>();
			val8.active = true;
			val8.maxPresses = 1;
			val8.pressCooldown = 0.25f;
			val8.hammerCanPress = true;
			val8.projectilesCanPress = true;
			val8.pressSound = clipButtonPress;
			val8.activeEvent = new UnityEvent();
			int capturedId = id;
			val8.activeEvent.AddListener((UnityAction)delegate
			{
				Activate(capturedId);
			});
			stationMarker.Button = val8;
			string arg = ((rowIndex < 0) ? "L" : ((rowIndex > 0) ? "R" : "C"));
			MapLabel val9 = val7.AddComponent<MapLabel>();
			val9.title = $"RADAR {id:00} [{arg}{towerIndex:+0;-0;0}]";
			val9.description = "Press button or hit with Hammer to pump Mass down";
			stationMarker.Label = val9;
		}

		private void EnsureBeaconHaloAssets()
		{
			//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_0022: Expected O, but got Unknown
			//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_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_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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Expected O, but got Unknown
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Expected O, but got Unknown
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)sharedHaloQuadMesh == (Object)null)
			{
				Mesh val = new Mesh
				{
					name = "TRACK_BeaconHaloQuad"
				};
				val.vertices = (Vector3[])(object)new Vector3[4]
				{
					new Vector3(-0.5f, -0.5f, 0f),
					new Vector3(0.5f, -0.5f, 0f),
					new Vector3(-0.5f, 0.5f, 0f),
					new Vector3(0.5f, 0.5f, 0f)
				};
				val.uv = (Vector2[])(object)new Vector2[4]
				{
					new Vector2(0f, 0f),
					new Vector2(1f, 0f),
					new Vector2(0f, 1f),
					new Vector2(1f, 1f)
				};
				val.normals = (Vector3[])(object)new Vector3[4]
				{
					Vector3.back,
					Vector3.back,
					Vector3.back,
					Vector3.back
				};
				val.colors = (Color[])(object)new Color[4]
				{
					Color.white,
					Color.white,
					Color.white,
					Color.white
				};
				val.triangles = new int[6] { 0, 2, 1, 1, 2, 3 };
				val.bounds = new Bounds(Vector3.zero, Vector3.one * 2f);
				sharedHaloQuadMesh = val;
				createdMeshes.Add(val);
			}
			if ((Object)(object)sharedHaloTexture == (Object)null)
			{
				Texture2D val2 = new Texture2D(64, 64, (TextureFormat)4, false);
				((Object)val2).name = "TRACK_BeaconRadialGlow";
				((Texture)val2).wrapMode = (TextureWrapMode)1;
				((Texture)val2).filterMode = (FilterMode)1;
				Color[] array = (Color[])(object)new Color[4096];
				float num = 31.5f;
				for (int i = 0; i < 64; i++)
				{
					for (int j = 0; j < 64; j++)
					{
						float num2 = ((float)j - num) / num;
						float num3 = ((float)i - num) / num;
						float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
						if (num4 >= 0.96f)
						{
							array[i * 64 + j] = new Color(1f, 1f, 1f, 0f);
							continue;
						}
						float num5 = Mathf.Clamp01((0.96f - num4) / 0.24f);
						float num6 = Mathf.Exp((0f - num4) * num4 * 16f);
						float num7 = Mathf.Clamp01(Mathf.Exp((0f - num4) * num4 * 3.8f) * num5 * 0.88f + num6 * 0.45f);
						float num8 = Mathf.Lerp(0.85f, 1f, num6);
						array[i * 64 + j] = new Color(num8, num8, num8, num7);
					}
				}
				val2.SetPixels(array);
				val2.Apply(false, true);
				sharedHaloTexture = val2;
				createdTextures.Add(val2);
			}
			if ((Object)(object)sharedHaloMaterial == (Object)null)
			{
				Material val3 = new Material(Shader.Find("Sprites/Default") ?? Shader.Find("Dark Machine/SHDR_Base_UnlitTransparent") ?? ((IEnumerable<Shader>)Resources.FindObjectsOfTypeAll<Shader>()).FirstOrDefault((Func<Shader, bool>)((Shader s) => (Object)(object)s != (Object)null && ((Object)s).name == "Dark Machine/SHDR_Base_UnlitTransparent")));
				((Object)val3).name = "WKMap_TRACK_BeaconHalo";
				if (val3.HasProperty("_MainTex"))
				{
					val3.SetTexture("_MainTex", (Texture)(object)sharedHaloTexture);
				}
				if (val3.HasProperty("_Color"))
				{
					val3.SetColor("_Color", Color.white);
				}
				if (val3.HasProperty("_IgnoreFog"))
				{
					val3.SetFloat("_IgnoreFog", 1f);
				}
				if (val3.HasProperty("_Bright"))
				{
					val3.SetFloat("_Bright", 0f);
				}
				if (val3.HasProperty("_Shading"))
				{
					val3.SetFloat("_Shading", 0f);
				}
				if (val3.HasProperty("_DitherAmount"))
				{
					val3.SetFloat("_DitherAmount", 0f);
				}
				if (val3.HasProperty("_Wiggle"))
				{
					val3.SetFloat("_Wiggle", 0f);
				}
				if (val3.HasProperty("_WorldWiggleModifier"))
				{
					val3.SetFloat("_WorldWiggleModifier", 0f);
				}
				if (val3.HasProperty("_ROUNDMULT"))
				{
					val3.SetFloat("_ROUNDMULT", 0f);
				}
				val3.renderQueue = 3150;
				sharedHaloMaterial = val3;
				createdMaterials.Add(val3);
			}
		}

		private BeaconHaloBillboard CreateBeaconHalo(Transform parent, string name, Vector3 worldPos, Color color, float baseSize, float angularFactor, float maxSize, float phase)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name)
			{
				layer = 0
			};
			val.transform.SetParent(parent, false);
			val.transform.position = worldPos;
			val.AddComponent<MeshFilter>().sharedMesh = sharedHaloQuadMesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = sharedHaloMaterial;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			BeaconHaloBillboard beaconHaloBillboard = val.AddComponent<BeaconHaloBillboard>();
			beaconHaloBillboard.BaseColor = color;
			beaconHaloBillboard.BaseSize = baseSize;
			beaconHaloBillboard.AngularFactor = angularFactor;
			beaconHaloBillboard.MinSize = Mathf.Max(0.9f, baseSize * 0.7f);
			beaconHaloBillboard.MaxSize = maxSize;
			beaconHaloBillboard.Phase = phase;
			return beaconHaloBillboard;
		}

		private static void AddRoachMarker(Transform parent, string name, Vector3 pos, int count)
		{
			//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_0018: 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)
			if (count > 0)
			{
				GameObject val = new GameObject(name);
				val.transform.SetParent(parent, false);
				val.transform.position = pos;
				val.AddComponent<RoachMarker>().Count = count;
			}
		}

		private static void AddPursuerMarker(Transform parent, string name, int threshold, Vector3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.position = pos;
			val.AddComponent<PursuerMarker>().Threshold = threshold;
		}

		private static int GetInteractLayer()
		{
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject != (Object)null)
			{
				int value = ((LayerMask)(ref playerObject.interactMask)).value;
				if ((value & 0x400000) != 0)
				{
					return 22;
				}
				for (int i = 0; i < 32; i++)
				{
					if ((value & (1 << i)) != 0)
					{
						return i;
					}
				}
			}
			return 22;
		}

		private void BuildButtonMaterials()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			DestroyCreatedMaterials();
			Material val = ((IEnumerable<Material>)Resources.FindObjectsOfTypeAll<Material>()).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null && ((Object)m.shader).name == "Dark Machine/SHDR_Base" && !(((Object)m).name ?? "").StartsWith("WKMap_")));
			Shader fallback = (((Object)(object)val != (Object)null) ? val.shader : (Shader.Find("Dark Machine/SHDR_Base") ?? Shader.Find("Standard")));
			matBtnOffline = MakeEmissiveMat(val, fallback, "WKMap_STATION_BtnOffline", new Color(0.95f, 0.18f, 0.06f), 1.4f);
			matBtnOnline = MakeEmissiveMat(val, fallback, "WKMap_STATION_BtnOnline", new Color(0.18f, 0.85f, 0.42f), 1.3f);
		}

		private Material MakeEmissiveMat(Material template, Shader fallback, string matName, Color col, float emiMult)
		{
			//IL_0012: 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_0018: Expected O, but got Unknown
			//IL_00e0: 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)
			Material val = (((Object)(object)template != (Object)null) ? new Material(template) : new Material(fallback));
			((Object)val).name = matName;
			if (val.HasProperty("_Noise"))
			{
				val.SetTexture("_Noise", (Texture)(object)Texture2D.whiteTexture);
			}
			if (val.HasProperty("_Shimmer"))
			{
				val.SetFloat("_Shimmer", 0f);
			}
			if (val.HasProperty("_ShimmerTextureMix"))
			{
				val.SetFloat("_ShimmerTextureMix", 0f);
			}
			if (val.HasProperty("_CorruptAmount"))
			{
				val.SetFloat("_CorruptAmount", 0f);
			}
			if (val.HasProperty("_MainTex"))
			{
				val.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture);
			}
			if (val.HasProperty("_BaseMap"))
			{
				val.SetTexture("_BaseMap", (Texture)(object)Texture2D.whiteTexture);
			}
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", col);
			}
			if (val.HasProperty("_Emission"))
			{
				val.SetTexture("_Emission", (Texture)(object)Texture2D.whiteTexture);
			}
			if (val.HasProperty("_EmissionMap"))
			{
				val.SetTexture("_EmissionMap", (Texture)(object)Texture2D.whiteTexture);
			}
			if (val.HasProperty("_EmissionColor"))
			{
				val.SetColor("_EmissionColor", col);
			}
			if (val.HasProperty("_EmissionMultiplier"))
			{
				val.SetFloat("_EmissionMultiplier", emiMult);
			}
			if (val.HasProperty("_Shading"))
			{
				val.SetFloat("_Shading", 0.15f);
			}
			createdMaterials.Add(val);
			return val;
		}

		private void DestroyCreatedMaterials()
		{
			for (int i = 0; i < createdMaterials.Count; i++)
			{
				if ((Object)(object)createdMaterials[i] != (Object)null)
				{
					Object.Destroy((Object)(object)createdMaterials[i]);
				}
			}
			createdMaterials.Clear();
			for (int j = 0; j < createdTextures.Count; j++)
			{
				if ((Object)(object)createdTextures[j] != (Object)null)
				{
					Object.Destroy((Object)(object)createdTextures[j]);
				}
			}
			createdTextures.Clear();
			for (int k = 0; k < createdMeshes.Count; k++)
			{
				if ((Object)(object)createdMeshes[k] != (Object)null)
				{
					Object.Destroy((Object)(object)createdMeshes[k]);
				}
			}
			createdMeshes.Clear();
			matBtnOffline = (matBtnOnline = null);
			sharedHaloMaterial = null;
			sharedHaloTexture = null;
			sharedHaloQuadMesh = null;
		}

		private void ResolveAudioClips()
		{
			AudioClip[] clips = Resources.FindObjectsOfTypeAll<AudioClip>();
			if ((Object)(object)clipButtonPress == (Object)null)
			{
				clipButtonPress = FindExactOrPartial(new string[5] { "mech_civilian_elevator_button_beep", "button", "switch", "click", "lever" });
			}
			if ((Object)(object)clipGeneratorOnline == (Object)null)
			{
				clipGeneratorOnline = FindExactOrPartial(new string[5] { "power", "generator", "machine", "hydraulic", "horn" });
			}
			if ((Object)(object)clipVictory == (Object)null)
			{
				clipVictory = FindExactOrPartial(new string[5] { "elevator_chime1", "computer_chime_new", "chime", "bell", "complete" });
			}
			if ((Object)(object)clipElevChime == (Object)null)
			{
				clipElevChime = FindExactOrPartial(new string[3] { "elevator_chime1", "computer_chime_new", "chime" });
			}
			if ((Object)(object)clipElevBeep == (Object)null)
			{
				clipElevBeep = FindExactOrPartial(new string[2] { "mech_civilian_elevator_button_beep", "button" });
			}
			faceScreamClips.Clear();
			string[] array = new string[7] { "MFace_hunt_start1", "MFace_hunt_start2", "den_face_call", "MFace_bark1", "MFace_bark2", "den_face_distant1", "den_face_distant2" };
			foreach (string nm in array)
			{
				AudioClip val = ((IEnumerable<AudioClip>)clips).FirstOrDefault((Func<AudioClip, bool>)((AudioClip c) => (Object)(object)c != (Object)null && string.Equals(((Object)c).name, nm, StringComparison.OrdinalIgnoreCase)));
				if ((Object)(object)val != (Object)null && !faceScreamClips.Contains(val))
				{
					faceScreamClips.Add(val);
				}
			}
			AudioClip FindExactOrPartial(string[] patterns)
			{
				string[] array2 = patterns;
				foreach (string pat in array2)
				{
					AudioClip val2 = ((IEnumerable<AudioClip>)clips).FirstOrDefault((Func<AudioClip, bool>)((AudioClip c) => (Object)(object)c != (Object)null && string.Equals(((Object)c).name, pat, StringComparison.OrdinalIgnoreCase)));
					if ((Object)(object)val2 != (Object)null)
					{
						return val2;
					}
				}
				array2 = patterns;
				foreach (string pat2 in array2)
				{
					AudioClip val3 = ((IEnumerable<AudioClip>)clips).FirstOrDefault((Func<AudioClip, bool>)((AudioClip c) => (Object)(object)c != (Object)null && ((Object)c).name.IndexOf(pat2, StringComparison.OrdinalIgnoreCase) >= 0));
					if ((Object)(object)val3 != (Object)null)
					{
						return val3;
					}
				}
				return null;
			}
		}

		private void PlayRealFaceSpawnScream(GameObject faceGo, ENT_Player player)
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			ResolveAudioClips();
			AudioClip val = faceScreamClips.FirstOrDefault();
			if ((Object)(object)val == (Object)null && (Object)(object)faceGo != (Object)null)
			{
				UT_AudioClipHandler componentInChildren = faceGo.GetComponentInChildren<UT_AudioClipHandler>(true);
				if ((Object)(object)componentInChildren != (Object)null && componentInChildren.groups != null)
				{
					foreach (AudioGroup group in componentInChildren.groups)
					{
						if (group?.audioSets == null)
						{
							continue;
						}
						foreach (AudioSet audioSet in group.audioSets)
						{
							if (audioSet?.clips != null)
							{
								AudioClip val2 = ((IEnumerable<AudioClip>)audioSet.clips).FirstOrDefault((Func<AudioClip, bool>)((AudioClip c) => (Object)(object)c != (Object)null && (((Object)c).name.IndexOf("hunt_start", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)c).name.IndexOf("face_call", StringComparison.OrdinalIgnoreCase) >= 0)));
								if ((Object)(object)val2 != (Object)null)
								{
									val = val2;
									break;
								}
							}
						}
						if ((Object)(object)val != (Object)null)
						{
							break;
						}
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				AudioManager.PlaySound(val, ((Component)player).transform.position, 1f, 1f, 0f, false, 0.85f, (AudioMixerGroup)null, "");
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Played authentic Dead Face (DEN_Face) scream '{((Object)val).name}' (len={val.length:F2}s).");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"No MFace_hunt_start / den_face_call clip found in memory.");
			}
		}

		private static bool IsValidCrawlerRoach(GameObject go)
		{
			if ((Object)(object)go == (Object)null || (Object)(object)go.GetComponent<DEN_Roach>() == (Object)null)
			{
				return false;
			}
			string text = ((Object)go).name ?? "";
			if (text.IndexOf("Navmesh", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Explosive", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Flying", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Tick", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Hopper", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return text.IndexOf("Giant", StringComparison.OrdinalIgnoreCase) < 0;
			}
			return false;
		}

		private void TryFindPrefabsInMemory()
		{
			WKAssetDatabase val = CL_AssetManager.GetFullCombinedAssetDatabase() ?? CL_AssetManager.GetBaseAssetDatabase();
			GameObject[] source = (((Object)(object)val != (Object)null) ? (from p in val.denizenPrefabs.Concat(val.entityPrefabs)
				where (Object)(object)p != (Object)null
				select p).Distinct().ToArray() : Array.Empty<GameObject>());
			GameObject[] source2 = (from r in Resources.FindObjectsOfTypeAll<DEN_Roach>().Where(delegate(DEN_Roach r)
				{
					//IL_000f: 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)
					if ((Object)(object)r != (Object)null)
					{
						Scene scene = ((Component)r).gameObject.scene;
						if (((Scene)(ref scene)).rootCount == 0)
						{
							return IsValidCrawlerRoach(((Component)r).gameObject);
						}
					}
					return false;
				})
				select ((Component)r).gameObject).Distinct().ToArray();
			if ((Object)(object)cachedRemainsPrefab == (Object)null)
			{
				if (!string.IsNullOrEmpty(remainsPrefabOverride.Value))
				{
					cachedRemainsPrefab = CL_AssetManager.GetAssetGameObject(remainsPrefabOverride.Value, "") ?? ((IEnumerable<GameObject>)source).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => ((Object)p).name.Equals(remainsPrefabOverride.Value, StringComparison.OrdinalIgnoreCase)));
				}
				object obj = cachedRemainsPrefab;
				if (obj == null)
				{
					obj = CL_AssetManager.GetAssetGameObject("Denizen_Remains_Active", "");
					if (obj == null)
					{
						obj = ((IEnumerable<GameObject>)source).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p.GetComponent<DEN_Remains_Active>() != (Object)null));
						if (obj == null)
						{
							DEN_Remains_Active? obj2 = ((IEnumerable<DEN_Remains_Active>)Resources.FindObjectsOfTypeAll<DEN_Remains_Active>()).FirstOrDefault((Func<DEN_Remains_Active, bool>)delegate(DEN_Remains_Active r)
							{
								//IL_000f: 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)
								if ((Object)(object)r != (Object)null)
								{
									Scene scene = ((Component)r).gameObject.scene;
									return ((Scene)(ref scene)).rootCount == 0;
								}
								return false;
							});
							obj = ((obj2 != null) ? ((Component)obj2).gameObject : null);
						}
					}
				}
				cachedRemainsPrefab = (GameObject)obj;
			}
			if ((Object)(object)cachedFacePrefab == (Object)null)
			{
				object obj3 = CL_AssetManager.GetAssetGameObject("Denizen_Face", "");
				if (obj3 == null)
				{
					obj3 = ((IEnumerable<GameObject>)source).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p.GetComponent<DEN_Face>() != (Object)null));
					if (obj3 == null)
					{
						DEN_Face? obj4 = ((IEnumerable<DEN_Face>)Resources.FindObjectsOfTypeAll<DEN_Face>()).FirstOrDefault((Func<DEN_Face, bool>)delegate(DEN_Face f)
						{
							//IL_000f: 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)
							if ((Object)(object)f != (Object)null)
							{
								Scene scene = ((Component)f).gameObject.scene;
								return ((Scene)(ref scene)).rootCount == 0;
							}
							return false;
						});
						obj3 = ((obj4 != null) ? ((Component)obj4).gameObject : null);
					}
				}
				cachedFacePrefab = (GameObject)obj3;
			}
			if ((Object)(object)cachedRoachPrefab == (Object)null)
			{
				GameObject assetGameObject = CL_AssetManager.GetAssetGameObject("Denizen_Roach", "");
				if (IsValidCrawlerRoach(assetGameObject))
				{
					cachedRoachPrefab = assetGameObject;
				}
				cachedRoachPrefab = cachedRoachPrefab ?? ((IEnumerable<GameObject>)source).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => IsValidCrawlerRoach(p) && ((Object)p).name.Equals("Denizen_Roach", StringComparison.OrdinalIgnoreCase))) ?? ((IEnumerable<GameObject>)source2).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => ((Object)p).name.Equals("Denizen_Roach", StringComparison.OrdinalIgnoreCase))) ?? ((IEnumerable<GameObject>)source).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => IsValidCrawlerRoach(p) && ((Object)p).name.IndexOf("Gold", StringComparison.OrdinalIgnoreCase) <