Decompiled source of PhotoMode v1.4.5

PhotoMode.dll

Decompiled 2 months 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 System.Threading;
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;
			}
		}
	}

	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static EmptyDelegate <>9__16_0;

		public static EmptyDelegate <>9__16_1;

		internal void <EnterPhotoMode>b__16_0()
		{
			SettingsConVars.enableDamageNumbers.SetBool(true);
		}

		internal void <EnterPhotoMode>b__16_1()
		{
			SettingsConVars.cvExpAndMoneyEffects.SetBool(true);
		}
	}

	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;

	[CompilerGenerated]
	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private EmptyDelegate m_OnExit;

	private Camera Camera => cameraRigController.sceneCam;

	public InputSource currentInputSource { get; private set; }

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

	private event EmptyDelegate OnExit
	{
		[CompilerGenerated]
		add
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			EmptyDelegate val = this.m_OnExit;
			EmptyDelegate val2;
			do
			{
				val2 = val;
				EmptyDelegate value2 = (EmptyDelegate)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
				val = Interlocked.CompareExchange(ref this.m_OnExit, value2, val2);
			}
			while (val != val2);
		}
		[CompilerGenerated]
		remove
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			EmptyDelegate val = this.m_OnExit;
			EmptyDelegate val2;
			do
			{
				val2 = val;
				EmptyDelegate value2 = (EmptyDelegate)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
				val = Interlocked.CompareExchange(ref this.m_OnExit, value2, val2);
			}
			while (val != val2);
		}
	}

	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_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Expected O, but got Unknown
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Expected O, but got Unknown
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Expected O, but got Unknown
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: 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);
			object obj = <>c.<>9__16_0;
			if (obj == null)
			{
				EmptyDelegate val = delegate
				{
					SettingsConVars.enableDamageNumbers.SetBool(true);
				};
				<>c.<>9__16_0 = val;
				obj = (object)val;
			}
			OnExit += (EmptyDelegate)obj;
		}
		if (SettingsConVars.cvExpAndMoneyEffects.value)
		{
			SettingsConVars.cvExpAndMoneyEffects.SetBool(false);
			object obj2 = <>c.<>9__16_1;
			if (obj2 == null)
			{
				EmptyDelegate val2 = delegate
				{
					SettingsConVars.cvExpAndMoneyEffects.SetBool(true);
				};
				<>c.<>9__16_1 = val2;
				obj2 = (object)val2;
			}
			OnExit += (EmptyDelegate)obj2;
		}
		((Behaviour)this.cameraRigController.hud.mainContainer.GetComponent<Canvas>()).enabled = false;
		OnExit += (EmptyDelegate)delegate
		{
			((Behaviour)this.cameraRigController.hud.mainContainer.GetComponent<Canvas>()).enabled = true;
		};
		if (PhotoModePlugin.disableIndicators.Value)
		{
			SetIndicatorsVisible(visible: false);
			OnExit += (EmptyDelegate)delegate
			{
				SetIndicatorsVisible(visible: true);
			};
		}
		SetupPhotoModeHUD(this.cameraRigController.hud);
		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 SetupPhotoModeHUD(HUD hud)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		GameObject gameObject = ((Component)hud).gameObject;
		GameObject val = new GameObject("PhotoModeHUD", new Type[1] { typeof(Canvas) });
	}

	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.Invoke();
		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_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: 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_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: 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_0365: 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_038a: 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;
		}
		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.4")]
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);
	}
}