Decompiled source of Celestial Tint v1.5.2

CelestialTint.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using LethalLevelLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CelestialTint")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Test")]
[assembly: AssemblyFileVersion("1.3.3.0")]
[assembly: AssemblyInformationalVersion("1.3.3")]
[assembly: AssemblyProduct("CelestialTint")]
[assembly: AssemblyTitle("CelestialTint")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("CelestialTint", "Celestial Tint", "1.5.2")]
public class CelestialTint : BaseUnityPlugin
{
	public class CoroutineHandler : MonoBehaviour
	{
		private static CoroutineHandler _instance;

		public static CoroutineHandler Instance
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_instance == (Object)null)
				{
					_instance = new GameObject("CoroutineHandler").AddComponent<CoroutineHandler>();
					Object.DontDestroyOnLoad((Object)(object)((Component)_instance).gameObject);
				}
				return _instance;
			}
		}
	}

	internal static CTConfig ModConfig;

	private void Awake()
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		if (assemblies.Any((Assembly assembly) => assembly.FullName.StartsWith("SpaceSunShine")))
		{
			Debug.LogError((object)"[Celestial Tint] Incompatible mod found: SpaceSunShine!");
		}
		Assembly[] assemblies2 = AppDomain.CurrentDomain.GetAssemblies();
		if (assemblies2.Any((Assembly assembly) => assembly.FullName.StartsWith("SpaceShipDoor")))
		{
			Debug.LogWarning((object)"[Celestial Tint] Semi-incompatible mod found: SpaceShipDoor!");
		}
		Debug.Log((object)"[Celestial Tint] Loading complete");
		ModConfig = new CTConfig(((BaseUnityPlugin)this).Config);
		if (ModConfig.VanillaMode.Value)
		{
			VanillaMode.Initialize();
		}
		if (!ModConfig.VanillaMode.Value)
		{
			CelestialTintLoader.Initialize();
		}
		if (ModConfig.DisplayShipParts.Value)
		{
			ShipPartsLoader.Initialize();
		}
		if (ModConfig.ShipDoorAccess.Value)
		{
			ShipDoorLoader.Initialize();
		}
	}

	public static bool CheckSceneState()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		int num;
		if (SceneManager.sceneCount == 1)
		{
			Scene activeScene = SceneManager.GetActiveScene();
			num = ((((Scene)(ref activeScene)).name == "SampleSceneRelay") ? 1 : 0);
		}
		else
		{
			num = 0;
		}
		bool flag = (byte)num != 0;
		if (ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)("[Celestial Tint] " + (flag ? "In Orbit" : "Out Orbit")));
		}
		return flag;
	}

	public static async Task<bool> DelayedCheckSceneStateAsync()
	{
		await Task.Yield();
		return CheckSceneState();
	}
}
public static class CelestialTintLoader
{
	private static bool hasLoadedAssetbundle = false;

	private static List<GameObject> instantiatedPrefabs = new List<GameObject>();

	private static GameObject prefab;

	private static string assetBundleName = "OrbitPrefabBundle";

	private static string SmallAssetBundleName = "SmallOrbitPrefabBundle";

	private static AssetBundle assetBundle;

	private static AssetBundle SmallAssetBundle;

	private static Dictionary<string, string> tagVanillaNameMapping = new Dictionary<string, string>
	{
		{ "Experimentation", "Prefab_Wasteland" },
		{ "Vow", "Prefab_Valley" },
		{ "Gordion", "Prefab_Company" },
		{ "March", "Prefab_Valley" },
		{ "Adamance", "Prefab_Valley" },
		{ "Rend", "Prefab_Tundra" },
		{ "Dine", "Prefab_Tundra" },
		{ "Offense", "Prefab_Canyon" },
		{ "Assurance", "Prefab_Canyon" },
		{ "Titan", "Prefab_Tundra" },
		{ "Artifice", "Prefab_Canyon" },
		{ "Liquidation", "Prefab_Ocean" },
		{ "Embrion", "Prefab_Valley" }
	};

