Decompiled source of BodycamHelmetCam v1.0.0

Mods\BodycamMod.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BodycamMod;
using BoneLib.BoneMenu;
using LabFusion.SDK.Modules;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "BodycamMod", "1.0.0", "you", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonPriority(20)]
[assembly: MelonOptionalDependencies(new string[] { "BoneLib", "LabFusion" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 BodycamMod
{
	[RegisterTypeInIl2Cpp]
	public class BodycamController : MonoBehaviour
	{
		private Camera _main;

		private Camera _chest;

		private GameObject _chestGO;

		private RenderTexture _rt;

		private float _yaw;

		private static BodycamController _i;

		public static void FindAndAttach()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)_i))
			{
				GameObject val = new GameObject("BodycamController");
				Object.DontDestroyOnLoad((Object)(object)val);
				_i = val.AddComponent<BodycamController>();
			}
		}

		private void Start()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			_main = Camera.main;
			if (Object.op_Implicit((Object)(object)_main))
			{
				BuildRT();
				_chestGO = new GameObject("BodycamChestCamera");
				_chestGO.transform.SetParent(((Component)this).transform);
				_chest = _chestGO.AddComponent<Camera>();
				_chest.CopyFrom(_main);
				_chest.clearFlags = (CameraClearFlags)1;
				_chest.targetTexture = _rt;
				((Behaviour)_chest).enabled = true;
				_yaw = ((Component)_main).transform.eulerAngles.y;
			}
		}

		private void BuildRT()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)_rt))
			{
				_rt.Release();
				Object.Destroy((Object)(object)_rt);
			}
			_rt = new RenderTexture(Screen.width, Screen.height, 24, (RenderTextureFormat)0);
			_rt.Create();
			if (Object.op_Implicit((Object)(object)_chest))
			{
				_chest.targetTexture = _rt;
			}
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)_rt))
			{
				_rt.Release();
				Object.Destroy((Object)(object)_rt);
			}
			_i = null;
		}

		private void LateUpdate()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_main))
			{
				_main = Camera.main;
			}
			if (Object.op_Implicit((Object)(object)_main) && Object.op_Implicit((Object)(object)_chest) && BodycamMenu.ModEnabled)
			{
				Vector3 position = ((Component)_main).transform.position;
				if (BodycamMenu.HelmetCamMode)
				{
					_chestGO.transform.position = new Vector3(position.x, position.y + BodycamMenu.ForwardOffset + 0.01f, position.z);
					_chestGO.transform.rotation = ((Component)_main).transform.rotation;
				}
				else
				{
					_chestGO.transform.position = new Vector3(position.x, position.y - BodycamMenu.ForwardOffset, position.z);
					float y = ((Component)_main).transform.eulerAngles.y;
					_yaw = Mathf.LerpAngle(_yaw, y, Time.deltaTime * BodycamMenu.RotationSmoothSpeed);
					_chestGO.transform.rotation = Quaternion.Euler(0f, _yaw, 0f);
				}
				_chest.fieldOfView = BodycamMenu.FOV;
				_chest.farClipPlane = _main.farClipPlane;
				_chest.nearClipPlane = _main.nearClipPlane;
			}
		}

		private void OnGUI()
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			float num = Screen.width;
			float num2 = Screen.height;
			if (num <= 0f || num2 <= 0f || !BodycamMenu.ModEnabled || !Object.op_Implicit((Object)(object)_rt))
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)_main))
			{
				_main = Camera.main;
			}
			if (Object.op_Implicit((Object)(object)_main))
			{
				float num3 = (float)((Texture)_rt).width / (float)((Texture)_rt).height;
				float num4 = num / num2;
				float num5;
				float num6;
				float num7;
				float num8;
				if (num3 > num4)
				{
					num5 = num;
					num6 = num / num3;
					num7 = 0f;
					num8 = (num2 - num6) / 2f;
				}
				else
				{
					num6 = num2;
					num5 = num2 * num3;
					num7 = (num - num5) / 2f;
					num8 = 0f;
				}
				GUI.DrawTexture(new Rect(num7, num8, num5, num6), (Texture)(object)_rt, (ScaleMode)0, false);
				if (BodycamMenu.ShowBorders)
				{
					DrawBars(num, num2, num5, num6, num7, num8);
				}
				DrawHUD(num, num2);
			}
		}

		private void DrawBars(float sw, float sh, float dw, float dh, float dx, float dy)
		{
			//IL_001c: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			float borderThickness = BodycamMenu.BorderThickness;
			if (!(borderThickness <= 0f))
			{
				float num = dw * borderThickness;
				Color color = GUI.color;
				GUI.color = Color.black;
				GUI.DrawTexture(new Rect(dx, dy, num, dh), (Texture)(object)Texture2D.whiteTexture);
				GUI.DrawTexture(new Rect(dx + dw - num, dy, num, dh), (Texture)(object)Texture2D.whiteTexture);
				GUI.color = color;
			}
		}

		private void DrawHUD(float sw, float sh)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontStyle = (FontStyle)1;
			val.normal.textColor = new Color(1f, 0.05f, 0.05f);
			val.fontSize = Mathf.RoundToInt(sh * 0.022f);
			GUI.Label(new Rect(sw * 0.025f, sh * 0.025f, 200f, 30f), "REC " + DateTime.Now.ToString("HH:mm:ss"), val);
		}
	}
	public static class BodycamMenu
	{
		private static MelonPreferences_Category c;

		private static MelonPreferences_Entry<bool> enabled;

		private static MelonPreferences_Entry<bool> borders;

		private static MelonPreferences_Entry<bool> helmetCam;

		private static MelonPreferences_Entry<float> forwardOffset;

		private static MelonPreferences_Entry<float> fov;

		private static MelonPreferences_Entry<float> smoothSpeed;

		private static MelonPreferences_Entry<float> borderThick;

		public static bool ModEnabled => enabled.Value;

		public static bool ShowBorders => borders.Value;

		public static bool HelmetCamMode => helmetCam.Value;

		public static float ForwardOffset => forwardOffset.Value;

		public static float FOV => fov.Value;

		public static float RotationSmoothSpeed => smoothSpeed.Value;

		public static float BorderThickness => borderThick.Value;

		public static int RenderWidth => Screen.width;

		public static int RenderHeight => Screen.height;

		public static void OnInitialize()
		{
			c = MelonPreferences.CreateCategory("BodycamMod");
			enabled = c.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			borders = c.CreateEntry<bool>("ShowBorders", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			helmetCam = c.CreateEntry<bool>("HelmetCamMode", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			forwardOffset = c.CreateEntry<float>("ForwardOffset", 0.4f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			fov = c.CreateEntry<float>("FOV", 120f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			smoothSpeed = c.CreateEntry<float>("RotationSmoothSpeed", 6f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			borderThick = c.CreateEntry<float>("BorderThickness", 0.15f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			CreateBoneMenu();
		}

		private static void CreateBoneMenu()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			Page val = Page.Root.CreatePage("Bodycam", Color.white, 0, true);
			val.CreateBool("Enabled", Color.green, enabled.Value, (Action<bool>)delegate(bool b)
			{
				enabled.Value = b;
				MelonPreferences.Save();
			});
			val.CreateBool("Borders", Color.white, borders.Value, (Action<bool>)delegate(bool b)
			{
				borders.Value = b;
				MelonPreferences.Save();
			});
			val.CreateBool("Helmet Cam", Color.white, helmetCam.Value, (Action<bool>)delegate(bool b)
			{
				helmetCam.Value = b;
				MelonPreferences.Save();
			});
			val.CreateFloat("Forward Offset", Color.white, forwardOffset.Value, 0.05f, 0f, 1f, (Action<float>)delegate(float f)
			{
				forwardOffset.Value = f;
				MelonPreferences.Save();
			});
			val.CreateFloat("FOV", Color.white, fov.Value, 5f, 60f, 170f, (Action<float>)delegate(float f)
			{
				fov.Value = f;
				MelonPreferences.Save();
			});
			val.CreateFloat("Smooth Speed", Color.white, smoothSpeed.Value, 0.5f, 0.5f, 15f, (Action<float>)delegate(float f)
			{
				smoothSpeed.Value = f;
				MelonPreferences.Save();
			});
			val.CreateFloat("Border Thickness", Color.white, borderThick.Value, 0.02f, 0f, 0.4f, (Action<float>)delegate(float f)
			{
				borderThick.Value = f;
				MelonPreferences.Save();
			});
		}
	}
	public class BodycamFusionModule : Module
	{
		public override string Name => "BodycamMod";

		public override string Author => "you";

		public override Version Version => new Version(1, 0, 0);

		protected override void OnModuleRegistered()
		{
			ModuleMessageManager.LoadHandlers(typeof(BodycamFusionModule).Assembly);
		}

		protected override void OnModuleUnregistered()
		{
		}
	}
	public static class FusionModuleLoader
	{
		public static void TryLoad()
		{
			if (MelonTypeBase<MelonMod>.RegisteredMelons.Any((MelonMod m) => ((MelonBase)m).Info.Name == "LabFusion"))
			{
				ModuleManager.RegisterModule<BodycamFusionModule>();
			}
		}
	}
	public class Main : MelonMod
	{
		public override void OnInitializeMelon()
		{
			BodycamMenu.OnInitialize();
			FusionModuleLoader.TryLoad();
			((MelonBase)this).LoggerInstance.Msg("BodycamMod loaded!");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			BodycamController.FindAndAttach();
		}
	}
}