Decompiled source of SelfCam v0.1.4

plugins/com.github.x-Kami.SelfCam.dll

Decompiled a week ago
using System;
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 BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.x-Kami.SelfCam")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.x-Kami.SelfCam")]
[assembly: AssemblyTitle("SelfCam")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace SelfCam
{
	[BepInPlugin("com.github.x-Kami.SelfCam", "SelfCam", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Camera selfCamCamera;

		private RenderTexture selfCamTexture;

		private bool selfCamEnabled;

		private bool showSettings;

		private ConfigEntry<float> DistanceBehindConfig;

		private ConfigEntry<float> HeightAboveConfig;

		private ConfigEntry<int> WindowSizeConfig;

		private ConfigEntry<bool> LookAtHeadConfig;

		public const string Id = "com.github.x-Kami.SelfCam";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "SelfCam";

		public static string Version => "0.1.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			DistanceBehindConfig = ((BaseUnityPlugin)this).Config.Bind<float>("SelfCam", "DistanceBehind", 0.2f, "Distance of the camera behind the head");
			HeightAboveConfig = ((BaseUnityPlugin)this).Config.Bind<float>("SelfCam", "HeightAbove", 0.1f, "Height of the camera above the head");
			WindowSizeConfig = ((BaseUnityPlugin)this).Config.Bind<int>("SelfCam", "WindowSize", 256, "Width of the selfcam window");
			LookAtHeadConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("SelfCam", "LookAtHead", false, "Whether the camera looks at the head");
			Log.LogInfo((object)"Configs loaded!");
		}

		private void Update()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Input.GetKeyDown((KeyCode)290))
				{
					selfCamEnabled = !selfCamEnabled;
					if (selfCamEnabled)
					{
						EnableSelfCam();
					}
					else
					{
						DisableSelfCam();
					}
				}
				if (Input.GetKeyDown((KeyCode)291))
				{
					showSettings = !showSettings;
				}
				if (selfCamEnabled && (Object)(object)selfCamCamera != (Object)null && (Object)(object)Player.localPlayer != (Object)null)
				{
					Vector3 position = ((Component)Player.localPlayer.character.refs.head).transform.position;
					Vector3 val = ((Component)Player.localPlayer.character.refs.head).transform.forward * DistanceBehindConfig.Value;
					Vector3 position2 = position + val + Vector3.up * HeightAboveConfig.Value;
					((Component)selfCamCamera).transform.position = position2;
					selfCamCamera.cullingMask = LayerMask.GetMask(new string[1] { "Default" }) | 0x400;
					if (LookAtHeadConfig.Value)
					{
						((Component)selfCamCamera).transform.LookAt(position);
						return;
					}
					((Component)selfCamCamera).transform.rotation = ((Component)Player.localPlayer.character.refs.head).transform.rotation;
					Transform transform = ((Component)selfCamCamera).transform;
					transform.rotation *= Quaternion.Euler(0f, 180f, 0f);
				}
			}
			catch
			{
				Log.LogError((object)"Error on Update..");
			}
		}

		private void EnableSelfCam()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			Log.LogInfo((object)"EnableSelfCam");
			try
			{
				if (!((Object)(object)Player.localPlayer == (Object)null))
				{
					GameObject val = new GameObject("SelfCamCamera");
					selfCamCamera = val.AddComponent<Camera>();
					selfCamCamera.clearFlags = (CameraClearFlags)2;
					selfCamCamera.backgroundColor = Color.clear;
					selfCamCamera.cullingMask = LayerMask.GetMask(new string[1] { "Default" });
					selfCamCamera.depth = Camera.main.depth + 1f;
					selfCamCamera.nearClipPlane = 0.001f;
					selfCamTexture = new RenderTexture(WindowSizeConfig.Value, WindowSizeConfig.Value, 16);
					selfCamCamera.targetTexture = selfCamTexture;
					Log.LogInfo((object)"SelfCam activated");
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Can't enable SelfCam: " + ex));
			}
		}

		private void DisableSelfCam()
		{
			try
			{
				if ((Object)(object)selfCamCamera != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)selfCamCamera).gameObject);
				}
				if ((Object)(object)selfCamTexture != (Object)null)
				{
					selfCamTexture.Release();
				}
				selfCamCamera = null;
				selfCamTexture = null;
				Log.LogInfo((object)"SelfCam deactivated");
			}
			catch
			{
				Log.LogError((object)"Error on disabling..");
			}
		}

		private void OnGUI()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (selfCamEnabled && (Object)(object)selfCamTexture != (Object)null)
				{
					int value = WindowSizeConfig.Value;
					GUI.DrawTexture(new Rect((float)((Screen.width - value) / 2), (float)(Screen.height - value - 20), (float)value, (float)value), (Texture)(object)selfCamTexture, (ScaleMode)2, true);
				}
				if (!showSettings)
				{
					return;
				}
				GUILayout.BeginArea(new Rect(20f, 20f, 300f, 250f), "SelfCam Settings", GUI.skin.window);
				GUILayout.Label($"Distance Behind: {DistanceBehindConfig.Value:F2}", Array.Empty<GUILayoutOption>());
				float num = GUILayout.HorizontalSlider(DistanceBehindConfig.Value, 0f, 5f, Array.Empty<GUILayoutOption>());
				if (num != DistanceBehindConfig.Value)
				{
					DistanceBehindConfig.Value = num;
					((BaseUnityPlugin)this).Config.Save();
				}
				GUILayout.Label($"Height Above: {HeightAboveConfig.Value:F2}", Array.Empty<GUILayoutOption>());
				float num2 = GUILayout.HorizontalSlider(HeightAboveConfig.Value, -2f, 5f, Array.Empty<GUILayoutOption>());
				if (num2 != HeightAboveConfig.Value)
				{
					HeightAboveConfig.Value = num2;
					((BaseUnityPlugin)this).Config.Save();
				}
				GUILayout.Label($"Window Size: {WindowSizeConfig.Value}", Array.Empty<GUILayoutOption>());
				int num3 = (int)GUILayout.HorizontalSlider((float)WindowSizeConfig.Value, 64f, 1024f, Array.Empty<GUILayoutOption>());
				if (num3 != WindowSizeConfig.Value)
				{
					WindowSizeConfig.Value = num3;
					if ((Object)(object)selfCamTexture != (Object)null)
					{
						selfCamTexture.Release();
						((Texture)selfCamTexture).width = num3;
						((Texture)selfCamTexture).height = num3;
						selfCamTexture.Create();
					}
					((BaseUnityPlugin)this).Config.Save();
				}
				bool flag = GUILayout.Toggle(LookAtHeadConfig.Value, "Look At Head", Array.Empty<GUILayoutOption>());
				if (flag != LookAtHeadConfig.Value)
				{
					LookAtHeadConfig.Value = flag;
					((BaseUnityPlugin)this).Config.Save();
				}
				GUILayout.EndArea();
			}
			catch
			{
				Log.LogError((object)"Error OnGui..");
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}