Decompiled source of CelestialMapRevamp v1.0.0

CelestialMapRevamp.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.Rendering;
using UnityStandardAssets.ImageEffects;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 CelestialMapRevamp
{
	[BepInPlugin("fr.dsp.celestialmaprevamp", "CelestialMapRevamp", "1.0.0")]
	public sealed class CelestialMapRevampPlugin : BaseUnityPlugin
	{
		private sealed class PlanetImpostor
		{
			public UIStarmapPlanet ui;

			public PlanetSimulator sim;

			public Camera camera;

			public RenderTexture texture;

			public GameObject cameraRoot;

			public GameObject billboard;

			public Renderer billboardRenderer;

			public Material billboardMaterial;

			public Transform bodyTransform;

			public Transform baseTransform;

			public Transform haloTransform;

			public Material bodyMaterial;

			public Material baseMaterial;

			public float builtBodyFraction;

			public Mesh discMesh;

			public Mesh haloMesh;

			public float schematicMeshRadius;

			public bool schematicWasEnabled;

			public bool failed;
		}

		private sealed class StarVisual
		{
			public UIStarmapStar ui;

			public GameObject root;

			public float contentRadius;

			public Transform simTransform;

			public Material[] materials;

			public Mesh mesh;

			public Transform bodyTransform;
		}

		private struct PartKey : IEquatable<PartKey>
		{
			public Mesh mesh;

			public int submesh;

			public Material material;

			public bool Equals(PartKey other)
			{
				if ((Object)(object)mesh == (Object)(object)other.mesh && submesh == other.submesh)
				{
					return (Object)(object)material == (Object)(object)other.material;
				}
				return false;
			}

			public override bool Equals(object other)
			{
				if (other is PartKey)
				{
					return Equals((PartKey)other);
				}
				return false;
			}

			public override int GetHashCode()
			{
				return ((((((Object)(object)mesh != (Object)null) ? ((Object)mesh).GetInstanceID() : 0) * 397) ^ submesh) * 397) ^ (((Object)(object)material != (Object)null) ? ((Object)material).GetInstanceID() : 0);
			}
		}

		private sealed class RemoteStructures
		{
			public int planetId;

			public Transform simTransform;

			public List<Mesh> meshes = new List<Mesh>();

			public List<Material> materials = new List<Material>();

			public int structureCount;

			public int beltPathCount;

			public int builtEntityCursor;

			public float builtAt;
		}

		private struct DrawEntry
		{
			public PlanetImpostor planet;

			public StarVisual star;

			public float distance;
		}

		public const string PluginGuid = "fr.dsp.celestialmaprevamp";

		public const string PluginName = "CelestialMapRevamp";

		public const string PluginVersion = "1.0.0";

		private const float MinRadius = 1E-05f;

		private const float ImpostorFov = 20f;

		private const float ImpostorFill = 0.86f;

		private const int OpacityPasses = 24;

		private const int BaseQueue = 3200;

		private const int BodyQueue = 3201;

		private static CelestialMapRevampPlugin instance;

		private ConfigEntry<bool> cfgRealPlanets;

		private ConfigEntry<int> cfgImpostorResolution;

		private ConfigEntry<bool> cfgRealStars;

		private ConfigEntry<bool> cfgBackdrop;

		private ConfigEntry<bool> cfgSunShafts;

		private ConfigEntry<bool> cfgRemoteStructures;

		private ConfigEntry<bool> cfgBelts;

		private ConfigEntry<int> cfgMaxStructures;

		private ConfigEntry<int> cfgStructureDetail;

		private ConfigEntry<bool> cfgDiagnostics;

		private const float StarBodyScale = 0.6f;

		private const int BeltStep = 4;

		private const float BeltWidth = 1f;

		private const float SunShaftIntensityScale = 1f;

		private const float SunShaftSizeScale = 4f;

		private readonly Dictionary<int, PlanetImpostor> impostors = new Dictionary<int, PlanetImpostor>();

		private readonly Dictionary<int, StarVisual> starVisuals = new Dictionary<int, StarVisual>();

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

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

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

		private Harmony harmony;

		private GameObject backdrop;

		private float backdropBaseRadius;

		private Shader billboardShader;

		private bool wasActive;

		private int loadedViewStarId;

		private int consecutiveErrors;

		private float errorMuteUntil;

		private int renderFailures;

		private bool impostorsDisabledRuntime;

		private int cachedGameMask;

		private bool hasCachedGameMask;

		private int impostorFrameMask = -1;

		private bool diagnosticsPending;

		private static Shader opaqueShaderCache;

		private static bool opaqueShaderSearched;

		private static Shader additiveShaderCache;

		private static bool additiveShaderSearched;

		private readonly Dictionary<int, RemoteStructures> remoteStructures = new Dictionary<int, RemoteStructures>();

		private readonly Dictionary<int, PartKey[]> modelPartCache = new Dictionary<int, PartKey[]>();

		private float nextStructureBuild;

		private int structureFailures;

		private bool structuresDisabled;

		private Material beltMaterial;

		private PostProcessingProfile impostorProfile;

		private bool impostorProfileSearched;

		private SunShafts mapSunShafts;

		private Camera mapSunShaftsCamera;

		private DepthTextureMode mapSunShaftsSavedDepth;

		private SunShafts gameSunShafts;

		private bool gameSunShaftsSearched;

		private bool sunShaftsWarned;

		private const float ShaftReachMargin = 1.15f;

		private const float ShaftReachMin = 0.04f;

		private static Texture flatFarDepth;

		private readonly List<DrawEntry> drawOrder = new List<DrawEntry>();

		private static readonly Comparison<DrawEntry> FarthestFirst = (DrawEntry a, DrawEntry b) => b.distance.CompareTo(a.distance);

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

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

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

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

		private int overlayReported = -1;

		private CommandBuffer overlayBuffer;

		private bool overlayDisabled;

		private void Awake()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Expected O, but got Unknown
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			cfgRealPlanets = ((BaseUnityPlugin)this).Config.Bind<bool>("Rendering", "RealPlanets", true, "Film every planet with a real in-game camera and show that render in the starmap, instead of the schematic globe: terrain, ocean, clouds, atmosphere and factories. This is the mod's main feature.");
			cfgImpostorResolution = ((BaseUnityPlugin)this).Config.Bind<int>("Rendering", "PlanetResolution", 8192, new ConfigDescription("Maximum render resolution per planet, in pixels. The actual resolution follows the planet's on-screen size, so this is only a ceiling — lower it if the starmap stutters or your VRAM is tight.", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[6] { 256, 512, 1024, 2048, 4096, 8192 }), Array.Empty<object>()));
			cfgRealStars = ((BaseUnityPlugin)this).Config.Bind<bool>("Rendering", "RealStars", true, "Show the real sun surface inside each star's glow. Black holes and neutron stars keep their own visuals.");
			cfgBackdrop = ((BaseUnityPlugin)this).Config.Bind<bool>("Rendering", "Starfield", true, "Show the game's real starfield behind the starmap.");
			cfgSunShafts = ((BaseUnityPlugin)this).Config.Bind<bool>("Rendering", "SunShaftsExperimental", false, "EXPERIMENTAL, off by default. Casts the game's own sun shafts (godrays) from the star across the map. It looks good, but the effect can pick up ghost silhouettes from the game view behind the map — turn it on only if you want to try it.");
			cfgRemoteStructures = ((BaseUnityPlugin)this).Config.Bind<bool>("Structures", "RemoteStructures", true, "Show the buildings of the other planets in the viewed system. The engine can only draw the planet you are standing on, so the mod draws these itself using the game's own meshes and materials. Nobody is teleported and your save is never touched.");
			cfgBelts = ((BaseUnityPlugin)this).Config.Bind<bool>("Structures", "ConveyorBelts", true, "Also draw those planets' conveyor belts, rebuilt from the game's transport paths.");
			cfgMaxStructures = ((BaseUnityPlugin)this).Config.Bind<int>("Structures", "MaxStructuresPerPlanet", 30000, new ConfigDescription("Maximum buildings prepared per planet, 0 for unlimited. Lower this if a large base causes a hitch or heavy memory use when the map opens.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 200000), Array.Empty<object>()));
			cfgStructureDetail = ((BaseUnityPlugin)this).Config.Bind<int>("Structures", "StructureDetail", 1, new ConfigDescription("Building level of detail: 0 is the highest and heaviest, 3 the lightest.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 3), Array.Empty<object>()));
			cfgDiagnostics = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DiagnosticLog", true, "Write a short diagnostic to BepInEx/LogOutput.log each time the starmap opens. Useful when reporting a problem.");
			try
			{
				harmony = new Harmony("fr.dsp.celestialmaprevamp");
				harmony.PatchAll(typeof(CelestialMapRevampPlugin));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Harmony patching failed: " + ex));
			}
			string text = "?";
			try
			{
				text = ((object)GameConfig.gameVersion/*cast due to .constrained prefix*/).ToString();
			}
			catch
			{
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("CelestialMapRevamp 1.0.0 chargé (jeu " + text + ")."));
		}

		private void OnDestroy()
		{
			CleanupAll();
			if (harmony != null)
			{
				try
				{
					harmony.UnpatchSelf();
				}
				catch
				{
				}
			}
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}

		private void LateUpdate()
		{
			UIStarmap starmap = GetStarmap();
			if (!((Object)(object)starmap != (Object)null) || !starmap.isFullOpened || UIStarmap.isChangingToMilkyWay || !((Object)(object)GameMain.universeSimulator != (Object)null))
			{
				if (wasActive)
				{
					CleanupAll();
				}
				wasActive = false;
				Camera main = GameCamera.main;
				if ((Object)(object)main != (Object)null && GameMain.mainPlayer != null && (Object)(object)starmap != (Object)null && main.cullingMask != 0)
				{
					cachedGameMask = main.cullingMask;
					hasCachedGameMask = true;
				}
				return;
			}
			if (!wasActive)
			{
				diagnosticsPending = true;
			}
			wasActive = true;
			try
			{
				int starmapLayer = GetStarmapLayer(starmap);
				if (cfgRealPlanets.Value && !impostorsDisabledRuntime)
				{
					RequestSystemLoading(starmap);
					SyncImpostors(starmap, starmapLayer);
					SyncRemoteStructures();
					RenderAllImpostors(starmap);
				}
				else if (impostors.Count > 0)
				{
					DestroyAllImpostors();
				}
				if (cfgRealStars.Value)
				{
					SyncStars(starmap, starmapLayer);
				}
				else if (starVisuals.Count > 0)
				{
					DestroyAllStarVisuals();
				}
				if (cfgBackdrop.Value)
				{
					SyncBackdrop(starmap, starmapLayer);
				}
				else if ((Object)(object)backdrop != (Object)null)
				{
					Object.Destroy((Object)(object)backdrop);
					backdrop = null;
				}
				SyncMapOverlay(starmap);
				if (cfgSunShafts.Value)
				{
					SyncSunShafts(starmap);
				}
				else if ((Object)(object)mapSunShafts != (Object)null)
				{
					DestroySunShafts();
				}
				if (diagnosticsPending)
				{
					diagnosticsPending = false;
					if (cfgDiagnostics.Value)
					{
						try
						{
							DumpDiagnostics(starmap);
						}
						catch (Exception ex)
						{
							((BaseUnityPlugin)this).Logger.LogWarning((object)("Diagnostic impossible : " + ex.Message));
						}
					}
				}
				consecutiveErrors = 0;
			}
			catch (Exception ex2)
			{
				consecutiveErrors++;
				if (Time.unscaledTime >= errorMuteUntil)
				{
					errorMuteUntil = Time.unscaledTime + 10f;
					((BaseUnityPlugin)this).Logger.LogWarning((object)("CelestialMapRevamp frame error: " + ex2));
				}
				if (consecutiveErrors > 600)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Trop d'erreurs consécutives : CelestialMapRevamp se met en pause et rend la carte d'origine.");
					try
					{
						CleanupAll();
					}
					catch
					{
					}
					((Behaviour)this).enabled = false;
				}
			}
		}

		private static UIStarmap GetStarmap()
		{
			UIRoot val = UIRoot.instance;
			if ((Object)(object)val == (Object)null || (Object)(object)val.uiGame == (Object)null)
			{
				return null;
			}
			return val.uiGame.starmap;
		}

		private static int GetStarmapLayer(UIStarmap starmap)
		{
			if ((Object)(object)starmap.starmapObjectGroup != (Object)null)
			{
				return starmap.starmapObjectGroup.layer;
			}
			UIStarmapPlanet[] planetUIs = starmap.planetUIs;
			if (planetUIs != null)
			{
				for (int i = 0; i < planetUIs.Length; i++)
				{
					if ((Object)(object)planetUIs[i] != (Object)null && (Object)(object)planetUIs[i].planetRenderer != (Object)null)
					{
						return ((Component)planetUIs[i].planetRenderer).gameObject.layer;
					}
				}
			}
			return 0;
		}

		private void RequestSystemLoading(UIStarmap starmap)
		{
			StarData viewStarSystem = starmap.viewStarSystem;
			if (viewStarSystem == null || viewStarSystem.id == loadedViewStarId)
			{
				return;
			}
			loadedViewStarId = viewStarSystem.id;
			try
			{
				PlanetModelingManager.RequestLoadStar(viewStarSystem);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Chargement du terrain des planètes de " + viewStarSystem.displayName + " demandé."));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Chargement du système impossible : " + ex.Message));
			}
		}

		private void SyncImpostors(UIStarmap starmap, int layer)
		{
			seenIds.Clear();
			UIStarmapPlanet[] planetUIs = starmap.planetUIs;
			if (planetUIs != null)
			{
				foreach (UIStarmapPlanet val in planetUIs)
				{
					if ((Object)(object)val == (Object)null || val.planet == null || (Object)(object)val.planetRenderer == (Object)null || !((Component)val).gameObject.activeInHierarchy)
					{
						continue;
					}
					int id = val.planet.id;
					seenIds.Add(id);
					if (impostors.TryGetValue(id, out var value))
					{
						bool flag = !value.failed && (Object)(object)value.sim != (Object)null && Mathf.Abs(value.builtBodyFraction - ComputeBodyFraction(value.sim)) > 0.02f;
						if ((Object)(object)value.ui != (Object)(object)val || flag || (!value.failed && ((Object)(object)value.billboard == (Object)null || (Object)(object)value.camera == (Object)null)))
						{
							DestroyImpostor(value);
							impostors.Remove(id);
							value = null;
						}
					}
					if (value == null)
					{
						value = BuildImpostor(val, layer);
						impostors[id] = value;
					}
					if (!value.failed)
					{
						UpdateImpostorBillboard(value, starmap);
					}
				}
			}
			staleIds.Clear();
			foreach (KeyValuePair<int, PlanetImpostor> impostor in impostors)
			{
				if (!seenIds.Contains(impostor.Key))
				{
					staleIds.Add(impostor.Key);
				}
			}
			for (int j = 0; j < staleIds.Count; j++)
			{
				DestroyImpostor(impostors[staleIds[j]]);
				impostors.Remove(staleIds[j]);
			}
		}

		private Shader FindBillboardShader()
		{
			if ((Object)(object)billboardShader != (Object)null)
			{
				return billboardShader;
			}
			string[] array = new string[4] { "Sprites/Default", "UI/Default", "Unlit/Transparent", "Particles/Alpha Blended" };
			for (int i = 0; i < array.Length; i++)
			{
				Shader val = Shader.Find(array[i]);
				if ((Object)(object)val != (Object)null)
				{
					billboardShader = val;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Shader d'affichage des planètes : " + array[i]));
					return val;
				}
			}
			return null;
		}

		private PlanetImpostor BuildImpostor(UIStarmapPlanet ui, int layer)
		{
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Expected O, but got Unknown
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Expected O, but got Unknown
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Expected O, but got Unknown
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Expected O, but got Unknown
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			//IL_0562: Unknown result type (might be due to invalid IL or missing references)
			//IL_0569: Expected O, but got Unknown
			//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c9: Expected O, but got Unknown
			//IL_05ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0621: Unknown result type (might be due to invalid IL or missing references)
			PlanetImpostor planetImpostor = new PlanetImpostor();
			planetImpostor.ui = ui;
			try
			{
				PlanetSimulator val = GameMain.universeSimulator.FindPlanetSimulator(ui.planet);
				if ((Object)(object)val == (Object)null)
				{
					WarnOnce(ui.planet.id, "aucun simulateur pour " + ui.planet.displayName);
					planetImpostor.failed = true;
					return planetImpostor;
				}
				Shader val2 = FindBillboardShader();
				if ((Object)(object)val2 == (Object)null)
				{
					WarnOnce(ui.planet.id, "aucun shader d'affichage disponible");
					planetImpostor.failed = true;
					return planetImpostor;
				}
				float schematicMeshRadius = 0.5f;
				MeshFilter component = ((Component)ui.planetRenderer).GetComponent<MeshFilter>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
				{
					Bounds bounds = component.sharedMesh.bounds;
					Vector3 extents = ((Bounds)(ref bounds)).extents;
					schematicMeshRadius = Mathf.Max(1E-05f, Mathf.Max(extents.x, Mathf.Max(extents.y, extents.z)));
				}
				planetImpostor.schematicMeshRadius = schematicMeshRadius;
				RenderTexture val3 = new RenderTexture(512, 512, 24, (RenderTextureFormat)0);
				((Object)val3).name = "CelestialMapRevamp RT " + ui.planet.id;
				val3.antiAliasing = 4;
				val3.Create();
				planetImpostor.texture = val3;
				GameObject val4 = new GameObject("CelestialMapRevamp Cam " + ui.planet.id);
				val4.SetActive(false);
				Camera val5 = val4.AddComponent<Camera>();
				((Behaviour)val5).enabled = false;
				val5.targetTexture = val3;
				val5.fieldOfView = 20f;
				val5.aspect = 1f;
				val5.clearFlags = (CameraClearFlags)2;
				val5.backgroundColor = new Color(0f, 0f, 0f, 0f);
				val5.allowHDR = false;
				val5.allowMSAA = true;
				val5.useOcclusionCulling = false;
				Camera main = GameCamera.main;
				if ((Object)(object)main != (Object)null)
				{
					val5.cullingMask = main.cullingMask & ~(1 << layer) & -33;
					val5.depthTextureMode = main.depthTextureMode;
					val5.renderingPath = main.renderingPath;
				}
				else
				{
					val5.cullingMask = ~((1 << layer) | 0x20);
				}
				try
				{
					PostProcessingProfile val6 = GetImpostorProfile();
					if ((Object)(object)val6 != (Object)null)
					{
						val4.AddComponent<PostProcessingBehaviour>().profile = val6;
					}
				}
				catch (Exception ex)
				{
					WarnOnce(-2000, "post-traitement impossible : " + ex.Message);
				}
				val4.SetActive(true);
				planetImpostor.cameraRoot = val4;
				planetImpostor.camera = val5;
				GameObject val7 = new GameObject("CelestialMapRevamp Billboard " + ui.planet.id);
				val7.layer = layer;
				float num = (planetImpostor.builtBodyFraction = ComputeBodyFraction(val));
				GameObject val8 = new GameObject("body");
				val8.layer = layer;
				val8.transform.SetParent(val7.transform, false);
				val8.transform.localPosition = new Vector3(0f, 0f, -0.001f);
				val8.transform.localScale = new Vector3(num, num, 1f);
				Mesh sharedMesh = (planetImpostor.discMesh = BuildDiscMesh(num));
				GameObject val9 = new GameObject("body-base");
				val9.layer = layer;
				val9.transform.SetParent(val8.transform, false);
				val9.transform.localPosition = new Vector3(0f, 0f, 0.002f);
				val9.transform.localScale = new Vector3(0.995f, 0.995f, 1f);
				val9.AddComponent<MeshFilter>().sharedMesh = sharedMesh;
				Shader val10 = FindOpaqueShader();
				Material val11 = new Material(((Object)(object)val10 != (Object)null) ? val10 : val2);
				((Object)val11).name = "CelestialMapRevamp Body Base Mat";
				if ((Object)(object)val10 != (Object)null)
				{
					if (val11.HasProperty("_Color"))
					{
						val11.color = Color.black;
					}
					if (val11.HasProperty("_Glossiness"))
					{
						val11.SetFloat("_Glossiness", 0f);
					}
					if (val11.HasProperty("_Metallic"))
					{
						val11.SetFloat("_Metallic", 0f);
					}
				}
				else
				{
					val11.mainTexture = (Texture)(object)Texture2D.whiteTexture;
					if (val11.HasProperty("_Color"))
					{
						val11.color = Color.black;
					}
				}
				val11.renderQueue = 3200;
				ConfigureRenderer(val9.AddComponent<MeshRenderer>(), val11);
				planetImpostor.baseTransform = val9.transform;
				Material val12 = new Material(val2);
				((Object)val12).name = "CelestialMapRevamp Body Mat";
				val12.mainTexture = (Texture)(object)val3;
				if (val12.HasProperty("_Color"))
				{
					val12.color = Color.white;
				}
				val12.renderQueue = 3201;
				MeshRenderer val13 = null;
				for (int i = 0; i < 24; i++)
				{
					GameObject val14 = new GameObject("body-pass")
					{
						layer = layer
					};
					val14.transform.SetParent(val8.transform, false);
					val14.AddComponent<MeshFilter>().sharedMesh = sharedMesh;
					MeshRenderer val15 = val14.AddComponent<MeshRenderer>();
					ConfigureRenderer(val15, val12);
					if ((Object)(object)val13 == (Object)null)
					{
						val13 = val15;
					}
				}
				planetImpostor.bodyTransform = val8.transform;
				planetImpostor.bodyMaterial = val12;
				planetImpostor.baseMaterial = val11;
				GameObject val16 = new GameObject("halo");
				val16.layer = layer;
				val16.transform.SetParent(val7.transform, false);
				MeshFilter obj = val16.AddComponent<MeshFilter>();
				planetImpostor.haloMesh = BuildHaloMesh(num);
				obj.sharedMesh = planetImpostor.haloMesh;
				MeshRenderer renderer = val16.AddComponent<MeshRenderer>();
				Shader val17 = FindAdditiveShader();
				Material val18 = new Material(((Object)(object)val17 != (Object)null) ? val17 : val2);
				((Object)val18).name = "CelestialMapRevamp Halo Mat";
				val18.mainTexture = (Texture)(object)val3;
				if (val18.HasProperty("_Color"))
				{
					val18.color = Color.white;
				}
				if (val18.HasProperty("_TintColor"))
				{
					val18.SetColor("_TintColor", new Color(0.5f, 0.5f, 0.5f, 0.5f));
				}
				val18.renderQueue = 3201;
				ConfigureRenderer(renderer, val18);
				planetImpostor.haloTransform = val16.transform;
				MeshRenderer[] componentsInChildren = val7.GetComponentsInChildren<MeshRenderer>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					((Renderer)componentsInChildren[j]).enabled = false;
				}
				planetImpostor.billboard = val7;
				planetImpostor.billboardRenderer = (Renderer)(object)val13;
				planetImpostor.billboardMaterial = val18;
				planetImpostor.sim = val;
				planetImpostor.schematicWasEnabled = ui.planetRenderer.enabled;
			}
			catch (Exception ex2)
			{
				WarnOnce((ui.planet != null) ? ui.planet.id : (-1), "rendu réel impossible : " + ex2.Message);
				DestroyImpostor(planetImpostor);
				planetImpostor.failed = true;
			}
			return planetImpostor;
		}

		private Shader FindOpaqueShader()
		{
			if (opaqueShaderSearched)
			{
				return opaqueShaderCache;
			}
			opaqueShaderSearched = true;
			string[] array = new string[4] { "Standard", "Legacy Shaders/Diffuse", "Mobile/Diffuse", "Unlit/Texture" };
			for (int i = 0; i < array.Length; i++)
			{
				Shader val = Shader.Find(array[i]);
				if ((Object)(object)val != (Object)null)
				{
					opaqueShaderCache = val;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Base opaque des planètes : " + array[i] + " (masque les éléments schématiques passant derrière)."));
					return val;
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Aucun shader opaque : les éléments de carte resteront visibles à travers les planètes.");
			return null;
		}

		private static float ComputeBodyFraction(PlanetSimulator sim)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			float num = 1.18f;
			try
			{
				if ((Object)(object)sim != (Object)null)
				{
					Vector4 atmoMatRadiusParam = sim.atmoMatRadiusParam;
					if (atmoMatRadiusParam.x > 0.0001f && atmoMatRadiusParam.z > atmoMatRadiusParam.x)
					{
						num = atmoMatRadiusParam.z / atmoMatRadiusParam.x;
					}
				}
			}
			catch
			{
			}
			num = Mathf.Clamp(num, 1.05f, 2f);
			return Mathf.Clamp(0.86f / num, 0.15f, 0.95f);
		}

		private static void ConfigureRenderer(MeshRenderer renderer, Material material)
		{
			((Renderer)renderer).sharedMaterial = material;
			((Renderer)renderer).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)renderer).receiveShadows = false;
			((Renderer)renderer).lightProbeUsage = (LightProbeUsage)0;
			((Renderer)renderer).reflectionProbeUsage = (ReflectionProbeUsage)0;
		}

		private Shader FindAdditiveShader()
		{
			if (additiveShaderSearched)
			{
				return additiveShaderCache;
			}
			additiveShaderSearched = true;
			string[] array = new string[4] { "Particles/Additive", "Legacy Shaders/Particles/Additive", "Mobile/Particles/Additive", "Particles/Alpha Blended Premultiply" };
			for (int i = 0; i < array.Length; i++)
			{
				Shader val = Shader.Find(array[i]);
				if ((Object)(object)val != (Object)null)
				{
					additiveShaderCache = val;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Shader additif du halo : " + array[i]));
					return val;
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Aucun shader additif trouvé : le halo garde le mélange normal.");
			return null;
		}

		private int GetStructureLayer()
		{
			if ((impostorFrameMask & 0x1000) != 0)
			{
				return 12;
			}
			for (int i = 0; i < 32; i++)
			{
				if ((impostorFrameMask & (1 << i)) != 0)
				{
					return i;
				}
			}
			return 0;
		}

		private static Mesh BuildDiscMesh(float bodyFraction)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			Vector3[] array = (Vector3[])(object)new Vector3[129];
			Vector2[] array2 = (Vector2[])(object)new Vector2[129];
			Color[] array3 = (Color[])(object)new Color[129];
			int[] array4 = new int[384];
			array[0] = Vector3.zero;
			array2[0] = new Vector2(0.5f, 0.5f);
			array3[0] = Color.white;
			for (int i = 0; i < 128; i++)
			{
				float num = (float)i / 128f * (float)Math.PI * 2f;
				float num2 = Mathf.Cos(num) * 0.5f;
				float num3 = Mathf.Sin(num) * 0.5f;
				array[i + 1] = new Vector3(num2, num3, 0f);
				array2[i + 1] = new Vector2(0.5f + num2 * bodyFraction, 0.5f + num3 * bodyFraction);
				array3[i + 1] = Color.white;
				int num4 = (i + 1) % 128;
				array4[i * 3] = 0;
				array4[i * 3 + 1] = i + 1;
				array4[i * 3 + 2] = num4 + 1;
			}
			Mesh val = new Mesh
			{
				name = "CelestialMapRevamp Disc",
				vertices = array,
				uv = array2,
				colors = array3,
				triangles = array4
			};
			val.RecalculateBounds();
			return val;
		}

		private static Mesh BuildHaloMesh(float bodyFraction)
		{
			//IL_009c: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			float num = bodyFraction * 0.5f * 0.995f;
			Vector3[] array = (Vector3[])(object)new Vector3[256];
			Vector2[] array2 = (Vector2[])(object)new Vector2[256];
			Color[] array3 = (Color[])(object)new Color[256];
			int[] array4 = new int[768];
			Vector3 val = default(Vector3);
			Vector3 val2 = default(Vector3);
			for (int i = 0; i < 128; i++)
			{
				float num2 = (float)i / 128f * (float)Math.PI * 2f;
				float num3 = Mathf.Cos(num2);
				float num4 = Mathf.Sin(num2);
				((Vector3)(ref val))..ctor(num3 * num, num4 * num, 0f);
				((Vector3)(ref val2))..ctor(num3 * 0.5f, num4 * 0.5f, 0f);
				array[i * 2] = val;
				array[i * 2 + 1] = val2;
				array2[i * 2] = new Vector2(val.x + 0.5f, val.y + 0.5f);
				array2[i * 2 + 1] = new Vector2(val2.x + 0.5f, val2.y + 0.5f);
				array3[i * 2] = Color.white;
				array3[i * 2 + 1] = Color.white;
				int num5 = (i + 1) % 128;
				int num6 = i * 2;
				int num7 = i * 2 + 1;
				int num8 = num5 * 2;
				int num9 = num5 * 2 + 1;
				array4[i * 6] = num6;
				array4[i * 6 + 1] = num7;
				array4[i * 6 + 2] = num9;
				array4[i * 6 + 3] = num6;
				array4[i * 6 + 4] = num9;
				array4[i * 6 + 5] = num8;
			}
			Mesh val3 = new Mesh
			{
				name = "CelestialMapRevamp Halo",
				vertices = array,
				uv = array2,
				colors = array3,
				triangles = array4
			};
			val3.RecalculateBounds();
			return val3;
		}

		private void UpdateImpostorBillboard(PlanetImpostor imp, UIStarmap starmap)
		{
			//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)
			//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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			Renderer planetRenderer = imp.ui.planetRenderer;
			if ((Object)(object)planetRenderer == (Object)null || (Object)(object)imp.billboard == (Object)null)
			{
				return;
			}
			bool activeInHierarchy = ((Component)imp.ui).gameObject.activeInHierarchy;
			if (imp.billboard.activeSelf != activeInHierarchy)
			{
				imp.billboard.SetActive(activeInHierarchy);
			}
			if (!activeInHierarchy)
			{
				return;
			}
			if (planetRenderer.enabled)
			{
				planetRenderer.enabled = false;
			}
			Camera screenCamera = starmap.screenCamera;
			if ((Object)(object)screenCamera == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)planetRenderer).transform;
			Vector3 lossyScale = transform.lossyScale;
			float num = Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Max(Mathf.Abs(lossyScale.y), Mathf.Abs(lossyScale.z)));
			if (num <= 1E-05f)
			{
				return;
			}
			float num2 = imp.schematicMeshRadius * num;
			float num3 = Mathf.Max(0.05f, imp.builtBodyFraction);
			float num4 = 2f * num2 / num3;
			Transform transform2 = imp.billboard.transform;
			transform2.position = transform.position;
			transform2.localScale = new Vector3(num4, num4, num4);
			Vector3 val = ((Component)screenCamera).transform.position - transform2.position;
			if (((Vector3)(ref val)).sqrMagnitude > 1E-06f)
			{
				transform2.rotation = Quaternion.LookRotation(-((Vector3)(ref val)).normalized, ((Component)screenCamera).transform.up);
			}
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (!(magnitude > 1E-05f) || !((Object)(object)imp.texture != (Object)null))
			{
				return;
			}
			float num5 = Mathf.Tan(screenCamera.fieldOfView * 0.5f * ((float)Math.PI / 180f));
			if (!(num5 > 1E-05f))
			{
				return;
			}
			int num6 = Mathf.NextPowerOfTwo(Mathf.CeilToInt(num4 * (float)screenCamera.pixelHeight / (2f * magnitude * num5)));
			num6 = Mathf.Clamp(num6, 256, Mathf.Clamp(cfgImpostorResolution.Value, 256, 8192));
			int num7 = ((num6 >= 4096) ? 1 : ((num6 >= 2048) ? 2 : 4));
			if (((Texture)imp.texture).width == num6 && imp.texture.antiAliasing == num7)
			{
				return;
			}
			try
			{
				imp.texture.Release();
				((Texture)imp.texture).width = num6;
				((Texture)imp.texture).height = num6;
				imp.texture.antiAliasing = num7;
				imp.texture.Create();
			}
			catch
			{
			}
		}

		private void RenderAllImpostors(UIStarmap starmap)
		{
			int starmapLayer = GetStarmapLayer(starmap);
			int num = (hasCachedGameMask ? cachedGameMask : (-1));
			num &= ~(1 << starmapLayer);
			num &= -33;
			try
			{
				UniverseSimulator universeSimulator = GameMain.universeSimulator;
				if ((Object)(object)universeSimulator != (Object)null && (Object)(object)universeSimulator.backgroundStars != (Object)null)
				{
					num &= ~(1 << ((Component)universeSimulator.backgroundStars).gameObject.layer);
				}
			}
			catch
			{
			}
			impostorFrameMask = num;
			if (impostors.Count == 0)
			{
				return;
			}
			bool flag = false;
			foreach (KeyValuePair<int, PlanetImpostor> impostor in impostors)
			{
				PlanetImpostor value = impostor.Value;
				if (value.failed || (Object)(object)value.camera == (Object)null || (Object)(object)value.sim == (Object)null || (Object)(object)value.ui == (Object)null)
				{
					continue;
				}
				try
				{
					RenderImpostor(value, starmap);
				}
				catch (Exception ex)
				{
					flag = true;
					if (Time.unscaledTime >= errorMuteUntil)
					{
						errorMuteUntil = Time.unscaledTime + 10f;
						((BaseUnityPlugin)this).Logger.LogWarning((object)("Rendu impossible pour la planète " + impostor.Key + " : " + ex.Message));
					}
				}
			}
			if (flag)
			{
				renderFailures++;
				if (renderFailures > 120)
				{
					impostorsDisabledRuntime = true;
					DestroyAllImpostors();
					((BaseUnityPlugin)this).Logger.LogError((object)"CelestialMapRevamp : trop d'échecs de rendu, les planètes réelles sont désactivées pour cette session afin de protéger l'affichage du jeu.");
				}
			}
			else
			{
				renderFailures = 0;
			}
		}

		private static void DispatchFactoryForImpostor(PlanetData planet, Camera targetCamera, Vector3 planetPos, Vector3 dirReal, Vector3 upReal, float worldRadius)
		{
			//IL_00f5: 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_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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if (planet == null || !planet.factoryLoaded || (Object)(object)planet.factoryModel == (Object)null)
			{
				return;
			}
			Camera main = GameCamera.main;
			Transform val = (((Object)(object)main != (Object)null) ? ((Component)main).transform : null);
			Vector3 position = Vector3.zero;
			Quaternion rotation = Quaternion.identity;
			float fieldOfView = 60f;
			if ((Object)(object)val != (Object)null)
			{
				position = val.position;
				rotation = val.rotation;
				fieldOfView = main.fieldOfView;
			}
			GPUInstancingManager gpuiManager = planet.factoryModel.gpuiManager;
			PlanetData specifyPlanet = gpuiManager?.specifyPlanet;
			try
			{
				if ((Object)(object)val != (Object)null)
				{
					val.position = planetPos + dirReal * (worldRadius * 1.3f);
					val.rotation = Quaternion.LookRotation(-dirReal, upReal);
					main.fieldOfView = 120f;
				}
				if (gpuiManager != null)
				{
					gpuiManager.specifyPlanet = planet;
				}
				planet.factoryModel.DrawInstancedBatches(targetCamera, true);
			}
			finally
			{
				if (gpuiManager != null)
				{
					gpuiManager.specifyPlanet = specifyPlanet;
				}
				if ((Object)(object)val != (Object)null)
				{
					val.position = position;
					val.rotation = rotation;
					main.fieldOfView = fieldOfView;
				}
			}
		}

		private void RenderImpostor(PlanetImpostor imp, UIStarmap starmap)
		{
			//IL_0263: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_021a: 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_022d: 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_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			Camera screenCamera = starmap.screenCamera;
			Transform transform = ((Component)imp.sim).transform;
			Renderer planetRenderer = imp.ui.planetRenderer;
			if ((Object)(object)screenCamera == (Object)null || (Object)(object)planetRenderer == (Object)null)
			{
				return;
			}
			PlanetData planet = imp.ui.planet;
			if (planet == null)
			{
				return;
			}
			Vector3 lossyScale = transform.lossyScale;
			float num = Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Max(Mathf.Abs(lossyScale.y), Mathf.Abs(lossyScale.z)));
			float num2 = Mathf.Max(1E-05f, planet.realRadius * num);
			Vector3 val = ((Component)screenCamera).transform.position - ((Component)planetRenderer).transform.position;
			if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
			{
				val = -((Component)screenCamera).transform.forward;
			}
			((Vector3)(ref val)).Normalize();
			Quaternion val2 = transform.rotation * Quaternion.Inverse(((Component)planetRenderer).transform.rotation);
			Vector3 val3 = val2 * val;
			Vector3 val4 = val2 * ((Component)screenCamera).transform.up;
			float num3 = 0.17453292f;
			float num4 = num2 / (Mathf.Tan(num3) * Mathf.Max(0.05f, imp.builtBodyFraction));
			Vector3 position = transform.position;
			Transform transform2 = ((Component)imp.camera).transform;
			transform2.position = position + val3 * num4;
			transform2.rotation = Quaternion.LookRotation(-val3, val4);
			imp.camera.cullingMask = impostorFrameMask;
			imp.camera.nearClipPlane = Mathf.Max(0.05f, num4 - num2 * 1.35f);
			imp.camera.farClipPlane = num4 + num2 * 1.35f;
			imp.camera.backgroundColor = new Color(0f, 0f, 0f, 0f);
			DispatchFactoryForImpostor(planet, imp.camera, position, val3, val4, num2);
			DrawRemoteStructures(planet, imp.camera, GetStructureLayer());
			Transform val5 = (((Object)(object)imp.sim != (Object)null) ? imp.sim.atmoTrans0 : null);
			Quaternion rotation = Quaternion.identity;
			if ((Object)(object)val5 != (Object)null)
			{
				rotation = val5.rotation;
				val5.rotation = Quaternion.LookRotation(-val3, val4);
			}
			try
			{
				imp.camera.Render();
			}
			finally
			{
				if ((Object)(object)val5 != (Object)null)
				{
					val5.rotation = rotation;
				}
			}
		}

		private void DestroyImpostor(PlanetImpostor imp)
		{
			if (imp == null)
			{
				return;
			}
			try
			{
				if ((Object)(object)imp.ui != (Object)null && (Object)(object)imp.ui.planetRenderer != (Object)null)
				{
					imp.ui.planetRenderer.enabled = true;
				}
			}
			catch
			{
			}
			if ((Object)(object)imp.billboard != (Object)null)
			{
				Object.Destroy((Object)(object)imp.billboard);
				imp.billboard = null;
			}
			if ((Object)(object)imp.discMesh != (Object)null)
			{
				Object.Destroy((Object)(object)imp.discMesh);
				imp.discMesh = null;
			}
			if ((Object)(object)imp.haloMesh != (Object)null)
			{
				Object.Destroy((Object)(object)imp.haloMesh);
				imp.haloMesh = null;
			}
			if ((Object)(object)imp.billboardMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)imp.billboardMaterial);
				imp.billboardMaterial = null;
			}
			if ((Object)(object)imp.bodyMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)imp.bodyMaterial);
				imp.bodyMaterial = null;
			}
			if ((Object)(object)imp.baseMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)imp.baseMaterial);
				imp.baseMaterial = null;
			}
			if ((Object)(object)imp.camera != (Object)null)
			{
				imp.camera.targetTexture = null;
			}
			if ((Object)(object)imp.cameraRoot != (Object)null)
			{
				Object.Destroy((Object)(object)imp.cameraRoot);
				imp.cameraRoot = null;
				imp.camera = null;
			}
			if ((Object)(object)imp.texture != (Object)null)
			{
				imp.texture.Release();
				Object.Destroy((Object)(object)imp.texture);
				imp.texture = null;
			}
		}

		private void DestroyAllImpostors()
		{
			foreach (KeyValuePair<int, PlanetImpostor> impostor in impostors)
			{
				DestroyImpostor(impostor.Value);
			}
			impostors.Clear();
		}

		private static string DescribeMask(int mask)
		{
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < 32; i++)
			{
				if ((mask & (1 << i)) != 0)
				{
					if (stringBuilder.Length > 0)
					{
						stringBuilder.Append(", ");
					}
					string value = LayerMask.LayerToName(i);
					stringBuilder.Append(i);
					if (!string.IsNullOrEmpty(value))
					{
						stringBuilder.Append('=').Append(value);
					}
				}
			}
			return stringBuilder.ToString();
		}

		private void DumpStarmapLayerContents(int layer)
		{
			try
			{
				Renderer[] array = Object.FindObjectsOfType<Renderer>();
				Dictionary<string, int> dictionary = new Dictionary<string, int>();
				Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
				int num = 0;
				int num2 = 0;
				foreach (Renderer val in array)
				{
					if ((Object)(object)val == (Object)null || !val.enabled || ((Component)val).gameObject.layer != layer || !((Component)val).gameObject.activeInHierarchy)
					{
						continue;
					}
					num++;
					string name = ((Object)((Component)val).gameObject).name;
					if (name.StartsWith("CelestialMapRevamp"))
					{
						num2++;
						continue;
					}
					Transform parent = ((Component)val).transform.parent;
					string key = (((Object)(object)parent != (Object)null) ? (((Object)parent).name + "/") : "") + name + " [" + ((object)val).GetType().Name + "]";
					dictionary.TryGetValue(key, out var value);
					dictionary[key] = value + 1;
					if (value == 0)
					{
						Material sharedMaterial = val.sharedMaterial;
						dictionary2[key] = (((Object)(object)sharedMaterial == (Object)null || (Object)(object)sharedMaterial.shader == (Object)null) ? "aucun matériau" : (((Object)sharedMaterial.shader).name + (sharedMaterial.HasProperty("_ZTest") ? " +ZTest" : " -ZTest") + (sharedMaterial.HasProperty("_ZWrite") ? " +ZWrite" : " -ZWrite") + " file=" + sharedMaterial.renderQueue));
					}
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"DIAG | rendus actifs sur la couche carte : {num} dont {num2} du mod, {dictionary.Count} familles");
				foreach (KeyValuePair<string, int> item in dictionary)
				{
					dictionary2.TryGetValue(item.Key, out var value2);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("DIAG |   x" + item.Value + "  " + item.Key + "  ->  " + (value2 ?? "?")));
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("DIAG | inventaire de la couche carte impossible : " + ex.Message));
			}
		}

		private void DumpDiagnostics(UIStarmap starmap)
		{
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected I4, but got Unknown
			Camera main = GameCamera.main;
			int num = (((Object)(object)main != (Object)null) ? main.cullingMask : (-999));
			int num2 = (((Object)(object)starmap.screenCamera != (Object)null) ? starmap.screenCamera.cullingMask : (-999));
			int starmapLayer = GetStarmapLayer(starmap);
			int num3 = -1;
			bool flag = false;
			try
			{
				num3 = (int)UIGame.viewMode;
				flag = UIGame.viewModeReady;
			}
			catch
			{
			}
			bool flag2 = false;
			try
			{
				flag2 = GameMain.inOtherScene;
			}
			catch
			{
			}
			int num4 = -1;
			try
			{
				UniverseSimulator universeSimulator = GameMain.universeSimulator;
				if ((Object)(object)universeSimulator != (Object)null && (Object)(object)universeSimulator.backgroundStars != (Object)null)
				{
					num4 = ((Component)universeSimulator.backgroundStars).gameObject.layer;
				}
			}
			catch
			{
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("DIAG | path={0} viewMode={1} ready={2} otherScene={3} | mainMask=0x{4:X} cachedMask=0x{5:X} impMask=0x{6:X} screenMask=0x{7:X} starmapLayer={8} bgLayer={9} | impostors={10}", "miniCam", num3, flag, flag2, num, hasCachedGameMask ? cachedGameMask : 0, impostorFrameMask, num2, starmapLayer, num4, impostors.Count));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("DIAG | couches filmées : " + DescribeMask(impostorFrameMask)));
			Camera screenCamera = starmap.screenCamera;
			if ((Object)(object)screenCamera != (Object)null)
			{
				DumpStarmapLayerContents(starmapLayer);
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"DIAG | caméra carte : clear={screenCamera.clearFlags} fond={screenCamera.backgroundColor} hdr={screenCamera.allowHDR} msaa={screenCamera.allowMSAA} profondeur={screenCamera.depthTextureMode} | couches vues : {DescribeMask(num2)}");
			}
			PlanetData localPlanet = GameMain.localPlanet;
			if (localPlanet == null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"DIAG | pas de planète locale");
				return;
			}
			GPUInstancingManager val = (((Object)(object)localPlanet.factoryModel != (Object)null) ? localPlanet.factoryModel.gpuiManager : null);
			int num5 = -1;
			int num6 = 0;
			int num7 = -1;
			if (val != null && val.objectRenderers != null)
			{
				num5 = val.objectRenderers.Length;
				for (int i = 0; i < val.objectRenderers.Length; i++)
				{
					ObjectRenderer val2 = val.objectRenderers[i];
					if (val2 == null)
					{
						continue;
					}
					int num8 = 0;
					try
					{
						num8 = Traverse.Create((object)val2).Field("instCursor").GetValue<int>();
					}
					catch
					{
					}
					if (num8 <= 1)
					{
						continue;
					}
					num6++;
					if (num7 >= 0)
					{
						continue;
					}
					try
					{
						BatchRenderer[] value = Traverse.Create((object)val2).Field("lodBatches").GetValue<BatchRenderer[]>();
						if (value != null && value.Length != 0 && value[0] != null)
						{
							num7 = value[0].layer;
						}
					}
					catch
					{
					}
				}
			}
			bool flag3 = num7 >= 0 && hasCachedGameMask && (cachedGameMask & (1 << num7)) != 0;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"DIAG | locale={localPlanet.displayName} factoryLoaded={localPlanet.factoryLoaded} model={(Object)(object)localPlanet.factoryModel != (Object)null} gpui={val != null} activeFactory={val != null && val.activeFactory != null} | objectRenderers={num5} avecInstances={num6} layerBatiments={num7} dansMasque={flag3}");
		}

		private void WarnOnce(int id, string message)
		{
			if (loggedWarnings.Add(id))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("CelestialMapRevamp : " + message + " (affichage d'origine conservé)."));
			}
		}

		private PartKey[] GetModelParts(int modelIndex)
		{
			if (modelPartCache.TryGetValue(modelIndex, out var value))
			{
				return value;
			}
			List<PartKey> list = new List<PartKey>();
			try
			{
				PrefabDesc val = (((Object)(object)LDB.models != (Object)null) ? ((ProtoSet<ModelProto>)(object)LDB.models).Select(modelIndex) : null)?.prefabDesc;
				if (val != null)
				{
					int num = Mathf.Clamp(cfgStructureDetail.Value, 0, 3);
					int num2 = Mathf.Max(0, val.lodCount);
					int num3 = -1;
					for (int num4 = Mathf.Min(num, num2 - 1); num4 >= 0; num4--)
					{
						if (val.lodMeshes != null && num4 < val.lodMeshes.Length && (Object)(object)val.lodMeshes[num4] != (Object)null)
						{
							num3 = num4;
							break;
						}
					}
					if (num3 >= 0)
					{
						Mesh mesh = val.lodMeshes[num3];
						Material[] materials = ((val.lodMaterials != null && num3 < val.lodMaterials.Length) ? val.lodMaterials[num3] : null);
						bool[] ignores = ((val.lodSubmeshIgnores != null && num3 < val.lodSubmeshIgnores.Length) ? val.lodSubmeshIgnores[num3] : null);
						AddParts(list, mesh, materials, ignores);
					}
					if (list.Count == 0)
					{
						AddParts(list, val.mesh, val.materials, null);
					}
					if (list.Count == 0 && (Object)(object)val.starmapMesh != (Object)null && (Object)(object)val.starmapMaterial != (Object)null)
					{
						list.Add(new PartKey
						{
							mesh = val.starmapMesh,
							submesh = 0,
							material = val.starmapMaterial
						});
					}
				}
			}
			catch
			{
			}
			value = list.ToArray();
			modelPartCache[modelIndex] = value;
			return value;
		}

		private static void AddParts(List<PartKey> parts, Mesh mesh, Material[] materials, bool[] ignores)
		{
			if ((Object)(object)mesh == (Object)null || materials == null)
			{
				return;
			}
			int num = Math.Min(mesh.subMeshCount, materials.Length);
			for (int i = 0; i < num; i++)
			{
				if (!((Object)(object)materials[i] == (Object)null) && (ignores == null || i >= ignores.Length || !ignores[i]))
				{
					parts.Add(new PartKey
					{
						mesh = mesh,
						submesh = i,
						material = materials[i]
					});
				}
			}
		}

		private void SyncRemoteStructures()
		{
			if (!cfgRemoteStructures.Value || structuresDisabled)
			{
				if (this.remoteStructures.Count > 0)
				{
					DestroyAllRemoteStructures();
				}
				return;
			}
			seenIds.Clear();
			foreach (KeyValuePair<int, PlanetImpostor> impostor in impostors)
			{
				seenIds.Add(impostor.Key);
			}
			staleIds.Clear();
			foreach (KeyValuePair<int, RemoteStructures> remoteStructure in this.remoteStructures)
			{
				if (!seenIds.Contains(remoteStructure.Key))
				{
					staleIds.Add(remoteStructure.Key);
				}
			}
			for (int i = 0; i < staleIds.Count; i++)
			{
				DestroyRemoteStructures(this.remoteStructures[staleIds[i]]);
				this.remoteStructures.Remove(staleIds[i]);
			}
			if (Time.unscaledTime < nextStructureBuild)
			{
				return;
			}
			PlanetData localPlanet = GameMain.localPlanet;
			foreach (KeyValuePair<int, PlanetImpostor> impostor2 in impostors)
			{
				PlanetImpostor value = impostor2.Value;
				if (value.failed || (Object)(object)value.ui == (Object)null || value.ui.planet == null || (Object)(object)value.sim == (Object)null)
				{
					continue;
				}
				PlanetData planet = value.ui.planet;
				if (planet == localPlanet || planet.factory == null)
				{
					continue;
				}
				PlanetFactory factory = planet.factory;
				if (factory.entityPool == null || factory.entityCursor <= 1)
				{
					continue;
				}
				if (this.remoteStructures.TryGetValue(planet.id, out var value2))
				{
					if (factory.entityCursor == value2.builtEntityCursor || Time.unscaledTime - value2.builtAt < 10f)
					{
						continue;
					}
					DestroyRemoteStructures(value2);
					this.remoteStructures.Remove(planet.id);
				}
				nextStructureBuild = Time.unscaledTime + 0.25f;
				RemoteStructures remoteStructures = BuildRemoteStructures(planet, ((Component)value.sim).transform);
				if (remoteStructures != null)
				{
					this.remoteStructures[planet.id] = remoteStructures;
				}
				break;
			}
		}

		private RemoteStructures BuildRemoteStructures(PlanetData planet, Transform simTransform)
		{
			//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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Expected O, but got Unknown
			RemoteStructures remoteStructures = new RemoteStructures();
			remoteStructures.planetId = planet.id;
			remoteStructures.simTransform = simTransform;
			try
			{
				Dictionary<PartKey, List<Matrix4x4>> dictionary = new Dictionary<PartKey, List<Matrix4x4>>();
				int value = cfgMaxStructures.Value;
				int num = 0;
				EntityData[] entityPool = planet.factory.entityPool;
				int num2 = Math.Min(planet.factory.entityCursor, entityPool.Length);
				for (int i = 1; i < num2; i++)
				{
					EntityData val = entityPool[i];
					if (val.id != i || val.modelIndex <= 0)
					{
						continue;
					}
					if (value > 0 && num >= value)
					{
						break;
					}
					PartKey[] modelParts = GetModelParts(val.modelIndex);
					if (modelParts.Length == 0)
					{
						continue;
					}
					Matrix4x4 item = Matrix4x4.TRS(val.pos, val.rot, Vector3.one);
					for (int j = 0; j < modelParts.Length; j++)
					{
						if (!dictionary.TryGetValue(modelParts[j], out var value2))
						{
							value2 = new List<Matrix4x4>();
							dictionary.Add(modelParts[j], value2);
						}
						value2.Add(item);
					}
					num++;
				}
				if (num == 0)
				{
					return null;
				}
				foreach (KeyValuePair<PartKey, List<Matrix4x4>> item2 in dictionary)
				{
					PartKey key = item2.Key;
					List<Matrix4x4> value3 = item2.Value;
					int num3 = Math.Max(1, key.mesh.vertexCount);
					int num4 = Mathf.Clamp(400000 / num3, 1, 4096);
					for (int k = 0; k < value3.Count; k += num4)
					{
						int num5 = Math.Min(num4, value3.Count - k);
						CombineInstance[] array = (CombineInstance[])(object)new CombineInstance[num5];
						for (int l = 0; l < num5; l++)
						{
							((CombineInstance)(ref array[l])).mesh = key.mesh;
							((CombineInstance)(ref array[l])).subMeshIndex = key.submesh;
							((CombineInstance)(ref array[l])).transform = value3[k + l];
						}
						Mesh val2 = new Mesh();
						((Object)val2).name = "CelestialMapRevamp Structures " + planet.id;
						val2.indexFormat = (IndexFormat)1;
						val2.CombineMeshes(array, true, true, false);
						val2.RecalculateBounds();
						remoteStructures.meshes.Add(val2);
						remoteStructures.materials.Add(key.material);
					}
				}
				if (cfgBelts.Value)
				{
					try
					{
						BuildBeltRibbons(planet, remoteStructures);
					}
					catch (Exception ex)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("Tapis de " + planet.displayName + " impossibles : " + ex.Message));
					}
				}
				remoteStructures.structureCount = num;
				remoteStructures.builtEntityCursor = planet.factory.entityCursor;
				remoteStructures.builtAt = Time.unscaledTime;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Structures de " + planet.displayName + " prêtes : " + num + " bâtiments, " + remoteStructures.beltPathCount + " tapis, " + remoteStructures.meshes.Count + " maillages."));
				return remoteStructures;
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Structures de " + planet.displayName + " impossibles : " + ex2.Message));
				DestroyRemoteStructures(remoteStructures);
				structureFailures++;
				if (structureFailures >= 3)
				{
					structuresDisabled = true;
					((BaseUnityPlugin)this).Logger.LogError((object)"CelestialMapRevamp : structures distantes désactivées pour cette session.");
				}
				return null;
			}
		}

		private void DrawRemoteStructures(PlanetData planet, Camera targetCamera, int layer)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (planet == null || !remoteStructures.TryGetValue(planet.id, out var value) || (Object)(object)value.simTransform == (Object)null || (Object)(object)targetCamera == (Object)null)
			{
				return;
			}
			Matrix4x4 localToWorldMatrix = value.simTransform.localToWorldMatrix;
			for (int i = 0; i < value.meshes.Count; i++)
			{
				Mesh val = value.meshes[i];
				Material val2 = value.materials[i];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
				{
					Graphics.DrawMesh(val, localToWorldMatrix, val2, layer, targetCamera, 0, (MaterialPropertyBlock)null, false, false, false);
				}
			}
		}

		private void DestroyRemoteStructures(RemoteStructures structures)
		{
			if (structures == null)
			{
				return;
			}
			for (int i = 0; i < structures.meshes.Count; i++)
			{
				if ((Object)(object)structures.meshes[i] != (Object)null)
				{
					Object.Destroy((Object)(object)structures.meshes[i]);
				}
			}
			structures.meshes.Clear();
			structures.materials.Clear();
		}

		private void DestroyBeltMaterial()
		{
			if ((Object)(object)beltMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)beltMaterial);
				beltMaterial = null;
			}
		}

		private void DestroyAllRemoteStructures()
		{
			foreach (KeyValuePair<int, RemoteStructures> remoteStructure in remoteStructures)
			{
				DestroyRemoteStructures(remoteStructure.Value);
			}
			remoteStructures.Clear();
		}

		private Material GetBeltMaterial()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)beltMaterial != (Object)null)
			{
				return beltMaterial;
			}
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Legacy Shaders/Diffuse");
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			beltMaterial = new Material(val);
			((Object)beltMaterial).name = "CelestialMapRevamp Belt Mat";
			if (beltMaterial.HasProperty("_Color"))
			{
				beltMaterial.color = new Color(0.3f, 0.33f, 0.36f, 1f);
			}
			if (beltMaterial.HasProperty("_Metallic"))
			{
				beltMaterial.SetFloat("_Metallic", 0.35f);
			}
			if (beltMaterial.HasProperty("_Glossiness"))
			{
				beltMaterial.SetFloat("_Glossiness", 0.3f);
			}
			if (beltMaterial.HasProperty("_Cull"))
			{
				beltMaterial.SetFloat("_Cull", 0f);
			}
			beltMaterial.SetInt("_Cull", 0);
			return beltMaterial;
		}

		private void BuildBeltRibbons(PlanetData planet, RemoteStructures result)
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			Material val = GetBeltMaterial();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			CargoTraffic cargoTraffic = planet.factory.cargoTraffic;
			CargoPath[] array = cargoTraffic?.pathPool;
			if (array == null)
			{
				return;
			}
			int num = 4;
			float num2 = 0.55f;
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			int num3 = 0;
			int num4 = Math.Min(cargoTraffic.pathCursor, array.Length);
			for (int i = 1; i < num4; i++)
			{
				CargoPath val2 = array[i];
				if (val2 == null || val2.id != i || val2.pointPos == null)
				{
					continue;
				}
				int num5 = Math.Min(val2.pathLength, val2.pointPos.Length);
				if (num5 < 2)
				{
					continue;
				}
				int num6 = -1;
				bool flag = false;
				for (int j = 0; j < num5; j += num)
				{
					int num7 = ((j + num >= num5) ? (num5 - 1) : j);
					Vector3 val3 = val2.pointPos[num7];
					if (((Vector3)(ref val3)).sqrMagnitude < 1f)
					{
						continue;
					}
					Vector3 normalized = ((Vector3)(ref val3)).normalized;
					Vector3 val4 = Vector3.zero;
					if (val2.pointRot != null && num7 < val2.pointRot.Length)
					{
						val4 = val2.pointRot[num7] * Vector3.right;
						val4 -= normalized * Vector3.Dot(val4, normalized);
					}
					if (((Vector3)(ref val4)).sqrMagnitude < 1E-06f)
					{
						int num8 = Math.Max(0, num7 - 1);
						int num9 = Math.Min(num5 - 1, num7 + 1);
						val4 = Vector3.Cross(normalized, val2.pointPos[num9] - val2.pointPos[num8]);
					}
					if (!(((Vector3)(ref val4)).sqrMagnitude < 1E-06f))
					{
						val4 = ((Vector3)(ref val4)).normalized * num2;
						Vector3 val5 = val3 + normalized * 0.15f;
						int count = list.Count;
						list.Add(val5 - val4);
						list.Add(val5 + val4);
						list2.Add(normalized);
						list2.Add(normalized);
						list3.Add(new Vector2(0f, (float)num7 * 0.25f));
						list3.Add(new Vector2(1f, (float)num7 * 0.25f));
						if (num6 >= 0)
						{
							list4.Add(num6);
							list4.Add(count);
							list4.Add(num6 + 1);
							list4.Add(num6 + 1);
							list4.Add(count);
							list4.Add(count + 1);
							flag = true;
						}
						num6 = count;
						if (num7 == num5 - 1)
						{
							break;
						}
					}
				}
				if (flag)
				{
					num3++;
				}
				if (list.Count > 240000)
				{
					FlushBeltMesh(result, val, list, list2, list3, list4, planet.id);
				}
			}
			FlushBeltMesh(result, val, list, list2, list3, list4, planet.id);
			result.beltPathCount = num3;
		}

		private static void FlushBeltMesh(RemoteStructures result, Material material, List<Vector3> vertices, List<Vector3> normals, List<Vector2> uvs, List<int> triangles, int planetId)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			if (vertices.Count < 3 || triangles.Count < 3)
			{
				vertices.Clear();
				normals.Clear();
				uvs.Clear();
				triangles.Clear();
				return;
			}
			Mesh val = new Mesh();
			((Object)val).name = "CelestialMapRevamp Belts " + planetId;
			val.indexFormat = (IndexFormat)1;
			val.SetVertices(vertices);
			val.SetNormals(normals);
			val.SetUVs(0, uvs);
			val.SetTriangles(triangles, 0);
			val.RecalculateBounds();
			result.meshes.Add(val);
			result.materials.Add(material);
			vertices.Clear();
			normals.Clear();
			uvs.Clear();
			triangles.Clear();
		}

		private PostProcessingProfile GetImpostorProfile()
		{
			if (impostorProfileSearched)
			{
				return impostorProfile;
			}
			impostorProfileSearched = true;
			try
			{
				Camera main = GameCamera.main;
				PostProcessingBehaviour val = (((Object)(object)main != (Object)null) ? ((Component)main).GetComponent<PostProcessingBehaviour>() : null);
				if ((Object)(object)val == (Object)null || (Object)(object)val.profile == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Aucun profil de post-traitement trouvé : rendu brut conservé.");
					return null;
				}
				PostProcessingProfile val2 = Object.Instantiate<PostProcessingProfile>(val.profile);
				((Object)val2).name = "CelestialMapRevamp Profile";
				if (val2.vignette != null)
				{
					((PostProcessingModel)val2.vignette).enabled = false;
				}
				if (val2.depthOfField != null)
				{
					((PostProcessingModel)val2.depthOfField).enabled = false;
				}
				if (val2.motionBlur != null)
				{
					((PostProcessingModel)val2.motionBlur).enabled = false;
				}
				if (val2.grain != null)
				{
					((PostProcessingModel)val2.grain).enabled = false;
				}
				if (val2.chromaticAberration != null)
				{
					((PostProcessingModel)val2.chromaticAberration).enabled = false;
				}
				if (val2.eyeAdaptation != null)
				{
					((PostProcessingModel)val2.eyeAdaptation).enabled = false;
				}
				if (val2.antialiasing != null)
				{
					((PostProcessingModel)val2.antialiasing).enabled = false;
				}
				if (val2.ambientOcclusion != null)
				{
					((PostProcessingModel)val2.ambientOcclusion).enabled = false;
				}
				if (val2.screenSpaceReflection != null)
				{
					((PostProcessingModel)val2.screenSpaceReflection).enabled = false;
				}
				if (val2.debugViews != null)
				{
					((PostProcessingModel)val2.debugViews).enabled = false;
				}
				impostorProfile = val2;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Post-traitement des planètes actif (profil du jeu, sans vignettage ni flou).");
				return val2;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Post-traitement indisponible : " + ex.Message));
				return null;
			}
		}

		private void SyncStars(UIStarmap starmap, int layer)
		{
			//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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Invalid comparison between Unknown and I4
			seenIds.Clear();
			UIStarmapStar[] starUIs = starmap.starUIs;
			if (starUIs != null)
			{
				foreach (UIStarmapStar val in starUIs)
				{
					if ((Object)(object)val == (Object)null || val.star == null || (Object)(object)val.starObject == (Object)null)
					{
						continue;
					}
					EStarType type = val.star.type;
					if ((int)type == 4 || (int)type == 3)
					{
						continue;
					}
					int id = val.star.id;
					seenIds.Add(id);
					if (starVisuals.TryGetValue(id, out var value) && ((Object)(object)value.ui != (Object)(object)val || (Object)(object)value.root == (Object)null))
					{
						DestroyStarVisual(value);
						starVisuals.Remove(id);
						value = null;
					}
					if (value == null)
					{
						value = BuildStarVisual(val, layer);
						if (value == null)
						{
							continue;
						}
						starVisuals[id] = value;
					}
					UpdateStarVisual(value);
				}
			}
			staleIds.Clear();
			foreach (KeyValuePair<int, StarVisual> starVisual in starVisuals)
			{
				if (!seenIds.Contains(starVisual.Key))
				{
					staleIds.Add(starVisual.Key);
				}
			}
			for (int j = 0; j < staleIds.Count; j++)
			{
				DestroyStarVisual(starVisuals[staleIds[j]]);
				starVisuals.Remove(staleIds[j]);
			}
		}

		private StarVisual BuildStarVisual(UIStarmapStar ui, int layer)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0083: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			try
			{
				StarSimulator val = GameMain.universeSimulator.FindStarSimulator(ui.star);
				if ((Object)(object)val == (Object)null || (Object)(object)val.bodyRenderer == (Object)null)
				{
					return null;
				}
				Mesh rendererMesh = GetRendererMesh(val.bodyRenderer);
				if ((Object)(object)rendererMesh == (Object)null)
				{
					return null;
				}
				Material[] sharedMaterials = val.bodyRenderer.sharedMaterials;
				if (sharedMaterials == null || sharedMaterials.Length == 0 || (Object)(object)sharedMaterials[0] == (Object)null)
				{
					return null;
				}
				Bounds bounds = rendererMesh.bounds;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				float num = Mathf.Max(extents.x, Mathf.Max(extents.y, extents.z));
				if (num <= 1E-05f)
				{
					return null;
				}
				Material[] array = null;
				GameObject val2 = new GameObject("CelestialMapRevamp Star " + ui.star.id);
				val2.layer = layer;
				val2.transform.SetParent(((Component)ui.starObject).transform, false);
				val2.transform.localPosition = Vector3.zero;
				val2.transform.localRotation = Quaternion.identity;
				val2.transform.localScale = Vector3.one;
				GameObject val3 = new GameObject("sun-body");
				val3.layer = layer;
				val3.transform.SetParent(val2.transform, false);
				val3.AddComponent<MeshFilter>().sharedMesh = rendererMesh;
				MeshRenderer val4 = val3.AddComponent<MeshRenderer>();
				Material[] array2 = (Material[])(object)new Material[sharedMaterials.Length];
				for (int i = 0; i < sharedMaterials.Length; i++)
				{
					if (!((Object)(object)sharedMaterials[i] == (Object)null))
					{
						Material val5 = new Material(sharedMaterials[i]);
						val5.renderQueue = 3201;
						array2[i] = val5;
					}
				}
				((Renderer)val4).sharedMaterials = array2;
				array = array2;
				((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)val4).receiveShadows = false;
				((Renderer)val4).lightProbeUsage = (LightProbeUsage)0;
				((Renderer)val4).reflectionProbeUsage = (ReflectionProbeUsage)0;
				try
				{
					MaterialPropertyBlock val6 = new MaterialPropertyBlock();
					val.bodyRenderer.GetPropertyBlock(val6);
					if (!val6.isEmpty)
					{
						((Renderer)val4).SetPropertyBlock(val6);
					}
				}
				catch
				{
				}
				((Renderer)val4).enabled = false;
				return new StarVisual
				{
					materials = array,
					ui = ui,
					root = val2,
					contentRadius = num,
					simTransform = ((Component)val).transform,
					mesh = rendererMesh,
					bodyTransform = val3.transform
				};
			}
			catch
			{
				return null;
			}
		}

		private void UpdateStarVisual(StarVisual visual)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			UIStarmapStarObject starObject = visual.ui.starObject;
			if ((Object)(object)starObject == (Object)null || (Object)(object)visual.root == (Object)null)
			{
				return;
			}
			Renderer val = (((Object)(object)starObject.massObj != (Object)null) ? starObject.massObj : starObject.spotObj);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Bounds bounds = val.bounds;
			Vector3 extents = ((Bounds)(ref bounds)).extents;
			float num = Mathf.Max(extents.x, Mathf.Max(extents.y, extents.z)) * 0.6f;
			if (num <= 1E-05f)
			{
				return;
			}
			Vector3 lossyScale = ((Component)starObject).transform.lossyScale;
			float num2 = Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Max(Mathf.Abs(lossyScale.y), Mathf.Abs(lossyScale.z)));
			if (!(num2 <= 1E-05f))
			{
				float num3 = num / (visual.contentRadius * num2);
				visual.root.transform.localScale = new Vector3(num3, num3, num3);
				if ((Object)(object)visual.simTransform != (Object)null)
				{
					visual.root.transform.rotation = visual.simTransform.rotation;
				}
			}
		}

		private void DestroyStarVisual(StarVisual visual)
		{
			if (visual == null)
			{
				return;
			}
			if ((Object)(object)visual.root != (Object)null)
			{
				Object.Destroy((Object)(object)visual.root);
				visual.root = null;
			}
			if (visual.materials == null)
			{
				return;
			}
			for (int i = 0; i < visual.materials.Length; i++)
			{
				if ((Object)(object)visual.materials[i] != (Object)null)
				{
					Object.Destroy((Object)(object)visual.materials[i]);
				}
			}
			visual.materials = null;
		}

		private void DestroyAllStarVisuals()
		{
			foreach (KeyValuePair<int, StarVisual> starVisual in starVisuals)
			{
				DestroyStarVisual(starVisual.Value);
			}
			starVisuals.Clear();
		}

		private void SyncBackdrop(UIStarmap starmap, int layer)
		{
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)backdrop == (Object)null)
			{
				UniverseSimulator universeSimulator = GameMain.universeSimulator;
				if ((Object)(object)universeSimulator == (Object)null || (Object)(object)universeSimulator.backgroundStars == (Object)null)
				{
					return;
				}
				backdrop = Object.Instantiate<GameObject>(((Component)universeSimulator.backgroundStars).gameObject);
				((Object)backdrop).name = "CelestialMapRevamp Backdrop";
				MonoBehaviour[] componentsInChildren = backdrop.GetComponentsInChildren<MonoBehaviour>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)null)
					{
						((Behaviour)componentsInChildren[i]).enabled = false;
					}
				}
				Camera[] componentsInChildren2 = backdrop.GetComponentsInChildren<Camera>(true);
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					Object.Destroy((Object)(object)componentsInChildren2[j]);
				}
				SetLayerRecursive(backdrop.transform, layer);
				backdrop.transform.rotation = universeSimulator.backgroundStars.rotation;
				backdrop.transform.localScale = Vector3.one;
				backdrop.SetActive(true);
				backdropBaseRadius = 0f;
				Renderer[] componentsInChildren3 = backdrop.GetComponentsInChildren<Renderer>(true);
				for (int k = 0; k < componentsInChildren3.Length; k++)
				{
					if ((Object)(object)componentsInChildren3[k] != (Object)null)
					{
						Bounds bounds = componentsInChildren3[k].bounds;
						Vector3 extents = ((Bounds)(ref bounds)).extents;
						backdropBaseRadius = Mathf.Max(backdropBaseRadius, Mathf.Max(extents.x, Mathf.Max(extents.y, extents.z)));
					}
				}
			}
			Camera screenCamera = starmap.screenCamera;
			if (!((Object)(object)screenCamera != (Object)null))
			{
				return;
			}
			backdrop.transform.position = ((Component)screenCamera).transform.position;
			if (backdropBaseRadius > 1E-05f)
			{
				float num = screenCamera.farClipPlane * 0.9f;
				if (backdropBaseRadius > num)
				{
					float num2 = num / backdropBaseRadius;
					backdrop.transform.localScale = new Vector3(num2, num2, num2);
				}
			}
		}

		private SunShafts FindGameSunShafts()
		{
			if (gameSunShaftsSearched && (Object)(object)gameSunShafts != (Object)null)
			{
				return gameSunShafts;
			}
			gameSunShaftsSearched = true;
			try
			{
				Camera main = GameCamera.main;
				if ((Object)(object)main != (Object)null)
				{
					SunShafts component = ((Component)main).GetComponent<SunShafts>();
					if ((Object)(object)component != (Object)null)
					{
						gameSunShafts = component;
						return component;
					}
					PostEffectController component2 = ((Component)main).GetComponent<PostEffectController>();
					if ((Object)(object)component2 != (Object)null && (Object)(object)component2.sunShaft != (Object)null)
					{
						gameSunShafts = component2.sunShaft;
						return gameSunShafts;
					}
				}
				PostEffectController val = Object.FindObjectOfType<PostEffectController>();
				if ((Object)(object)val != (Object)null && (Object)(object)val.sunShaft != (Object)null)
				{
					gameSunShafts = val.sunShaft;
					return gameSunShafts;
				}
			}
			catch (Exception ex)
			{
				if (!sunShaftsWarned)
				{
					sunShaftsWarned = true;
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Rayons solaires : composant du jeu introuvable (" + ex.Message + ")."));
				}
			}
			return gameSunShafts;
		}

		private UIStarmapStarObject FindMapStarObject(UIStarmap starmap)
		{
			StarData viewStarSystem = starmap.viewStarSystem;
			if (viewStarSystem == null)
			{
				return null;
			}
			UIStarmapStar[] starUIs = starmap.starUIs;
			if (starUIs == null)
			{
				return null;
			}
			foreach (UIStarmapStar val in starUIs)
			{
				if ((Object)(object)val != (Object)null && val.star != null && val.star.id == viewStarSystem.id && (Object)(object)val.starObject != (Object)null && ((Component)val.starObject).gameObject.activeInHierarchy)
				{
					return val.starObject;
				}
			}
			return null;
		}

		private float ComputePlanetSpan(Camera view, UIStarmap starmap, Vector2 sunViewport, out bool anyPlanet)
		{
			//IL_003e: 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_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_0096: 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_009d: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_012c: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			anyPlanet = false;
			float num = 0f;
			UIStarmapPlanet[] planetUIs = starmap.planetUIs;
			if (planetUIs == null)
			{
				return num;
			}
			float num2 = Mathf.Tan(view.fieldOfView * 0.5f * ((float)Math.PI / 180f));
			if (num2 <= 1E-05f)
			{
				return num;
			}
			Vector3 position = ((Component)view).transform.position;
			foreach (UIStarmapPlanet val in planetUIs)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)val.planetRenderer == (Object)null || !((Component)val).gameObject.activeInHierarchy)
				{
					continue;
				}
				Vector3 position2 = ((Component)val.planetRenderer).transform.position;
				Vector3 val2 = view.WorldToViewportPoint(position2);
				if (val2.z <= 0f || val2.x < -0.25f || val2.x > 1.25f || val2.y < -0.25f || val2.y > 1.25f)
				{
					continue;
				}
				float num3 = Vector3.Distance(position, position2);
				if (!(num3 <= 1E-05f))
				{
					Bounds bounds = val.planetRenderer.bounds;
					Vector3 extents = ((Bounds)(ref bounds)).extents;
					float num4 = Mathf.Max(extents.x, Mathf.Max(extents.y, extents.z));
					float num5 = 0.5f * num4 / (num3 * num2);
					anyPlanet = true;
					float num6 = Vector2.Distance(new Vector2(val2.x, val2.y), sunViewport) + num5;
					if (num6 > num)
					{
						num = num6;
					}
				}
			}
			return num * 1.15f;
		}

		private void SyncSunShafts(UIStarmap starmap)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_01fe: Unknown result type (might be due to invalid IL or missing references)
			Camera screenCamera = starmap.screenCamera;
			SunShafts val = FindGameSunShafts();
			if ((Object)(object)screenCamera == (Object)null || (Object)(object)val == (Object)null)
			{
				DestroySunShafts();
				return;
			}
			if ((Object)(object)mapSunShafts != (Object)null && (Object)(object)mapSunShaftsCamera != (Object)(object)screenCamera)
			{
				DestroySunShafts();
			}
			if ((Object)(object)mapSunShafts == (Object)null)
			{
				mapSunShaftsCamera = screenCamera;
				mapSunShaftsSavedDepth = screenCamera.depthTextureMode;
				mapSunShafts = ((Component)screenCamera).gameObject.AddComponent<SunShafts>();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Rayons solaires de la carte activés (réglages repris de la caméra du jeu).");
			}
			UIStarmapStarObject val2 = FindMapStarObject(starmap);
			if ((Object)(object)val2 == (Object)null)
			{
				((Behaviour)mapSunShafts).enabled = false;
				return;
			}
			Transform transform = ((Component)val2).transform;
			Vector3 val3 = screenCamera.WorldToViewportPoint(transform.position);
			if (val3.z <= 0f)
			{
				((Behaviour)mapSunShafts).enabled = false;
				return;
			}
			mapSunShafts.sunShaftsShader = val.sunShaftsShader;
			mapSunShafts.simpleClearShader = val.simpleClearShader;
			mapSunShafts.resolution = val.resolution;
			mapSunShafts.screenBlendMode = val.screenBlendMode;
			mapSunShafts.radialBlurIterations = val.radialBlurIterations;
			mapSunShafts.sunThreshold = val.sunThreshold;
			Vector2 sunViewport = default(Vector2);
			((Vector2)(ref sunViewport))..ctor(val3.x, val3.y);
			float num = ((val.maxRadius > 0.01f) ? val.maxRadius : 0.75f);
			float num2 = ComputePlanetSpan(screenCamera, starmap, sunViewport, out var anyPlanet);
			if (!anyPlanet)
			{
				((Behaviour)mapSunShafts).enabled = false;
				return;
			}
			num2 = Mathf.Clamp(num2 * 4f, 0.04f, num);
			mapSunShafts.maxRadius = num2;
			mapSunShafts.sunShaftBlurRadius = val.sunShaftBlurRadius * Mathf.Clamp(num2 / num, 0.25f, 1f);
			mapSunShafts.useDepthTexture = true;
			mapSunShafts.sunTransform = transform;
			mapSunShafts.sunColor = ResolveSunShaftColor(starmap, val);
			float num3 = ((val.sunShaftIntensity > 0.01f) ? val.sunShaftIntensity : 1.15f);
			mapSunShafts.sunShaftIntensity = num3 * 1f;
			((Behaviour)mapSunShafts).enabled = true;
		}

		private Color ResolveSunShaftColor(UIStarmap starmap, SunShafts source)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0052: Unknown result type (might be due to invalid IL or missing reference