Decompiled source of PhotoMode v1.4.6

PhotoMode.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using On.RoR2;
using On.RoR2.UI;
using Rewired;
using RoR2;
using RoR2.UI;
using RoR2.UI.SkinControllers;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[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 = "")]
[assembly: AssemblyCompany("PhotoMode")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PhotoMode")]
[assembly: AssemblyTitle("PhotoMode")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PhotoMode;

internal class PhotoModeController : MonoBehaviour, ICameraStateProvider
{
	internal struct PhotoModeCameraState
	{
		internal float pitch;

		internal float yaw;

		internal float roll;

		internal Vector3 position;

		internal float fov;

		internal Quaternion Rotation
		{
			get
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: 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)
				return Quaternion.Euler(pitch, yaw, roll);
			}
			set
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				Vector3 eulerAngles = ((Quaternion)(ref value)).eulerAngles;
				pitch = eulerAngles.x;
				yaw = eulerAngles.y;
				roll = eulerAngles.z;
			}
		}
	}

	private static float cameraSpeed = 10f;

	private static float cameraSprintMultiplier = 5f;

	private static float cameraSlowMultiplier = 0.3f;

	public CameraRigController cameraRigController;

	public PauseScreenController pauseController;

	private PhotoModeCameraState cameraState;

	private bool locked;

	private Camera Camera => cameraRigController.sceneCam;

	public InputSource currentInputSource { get; private set; }

	private bool gamepad => (int)currentInputSource == 1;

	private event Action OnExit;

	internal void EnterPhotoMode(PauseScreenController pauseController, CameraRigController cameraRigController)
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Expected O, but got Unknown
		this.cameraRigController = cameraRigController;
		Debug.Log((object)"Entering photo mode");
		Time.timeScale = 0f;
		if (Object.op_Implicit((Object)(object)this.cameraRigController))
		{
			this.cameraRigController.SetOverrideCam((ICameraStateProvider)(object)this, 0f);
			this.cameraRigController.enableFading = false;
		}
		cameraState = default(PhotoModeCameraState);
		cameraState.position = ((Component)Camera).transform.position;
		cameraState.Rotation = Quaternion.LookRotation(((Component)Camera).transform.rotation * Vector3.forward, Vector3.up);
		cameraState.fov = Camera.fieldOfView;
		if (SettingsConVars.enableDamageNumbers.value)
		{
			SettingsConVars.enableDamageNumbers.SetBool(false);
			OnExit += delegate
			{
				SettingsConVars.enableDamageNumbers.SetBool(true);
			};
		}
		if (SettingsConVars.cvExpAndMoneyEffects.value)
		{
			SettingsConVars.cvExpAndMoneyEffects.SetBool(false);
			OnExit += delegate
			{
				SettingsConVars.cvExpAndMoneyEffects.SetBool(true);
			};
		}
		((Behaviour)this.cameraRigController.hud.mainContainer.GetComponent<Canvas>()).enabled = false;
		OnExit += delegate
		{
			((Behaviour)this.cameraRigController.hud.mainContainer.GetComponent<Canvas>()).enabled = true;
		};
		if (PhotoModePlugin.disableIndicators.Value)
		{
			SetIndicatorsVisible(visible: false);
			OnExit += delegate
			{
				SetIndicatorsVisible(visible: true);
			};
		}
		Player inputPlayer = this.cameraRigController.localUserViewer.inputPlayer;
		inputPlayer.controllers.AddLastActiveControllerChangedDelegate(new PlayerActiveControllerChangedDelegate(OnLastActiveControllerChanged));
		OnLastActiveControllerChanged(inputPlayer, inputPlayer.controllers.GetLastActiveController());
	}

	private void OnDisable()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		Player inputPlayer = cameraRigController.localUserViewer.inputPlayer;
		inputPlayer.controllers.RemoveLastActiveControllerChangedDelegate(new PlayerActiveControllerChangedDelegate(OnLastActiveControllerChanged));
	}

	private void OnLastActiveControllerChanged(Player player, Controller controller)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected I4, but got Unknown
		if (controller != null)
		{
			ControllerType type = controller.type;
			ControllerType val = type;
			switch ((int)val)
			{
			case 0:
				currentInputSource = (InputSource)0;
				break;
			case 1:
				currentInputSource = (InputSource)0;
				break;
			case 2:
				currentInputSource = (InputSource)1;
				break;
			}
		}
	}

	private void ExitPhotoMode()
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		this.OnExit();
		if (Object.op_Implicit((Object)(object)cameraRigController))
		{
			cameraRigController.enableFading = true;
			cameraRigController.SetOverrideCam((ICameraStateProvider)null, 1f);
		}
		Debug.Log((object)"Exiting photo mode");
		((Component)Camera).transform.localPosition = Vector3.zero;
		((Component)Camera).transform.localRotation = Quaternion.identity;
		for (int i = 0; i < PauseScreenController.instancesList.Count; i++)
		{
			PauseScreenController.instancesList[i].DestroyPauseScreen(true);
		}
		Time.timeScale = 1f;
		Object.Destroy((Object)(object)((Component)this).gameObject);
	}

	private void SetIndicatorsVisible(bool visible)
	{
		Type nestedType = typeof(Indicator).GetNestedType("IndicatorManager", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		if (nestedType == null)
		{
			Debug.Log((object)"Failed to find indicatorManagerTypeInfo");
		}
		else
		{
			FieldInfo field = nestedType.GetField("runningIndicators", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				Debug.Log((object)"Failed to find runningIndicatorsFieldInfo");
			}
			else
			{
				Debug.Log((object)field.ToString());
				object value = field.GetValue(null);
				if (value is List<Indicator>)
				{
					((List<Indicator>)value).ForEach(delegate(Indicator indicator)
					{
						indicator.SetVisualizerInstantiated(visible);
					});
				}
				if (!visible)
				{
					DamageNumberManager.instance.ps.Clear(true);
				}
			}
		}
		((Behaviour)cameraRigController.hud.combatHealthBarViewer).enabled = visible;
		PingIndicator.instancesList.ForEach(delegate(PingIndicator pingIndicator)
		{
			((Component)pingIndicator).gameObject.SetActive(visible);
		});
		if (!visible)
		{
			cameraRigController.sprintingParticleSystem.Clear(true);
		}
	}

	private void Update()
	{
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0316: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: 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_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: 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_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: 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_03bd: Unknown result type (might be due to invalid IL or missing references)
		UserProfile userProfile = cameraRigController.localUserViewer.userProfile;
		Player inputPlayer = cameraRigController.localUserViewer.inputPlayer;
		if (inputPlayer.GetButton(25))
		{
			ExitPhotoMode();
			return;
		}
		if (Input.GetKeyDown((KeyCode)301))
		{
			locked = !locked;
		}
		if (!locked)
		{
			Time.timeScale = 0f;
			float mouseLookSensitivity = userProfile.mouseLookSensitivity;
			float mouseLookScaleX = userProfile.mouseLookScaleX;
			float mouseLookScaleY = userProfile.mouseLookScaleY;
			float axis = inputPlayer.GetAxis(23);
			float axis2 = inputPlayer.GetAxis(24);
			float num = 1f;
			if (gamepad)
			{
				num = 10f;
			}
			if ((gamepad && inputPlayer.GetButton(9)) || Input.GetMouseButton(1))
			{
				cameraState.fov = Mathf.Clamp(Camera.fieldOfView + mouseLookSensitivity * Time.unscaledDeltaTime * axis2 * num, 4f, 120f);
			}
			if ((gamepad && inputPlayer.GetButton(10)) || Input.GetMouseButton(2))
			{
				cameraState.roll += (0f - mouseLookScaleX) * mouseLookSensitivity * Time.unscaledDeltaTime * axis * num;
			}
			else
			{
				float value = mouseLookScaleX * mouseLookSensitivity * Time.unscaledDeltaTime * axis * num;
				float value2 = mouseLookScaleY * mouseLookSensitivity * Time.unscaledDeltaTime * axis2 * num;
				ConditionalNegate(ref value, userProfile.mouseLookInvertX);
				ConditionalNegate(ref value2, userProfile.mouseLookInvertY);
				float num2 = cameraState.roll * (MathF.PI / 180f);
				cameraState.yaw += cameraState.fov * (value * Mathf.Cos(num2) - value2 * Mathf.Sin(num2));
				cameraState.pitch += cameraState.fov * ((0f - value2) * Mathf.Cos(num2) - value * Mathf.Sin(num2));
				cameraState.pitch = Mathf.Clamp(cameraState.pitch, -89f, 89f);
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(inputPlayer.GetAxis(0) * num, 0f, inputPlayer.GetAxis(1) * num);
			if ((gamepad && inputPlayer.GetButton(7)) || Input.GetKey((KeyCode)113))
			{
				val.y -= 1f;
			}
			if ((gamepad && inputPlayer.GetButton(8)) || Input.GetKey((KeyCode)101))
			{
				val.y += 1f;
			}
			((Vector3)(ref val)).Normalize();
			if (inputPlayer.GetButton("Sprint"))
			{
				val *= cameraSprintMultiplier;
			}
			if (Input.GetKey((KeyCode)306))
			{
				val *= cameraSlowMultiplier;
			}
			ref Vector3 position = ref cameraState.position;
			position += cameraState.Rotation * val * Time.unscaledDeltaTime * cameraSpeed;
			((Component)Camera).transform.position = cameraState.position;
			Quaternion val2 = cameraState.Rotation;
			if ((double)Mathf.Abs(((Quaternion)(ref val2)).eulerAngles.z) < 2.0)
			{
				val2 = val2.WithEulerAngles(null, null, 0f);
			}
			((Component)Camera).transform.rotation = val2;
			Camera.fieldOfView = cameraState.fov;
		}
	}

	public void GetCameraState(CameraRigController cameraRigController, ref CameraState cameraState)
	{
	}

	private void ConditionalNegate(ref float value, bool condition)
	{
		value = (condition ? (0f - value) : value);
	}

	public bool IsHudAllowed(CameraRigController cameraRigController)
	{
		return false;
	}

	public bool IsUserControlAllowed(CameraRigController cameraRigController)
	{
		return false;
	}

	public bool IsUserLookAllowed(CameraRigController cameraRigController)
	{
		return false;
	}
}
[BepInPlugin("com.cwmlolzlz.photomode", "PhotoMode", "1.4.6")]
public class PhotoModePlugin : BaseUnityPlugin
{
	public CameraRigController cameraRigController;

	public static ConfigEntry<bool> disableIndicators;

	public static ConfigEntry<int> buttonPlacement;

	public void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_002c: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		//IL_005c: Expected O, but got Unknown
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		disableIndicators = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Disable Ping Indicators In Photo Mode", "Disable"), false, new ConfigDescription("Enabling this can cause indicators to not reenable again until the scene is reloaded.", (AcceptableValueBase)null, Array.Empty<object>()));
		buttonPlacement = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition("Button Placement Index", "Index"), 2, new ConfigDescription("Index will be the button count and it starts at 0. 0-1 will place it at the top.", (AcceptableValueBase)null, Array.Empty<object>()));
		CameraRigController.OnEnable += (hook_OnEnable)delegate(orig_OnEnable orig, CameraRigController self)
		{
			orig.Invoke(self);
			cameraRigController = self;
		};
		CameraRigController.OnDisable += (hook_OnDisable)delegate(orig_OnDisable orig, CameraRigController self)
		{
			orig.Invoke(self);
			cameraRigController = null;
		};
		PauseScreenController.Awake += (hook_Awake)delegate(orig_Awake orig, PauseScreenController self)
		{
			orig.Invoke(self);
			SetupPhotoModeButton(self);
		};
	}

	private void SetupPhotoModeButton(PauseScreenController pauseScreenController)
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		GameObject gameObject = ((Component)((Component)pauseScreenController).GetComponentInChildren<ButtonSkinController>()).gameObject;
		GameObject val = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
		((Object)val).name = "GenericMenuButton (Photo mode)";
		val.SetActive(true);
		ButtonSkinController component = val.GetComponent<ButtonSkinController>();
		((Component)component).GetComponent<LanguageTextMeshController>().token = "Photo mode";
		HGButton component2 = val.GetComponent<HGButton>();
		((Selectable)component2).interactable = cameraRigController.localUserViewer != null;
		((UnityEvent)((Button)component2).onClick).AddListener((UnityAction)delegate
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			GameObject val2 = new GameObject("PhotoModeController");
			PhotoModeController photoModeController = val2.AddComponent<PhotoModeController>();
			photoModeController.EnterPhotoMode(pauseScreenController, cameraRigController);
		});
		val.transform.SetSiblingIndex(buttonPlacement.Value);
	}
}
public static class QuaternionExtension
{
	public static Quaternion WithEulerAngles(this Quaternion quaternion, float? x = null, float? y = null, float? z = null)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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_005f: 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_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		Vector3 eulerAngles = ((Quaternion)(ref quaternion)).eulerAngles;
		((Vector3)(ref eulerAngles)).Set(x ?? eulerAngles.x, y ?? eulerAngles.y, z ?? eulerAngles.z);
		return Quaternion.Euler(eulerAngles);
	}
}