Decompiled source of CelestialMapRevamp v1.1.0

CelestialMapRevamp.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.Rendering;
using UnityStandardAssets.ImageEffects;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CelestialMapRevamp;

[BepInPlugin("fr.dsp.celestialmaprevamp", "CelestialMapRevamp", "1.3.4")]
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 Quaternion stabilizedCaptureRotation;

		public bool captureRotationReady;

		public GameObject[] isolatedLayerObjects;

		public int[] isolatedOriginalLayers;

		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 animated;

		public bool Equals(PartKey other)
		{
			if ((Object)(object)mesh == (Object)(object)other.mesh && submesh == other.submesh && (Object)(object)material == (Object)(object)other.material)
			{
				return animated == other.animated;
			}
			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)) * 397) ^ (animated ? 1 : 0);
		}
	}

	private struct RemoteDynamicInstance
	{
		public int entityId;

		public Matrix4x4 baseMatrix;

		public PrefabDesc desc;
	}

	private sealed class RemoteDynamicGroup
	{
		public PartKey part;

		public readonly List<RemoteDynamicInstance> instances = new List<RemoteDynamicInstance>();
	}

	private struct RemoteLightPoint
	{
		public int entityId;

		public Vector3 localPosition;

		public float size;
	}

	private struct RemoteBeltPath
	{
		public int pathId;

		public int speed;

		public float phase;
	}

	private sealed class RemoteStructures
	{
		public int planetId;

		public Transform simTransform;

		public GPUInstancingManager nativeManager;

		public ComputeBuffer nativeEntityAnimBuffer;

		public int nativeEntityAnimCapacity;

		public bool nativeAnimationInitialized;

		public ComputeBuffer nativeEntitySignBuffer;

		public int nativeEntitySignCapacity;

		public Material nativeEntitySignMaterial;

		public int nativeRendererCount;

		public bool nativeRenderLogged;

		public bool nativeFailureLogged;

		public int lastNativeDroneCount = -1;

		public int lastNativeCourierCount = -1;

		public int lastCombatEffectCount = -1;

		public float nextActivityDiagnostic;

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

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

		public List<RemoteDynamicGroup> dynamicGroups = new List<RemoteDynamicGroup>();

		public List<RemoteLightPoint> lightPoints = new List<RemoteLightPoint>();

		public List<RemoteBeltPath> beltPaths = new List<RemoteBeltPath>();

		public Mesh beltCargoDynamicMesh;

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

		public readonly List<Color> beltCargoColors = new List<Color>();

		public readonly List<int> beltCargoTriangles = new List<int>();

		public bool beltCargoLogged;

		public int factoryMeshCount;

		public int structureCount;

		public int dynamicPartCount;

		public int beltPathCount;

		public int builtEntityCursor;

		public float builtAt;
	}

	private sealed class RemoteShaderState
	{
		public Vector4 sunDir;

		public Color sunset0;

		public Color sunset1;

		public Color sunset2;

		public Color ambient0;

		public Color ambient1;

		public Color ambient2;

		public Color water0;

		public Color water1;

		public Color water2;

		public Color biomo0;

		public Color biomo1;

		public Color biomo2;

		public Color custom0;

		public Color custom1;

		public Color custom2;

		public Color custom3;

		public Color ground;

		public float radius;

		public float ionHeight;

		public float whiteMode;

		public Texture reflection;

		public Vector4 lightDirection;

		public Color lightColor;
	}

	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.3.4";

	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 const int RemotePlanetCaptureLayer = 29;

	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<bool> cfgBeltCargoPlaceholders;

	private ConfigEntry<float> cfgBeltCargoSpeedMultiplier;

	private ConfigEntry<int> cfgMaxStructures;

	private ConfigEntry<int> cfgStructureDetail;

	private ConfigEntry<bool> cfgAnimatedStructures;

	private ConfigEntry<bool> cfgStructureLights;

	private ConfigEntry<float> cfgSunlightIntensity;

	private ConfigEntry<bool> cfgRemoteTraffic;

	private ConfigEntry<bool> cfgCombatEffects;

	private ConfigEntry<int> cfgMaxDynamicObjects;

	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, PlanetSimulator> remotePlanetSimulators = new Dictionary<int, PlanetSimulator>();

	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 StarData loadedViewStar;

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

	private float nextRemoteLoadMaintenance;

	private float nextRemoteLoadStatusLog;

	private bool remoteSystemReadyLogged;

	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 readonly Matrix4x4[] dynamicDrawMatrices = (Matrix4x4[])(object)new Matrix4x4[1023];

	private GameObject remoteSunRoot;

	private Light remoteSunLight;

	private Mesh activityDiscMesh;

	private Mesh activityBeamMesh;

	private Material activityGlowMaterial;

	private Material activityLaserMaterial;

	private Material activityTrailMaterial;

	private Material beltCargoMaterial;

	private Texture2D beltTexture;

	private MaterialPropertyBlock dynamicPropertyBlock;

	private CommandBuffer nativeOverlayCommands;

	private static readonly FieldInfo ObjectRendererInstBufferField = AccessTools.Field(typeof(ObjectRenderer), "instBuffer");

	private static readonly FieldInfo ObjectRendererKernelField = AccessTools.Field(typeof(ObjectRenderer), "csKernelId");

	private static readonly FieldInfo ObjectRendererThreadsField = AccessTools.Field(typeof(ObjectRenderer), "csThreads");

	private static readonly FieldInfo InserterPoseBufferField = AccessTools.Field(typeof(InserterRenderer), "pose2Buffer");

	private static readonly FieldInfo LabStateBufferField = AccessTools.Field(typeof(LabRenderer), "stateBuffer");

	private static readonly FieldInfo DynamicExtraBufferField = AccessTools.Field(typeof(DynamicRenderer), "extraBuffer");

	private static readonly FieldInfo DroneBufferField = AccessTools.Field(typeof(LogisticDroneRenderer), "dronesBuffer");

	private static readonly FieldInfo DroneMaterialsField = AccessTools.Field(typeof(LogisticDroneRenderer), "droneMats");

	private static readonly FieldInfo DroneMeshField = AccessTools.Field(typeof(LogisticDroneRenderer), "droneMesh");

	private static readonly FieldInfo DroneCountField = AccessTools.Field(typeof(LogisticDroneRenderer), "droneCount");

	private static readonly FieldInfo DroneArgsField = AccessTools.Field(typeof(LogisticDroneRenderer), "argBuffer");

	private static readonly FieldInfo CourierBufferField = AccessTools.Field(typeof(LogisticCourierRenderer), "couriersBuffer");

	private static readonly FieldInfo CourierMaterialsField = AccessTools.Field(typeof(LogisticCourierRenderer), "courierMats");

	private static readonly FieldInfo CourierMeshField = AccessTools.Field(typeof(LogisticCourierRenderer), "courierMesh");

	private static readonly FieldInfo CourierCountField = AccessTools.Field(typeof(LogisticCourierRenderer), "courierCount");

	private static readonly FieldInfo CourierArgsField = AccessTools.Field(typeof(LogisticCourierRenderer), "argBuffer");

	private static readonly int AnimTimeId = Shader.PropertyToID("_AnimTime");

	private static readonly int AnimStateId = Shader.PropertyToID("_AnimState");

	private static readonly int AnimPowerId = Shader.PropertyToID("_AnimPower");

	private static readonly int StateId = Shader.PropertyToID("_State");

	private static readonly int PowerId = Shader.PropertyToID("_Power");

	private static readonly int[] BeltCargoCubeIndices = new int[36]
	{
		0, 2, 1, 0, 3, 2, 4, 5, 6, 4,
		6, 7, 0, 1, 5, 0, 5, 4, 3, 7,
		6, 3, 6, 2, 1, 2, 6, 1, 6, 5,
		0, 4, 7, 0, 7, 3
	};

	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_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Expected O, but got Unknown
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Expected O, but got Unknown
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Expected O, but got Unknown
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Expected O, but got Unknown
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Expected O, but got Unknown
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Expected O, but got Unknown
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		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 inside each planet camera through an independent copy of DSP's native GPU renderer. 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.");
		cfgBeltCargoPlaceholders = ((BaseUnityPlugin)this).Config.Bind<bool>("Structures", "BeltCargoPlaceholders", true, "Animate small brown non-emissive placeholder cubes along the real paths of remote conveyor belts.");
		cfgBeltCargoSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Structures", "BeltCargoSpeedMultiplier", 12f, new ConfigDescription("Travel-speed multiplier for remote placeholder cargo cubes. The default is deliberately very fast; lower it if you prefer slower traffic.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 50f), Array.Empty<object>()));
		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>()));
		cfgAnimatedStructures = ((BaseUnityPlugin)this).Config.Bind<bool>("Structures", "AnimatedStructures", true, "Feed the live factory AnimData to remote native building shaders: rotors, mechanisms, sorter arms and turret heads.");
		cfgStructureLights = ((BaseUnityPlugin)this).Config.Bind<bool>("Structures", "StructureLights", true, "Keep the native powered/emissive building materials and add small visibility lights on remote factories.");
		cfgSunlightIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Structures", "SunlightIntensity", 1f, new ConfigDescription("Intensity multiplier for the directional sunlight applied to remote structures. Direction and colour come from the viewed planet's real star.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
		cfgRemoteTraffic = ((BaseUnityPlugin)this).Config.Bind<bool>("Activity", "PlanetDrones", true, "Show active logistics drones and delivery couriers on remote planets.");
		cfgCombatEffects = ((BaseUnityPlugin)this).Config.Bind<bool>("Activity", "CombatEffects", true, "Show remote turret missiles, laser beams and the main visible projectile trails.");
		cfgMaxDynamicObjects = ((BaseUnityPlugin)this).Config.Bind<int>("Activity", "MaxDynamicObjectsPerPlanet", 4096, new ConfigDescription("Safety cap for animated submeshes, lights, drones, couriers and combat effects prepared for one remote planet.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(128, 20000), 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.3.4 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);
				if (starmap.viewStarSystem != null)
				{
					MaintainRemoteSystemLoading(starmap.viewStarSystem);
					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;
		int num = viewStarSystem?.id ?? 0;
		if (num == loadedViewStarId)
		{
			return;
		}
		StarData star = loadedViewStar;
		DestroyAllImpostors();
		DestroyAllRemoteStructures();
		DestroyRemoteActivityResources();
		DestroyBeltMaterial();
		modelPartCache.Clear();
		ForgetRemoteSimulators(star);
		ReleaseRequestedRemoteSystem(star);
		loadedViewStarId = num;
		loadedViewStar = viewStarSystem;
		diagnosticsPending = true;
		nextRemoteLoadMaintenance = 0f;
		nextRemoteLoadStatusLog = Time.unscaledTime + 1f;
		remoteSystemReadyLogged = false;
		if (viewStarSystem == null)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Vue détaillée libérée : aucun système sélectionné.");
			return;
		}
		try
		{
			for (int i = 0; i < viewStarSystem.planetCount; i++)
			{
				PlanetData val = viewStarSystem.planets[i];
				if (val != null && !val.loaded && !val.loading)
				{
					modRequestedPlanetIds.Add(val.id);
				}
			}
			PlanetModelingManager.RequestLoadStar(viewStarSystem);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Système détaillé actif : " + viewStarSystem.displayName + ". Les ressources visuelles du système précédent ont été libérées."));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Chargement du système impossible : " + ex.Message));
		}
	}

	private void MaintainRemoteSystemLoading(StarData star)
	{
		if (star == null || star != loadedViewStar || Time.unscaledTime < nextRemoteLoadMaintenance)
		{
			return;
		}
		nextRemoteLoadMaintenance = Time.unscaledTime + 0.5f;
		int num = 0;
		StringBuilder stringBuilder = null;
		for (int i = 0; i < star.planetCount; i++)
		{
			PlanetData val = star.planets[i];
			if (val == null)
			{
				continue;
			}
			if (!val.loaded)
			{
				if (star != GameMain.localStar)
				{
					modRequestedPlanetIds.Add(val.id);
				}
				try
				{
					PlanetModelingManager.RequestLoadPlanet(val);
				}
				catch (Exception ex)
				{
					WarnOnce(-300000 - val.id, "requête de terrain impossible pour " + val.displayName + " : " + ex.Message);
				}
			}
			PlanetSimulator val2 = FindPlanetSimulatorForMap(val);
			if (val.loaded && (Object)(object)val2 != (Object)null)
			{
				num++;
				continue;
			}
			if (stringBuilder == null)
			{
				stringBuilder = new StringBuilder();
			}
			else
			{
				stringBuilder.Append(" ; ");
			}
			stringBuilder.Append(val.displayName).Append("[loaded=").Append(val.loaded)
				.Append(", loading=")
				.Append(val.loading)
				.Append(", wanted=")
				.Append(val.wanted)
				.Append(", objet=")
				.Append((Object)(object)val.gameObject != (Object)null)
				.Append(", sim=")
				.Append((Object)(object)val2 != (Object)null)
				.Append(']');
		}
		if (num >= star.planetCount)
		{
			if (!remoteSystemReadyLogged)
			{
				remoteSystemReadyLogged = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Rendu réel distant prêt pour " + star.displayName + " : " + num + "/" + star.planetCount + " planètes."));
			}
		}
		else if (Time.unscaledTime >= nextRemoteLoadStatusLog)
		{
			nextRemoteLoadStatusLog = Time.unscaledTime + 5f;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Chargement du rendu réel de " + star.displayName + " : " + num + "/" + star.planetCount + " prêtes" + ((stringBuilder != null) ? (" | " + stringBuilder) : "")));
		}
	}

	private void RememberRemoteSimulator(PlanetSimulator sim, PlanetData planet)
	{
		if (!((Object)(object)sim == (Object)null) && planet != null && planet.star != null)
		{
			remotePlanetSimulators[planet.id] = sim;
		}
	}

	private void ForgetRemoteSimulators(StarData star)
	{
		if (star == null)
		{
			return;
		}
		for (int i = 0; i < star.planetCount; i++)
		{
			PlanetData val = star.planets[i];
			if (val != null)
			{
				remotePlanetSimulators.Remove(val.id);
			}
		}
	}

	private void ReleaseRequestedRemoteSystem(StarData star)
	{
		if (star == null)
		{
			return;
		}
		bool flag = star == GameMain.localStar;
		for (int i = 0; i < star.planetCount; i++)
		{
			PlanetData val = star.planets[i];
			if (val == null || !modRequestedPlanetIds.Remove(val.id) || flag)
			{
				continue;
			}
			try
			{
				if (val.loading)
				{
					val.wanted = false;
				}
				else if (val.loaded)
				{
					val.Unload();
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Déchargement visuel de " + val.displayName + " 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)FindPlanetSimulatorForMap(val.planet) != (Object)null;
					bool flag2 = !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 || flag2 || (!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_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Expected O, but got Unknown
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Expected O, but got Unknown
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_0386: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Expected O, but got Unknown
		//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_040e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0415: Expected O, but got Unknown
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Expected O, but got Unknown
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: 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_00da: 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_00e8: 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_04d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04da: Expected O, but got Unknown
		//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0522: Unknown result type (might be due to invalid IL or missing references)
		//IL_0527: Unknown result type (might be due to invalid IL or missing references)
		//IL_052e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_059a: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a1: Expected O, but got Unknown
		//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0601: Expected O, but got Unknown
		//IL_0626: Unknown result type (might be due to invalid IL or missing references)
		//IL_0659: Unknown result type (might be due to invalid IL or missing references)
		PlanetImpostor planetImpostor = new PlanetImpostor();
		planetImpostor.ui = ui;
		try
		{
			PlanetSimulator val = FindPlanetSimulatorForMap(ui.planet);
			if ((Object)(object)val == (Object)null)
			{
				WarnOnce(ui.planet.id, "aucun simulateur pour " + ui.planet.displayName);
				planetImpostor.failed = true;
				return planetImpostor;
			}
			RefreshMapPlanetSimulator(val, ui.planet);
			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;
			((Texture)val3).filterMode = (FilterMode)1;
			((Texture)val3).wrapMode = (TextureWrapMode)1;
			val3.useMipMap = false;
			val3.autoGenerateMips = false;
			((Texture)val3).anisoLevel = 0;
			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.allowDynamicResolution = false;
			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_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: 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_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: 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)
		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;
		PlanetData planet = imp.ui.planet;
		Vector3 val = transform.position;
		Vector3 val2 = ((Component)screenCamera).transform.position - val;
		if (planet != null)
		{
			val = VectorLF3.op_Implicit((planet.uPosition - starmap.viewTargetUPos) * 0.00025);
			val2 = VectorLF3.op_Implicit((starmap.screenCameraUPos - planet.uPosition) * 0.00025);
		}
		transform2.position = val;
		transform2.localScale = new Vector3(num4, num4, num4);
		Vector3 val3 = val2;
		if (((Vector3)(ref val3)).sqrMagnitude > 1E-06f)
		{
			transform2.rotation = Quaternion.LookRotation(-((Vector3)(ref val3)).normalized, ((Component)screenCamera).transform.up);
		}
		float magnitude = ((Vector3)(ref val3)).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;
		}
		float num6 = num4 * (float)screenCamera.pixelHeight / (2f * magnitude * num5);
		int num7 = Mathf.Clamp(cfgImpostorResolution.Value, 256, 8192);
		int width = ((Texture)imp.texture).width;
		float num8 = num6 * 1.5f;
		int num9 = width;
		if (width > num7)
		{
			num9 = num7;
		}
		else if (num8 > (float)width * 1.2f || num8 < (float)width * 0.45f)
		{
			num9 = Mathf.NextPowerOfTwo(Mathf.Max(1, Mathf.CeilToInt(num8)));
			num9 = Mathf.Clamp(num9, 256, num7);
		}
		int num10 = ((num9 >= 4096) ? 1 : ((num9 >= 2048) ? 2 : 4));
		if (width == num9 && imp.texture.antiAliasing == num10)
		{
			return;
		}
		try
		{
			imp.texture.Release();
			((Texture)imp.texture).width = num9;
			((Texture)imp.texture).height = num9;
			imp.texture.antiAliasing = num10;
			imp.texture.Create();
		}
		catch
		{
		}
	}

	private PlanetSimulator FindPlanetSimulatorForMap(PlanetData planet)
	{
		if (planet == null || !planet.loaded || planet.loading)
		{
			return null;
		}
		try
		{
			UniverseSimulator universeSimulator = GameMain.universeSimulator;
			PlanetSimulator value = (((Object)(object)universeSimulator != (Object)null) ? universeSimulator.FindPlanetSimulator(planet) : null);
			if ((Object)(object)value != (Object)null)
			{
				return value;
			}
			if (remotePlanetSimulators.TryGetValue(planet.id, out value))
			{
				if ((Object)(object)value != (Object)null && value.planetData == planet)
				{
					return value;
				}
				remotePlanetSimulators.Remove(planet.id);
			}
			GameObject gameObject = planet.gameObject;
			value = (((Object)(object)gameObject != (Object)null) ? gameObject.GetComponent<PlanetSimulator>() : null);
			if ((Object)(object)value != (Object)null)
			{
				RememberRemoteSimulator(value, planet);
				return value;
			}
			PlanetSimulator[] array = Resources.FindObjectsOfTypeAll<PlanetSimulator>();
			for (int i = 0; i < array.Length; i++)
			{
				value = array[i];
				if ((Object)(object)value != (Object)null && value.planetData == planet)
				{
					RememberRemoteSimulator(value, planet);
					return value;
				}
			}
			return null;
		}
		catch
		{
			return null;
		}
	}

	private static void RefreshMapPlanetSimulator(PlanetSimulator sim, PlanetData planet)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)sim == (Object)null || planet == null || planet.star == GameMain.localStar || GameMain.mainPlayer == null || (Object)(object)GameCamera.main == (Object)null)
		{
			return;
		}
		try
		{
			if (!((Component)sim).gameObject.activeSelf)
			{
				((Component)sim).gameObject.SetActive(true);
			}
			sim.UpdateUniversalPosition(GameMain.mainPlayer.uPosition, ((Component)GameCamera.main).transform.position);
		}
		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 static bool BeginIsolatedRemoteCapture(PlanetImpostor imp)
	{
		if (imp == null || (Object)(object)imp.sim == (Object)null)
		{
			return false;
		}
		bool flag = imp.isolatedLayerObjects == null || imp.isolatedOriginalLayers == null || imp.isolatedLayerObjects.Length != imp.isolatedOriginalLayers.Length;
		if (!flag)
		{
			for (int i = 0; i < imp.isolatedLayerObjects.Length; i++)
			{
				if ((Object)(object)imp.isolatedLayerObjects[i] == (Object)null)
				{
					flag = true;
					break;
				}
			}
		}
		if (flag)
		{
			Renderer[] componentsInChildren = ((Component)imp.sim).GetComponentsInChildren<Renderer>(true);
			List<GameObject> list = new List<GameObject>(componentsInChildren.Length);
			HashSet<int> hashSet = new HashSet<int>();
			foreach (Renderer val in componentsInChildren)
			{
				GameObject val2 = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : null);
				if ((Object)(object)val2 != (Object)null && hashSet.Add(((Object)val2).GetInstanceID()))
				{
					list.Add(val2);
				}
			}
			imp.isolatedLayerObjects = list.ToArray();
			imp.isolatedOriginalLayers = new int[imp.isolatedLayerObjects.Length];
		}
		int num = 0;
		try
		{
			for (int k = 0; k < imp.isolatedLayerObjects.Length; k++)
			{
				GameObject val3 = imp.isolatedLayerObjects[k];
				if (!((Object)(object)val3 == (Object)null))
				{
					imp.isolatedOriginalLayers[k] = val3.layer;
					val3.layer = 29;
					num = k + 1;
				}
			}
			return true;
		}
		catch
		{
			for (int l = 0; l < num; l++)
			{
				GameObject val4 = imp.isolatedLayerObjects[l];
				if ((Object)(object)val4 != (Object)null)
				{
					val4.layer = imp.isolatedOriginalLayers[l];
				}
			}
			throw;
		}
	}

	private static void EndIsolatedRemoteCapture(PlanetImpostor imp)
	{
		if (imp == null || imp.isolatedLayerObjects == null || imp.isolatedOriginalLayers == null)
		{
			return;
		}
		int num = Math.Min(imp.isolatedLayerObjects.Length, imp.isolatedOriginalLayers.Length);
		for (int i = 0; i < num; i++)
		{
			GameObject val = imp.isolatedLayerObjects[i];
			if ((Object)(object)val != (Object)null)
			{
				val.layer = imp.isolatedOriginalLayers[i];
			}
		}
	}

	private static void PrepareStableRemotePlanetVisual(PlanetSimulator sim, PlanetData planet, Camera camera, float cameraDistance)
	{
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Unknown result type (might be due to invalid IL or missing references)
		//IL_0306: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: 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_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_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)sim == (Object)null || planet == null || (Object)(object)camera == (Object)null)
		{
			return;
		}
		Transform transform = ((Component)sim).transform;
		Vector3 val = planet.runtimeLocalSunDirection;
		if (((Vector3)(ref val)).sqrMagnitude < 1E-06f && planet.star != null)
		{
			Vector3 val2 = VectorLF3.op_Implicit(planet.star.uPosition - planet.uPosition);
			val = Quaternion.Inverse(planet.runtimeRotation) * val2;
		}
		if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
		{
			val = Vector3.forward;
		}
		Vector3 val3 = transform.TransformDirection(((Vector3)(ref val)).normalized);
		Quaternion rotation = transform.rotation;
		Vector4 val4 = default(Vector4);
		((Vector4)(ref val4))..ctor(rotation.x, rotation.y, rotation.z, rotation.w);
		if (sim.surfaceRenderer != null)
		{
			for (int i = 0; i < sim.surfaceRenderer.Length; i++)
			{
				Renderer val5 = sim.surfaceRenderer[i];
				Material val6 = (((Object)(object)val5 != (Object)null) ? val5.sharedMaterial : null);
				if (!((Object)(object)val6 == (Object)null))
				{
					val6.SetVector("_SunDir", Vector4.op_Implicit(val3));
					val6.SetVector("_Rotation", val4);
					val6.SetFloat("_Distance", cameraDistance);
				}
			}
		}
		if ((Object)(object)sim.reformMat0 != (Object)null)
		{
			sim.reformMat0.SetVector("_SunDir", Vector4.op_Implicit(val3));
			sim.reformMat0.SetVector("_Rotation", val4);
			sim.reformMat0.SetFloat("_Distance", cameraDistance);
		}
		if ((Object)(object)sim.reformMat1 != (Object)null)
		{
			sim.reformMat1.SetVector("_SunDir", Vector4.op_Implicit(val3));
			sim.reformMat1.SetVector("_Rotation", val4);
			sim.reformMat1.SetFloat("_Distance", cameraDistance);
		}
		if ((Object)(object)sim.cloudSimulator != (Object)null)
		{
			sim.cloudSimulator.OnLateUpdate();
		}
		Transform atmoTrans = sim.atmoTrans0;
		Transform atmoTrans2 = sim.atmoTrans1;
		if (!((Object)(object)atmoTrans == (Object)null) && !((Object)(object)atmoTrans2 == (Object)null))
		{
			atmoTrans.rotation = ((Component)camera).transform.rotation;
			atmoTrans2.localPosition = Vector3.zero;
			atmoTrans2.localRotation = Quaternion.identity;
			atmoTrans2.localScale = Vector3.one * (planet.realRadius * 5f);
			Vector4 atmoMatRadiusParam = sim.atmoMatRadiusParam;
			Vector3 position = ((Component)camera).transform.position;
			Vector3 localSurface = ((Vector3)(ref position)).normalized * planet.realRadius;
			float intensity = Mathf.Clamp01(8000f / Mathf.Max(0.001f, cameraDistance));
			float distanceControl = Mathf.Max(0f, cameraDistance / 6000f - 1f);
			float sunrisePower = Mathf.Max(60f, (cameraDistance - planet.realRadius * 2f) * 0.18f);
			StarSimulator star = null;
			try
			{
				UniverseSimulator universeSimulator = GameMain.universeSimulator;
				star = (((Object)(object)universeSimulator != (Object)null && planet.star != null) ? universeSimulator.FindStarSimulator(planet.star) : null);
			}
			catch
			{
			}
			ConfigureStableAtmosphereMaterial(sim.atmoMat, atmoMatRadiusParam, val3, localSurface, sunrisePower, intensity, distanceControl, star, late: false);
			ConfigureStableAtmosphereMaterial(sim.atmoMatLate, atmoMatRadiusParam, val3, localSurface, sunrisePower, intensity, distanceControl, star, late: true);
		}
	}

	private static void ConfigureStableAtmosphereMaterial(Material material, Vector4 radii, Vector3 worldSun, Vector3 localSurface, float sunrisePower, float intensity, float distanceControl, StarSimulator star, bool late)
	{
		//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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: 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)
		if (!((Object)(object)material == (Object)null))
		{
			material.SetVector("_PlanetPos", Vector4.op_Implicit(Vector3.zero));
			material.SetVector("_SunDir", Vector4.op_Implicit(worldSun));
			material.SetVector("_PlanetRadius", radii);
			material.SetVector("_LocalPos", Vector4.op_Implicit(localSurface));
			material.SetFloat("_SunRiseScatterPower", sunrisePower);
			material.SetFloat("_IntensityControl", intensity);
			material.SetFloat("_DistanceControl", distanceControl);
			if ((Object)(object)star != (Object)null)
			{
				material.SetColor("_Color4", star.sunAtmosColor);
				material.SetColor("_Sky4", star.sunriseAtmosColor);
			}
			material.renderQueue = 2989;
			if (late)
			{
				material.SetInt("_StencilRef", 0);
				material.SetInt("_StencilComp", 1);
			}
		}
	}

	private void RenderImpostor(PlanetImpostor imp, UIStarmap starmap)
	{
		//IL_050f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0522: Unknown result type (might be due to invalid IL or missing references)
		//IL_052b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0534: Unknown result type (might be due to invalid IL or missing references)
		//IL_054b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0553: Unknown result type (might be due to invalid IL or missing references)
		//IL_055b: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_0076: 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_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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_00c2: 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_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: 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_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: 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_01af: 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_01b3: 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_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d1: 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_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_040e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0413: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0444: Unknown result type (might be due to invalid IL or missing references)
		//IL_0446: Unknown result type (might be due to invalid IL or missing references)
		//IL_044b: Unknown result type (might be due to invalid IL or missing references)
		//IL_044d: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c4: 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;
		}
		RefreshMapPlanetSimulator(imp.sim, planet);
		bool flag = planet.star != GameMain.localStar;
		Vector3 localPosition = transform.localPosition;
		Quaternion localRotation = transform.localRotation;
		Vector3 localScale = transform.localScale;
		bool flag2 = false;
		if (flag)
		{
			transform.position = Vector3.zero;
			transform.localScale = Vector3.one;
		}
		try
		{
			if (flag)
			{
				flag2 = BeginIsolatedRemoteCapture(imp);
			}
			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 (flag)
			{
				VectorLF3 val2 = starmap.screenCameraUPos - planet.uPosition;
				if (((VectorLF3)(ref val2)).sqrMagnitude > 1E-06)
				{
					val = VectorLF3.op_Implicit(((VectorLF3)(ref val2)).normalized);
				}
			}
			if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
			{
				val = -((Component)screenCamera).transform.forward;
			}
			((Vector3)(ref val)).Normalize();
			Quaternion val3 = transform.rotation * Quaternion.Inverse(((Component)planetRenderer).transform.rotation);
			Vector3 val4 = val3 * val;
			Vector3 val5 = val3 * ((Component)screenCamera).transform.up;
			Quaternion val6 = Quaternion.LookRotation(-val4, val5);
			Quaternion val7 = val6;
			if (flag)
			{
				float num3 = Quaternion.Angle(imp.stabilizedCaptureRotation, val6);
				if (!imp.captureRotationReady || num3 > 15f)
				{
					imp.stabilizedCaptureRotation = val6;
					imp.captureRotationReady = true;
				}
				else
				{
					float num4 = (((Object)(object)imp.texture != (Object)null) ? Mathf.Max(256f, (float)((Texture)imp.texture).height) : 512f);
					float num5 = 20f / num4;
					float num6 = num5 * 0.15f;
					if (num3 > num6)
					{
						float num7 = ((num3 > num5 * 4f) ? 32f : 8f);
						float num8 = 1f - Mathf.Exp((0f - num7) * Mathf.Max(0.0001f, Time.unscaledDeltaTime));
						imp.stabilizedCaptureRotation = Quaternion.Slerp(imp.stabilizedCaptureRotation, val6, Mathf.Clamp01(num8));
					}
				}
				val7 = imp.stabilizedCaptureRotation;
				val4 = -(val7 * Vector3.forward);
				val5 = val7 * Vector3.up;
			}
			float num9 = 0.17453292f;
			float num10 = num2 / (Mathf.Tan(num9) * Mathf.Max(0.05f, imp.builtBodyFraction));
			Vector3 position = transform.position;
			Transform transform2 = ((Component)imp.camera).transform;
			transform2.position = position + val4 * num10;
			transform2.rotation = val7;
			int num11 = (flag ? 29 : GetStructureLayer());
			imp.camera.cullingMask = (flag ? 536870912 : impostorFrameMask);
			imp.camera.nearClipPlane = Mathf.Max(0.05f, num10 - num2 * 1.35f);
			imp.camera.farClipPlane = num10 + num2 * 1.35f;
			imp.camera.backgroundColor = new Color(0f, 0f, 0f, 0f);
			Transform val8 = (((Object)(object)imp.sim != (Object)null) ? imp.sim.atmoTrans0 : null);
			Quaternion rotation = Quaternion.identity;
			Transform val9 = (((Object)(object)imp.sim != (Object)null) ? imp.sim.atmoTrans1 : null);
			Vector3 localPosition2 = Vector3.zero;
			Quaternion localRotation2 = Quaternion.identity;
			Vector3 localScale2 = Vector3.one;
			if ((Object)(object)val8 != (Object)null)
			{
				rotation = val8.rotation;
			}
			if ((Object)(object)val9 != (Object)null)
			{
				localPosition2 = val9.localPosition;
				localRotation2 = val9.localRotation;
				localScale2 = val9.localScale;
			}
			if (flag)
			{
				PrepareStableRemotePlanetVisual(imp.sim, planet, imp.camera, num10);
			}
			else if ((Object)(object)val8 != (Object)null)
			{
				val8.rotation = Quaternion.LookRotation(-val4, val5);
			}
			EnableRemoteSunlight(planet, ((Component)imp.sim).transform, num11);
			bool flag3 = false;
			bool nativeTrafficActive = false;
			RemoteShaderState shaderState = null;
			try
			{
				imp.camera.ResetProjectionMatrix();
				if (planet != GameMain.localPlanet && remoteStructures.TryGetValue(planet.id, out var value))
				{
					flag3 = AttachNativeRemoteFactoryPass(planet, value, imp.camera, out shaderState, out nativeTrafficActive);
				}
				if (planet == GameMain.localPlanet)
				{
					DispatchFactoryForImpostor(planet, imp.camera, position, val4, val5, num2);
				}
				DrawRemoteStructures(planet, imp.camera, num11, flag3, nativeTrafficActive);
				imp.camera.Render();
			}
			finally
			{
				DetachNativeRemoteFactoryPass(imp.camera, flag3, shaderState);
				DisableRemoteSunlight();
				if ((Object)(object)val8 != (Object)null)
				{
					val8.rotation = rotation;
				}
				if ((Object)(object)val9 != (Object)null)
				{
					val9.localPosition = localPosition2;
					val9.localRotation = localRotation2;
					val9.localScale = localScale2;
				}
			}
		}
		finally
		{
			if (flag2)
			{
				EndIsolatedRemoteCapture(imp);
			}
			if (flag)
			{
				transform.localPosition = localPosition;
				transform.localRotation = localRotation;
				transform.localScale = localScale;
			}
		}
	}

	private void DestroyImpostor(PlanetImpostor imp)
	{
		if (imp == null)
		{
			return;
		}
		try
		{
			EndIsolatedRemoteCapture(imp);
		}
		catch
		{
		}
		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;
		}
		imp.isolatedLayerObjects = null;
		imp.isolatedOriginalLayers = 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,
						animated = false
					});
				}
			}
		}
		catch
		{
		}
		value = list.ToArray();
		modelPartCache[modelIndex] = value;
		return value;
	}

	private static PrefabDesc GetPrefabDesc(int modelIndex)
	{
		try
		{
			return (((Object)(object)LDB.models != (Object)null) ? ((ProtoSet<ModelProto>)(object)LDB.models).Select(modelIndex) : null)?.prefabDesc;
		}
		catch
		{
			return null;
		}
	}

	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))
			{
				bool animated = ignores != null && i < ignores.Length && ignores[i];
				parts.Add(new PartKey
				{
					mesh = mesh,
					submesh = i,
					material = materials[i],
					animated = animated
				});
			}
		}
	}

	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_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_00cd: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_038c: Expected O, but got Unknown
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		RemoteStructures remoteStructures = new RemoteStructures();
		remoteStructures.planetId = planet.id;
		remoteStructures.simTransform = simTransform;
		try
		{
			Dictionary<PartKey, List<Matrix4x4>> dictionary = new Dictionary<PartKey, List<Matrix4x4>>();
			Dictionary<PartKey, RemoteDynamicGroup> dictionary2 = new Dictionary<PartKey, RemoteDynamicGroup>();
			int value = cfgMaxStructures.Value;
			int value2 = cfgMaxDynamicObjects.Value;
			int num = 0;
			int num2 = 0;
			EntityData[] entityPool = planet.factory.entityPool;
			int num3 = Math.Min(planet.factory.entityCursor, entityPool.Length);
			for (int i = 1; i < num3; 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;
				}
				PrefabDesc prefabDesc = GetPrefabDesc(val.modelIndex);
				Matrix4x4 val2 = Matrix4x4.TRS(val.pos, val.rot, Vector3.one);
				for (int j = 0; j < modelParts.Length; j++)
				{
					if (modelParts[j].animated && cfgAnimatedStructures.Value && num2 < value2)
					{
						if (!dictionary2.TryGetValue(modelParts[j], out var value3))
						{
							value3 = new RemoteDynamicGroup();
							value3.part = modelParts[j];
							dictionary2.Add(modelParts[j], value3);