	private static Dictionary<string, string> tagPrefabNameMapping = new Dictionary<string, string>
	{
		{ "Desert", "Prefab_Canyon" },
		{ "Forest", "Prefab_Valley" },
		{ "Snow", "Prefab_Tundra" },
		{ "Wasteland", "Prefab_Wasteland" },
		{ "Valley", "Prefab_Valley" },
		{ "Marsh", "Prefab_Valley" },
		{ "Tundra", "Prefab_Tundra" },
		{ "Canyon", "Prefab_Canyon" },
		{ "Company", "Prefab_Company" },
		{ "Ocean", "Prefab_Ocean" },
		{ "Rocky", "Prefab_Rocky" },
		{ "Volcanic", "Prefab_Volcanic" },
		{ "Argon", "Prefab_Argon" }
	};

	private static Dictionary<string, string> fallbackPrefabNameMapping = new Dictionary<string, string>
	{
		{ "moon1", "Prefab_Wasteland" },
		{ "moon2", "Prefab_Valley" },
		{ "moon3", "Prefab_Tundra" }
	};

	public static void Initialize()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		if (CelestialTint.ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)"[Celestial Tint Loader] Loader initialized");
		}
		Harmony val = new Harmony("com.celestialtint.mod");
		val.PatchAll(typeof(CelestialTintLoader));
		LoadAssetBundle();
		SceneManager.sceneLoaded += OnSceneLoaded;
		SceneManager.sceneUnloaded += OnSceneUnloaded;
	}

	private static void LoadAssetBundle()
	{
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text = Path.Combine(directoryName, assetBundleName);
		string directoryName2 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text2 = Path.Combine(directoryName2, SmallAssetBundleName);
		if (File.Exists(text))
		{
			assetBundle = AssetBundle.LoadFromFile(text);
			hasLoadedAssetbundle = true;
			if ((Object)(object)assetBundle != (Object)null)
			{
				if (CelestialTint.ModConfig.DebugLogging.Value)
				{
					Debug.Log((object)("[Celestial Tint Loader] AssetBundle loaded successfully from path: " + text));
				}
			}
			else
			{
				Debug.LogError((object)("[Celestial Tint Loader] Failed to load AssetBundle at path: " + text));
			}
		}
		else
		{
			Debug.LogError((object)("[Celestial Tint Loader] AssetBundle not found at path: " + text));
		}
		if (File.Exists(text2))
		{
			SmallAssetBundle = AssetBundle.LoadFromFile(text2);
			if ((Object)(object)SmallAssetBundle != (Object)null)
			{
				if (CelestialTint.ModConfig.DebugLogging.Value)
				{
					Debug.Log((object)("[Celestial Tint Loader] AssetBundle loaded successfully from path: " + text2));
				}
			}
			else
			{
				Debug.LogError((object)("[Celestial Tint Loader] Failed to load AssetBundle at path: " + text2));
			}
		}
		else
		{
			Debug.LogError((object)("[Celestial Tint Loader] AssetBundle not found at path: " + text2));
		}
	}

	private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if (CelestialTint.CheckSceneState())
		{
			LoadStarmapContainerPrefab();
		}
		else
		{
			UnloadStarmapContainerPrefab();
		}
	}

	private static async void OnSceneUnloaded(Scene scene)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (await CelestialTint.DelayedCheckSceneStateAsync())
		{
			LoadStarmapContainerPrefab();
		}
		else
		{
			UnloadStarmapContainerPrefab();
		}
	}

	private static void LoadStarmapContainerPrefab()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)SmallAssetBundle != (Object)null)
		{
			prefab = SmallAssetBundle.LoadAsset<GameObject>("StarmapContainer");
			if ((Object)(object)prefab != (Object)null)
			{
				GameObject item = Object.Instantiate<GameObject>(prefab, prefab.transform.position, Quaternion.identity);
				instantiatedPrefabs.Add(item);
				if (CelestialTint.ModConfig.DebugLogging.Value)
				{
					Debug.Log((object)"[Celestial Tint Loader] Instantiated StarmapContainer prefab.");
				}
			}
			else
			{
				Debug.LogError((object)"[Celestial Tint Loader] StarmapContainer prefab not found in AssetBundle.");
			}
		}
		else
		{
			Debug.LogError((object)"[Celestial Tint Loader] AssetBundle is not loaded.");
		}
	}

	private static void UnloadStarmapContainerPrefab()
	{
		foreach (GameObject instantiatedPrefab in instantiatedPrefabs)
		{
			Object.Destroy((Object)(object)instantiatedPrefab);
		}
		instantiatedPrefabs.Clear();
		if (CelestialTint.ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)"[Celestial Tint Loader] All instantiated StarmapContainer prefabs have been destroyed.");
		}
	}

	private static void ReplaceVanillaPlanetPrefabs()
	{
		if ((Object)(object)assetBundle != (Object)null)
		{
			StartOfRound val = Object.FindObjectOfType<StartOfRound>();
			SelectableLevel[] levels = val.levels;
			foreach (SelectableLevel val2 in levels)
			{
				bool flag = false;
				if (!string.IsNullOrEmpty(CelestialTint.ModConfig.PlanetTagMappings.Value))
				{
					string[] array = CelestialTint.ModConfig.PlanetTagMappings.Value.Split(',');
					foreach (string text in array)
					{
						string[] array2 = text.Trim().Split('@');
						if (array2.Length != 2)
						{
							if (CelestialTint.ModConfig.DebugLogging.Value)
							{
								Debug.LogWarning((object)("[Celestial Tint Loader] Invalid mapping format: " + text + ". Skipping."));
							}
							continue;
						}
						string value = array2[0].Trim();
						string key = array2[1].Trim();
						string text2 = val2.PlanetName.TrimStart(' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
						if (text2.Equals(value, StringComparison.OrdinalIgnoreCase) && tagPrefabNameMapping.TryGetValue(key, out var value2))
						{
							LoadAndSetPrefab(val2, value2);
							flag = true;
							if (CelestialTint.ModConfig.DebugLogging.Value)
							{
								Debug.Log((object)("[Celestial Tint Loader] Replaced planetPrefab for " + val2.PlanetName + " with " + value2 + " based on custom mapping."));
							}
							break;
						}
					}
				}
				if (flag)
				{
					continue;
				}
				string key2 = val2.PlanetName.TrimStart(' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
				if (tagVanillaNameMapping.TryGetValue(key2, out var value3))
				{
					LoadAndSetPrefab(val2, value3);
					continue;
				}
				LoadAndSetPrefab(val2, "Prefab_Wasteland");
				if (CelestialTint.ModConfig.DebugLogging.Value)
				{
					Debug.LogWarning((object)("[Celestial Tint Loader] No fallback prefab found for level " + val2.PlanetName + ". Using default Prefab_Wasteland."));
				}
			}
			StartOfRound.Instance.ChangePlanet();
		}
		else if (!hasLoadedAssetbundle)
		{
			Debug.LogError((object)"[Celestial Tint Loader] AssetBundle is not loaded. Unable to replace prefabs.");
		}
	}

	private static void ReplaceCurrentPlanetPrefabs()
	{
		if ((Object)(object)assetBundle != (Object)null)
		{
			foreach (ExtendedLevel extendedLevel in PatchedContent.ExtendedLevels)
			{
				SelectableLevel selectableLevel = extendedLevel.SelectableLevel;
				bool flag = false;
				if (!string.IsNullOrEmpty(CelestialTint.ModConfig.PlanetTagMappings.Value))
				{
					string[] array = CelestialTint.ModConfig.PlanetTagMappings.Value.Split(',');
					foreach (string text in array)
					{
						string[] array2 = text.Trim().Split('@');
						if (array2.Length != 2)
						{
							if (CelestialTint.ModConfig.DebugLogging.Value)
							{
								Debug.LogWarning((object)("[Celestial Tint Loader] Invalid mapping format: " + text + ". Skipping."));
							}
							continue;
						}
						string value = array2[0].Trim();
						string key = array2[1].Trim();
						if (extendedLevel.NumberlessPlanetName.Equals(value) && tagPrefabNameMapping.TryGetValue(key, out var value2))
						{
							LoadAndSetPrefab(selectableLevel, value2);
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					foreach (ContentTag contentTag in ((ExtendedContent)extendedLevel).ContentTags)
					{
						if (tagPrefabNameMapping.TryGetValue(contentTag.contentTagName, out var value3))
						{
							LoadAndSetPrefab(selectableLevel, value3);
							flag = true;
							break;
						}
					}
				}
				if (flag)
				{
					continue;
				}
				if (fallbackPrefabNameMapping.TryGetValue(((Object)selectableLevel.planetPrefab).name.ToLower(), out var value4))
				{
					LoadAndSetPrefab(selectableLevel, value4);
					continue;
				}
				LoadAndSetPrefab(selectableLevel, "Prefab_Wasteland");
				if (CelestialTint.ModConfig.DebugLogging.Value)
				{
					Debug.LogWarning((object)("[Celestial Tint Loader] No fallback prefab found for level " + selectableLevel.PlanetName + ". Using default Prefab_Wasteland."));
				}
			}
			StartOfRound.Instance.ChangePlanet();
		}
		else if (!hasLoadedAssetbundle)
		{
			Debug.LogError((object)"[Celestial Tint Loader] AssetBundle is not loaded. Unable to replace prefabs.");
		}
	}

	private static void LoadAndSetPrefab(SelectableLevel selectableLevel, string prefabName)
	{
		GameObject val = assetBundle.LoadAsset<GameObject>(prefabName);
		if ((Object)(object)val != (Object)null)
		{
			selectableLevel.planetPrefab = val;
			if (CelestialTint.ModConfig.DebugLogging.Value)
			{
				Debug.Log((object)("[Celestial Tint Loader] Replaced planetPrefab for " + selectableLevel.PlanetName + " with " + prefabName));
			}
		}
		else
		{
			Debug.LogError((object)("[Celestial Tint Loader] Prefab not found in AssetBundle: " + prefabName));
		}
	}

	[HarmonyPatch(typeof(Terminal), "Start")]
	[HarmonyPostfix]
	private static void Terminal_Start_Postfix()
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		if (assemblies.Any((Assembly assembly) => assembly.FullName.StartsWith("LethalLevelLoader")))
		{
			if (CelestialTint.ModConfig.DebugLogging.Value)
			{
				Debug.Log((object)"[Celestial Tint Loader] Detected LethalLevelLoader");
			}
			ReplaceCurrentPlanetPrefabs();
		}
		else
		{
			if (CelestialTint.ModConfig.DebugLogging.Value)
			{
				Debug.Log((object)"[Celestial Tint Loader] Did not detect LethalLevelLoader");
			}
			ReplaceVanillaPlanetPrefabs();
		}
		LoadStarmapContainerPrefab();
		if ((Object)(object)assetBundle != (Object)null)
		{
			assetBundle.Unload(false);
		}
	}
}
public class CTConfig
{
	public ConfigEntry<bool> VanillaMode { get; set; }

	public ConfigEntry<string> PlanetTagMappings { get; set; }

	public ConfigEntry<bool> DisplayShipParts { get; set; }

	public ConfigEntry<bool> ShipDoorAccess { get; set; }

	public ConfigEntry<bool> DebugLogging { get; set; }

	public CTConfig(ConfigFile configFile)
	{
		VanillaMode = configFile.Bind<bool>("1. Planets", "VanillaMode", false, "Whether the outside should show the vanilla planets. Also adds in a sun object. Illusion can break when enabling ShipDoorAccess.");
		PlanetTagMappings = configFile.Bind<string>("1. Planets", "PlanetTagMappings", "", "Mappings of planet names and tags. Separate each mapping with a comma. Each mapping should be in the format 'PlanetName@TagName'. Example: Experimentation@Wasteland, Vow@Valley. Go to the Celestial Tint github wiki page for previews.");
		DisplayShipParts = configFile.Bind<bool>("2. Ship", "DisplayShipParts", false, " Whether to display ship parts in orbit. Only visible if you go outside.");
		ShipDoorAccess = configFile.Bind<bool>("2. Ship", "ShipDoorAccess", false, "Whether to door can be opened while in orbit.");
		DebugLogging = configFile.Bind<bool>("3. Debugging", "DebugLogging", false, "Whether to display debug messages. When false, Celestial Tint will not display any messages.");
	}
}
public class NightSkyController : MonoBehaviour
{
	[Header("On Planet Settings")]
	public float starBrightness = 6f;

	[Header("References")]
	public Volume stormySkyVolume;

	public Volume eclipsedSkyVolume;

	public Volume clearSkyVolume;

	private PhysicallyBasedSky sky;

	public void Awake()
	{
		SetSettings();
	}

	private void OnValidate()
	{
		SetSettings();
	}

	private void FixedUpdate()
	{
		if ((Object)(object)sky != (Object)null)
		{
			((VolumeParameter<float>)(object)sky.spaceEmissionMultiplier).value = starBrightness;
		}
		else
		{
			Debug.LogError((object)"[NightSkyController] Sky is null. Unable to set spaceEmissionMultiplier.");
		}
	}

	public void SetSettings()
	{
		if ((Object)(object)clearSkyVolume != (Object)null)
		{
			clearSkyVolume.profile.TryGet<PhysicallyBasedSky>(ref sky);
		}
		else if ((Object)(object)stormySkyVolume != (Object)null)
		{
			stormySkyVolume.profile.TryGet<PhysicallyBasedSky>(ref sky);
		}
		else if ((Object)(object)eclipsedSkyVolume != (Object)null)
		{
			eclipsedSkyVolume.profile.TryGet<PhysicallyBasedSky>(ref sky);
		}
		else
		{
			Debug.LogError((object)"[Night Sky] No Volumes where found");
		}
	}
}
public class OrbitController : MonoBehaviour
{
	[Header("In Space Settings")]
	public Vector3 sunRotateVector = new Vector3(0.0015f, 0f, 0f);

	public Vector3 planetRotateVector = new Vector3(0f, 0f, -0.0015f);

	public Vector3 planetRotateStartVector = new Vector3(0f, 0f, -10f);

	[Space]
	public Vector3 planetPosition;

	public float orbitHeight = 250000f;

	[Space]
	public float sunStartMin = 8f;

	public float sunStartMax = 15f;

	[Space]
	public GameObject meteorShower;

	public float meteorShowerChance = 3f;

	[Header("Colorization Settings")]
	public Texture2D planetTexture;

	public Color planetTint;

	public Color airTint;

	[Header("Material Settings")]
	public Material planetMaterial;

	public CustomRenderTexture planetRenderTexture;

	[Header("References")]
	public GameObject sun;

	public Volume skyVolume;

	private PhysicallyBasedSky sky;

	private void OnValidate()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		if (CelestialTint.ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)"[CT OrbitController] OnVoid called");
		}
		if ((Object)(object)planetMaterial != (Object)null)
		{
			planetMaterial.SetColor("_SurfaceColor", planetTint);
			planetMaterial.SetTexture("_SurfaceTexture", (Texture)(object)planetTexture);
			if (CelestialTint.ModConfig.DebugLogging.Value)
			{
				Debug.Log((object)"[CT OrbitController] Shader properties set successfully");
			}
		}
		else
		{
			Debug.LogError((object)"[CT OrbitController] planetMaterial is null. Cannot set shader properties.");
		}
		planetRenderTexture.Update();
		planetRenderTexture.Initialize();
	}

	private void Start()
	{
		//IL_00be: 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_00ec: 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_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		if (CelestialTint.ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)"[CT OrbitController] Awake started");
		}
		if ((Object)(object)skyVolume != (Object)null && (Object)(object)skyVolume.profile != (Object)null)
		{
			if (skyVolume.profile.TryGet<PhysicallyBasedSky>(ref sky))
			{
				if (CelestialTint.ModConfig.DebugLogging.Value)
				{
					Debug.Log((object)"[CT OrbitController] Physically Based Sky successfully obtained");
				}
				sun.transform.Rotate(Random.Range(sunStartMin, sunStartMax), 0f, 0f, (Space)1);
				((VolumeParameter<Vector3>)(object)sky.planetRotation).value = planetRotateStartVector;
				((VolumeParameter<Color>)(object)sky.airTint).value = airTint;
				((VolumeParameter<Color>)(object)sky.groundTint).value = planetTint;
				planetRenderTexture.Update();
				planetRenderTexture.Initialize();
				planetMaterial.SetColor("_SurfaceColor", planetTint);
				planetMaterial.SetTexture("_SurfaceTexture", (Texture)(object)planetTexture);
				planetPosition = new Vector3(10000000f, 0f - (((VolumeParameter<float>)(object)sky.planetaryRadius).value + orbitHeight), 0f);
				((VolumeParameter<Vector3>)(object)sky.planetCenterPosition).value = planetPosition;
				if (CelestialTint.ModConfig.DebugLogging.Value)
				{
					Vector3 value = ((VolumeParameter<Vector3>)(object)sky.planetCenterPosition).value;
					Debug.Log((object)("[CT OrbitController] Set planet center to " + ((object)(Vector3)(ref value)).ToString()));
				}
			}
			else
			{
				Debug.LogError((object)"[CT OrbitController] Physically Based Sky not found in profile");
			}
		}
		else
		{
			Debug.LogError((object)"[CT OrbitController] SkyVolume or its profile is null");
		}
		if (CelestialTint.ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)"[CT OrbitController] Awake completed");
		}
	}

	public void FixedUpdate()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		sun.transform.Rotate(sunRotateVector);
		Vector3Parameter planetRotation = sky.planetRotation;
		((VolumeParameter<Vector3>)(object)planetRotation).value = ((VolumeParameter<Vector3>)(object)planetRotation).value + planetRotateVector;
		((VolumeParameter<Vector3>)(object)sky.planetCenterPosition).value = planetPosition;
	}
}
public static class ShipDoorLoader
{
	[HarmonyPatch(typeof(HangarShipDoor), "Update")]
	private class CTDoorHangarShipDoor
	{
		private static void Prefix(HangarShipDoor __instance)
		{
			if (!__instance.buttonsEnabled)
			{
				__instance.SetDoorButtonsEnabled(true);
			}
		}
	}

