Decompiled source of AntonzloCameras v1.0.2

Mod.dll

Decompiled 6 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AntonzloCameras.Patches;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
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: AssemblyTitle("AntonzloCameras")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AntonzloCameras")]
[assembly: AssemblyCopyright("Copyright Antonzlo ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2cee61ba-15cf-4687-8f41-c05b556dd1d2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AntonzloCameras
{
	public class Handler : MonoBehaviour
	{
		public int cameraState = 0;

		public static GameObject second;

		public void ToggleCameraState(PlayerControllerB playerControllerB)
		{
			GameObject.Find("StartGameLever").GetComponent<AudioSource>().PlayOneShot(Plugin.zoomSound);
			if (cameraState == 0)
			{
				cameraState = 1;
			}
			else if (cameraState == 1)
			{
				cameraState = 0;
			}
			else if (cameraState == 2)
			{
				cameraState = 0;
			}
			Plugin.Log.LogInfo((object)("camera: " + cameraState));
			Camera component = GameObject.Find("Environment/HangarShip/Cameras/ShipCamera").GetComponent<Camera>();
			Plugin.Log.LogInfo((object)$"Camera state: {((Behaviour)component).enabled}, {((Behaviour)component).isActiveAndEnabled}");
		}

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)GameObject.Find("MapCamera")))
			{
				if (cameraState == 0)
				{
					((Renderer)second.GetComponent<MeshRenderer>()).materials[1].mainTexture = (Texture)(object)Plugin.internalCameraRt;
				}
				else if (cameraState == 1)
				{
					((Renderer)second.GetComponent<MeshRenderer>()).materials[1].mainTexture = (Texture)(object)Plugin.externalCameraRt;
				}
				else if (cameraState != 2)
				{
				}
			}
		}
	}
	[BepInPlugin("antonzlo.AntonzloCameras", "AntonzloCameras", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "antonzlo.AntonzloCameras";

		public const string ModName = "AntonzloCameras";

		public const string ModVersion = "1.0.0";

		private readonly bool appliedMonitorChanges = false;

		public static ManualLogSource Log = Logger.CreateLogSource("antonzlo.AntonzloCameras");

		public static Plugin Instance;

		public static AssetBundle Bundle;

		public static GameObject ButtonPrefab;

		public static AudioClip zoomSound;

		public static Material ButtonMaterial;

		public static RenderTexture internalCameraRt;

		public static RenderTexture externalCameraRt;

		public static string PluginDirectory;

		private readonly Harmony harmony = new Harmony("Antonzlo.AntonzloCameras");

		private bool didLoad = false;

		private void Awake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			}
			Log.LogInfo((object)"AntonzloCameras start ok");
			PluginDirectory = ((BaseUnityPlugin)this).Info.Location;
			LoadAssets();
			Object.DontDestroyOnLoad((Object)this);
			SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
			{
				if (((Scene)(ref scene)).name != "MainMenu" && ((Scene)(ref scene)).name != "InitScene" && ((Scene)(ref scene)).name != "InitSceneLaunchOptions")
				{
					((MonoBehaviour)this).StartCoroutine(OnSceneLoaded());
				}
			};
			harmony.PatchAll(typeof(Handler));
			harmony.PatchAll(typeof(StartOfRoundPatch));
		}

		private void LoadAssets()
		{
			if (didLoad)
			{
				Log.LogInfo((object)"Already Loaded?");
				return;
			}
			try
			{
				Bundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(PluginDirectory), "antonzloAssets"));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Couldn't load asset bundle: " + ex.Message));
				return;
			}
			try
			{
				ButtonPrefab = Bundle.LoadAsset<GameObject>("CameraZoomSwitchButton.prefab");
				zoomSound = Bundle.LoadAsset<AudioClip>("zoom.wav");
				ButtonMaterial = Bundle.LoadAsset<Material>("GreenButton.mat");
				Log.LogInfo((object)"Successfully loaded assets!");
				didLoad = true;
			}
			catch (Exception ex2)
			{
				Log.LogError((object)("Couldn't load assets: " + ex2.Message));
			}
		}

		private IEnumerator OnSceneLoaded()
		{
			yield return (object)new WaitForSeconds(5f);
			if (!appliedMonitorChanges)
			{
				internalCameraRt = new RenderTexture(1280, 720, 32, (RenderTextureFormat)0);
				GameObject internalCamera = GameObject.Find("Environment/HangarShip/Cameras/ShipCamera");
				internalCamera.GetComponent<Camera>().targetTexture = internalCameraRt;
				GameObject topMonitors = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube");
				((Renderer)topMonitors.GetComponent<MeshRenderer>()).materials[2].mainTexture = (Texture)internalCameraRt;
				Log.LogInfo((object)((Renderer)topMonitors.GetComponent<MeshRenderer>()).materials.Length);
				Material[] materials = ((Renderer)topMonitors.GetComponent<MeshRenderer>()).materials;
				Material[] array = materials;
				foreach (Material material in array)
				{
					Log.LogInfo((object)(((Object)material).name + " " + ((Object)material.mainTexture).name));
				}
				externalCameraRt = new RenderTexture(1280, 720, 32, (RenderTextureFormat)0);
				GameObject externalCamera = GameObject.Find("Environment/HangarShip/Cameras/FrontDoorSecurityCam/SecurityCamera");
				externalCamera.GetComponent<Camera>().targetTexture = externalCameraRt;
				GameObject bottomMonitors = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube.001");
				Log.LogInfo((object)((Renderer)bottomMonitors.GetComponent<MeshRenderer>()).materials);
				GameObject doorMonitor = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/SingleScreen");
				((Renderer)doorMonitor.GetComponent<MeshRenderer>()).materials[1].mainTexture = (Texture)externalCameraRt;
				((Behaviour)internalCamera.GetComponent<Camera>()).enabled = true;
			}
		}
	}
}
namespace AntonzloCameras.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void Update_Postfix()
		{
			//IL_0059: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			if ((Object)(object)GameObject.Find("CameraZoomSwitchButton(Clone)") == (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(Plugin.ButtonPrefab);
				val.transform.parent = GameObject.Find("CameraMonitorSwitchButton").transform.parent;
				val.transform.localPosition = new Vector3(GameObject.Find("CameraMonitorSwitchButton").transform.localPosition.x, GameObject.Find("CameraMonitorSwitchButton").transform.localPosition.y + 1.9f, -0.5f);
				val.transform.rotation = GameObject.Find("CameraMonitorSwitchButton").transform.rotation;
				((Component)val.transform.GetChild(0)).gameObject.AddComponent<Handler>();
				((UnityEvent<PlayerControllerB>)(object)((Component)val.transform.GetChild(0)).GetComponent<InteractTrigger>().onInteract).AddListener((UnityAction<PlayerControllerB>)((Component)val.transform.GetChild(0)).GetComponent<Handler>().ToggleCameraState);
				((Component)val.transform.GetChild(0)).GetComponent<InteractTrigger>().hoverTip = "Toggle Camera : [E]";
				Plugin.Log.LogInfo((object)"OK!");
				GameObject val2 = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/SingleScreen");
				Handler.second = Object.Instantiate<GameObject>(val2);
				Handler.second.transform.parent = val2.transform.parent;
				Handler.second.transform.localPosition = new Vector3(val2.transform.localPosition.x + 12f, val2.transform.localPosition.y - 1.65f, val2.transform.localPosition.z + 1f);
				Handler.second.transform.rotation = val2.transform.rotation;
				Handler.second.transform.localScale = new Vector3(1f, 1f, 1f);
				((Renderer)Handler.second.GetComponent<MeshRenderer>()).materials[1].mainTexture = (Texture)Plugin.internalCameraRt;
			}
		}
	}
}