Decompiled source of Vertigone v1.0.2

Vertigone.dll

Decompiled 3 days ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Vertigone")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Vertigone")]
[assembly: AssemblyTitle("Vertigone")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.sanderroli.vertigone", "Fear of Heights Accessibility", "1.0.0")]
public class Vertigone : BaseUnityPlugin
{
	private ConfigEntry<bool> cfgEnabled;

	private ConfigEntry<float> cfgHeightOffset;

	private ConfigEntry<float> cfgPlaneSize;

	private ConfigEntry<float> cfgSoftEdgeRatio;

	private ConfigEntry<float> cfgAlpha;

	private ConfigEntry<KeyCode> cfgToggleKey;

	private ConfigEntry<KeyCode> cfgHUDToggleKey;

	private ConfigEntry<KeyCode> cfgHeightUpKey;

	private ConfigEntry<KeyCode> cfgHeightDownKey;

	private ConfigEntry<KeyCode> cfgPlaneSizeUpKey;

	private ConfigEntry<KeyCode> cfgPlaneSizeDownKey;

	private ConfigEntry<KeyCode> cfgSoftEdgeUpKey;

	private ConfigEntry<KeyCode> cfgSoftEdgeDownKey;

	private ConfigEntry<KeyCode> cfgOpacityUpKey;

	private ConfigEntry<KeyCode> cfgOpacityDownKey;

	private GameObject fogObject;

	private Renderer fogRenderer;

	private Material fogMaterial;

	private Camera mainCam;

	private bool showHUD = false;

	private float stepMultiplier = 1f;

	private void Awake()
	{
		cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable the fog plane");
		cfgHeightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "HeightOffset", -7f, "Vertical offset from camera");
		cfgPlaneSize = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PlaneSize", 50f, "Size of the fog plane");
		cfgSoftEdgeRatio = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SoftEdgeRatio", 0.5f, "Blend between solid center and soft edge");
		cfgAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Alpha", 1f, "Fog opacity");
		cfgToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "ToggleKey", (KeyCode)289, "Toggle fog on/off");
		cfgHUDToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "HUDToggleKey", (KeyCode)290, "Toggle fog settings HUD");
		cfgHeightUpKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "HeightUpKey", (KeyCode)273, "Raise the fog plane");
		cfgHeightDownKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "HeightDownKey", (KeyCode)274, "Lower the fog plane");
		cfgPlaneSizeUpKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "PlaneSizeUpKey", (KeyCode)0, "Increase fog size");
		cfgPlaneSizeDownKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "PlaneSizeDownKey", (KeyCode)0, "Decrease fog size");
		cfgSoftEdgeUpKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "SoftEdgeUpKey", (KeyCode)0, "Increase soft edge");
		cfgSoftEdgeDownKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "SoftEdgeDownKey", (KeyCode)0, "Decrease soft edge");
		cfgOpacityUpKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "OpacityUpKey", (KeyCode)0, "Increase fog opacity");
		cfgOpacityDownKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "OpacityDownKey", (KeyCode)0, "Decrease fog opacity");
		CreateFogObject();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Vertigone loaded");
	}

	private void CreateFogObject()
	{
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Expected O, but got Unknown
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: 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)
		if ((Object)(object)fogObject != (Object)null)
		{
			Object.Destroy((Object)(object)fogObject);
			fogObject = null;
		}
		fogObject = GameObject.CreatePrimitive((PrimitiveType)4);
		((Object)fogObject).name = "Vertigone_AccessibilityPlane";
		Collider component = fogObject.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.Destroy((Object)(object)component);
		}
		Shader val = Shader.Find("Universal Render Pipeline/Unlit");
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Unlit/Transparent");
		}
		fogMaterial = new Material(val);
		if (fogMaterial.HasProperty("_Surface"))
		{
			fogMaterial.SetFloat("_Surface", 1f);
		}
		if (fogMaterial.HasProperty("_Blend"))
		{
			fogMaterial.SetFloat("_Blend", 0f);
		}
		if (fogMaterial.HasProperty("_AlphaClip"))
		{
			fogMaterial.SetFloat("_AlphaClip", 0f);
		}
		fogMaterial.SetInt("_SrcBlend", 5);
		fogMaterial.SetInt("_DstBlend", 10);
		fogMaterial.SetInt("_ZWrite", 0);
		fogMaterial.renderQueue = 3000;
		fogMaterial.color = new Color(0.8f, 0.85f, 0.9f, cfgAlpha.Value);
		Texture2D val2 = GenerateCircularGradient();
		fogMaterial.mainTexture = (Texture)(object)val2;
		fogMaterial.mainTextureScale = new Vector2(1f, 1f);
		fogMaterial.SetTexture("_BaseMap", (Texture)(object)val2);
		fogMaterial.SetTexture("_MainTex", (Texture)(object)val2);
		fogRenderer = fogObject.GetComponent<Renderer>();
		fogRenderer.sharedMaterial = fogMaterial;
		fogRenderer.shadowCastingMode = (ShadowCastingMode)0;
		fogRenderer.receiveShadows = false;
		float num = cfgPlaneSize.Value / 10f;
		fogObject.transform.localScale = new Vector3(num, 1f, num);
		fogObject.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
		fogObject.transform.position = new Vector3(0f, -1000f, 0f);
		Object.DontDestroyOnLoad((Object)(object)fogObject);
	}

	private Texture2D GenerateCircularGradient(int size = 256)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0050: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor((float)size / 2f, (float)size / 2f);
		float num = (float)size / 2f;
		float num2 = num * cfgSoftEdgeRatio.Value;
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num3 = Vector2.Distance(val2, new Vector2((float)j, (float)i));
				float num4;
				if (num3 <= num2)
				{
					num4 = 1f;
				}
				else
				{
					float num5 = Mathf.Clamp01((num3 - num2) / (num - num2));
					num4 = Mathf.SmoothStep(1f, 0f, num5);
				}
				val.SetPixel(j, i, new Color(1f, 1f, 1f, num4));
			}
		}
		val.Apply();
		return val;
	}

	private void Update()
	{
		//IL_0007: 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)
		//IL_00b5: 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_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: 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: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_040c: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(cfgToggleKey.Value))
		{
			cfgEnabled.Value = !cfgEnabled.Value;
		}
		if (Input.GetKeyDown(cfgHUDToggleKey.Value))
		{
			showHUD = !showHUD;
		}
		stepMultiplier = (Input.GetKey((KeyCode)304) ? 2.5f : 1f);
		float num = 40f * Time.deltaTime * stepMultiplier;
		float num2 = 4f * Time.deltaTime * stepMultiplier;
		float num3 = 0.4f * Time.deltaTime * stepMultiplier;
		if (Input.GetKey(cfgHeightUpKey.Value))
		{
			cfgHeightOffset.Value = Mathf.Min(cfgHeightOffset.Value + num2, -1.5f);
		}
		if (Input.GetKey(cfgHeightDownKey.Value))
		{
			cfgHeightOffset.Value = Mathf.Max(cfgHeightOffset.Value - num2, -30f);
		}
		if (Input.GetKey(cfgPlaneSizeUpKey.Value))
		{
			cfgPlaneSize.Value = Mathf.Min(cfgPlaneSize.Value + num, 300f);
			UpdateFogScale();
		}
		if (Input.GetKey(cfgPlaneSizeDownKey.Value))
		{
			cfgPlaneSize.Value = Mathf.Max(cfgPlaneSize.Value - num, 5f);
			UpdateFogScale();
		}
		if (Input.GetKey(cfgSoftEdgeUpKey.Value))
		{
			cfgSoftEdgeRatio.Value = Mathf.Clamp01(cfgSoftEdgeRatio.Value + num3);
			UpdateFogTexture();
		}
		if (Input.GetKey(cfgSoftEdgeDownKey.Value))
		{
			cfgSoftEdgeRatio.Value = Mathf.Clamp01(cfgSoftEdgeRatio.Value - num3);
			UpdateFogTexture();
		}
		if (Input.GetKey(cfgOpacityUpKey.Value))
		{
			cfgAlpha.Value = Mathf.Clamp(cfgAlpha.Value + num3, 0.25f, 1f);
		}
		if (Input.GetKey(cfgOpacityDownKey.Value))
		{
			cfgAlpha.Value = Mathf.Clamp(cfgAlpha.Value - num3, 0.25f, 1f);
		}
		if (!cfgEnabled.Value)
		{
			if ((Object)(object)fogObject != (Object)null && fogObject.activeSelf)
			{
				fogObject.SetActive(false);
			}
			return;
		}
		if ((Object)(object)fogObject != (Object)null && !fogObject.activeSelf)
		{
			fogObject.SetActive(true);
		}
		if ((Object)(object)mainCam == (Object)null)
		{
			mainCam = Camera.main;
		}
		if ((Object)(object)mainCam != (Object)null)
		{
			Vector3 position = ((Component)mainCam).transform.position;
			fogObject.transform.position = new Vector3(position.x, position.y + cfgHeightOffset.Value, position.z);
			fogObject.transform.rotation = Quaternion.identity;
		}
		if ((Object)(object)fogMaterial != (Object)null)
		{
			Color color = fogMaterial.color;
			if (Mathf.Abs(color.a - cfgAlpha.Value) > 0.001f)
			{
				color.a = cfgAlpha.Value;
				fogMaterial.color = color;
			}
		}
		if (cfgEnabled.Value && (Object)(object)fogMaterial != (Object)null)
		{
			UpdateFogColorFromSkybox();
		}
	}

	private void UpdateFogScale()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)fogObject != (Object)null)
		{
			float num = cfgPlaneSize.Value / 10f;
			fogObject.transform.localScale = new Vector3(num, 1f, num);
		}
	}

	private void UpdateFogTexture()
	{
		if (!((Object)(object)fogMaterial == (Object)null))
		{
			Texture mainTexture = fogMaterial.mainTexture;
			Texture2D val = GenerateCircularGradient();
			fogMaterial.mainTexture = (Texture)(object)val;
			fogMaterial.SetTexture("_BaseMap", (Texture)(object)val);
			if ((Object)(object)mainTexture != (Object)null)
			{
				Object.Destroy((Object)(object)mainTexture);
			}
		}
	}

	private void UpdateFogColorFromSkybox()
	{
		//IL_0016: 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)
		//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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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)
		if (!((Object)(object)fogMaterial == (Object)null))
		{
			Color val = RenderSettings.ambientSkyColor;
			if ((Object)(object)RenderSettings.skybox != (Object)null && RenderSettings.skybox.HasProperty("_Tint"))
			{
				val = RenderSettings.skybox.GetColor("_Tint");
			}
			else if ((Object)(object)RenderSettings.skybox != (Object)null && RenderSettings.skybox.HasProperty("_SkyTint"))
			{
				val = RenderSettings.skybox.GetColor("_SkyTint");
			}
			val.a = cfgAlpha.Value;
			fogMaterial.color = Color.Lerp(fogMaterial.color, val, Time.deltaTime * 2f);
		}
	}

	private void OnGUI()
	{
		//IL_0029: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: 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_0094: Expected O, but got Unknown
		//IL_009a: 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_00ac: Expected O, but got Unknown
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		if (showHUD && cfgEnabled.Value)
		{
			GUI.color = new Color(fogMaterial.color.r, fogMaterial.color.g, fogMaterial.color.b, 0.8f);
			GUIStyle val = new GUIStyle(GUI.skin.box)
			{
				fontSize = 18,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)0,
				wordWrap = true
			};
			val.normal.textColor = Color.white;
			GUIStyle val2 = new GUIStyle(val);
			val2.normal.textColor = Color.black;
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(20f, 20f, 280f, 170f);
			GUI.Box(val3, "", val);
			GUI.Label(new Rect(((Rect)(ref val3)).x + 6f, ((Rect)(ref val3)).y + 4f, ((Rect)(ref val3)).width, ((Rect)(ref val3)).height), "Vertigone Settings\n" + $"Height Offset: {cfgHeightOffset.Value:F1}\n" + $"Plane Size: {cfgPlaneSize.Value:F1}\n" + $"Soft Edge Ratio: {cfgSoftEdgeRatio.Value:F2}\n" + $"Opacity: {cfgAlpha.Value:F2}\n\n" + "[Shift] = Faster adjustments", val);
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)fogObject != (Object)null)
		{
			Object.Destroy((Object)(object)fogObject);
		}
	}
}