	[HarmonyPatch(typeof(StartOfRound), "TeleportPlayerInShipIfOutOfRoomBounds")]
	private class CTDoorStartOfRound
	{
		private static bool Prefix(StartOfRound __instance)
		{
			return !__instance.inShipPhase;
		}
	}

	public static void Initialize()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.celestialtint.mod");
		val.PatchAll(typeof(CTDoorHangarShipDoor));
		val.PatchAll(typeof(CTDoorStartOfRound));
		if (CelestialTint.ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)"[CT ShipDoorLoader] Ship doors opened");
		}
	}
}
public static class ShipPartsLoader
{
	private static List<GameObject> spacePropsCopies = new List<GameObject>();

	private static List<string> propNames = new List<string>
	{
		"ShipLightsPost", "OutsideShipRoom", "ThrusterBackLeft", "ThrusterBackRight", "ThrusterFrontLeft", "ThrusterFrontRight", "SideMachineryLeft", "SideMachineryRight", "ShipSupportBeams", "ShipSupportBeams.001",
		"MeterBoxDevice.001"
	};

	public static void Initialize()
	{
		if (CelestialTint.ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)"[CT ShipPartsLoader] Parts Loading");
		}
		SceneManager.sceneLoaded += OnSceneLoaded;
		SceneManager.sceneUnloaded += OnSceneUnloaded;
	}

	private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (CelestialTint.CheckSceneState())
		{
			ActivateSpaceProps();
			return;
		}
		Scene activeScene = SceneManager.GetActiveScene();
		if (((Scene)(ref activeScene)).name == "SampleSceneRelay")
		{
			DeactivateSpaceProps();
		}
		else
		{
			spacePropsCopies.Clear();
		}
	}

	private static async void OnSceneUnloaded(Scene scene)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (await CelestialTint.DelayedCheckSceneStateAsync())
		{
			ActivateSpaceProps();
			return;
		}
		Scene activeScene = SceneManager.GetActiveScene();
		if (((Scene)(ref activeScene)).name == "SampleSceneRelay")
		{
			DeactivateSpaceProps();
		}
		else
		{
			spacePropsCopies.Clear();
		}
	}

	private static void ActivateSpaceProps()
	{
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		foreach (string propName in propNames)
		{
			GameObject val = spacePropsCopies.Find((GameObject c) => ((Object)c).name == propName + "_copy");
			if ((Object)(object)val != (Object)null)
			{
				val.SetActive(true);
				continue;
			}
			GameObject val2 = GameObject.Find(propName);
			if ((Object)(object)val2 != (Object)null)
			{
				val = Object.Instantiate<GameObject>(val2, val2.transform.position, val2.transform.rotation);
				((Object)val).name = propName + "_copy";
				val.SetActive(true);
				spacePropsCopies.Add(val);
			}
			else
			{
				Debug.LogError((object)("[CT ShipPartsLoader] GameObject with name '" + propName + "' not found."));
			}
		}
	}

	private static void DeactivateSpaceProps()
	{
		foreach (GameObject spacePropsCopy in spacePropsCopies)
		{
			spacePropsCopy.SetActive(false);
		}
	}
}
public static class VanillaMode
{
	private static GameObject sunCopy;

