Decompiled source of REPOLAST v0.1.2

REPOLAST.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("REPOLAST")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2")]
[assembly: AssemblyProduct("REPOLAST")]
[assembly: AssemblyTitle("REPOLAST")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 SharpGlass
{
	internal static class GlassAudio
	{
		private static readonly List<AudioSource> Sources = new List<AudioSource>();

		private static AudioClip[] _clips = Array.Empty<AudioClip>();

		private static int _nextSource;

		public static int ClipCount => _clips.Length;

		public static void Init()
		{
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			List<string> list = new List<string>();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				if (text.StartsWith("SharpGlass.Assets.glass_crunch_", StringComparison.Ordinal) && text.EndsWith(".wav", StringComparison.OrdinalIgnoreCase))
				{
					list.Add(text);
				}
			}
			list.Sort(StringComparer.Ordinal);
			List<AudioClip> list2 = new List<AudioClip>();
			foreach (string item in list)
			{
				using Stream stream = executingAssembly.GetManifestResourceStream(item);
				if (stream != null)
				{
					AudioClip val = GlassWav.Load(stream, Path.GetFileNameWithoutExtension(item));
					if ((Object)(object)val != (Object)null)
					{
						list2.Add(val);
					}
				}
			}
			_clips = list2.ToArray();
			GameObject val2 = new GameObject("SharpGlassAudio");
			Object.DontDestroyOnLoad((Object)(object)val2);
			for (int j = 0; j < 8; j++)
			{
				GameObject val3 = new GameObject($"SharpGlassAudio_{j}");
				val3.transform.SetParent(val2.transform, false);
				AudioSource val4 = val3.AddComponent<AudioSource>();
				val4.playOnAwake = false;
				val4.spatialBlend = 1f;
				val4.dopplerLevel = 0f;
				val4.rolloffMode = (AudioRolloffMode)1;
				val4.minDistance = 1.5f;
				val4.maxDistance = GlassConfig.AudioMaxDistance.Value;
				Sources.Add(val4);
			}
			ManualLogSource? log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)$"REPOLAST: loaded {_clips.Length} crunch clip(s).");
			}
		}

		public static void Play(Vector3 position, int variant, float volume)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (_clips.Length != 0 && Sources.Count != 0)
			{
				AudioSource obj = Sources[_nextSource];
				_nextSource = (_nextSource + 1) % Sources.Count;
				((Component)obj).transform.position = position;
				obj.clip = _clips[Mathf.Abs(variant) % _clips.Length];
				obj.volume = Mathf.Clamp01(volume);
				obj.pitch = Random.Range(0.92f, 1.08f);
				obj.maxDistance = GlassConfig.AudioMaxDistance.Value;
				obj.Play();
			}
		}
	}
	internal static class GlassConfig
	{
		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<int> PatchesPerLevel;

		public static ConfigEntry<int> MaxPatches;

		public static ConfigEntry<float> MinPatchSpacing;

		public static ConfigEntry<float> ExtractionClearance;

		public static ConfigEntry<float> TruckClearance;

		public static ConfigEntry<float> MaxFloorSlope;

		public static ConfigEntry<int> WalkRadius;

		public static ConfigEntry<int> SprintRadius;

		public static ConfigEntry<int> LandingRadius;

		public static ConfigEntry<bool> CrouchSilent;

		public static ConfigEntry<float> NoiseCooldown;

		public static ConfigEntry<float> AudioVolume;

		public static ConfigEntry<float> AudioMaxDistance;

		public static ConfigEntry<bool> DrawGizmos;

		public static void Init(ConfigFile config)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Expected O, but got Unknown
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Expected O, but got Unknown
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			Enabled = config.Bind<bool>("General", "Enabled", true, "Master switch for Sharp Glass.");
			PatchesPerLevel = config.Bind<int>("General", "PatchesPerLevel", 18, new ConfigDescription("Base number of glass patches per level. Room count scales this value.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(6, 40), Array.Empty<object>()));
			MaxPatches = config.Bind<int>("General", "MaxPatches", 30, new ConfigDescription("Hard cap on patches after room scaling.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 60), Array.Empty<object>()));
			MinPatchSpacing = config.Bind<float>("Placement", "MinPatchSpacing", 2.5f, new ConfigDescription("Minimum distance between glass patches in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1.5f, 5f), Array.Empty<object>()));
			ExtractionClearance = config.Bind<float>("Placement", "ExtractionClearance", 4f, new ConfigDescription("Keep glass at least this far from extraction points.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			TruckClearance = config.Bind<float>("Placement", "TruckClearance", 8f, new ConfigDescription("Keep glass at least this far from the truck/start.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), Array.Empty<object>()));
			MaxFloorSlope = config.Bind<float>("Placement", "MaxFloorSlope", 12f, new ConfigDescription("Maximum floor angle in degrees. Steeper surfaces are rejected.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 30f), Array.Empty<object>()));
			WalkRadius = config.Bind<int>("Noise", "WalkRadius", 12, new ConfigDescription("Enemy investigate radius for walking on glass. Values above 10 also affect enemy respawn timers.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 25), Array.Empty<object>()));
			SprintRadius = config.Bind<int>("Noise", "SprintRadius", 18, new ConfigDescription("Enemy investigate radius for sprinting on glass.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 25), Array.Empty<object>()));
			LandingRadius = config.Bind<int>("Noise", "LandingRadius", 20, new ConfigDescription("Enemy investigate radius for landing on glass.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 25), Array.Empty<object>()));
			CrouchSilent = config.Bind<bool>("Noise", "CrouchSilent", true, "Crouch-walking on glass makes no noise.");
			NoiseCooldown = config.Bind<float>("Noise", "NoiseCooldown", 0.6f, new ConfigDescription("Seconds between glass noise events for one player.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 2f), Array.Empty<object>()));
			AudioVolume = config.Bind<float>("Audio", "Volume", 0.8f, new ConfigDescription("Crunch volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			AudioMaxDistance = config.Bind<float>("Audio", "MaxDistance", 25f, new ConfigDescription("Maximum distance at which a crunch can be heard.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 60f), Array.Empty<object>()));
			DrawGizmos = config.Bind<bool>("Debug", "DrawGizmos", false, "Draw glass patch positions in the Unity scene view.");
		}
	}
	public sealed class GlassManager : MonoBehaviour
	{
		private readonly List<GlassPatch> _patches = new List<GlassPatch>();

		private readonly List<Placement> _placements = new List<Placement>();

		private GameObject? _root;

		private int _seed;

		private int _levelIndex;

		private bool _levelReady;

		private bool _hasPlacements;

		private float[]? _pendingPlacementData;

		private float _nextCheck;

		private float _nextLevelCheck;

		private float _lastStepTime;

		private int _lastGenerateFrame = -1;

		private GlassPatch? _lastPatch;

		public static GlassManager? Instance { get; private set; }

		public static void Create()
		{
			//IL_0013: 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: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				GameObject val = new GameObject("SharpGlassManager");
				Object.DontDestroyOnLoad((Object)val);
				Instance = val.AddComponent<GlassManager>();
			}
		}

		private void Awake()
		{
			Instance = this;
		}

		private void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		public void OnLevelGenerated()
		{
			if (Time.frameCount == _lastGenerateFrame)
			{
				return;
			}
			int levelIndex = GlassReflection.GetLevelIndex();
			if (!_hasPlacements || _levelIndex != levelIndex)
			{
				_lastGenerateFrame = Time.frameCount;
				ClearPatches();
				_hasPlacements = false;
				_pendingPlacementData = null;
				_placements.Clear();
				_levelIndex = levelIndex;
				_levelReady = true;
				if (GlassConfig.Enabled.Value && GlassReflection.IsRunLevel())
				{
					((MonoBehaviour)this).StartCoroutine(GenerateWhenReady());
				}
			}
		}

		private IEnumerator GenerateWhenReady()
		{
			if (GlassNetwork.IsHost)
			{
				float deadline = Time.time + 10f;
				while (Time.time < deadline && !NavMeshReady())
				{
					yield return (object)new WaitForSeconds(0.25f);
				}
				int seed = Random.Range(1, int.MaxValue);
				Random rng = new Random(seed);
				List<Placement> placements = GlassPlacer.Place(GlassPlacer.CollectCandidates(rng), rng);
				ApplyPlacements(placements, seed);
				GlassNetwork.BroadcastPlacements(_levelIndex, placements);
				yield break;
			}
			if (_pendingPlacementData != null)
			{
				float[] pendingPlacementData = _pendingPlacementData;
				_pendingPlacementData = null;
				ApplyPlacementData(pendingPlacementData);
				yield break;
			}
			for (int attempt = 0; attempt < 10; attempt++)
			{
				if (_hasPlacements)
				{
					break;
				}
				if (_pendingPlacementData != null)
				{
					float[] pendingPlacementData2 = _pendingPlacementData;
					_pendingPlacementData = null;
					ApplyPlacementData(pendingPlacementData2);
					break;
				}
				if (_hasPlacements)
				{
					break;
				}
				GlassNetwork.RequestPlacements(_levelIndex);
				yield return (object)new WaitForSeconds(1f);
			}
		}

		public void OnPlacementsReceived(int levelIndex, float[] data)
		{
			if (levelIndex == _levelIndex && !_hasPlacements)
			{
				if (!_levelReady)
				{
					_pendingPlacementData = data;
				}
				else
				{
					ApplyPlacementData(data);
				}
			}
		}

		public void OnPlacementsRequested(int levelIndex)
		{
			if (GlassNetwork.IsHost && _hasPlacements && levelIndex == _levelIndex)
			{
				GlassNetwork.BroadcastPlacements(_levelIndex, _placements);
			}
		}

		private void ApplyPlacementData(float[] data)
		{
			ApplyPlacements(ParsePlacements(data), 0);
		}

		private static List<Placement> ParsePlacements(float[] data)
		{
			//IL_005c: 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)
			List<Placement> list = new List<Placement>();
			if (data == null || data.Length % 9 != 0)
			{
				return list;
			}
			Vector3 position = default(Vector3);
			Vector3 normal = default(Vector3);
			for (int i = 0; i < data.Length; i += 9)
			{
				((Vector3)(ref position))..ctor(data[i], data[i + 1], data[i + 2]);
				((Vector3)(ref normal))..ctor(data[i + 3], data[i + 4], data[i + 5]);
				float radius = data[i + 6];
				int variant = Mathf.RoundToInt(data[i + 7]);
				float yaw = data[i + 8];
				list.Add(new Placement(position, normal, radius, variant, yaw));
			}
			return list;
		}

		private void ApplyPlacements(List<Placement> placements, int seed)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			_hasPlacements = true;
			_seed = seed;
			_placements.Clear();
			_placements.AddRange(placements);
			ClearPatches();
			_root = new GameObject("SharpGlassRoot");
			_root.transform.SetParent(((Component)this).transform, false);
			for (int i = 0; i < placements.Count; i++)
			{
				_patches.Add(GlassPatch.Create(_root.transform, placements[i], i));
			}
			ulong num = ComputeHash(placements);
			ManualLogSource? log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)$"REPOLAST: {_patches.Count} patches on level {_levelIndex}, seed {seed}, hash=0x{num:X16}.");
			}
		}

		private static bool NavMeshReady()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			List<Component> pathPoints = GlassReflection.GetPathPoints();
			if (pathPoints.Count == 0)
			{
				return true;
			}
			NavMeshHit val = default(NavMeshHit);
			foreach (Component item in pathPoints)
			{
				if (NavMesh.SamplePosition(item.transform.position, ref val, 2f, -1))
				{
					return true;
				}
			}
			return false;
		}

		private void Update()
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time >= _nextLevelCheck)
			{
				_nextLevelCheck = Time.time + 2f;
				if (GlassReflection.GetLevelIndex() != _levelIndex)
				{
					_levelReady = false;
					_hasPlacements = false;
				}
				if (!_levelReady && (Object)(object)GlassReflection.GetLocalPlayer() != (Object)null && GlassReflection.IsRunLevel())
				{
					OnLevelGenerated();
				}
			}
			if (!GlassConfig.Enabled.Value || _patches.Count == 0 || Time.time < _nextCheck)
			{
				return;
			}
			_nextCheck = Time.time + 0.1f;
			Component localPlayer = GlassReflection.GetLocalPlayer();
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			PlayerState playerState = GlassReflection.GetPlayerState(localPlayer);
			if (playerState.Speed < 0.4f)
			{
				_lastPatch = null;
				return;
			}
			if (playerState.IsCrouching && !playerState.IsSprinting && GlassConfig.CrouchSilent.Value)
			{
				_lastPatch = null;
				return;
			}
			GlassPatch glassPatch = FindPatch(localPlayer.transform.position);
			if ((Object)(object)glassPatch == (Object)null)
			{
				_lastPatch = null;
			}
			else if (!(Time.time - _lastStepTime < GlassConfig.NoiseCooldown.Value))
			{
				_lastPatch = glassPatch;
				TriggerStep(glassPatch, playerState);
			}
		}

		private GlassPatch? FindPatch(Vector3 playerPosition)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_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)
			GlassPatch result = null;
			float num = float.MaxValue;
			foreach (GlassPatch patch in _patches)
			{
				Vector3 val = ((Component)patch).transform.position - playerPosition;
				if (!(Mathf.Abs(val.y) > 1.5f))
				{
					Vector2 val2 = new Vector2(val.x, val.z);
					float magnitude = ((Vector2)(ref val2)).magnitude;
					if (!(magnitude > patch.Radius + 0.35f) && magnitude < num)
					{
						num = magnitude;
						result = patch;
					}
				}
			}
			return result;
		}

		private void TriggerStep(GlassPatch patch, PlayerState state)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			_lastStepTime = Time.time;
			int variant = Random.Range(0, Mathf.Max(1, GlassAudio.ClipCount));
			GlassAudio.Play(((Component)patch).transform.position, variant, GlassConfig.AudioVolume.Value);
			GlassNetwork.SendCrunch(patch.Index, variant);
			int action = (state.JustLanded ? 2 : (state.IsSprinting ? 1 : 0));
			if (GlassNetwork.IsHost)
			{
				GlassReflection.SetInvestigate(((Component)patch).transform.position, RadiusForAction(action));
			}
			else
			{
				GlassNetwork.SendNoise(((Component)patch).transform.position, action);
			}
		}

		private static float RadiusForAction(int action)
		{
			return action switch
			{
				2 => GlassConfig.LandingRadius.Value, 
				1 => GlassConfig.SprintRadius.Value, 
				_ => GlassConfig.WalkRadius.Value, 
			};
		}

		public void HandleNoise(Vector3 position, int action, int senderActor)
		{
			//IL_0050: 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)
			if (!GlassNetwork.IsHost)
			{
				return;
			}
			Component playerByActor = GlassReflection.GetPlayerByActor(senderActor);
			if ((Object)(object)playerByActor != (Object)null && Vector3.Distance(playerByActor.transform.position, position) > 4f)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogDebug((object)$"REPOLAST: rejected noise from actor {senderActor} (too far from reported position).");
				}
			}
			else
			{
				GlassReflection.SetInvestigate(position, Mathf.Clamp(RadiusForAction(action), 0f, 25f));
			}
		}

		public void HandleCrunch(int patchIndex, int variant)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (patchIndex >= 0 && patchIndex < _patches.Count)
			{
				GlassAudio.Play(((Component)_patches[patchIndex]).transform.position, variant, GlassConfig.AudioVolume.Value);
			}
		}

		private void ClearPatches()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
				_root = null;
			}
			_patches.Clear();
			_lastPatch = null;
			_lastStepTime = 0f;
		}

		private static ulong ComputeHash(List<Placement> placements)
		{
			//IL_001d: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			ulong num = 1469598103934665603uL;
			foreach (Placement placement in placements)
			{
				num = Mix(num, Mathf.RoundToInt(placement.Position.x * 100f));
				num = Mix(num, Mathf.RoundToInt(placement.Position.y * 100f));
				num = Mix(num, Mathf.RoundToInt(placement.Position.z * 100f));
			}
			return num;
		}

		private static ulong Mix(ulong hash, int value)
		{
			hash ^= (uint)value;
			hash *= 1099511628211L;
			return hash;
		}
	}
	internal static class GlassNetwork
	{
		private static NetworkedEvent? _placementsEvent;

		private static NetworkedEvent? _requestPlacementsEvent;

		private static NetworkedEvent? _noiseEvent;

		private static NetworkedEvent? _crunchEvent;

		public static bool IsHost
		{
			get
			{
				if (PhotonNetwork.InRoom)
				{
					return PhotonNetwork.IsMasterClient;
				}
				return true;
			}
		}

		public static void Init()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			_placementsEvent = new NetworkedEvent("SharpGlass Placements", (Action<EventData>)OnPlacements);
			_requestPlacementsEvent = new NetworkedEvent("SharpGlass RequestPlacements", (Action<EventData>)OnRequestPlacements);
			_noiseEvent = new NetworkedEvent("SharpGlass Noise", (Action<EventData>)OnNoise);
			_crunchEvent = new NetworkedEvent("SharpGlass Crunch", (Action<EventData>)OnCrunch);
		}

		public static void BroadcastPlacements(int levelIndex, List<Placement> placements)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			float[] array = new float[placements.Count * 9];
			for (int i = 0; i < placements.Count; i++)
			{
				Placement placement = placements[i];
				int num = i * 9;
				array[num] = placement.Position.x;
				array[num + 1] = placement.Position.y;
				array[num + 2] = placement.Position.z;
				array[num + 3] = placement.Normal.x;
				array[num + 4] = placement.Normal.y;
				array[num + 5] = placement.Normal.z;
				array[num + 6] = placement.Radius;
				array[num + 7] = placement.Variant;
				array[num + 8] = placement.Yaw;
			}
			NetworkedEvent? placementsEvent = _placementsEvent;
			if (placementsEvent != null)
			{
				Hashtable val = new Hashtable();
				((Dictionary<object, object>)val).Add((object)"level", (object)levelIndex);
				((Dictionary<object, object>)val).Add((object)"data", (object)array);
				placementsEvent.RaiseEvent((object)val, NetworkingEvents.RaiseAll, SendOptions.SendReliable);
			}
		}

		public static void RequestPlacements(int levelIndex)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			NetworkedEvent? requestPlacementsEvent = _requestPlacementsEvent;
			if (requestPlacementsEvent != null)
			{
				Hashtable val = new Hashtable();
				((Dictionary<object, object>)val).Add((object)"level", (object)levelIndex);
				requestPlacementsEvent.RaiseEvent((object)val, NetworkingEvents.RaiseMasterClient, SendOptions.SendReliable);
			}
		}

		public static void SendNoise(Vector3 position, int action)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			NetworkedEvent? noiseEvent = _noiseEvent;
			if (noiseEvent != null)
			{
				Hashtable val = new Hashtable();
				((Dictionary<object, object>)val).Add((object)"x", (object)position.x);
				((Dictionary<object, object>)val).Add((object)"y", (object)position.y);
				((Dictionary<object, object>)val).Add((object)"z", (object)position.z);
				((Dictionary<object, object>)val).Add((object)"action", (object)action);
				noiseEvent.RaiseEvent((object)val, NetworkingEvents.RaiseMasterClient, SendOptions.SendReliable);
			}
		}

		public static void SendCrunch(int patchIndex, int variant)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			NetworkedEvent? crunchEvent = _crunchEvent;
			if (crunchEvent != null)
			{
				Hashtable val = new Hashtable();
				((Dictionary<object, object>)val).Add((object)"index", (object)patchIndex);
				((Dictionary<object, object>)val).Add((object)"variant", (object)variant);
				crunchEvent.RaiseEvent((object)val, NetworkingEvents.RaiseOthers, SendOptions.SendUnreliable);
			}
		}

		private static void OnPlacements(EventData data)
		{
			object customData = data.CustomData;
			Hashtable val = (Hashtable)((customData is Hashtable) ? customData : null);
			if (val != null && val[(object)"data"] is float[] data2)
			{
				GlassManager.Instance?.OnPlacementsReceived(ToInt(val, "level"), data2);
			}
		}

		private static void OnRequestPlacements(EventData data)
		{
			object customData = data.CustomData;
			Hashtable val = (Hashtable)((customData is Hashtable) ? customData : null);
			if (val != null)
			{
				GlassManager.Instance?.OnPlacementsRequested(ToInt(val, "level"));
			}
		}

		private static void OnNoise(EventData data)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			object customData = data.CustomData;
			Hashtable val = (Hashtable)((customData is Hashtable) ? customData : null);
			if (val != null)
			{
				Vector3 position = default(Vector3);
				((Vector3)(ref position))..ctor(ToFloat(val, "x"), ToFloat(val, "y"), ToFloat(val, "z"));
				GlassManager.Instance?.HandleNoise(position, ToInt(val, "action"), data.Sender);
			}
		}

		private static void OnCrunch(EventData data)
		{
			object customData = data.CustomData;
			Hashtable val = (Hashtable)((customData is Hashtable) ? customData : null);
			if (val != null)
			{
				GlassManager.Instance?.HandleCrunch(ToInt(val, "index"), ToInt(val, "variant"));
			}
		}

		private static int ToInt(Hashtable table, string key)
		{
			if (table[(object)key] != null)
			{
				return Convert.ToInt32(table[(object)key]);
			}
			return 0;
		}

		private static float ToFloat(Hashtable table, string key)
		{
			if (table[(object)key] != null)
			{
				return Convert.ToSingle(table[(object)key]);
			}
			return 0f;
		}
	}
	public sealed class GlassPatch : MonoBehaviour
	{
		private static readonly Material?[] Materials = (Material?[])(object)new Material[3];

		public int Index;

		public int Variant;

		public float Radius;

		private Mesh? _mesh;

		internal static GlassPatch Create(Transform parent, Placement placement, int index)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0044: 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_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_007f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject($"GlassPatch_{index}");
			val.transform.SetParent(parent, false);
			val.transform.position = placement.Position;
			val.transform.rotation = Quaternion.FromToRotation(Vector3.up, placement.Normal) * Quaternion.Euler(0f, placement.Yaw, 0f);
			val.transform.localScale = new Vector3(placement.Radius, 1f, placement.Radius);
			GlassPatch glassPatch = val.AddComponent<GlassPatch>();
			glassPatch.Index = index;
			glassPatch.Variant = placement.Variant;
			glassPatch.Radius = placement.Radius;
			glassPatch.Build();
			return glassPatch;
		}

		private void Build()
		{
			//IL_0032: 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_00ac: 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_017d: 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_0198: 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_01a7: 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)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: 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_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Expected O, but got Unknown
			Random random = new Random(Index * 7919 + Variant * 104729);
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			List<Vector2> list3 = new List<Vector2>();
			list.Add(Vector3.zero);
			list3.Add(new Vector2(0.5f, 0.5f));
			for (int i = 0; i < 14; i++)
			{
				float num = (float)((double)i / 14.0 * 3.1415927410125732 * 2.0);
				float num2 = 0.74f + (float)random.NextDouble() * 0.26f;
				list.Add(new Vector3(Mathf.Cos(num) * num2, 0f, Mathf.Sin(num) * num2));
				list3.Add(new Vector2(0.5f + Mathf.Cos(num) * 0.5f, 0.5f + Mathf.Sin(num) * 0.5f));
			}
			for (int j = 0; j < 14; j++)
			{
				int c = 1 + j;
				int b = 1 + (j + 1) % 14;
				AddTriangle(list, list2, 0, b, c);
			}
			for (int k = 0; k < 9; k++)
			{
				float num3 = (float)random.NextDouble() * MathF.PI * 2f;
				float num4 = 0.16f + (float)random.NextDouble() * 0.56f;
				Vector3 val = new Vector3(Mathf.Cos(num3) * num4, 0.004f + (float)random.NextDouble() * 0.03f, Mathf.Sin(num3) * num4);
				float num5 = 0.035f + (float)random.NextDouble() * 0.075f;
				Vector3 item = val;
				Vector3 item2 = val + new Vector3(num5, 0.012f, 0f);
				Vector3 item3 = val + new Vector3(0f, 0.008f, num5);
				int count = list.Count;
				list.Add(item);
				list.Add(item2);
				list.Add(item3);
				list3.Add(new Vector2(0.5f, 0.5f));
				list3.Add(new Vector2(0.5f, 0.5f));
				list3.Add(new Vector2(0.5f, 0.5f));
				AddTriangle(list, list2, count, count + 1, count + 2);
			}
			_mesh = new Mesh
			{
				name = $"SharpGlass_{Index}"
			};
			_mesh.SetVertices(list);
			_mesh.SetTriangles(list2, 0);
			_mesh.SetUVs(0, list3);
			_mesh.RecalculateNormals();
			_mesh.RecalculateBounds();
			((Component)this).gameObject.AddComponent<MeshFilter>().sharedMesh = _mesh;
			MeshRenderer obj = ((Component)this).gameObject.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = GetMaterial(Variant);
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = true;
		}

		private static void AddTriangle(List<Vector3> vertices, List<int> triangles, int a, int b, int c)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_0022: 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)
			if (Vector3.Cross(vertices[b] - vertices[a], vertices[c] - vertices[a]).y < 0f)
			{
				int num = c;
				c = b;
				b = num;
			}
			triangles.Add(a);
			triangles.Add(b);
			triangles.Add(c);
		}

		private static Material GetMaterial(int variant)
		{
			//IL_0084: 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_00a0: Expected O, but got Unknown
			//IL_00bf: 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_00fe: 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_00e0: 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)
			variant = Mathf.Abs(variant) % Materials.Length;
			if ((Object)(object)Materials[variant] != (Object)null)
			{
				return Materials[variant];
			}
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Legacy Shaders/Diffuse");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Unlit/Color");
			}
			if ((Object)(object)val == (Object)null)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)"REPOLAST: no usable shader found; glass will use the error shader.");
				}
				val = Shader.Find("Hidden/InternalErrorShader");
			}
			Material val2 = new Material(val)
			{
				name = $"SharpGlass_{variant}"
			};
			Material val3 = val2;
			val3.color = (Color)(variant switch
			{
				0 => new Color(0.62f, 0.78f, 0.74f, 1f), 
				1 => new Color(0.48f, 0.62f, 0.55f, 1f), 
				_ => new Color(0.72f, 0.78f, 0.82f, 1f), 
			});
			if (val2.HasProperty("_Metallic"))
			{
				val2.SetFloat("_Metallic", 0.15f);
			}
			if (val2.HasProperty("_Glossiness"))
			{
				val2.SetFloat("_Glossiness", 0.85f);
			}
			Materials[variant] = val2;
			return val2;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_mesh != (Object)null)
			{
				Object.Destroy((Object)(object)_mesh);
			}
		}

		private void OnDrawGizmos()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (GlassConfig.DrawGizmos != null && GlassConfig.DrawGizmos.Value)
			{
				Gizmos.color = new Color(0.6f, 0.9f, 1f, 0.45f);
				Gizmos.DrawWireSphere(((Component)this).transform.position, Radius);
			}
		}
	}
	internal readonly struct Candidate
	{
		public readonly Vector3 Position;

		public readonly Vector3 Right;

		public readonly bool Doorway;

		public Candidate(Vector3 position, Vector3 right, bool doorway)
		{
			//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_001f: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			Position = position;
			Right = ((((Vector3)(ref right)).sqrMagnitude > 0.001f) ? ((Vector3)(ref right)).normalized : Vector3.right);
			Doorway = doorway;
		}
	}
	internal readonly struct Placement
	{
		public readonly Vector3 Position;

		public readonly Vector3 Normal;

		public readonly float Radius;

		public readonly int Variant;

		public readonly float Yaw;

		public Placement(Vector3 position, Vector3 normal, float radius, int variant, float yaw)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			Position = position;
			Normal = normal;
			Radius = radius;
			Variant = variant;
			Yaw = yaw;
		}
	}
	internal static class GlassPlacer
	{
		public static List<Candidate> CollectCandidates(Random rng)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00e9: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: 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)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			List<Candidate> list = new List<Candidate>();
			List<Component> pathPoints = GlassReflection.GetPathPoints();
			pathPoints.Sort(CompareComponent);
			List<Vector3> extractionPositions = GlassReflection.GetExtractionPositions();
			foreach (Component item in pathPoints)
			{
				Vector3 position = item.transform.position;
				bool flag = false;
				foreach (Vector3 item2 in extractionPositions)
				{
					if (Vector3.Distance(item2, position) < 3f)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					Vector3 right = item.transform.right;
					list.Add(new Candidate(position + right * NextFloat(rng, 0.7f, 1.8f), right, doorway: false));
					list.Add(new Candidate(position - right * NextFloat(rng, 0.7f, 1.8f), right, doorway: false));
				}
			}
			for (int i = 0; i < pathPoints.Count; i++)
			{
				for (int j = i + 1; j < pathPoints.Count; j++)
				{
					Vector3 position2 = pathPoints[i].transform.position;
					Vector3 position3 = pathPoints[j].transform.position;
					if (!(Vector3.Distance(position2, position3) > 4f))
					{
						Vector3 position4 = (position2 + position3) * 0.5f;
						list.Add(new Candidate(position4, pathPoints[i].transform.right, doorway: true));
					}
				}
			}
			List<Component> list2 = GlassReflection.FindComponents("RoomVolume");
			list2.Sort(CompareComponent);
			foreach (Component item3 in list2)
			{
				Bounds roomBounds = GetRoomBounds(item3);
				for (int k = 0; k < 6; k++)
				{
					float num = NextFloat(rng, ((Bounds)(ref roomBounds)).min.x, ((Bounds)(ref roomBounds)).max.x);
					float num2 = NextFloat(rng, ((Bounds)(ref roomBounds)).min.z, ((Bounds)(ref roomBounds)).max.z);
					float num3 = ((Bounds)(ref roomBounds)).min.y + 0.2f;
					list.Add(new Candidate(new Vector3(num, num3, num2), item3.transform.right, doorway: false));
				}
			}
			return Deduplicate(list);
		}

		private static Bounds GetRoomBounds(Component room)
		{
			//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_0012: 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_002b: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			Collider[] componentsInChildren = room.GetComponentsInChildren<Collider>(true);
			if (componentsInChildren.Length == 0)
			{
				return new Bounds(room.transform.position, new Vector3(8f, 3f, 8f));
			}
			Bounds bounds = componentsInChildren[0].bounds;
			for (int i = 1; i < componentsInChildren.Length; i++)
			{
				((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds);
			}
			return bounds;
		}

		private static List<Candidate> Deduplicate(List<Candidate> candidates)
		{
			//IL_002c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			List<Candidate> list = new List<Candidate>(candidates.Count);
			HashSet<string> hashSet = new HashSet<string>();
			foreach (Candidate candidate in candidates)
			{
				string item = $"{Mathf.RoundToInt(candidate.Position.x * 100f)}," + $"{Mathf.RoundToInt(candidate.Position.y * 100f)}," + $"{Mathf.RoundToInt(candidate.Position.z * 100f)}";
				if (hashSet.Add(item))
				{
					list.Add(candidate);
				}
			}
			return list;
		}

		public static List<Placement> Place(List<Candidate> candidates, Random rng)
		{
			candidates.Sort((Candidate a, Candidate b) => CompareQuantized(a.Position, b.Position));
			Shuffle(candidates, rng);
			int count = GlassReflection.FindComponents("RoomVolume").Count;
			int num = Mathf.Clamp(GlassConfig.PatchesPerLevel.Value + Mathf.RoundToInt((float)count * 0.5f), 6, GlassConfig.MaxPatches.Value);
			List<Vector3> extractionPositions = GlassReflection.GetExtractionPositions();
			Vector3? truckPosition = GlassReflection.GetTruckPosition();
			List<Placement> list = new List<Placement>();
			foreach (Candidate candidate in candidates)
			{
				if (list.Count >= num)
				{
					break;
				}
				if (TryValidate(candidate, list, extractionPositions, truckPosition, rng, relaxed: false, out var placement))
				{
					list.Add(placement);
				}
			}
			if (list.Count < Mathf.Min(6, num))
			{
				foreach (Candidate candidate2 in candidates)
				{
					if (list.Count >= num)
					{
						break;
					}
					if (TryValidate(candidate2, list, extractionPositions, truckPosition, rng, relaxed: true, out var placement2))
					{
						list.Add(placement2);
					}
				}
			}
			return list;
		}

		private static bool TryValidate(Candidate candidate, List<Placement> placed, List<Vector3> extractions, Vector3? truck, Random rng, bool relaxed, out Placement placement)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_003f: 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_007c: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: 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_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			placement = default(Placement);
			if (!TryGetFloorHit(candidate.Position + Vector3.up * 1.5f, out var hit))
			{
				return false;
			}
			if (HasBlockingComponent(((RaycastHit)(ref hit)).collider))
			{
				return false;
			}
			if (((RaycastHit)(ref hit)).normal.y < Mathf.Cos(GlassConfig.MaxFloorSlope.Value * (MathF.PI / 180f)))
			{
				return false;
			}
			NavMeshHit val = default(NavMeshHit);
			if (!NavMesh.SamplePosition(((RaycastHit)(ref hit)).point, ref val, 1f, -1))
			{
				return false;
			}
			if (Mathf.Abs(((NavMeshHit)(ref val)).position.y - ((RaycastHit)(ref hit)).point.y) > 0.3f)
			{
				return false;
			}
			Collider[] array = Physics.OverlapBox(((RaycastHit)(ref hit)).point + Vector3.up * 0.1f, new Vector3(0.8f, 0.2f, 0.8f), Quaternion.identity, -1, (QueryTriggerInteraction)1);
			Type type = GlassReflection.FindType("PlayerAvatar");
			Collider[] array2 = array;
			foreach (Collider val2 in array2)
			{
				if (!((Object)(object)val2 == (Object)(object)((RaycastHit)(ref hit)).collider) && (!(type != null) || !((Object)(object)((Component)val2).GetComponentInParent(type) != (Object)null)))
				{
					string name = ((object)val2).GetType().Name;
					if (!name.Contains("Player") && !name.Contains("Glass") && HasBlockingComponent(val2))
					{
						return false;
					}
				}
			}
			foreach (Vector3 extraction in extractions)
			{
				if (Vector3.Distance(extraction, ((RaycastHit)(ref hit)).point) < GlassConfig.ExtractionClearance.Value)
				{
					return false;
				}
			}
			if (truck.HasValue && Vector3.Distance(truck.Value, ((RaycastHit)(ref hit)).point) < GlassConfig.TruckClearance.Value)
			{
				return false;
			}
			float num = (relaxed ? Mathf.Min(1.4f, GlassConfig.MinPatchSpacing.Value) : GlassConfig.MinPatchSpacing.Value);
			foreach (Placement item in placed)
			{
				if (Vector3.Distance(item.Position, ((RaycastHit)(ref hit)).point) < num)
				{
					return false;
				}
			}
			if (!HasSafeSide(((RaycastHit)(ref hit)).point, candidate.Right))
			{
				return false;
			}
			placement = new Placement(((RaycastHit)(ref hit)).point + Vector3.up * 0.005f, ((RaycastHit)(ref hit)).normal, NextFloat(rng, 0.75f, 1.25f), rng.Next(0, 3), NextFloat(rng, 0f, 360f));
			return true;
		}

		private static bool HasBlockingComponent(Collider collider)
		{
			string[] array = new string[6] { "PhysGrabObject", "ValuableObject", "Door", "Item", "Cart", "Mine" };
			for (int i = 0; i < array.Length; i++)
			{
				Type type = GlassReflection.FindType(array[i]);
				if (type != null && (Object)(object)((Component)collider).GetComponentInParent(type) != (Object)null)
				{
					return true;
				}
			}
			return false;
		}

		private static bool TryGetFloorHit(Vector3 origin, out RaycastHit hit)
		{
			//IL_0001: 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_0008: 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_005d: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			hit = default(RaycastHit);
			RaycastHit[] array = Physics.RaycastAll(origin, Vector3.down, 3f, -1, (QueryTriggerInteraction)1);
			if (array.Length == 0)
			{
				return false;
			}
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			Type type = GlassReflection.FindType("PlayerAvatar");
			RaycastHit[] array2 = array;
			for (int num = 0; num < array2.Length; num++)
			{
				RaycastHit val = array2[num];
				if (!((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) && !((RaycastHit)(ref val)).collider.isTrigger && (!(type != null) || !((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent(type) != (Object)null)))
				{
					hit = val;
					return true;
				}
			}
			return false;
		}

		private static bool HasSafeSide(Vector3 center, Vector3 right)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0011: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			bool num = Physics.Raycast(center - right * 0.9f + Vector3.up * 0.8f, Vector3.down, ref val, 1.6f, -1, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val)).normal.y > 0.5f;
			RaycastHit val2 = default(RaycastHit);
			bool flag = Physics.Raycast(center + right * 0.9f + Vector3.up * 0.8f, Vector3.down, ref val2, 1.6f, -1, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val2)).normal.y > 0.5f;
			return num || flag;
		}

		private static void Shuffle<T>(IList<T> list, Random rng)
		{
			for (int num = list.Count - 1; num > 0; num--)
			{
				int num2 = rng.Next(num + 1);
				int index = num;
				int index2 = num2;
				T value = list[num2];
				T value2 = list[num];
				list[index] = value;
				list[index2] = value2;
			}
		}

		private static int CompareComponent(Component a, Component b)
		{
			//IL_0006: 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_0027: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			int num = CompareQuantized(a.transform.position, b.transform.position);
			if (num != 0)
			{
				return num;
			}
			num = CompareQuantized(a.transform.right, b.transform.right);
			if (num != 0)
			{
				return num;
			}
			return CompareQuantized(a.transform.forward, b.transform.forward);
		}

		private static int CompareQuantized(Vector3 a, Vector3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.RoundToInt(a.x * 100f);
			int num2 = Mathf.RoundToInt(b.x * 100f);
			if (num != num2)
			{
				return num.CompareTo(num2);
			}
			int num3 = Mathf.RoundToInt(a.y * 100f);
			int num4 = Mathf.RoundToInt(b.y * 100f);
			if (num3 != num4)
			{
				return num3.CompareTo(num4);
			}
			return Mathf.RoundToInt(a.z * 100f).CompareTo(Mathf.RoundToInt(b.z * 100f));
		}

		private static float NextFloat(Random rng, float minimum, float maximum)
		{
			return minimum + (float)rng.NextDouble() * (maximum - minimum);
		}
	}
	internal readonly struct PlayerState
	{
		public readonly float Speed;

		public readonly bool IsCrouching;

		public readonly bool IsSprinting;

		public readonly bool JustLanded;

		public PlayerState(float speed, bool isCrouching, bool isSprinting, bool justLanded)
		{
			Speed = speed;
			IsCrouching = isCrouching;
			IsSprinting = isSprinting;
			JustLanded = justLanded;
		}
	}
	internal static class GlassReflection
	{
		private static readonly Dictionary<string, Type?> TypeCache = new Dictionary<string, Type>();

		private static readonly HashSet<string> Warned = new HashSet<string>();

		private static Vector3 _lastPlayerPosition;

		private static bool _wasGrounded = true;

		public static Type? FindType(string name)
		{
			if (TypeCache.TryGetValue(name, out Type value))
			{
				return value;
			}
			Type type = AccessTools.TypeByName(name);
			TypeCache[name] = type;
			return type;
		}

		public static object? Static(string typeName, params string[] memberNames)
		{
			Type type = FindType(typeName);
			if (type == null)
			{
				return null;
			}
			foreach (string name in memberNames)
			{
				try
				{
					PropertyInfo property = type.GetProperty(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null)
					{
						return property.GetValue(null);
					}
					FieldInfo field = type.GetField(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null)
					{
						return field.GetValue(null);
					}
				}
				catch
				{
				}
			}
			return null;
		}

		public static object? Member(object? instance, params string[] memberNames)
		{
			if (instance == null)
			{
				return null;
			}
			Type type = instance.GetType();
			foreach (string name in memberNames)
			{
				try
				{
					PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null)
					{
						return property.GetValue(instance);
					}
					FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null)
					{
						return field.GetValue(instance);
					}
				}
				catch
				{
				}
			}
			return null;
		}

		public static bool HasMember(object? instance, params string[] memberNames)
		{
			if (instance == null)
			{
				return false;
			}
			Type type = instance.GetType();
			foreach (string name in memberNames)
			{
				if (type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) != null)
				{
					return true;
				}
				if (type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) != null)
				{
					return true;
				}
			}
			return false;
		}

		public static bool GetBool(object? instance, params string[] memberNames)
		{
			object obj = Member(instance, memberNames);
			if (!(obj is bool result))
			{
				if (!(obj is int num))
				{
					if (obj is float num2)
					{
						return num2 > 0.5f;
					}
					return false;
				}
				return num != 0;
			}
			return result;
		}

		public static float GetFloat(object? instance, params string[] memberNames)
		{
			object obj = Member(instance, memberNames);
			if (!(obj is float result))
			{
				if (!(obj is double num))
				{
					if (obj is int num2)
					{
						return num2;
					}
					return 0f;
				}
				return (float)num;
			}
			return result;
		}

		public static Component? GetComponentByName(Component owner, string typeName)
		{
			Type type = FindType(typeName);
			if (type == null)
			{
				return null;
			}
			Component component = owner.GetComponent(type);
			if ((Object)(object)component != (Object)null)
			{
				return component;
			}
			component = owner.GetComponentInChildren(type, true);
			if (!((Object)(object)component != (Object)null))
			{
				return owner.GetComponentInParent(type, true);
			}
			return component;
		}

		public static IEnumerable<object> Enumerate(object? value)
		{
			if (value == null || !(value is IEnumerable enumerable))
			{
				yield break;
			}
			foreach (object item in enumerable)
			{
				if (item != null)
				{
					yield return item;
				}
			}
		}

		public static List<Component> FindComponents(string typeName)
		{
			List<Component> list = new List<Component>();
			Type type = FindType(typeName);
			if (type == null)
			{
				return list;
			}
			Object[] array = Object.FindObjectsByType(type, (FindObjectsSortMode)0);
			foreach (Object obj in array)
			{
				Component val = (Component)(object)((obj is Component) ? obj : null);
				if (val != null)
				{
					list.Add(val);
				}
			}
			return list;
		}

		public static List<Component> GetPathPoints()
		{
			List<Component> list = new List<Component>();
			foreach (object item in Enumerate(Member(Static("LevelGenerator", "Instance"), "LevelPathPoints")))
			{
				Component val = (Component)((item is Component) ? item : null);
				if (val != null)
				{
					list.Add(val);
				}
			}
			return list;
		}

		public static List<Vector3> GetExtractionPositions()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			foreach (Component item in FindComponents("ExtractionPoint"))
			{
				list.Add(item.transform.position);
			}
			return list;
		}

		public static Vector3? GetTruckPosition()
		{
			//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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			object obj = Member(Static("LevelGenerator", "Instance"), "LevelPathTruck");
			if (obj == null)
			{
				return null;
			}
			Vector3 position = GetPosition(obj);
			if (!(position == Vector3.zero))
			{
				return position;
			}
			return null;
		}

		public static Vector3 GetPosition(object? value)
		{
			//IL_0010: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			Component val = (Component)((value is Component) ? value : null);
			if (val != null)
			{
				return val.transform.position;
			}
			GameObject val2 = (GameObject)((value is GameObject) ? value : null);
			if (val2 != null)
			{
				return val2.transform.position;
			}
			return Vector3.zero;
		}

		public static string GetLevelName()
		{
			return (Member(Member(Static("LevelGenerator", "Instance"), "Level"), "name", "NarrativeName", "ResourcePath") as string) ?? string.Empty;
		}

		public static bool IsRunLevel()
		{
			if (Member(Static("LevelGenerator", "Instance"), "Level") == null)
			{
				return false;
			}
			string text = GetLevelName().ToLowerInvariant();
			if (text.Contains("lobby") || text.Contains("shop") || text.Contains("main menu") || text.Contains("tutorial") || text.Contains("splash") || text.Contains("recording") || text.Contains("menu"))
			{
				return false;
			}
			if (GetPathPoints().Count <= 0)
			{
				return FindComponents("RoomVolume").Count > 0;
			}
			return true;
		}

		public static int GetLevelIndex()
		{
			object obj = Member(Static("RunManager", "instance", "Instance"), "levelsCompleted");
			if (obj is int)
			{
				return (int)obj;
			}
			return 0;
		}

		public static Component? GetLocalPlayer()
		{
			object? obj = Static("PlayerAvatar", "instance", "Instance");
			Component val = (Component)((obj is Component) ? obj : null);
			if (val != null)
			{
				return val;
			}
			Type type = FindType("PlayerAvatar");
			if (type == null)
			{
				return null;
			}
			Object[] array = Object.FindObjectsByType(type, (FindObjectsSortMode)0);
			foreach (Object obj2 in array)
			{
				Component val2 = (Component)(object)((obj2 is Component) ? obj2 : null);
				if (val2 != null && GetBool(val2, "isLocal", "IsLocal"))
				{
					return val2;
				}
			}
			array = Object.FindObjectsByType(type, (FindObjectsSortMode)0);
			foreach (Object obj3 in array)
			{
				Component val3 = (Component)(object)((obj3 is Component) ? obj3 : null);
				if (val3 != null)
				{
					return val3;
				}
			}
			return null;
		}

		public static Component? GetPlayerByActor(int actorNumber)
		{
			Type type = FindType("PlayerAvatar");
			if (type == null)
			{
				return null;
			}
			Object[] array = Object.FindObjectsByType(type, (FindObjectsSortMode)0);
			foreach (Object obj in array)
			{
				Component val = (Component)(object)((obj is Component) ? obj : null);
				if (val != null && Member(Member(Member(val, "photonView", "PhotonView"), "Owner", "owner"), "ActorNumber", "actorNumber") is int num && num == actorNumber)
				{
					return val;
				}
			}
			return null;
		}

		public static PlayerState GetPlayerState(Component player)
		{
			//IL_0157: 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_015e: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: 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_01cf: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			Component val = GetComponentByName(player, "PlayerController");
			if ((Object)(object)val == (Object)null)
			{
				val = player;
			}
			bool flag = HasMember(val, "Crouching", "crouching", "IsCrouching", "isCrouching", "Crouch", "crouch");
			bool flag2 = HasMember(val, "Sprinting", "sprinting", "IsSprinting", "isSprinting", "Sprint", "sprint");
			bool isCrouching = (flag ? GetBool(val, "Crouching", "crouching", "IsCrouching", "isCrouching", "Crouch", "crouch") : (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)99)));
			bool isSprinting = (flag2 ? GetBool(val, "Sprinting", "sprinting", "IsSprinting", "isSprinting", "Sprint", "sprint") : Input.GetKey((KeyCode)304));
			CharacterController val2 = player.GetComponent<CharacterController>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = player.GetComponentInChildren<CharacterController>(true);
			}
			Vector3 position = player.transform.position;
			Vector3 val3 = (position - _lastPlayerPosition) / Mathf.Max(Time.deltaTime, 0.0001f);
			Vector3 val5;
			if (!(Member(val, "Velocity", "velocity") is Vector3 val4) || !(((Vector3)(ref val4)).sqrMagnitude > 0.01f))
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Vector3 velocity = val2.velocity;
					if (((Vector3)(ref velocity)).sqrMagnitude > 0.01f)
					{
						val5 = val2.velocity;
						goto IL_01ee;
					}
				}
				val5 = val3;
			}
			else
			{
				val5 = val4;
			}
			goto IL_01ee;
			IL_01ee:
			Vector3 val6 = val5;
			Component componentByName = GetComponentByName(player, "PlayerCollisionGrounded");
			bool flag3 = (((Object)(object)componentByName != (Object)null) ? GetBool(componentByName, "Grounded") : ((Object)(object)val2 == (Object)null || val2.isGrounded));
			bool justLanded = !_wasGrounded && flag3;
			_wasGrounded = flag3;
			_lastPlayerPosition = position;
			Vector2 val7 = new Vector2(val6.x, val6.z);
			return new PlayerState(((Vector2)(ref val7)).magnitude, isCrouching, isSprinting, justLanded);
		}

		public static void SetInvestigate(Vector3 position, float radius)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			object obj = Static("EnemyDirector", "instance", "Instance");
			if (obj == null)
			{
				WarnOnce("REPOLAST: EnemyDirector instance not found; noise events are disabled.");
				return;
			}
			MethodInfo method = obj.GetType().GetMethod("SetInvestigate", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[3]
			{
				typeof(Vector3),
				typeof(float),
				typeof(bool)
			}, null);
			if (method == null)
			{
				WarnOnce("REPOLAST: EnemyDirector.SetInvestigate(Vector3, float, bool) not found; noise events are disabled.");
				return;
			}
			try
			{
				method.Invoke(method.IsStatic ? null : obj, new object[3] { position, radius, false });
			}
			catch (Exception ex)
			{
				WarnOnce("REPOLAST: SetInvestigate failed: " + ex.Message);
			}
		}

		private static void WarnOnce(string message)
		{
			if (Warned.Add(message))
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)message);
				}
			}
		}
	}
	internal static class GlassWav
	{
		public static AudioClip? Load(Stream stream, string name)
		{
			using BinaryReader binaryReader = new BinaryReader(stream);
			if (ReadTag(binaryReader) != "RIFF")
			{
				return null;
			}
			binaryReader.ReadInt32();
			if (ReadTag(binaryReader) != "WAVE")
			{
				return null;
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			byte[] array = null;
			while (binaryReader.BaseStream.Position + 8 <= binaryReader.BaseStream.Length)
			{
				string text = ReadTag(binaryReader);
				int num4 = binaryReader.ReadInt32();
				long val = binaryReader.BaseStream.Position + num4 + num4 % 2;
				if (text == "fmt ")
				{
					short num5 = binaryReader.ReadInt16();
					num = binaryReader.ReadInt16();
					num2 = binaryReader.ReadInt32();
					binaryReader.ReadInt32();
					binaryReader.ReadInt16();
					num3 = binaryReader.ReadInt16();
					if (num5 != 1 || num3 != 16 || num < 1)
					{
						return null;
					}
				}
				else if (text == "data")
				{
					array = binaryReader.ReadBytes(num4);
				}
				binaryReader.BaseStream.Position = Math.Min(val, binaryReader.BaseStream.Length);
			}
			if (array == null || num < 1 || num2 < 1)
			{
				return null;
			}
			int num6 = array.Length / (2 * num);
			float[] array2 = new float[num6];
			for (int i = 0; i < num6; i++)
			{
				float num7 = 0f;
				for (int j = 0; j < num; j++)
				{
					int startIndex = (i * num + j) * 2;
					short num8 = BitConverter.ToInt16(array, startIndex);
					num7 += (float)num8 / 32768f;
				}
				array2[i] = num7 / (float)num;
			}
			AudioClip obj = AudioClip.Create(name, num6, 1, num2, false);
			obj.SetData(array2, 0);
			return obj;
		}

		private static string ReadTag(BinaryReader reader)
		{
			return new string(reader.ReadChars(4));
		}
	}
	internal static class LevelHooks
	{
		public static void LevelReadyPostfix()
		{
			GlassManager.Instance?.OnLevelGenerated();
		}
	}
	[BepInPlugin("camerin.REPOLAST", "REPOLAST", "0.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "camerin.REPOLAST";

		public const string PluginName = "REPOLAST";

		public const string PluginVersion = "0.1.2";

		private Harmony? _harmony;

		internal static Plugin? Instance { get; private set; }

		internal static ManualLogSource? Log { get; private set; }

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			GlassConfig.Init(((BaseUnityPlugin)this).Config);
			GlassNetwork.Init();
			GlassAudio.Init();
			GlassManager.Create();
			_harmony = new Harmony("camerin.REPOLAST");
			MethodInfo methodInfo = AccessTools.Method("LevelGenerator:GenerateDoneApply", (Type[])null, (Type[])null) ?? AccessTools.Method("LevelGenerator:GenerateDone", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				Log.LogError((object)"REPOLAST: LevelGenerator.GenerateDoneApply/GenerateDone not found; glass placement is disabled.");
			}
			else
			{
				HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(LevelHooks), "LevelReadyPostfix", (Type[])null, (Type[])null));
				_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)("REPOLAST: patched LevelGenerator." + methodInfo.Name + "."));
			}
			Log.LogInfo((object)"SharpGlass v0.1.2 loaded.");
		}

		private void OnDestroy()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}