Decompiled source of Green Screen v1.5.0

PEAKGreenScreen.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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
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+9873cdfa51f8ea731e5aea7d7e43296cb1cc5faf")]
[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]
	[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 PEAKGreenScreen
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.atomic.greenscreen", "PEAK Green Screen", "1.5.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<bool> sideWalls;

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

		public static AssetBundle LightBundle;

		private Light frontLeftLight;

		private Light frontRightLight;

		private Renderer greenScreenRenderer1;

		private Renderer greenScreenRenderer2;

		private Renderer greenScreenRenderer3;

		private Renderer greenScreenRenderer4;

		private Renderer greenScreenRendererSide1;

		private Renderer greenScreenRendererSide2;

		private string CurrentScene = "";

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin PEAKGreenScreen is loaded!");
			Object.DontDestroyOnLoad((Object)(object)this);
			CheckMod("tony4twentys.Airport_Remixed", ref isAirportRemixedLoaded);
			if (isAirportRemixedLoaded)
			{
				Logger.LogInfo((object)"Airport Remixed is loaded, applying compatibility settings.");
			}
			else
			{
				Logger.LogInfo((object)"Airport Remixed is not loaded. Resume normal behavior.");
			}
			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.");
			sideWalls = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Side Walls", true, "If set to true, the left and right of the green screen will have two extra walls to full enclose. May be buggy if someone without the mod walks through one.");
			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;
			sideWalls.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 (Object.op_Implicit((Object)(object)GameObject.Find("BL_Holiday")))
				{
					GameObject val = GameObject.Find("SpecialDay Airport (1)");
					((Component)val.transform.Find("Directional Light")).gameObject.SetActive(sunLighting.Value);
				}
				else
				{
					GameObject val2 = GameObject.Find("SpecialDay Airport");
					((Component)val2.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_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: 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_02d8: 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_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: 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_00ae: 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_00e8: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: 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_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			CurrentScene = ((Scene)(ref scene)).name;
			if (!(((Scene)(ref scene)).name == "Airport"))
			{
				return;
			}
			GameObject val = GameObject.Find("SpecialDay Airport");
			((Component)val.transform.Find("Directional Light")).gameObject.SetActive(sunLighting.Value);
			Material material = new Material(Shader.Find("Universal Render Pipeline/Unlit"));
			Material material2 = new Material(Shader.Find("W/Peak_Standard"));
			if (!isAirportRemixedLoaded)
			{
				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");
				if (sideWalls.Value)
				{
					greenScreenRendererSide1 = CreateCube(new Vector3(-13.9164f, 3.75f, 119.1569f), new Vector3(0.0073f, 6.9709f, 10.1f), Quaternion.Euler(0f, 180f, 180f), material, "GreenScreenSide1");
					greenScreenRendererSide2 = CreateCube(new Vector3(0.9336f, 3.75f, 119.1569f), new Vector3(0.0073f, 6.9709f, 10.1f), Quaternion.Euler(0f, 180f, 180f), material, "GreenScreenSide2");
				}
			}
			else
			{
				greenScreenRenderer1 = CreateCube(new Vector3(-27.8256f, 8.2482f, 48.777f), new Vector3(0.0073f, 15.1564f, 22.1709f), Quaternion.Euler(0f, 90f, 0f), material, "GreenScreenPart1");
				greenScreenRenderer2 = CreateCube(new Vector3(-27.6983f, -1.44f, 41.3118f), new Vector3(14.9472f, 4.6709f, 21.911f), Quaternion.Euler(0f, 90f, 0f), material, "GreenScreenPart2");
				greenScreenRenderer3 = CreateCube(new Vector3(-27.8256f, 8.2482f, 48.778f), new Vector3(0.0073f, 15.1564f, 22.1709f), Quaternion.Euler(0f, 90f, 0f), material2, "GreenScreenPart3");
				greenScreenRenderer4 = CreateCube(new Vector3(-38.6728f, 8.2482f, 44.9271f), new Vector3(0.4073f, 15.1564f, 22.1709f), Quaternion.Euler(0f, 0f, 0f), material, "GreenScreenPart4");
			}
			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.");
			}
			if (!isAirportRemixedLoaded)
			{
				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);
			}
			else
			{
				frontLeftLight = CreateLight(new Vector3(-20.8874f, 2.0162f, 33.4678f), new Vector3(0.5f, 0.5f, 0.5f), Quaternion.Euler(0f, 50.3132f, 180f), "GreenScreenLight1", val2);
				frontRightLight = CreateLight(new Vector3(-34.7994f, 2.0226f, 33.4846f), 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)
			//IL_00d1: 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_00ee: 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_01a2: 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_01be: 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_01db: 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)greenScreenRenderer4 != (Object)null)
			{
				greenScreenRenderer4.material.color = val;
				greenScreenRenderer4.material.SetColor("_EmissionColor", val * 10f);
			}
			if ((Object)(object)greenScreenRendererSide1 != (Object)null && (Object)(object)greenScreenRendererSide2 != (Object)null)
			{
				if (!sideWalls.Value)
				{
					((Component)greenScreenRendererSide1).gameObject.SetActive(false);
					((Component)greenScreenRendererSide2).gameObject.SetActive(false);
				}
				else
				{
					((Component)greenScreenRendererSide1).gameObject.SetActive(true);
					((Component)greenScreenRendererSide2).gameObject.SetActive(true);
					greenScreenRendererSide1.material.color = val;
					greenScreenRendererSide1.material.SetColor("_EmissionColor", val * 10f);
					greenScreenRendererSide2.material.color = val;
					greenScreenRendererSide2.material.SetColor("_EmissionColor", val * 10f);
				}
			}
			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 void CheckMod(string modGUID, ref bool loaded)
		{
			Chainloader.PluginInfos.TryGetValue(modGUID, out var value);
			loaded = value != null;
		}
	}
	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";
	}
}