	private static string sunName = "Sun";

	public static void Initialize()
	{
		if (CelestialTint.ModConfig.DebugLogging.Value)
		{
			Debug.Log((object)"[CT VanillaMode] Parts Loading");
		}
		SceneManager.sceneLoaded += OnSceneLoaded;
		SceneManager.sceneUnloaded += OnSceneUnloaded;
	}

	private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if (CelestialTint.CheckSceneState())
		{
			ActivateSun();
		}
		else
		{
			DeactivateSun();
		}
	}

	private static async void OnSceneUnloaded(Scene scene)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (await CelestialTint.DelayedCheckSceneStateAsync())
		{
			ActivateSun();
		}
		else
		{
			DeactivateSun();
		}
	}

	private static void ActivateSun()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)sunCopy != (Object)null)
		{
			sunCopy.SetActive(true);
			EnableLightComponent(sunCopy, enable: true);
			return;
		}
		GameObject val = GameObject.Find(sunName);
		if ((Object)(object)val != (Object)null)
		{
			sunCopy = Object.Instantiate<GameObject>(val, val.transform.position, val.transform.rotation);
			((Object)sunCopy).name = sunName + "_copy";
			sunCopy.SetActive(true);
			EnableLightComponent(sunCopy, enable: true);
		}
		else
		{
			Debug.LogError((object)("[CT VanillaMode] GameObject with name '" + sunName + "' not found."));
		}
	}

	private static void DeactivateSun()
	{
		if ((Object)(object)sunCopy != (Object)null)
		{
			EnableLightComponent(sunCopy, enable: false);
			sunCopy.SetActive(false);
		}
	}

	private static void EnableLightComponent(GameObject obj, bool enable)
	{
		Light component = obj.GetComponent<Light>();
		if ((Object)(object)component != (Object)null)
		{
			((Behaviour)component).enabled = enable;
		}
		else
		{
			Debug.LogError((object)("[CT VanillaMode] No Light component found on GameObject '" + ((Object)obj).name + "'."));
		}
	}
}