Decompiled source of BodycamForBonelab v3.0.1

BodycamModBONELAB.dll

Decompiled 9 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BodycamModBONELAB;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.BoneMenu.Elements;
using FieldInjector;
using MelonLoader;
using MelonLoader.Preferences;
using UnhollowerBaseLib;
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(ModMain), "Bodycam Mod For Bonelab", "1.0.0", "cometmb.pkg", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("BodycamModBONELAB")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BodycamModBONELAB")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a387e336-a7c0-49a5-a7fc-40755788d837")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BodycamModBONELAB;

public class BodycamCameraDriver : MonoBehaviour
{
	public bool isEnabled;

	public bool hasInitialized;

	public GameObject spectatorTarget;

	public GameObject spectatorCamera;

	public GameObject playerChest;

	public GameObject playerHead;

	public void Update()
	{
		isEnabled = ModMain.IsEnabled;
		hasInitialized = ModMain.hasInitialized;
		if (isEnabled && hasInitialized)
		{
			if (!Object.op_Implicit((Object)(object)spectatorTarget) || !Object.op_Implicit((Object)(object)spectatorCamera) || !Object.op_Implicit((Object)(object)playerChest) || !Object.op_Implicit((Object)(object)playerHead))
			{
				hasInitialized = false;
				ModMain.Initialize();
			}
			else
			{
				MoveCamera();
			}
		}
	}

	public void MoveCamera()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: 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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		Vector3 zero = Vector3.zero;
		Vector3 zero2 = Vector3.zero;
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(ModMain.offsetPositionX, ModMain.offsetPositionY, ModMain.offsetPositionZ);
		if (ModMain.IsBodyCam)
		{
			spectatorTarget.transform.SetParent(playerChest.transform);
			zero = val;
			zero2 = playerChest.transform.forward;
			spectatorTarget.transform.localPosition = zero;
			spectatorTarget.transform.forward = zero2;
		}
		else
		{
			spectatorTarget.transform.SetParent(playerHead.transform);
			zero = val;
			zero2 = playerHead.transform.forward;
			spectatorTarget.transform.localPosition = zero;
			spectatorTarget.transform.forward = zero2;
		}
	}

	public BodycamCameraDriver(IntPtr ptr)
		: base(ptr)
	{
	}
}
public class ModMain : MelonMod
{
	public static float offsetPositionX;

	public static float offsetPositionY;

	public static float offsetPositionZ;

	public static bool hasInitialized;

	public static BodycamCameraDriver driver;

	private static bool _prefsSavingDisableReentry;

