Decompiled source of YvesWorkshop ULTRASKY v0.4.1

ULTRASKY.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ULTRASKY
{
	[BepInPlugin("pavel.ultrakill.ultrasky", "ULTRASKY", "0.4.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private bool panelOpen;

		private bool customEnabled;

		private string status = "Ready.";

		private string dataFolder;

		private string bundlePath;

		private AssetBundle bundle;

		private Material customSkybox;

		private Material previousSkybox;

		private bool fogEnabled;

		private bool fogSnapshotTaken;

		private bool originalFog;

		private FogMode originalFogMode;

		private Color originalFogColor;

		private float originalFogDensity;

		private float originalFogStart;

		private float originalFogEnd;

		private FogMode fogMode = (FogMode)2;

		private Color fogColor = new Color(0.55f, 0.62f, 0.72f, 1f);

		private float fogDensity = 0.015f;

		private float fogStart = 20f;

		private float fogEnd = 400f;

		private void Awake()
		{
			dataFolder = Path.Combine(Paths.PluginPath, "ULTRASKY");
			bundlePath = Path.Combine(dataFolder, "ultrasky");
			Directory.CreateDirectory(dataFolder);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ULTRASKY 0.4.0 initialized.");
		}

		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)287))
			{
				panelOpen = !panelOpen;
			}
		}

		private void OnGUI()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0146: 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_01d5: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Invalid comparison between Unknown and I4
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Invalid comparison between Unknown and I4
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			if (!panelOpen)
			{
				return;
			}
			GUI.Box(new Rect(20f, 20f, 470f, 510f), "ULTRASKY 0.4.0 - SKYBOX & WORLD FOG");
			GUI.Label(new Rect(36f, 52f, 430f, 25f), status);
			if (GUI.Button(new Rect(36f, 85f, 190f, 30f), "Load AssetBundle"))
			{
				LoadSkybox();
			}
			if (GUI.Button(new Rect(236f, 85f, 215f, 30f), customEnabled ? "Restore skybox" : "Apply skybox"))
			{
				if (customEnabled)
				{
					RestoreSkybox();
				}
				else
				{
					ApplySkybox();
				}
			}
			GUI.Label(new Rect(36f, 130f, 420f, 25f), "WORLD FOG");
			if (GUI.Button(new Rect(36f, 158f, 415f, 30f), fogEnabled ? "Disable fog / Restore original" : "Enable custom fog"))
			{
				if (fogEnabled)
				{
					DisableFog();
				}
				else
				{
					EnableFog();
				}
			}
			GUI.Label(new Rect(36f, 197f, 410f, 20f), "Mode: " + ((object)Unsafe.As<FogMode, FogMode>(ref fogMode)/*cast due to .constrained prefix*/).ToString());
			if (GUI.Button(new Rect(36f, 218f, 415f, 27f), "Cycle fog mode"))
			{
				if ((int)fogMode == 1)
				{
					fogMode = (FogMode)2;
				}
				else if ((int)fogMode == 2)
				{
					fogMode = (FogMode)3;
				}
				else
				{
					fogMode = (FogMode)1;
				}
				ApplyFog();
			}
			GUI.Label(new Rect(36f, 253f, 410f, 20f), "Fog color - RGB");
			float num = GUI.HorizontalSlider(new Rect(36f, 278f, 400f, 18f), fogColor.r, 0f, 1f);
			float num2 = GUI.HorizontalSlider(new Rect(36f, 303f, 400f, 18f), fogColor.g, 0f, 1f);
			float num3 = GUI.HorizontalSlider(new Rect(36f, 328f, 400f, 18f), fogColor.b, 0f, 1f);
			fogColor = new Color(num, num2, num3, 1f);
			GUI.Label(new Rect(36f, 350f, 410f, 20f), "Density: " + fogDensity.ToString("F3"));
			fogDensity = GUI.HorizontalSlider(new Rect(36f, 373f, 400f, 18f), fogDensity, 0.001f, 0.08f);
			GUI.Label(new Rect(36f, 394f, 410f, 20f), "Fog start: " + fogStart.ToString("F0"));
			fogStart = GUI.HorizontalSlider(new Rect(36f, 416f, 400f, 18f), fogStart, 0f, 500f);
			GUI.Label(new Rect(36f, 437f, 410f, 20f), "Fog end: " + fogEnd.ToString("F0"));
			fogEnd = GUI.HorizontalSlider(new Rect(36f, 459f, 400f, 18f), fogEnd, 50f, 2000f);
			if (GUI.Button(new Rect(36f, 482f, 415f, 28f), "Apply fog settings"))
			{
				ApplyFog();
			}
			if (fogEnabled)
			{
				ApplyFog();
			}
		}

		private void LoadSkybox()
		{
			try
			{
				if (!File.Exists(bundlePath))
				{
					throw new FileNotFoundException(bundlePath);
				}
				if ((Object)(object)bundle != (Object)null)
				{
					bundle.Unload(false);
				}
				bundle = AssetBundle.LoadFromFile(bundlePath);
				if ((Object)(object)bundle == (Object)null)
				{
					throw new Exception("AssetBundle failed to load.");
				}
				customSkybox = bundle.LoadAsset<Material>("ULTRASKY_Skybox");
				if ((Object)(object)customSkybox == (Object)null)
				{
					throw new Exception("Skybox material missing.");
				}
				status = "Native skybox loaded!";
				((BaseUnityPlugin)this).Logger.LogInfo((object)status);
			}
			catch (Exception ex)
			{
				status = "Bundle error: " + ex.Message;
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
		}

		private void ApplySkybox()
		{
			try
			{
				if ((Object)(object)customSkybox == (Object)null)
				{
					throw new Exception("Load the bundle first.");
				}
				previousSkybox = RenderSettings.skybox;
				RenderSettings.skybox = customSkybox;
				DynamicGI.UpdateEnvironment();
				customEnabled = true;
				status = "Native skybox applied!";
			}
			catch (Exception ex)
			{
				status = "Skybox error: " + ex.Message;
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
		}

		private void RestoreSkybox()
		{
			RenderSettings.skybox = previousSkybox;
			DynamicGI.UpdateEnvironment();
			customEnabled = false;
			status = "Original skybox restored.";
		}

		private void EnableFog()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			if (!fogSnapshotTaken)
			{
				originalFog = RenderSettings.fog;
				originalFogMode = RenderSettings.fogMode;
				originalFogColor = RenderSettings.fogColor;
				originalFogDensity = RenderSettings.fogDensity;
				originalFogStart = RenderSettings.fogStartDistance;
				originalFogEnd = RenderSettings.fogEndDistance;
				fogSnapshotTaken = true;
			}
			fogEnabled = true;
			ApplyFog();
			status = "World fog enabled!";
		}

		private void ApplyFog()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (fogEnabled)
			{
				RenderSettings.fog = true;
				RenderSettings.fogMode = fogMode;
				RenderSettings.fogColor = fogColor;
				RenderSettings.fogDensity = fogDensity;
				RenderSettings.fogStartDistance = fogStart;
				RenderSettings.fogEndDistance = Mathf.Max(fogStart + 1f, fogEnd);
				status = "World fog settings applied.";
			}
		}

		private void DisableFog()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (fogSnapshotTaken)
			{
				RenderSettings.fog = originalFog;
				RenderSettings.fogMode = originalFogMode;
				RenderSettings.fogColor = originalFogColor;
				RenderSettings.fogDensity = originalFogDensity;
				RenderSettings.fogStartDistance = originalFogStart;
				RenderSettings.fogEndDistance = originalFogEnd;
			}
			fogEnabled = false;
			fogSnapshotTaken = false;
			status = "Original world fog restored.";
		}

		private void OnDestroy()
		{
			if (customEnabled)
			{
				RestoreSkybox();
			}
			if (fogEnabled)
			{
				DisableFog();
			}
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(false);
				bundle = null;
			}
		}
	}
}