Decompiled source of PhotoMode v1.4.2

PhotoMode.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using On.RoR2;
using On.RoR2.UI;
using R2API.Utils;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Dragonyck")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PhotoMode")]
[assembly: AssemblyTitle("PhotoMode")]
[assembly: AssemblyVersion("1.0.0.0")]
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_0012: Unknown result type (might be due to invalid IL or missing references)
				return Quaternion.Euler(pitch, yaw, roll);
			}
			set
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: 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_0021: 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]
	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_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: 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_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Expected O, but got Unknown
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Expected O, but got Unknown
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Expected O, but got Unknown
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Expected O, but got Unknown
		//IL_0131: 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_013c: Expected O, but got Unknown
		this.pauseController = pauseController;
		this.cameraRigController = cameraRigController;
		Debug.Log((object)"Entering photo mode");
		((Component)this.pauseController).gameObject.SetActive(false);
		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;
		Time.timeScale = 0f;
		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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		cameraRigController.localUserViewer.inputPlayer.controllers.RemoveLastActiveControllerChangedDelegate(new PlayerActiveControllerChangedDelegate(OnLastActiveControllerChanged));
	}

	private void OnLastActiveControllerChanged(Player player, Controller controller)
	{
		//IL_0005: 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_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected I4, but got Unknown
		if (controller != null)
		{
			ControllerType type = controller.type;
			switch ((int)type)
			{
			case 0:
				currentInputSource = (InputSource)0;
				break;
			case 1:
				currentInputSource = (InputSource)0;
				break;
			case 2:
				currentInputSource = (InputSource)1;
				break;
			}
		}
	}

	private void SetupPhotoModeHUD(HUD hud)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		_ = ((Component)hud).gameObject;
		new GameObject("PhotoModeHUD", new Type[1] { typeof(Canvas) });
	}

	private void ExitPhotoMode()
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		this.OnExit.Invoke();
		((Component)pauseController).gameObject.SetActive(true);
		if (Object.op_Implicit((Object)(object)cameraRigController))
		{
			cameraRigController.enableFading = true;
			cameraRigController.SetOverrideCam((ICameraStateProvider)null, 1f);
		}
		Debug.Log((object)"Exiting photo mode");
		Time.timeScale = 1f;
		((Component)Camera).transform.localPosition = Vector3.zero;
		((Component)Camera).transform.localRotation = Quaternion.identity;
		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)
				{
					Reflection.GetFieldValue<ParticleSystem>((object)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_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: 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_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: 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;
		}
		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;
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.cwmlolzlz.photomode", "PhotoMode", "1.4.2")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class PhotoModePlugin : BaseUnityPlugin
{
	public CameraRigController cameraRigController;

	public static ConfigEntry<bool> disableIndicators;

	public void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		//IL_002b: Expected O, but got Unknown
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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>()));
		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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Expected O, but got Unknown
		GameObject gameObject = ((Component)((Component)pauseScreenController).GetComponentInChildren<ButtonSkinController>()).gameObject;
		GameObject obj = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
		((Object)obj).name = "GenericMenuButton (Photo mode)";
		obj.transform.SetSiblingIndex(1);
		((Component)obj.GetComponent<ButtonSkinController>()).GetComponent<LanguageTextMeshController>().token = "Photo mode";
		HGButton component = obj.GetComponent<HGButton>();
		((Selectable)component).interactable = cameraRigController.localUserViewer != null;
		for (int i = 0; i < ((UnityEventBase)((Button)component).onClick).GetPersistentEventCount(); i++)
		{
			Debug.Log((object)((UnityEventBase)((Button)component).onClick).GetPersistentMethodName(i).ToString());
			((UnityEventBase)((Button)component).onClick).SetPersistentListenerState(i, (UnityEventCallState)0);
		}
		((UnityEvent)((Button)component).onClick).AddListener((UnityAction)delegate
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new GameObject("PhotoModeController").AddComponent<PhotoModeController>().EnterPhotoMode(pauseScreenController, cameraRigController);
		});
	}
}
public static class QuaternionExtension
{
	public static Quaternion WithEulerAngles(this Quaternion quaternion, float? x = null, float? y = null, float? z = null)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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);
	}
}