	public static MelonPreferences_Category MelonPrefCategory { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefEnabled { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefIsBodyCam { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefOffsetPosX { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefOffsetPosY { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefOffsetPosZ { get; private set; }

	public static MenuCategory BoneMenuCategory { get; private set; }

	public static BoolElement EnabledElement { get; private set; }

	public static BoolElement IsBodyCamElement { get; private set; }

	public static FloatElement xOffsetPosElement { get; private set; }

	public static FloatElement yOffsetPosElement { get; private set; }

	public static FloatElement zOffsetPosElement { get; private set; }

	public static bool IsEnabled { get; private set; }

	public static bool IsBodyCam { get; private set; }

	public override void OnInitializeMelon()
	{
		SerialisationHandler.Inject<BodycamCameraDriver>(0);
		((MelonBase)this).LoggerInstance.Msg("Bodycam Initializing.");
		SetupMelonPrefs();
		SetupBoneMenu();
	}

	public static void SetupMelonPrefs()
	{
		MelonPrefCategory = MelonPreferences.CreateCategory("Bodycam Mod");
		MelonPrefEnabled = MelonPrefCategory.CreateEntry<bool>("IsEnabled", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefIsBodyCam = MelonPrefCategory.CreateEntry<bool>("IsBodyCam", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefOffsetPosX = MelonPrefCategory.CreateEntry<float>("Position Offset X", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefOffsetPosY = MelonPrefCategory.CreateEntry<float>("Position Offset Y", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefOffsetPosZ = MelonPrefCategory.CreateEntry<float>("Position Offset Z", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IsEnabled = MelonPrefEnabled.Value;
	}

	public void SetupBoneMenu()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		BoneMenuCategory = MenuManager.CreateCategory("Comet's Bodycam", Color.cyan);
		EnabledElement = BoneMenuCategory.CreateBoolElement("Mod Toggle", Color.yellow, MelonPrefEnabled.Value, CreateSetAndSaveDelegate<bool>(MelonPrefEnabled));
		IsBodyCamElement = BoneMenuCategory.CreateBoolElement("Is Bodycam?", Color.yellow, MelonPrefIsBodyCam.Value, CreateSetAndSaveDelegate<bool>(MelonPrefIsBodyCam));
		xOffsetPosElement = BoneMenuCategory.CreateFloatElement("Position Offset X", Color.red, MelonPrefOffsetPosX.Value, 0.1f, -10f, 10f, CreateSetAndSaveDelegate<float>(MelonPrefOffsetPosX));
		yOffsetPosElement = BoneMenuCategory.CreateFloatElement("Position Offset Y", Color.red, MelonPrefOffsetPosY.Value, 0.1f, -10f, 10f, CreateSetAndSaveDelegate<float>(MelonPrefOffsetPosY));
		zOffsetPosElement = BoneMenuCategory.CreateFloatElement("Position Offset Z", Color.red, MelonPrefOffsetPosZ.Value, 0.1f, -10f, 10f, CreateSetAndSaveDelegate<float>(MelonPrefOffsetPosZ));
	}

	private static Action<T> CreateSetAndSaveDelegate<T>(MelonPreferences_Entry<T> entry)
	{
		return delegate(T value)
		{
			if (!_prefsSavingDisableReentry)
			{
				entry.Value = value;
				((MelonPreferences_Entry)entry).Category.SaveToFile(true);
			}
		};
	}

	public override void OnPreferencesLoaded()
	{
		((MelonBase)this).LoggerInstance.Msg("Preferences were loaded from MelonLoader. Updating Bone Menu display data...");
		_prefsSavingDisableReentry = true;
		((GenericElement<bool>)(object)EnabledElement).SetValue(MelonPrefEnabled.Value);
		((GenericElement<bool>)(object)IsBodyCamElement).SetValue(MelonPrefIsBodyCam.Value);
		((GenericElement<float>)(object)xOffsetPosElement).SetValue(MelonPrefOffsetPosX.Value);
		((GenericElement<float>)(object)yOffsetPosElement).SetValue(MelonPrefOffsetPosY.Value);
		((GenericElement<float>)(object)zOffsetPosElement).SetValue(MelonPrefOffsetPosZ.Value);
		_prefsSavingDisableReentry = false;
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		hasInitialized = false;
		Initialize();
	}

	public static void Log(string msg)
	{
		Melon<ModMain>.Logger.Msg(msg);
	}

	public override void OnUpdate()
	{
		if (!hasInitialized)
		{
			Initialize();
		}
		if (IsEnabled != MelonPrefEnabled.Value)
		{
			IsEnabled = MelonPrefEnabled.Value;
		}
		if (IsBodyCam != MelonPrefIsBodyCam.Value)
		{
			IsBodyCam = MelonPrefIsBodyCam.Value;
		}
		if (offsetPositionX != MelonPrefOffsetPosX.Value)
		{
			offsetPositionX = MelonPrefOffsetPosX.Value;
		}
		if (offsetPositionY != MelonPrefOffsetPosY.Value)
		{
			offsetPositionY = MelonPrefOffsetPosY.Value;
		}
		if (offsetPositionZ != MelonPrefOffsetPosZ.Value)
		{
			offsetPositionZ = MelonPrefOffsetPosZ.Value;
		}
	}

	public static void Initialize()
	{
		GameObject val = GameObject.Find("[RigManager (Blank)]");
		if (!Object.op_Implicit((Object)(object)val))
		{
			Log("No Rig Here! Aborting Initialization until the next scene.");
			return;
		}
		if (!Object.op_Implicit((Object)(object)driver))
		{
			driver = val.AddComponent<BodycamCameraDriver>();
		}
		driver.playerChest = ((Component)Player.physicsRig.torso.rbChest).gameObject;
		driver.spectatorTarget = GameObject.Find("Spectator Target");
		Camera[] array = Il2CppArrayBase<Camera>.op_Implicit(val.GetComponentsInChildren<Camera>(true));
		for (int i = 0; i < array.Length; i++)
		{
			if (((Object)((Component)array[i]).gameObject).name == "Spectator Camera")
			{
				driver.spectatorCamera = ((Component)array[i]).gameObject;
			}
			if (((Object)((Component)array[i]).gameObject).name == "Head")
			{
				driver.playerHead = ((Component)array[i]).gameObject;
			}
		}
		hasInitialized = true;
	}
}