Decompiled source of CloseViewMode v1.0.3

CloseViewMode.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using Bounce.Unmanaged;
using HarmonyLib;
using LordAshes;
using RadialUI;
using TMPro;
using Unity.Mathematics;
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: AssemblyTitle("CloseViewMode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CloseViewMode")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("CloseViewMode")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.3.0")]
namespace XJ_Nekomancer;

[BepInPlugin("org.XJ_Nekomancer.plugins.CloseViewMode", "CloseViewMode Plugin", "1.0.3.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CloseViewMode : BaseUnityPlugin
{
	[HarmonyPatch(typeof(CameraController), "Update")]
	public static class PatchCameraControllerUpdate
	{
		public static void Postfix()
		{
			//IL_000e: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			if (!CloseViewActive)
			{
				return;
			}
			CreatureBoardAsset val = default(CreatureBoardAsset);
			CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
			if ((Object)(object)val != (Object)null)
			{
				if (disablecam)
				{
					CameraController.ToggleCameraMovement(true);
					disablecam = false;
				}
				Quaternion rotation = val.HookHead.rotation;
				double num = ((Quaternion)(ref rotation)).eulerAngles.y;
				Vector3 position = val.HookHead.position;
				position.x -= float.Parse(Math.Cos(num * Math.PI / 180.0).ToString()) / 3f;
				position.z += float.Parse(Math.Sin(num * Math.PI / 180.0).ToString()) / 3f;
				position.y -= 0.3f;
				CameraController.MoveToPosition(position, true, false, false);
			}
			else if (!disablecam)
			{
				if (!LocalClient.IsInGmMode)
				{
					CameraController.ToggleCameraMovement(false);
					disablecam = true;
				}
				else
				{
					Instance.CViewOff();
				}
			}
		}
	}

	public static class Utility
	{
		public static void PostOnMainPage(MemberInfo plugin)
		{
			SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				try
				{
					if (((Scene)(ref scene)).name == "UI")
					{
						TextMeshProUGUI uITextByName = GetUITextByName("BETA");
						if (Object.op_Implicit((Object)(object)uITextByName))
						{
							((TMP_Text)uITextByName).text = "INJECTED BUILD - unstable mods";
						}
					}
					else
					{
						TextMeshProUGUI uITextByName2 = GetUITextByName("TextMeshPro Text");
						if (Object.op_Implicit((Object)(object)uITextByName2))
						{
							BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(plugin, typeof(BepInPlugin));
							if (((TMP_Text)uITextByName2).text.EndsWith("</size>"))
							{
								((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + "\n\nMods Currently Installed:\n";
							}
							TextMeshProUGUI val2 = uITextByName2;
							((TMP_Text)val2).text = ((TMP_Text)val2).text + "\nLord Ashes' " + val.Name + " - " + val.Version;
						}
					}
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex);
				}
			};
		}

		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static bool StrictKeyCheck(KeyboardShortcut check)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (!((KeyboardShortcut)(ref check)).IsUp())
			{
				return false;
			}
			KeyCode[] array = new KeyCode[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			KeyCode[] array2 = (KeyCode[])(object)array;
			foreach (KeyCode val in array2)
			{
				if (Input.GetKey(val) != ((KeyboardShortcut)(ref check)).Modifiers.Contains(val))
				{
					return false;
				}
			}
			return true;
		}

		private static TextMeshProUGUI GetUITextByName(string name)
		{
			TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>();
			for (int i = 0; i < array.Length; i++)
			{
				if (((Object)array[i]).name == name)
				{
					return array[i];
				}
			}
			return null;
		}
	}

	public enum DiagnosticMode
	{
		none,
		low,
		high,
		ultra
	}

	public const string Name = "CloseViewMode Plugin";

	public const string Guid = "org.XJ_Nekomancer.plugins.CloseViewMode";

	public const string Version = "1.0.3.0";

	public const string Author = "XJ_Nekomancer";

	public static CloseViewMode Instance;

	public static DiagnosticMode diagnostics;

	private string dir = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/TaleSpire_CustomData/";

	public static bool CloseViewActive;

	public static bool GMCloseViewActive;

	public static bool disablecam;

	private static RootTargetCameraMode instance;

	private FieldInfo minFI;

	private FieldInfo maxFI;

	private Vector3 minFibackup = Vector3.zero;

	private Vector3 maxFibackup = Vector3.zero;

	private void Awake()
	{
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Expected O, but got Unknown
		Debug.Log((object)"CloseViewMode: CloseViewMode Is Active.");
		diagnostics = ((BaseUnityPlugin)this).Config.Bind<DiagnosticMode>("Troubleshooting", "Diagnostic Mode", DiagnosticMode.ultra, (ConfigDescription)null).Value;
		if (diagnostics >= DiagnosticMode.ultra)
		{
			Debug.Log((object)"CloseViewMode:  Active");
		}
		AssetDataPlugin.Subscribe("org.XJ_Nekomancer.plugins.CloseViewMode.CloseON", (Action<DatumChange>)CallbackCloseon);
		AssetDataPlugin.Subscribe("org.XJ_Nekomancer.plugins.CloseViewMode.CloseOFF", (Action<DatumChange>)CallbackCloseoff);
		minFI = (from f in typeof(RootTargetCameraMode).GetRuntimeFields()
			where f.Name == "minZoomPos"
			select f).ElementAt(0);
		maxFI = (from f in typeof(RootTargetCameraMode).GetRuntimeFields()
			where f.Name == "maxZoomPos"
			select f).ElementAt(0);
		RadialSubmenu.EnsureMainMenuItem("org.XJ_Nekomancer.plugins.CloseViewMode.MainMenuCV", (MenuType)1, "CloseView Menu", Image.LoadSprite("xj_cvm_BASE.png", (CacheType)999));
		RadialSubmenu.CreateSubMenuItem("org.XJ_Nekomancer.plugins.CloseViewMode.MainMenuCV", "Close View On", Image.LoadSprite("xj_cvm_ON.png", (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid cid, string obj, MapMenuItem mi)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CViewOn(cid);
		}, true, (Func<bool>)(() => !CloseViewActive));
		RadialSubmenu.CreateSubMenuItem("org.XJ_Nekomancer.plugins.CloseViewMode.MainMenuCV", "Close View Off", Image.LoadSprite("xj_cvm_OFF.png", (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid cid, string obj, MapMenuItem mi)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CViewOff(cid);
		}, true, (Func<bool>)(() => CloseViewActive));
		RadialSubmenu.CreateSubMenuItem("org.XJ_Nekomancer.plugins.CloseViewMode.MainMenuCV", "(GM only) Force Close View on all players", Image.LoadSprite("xj_cvm_GMON.png", (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid cid, string obj, MapMenuItem mi)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CViewOnGM(cid);
		}, true, (Func<bool>)(() => LocalClient.IsInGmMode));
		RadialSubmenu.CreateSubMenuItem("org.XJ_Nekomancer.plugins.CloseViewMode.MainMenuCV", "(GM only) Disable Close View on all players", Image.LoadSprite("xj_cvm_GMOFF.png", (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid cid, string obj, MapMenuItem mi)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CViewOffGM(cid);
		}, true, (Func<bool>)(() => LocalClient.IsInGmMode));
		Harmony val = new Harmony("org.XJ_Nekomancer.plugins.CloseViewMode");
		val.PatchAll();
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void Update()
	{
	}

	public void CViewOn(CreatureGuid a = default(CreatureGuid))
	{
		//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_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		if (diagnostics >= DiagnosticMode.low)
		{
			Debug.Log((object)"CloseViewMode: CViewOn");
		}
		if (CloseViewActive)
		{
			return;
		}
		CloseViewActive = true;
		if ((Object)(object)instance == (Object)null)
		{
			try
			{
				instance = SingletonBehaviour<RootTargetCameraMode>.Instance;
			}
			catch (Exception ex)
			{
				instance = SingletonBehaviour<RootTargetCameraMode>.Instance;
				if (diagnostics >= DiagnosticMode.ultra)
				{
					Debug.Log((object)("CloseViewMode: catch ex:" + ex.Message));
				}
			}
		}
		if (minFibackup == Vector3.zero)
		{
			object value = minFI.GetValue(SingletonBehaviour<RootTargetCameraMode>.Instance);
			object value2 = maxFI.GetValue(SingletonBehaviour<RootTargetCameraMode>.Instance);
			minFibackup = (Vector3)value;
			maxFibackup = (Vector3)value2;
		}
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(0f, 0f, -0.8f);
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(0f, 0f, -3f);
		minFI.SetValue(SingletonBehaviour<RootTargetCameraMode>.Instance, val);
		maxFI.SetValue(SingletonBehaviour<RootTargetCameraMode>.Instance, val2);
	}

	public void CViewOff(CreatureGuid a = default(CreatureGuid))
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		if (diagnostics >= DiagnosticMode.low)
		{
			Debug.Log((object)"CloseViewMode: CViewOff");
		}
		if (!GMCloseViewActive && CloseViewActive)
		{
			CameraController.ToggleCameraMovement(true);
			disablecam = false;
			CloseViewActive = false;
			minFI.SetValue(SingletonBehaviour<RootTargetCameraMode>.Instance, minFibackup);
			maxFI.SetValue(SingletonBehaviour<RootTargetCameraMode>.Instance, maxFibackup);
		}
	}

	public void CViewOnGM(CreatureGuid a)
	{
		if (LocalClient.IsInGmMode)
		{
			CameraController.ToggleCameraMovement(true);
			if (diagnostics >= DiagnosticMode.high)
			{
				Debug.Log((object)"CloseViewMode: CViewOnGM");
			}
			AssetDataPlugin.SendInfo("org.XJ_Nekomancer.plugins.CloseViewMode.CloseON", DateTime.Now.ToString());
		}
		else
		{
			SystemMessage.DisplayInfoText("This option is only enabled for GMs", 2.5f);
		}
	}

	public void CViewOffGM(CreatureGuid a)
	{
		if (LocalClient.IsInGmMode)
		{
			if (diagnostics >= DiagnosticMode.high)
			{
				Debug.Log((object)"CloseViewMode: CViewOffGM");
			}
			AssetDataPlugin.SendInfo("org.XJ_Nekomancer.plugins.CloseViewMode.CloseOFF", DateTime.Now.ToString());
		}
		else
		{
			SystemMessage.DisplayInfoText("This option is only enabled for GMs", 2.5f);
		}
	}

	private void CallbackCloseon(DatumChange change)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		if (!LocalClient.IsInGmMode)
		{
			CreatureBoardAsset val = default(CreatureBoardAsset);
			CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
			if ((Object)(object)val != (Object)null)
			{
				CViewOn();
				GMCloseViewActive = true;
				ChatManager.SendChatMessageToGms(SimpleSingletonBehaviour<LocalClient>._name.ToString() + "CloseviewMode ON", NGuid.Empty, (float3?)null, false);
			}
			else
			{
				ChatManager.SendChatMessageToGms(SimpleSingletonBehaviour<LocalClient>._name.ToString() + "CloseviewMode can't be activated (not target selected)", NGuid.Empty, (float3?)null, false);
			}
		}
	}

	private void CallbackCloseoff(DatumChange change)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if (!LocalClient.IsInGmMode)
		{
			GMCloseViewActive = false;
			CViewOff();
		}
	}
}