Decompiled source of Motion Level 94 v1.0.1

GreenHills.dll

Decompiled a day 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 System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLevelLoader;
using LethalLevelLoader.Tools;
using Microsoft.CodeAnalysis;
using Unity.AI.Navigation;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GreenHills")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GreenHills")]
[assembly: AssemblyTitle("GreenHills")]
[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 GreenHills
{
	public class GreenHillsAmbiance : MonoBehaviour
	{
		[Header("Lumières")]
		public Light soleil;

		public Light remplissage;

		public Transform lampadaires;

		[Header("Ciel")]
		public Renderer dome;

		public Material cielJour;

		public Material cielNuit;

		public Transform nuages;

		public Transform sortiesSecours;

		[Header("Dôme (repère local de l'objet 'centreDome')")]
		public Transform centreDome;

		public float rayonDome = 650f;

		public float hauteurMur = 260f;

		public float hauteurCalotte = 120f;

		public float margeDouce = 25f;

		public float forceDouce = 60f;

		public static GreenHillsAmbiance Instance;

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

		private Volume volume;

		private bool dedansPrecedent;

		private bool nuitPrecedente;

		private float nuitT = -1f;

		private Material jourInst;

		private Material nuitInst;

		private Material nuagesInst;

		private Renderer[] rendusNuages = (Renderer[])(object)new Renderer[0];

		private readonly List<(Transform t, Renderer[] r, Light[] l)> sorties = new List<(Transform, Renderer[], Light[])>();

		private float prochaineRecherche;

		private float prochainDetecteur;

		private EnemyVent[] aerations = (EnemyVent[])(object)new EnemyVent[0];

		private Light[] lumieresLampadaires = (Light[])(object)new Light[0];

		private float[] intensitesLampadaires = new float[0];

		private const int SortiesMini = 5;

		internal readonly Dictionary<Transform, EntranceTeleport> poignees = new Dictionary<Transform, EntranceTeleport>();

		private const float DureeEtoiles = 9f;

		private const float DureeLever = 12f;

		private float sombreActuel;

		private readonly Dictionary<EntranceTeleport, float> dernierPassage = new Dictionary<EntranceTeleport, float>();

		private int deplacements;

		public bool JoueurDedans => dedansPrecedent;

		public bool EstNuit
		{
			get
			{
				if (dedansPrecedent)
				{
					return nuitPrecedente;
				}
				return false;
			}
		}

		public bool PleinJour => nuitT <= 0.001f;

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			Instance = this;
			if ((Object)(object)lampadaires != (Object)null)
			{
				lumieresLampadaires = ((Component)lampadaires).GetComponentsInChildren<Light>(true);
				intensitesLampadaires = lumieresLampadaires.Select((Light l) => l.intensity).ToArray();
			}
			if ((Object)(object)cielJour != (Object)null)
			{
				jourInst = new Material(cielJour);
			}
			if ((Object)(object)cielNuit != (Object)null)
			{
				nuitInst = new Material(cielNuit);
			}
			if ((Object)(object)nuages != (Object)null)
			{
				rendusNuages = ((Component)nuages).GetComponentsInChildren<Renderer>(true);
				if (rendusNuages.Length != 0 && (Object)(object)rendusNuages[0].sharedMaterial != (Object)null)
				{
					nuagesInst = new Material(rendusNuages[0].sharedMaterial);
					Renderer[] array = rendusNuages;
					for (int num = 0; num < array.Length; num++)
					{
						array[num].sharedMaterial = nuagesInst;
					}
				}
			}
			if ((Object)(object)sortiesSecours != (Object)null)
			{
				foreach (Transform sortiesSecour in sortiesSecours)
				{
					Transform val = sortiesSecour;
					Transform val2 = val.Find("Visuel");
					if ((Object)(object)val2 != (Object)null)
					{
						sorties.Add((val, ((Component)val2).GetComponentsInChildren<Renderer>(true), ((Component)val2).GetComponentsInChildren<Light>(true)));
					}
				}
			}
			AppliquerDedans(actif: false);
			AppliquerFondu(0f);
		}

		private IEnumerator Start()
		{
			float debut = Time.time;
			while ((Object)(object)RoundManager.Instance != (Object)null && !RoundManager.Instance.dungeonCompletedGenerating && Time.time - debut < 120f)
			{
				yield return null;
			}
			yield return (object)new WaitForSeconds(1f);
			if ((Object)(object)sortiesSecours == (Object)null)
			{
				yield break;
			}
			List<string> list = new List<string>();
			foreach (Transform sortiesSecour in sortiesSecours)
			{
				Transform val = sortiesSecour;
				if (((Component)val).gameObject.activeInHierarchy)
				{
					list.Add($"{((Object)val).name} ({val.position.x:0}, {val.position.y:0}, {val.position.z:0})");
				}
			}
			GreenHillsPlugin.Log.LogInfo((object)($"[Sorties] {list.Count} présente(s) : " + string.Join(" ; ", list)));
			yield return AjouterSorties();
		}

		private IEnumerator AjouterSorties()
		{
			List<Transform> actives = (from x in sorties
				where (Object)(object)x.t != (Object)null && ((Component)x.t).gameObject.activeSelf
				select x.t).ToList();
			if (actives.Count >= 5)
			{
				yield break;
			}
			List<EntranceTeleport> vraies = null;
			List<EntranceTeleport> toutes = null;
			float debut = Time.time;
			while (Time.time - debut < 20f)
			{
				toutes = (from e in Object.FindObjectsOfType<EntranceTeleport>()
					where !e.isEntranceToBuilding && EstDansLeDome(((Component)e).transform.position)
					orderby ((Component)e).transform.position.x, ((Component)e).transform.position.z
					select e).ToList();
				vraies = toutes.Where((EntranceTeleport e) => e.entranceId != 0).ToList();
				if (vraies.Count >= actives.Count && vraies.Count > 0)
				{
					break;
				}
				yield return (object)new WaitForSeconds(1f);
			}
			if (vraies == null || vraies.Count == 0)
			{
				vraies = toutes?.Where((EntranceTeleport e) => e.entranceId == 0).ToList();
			}
			if (vraies == null || vraies.Count == 0)
			{
				GreenHillsPlugin.Log.LogInfo((object)"[Sorties] aucune porte de la lune trouvée : rien à ajouter.");
				yield break;
			}
			List<Transform> list = (from x in sorties
				select x.t into t
				where (Object)(object)t != (Object)null && !((Component)t).gameObject.activeSelf
				select t).OrderBy<Transform, string>((Transform t) => ((Object)t).name, StringComparer.Ordinal).ToList();
			Random random = new Random((((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.randomMapSeed : 0) + 4243);
			List<string> list2 = new List<string>();
			for (int num = actives.Count; num < 5; num++)
			{
				if (list.Count <= 0)
				{
					break;
				}
				Transform val = list[random.Next(list.Count)];
				list.Remove(val);
				EntranceTeleport val2 = vraies[random.Next(vraies.Count)];
				((Component)val).gameObject.SetActive(true);
				if (!CreerPoignee(val, val2))
				{
					((Component)val).gameObject.SetActive(false);
				}
				else
				{
					list2.Add($"{((Object)val).name} -> sortie n°{val2.entranceId}");
				}
			}
			if (list2.Count > 0)
			{
				GreenHillsPlugin.Log.LogInfo((object)($"[Sorties] {list2.Count} ajoutée(s) pour en avoir {5} : " + string.Join(" ; ", list2)));
			}
		}

		internal bool EstDansLeDome(Vector3 p)
		{
			//IL_0016: 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_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_0023: 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_002e: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)centreDome == (Object)null)
			{
				return false;
			}
			Vector3 val = centreDome.InverseTransformPoint(p);
			Vector2 val2 = new Vector2(val.x, val.z);
			if (((Vector2)(ref val2)).magnitude < rayonDome + 50f && val.y > -200f)
			{
				return val.y < 800f;
			}
			return false;
		}

		private bool CreerPoignee(Transform emplacement, EntranceTeleport vraie)
		{
			//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_0043: 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_0061: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ad: 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)
			//IL_00ca: 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_011b: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			InteractTrigger componentInChildren = ((Component)vraie).GetComponentInChildren<InteractTrigger>(true);
			Transform val = emplacement.Find("SpawnEntranceBTrigger");
			if ((Object)(object)componentInChildren == (Object)null || (Object)(object)val == (Object)null)
			{
				return false;
			}
			GameObject val2 = new GameObject("PoigneeSortie")
			{
				layer = ((Component)componentInChildren).gameObject.layer,
				tag = ((Component)componentInChildren).gameObject.tag
			};
			val2.transform.SetParent(val, false);
			val2.transform.localPosition = ((Component)vraie).transform.InverseTransformPoint(((Component)componentInChildren).transform.position);
			val2.transform.localRotation = Quaternion.Inverse(((Component)vraie).transform.rotation) * ((Component)componentInChildren).transform.rotation;
			val2.transform.localScale = ((Component)componentInChildren).transform.lossyScale;
			BoxCollider component = ((Component)componentInChildren).GetComponent<BoxCollider>();
			BoxCollider val3 = val2.AddComponent<BoxCollider>();
			if ((Object)(object)component != (Object)null)
			{
				val3.center = component.center;
				val3.size = component.size;
				((Collider)val3).isTrigger = ((Collider)component).isTrigger;
			}
			else
			{
				val3.size = new Vector3(1.2f, 2.4f, 1.2f);
				val3.center = Vector3.up * 1.2f;
				((Collider)val3).isTrigger = true;
			}
			InteractTrigger obj = val2.AddComponent<InteractTrigger>();
			FieldInfo[] fields = typeof(InteractTrigger).GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly)
				{
					fieldInfo.SetValue(obj, fieldInfo.GetValue(componentInChildren));
				}
			}
			poignees[emplacement] = vraie;
			return true;
		}

		private void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
			AppliquerDedans(actif: false);
			if ((Object)(object)volume != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)volume).gameObject);
			}
			if ((Object)(object)jourInst != (Object)null)
			{
				Object.Destroy((Object)(object)jourInst);
			}
			if ((Object)(object)nuitInst != (Object)null)
			{
				Object.Destroy((Object)(object)nuitInst);
			}
			if ((Object)(object)nuagesInst != (Object)null)
			{
				Object.Destroy((Object)(object)nuagesInst);
			}
		}

		private void LateUpdate()
		{
			PlayerControllerB joueurSuivi;
			bool flag = JoueurDansIntérieur(out joueurSuivi);
			if (flag != dedansPrecedent)
			{
				AppliquerDedans(flag);
				dedansPrecedent = flag;
				nuitPrecedente = flag && EstLaNuit();
				nuitT = -1f;
				AppliquerFondu(nuitPrecedente ? 1f : 0f);
			}
			if (!flag)
			{
				return;
			}
			nuitPrecedente = EstLaNuit();
			float num = DureeCoucher() + 9f;
			float num2 = (nuitPrecedente ? 1f : 0f);
			float num3 = (nuitPrecedente ? num : Mathf.Min(num, 12f));
			AppliquerFondu((num <= 0.01f) ? num2 : Mathf.MoveTowards(nuitT, num2, Time.deltaTime / num3));
			float num4 = 1f - sombreActuel;
			float num5 = ((GreenHillsPlugin.IntensiteSoleil != null) ? GreenHillsPlugin.IntensiteSoleil.Value : 6f) * num4;
			float num6 = ((GreenHillsPlugin.PartRemplissage != null) ? GreenHillsPlugin.PartRemplissage.Value : 0.45f);
			float num7 = ((GreenHillsPlugin.LumiereAmbiante != null) ? GreenHillsPlugin.LumiereAmbiante.Value : 0.4f);
			if ((Object)(object)soleil != (Object)null)
			{
				soleil.intensity = num5;
			}
			if ((Object)(object)remplissage != (Object)null)
			{
				remplissage.intensity = num5 * num6;
			}
			foreach (Light ambiance in ambiances)
			{
				if ((Object)(object)ambiance != (Object)null)
				{
					ambiance.intensity = num5 * num7;
				}
			}
			TimeOfDay instance = TimeOfDay.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.insideLighting = true;
			}
			HUDManager instance2 = HUDManager.Instance;
			if ((Object)(object)instance2 != (Object)null && instance2.Clock != null && (Object)(object)instance2.Clock.canvasGroup != (Object)null)
			{
				instance2.Clock.targetAlpha = 0f;
				instance2.Clock.canvasGroup.alpha = 0f;
			}
			OrienterNuages(nuages, CameraActive());
			AfficherSorties(CameraActive());
			CouperSons(couper: true);
			PlafondDoux(joueurSuivi);
			Detecteur(joueurSuivi);
		}

		internal bool EstLaNuit()
		{
			TimeOfDay instance = TimeOfDay.Instance;
			if ((Object)(object)instance == (Object)null || !instance.currentDayTimeStarted)
			{
				return false;
			}
			string obj = ((GreenHillsPlugin.HeuresNuits != null) ? GreenHillsPlugin.HeuresNuits.Value : "12.5;16.5;21");
			float num = instance.lengthOfHours * (float)instance.numberOfHours;
			float num2 = LargeurNuit() * instance.globalTimeSpeedMultiplier;
			float num3 = ((num > 0f) ? (num2 / num) : 0.08f);
			float normalizedTimeOfDay = instance.normalizedTimeOfDay;
			string[] array = obj.Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				if (float.TryParse(array[i].Trim().Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					float num4 = (result - 6f) / (float)Mathf.Max(1, instance.numberOfHours);
					if (normalizedTimeOfDay >= num4 && normalizedTimeOfDay < num4 + num3)
					{
						return true;
					}
				}
			}
			return false;
		}

		public bool NuitNoire(out int index)
		{
			index = -1;
			TimeOfDay instance = TimeOfDay.Instance;
			if ((Object)(object)instance == (Object)null || !instance.currentDayTimeStarted)
			{
				return false;
			}
			string text = ((GreenHillsPlugin.HeuresNuits != null) ? GreenHillsPlugin.HeuresNuits.Value : "12.5;16.5;21");
			float num = instance.lengthOfHours * (float)instance.numberOfHours;
			if (num <= 0f)
			{
				return false;
			}
			float globalTimeSpeedMultiplier = instance.globalTimeSpeedMultiplier;
			float num2 = LargeurNuit() * globalTimeSpeedMultiplier / num;
			float num3 = (DureeCoucher() + 9f) * globalTimeSpeedMultiplier / num;
			float normalizedTimeOfDay = instance.normalizedTimeOfDay;
			int num4 = 0;
			string[] array = text.Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				if (float.TryParse(array[i].Trim().Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					float num5 = (result - 6f) / (float)Mathf.Max(1, instance.numberOfHours);
					if (normalizedTimeOfDay >= num5 + num3 && normalizedTimeOfDay < num5 + num2)
					{
						index = num4;
						return true;
					}
					num4++;
				}
			}
			return false;
		}

		private static float LargeurNuit()
		{
			return ((GreenHillsPlugin.DureeNuitSecondes != null) ? GreenHillsPlugin.DureeNuitSecondes.Value : 35f) + DureeCoucher() + 9f;
		}

		private static float DureeCoucher()
		{
			return Mathf.Max(0f, (GreenHillsPlugin.DureeFondu != null) ? GreenHillsPlugin.DureeFondu.Value : 15f);
		}

		private void AppliquerFondu(float t)
		{
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			if (Mathf.Approximately(t, nuitT))
			{
				return;
			}
			nuitT = t;
			float num = DureeCoucher();
			float num2 = num + 9f;
			float num3 = t * num2;
			float num4 = ((num > 0.01f) ? Mathf.Clamp01(num3 / num) : ((t > 0f) ? 1f : 0f));
			float num5 = Mathf.Clamp01((num3 - num) / 9f);
			sombreActuel = num4;
			bool enabled = dedansPrecedent && num4 < 0.999f;
			if ((Object)(object)soleil != (Object)null)
			{
				((Behaviour)soleil).enabled = enabled;
			}
			if ((Object)(object)remplissage != (Object)null)
			{
				((Behaviour)remplissage).enabled = enabled;
			}
			foreach (Light ambiance in ambiances)
			{
				if ((Object)(object)ambiance != (Object)null)
				{
					((Behaviour)ambiance).enabled = enabled;
				}
			}
			if ((Object)(object)dome != (Object)null && (Object)(object)jourInst != (Object)null && (Object)(object)nuitInst != (Object)null)
			{
				bool flag = num4 >= 0.999f;
				Material val = (flag ? nuitInst : jourInst);
				val.SetColor("_UnlitColor", Color.white * (flag ? num5 : (1f - num4)));
				if ((Object)(object)dome.sharedMaterial != (Object)(object)val)
				{
					dome.sharedMaterial = val;
				}
			}
			if ((Object)(object)nuagesInst != (Object)null)
			{
				bool flag2 = num4 < 0.999f;
				nuagesInst.SetColor("_UnlitColor", new Color(1f - num4, 1f - num4, 1f - num4, 1f));
				Renderer[] array = rendusNuages;
				foreach (Renderer val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && val2.enabled != flag2)
					{
						val2.enabled = flag2;
					}
				}
			}
			float num6 = ((GreenHillsPlugin.IntensiteLampadaires != null) ? GreenHillsPlugin.IntensiteLampadaires.Value : 1f);
			for (int j = 0; j < lumieresLampadaires.Length; j++)
			{
				if (!((Object)(object)lumieresLampadaires[j] == (Object)null))
				{
					((Behaviour)lumieresLampadaires[j]).enabled = dedansPrecedent && num5 > 0.001f;
					lumieresLampadaires[j].intensity = intensitesLampadaires[j] * num6 * num5;
				}
			}
		}

		private void AppliquerDedans(bool actif)
		{
			dedansPrecedent = actif;
			if ((Object)(object)soleil != (Object)null)
			{
				((Behaviour)soleil).enabled = actif;
			}
			if ((Object)(object)remplissage != (Object)null)
			{
				((Behaviour)remplissage).enabled = actif;
			}
			if (!actif)
			{
				Light[] array = lumieresLampadaires;
				foreach (Light val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						((Behaviour)val).enabled = false;
					}
				}
			}
			if (actif)
			{
				AssurerVolume();
				AssurerAmbiances();
				CouperMeteo(couper: true);
			}
			else
			{
				if ((Object)(object)volume != (Object)null)
				{
					Object.Destroy((Object)(object)volume.sharedProfile);
					Object.Destroy((Object)(object)((Component)volume).gameObject);
					volume = null;
				}
				foreach (Light ambiance in ambiances)
				{
					if ((Object)(object)ambiance != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)ambiance).gameObject);
					}
				}
				ambiances.Clear();
				if ((Object)(object)TimeOfDay.Instance != (Object)null)
				{
					TimeOfDay.Instance.insideLighting = false;
				}
				CouperMeteo(couper: false);
			}
			if (!actif)
			{
				CouperSons(couper: false);
			}
		}

		private void AssurerAmbiances()
		{
			//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_0041: 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_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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			if (ambiances.Count <= 0)
			{
				Vector3[] array = (Vector3[])(object)new Vector3[5]
				{
					new Vector3(30f, 0f, 0f),
					new Vector3(30f, 90f, 0f),
					new Vector3(30f, 180f, 0f),
					new Vector3(30f, 270f, 0f),
					new Vector3(-70f, 0f, 0f)
				};
				foreach (Vector3 val in array)
				{
					GameObject val2 = new GameObject("GreenHills_Ambiance");
					val2.transform.SetParent(((Component)this).transform, false);
					val2.transform.rotation = Quaternion.Euler(val);
					HDAdditionalLightData obj = GameObjectExtension.AddHDLight(val2, (HDLightTypeAndShape)4);
					obj.EnableShadows(false);
					obj.affectsVolumetric = false;
					obj.interactsWithSky = false;
					Light component = val2.GetComponent<Light>();
					component.intensity = 1f;
					ambiances.Add(component);
				}
			}
		}

		private static void CouperMeteo(bool couper)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			TimeOfDay instance = TimeOfDay.Instance;
			if (!((Object)(object)instance == (Object)null) && instance.effects != null)
			{
				if (couper)
				{
					instance.DisableAllWeather(false);
				}
				else if ((int)instance.currentLevelWeather != -1 && (int)instance.currentLevelWeather < instance.effects.Length)
				{
					instance.effects[instance.currentLevelWeather].effectEnabled = true;
				}
			}
		}

		public float SecondesAvantNuit()
		{
			TimeOfDay instance = TimeOfDay.Instance;
			if ((Object)(object)instance == (Object)null || !instance.currentDayTimeStarted)
			{
				return float.PositiveInfinity;
			}
			string obj = ((GreenHillsPlugin.HeuresNuits != null) ? GreenHillsPlugin.HeuresNuits.Value : "12.5;16.5;21");
			float num = instance.lengthOfHours * (float)instance.numberOfHours;
			float num2 = float.PositiveInfinity;
			string[] array = obj.Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				if (float.TryParse(array[i].Trim().Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					float num3 = ((result - 6f) / (float)Mathf.Max(1, instance.numberOfHours) - instance.normalizedTimeOfDay) * num / Mathf.Max(0.01f, instance.globalTimeSpeedMultiplier);
					if (num3 >= 0f && num3 < num2)
					{
						num2 = num3;
					}
				}
			}
			return num2;
		}

		public bool PeriodeEnCours(out int periode, out float ecoule)
		{
			periode = 0;
			ecoule = 0f;
			TimeOfDay instance = TimeOfDay.Instance;
			if ((Object)(object)instance == (Object)null || !instance.currentDayTimeStarted)
			{
				return false;
			}
			string obj = ((GreenHillsPlugin.HeuresNuits != null) ? GreenHillsPlugin.HeuresNuits.Value : "12.5;16.5;21");
			float num = instance.lengthOfHours * (float)instance.numberOfHours;
			float num2 = Mathf.Max(0.01f, instance.globalTimeSpeedMultiplier);
			float num3 = instance.normalizedTimeOfDay * num / num2;
			float num4 = LargeurNuit();
			float num5 = 0f;
			List<float> list = new List<float>();
			string[] array = obj.Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				if (float.TryParse(array[i].Trim().Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					list.Add((result - 6f) / (float)Mathf.Max(1, instance.numberOfHours) * num / num2 + num4);
				}
			}
			list.Sort();
			foreach (float item in list)
			{
				if (num3 >= item)
				{
					periode++;
					num5 = item;
				}
			}
			ecoule = num3 - num5;
			return true;
		}

		private static Transform CameraActive()
		{
			Camera val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.activeCamera : null);
			if ((Object)(object)val == (Object)null)
			{
				val = Camera.main;
			}
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return ((Component)val).transform;
		}

		public static void OrienterNuages(Transform nuages, Transform cam)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_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_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_0064: 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_007b: 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)
			if ((Object)(object)nuages == (Object)null || (Object)(object)cam == (Object)null)
			{
				return;
			}
			Vector3 position = cam.position;
			for (int i = 0; i < nuages.childCount; i++)
			{
				Transform child = nuages.GetChild(i);
				Vector3 val = child.position - position;
				Vector2 val2 = new Vector2(val.x, val.z);
				float magnitude = ((Vector2)(ref val2)).magnitude;
				if (!(magnitude < 0.5f))
				{
					float num = magnitude * 1.732f;
					val.y = Mathf.Clamp(val.y, 0f - num, num);
					child.rotation = Quaternion.LookRotation(val, Vector3.up);
				}
			}
		}

		private void AfficherSorties(Transform cam)
		{
			//IL_00bb: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cam == (Object)null)
			{
				return;
			}
			bool flag = GreenHillsPlugin.LimiterVisibiliteSorties != null && GreenHillsPlugin.LimiterVisibiliteSorties.Value;
			float num = ((GreenHillsPlugin.VisibiliteSorties != null) ? GreenHillsPlugin.VisibiliteSorties.Value : 60f);
			float num2 = num * num;
			float num3 = ((GreenHillsPlugin.VisibiliteSortiesFace != null) ? GreenHillsPlugin.VisibiliteSortiesFace.Value : 250f);
			float num4 = ((GreenHillsPlugin.HauteurMaxSorties != null) ? GreenHillsPlugin.HauteurMaxSorties.Value : 40f);
			foreach (var (val, array, array2) in sorties)
			{
				if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
				{
					continue;
				}
				Vector3 val2 = cam.position - val.position;
				int num5;
				if (val2.y < num4)
				{
					Vector2 val3 = new Vector2(val2.x, val2.z);
					num5 = ((((Vector2)(ref val3)).sqrMagnitude < num3 * num3) ? 1 : 0);
				}
				else
				{
					num5 = 0;
				}
				bool flag2 = (byte)num5 != 0;
				bool flag3 = !flag || ((Vector3)(ref val2)).sqrMagnitude < num2 || flag2;
				Renderer[] array3 = array;
				foreach (Renderer val4 in array3)
				{
					if ((Object)(object)val4 != (Object)null && val4.enabled != flag3)
					{
						val4.enabled = flag3;
					}
				}
				Light[] array4 = array2;
				foreach (Light val5 in array4)
				{
					if ((Object)(object)val5 != (Object)null && ((Behaviour)val5).enabled != flag3)
					{
						((Behaviour)val5).enabled = flag3;
					}
				}
			}
		}

		internal void SortieUtilisee(EntranceTeleport e, Vector3? avant)
		{
			//IL_005d: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: 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_0253: 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_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			if (dernierPassage.TryGetValue(e, out var value) && Time.time - value < 3f)
			{
				return;
			}
			Transform proche = null;
			float num = (avant.HasValue ? 10f : 6f);
			Vector3 val = (Vector3)(((??)avant) ?? ((Component)e).transform.position);
			foreach (var sorty in sorties)
			{
				Transform item = sorty.t;
				if (!((Object)(object)item == (Object)null) && ((Component)item).gameObject.activeSelf && (poignees.TryGetValue(item, out var value2) ? ((Object)(object)value2 == (Object)(object)e) : (Vector3.Distance(item.position, ((Component)e).transform.position) < 6f)))
				{
					float num2 = Vector3.Distance(item.position, val);
					if (num2 < num)
					{
						num = num2;
						proche = item;
					}
				}
			}
			if ((Object)(object)proche == (Object)null)
			{
				return;
			}
			dernierPassage[e] = Time.time;
			List<Transform> list = (from x in sorties
				select x.t into t
				where (Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)proche && !((Component)t).gameObject.activeSelf
				select t).OrderBy<Transform, string>((Transform t) => ((Object)t).name, StringComparer.Ordinal).ToList();
			if (list.Count == 0)
			{
				GreenHillsPlugin.Log.LogInfo((object)("[Sorties] " + ((Object)proche).name + " utilisée : aucun emplacement libre, elle reste."));
				return;
			}
			int num3 = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.randomMapSeed : 0);
			Transform val2 = list[new Random(num3 + 7919 * (deplacements + 1)).Next(list.Count)];
			deplacements++;
			Vector3 localPosition = proche.localPosition;
			Quaternion localRotation = proche.localRotation;
			proche.localPosition = val2.localPosition;
			proche.localRotation = val2.localRotation;
			val2.localPosition = localPosition;
			val2.localRotation = localRotation;
			if (!poignees.ContainsKey(proche))
			{
				Transform val3 = proche.Find("SpawnEntranceBTrigger");
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)e).transform.SetPositionAndRotation(val3.position, val3.rotation);
				}
				else
				{
					((Component)e).transform.position = proche.position;
				}
			}
			GreenHillsPlugin.Log.LogInfo((object)$"[Sorties] {((Object)proche).name} utilisée : déplacée à l'ancienne place de {((Object)val2).name} ({proche.position.x:0}, {proche.position.y:0}, {proche.position.z:0}).");
		}

		private void AssurerVolume()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			if (!((Object)(object)volume != (Object)null))
			{
				GameObject val = new GameObject("GreenHills_Volume");
				val.layer = CalqueVolume();
				volume = val.AddComponent<Volume>();
				volume.isGlobal = true;
				volume.priority = 1000f;
				VolumeProfile val2 = ScriptableObject.CreateInstance<VolumeProfile>();
				((VolumeParameter<bool>)(object)val2.Add<Fog>(true).enabled).Override(false);
				volume.sharedProfile = val2;
			}
		}

		internal static int CalqueVolume()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			Camera val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.activeCamera : Camera.main);
			HDAdditionalCameraData val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<HDAdditionalCameraData>() : null);
			int num = ((!((Object)(object)val2 != (Object)null)) ? 1 : LayerMask.op_Implicit(val2.volumeLayerMask));
			for (int i = 0; i < 32; i++)
			{
				if ((num & (1 << i)) != 0)
				{
					return i;
				}
			}
			return 0;
		}

		private void CouperSons(bool couper)
		{
			SoundManager instance = SoundManager.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				if ((Object)(object)instance.ambienceAudio != (Object)null)
				{
					instance.ambienceAudio.mute = couper;
				}
				if ((Object)(object)instance.ambienceAudioNonDiagetic != (Object)null)
				{
					instance.ambienceAudioNonDiagetic.mute = couper;
				}
			}
			if (couper && Time.time >= prochaineRecherche)
			{
				aerations = Object.FindObjectsOfType<EnemyVent>();
				prochaineRecherche = Time.time + 3f;
			}
			EnemyVent[] array = aerations;
			foreach (EnemyVent val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val.ventAudio != (Object)null)
				{
					val.ventAudio.mute = couper;
				}
			}
		}

		private void Detecteur(PlayerControllerB joueur)
		{
			//IL_0042: 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_0098: 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_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			if (GreenHillsPlugin.DetecteurSons == null || !GreenHillsPlugin.DetecteurSons.Value || (Object)(object)joueur == (Object)null || Time.time < prochainDetecteur)
			{
				return;
			}
			prochainDetecteur = Time.time + 15f;
			Vector3 position = ((Component)joueur).transform.position;
			AudioSource[] array = Object.FindObjectsOfType<AudioSource>();
			foreach (AudioSource val in array)
			{
				if (!((Object)(object)val == (Object)null) && val.isPlaying && !val.mute && !(val.volume <= 0.01f))
				{
					float num = ((val.spatialBlend < 0.5f) ? 0f : Vector3.Distance(position, ((Component)val).transform.position));
					if (!(val.spatialBlend >= 0.5f) || !(num > val.maxDistance))
					{
						ManualLogSource log = GreenHillsPlugin.Log;
						object[] obj = new object[9]
						{
							val.loop ? "BOUCLE" : "ponctuel",
							((Object)((Component)val).gameObject).name,
							((Object)(object)val.clip != (Object)null) ? ((Object)val.clip).name : "-",
							val.volume,
							num,
							((Object)(object)((Component)val).transform.parent != (Object)null) ? ((Object)((Component)val).transform.parent).name : "-",
							((Object)((Component)val).transform.root).name,
							null,
							null
						};
						Scene scene = ((Component)val).gameObject.scene;
						obj[7] = ((Scene)(ref scene)).name;
						obj[8] = ((val.spatialBlend < 0.5f) ? "oui" : "non");
						log.LogInfo((object)string.Format("[Son] {0} '{1}' clip={2} vol={3:0.00} dist={4:0} parent={5} racine={6} scène={7} 2D={8}", obj));
					}
				}
			}
		}

		private void PlafondDoux(PlayerControllerB joueur)
		{
			//IL_0042: 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_0051: 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_005b: 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_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_008f: 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_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_00b0: 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_00fc: 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_0138: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: 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_0153: 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_0163: 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)
			if (!((Object)(object)joueur == (Object)null) && !joueur.isPlayerDead && !((Object)(object)centreDome == (Object)null) && (!((Object)(object)joueur.thisController != (Object)null) || !joueur.thisController.isGrounded) && !Physics.Raycast(((Component)joueur).transform.position + Vector3.up * 0.5f, Vector3.down, 6.5f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				Vector3 val = centreDome.InverseTransformPoint(((Component)joueur).transform.position);
				Vector2 val2 = new Vector2(val.x, val.z);
				float magnitude = ((Vector2)(ref val2)).magnitude;
				float num = float.MaxValue;
				if (val.y > hauteurMur - margeDouce)
				{
					float num2 = Mathf.Clamp01(magnitude / rayonDome);
					num = hauteurMur + hauteurCalotte * Mathf.Sqrt(Mathf.Max(0f, 1f - num2 * num2)) - val.y;
				}
				Vector3 val3 = Vector3.zero;
				if (num < margeDouce)
				{
					val3 += Vector3.down * (1f - Mathf.Clamp01(num / margeDouce));
				}
				if (!(val3 == Vector3.zero))
				{
					joueur.externalForces += centreDome.TransformDirection(val3) * forceDouce;
				}
			}
		}

		private static bool JoueurDansIntérieur(out PlayerControllerB joueurSuivi)
		{
			joueurSuivi = null;
			GameNetworkManager instance = GameNetworkManager.Instance;
			PlayerControllerB val = (((Object)(object)instance != (Object)null) ? instance.localPlayerController : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			if (val.isPlayerDead)
			{
				PlayerControllerB spectatedPlayerScript = val.spectatedPlayerScript;
				if ((Object)(object)spectatedPlayerScript != (Object)null && !spectatedPlayerScript.isPlayerDead)
				{
					return spectatedPlayerScript.isInsideFactory;
				}
				return false;
			}
			joueurSuivi = val;
			return val.isInsideFactory;
		}
	}
	public class GreenHillsCruiser : MonoBehaviour
	{
		public Transform points;

		internal static GreenHillsCruiser Instance;

		private void Awake()
		{
			Instance = this;
		}

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

		private IEnumerator Start()
		{
			if (GreenHillsPlugin.CruiserBlanc == null || GreenHillsPlugin.CruiserBlanc.Value)
			{
				((MonoBehaviour)this).StartCoroutine(Peinture.Preparer());
			}
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer)
			{
				yield break;
			}
			if (GreenHillsPlugin.CruiserActif != null && !GreenHillsPlugin.CruiserActif.Value)
			{
				GreenHillsPlugin.Log.LogInfo((object)"Cruiser de Green Hills désactivé dans le cfg.");
				yield break;
			}
			GreenHillsPlugin.Log.LogInfo((object)"Cruiser de Green Hills : en attente de la fin de la génération.");
			float debut = Time.time;
			while ((Object)(object)RoundManager.Instance != (Object)null && !RoundManager.Instance.dungeonCompletedGenerating && Time.time - debut < 180f)
			{
				yield return null;
			}
			while (!Peinture.Prete && Time.time - debut < 60f)
			{
				yield return null;
			}
			yield return (object)new WaitForSeconds(1f);
			Terminal terminal = null;
			string text = null;
			for (int essai = 0; essai < 16; essai++)
			{
				if (essai > 0)
				{
					yield return (object)new WaitForSeconds(2f);
				}
				text = null;
				if ((Object)(object)this == (Object)null)
				{
					yield break;
				}
				if ((Object)(object)points == (Object)null || points.childCount == 0)
				{
					text = "aucun emplacement sur les routes";
					break;
				}
				if ((Object)(object)StartOfRound.Instance == (Object)null || StartOfRound.Instance.inShipPhase)
				{
					text = "le vaisseau n'est pas posé";
					continue;
				}
				if (Object.FindObjectsOfType<VehicleController>().Length != 0)
				{
					GreenHillsPlugin.Log.LogInfo((object)"Cruiser de Green Hills : un Cruiser existe déjà, on n'en ajoute pas.");
					yield break;
				}
				terminal = Object.FindObjectOfType<Terminal>();
				if ((Object)(object)terminal == (Object)null || terminal.buyableVehicles == null || terminal.buyableVehicles.Length == 0)
				{
					text = "aucun véhicule dans le terminal";
					break;
				}
				if (terminal.buyableVehicles[0] == null || (Object)(object)terminal.buyableVehicles[0].vehiclePrefab == (Object)null)
				{
					text = "véhicule du terminal sans modèle";
					break;
				}
				if (terminal.vehicleInDropship)
				{
					text = "un véhicule est dans la navette";
					continue;
				}
				if (terminal.orderedVehicleFromTerminal != -1)
				{
					text = $"un véhicule est commandé (n°{terminal.orderedVehicleFromTerminal})";
					continue;
				}
				ItemDropship val = Object.FindObjectOfType<ItemDropship>();
				if ((Object)(object)val != (Object)null && val.deliveringVehicle)
				{
					text = "la navette livre un véhicule";
					continue;
				}
				if (!((Object)(object)RoundManager.Instance == (Object)null))
				{
					break;
				}
				text = "RoundManager absent";
			}
			if (text != null)
			{
				GreenHillsPlugin.Log.LogInfo((object)("Cruiser de Green Hills non posé : " + text + "."));
				yield break;
			}
			Transform child = points.GetChild(Random.Range(0, points.childCount));
			Vector3 val2 = child.position;
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Raycast(val2 + Vector3.up * 6f, Vector3.down, ref val3, 20f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				val2 = ((RaycastHit)(ref val3)).point;
			}
			val2 += Vector3.up * 0.6f;
			GameObject obj = Object.Instantiate<GameObject>(terminal.buyableVehicles[0].vehiclePrefab, val2, child.rotation, RoundManager.Instance.VehiclesContainer);
			VehicleController component = obj.GetComponent<VehicleController>();
			if ((Object)(object)component != (Object)null)
			{
				component.hasBeenSpawned = true;
			}
			obj.GetComponent<NetworkObject>().Spawn(false);
			GreenHillsPlugin.Log.LogInfo((object)("Cruiser de Green Hills posé sur la route (" + ((Object)child).name + ")."));
			if ((Object)(object)component != (Object)null)
			{
				((MonoBehaviour)this).StartCoroutine(Recaler(component, val2, child.rotation));
			}
		}

		private IEnumerator Recaler(VehicleController vc, Vector3 pos, Quaternion rot)
		{
			//IL_000e: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody rb = vc.mainRigidbody;
			float fin = Time.time + 4f;
			Vector3 val2 = default(Vector3);
			while (Time.time < fin && (Object)(object)vc != (Object)null && (Object)(object)rb != (Object)null)
			{
				yield return (object)new WaitForFixedUpdate();
				if ((Object)(object)vc.currentDriver != (Object)null || vc.carDestroyed)
				{
					yield break;
				}
				Vector3 val = rb.position - pos;
				val.y = 0f;
				if (((Vector3)(ref val)).magnitude > 0.5f || Quaternion.Angle(rb.rotation, rot) > 15f)
				{
					((Vector3)(ref val2))..ctor(pos.x, rb.position.y, pos.z);
					rb.velocity = Vector3.zero;
					rb.angularVelocity = Vector3.zero;
					rb.position = val2;
					rb.rotation = rot;
					((Component)vc).transform.SetPositionAndRotation(val2, rot);
				}
			}
			yield return (object)new WaitForSeconds(3f);
			if (!((Object)(object)vc == (Object)null) && !((Object)(object)rb == (Object)null))
			{
				Vector3 val3 = rb.position - pos;
				val3.y = 0f;
				GreenHillsPlugin.Log.LogInfo((object)$"Cruiser de Green Hills : écart à son emplacement {((Vector3)(ref val3)).magnitude:0.0} m, angle {Quaternion.Angle(rb.rotation, rot):0}°.");
			}
		}

		internal static bool EstNotreEmplacement(Vector3 p)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_003f: 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_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_0052: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null || (Object)(object)Instance.points == (Object)null)
			{
				return false;
			}
			foreach (Transform point in Instance.points)
			{
				Transform val = point;
				Vector3 val2 = p - val.position;
				Vector2 val3 = new Vector2(val2.x, val2.z);
				if (((Vector2)(ref val3)).magnitude < 4f && Mathf.Abs(val2.y) < 8f)
				{
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(VehicleController), "Start")]
	internal static class GreenHillsCruiserLivre
	{
		[HarmonyPostfix]
		private static void Apres(VehicleController __instance)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && !__instance.magnetedToShip && !((Object)(object)StartOfRound.Instance == (Object)null) && !StartOfRound.Instance.inShipPhase && !((Object)(object)StartOfRound.Instance.attachedVehicle == (Object)(object)__instance) && GreenHillsCruiser.EstNotreEmplacement(((Component)__instance).transform.position))
			{
				__instance.hasBeenSpawned = true;
				if (GreenHillsPlugin.CruiserBlanc == null || GreenHillsPlugin.CruiserBlanc.Value)
				{
					Peinture.Blanchir(__instance);
				}
			}
		}
	}
	internal static class Peinture
	{
		private static readonly Dictionary<Material, Material> copies = new Dictionary<Material, Material>();

		private static readonly Dictionary<Texture, Texture2D> textures = new Dictionary<Texture, Texture2D>();

		private static bool enCours;

		internal static bool Prete;

		private const int N = 2048;

		internal static IEnumerator Preparer()
		{
			if (Prete || enCours)
			{
				yield break;
			}
			Texture source = null;
			Terminal val = Object.FindObjectOfType<Terminal>();
			if ((Object)(object)val != (Object)null && val.buyableVehicles != null && val.buyableVehicles.Length != 0 && (Object)(object)val.buyableVehicles[0].vehiclePrefab != (Object)null)
			{
				Renderer[] componentsInChildren = val.buyableVehicles[0].vehiclePrefab.GetComponentsInChildren<Renderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Material[] sharedMaterials = componentsInChildren[i].sharedMaterials;
					foreach (Material val2 in sharedMaterials)
					{
						if ((Object)(object)val2 != (Object)null && ((Object)val2).name.StartsWith("TruckTexture") && val2.HasProperty("_BaseColorMap") && (Object)(object)val2.GetTexture("_BaseColorMap") != (Object)null)
						{
							source = val2.GetTexture("_BaseColorMap");
							break;
						}
					}
					if ((Object)(object)source != (Object)null)
					{
						break;
					}
				}
			}
			if ((Object)(object)source == (Object)null)
			{
				Prete = true;
				yield break;
			}
			if (textures.ContainsKey(source))
			{
				Prete = true;
				yield break;
			}
			enCours = true;
			Texture2D t;
			Color32[] px = Lire(source, out t);
			Task tache = Task.Run(delegate
			{
				Blanchir(px);
			});
			while (!tache.IsCompleted)
			{
				yield return null;
			}
			if (tache.Exception == null)
			{
				t.SetPixels32(px);
				t.Apply(true, true);
				textures[source] = t;
				GreenHillsPlugin.Log.LogInfo((object)"Peinture blanche du Cruiser préparée (en arrière-plan).");
			}
			else
			{
				GreenHillsPlugin.Log.LogWarning((object)("Peinture du Cruiser : " + tache.Exception.GetBaseException().Message));
			}
			enCours = false;
			Prete = true;
		}

		internal static void Blanchir(VehicleController vc)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			try
			{
				int num = 0;
				Renderer[] componentsInChildren = ((Component)vc).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val in componentsInChildren)
				{
					Material[] sharedMaterials = val.sharedMaterials;
					bool flag = false;
					for (int j = 0; j < sharedMaterials.Length; j++)
					{
						Material val2 = sharedMaterials[j];
						if ((Object)(object)val2 == (Object)null || !((Object)val2).name.StartsWith("TruckTexture"))
						{
							continue;
						}
						if (!copies.TryGetValue(val2, out var value))
						{
							value = new Material(val2)
							{
								name = ((Object)val2).name + " (GreenHills blanc)"
							};
							Texture val3 = (val2.HasProperty("_BaseColorMap") ? val2.GetTexture("_BaseColorMap") : null);
							if ((Object)(object)val3 != (Object)null)
							{
								Texture2D val4 = TextureBlanche(val3);
								value.SetTexture("_BaseColorMap", (Texture)(object)val4);
								if (value.HasProperty("_MainTex"))
								{
									value.SetTexture("_MainTex", (Texture)(object)val4);
								}
							}
							copies[val2] = value;
						}
						sharedMaterials[j] = value;
						flag = true;
					}
					if (flag)
					{
						val.sharedMaterials = sharedMaterials;
						num++;
					}
				}
				GreenHillsPlugin.Log.LogInfo((object)$"Cruiser de Green Hills peint en blanc ({num} pièces).");
			}
			catch (Exception ex)
			{
				GreenHillsPlugin.Log.LogWarning((object)("Peinture du Cruiser impossible : " + ex.Message));
			}
		}

		private static Texture2D TextureBlanche(Texture source)
		{
			if (textures.TryGetValue(source, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Color32[] array = Lire(source, out value);
			Blanchir(array);
			value.SetPixels32(array);
			value.Apply(true, true);
			textures[source] = value;
			return value;
		}

		private static Color32[] Lire(Texture source, out Texture2D t)
		{
			//IL_0033: 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)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			RenderTexture temporary = RenderTexture.GetTemporary(2048, 2048, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
			RenderTexture active = RenderTexture.active;
			Graphics.Blit(source, temporary);
			RenderTexture.active = temporary;
			t = new Texture2D(2048, 2048, (TextureFormat)4, true, false)
			{
				name = "CruiserBlanc",
				hideFlags = (HideFlags)32
			};
			t.ReadPixels(new Rect(0f, 0f, 2048f, 2048f), 0, 0);
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return t.GetPixels32();
		}

		private static void Blanchir(Color32[] px)
		{
			//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)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: 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_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: 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_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			Color32 blanc = new Color32((byte)236, (byte)236, (byte)232, byte.MaxValue);
			int[] array = new int[px.Length];
			int[] array2 = new int[px.Length];
			List<int> list = new List<int> { 0 };
			List<int> list2 = new List<int> { 0 };
			for (int i = 0; i < px.Length; i++)
			{
				if (array[i] != 0)
				{
					continue;
				}
				if (Fond(px[i]))
				{
					array[i] = -1;
					continue;
				}
				int count = list.Count;
				int num = 0;
				int num2 = 0;
				int num3 = 0;
				array2[num3++] = i;
				array[i] = count;
				while (num3 > 0)
				{
					int num4 = array2[--num3];
					num2++;
					if (Rouge(px[num4]))
					{
						num++;
					}
					int num5 = num4 % 2048;
					int num6 = num4 / 2048;
					for (int j = 0; j < 4; j++)
					{
						int num7 = num5 + j switch
						{
							1 => -1, 
							0 => 1, 
							_ => 0, 
						};
						int num8 = num6 + j switch
						{
							3 => -1, 
							2 => 1, 
							_ => 0, 
						};
						if (num7 < 0 || num8 < 0 || num7 >= 2048 || num8 >= 2048)
						{
							continue;
						}
						int num9 = num8 * 2048 + num7;
						if (array[num9] == 0)
						{
							if (Fond(px[num9]))
							{
								array[num9] = -1;
								continue;
							}
							array[num9] = count;
							array2[num3++] = num9;
						}
					}
				}
				list.Add(num);
				list2.Add(num2);
			}
			for (int k = 0; k < px.Length; k++)
			{
				int num10 = array[k];
				if ((num10 > 0 && (float)list[num10] > (float)list2[num10] * 0.35f) || Rouge(px[k]))
				{
					px[k] = new Color32(blanc.r, blanc.g, blanc.b, px[k].a);
				}
			}
			for (int l = 0; l < 2; l++)
			{
				for (int m = 1; m < 2047; m++)
				{
					for (int n = 1; n < 2047; n++)
					{
						int num11 = m * 2048 + n;
						if (array[num11] != -1)
						{
							continue;
						}
						int num12 = 0;
						for (int num13 = 1; num13 <= 12 && n + num13 < 2048; num13++)
						{
							if (B(num11 + num13))
							{
								num12++;
								break;
							}
						}
						for (int num14 = 1; num14 <= 12 && n - num14 >= 0; num14++)
						{
							if (B(num11 - num14))
							{
								num12++;
								break;
							}
						}
						for (int num15 = 1; num15 <= 12 && m + num15 < 2048; num15++)
						{
							if (B(num11 + num15 * 2048))
							{
								num12++;
								break;
							}
						}
						for (int num16 = 1; num16 <= 12 && m - num16 >= 0; num16++)
						{
							if (B(num11 - num16 * 2048))
							{
								num12++;
								break;
							}
						}
						if (num12 == 4)
						{
							px[num11] = new Color32(blanc.r, blanc.g, blanc.b, px[num11].a);
						}
					}
				}
			}
			bool B(int num17)
			{
				if (px[num17].r == blanc.r && px[num17].g == blanc.g)
				{
					return px[num17].b == blanc.b;
				}
				return false;
			}
			static bool Fond(Color32 c)
			{
				//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
				return Mathf.Max((int)c.r, Mathf.Max((int)c.g, (int)c.b)) < 14;
			}
			static bool Rouge(Color32 c)
			{
				//IL_0000: 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_0012: 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)
				int num17 = Mathf.Max((int)c.g, (int)c.b);
				if (c.r - num17 >= 25)
				{
					return (float)(int)c.r > 2.2f * (float)num17;
				}
				return false;
			}
		}
	}
	[HarmonyPatch(typeof(EntranceTeleport))]
	internal static class GreenHillsEntrees
	{
		[HarmonyPostfix]
		[HarmonyPatch("TeleportPlayer")]
		private static void ApresTeleportation(EntranceTeleport __instance)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			GreenHillsAmbiance instance = GreenHillsAmbiance.Instance;
			if ((Object)(object)instance == (Object)null || !__instance.isEntranceToBuilding)
			{
				return;
			}
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			if (!((Object)(object)val == (Object)null) && !val.isPlayerDead)
			{
				if (TrouverPointAleatoire(instance, out var pos, out var yaw))
				{
					val.TeleportPlayer(pos, false, 0f, false, true);
					val.thisPlayerBody.eulerAngles = new Vector3(val.thisPlayerBody.eulerAngles.x, yaw, val.thisPlayerBody.eulerAngles.z);
					GreenHillsPlugin.Log.LogInfo((object)$"Arrivée dans Green Hills en {pos}");
				}
				else
				{
					GreenHillsPlugin.Log.LogWarning((object)"Arrivée aléatoire introuvable : le joueur reste au point d'entrée.");
				}
			}
		}

		internal static bool TrouverPointAleatoire(GreenHillsAmbiance monde, out Vector3 pos, out float yaw)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: 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_019b: 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_019f: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: 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_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_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_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			Transform centreDome = monde.centreDome;
			float num = monde.rayonDome - 160f;
			for (int i = 0; i < 200; i++)
			{
				float num2 = Random.value * MathF.PI * 2f;
				float num3 = Mathf.Sqrt(Random.value) * num;
				RaycastHit[] array = Physics.RaycastAll(centreDome.TransformPoint(new Vector3(Mathf.Cos(num2) * num3, monde.hauteurMur - 10f, Mathf.Sin(num2) * num3)), Vector3.down, 700f, -1, (QueryTriggerInteraction)1);
				Array.Sort(array, (RaycastHit x, RaycastHit y) => ((RaycastHit)(ref x)).distance.CompareTo(((RaycastHit)(ref y)).distance));
				RaycastHit val = default(RaycastHit);
				bool flag = false;
				RaycastHit[] array2 = array;
				for (int num4 = 0; num4 < array2.Length; num4++)
				{
					RaycastHit val2 = array2[num4];
					if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && (!((Object)(object)monde.dome != (Object)null) || !((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(((Component)monde.dome).transform)) && !((Object)((RaycastHit)(ref val2)).collider).name.StartsWith("Dome") && ((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(centreDome))
					{
						val = val2;
						flag = true;
						break;
					}
				}
				if (flag && ((Object)((RaycastHit)(ref val)).collider).name.StartsWith("Terrain") && (i >= 150 || !(Vector3.Dot(((RaycastHit)(ref val)).normal, Vector3.up) < 0.8f)))
				{
					Vector3 val3 = ((RaycastHit)(ref val)).point + Vector3.up * 0.3f;
					if (!Physics.CheckCapsule(val3 + Vector3.up * 0.5f, val3 + Vector3.up * 2.2f, 0.6f, StartOfRound.Instance.collidersAndRoomMaskAndDefault & ~(1 << ((Component)((RaycastHit)(ref val)).collider).gameObject.layer), (QueryTriggerInteraction)1))
					{
						pos = val3;
						yaw = Random.value * 360f;
						return true;
					}
				}
			}
			pos = Vector3.zero;
			yaw = 0f;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("TeleportPlayer")]
		private static void AvantSortieLocale(out Vector3? __state)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			__state = (((Object)(object)val != (Object)null) ? new Vector3?(((Component)val).transform.position) : ((Vector3?)null));
		}

		[HarmonyPostfix]
		[HarmonyPatch("TeleportPlayer")]
		private static void ApresSortieLocale(EntranceTeleport __instance, Vector3? __state)
		{
			SiSortieDeSecours(__instance, __state);
		}

		[HarmonyPrefix]
		[HarmonyPatch("TeleportPlayerClientRpc")]
		private static void AvantSortieAnnoncee(int playerObj, out Vector3? __state)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			__state = (((Object)(object)instance != (Object)null && instance.allPlayerScripts != null && playerObj >= 0 && playerObj < instance.allPlayerScripts.Length && (Object)(object)instance.allPlayerScripts[playerObj] != (Object)null) ? new Vector3?(((Component)instance.allPlayerScripts[playerObj]).transform.position) : ((Vector3?)null));
		}

		[HarmonyPostfix]
		[HarmonyPatch("TeleportPlayerClientRpc")]
		private static void ApresSortieAnnoncee(EntranceTeleport __instance, Vector3? __state)
		{
			SiSortieDeSecours(__instance, __state);
		}

		private static void SiSortieDeSecours(EntranceTeleport e, Vector3? avant)
		{
			//IL_0036: 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)
			GreenHillsAmbiance instance = GreenHillsAmbiance.Instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)e == (Object)null) && !e.isEntranceToBuilding && !((Object)(object)instance.centreDome == (Object)null) && instance.EstDansLeDome(((Component)e).transform.position))
			{
				if (avant.HasValue && !instance.EstDansLeDome(avant.Value))
				{
					avant = null;
				}
				instance.SortieUtilisee(e, avant);
			}
		}
	}
	public class GreenHillsExtras : MonoBehaviour
	{
		public Transform hautParleurs;

		public GreenHillsAmbiance ambiance;

		private Volume filtre;

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

		private AudioSource[] sources = (AudioSource[])(object)new AudioSource[0];

		private bool dedansPrecedent;

		private bool musiqueActive;

		private int morceauJoue = -1;

		private bool effetsPoses;

		private static readonly List<AudioClip> musiques = new List<AudioClip>();

		private static bool chargementLance;

		private static readonly List<AudioClip> fonds = new List<AudioClip>();

		private AudioSource fond;

		private float fondVolume;

		private static readonly FieldRef<StormyWeather, GrabbableObject> objetCharge = AccessTools.FieldRefAccess<StormyWeather, GrabbableObject>("setStaticGrabbableObject");

		private StormyWeather orage;

		private float prochainOrage;

		private readonly List<AudioSource> sonsCoupes = new List<AudioSource>();

		private float prochainScanLune;

		private int sonsCoupesSignales;

		private readonly HashSet<Renderer> decorCache = new HashSet<Renderer>();

		private readonly List<Terrain> terrainsCaches = new List<Terrain>();

		private float prochainScanDecor;

		private float prochaineRecherche;

		private void Awake()
		{
			if ((Object)(object)hautParleurs != (Object)null)
			{
				sources = ((Component)hautParleurs).GetComponentsInChildren<AudioSource>(true);
			}
			((Component)this).gameObject.AddComponent<GreenHillsMasked>().ambiance = ambiance;
			((Component)this).gameObject.AddComponent<GreenHillsPortes>().ambiance = ambiance;
			if (!chargementLance)
			{
				chargementLance = true;
				((MonoBehaviour)this).StartCoroutine(ChargerMusiques());
				((MonoBehaviour)this).StartCoroutine(ChargerFonds());
			}
		}

		private void OnDestroy()
		{
			Appliquer(actif: false);
		}

		private void LateUpdate()
		{
			bool flag = (Object)(object)ambiance != (Object)null && ambiance.JoueurDedans;
			if (flag != dedansPrecedent)
			{
				Appliquer(flag);
				dedansPrecedent = flag;
			}
			if (!flag)
			{
				return;
			}
			if ((Object)(object)filtre != (Object)null)
			{
				filtre.weight = ((GreenHillsPlugin.IntensiteFiltre != null) ? Mathf.Clamp01(GreenHillsPlugin.IntensiteFiltre.Value) : 1f);
			}
			CacherSoleil();
			CouperGresillement();
			CouperSonsDeLaLune();
			CacherDecorDeLaLune();
			float num = ((GreenHillsPlugin.SilenceAvantNuit != null) ? GreenHillsPlugin.SilenceAvantNuit.Value : 10f);
			bool flag2 = !ambiance.EstNuit && ambiance.PleinJour && ambiance.SecondesAvantNuit() > num && musiques.Count > 0 && (GreenHillsPlugin.ActiverMusique == null || GreenHillsPlugin.ActiverMusique.Value);
			if (flag2 != musiqueActive)
			{
				if (!flag2)
				{
					Musique(jouer: false);
				}
				musiqueActive = flag2;
				morceauJoue = -1;
			}
			if (flag2)
			{
				SuivreProgramme();
			}
			FondSonore(!ambiance.EstNuit && ambiance.PleinJour && ambiance.SecondesAvantNuit() > num);
		}

		private void Appliquer(bool actif)
		{
			//IL_0033: 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)
			//IL_0044: Expected O, but got Unknown
			if (actif && (Object)(object)filtre == (Object)null && (GreenHillsPlugin.Filtre == null || GreenHillsPlugin.Filtre.Value != "None"))
			{
				GameObject val = new GameObject("GreenHills_Filtre")
				{
					layer = GreenHillsAmbiance.CalqueVolume()
				};
				filtre = val.AddComponent<Volume>();
				filtre.isGlobal = true;
				filtre.priority = 1001f;
				filtre.sharedProfile = ProfilEblouissant();
			}
			else if (!actif && (Object)(object)filtre != (Object)null)
			{
				Object.Destroy((Object)(object)filtre.sharedProfile);
				Object.Destroy((Object)(object)((Component)filtre).gameObject);
				filtre = null;
			}
			if (!actif)
			{
				foreach (Renderer soleilsCache in soleilsCaches)
				{
					if ((Object)(object)soleilsCache != (Object)null)
					{
						soleilsCache.enabled = true;
					}
				}
				soleilsCaches.Clear();
			}
			if (!actif)
			{
				Musique(jouer: false);
				musiqueActive = false;
				morceauJoue = -1;
				if ((Object)(object)fond != (Object)null)
				{
					fond.Stop();
					fondVolume = 0f;
				}
				RendreSonsDeLaLune();
				RendreDecorDeLaLune();
			}
		}

		private void CouperGresillement()
		{
			if ((Object)(object)orage == (Object)null && Time.time >= prochainOrage)
			{
				prochainOrage = Time.time + 5f;
				orage = Object.FindObjectOfType<StormyWeather>();
			}
			if ((Object)(object)orage == (Object)null || (Object)(object)orage.staticElectricityParticle == (Object)null)
			{
				return;
			}
			GrabbableObject val = objetCharge.Invoke(orage);
			if (!((Object)(object)val == (Object)null) && val.isInFactory)
			{
				AudioSource component = ((Component)orage.staticElectricityParticle).GetComponent<AudioSource>();
				if ((Object)(object)component != (Object)null && component.isPlaying)
				{
					component.Stop();
				}
			}
		}

		private void CouperSonsDeLaLune()
		{
			//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)
			if (Time.time < prochainScanLune)
			{
				return;
			}
			prochainScanLune = Time.time + 2f;
			SelectableLevel val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.currentLevel : null);
			if ((Object)(object)val == (Object)null || string.IsNullOrEmpty(val.sceneName))
			{
				return;
			}
			Scene sceneByName = SceneManager.GetSceneByName(val.sceneName);
			if (!((Scene)(ref sceneByName)).IsValid() || !((Scene)(ref sceneByName)).isLoaded)
			{
				return;
			}
			Transform props = (((Object)(object)RoundManager.Instance != (Object)null && (Object)(object)RoundManager.Instance.mapPropsContainer != (Object)null) ? RoundManager.Instance.mapPropsContainer.transform : null);
			GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
			for (int i = 0; i < rootGameObjects.Length; i++)
			{
				AudioSource[] componentsInChildren = rootGameObjects[i].GetComponentsInChildren<AudioSource>(true);
				foreach (AudioSource val2 in componentsInChildren)
				{
					if (!((Object)(object)val2 == (Object)null) && !val2.mute && !sonsCoupes.Contains(val2) && !DeGreenHills(((Component)val2).transform, props) && !((Object)(object)((Component)val2).GetComponentInParent<EnemyAI>() != (Object)null) && !((Object)(object)((Component)val2).GetComponentInParent<GrabbableObject>() != (Object)null) && !((Object)(object)((Component)val2).GetComponentInParent<PlayerControllerB>() != (Object)null))
					{
						val2.mute = true;
						sonsCoupes.Add(val2);
					}
				}
			}
			if (sonsCoupes.Count != sonsCoupesSignales)
			{
				sonsCoupesSignales = sonsCoupes.Count;
				GreenHillsPlugin.Log.LogInfo((object)$"[Sons de la lune] {sonsCoupes.Count} son(s) de {val.sceneName} coupé(s) dans Green Hills.");
			}
		}

		private void CacherDecorDeLaLune()
		{
			//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)
			if (Time.time < prochainScanDecor)
			{
				return;
			}
			prochainScanDecor = Time.time + 2f;
			SelectableLevel val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.currentLevel : null);
			if ((Object)(object)val == (Object)null || string.IsNullOrEmpty(val.sceneName))
			{
				return;
			}
			Scene sceneByName = SceneManager.GetSceneByName(val.sceneName);
			if (!((Scene)(ref sceneByName)).IsValid() || !((Scene)(ref sceneByName)).isLoaded)
			{
				return;
			}
			Transform props = (((Object)(object)RoundManager.Instance != (Object)null && (Object)(object)RoundManager.Instance.mapPropsContainer != (Object)null) ? RoundManager.Instance.mapPropsContainer.transform : null);
			int count = decorCache.Count;
			GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
			foreach (GameObject val2 in rootGameObjects)
			{
				Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val3 in componentsInChildren)
				{
					if ((Object)(object)val3 == (Object)null || !val3.enabled)
					{
						continue;
					}
					if (!decorCache.Contains(val3))
					{
						if (DeGreenHills(((Component)val3).transform, props) || (Object)(object)((Component)val3).GetComponentInParent<EnemyAI>() != (Object)null || (Object)(object)((Component)val3).GetComponentInParent<GrabbableObject>() != (Object)null || (Object)(object)((Component)val3).GetComponentInParent<PlayerControllerB>() != (Object)null || (Object)(object)((Component)val3).GetComponentInParent<VehicleController>() != (Object)null)
						{
							continue;
						}
						decorCache.Add(val3);
					}
					val3.enabled = false;
				}
				Terrain[] componentsInChildren2 = val2.GetComponentsInChildren<Terrain>(true);
				foreach (Terrain val4 in componentsInChildren2)
				{
					if ((Object)(object)val4 != (Object)null && val4.drawHeightmap && !DeGreenHills(((Component)val4).transform, props))
					{
						val4.drawHeightmap = false;
						val4.drawTreesAndFoliage = false;
						terrainsCaches.Add(val4);
					}
				}
			}
			if (decorCache.Count != count)
			{
				GreenHillsPlugin.Log.LogInfo((object)$"[Décor de la lune] {decorCache.Count} objet(s) et {terrainsCaches.Count} terrain(s) de {val.sceneName} masqués dans Green Hills.");
			}
		}

		private void RendreDecorDeLaLune()
		{
			foreach (Renderer item in decorCache)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.enabled = true;
				}
			}
			decorCache.Clear();
			foreach (Terrain terrainsCache in terrainsCaches)
			{
				if ((Object)(object)terrainsCache != (Object)null)
				{
					terrainsCache.drawHeightmap = true;
					terrainsCache.drawTreesAndFoliage = true;
				}
			}
			terrainsCaches.Clear();
			prochainScanDecor = 0f;
		}

		private static bool DeGreenHills(Transform t, Transform props)
		{
			Transform val = t;
			while ((Object)(object)val != (Object)null)
			{
				if ((Object)(object)val == (Object)(object)props || ((Object)val).name.StartsWith("GH_") || ((Object)val).name.StartsWith("GreenHills_"))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		private void RendreSonsDeLaLune()
		{
			foreach (AudioSource sonsCoupe in sonsCoupes)
			{
				if ((Object)(object)sonsCoupe != (Object)null)
				{
					sonsCoupe.mute = false;
				}
			}
			sonsCoupes.Clear();
			prochainScanLune = 0f;
			sonsCoupesSignales = 0;
		}

		private void CacherSoleil()
		{
			if (Time.time >= prochaineRecherche)
			{
				prochaineRecherche = Time.time + 15f;
				TimeOfDay instance = TimeOfDay.Instance;
				List<Renderer> list = new List<Renderer>();
				if ((Object)(object)instance != (Object)null && (Object)(object)instance.sunAnimator != (Object)null)
				{
					list.AddRange(((Component)instance.sunAnimator).GetComponentsInChildren<Renderer>(true));
				}
				Renderer[] array = Object.FindObjectsOfType<Renderer>();
				foreach (Renderer val in array)
				{
					if ((Object)(object)val != (Object)null && (((Object)val).name.StartsWith("SunTexture") || ((Object)val).name == "Sun" || ((Object)val).name.StartsWith("Moon")))
					{
						list.Add(val);
					}
				}
				foreach (Renderer item in list)
				{
					if ((Object)(object)item != (Object)null && !soleilsCaches.Contains(item))
					{
						soleilsCaches.Add(item);
					}
				}
			}
			foreach (Renderer soleilsCache in soleilsCaches)
			{
				if ((Object)(object)soleilsCache != (Object)null && soleilsCache.enabled)
				{
					soleilsCache.enabled = false;
				}
			}
		}

		private static VolumeProfile ProfilEblouissant()
		{
			//IL_0091: 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)
			VolumeProfile obj = ScriptableObject.CreateInstance<VolumeProfile>();
			ColorAdjustments obj2 = obj.Add<ColorAdjustments>(true);
			((VolumeParameter<float>)(object)obj2.postExposure).Override(0.45f);
			((VolumeParameter<float>)(object)obj2.contrast).Override(-22f);
			((VolumeParameter<float>)(object)obj2.saturation).Override(-15f);
			Bloom obj3 = obj.Add<Bloom>(true);
			((VolumeParameter<float>)(object)obj3.intensity).Override(0.7f);
			((VolumeParameter<float>)(object)obj3.threshold).Override(0.6f);
			((VolumeParameter<float>)(object)obj3.scatter).Override(0.85f);
			((VolumeParameter<Vector4>)(object)obj.Add<LiftGammaGain>(true).lift).Override(new Vector4(1f, 1f, 1f, 0.07f));
			Vignette obj4 = obj.Add<Vignette>(true);
			((VolumeParameter<float>)(object)obj4.intensity).Override(0.25f);
			((VolumeParameter<Color>)(object)obj4.color).Override(Color.white);
			((VolumeParameter<float>)(object)obj4.smoothness).Override(0.8f);
			return obj;
		}

		private void Musique(bool jouer)
		{
			if (jouer)
			{
				return;
			}
			AudioSource[] array = sources;
			foreach (AudioSource val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.Stop();
				}
			}
		}

		private void SuivreProgramme()
		{
			PoserEffets();
			if (!ambiance.PeriodeEnCours(out var _, out var ecoule))
			{
				return;
			}
			float num = Vitesse();
			int num2 = new Random(((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.randomMapSeed : 0).Next(musiques.Count);
			AudioClip val = musiques[num2];
			float volume = ((GreenHillsPlugin.VolumeMusique != null) ? GreenHillsPlugin.VolumeMusique.Value : 0.6f);
			AudioSource[] array = sources;
			foreach (AudioSource val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					val2.volume = volume;
					val2.pitch = num;
					val2.loop = true;
					if ((Object)(object)val2.clip != (Object)(object)val || !val2.isPlaying)
					{
						val2.clip = val;
						val2.time = Mathf.Repeat(ecoule * num, Mathf.Max(0.1f, val.length - 0.1f));
						val2.Play();
					}
				}
			}
			if (num2 != morceauJoue)
			{
				morceauJoue = num2;
				GreenHillsPlugin.Log.LogInfo((object)("Musique du jour : " + ((Object)val).name));
			}
		}

		private static float Vitesse()
		{
			if (GreenHillsPlugin.EffetLiminal != null && !GreenHillsPlugin.EffetLiminal.Value)
			{
				return 1f;
			}
			return Mathf.Clamp((GreenHillsPlugin.VitesseMusique != null) ? GreenHillsPlugin.VitesseMusique.Value : 0.92f, 0.5f, 1.5f);
		}

		private void PoserEffets()
		{
			if (effetsPoses)
			{
				return;
			}
			effetsPoses = true;
			bool flag = GreenHillsPlugin.EffetLiminal == null || GreenHillsPlugin.EffetLiminal.Value;
			float num = Mathf.Clamp01((GreenHillsPlugin.Echo != null) ? GreenHillsPlugin.Echo.Value : 0.6f);
			AudioSource[] array = sources;
			foreach (AudioSource val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				AudioReverbFilter val2 = ((Component)val).GetComponent<AudioReverbFilter>();
				if (!flag || num <= 0f)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						((Behaviour)val2).enabled = false;
					}
					continue;
				}
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = ((Component)val).gameObject.AddComponent<AudioReverbFilter>();
				}
				((Behaviour)val2).enabled = true;
				val2.reverbPreset = (AudioReverbPreset)27;
				val2.dryLevel = Mathf.Lerp(0f, -600f, num);
				val2.room = Mathf.Lerp(-2500f, 0f, num);
				val2.roomHF = -1200f;
				val2.decayTime = Mathf.Lerp(1.5f, 6f, num);
				val2.decayHFRatio = 0.6f;
				val2.reflectionsLevel = -800f;
				val2.reflectionsDelay = 0.04f;
				val2.reverbLevel = Mathf.Lerp(-600f, 300f, num);
				val2.reverbDelay = 0.06f;
				val2.diffusion = 100f;
				val2.density = 100f;
				AudioLowPassFilter component = ((Component)val).GetComponent<AudioLowPassFilter>();
				if ((Object)(object)component != (Object)null)
				{
					component.cutoffFrequency = Mathf.Min(component.cutoffFrequency, 3200f);
				}
			}
		}

		private void FondSonore(bool jouer)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if (fonds.Count == 0)
			{
				return;
			}
			if ((Object)(object)fond == (Object)null)
			{
				GameObject val = new GameObject("GreenHills_FondSonore");
				val.transform.SetParent(((Component)this).transform, false);
				fond = val.AddComponent<AudioSource>();
				fond.spatialBlend = 0f;
				fond.loop = true;
				fond.playOnAwake = false;
				fond.dopplerLevel = 0f;
				fond.priority = 64;
				AudioSource[] array = sources;
				foreach (AudioSource val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && (Object)(object)val2.outputAudioMixerGroup != (Object)null)
					{
						fond.outputAudioMixerGroup = val2.outputAudioMixerGroup;
						break;
					}
				}
			}
			float num = (jouer ? Mathf.Clamp01((GreenHillsPlugin.VolumeFond != null) ? GreenHillsPlugin.VolumeFond.Value : 0.35f) : 0f);
			fondVolume = Mathf.MoveTowards(fondVolume, num, Time.deltaTime / 2f);
			fond.volume = fondVolume;
			if (fondVolume > 0f && !fond.isPlaying)
			{
				int num2 = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.randomMapSeed : 0);
				AudioClip val3 = fonds[new Random(num2 + 7).Next(fonds.Count)];
				fond.clip = val3;
				fond.time = Random.Range(0f, Mathf.Max(0f, val3.length - 1f));
				fond.Play();
				GreenHillsPlugin.Log.LogInfo((object)("Fond sonore : " + ((Object)val3).name));
			}
			else if (fondVolume <= 0f && fond.isPlaying)
			{
				fond.Stop();
			}
		}

		private static string[] FichiersAudio(string nom)
		{
			List<string> list = new List<string>();
			string path = Path.Combine(GreenHillsPlugin.Dossier, nom);
			if (Directory.Exists(path))
			{
				list.AddRange(Directory.GetFiles(path));
			}
			else
			{
				try
				{
					Directory.CreateDirectory(path);
				}
				catch
				{
				}
			}
			string[] files = Directory.GetFiles(GreenHillsPlugin.Dossier, "*", SearchOption.AllDirectories);
			foreach (string text in files)
			{
				if (Path.GetFileName(text).StartsWith(nom + "_", StringComparison.OrdinalIgnoreCase) && !list.Contains(text))
				{
					list.Add(text);
				}
			}
			list.Sort((string a, string b) => string.Compare(Path.GetFileName(a), Path.GetFileName(b), StringComparison.OrdinalIgnoreCase));
			return list.ToArray();
		}

		private static IEnumerator ChargerFonds()
		{
			string[] array = FichiersAudio("Ambiance");
			if (array.Length == 0)
			{
				GreenHillsPlugin.Log.LogWarning((object)"Aucun fond sonore trouvé (dossier Ambiance vide, ni fichier « Ambiance_… »).");
			}
			string[] array2 = array;
			foreach (string f in array2)
			{
				AudioType val = (AudioType)(Path.GetExtension(f).ToLowerInvariant() switch
				{
					".mp3" => 13, 
					".wav" => 20, 
					".ogg" => 14, 
					_ => 0, 
				});
				if ((int)val == 0)
				{
					continue;
				}
				UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip("file:///" + f.Replace('\\', '/'), val);
				try
				{
					yield return req.SendWebRequest();
					if ((int)req.result != 1)
					{
						GreenHillsPlugin.Log.LogWarning((object)("Fond sonore illisible : " + f));
						continue;
					}
					AudioClip content = DownloadHandlerAudioClip.GetContent(req);
					((Object)content).name = Path.GetFileNameWithoutExtension(f);
					fonds.Add(content);
					GreenHillsPlugin.Log.LogInfo((object)("Fond sonore chargé : " + ((Object)content).name));
				}
				finally
				{
					((IDisposable)req)?.Dispose();
				}
			}
		}

		private static IEnumerator ChargerMusiques()
		{
			string[] array = FichiersAudio("Musique");
			if (array.Length == 0)
			{
				GreenHillsPlugin.Log.LogWarning((object)"Aucune musique trouvée (dossier Musique vide, ni fichier « Musique_… »).");
			}
			string[] array2 = array;
			foreach (string f in array2)
			{
				AudioType val = (AudioType)(Path.GetExtension(f).ToLowerInvariant() switch
				{
					".mp3" => 13, 
					".wav" => 20, 
					".ogg" => 14, 
					_ => 0, 
				});
				if ((int)val == 0)
				{
					continue;
				}
				UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip("file:///" + f.Replace('\\', '/'), val);
				try
				{
					yield return req.SendWebRequest();
					if ((int)req.result != 1)
					{
						GreenHillsPlugin.Log.LogWarning((object)("Musique illisible : " + f));
						continue;
					}
					AudioClip content = DownloadHandlerAudioClip.GetContent(req);
					((Object)content).name = Path.GetFileNameWithoutExtension(f);
					musiques.Add(content);
					GreenHillsPlugin.Log.LogInfo((object)("Musique chargée : " + ((Object)content).name));
				}
				finally
				{
					((IDisposable)req)?.Dispose();
				}
			}
		}
	}
	[HarmonyPatch(typeof(ExtendedDungeonConfig), "BindConfigs")]
	internal static class GreenHillsLLL
	{
		private static readonly (string tag, int poids)[] ParDefaut = new(string, int)[2]
		{
			("Custom", 100),
			("Vanilla", 100)
		};

		[HarmonyPrefix]
		private static void Avant(ExtendedDungeonFlow extendedDungeonFlow)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			if ((Object)(object)extendedDungeonFlow == (Object)null || extendedDungeonFlow.DungeonName != "Green Hills")
			{
				return;
			}
			LevelMatchingProperties levelMatchingProperties = extendedDungeonFlow.LevelMatchingProperties;
			if (!((Object)(object)levelMatchingProperties == (Object)null) && levelMatchingProperties.levelTags.Count <= 0)
			{
				(string, int)[] parDefaut = ParDefaut;
				for (int i = 0; i < parDefaut.Length; i++)
				{
					var (text, num) = parDefaut[i];
					levelMatchingProperties.levelTags.Add(new StringWithRarity(text, num));
				}
				GreenHillsPlugin.Log.LogInfo((object)("Apparition par défaut : " + string.Join(",", ParDefaut.Select(((string tag, int poids) d) => d.tag + ":" + d.poids)) + " (réglable dans LethalLevelLoader.cfg, section « Custom Dungeon: Green Hills »)."));
			}
		}
	}
	public class GreenHillsMasked : MonoBehaviour
	{
		[HarmonyPatch(typeof(MaskedPlayerEnemy))]
		private static class Patchs
		{
			[HarmonyPrefix]
			[HarmonyPatch("DoAIInterval")]
			private static bool AvantIA(MaskedPlayerEnemy __instance)
			{
				return !Fige(__instance);
			}

			[HarmonyPrefix]
			[HarmonyPatch("OnCollideWithPlayer")]
			private static bool AvantContact(MaskedPlayerEnemy __instance)
			{
				return !Fige(__instance);
			}

			[HarmonyPostfix]
			[HarmonyPatch("Update")]
			private static void ApresUpdate(MaskedPlayerEnemy __instance)
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				NavMeshAgent agent = ((EnemyAI)__instance).agent;
				if (Fige(__instance))
				{
					if ((Object)(object)agent != (Object)null && agent.isOnNavMesh)
					{
						agent.isStopped = true;
						agent.velocity = Vector3.zero;
					}
					figes.Add(__instance);
				}
				else if (figes.Remove(__instance) && (Object)(object)agent != (Object)null && agent.isOnNavMesh)
				{
					agent.isStopped = false;
				}
			}
		}

		public GreenHillsAmbiance ambiance;

		private static EnemyType typeMasked;

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

		private int apparus;

		private bool prepare;

		private static readonly HashSet<MaskedPlayerEnemy> figes = new HashSet<MaskedPlayerEnemy>();

		private void Update()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer || (Object)(object)ambiance == (Object)null || (Object)(object)ambiance.centreDome == (Object)null)
			{
				return;
			}
			RoundManager instance = RoundManager.Instance;
			TimeOfDay instance2 = TimeOfDay.Instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance2 == (Object)null) && instance.dungeonCompletedGenerating && instance2.currentDayTimeStarted)
			{
				if (!prepare)
				{
					Preparer(instance2);
				}
				if (apparus < heures.Count && !(instance2.normalizedTimeOfDay < heures[apparus]))
				{
					apparus++;
					Apparaitre(instance);
				}
			}
		}

		private void Preparer(TimeOfDay tod)
		{
			prepare = true;
			int num = ((GreenHillsPlugin.NombreMasked != null) ? Mathf.Clamp(GreenHillsPlugin.NombreMasked.Value, 0, 10) : 2);
			Random random = new Random((((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.randomMapSeed : 0) + 4241);
			float num2 = Mathf.Max(0.03f, tod.normalizedTimeOfDay + 0.01f);
			for (int i = 0; i < num; i++)
			{
				heures.Add(Mathf.Lerp(num2, 0.85f, (float)random.NextDouble()));
			}
			heures.Sort();
			GreenHillsPlugin.Log.LogInfo((object)string.Format("[Masked] {0} prévu(s) (moments de la journée : {1}).", num, string.Join(", ", heures.Select((float h) => h.ToString("0.00")))));
		}

		private static EnemyType TrouverMasked()
		{
			if ((Object)(object)typeMasked != (Object)null)
			{
				return typeMasked;
			}
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || instance.levels == null)
			{
				return null;
			}
			SelectableLevel[] levels = instance.levels;
			foreach (SelectableLevel val in levels)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				List<SpawnableEnemyWithRarity>[] array = new List<SpawnableEnemyWithRarity>[3] { val.Enemies, val.OutsideEnemies, val.DaytimeEnemies };
				foreach (List<SpawnableEnemyWithRarity> list in array)
				{
					if (list == null)
					{
						continue;
					}
					foreach (SpawnableEnemyWithRarity item in list)
					{
						if (item != null && (Object)(object)item.enemyType != (Object)null && (Object)(object)item.enemyType.enemyPrefab != (Object)null && (Object)(object)item.enemyType.enemyPrefab.GetComponent<MaskedPlayerEnemy>() != (Object)null)
						{
							return typeMasked = item.enemyType;
						}
					}
				}
			}
			return null;
		}

		private void Apparaitre(RoundManager rm)
		{
			//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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: 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_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_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: 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_0250: Unknown result type (might be due to invalid IL or missing references)
			EnemyType val = TrouverMasked();
			if ((Object)(object)val == (Object)null)
			{
				GreenHillsPlugin.Log.LogWarning((object)"[Masked] type de monstre « Masked » introuvable : aucun Masked.");
				return;
			}
			Random random = new Random((((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.randomMapSeed : 0) + 977 * apparus);
			Transform centreDome = ambiance.centreDome;
			List<Transform> list = (from t in ((Component)centreDome).GetComponentsInChildren<Transform>()
				where ((Object)t).name.StartsWith("Maison_") && (Object)(object)t.Find("Corps") != (Object)null
				select t).ToList();
			NavMeshHit val4 = default(NavMeshHit);
			for (int num = 0; num < 30; num++)
			{
				bool flag = list.Count > 0 && random.NextDouble() < 0.5;
				Vector3 val2;
				if (flag)
				{
					val2 = list[random.Next(list.Count)].position + Vector3.up * 1.2f;
				}
				else
				{
					float num2 = (float)(random.NextDouble() * 3.1415927410125732 * 2.0);
					float num3 = ambiance.rayonDome * 0.75f * Mathf.Sqrt((float)random.NextDouble());
					List<RaycastHit> list2 = (from h in Physics.RaycastAll(centreDome.TransformPoint(new Vector3(Mathf.Cos(num2) * num3, 400f, Mathf.Sin(num2) * num3)), Vector3.down, 1200f, -1, (QueryTriggerInteraction)1)
						where ((Object)((RaycastHit)(ref h)).collider).name.StartsWith("Terrain")
						orderby ((RaycastHit)(ref h)).distance
						select h).ToList();
					if (list2.Count == 0)
					{
						continue;
					}
					RaycastHit val3 = list2[0];
					val2 = ((RaycastHit)(ref val3)).point;
				}
				if (NavMesh.SamplePosition(val2, ref val4, flag ? 5f : 10f, -1))
				{
					rm.SpawnEnemyGameObject(((NavMeshHit)(ref val4)).position, (float)random.NextDouble() * 360f, -1, val);
					GreenHillsPlugin.Log.LogInfo((object)string.Format("[Masked] apparu {0} en ({1:0}, {2:0}, {3:0}).", flag ? "dans une maison" : "sur les collines", ((NavMeshHit)(ref val4)).position.x, ((NavMeshHit)(ref val4)).position.y, ((NavMeshHit)(ref val4)).position.z));
					return;
				}
			}
			GreenHillsPlugin.Log.LogWarning((object)"[Masked] aucun emplacement trouvé sur le NavMesh.");
		}

		internal static bool Fige(MaskedPlayerEnemy m)
		{
			GreenHillsAmbiance instance = GreenHillsAmbiance.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)m != (Object)null && !((EnemyAI)m).isEnemyDead && !((EnemyAI)m).isOutside)
			{
				return instance.EstLaNuit();
			}
			return false;
		}
	}
	public class GreenHillsMonstres : MonoBehaviour
	{
		private class Maison
		{
			public Transform t;

			public AnimatedObjectTrigger porte;

			public Transform battant;

			public Vector3 battantPos;
		}

		private class Sourire
		{
			public PlayerControllerB cible;

			public GameObject go;

			public Light lumiere;

			public Vector3 pos;

			public float ne;

			public float echelle;

			public float apparition;

			public float disparition = -1f;

			public float reduc = 1f;

			public bool aLaPorte;

			public Maison maison;

			public Maison entre;

			public AudioSource souffle;

			public AudioSource murmures;

			public AudioSource coups;

			public AudioSource choc;

			public int dernierePoussee = -1;
		}

		private struct Filtre
		{
			public float bas;

			public float bande;

			public float Pas(float x, float fc, float q)
			{
				float num = 2f * Mathf.Sin(MathF.PI * Mathf.Min(fc, 8000f) / 44100f);
				bas += num * bande;
				float num2 = x - bas - q * bande;
				bande += num * num2;
				return bande;
			}
		}

		public GreenHillsAmbiance ambia