Decompiled source of Green Screen v1.3.0

plugins/PEAKGreenScreen.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
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("PEAKGreenScreen")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Adds green screen/blue screen to PEAK")]
[assembly: AssemblyTitle("PEAKGreenScreen")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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;
		}
	}
}
namespace PEAKGreenScreen
{
	[BepInPlugin("PEAKGreenScreen", "Green Screen", "1.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static ConfigEntry<float> configColorR;

		public static ConfigEntry<float> configColorG;

		public static ConfigEntry<float> configColorB;

		public static ConfigEntry<bool> sunLighting;

		public static ConfigEntry<float> frontLeftIntensity;

		public static ConfigEntry<float> frontLeftSpotAngle;

		public static ConfigEntry<bool> frontLeftLightActive;

		public static ConfigEntry<float> frontRightIntensity;

		public static ConfigEntry<float> frontRightSpotAngle;

		public static ConfigEntry<bool> frontRightLightActive;

		public static AssetBundle LightBundle;

		private Light frontLeftLight;

		private Light frontRightLight;

		private Renderer greenScreenRenderer1;

		private Renderer greenScreenRenderer2;

		private Renderer greenScreenRenderer3;

		private string CurrentScene = "";

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin PEAKGreenScreen is loaded!");
			Object.DontDestroyOnLoad((Object)(object)this);
			configColorR = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ColorR", 0f, "Red value for custom color (0-255).");
			configColorG = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ColorG", 255f, "Green value for custom color (0-255).");
			configColorB = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ColorB", 0f, "Blue value for custom color (0-255).");
			sunLighting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SunLighting", true, "If set to false, in the airport the sun won't have any lighting effects, good for getting that perfect shot.");
			frontLeftIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Front Left Light", "FL Intensity", 1f, "Intensity of the front left light.");
			frontLeftSpotAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Front Left Light", "FL SpotAngle", 120f, "Spot angle of the front left light.");
			frontLeftLightActive = ((BaseUnityPlugin)this).Config.Bind<bool>("Front Left Light", "FL LightActive", true, "If set to false, the front left light will be disabled.");
			frontRightIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Front Right Light", "FR Intensity", 1f, "Intensity of the front right light.");
			frontRightSpotAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Front Right Light", "FR SpotAngle", 120f, "Spot angle of the front right light.");
			frontRightLightActive = ((BaseUnityPlugin)this).Config.Bind<bool>("Front Right Light", "FR LightActive", true, "If set to false, the front right light will be disabled.");
			configColorR.SettingChanged += OnConfigSettingChanged;
			configColorG.SettingChanged += OnConfigSettingChanged;
			configColorB.SettingChanged += OnConfigSettingChanged;
			frontLeftIntensity.SettingChanged += OnConfigSettingChanged;
			frontLeftSpotAngle.SettingChanged += OnConfigSettingChanged;
			frontLeftLightActive.SettingChanged += OnConfigSettingChanged;
			frontRightIntensity.SettingChanged += OnConfigSettingChanged;
			frontRightSpotAngle.SettingChanged += OnConfigSettingChanged;
			frontRightLightActive.SettingChanged += OnConfigSettingChanged;
			configColorR.Value = Mathf.Clamp(configColorR.Value, 0f, 255f);
			configColorG.Value = Mathf.Clamp(configColorG.Value, 0f, 255f);
			configColorB.Value = Mathf.Clamp(configColorB.Value, 0f, 255f);
			sunLighting.SettingChanged += delegate
			{
				if (CurrentScene == "Airport")
				{
					GameObject val = GameObject.Find("SpecialDay Airport");
					((Component)val.transform.Find("Directional Light")).gameObject.SetActive(sunLighting.Value);
				}
			};
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			LightBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "lightbundle.atomic"));
			if ((Object)(object)LightBundle == (Object)null)
			{
				Logger.LogError((object)"Failed to load the light bundle!!");
			}
			else
			{
				Logger.LogMessage((object)"Light bundle loaded successfully.");
			}
		}

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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)
			//IL_01b2: Expected O, but got Unknown
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: 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)
			CurrentScene = ((Scene)(ref scene)).name;
			if (((Scene)(ref scene)).name == "Airport")
			{
				GameObject val = GameObject.Find("SpecialDay Airport");
				((Component)val.transform.Find("Directional Light")).gameObject.SetActive(sunLighting.Value);
				Material material = new Material(Shader.Find("Unlit/Color"));
				Material material2 = new Material(Shader.Find("W/Peak_Standard"));
				greenScreenRenderer1 = CreateCube(new Vector3(-6.3764f, 3.94f, 122.8569f), new Vector3(0.0073f, 6.9709f, 15.1f), Quaternion.Euler(0f, 90f, 0f), material, "GreenScreenPart1");
				greenScreenRenderer2 = CreateCube(new Vector3(-6.3764f, -1.76f, 122.4569f), new Vector3(16.6818f, 4.6709f, 15.1f), Quaternion.Euler(0f, 90f, 0f), material, "GreenScreenPart2");
				greenScreenRenderer3 = CreateCube(new Vector3(-6.3764f, 3.94f, 122.8669f), new Vector3(0.0073f, 6.9709f, 15.1f), Quaternion.Euler(0f, 90f, 0f), material2, "GreenScreenPart3");
				Object.Destroy((Object)(object)GameObject.Find("fence (17)"));
				Object.Destroy((Object)(object)GameObject.Find("fence (16)"));
				Object.Destroy((Object)(object)GameObject.Find("fence (15)"));
				Object.Destroy((Object)(object)GameObject.Find("fence (14)"));
				Material val2 = new Material(Shader.Find("Universal Render Pipeline/Unlit"));
				Texture2D val3 = LightBundle.LoadAsset<Texture2D>("LightTexture");
				if ((Object)(object)val3 != (Object)null)
				{
					val2.SetTexture("_BaseMap", (Texture)(object)val3);
					Logger.LogMessage((object)"LightTexture loaded and applied to material successfully.");
				}
				else
				{
					Logger.LogError((object)"Failed to load LightTexture from the asset bundle.");
				}
				frontLeftLight = CreateLight(new Vector3(-2.0073f, 1.7926f, 113.8106f), new Vector3(0.5f, 0.5f, 0.5f), Quaternion.Euler(0f, 50.3132f, 180f), "GreenScreenLight1", val2);
				frontRightLight = CreateLight(new Vector3(-10.6891f, 1.7926f, 113.8106f), new Vector3(0.5f, 0.5f, 0.5f), Quaternion.Euler(0f, 130.4433f, 180f), "GreenScreenLight2", val2);
				UpdateObjects();
			}
		}

		private void OnConfigSettingChanged(object sender, EventArgs e)
		{
			configColorR.Value = Mathf.Clamp(configColorR.Value, 0f, 255f);
			configColorG.Value = Mathf.Clamp(configColorG.Value, 0f, 255f);
			configColorB.Value = Mathf.Clamp(configColorB.Value, 0f, 255f);
			if ((Object)(object)greenScreenRenderer1 != (Object)null && (Object)(object)frontLeftLight != (Object)null)
			{
				UpdateObjects();
			}
		}

		private void UpdateObjects()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0093: 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)
			Color val = default(Color);
			((Color)(ref val))..ctor(configColorR.Value / 255f, configColorG.Value / 255f, configColorB.Value / 255f);
			greenScreenRenderer1.material.color = val;
			greenScreenRenderer1.material.SetColor("_EmissionColor", val * 10f);
			greenScreenRenderer2.material.color = val;
			greenScreenRenderer2.material.SetColor("_EmissionColor", val * 10f);
			greenScreenRenderer3.material.SetColor("_BaseColor", val);
			if ((Object)(object)frontLeftLight != (Object)null)
			{
				((Component)frontLeftLight).gameObject.SetActive(frontLeftLightActive.Value);
				frontLeftLight.intensity = frontLeftIntensity.Value;
				frontLeftLight.spotAngle = frontLeftSpotAngle.Value;
			}
			if ((Object)(object)frontRightLight != (Object)null)
			{
				((Component)frontRightLight).gameObject.SetActive(frontRightLightActive.Value);
				frontRightLight.intensity = frontRightIntensity.Value;
				frontRightLight.spotAngle = frontRightSpotAngle.Value;
			}
		}

		private Light CreateLight(Vector3 pos, Vector3 scale, Quaternion rotation, string Name, Material material)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = LightBundle.LoadAsset<GameObject>("GreenScreenLight");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)("Failed to load " + Name + " from bundle."));
				return null;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val);
			MeshRenderer component = val2.GetComponent<MeshRenderer>();
			MeshCollider val3 = val2.AddComponent<MeshCollider>();
			if ((Object)(object)material != (Object)null)
			{
				((Renderer)component).material = material;
			}
			val2.transform.position = pos;
			val2.transform.localScale = scale;
			val2.transform.rotation = rotation;
			((Object)val2).name = Name;
			val3.sharedMesh = val2.GetComponent<MeshFilter>().sharedMesh;
			val3.convex = true;
			Transform val4 = val2.transform.Find("Spot Light");
			if ((Object)(object)val4 != (Object)null)
			{
				val4.localEulerAngles = new Vector3(0f, 90f, 0f);
				Light component2 = ((Component)val4).GetComponent<Light>();
				if ((Object)(object)component2 != (Object)null)
				{
					return component2;
				}
			}
			return null;
		}

		private Renderer CreateCube(Vector3 pos, Vector3 scale, Quaternion rotation, Material material, string Name)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			Renderer component = val.GetComponent<Renderer>();
			component.material = material;
			val.transform.position = pos;
			val.transform.localScale = scale;
			val.transform.rotation = rotation;
			((Object)val).name = Name;
			return component;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PEAKGreenScreen";

		public const string PLUGIN_NAME = "Adds green screen/blue screen to PEAK";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}