Decompiled source of BetterSpectator v1.2.1

Mods/BetterSpectator.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using MelonLoader;
using MelonLoader.Preferences;
using ModThatIsNotMod;
using ModThatIsNotMod.BoneMenu;
using UnhollowerBaseLib;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
using aaaaaaaaaaaaaaaa;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Class2), "Better Spectator", "1.1.0", "spark", null)]
[assembly: MelonGame("Stress Level Zero", "BONEWORKS")]
[assembly: AssemblyTitle("BetterSpectator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterSpectator")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d4732d09-e14e-49cf-bc74-304efc5869dc")]
[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 aaaaaaaaaaaaaaaa;

public class Class2 : MelonMod
{
	public MenuCategory bonemenupage;

	private Camera actioncamera;

	private GameObject cameraobject;

	private Transform rigmanager;

	private Transform parentbackup;

	public GameObject brettbody;

	public GameObject brettface;

	public GameObject bretthaircap;

	public GameObject bretthaircards;

	public GameObject camanchorholster;

	private SkinnedMeshRenderer bodysmr;

	private float setfov;

	private bool setnotifications;

	private bool setshowhead;

	private bool alreadyloaded;

	private bool alreadynotified;

	private bool alreadywarned;

	private bool alreadywarnedabtplrhead;

	private bool bugfixthing;

	private bool configuratedpivot;

	private bool anchored;

	private bool lookat;

	private bool shouldlookat;

	private Vector3 ogpivotpos;

	private Quaternion ogpivotrot;

	private MelonPreferences_Category spectatorprefs;

	private MelonPreferences_Entry<float> savedfov;

	private MelonPreferences_Entry<bool> savednotifications;

	private MelonPreferences_Entry<bool> savedhead;

	public override void OnInitializeMelon()
	{
		spectatorprefs = MelonPreferences.CreateCategory("Better Spectator");
		savedfov = spectatorprefs.CreateEntry<float>("FOV", 90f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		savednotifications = spectatorprefs.CreateEntry<bool>("Notifications", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		savedhead = spectatorprefs.CreateEntry<bool>("Show Player Head", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
	}

	public void updatevalues()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		MelonPreferences.Save();
		if (savednotifications.Value)
		{
			Notifications.SendNotification("Applied settings!", 2f, Color.white);
			MelonLogger.Msg("Applied settings!");
		}
		if (anchored)
		{
			bugfixthing = true;
			if ((Object)(object)camanchorholster == (Object)null)
			{
				GameObject val = new GameObject();
				parentbackup = cameraobject.transform.parent;
				ogpivotpos = cameraobject.transform.localPosition;
				ogpivotrot = cameraobject.transform.localRotation;
				configuratedpivot = true;
				camanchorholster = val;
				camanchorholster.transform.parent = rigmanager;
				camanchorholster.transform.position = parentbackup.position;
				camanchorholster.transform.rotation = parentbackup.rotation;
			}
			cameraobject.transform.parent = camanchorholster.transform;
			Camera component = cameraobject.GetComponent<Camera>();
			if ((Object)(object)component != (Object)null)
			{
				actioncamera = component;
			}
			if (savedhead.Value)
			{
				if (((Renderer)bodysmr).enabled)
				{
					brettface.SetActive(true);
					bretthaircap.SetActive(true);
					bretthaircards.SetActive(true);
				}
				else if (!((Renderer)bodysmr).enabled && savednotifications.Value)
				{
					Notifications.SendNotification("Show Player Head does not support custom avatars.", 1f, Color.red);
					MelonLogger.Msg("Show Player Head does not support custom avatars.");
				}
			}
			else if (!savedhead.Value)
			{
				brettface.SetActive(false);
				bretthaircap.SetActive(false);
				bretthaircards.SetActive(false);
			}
		}
		else if (!anchored && bugfixthing)
		{
			cameraobject.transform.parent = parentbackup;
			bugfixthing = false;
		}
		if (cameraobject.activeSelf && savedhead.Value && (Object)(object)bodysmr != (Object)null && anchored && ((Renderer)bodysmr).enabled)
		{
			if ((Object)(object)brettface != (Object)null)
			{
				brettface.SetActive(true);
			}
			if ((Object)(object)bretthaircap != (Object)null)
			{
				bretthaircap.SetActive(true);
			}
			if ((Object)(object)bretthaircards != (Object)null)
			{
				bretthaircards.SetActive(true);
			}
		}
		if (lookat)
		{
			shouldlookat = true;
		}
		else if (!lookat)
		{
			shouldlookat = false;
		}
		actioncamera.fieldOfView = savedfov.Value;
	}

	public void hfghjgjfgfj()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
		if (!alreadyloaded)
		{
			alreadyloaded = true;
			bonemenupage = MenuManager.CreateCategory("Better Spectator", Color.white);
			bonemenupage.CreateFloatElement("FOV", Color.blue, savedfov.Value, (Action<float>)delegate(float fovfloat)
			{
				setfov = fovfloat;
				savedfov.Value = fovfloat;
			}, 1f, 10f, 120f, true);
			bonemenupage.CreateBoolElement("Notifications", Color.magenta, savednotifications.Value, (Action<bool>)delegate(bool notifsenabled)
			{
				setnotifications = notifsenabled;
				savednotifications.Value = notifsenabled;
			});
			bonemenupage.CreateBoolElement("Camera Anchored", Color.red, false, (Action<bool>)delegate(bool anchoredcam)
			{
				anchored = anchoredcam;
			});
			bonemenupage.CreateBoolElement("Show Player Head", Color.cyan, savedhead.Value, (Action<bool>)delegate(bool showheadenabled)
			{
				setshowhead = showheadenabled;
				savedhead.Value = showheadenabled;
			});
			bonemenupage.CreateBoolElement("Look At Player", Color.yellow, false, (Action<bool>)delegate(bool lookatplayerval)
			{
				lookat = lookatplayerval;
			});
			bonemenupage.CreateFunctionElement("Apply Settings", Color.green, (Action)delegate
			{
				updatevalues();
			});
			bonemenupage.CreateFunctionElement("Reset Camera Pivot", Color.grey, (Action)delegate
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)cameraobject != (Object)null && configuratedpivot && !anchored)
				{
					cameraobject.transform.localPosition = ogpivotpos;
					cameraobject.transform.localRotation = ogpivotrot;
				}
			});
		}
		Il2CppArrayBase<GameObject> val = Resources.FindObjectsOfTypeAll<GameObject>();
		foreach (GameObject item in val)
		{
			if (((Object)item).name.Contains("Follow"))
			{
				Camera component = item.GetComponent<Camera>();
				if ((Object)(object)component != (Object)null)
				{
					PostProcessLayer component2 = item.GetComponent<PostProcessLayer>();
					PostProcessVolume component3 = item.GetComponent<PostProcessVolume>();
					if ((Object)(object)component2 != (Object)null)
					{
						((Behaviour)component2).enabled = false;
					}
					if ((Object)(object)component3 != (Object)null)
					{
						((Behaviour)component3).enabled = false;
					}
					actioncamera = component;
					cameraobject = item;
					component.fieldOfView = savedfov.Value;
					component.allowHDR = false;
					component.allowMSAA = false;
				}
			}
			else if (((Object)item).name.Contains("[RigManager (Default Brett)]"))
			{
				rigmanager = item.transform;
			}
			else if (((Object)item).name.Contains("brett_body"))
			{
				brettbody = item;
				SkinnedMeshRenderer component4 = brettbody.GetComponent<SkinnedMeshRenderer>();
				if ((Object)(object)component4 != (Object)null)
				{
					bodysmr = component4;
				}
			}
			else if (((Object)item).name.Contains("brett_face"))
			{
				brettface = item;
			}
			else if (((Object)item).name.Contains("brett_hairCap"))
			{
				bretthaircap = item;
			}
			else if (((Object)item).name.Contains("brett_hairCards"))
			{
				bretthaircards = item;
			}
		}
		if (!alreadynotified)
		{
			alreadynotified = true;
			if (savednotifications.Value)
			{
				Notifications.SendNotification("Sucessfully loaded Better Spectator!", 3f, Color.white);
				MelonLogger.Msg("Sucessfully loaded Better Spectator!");
			}
		}
		if (!alreadywarned)
		{
			alreadywarned = true;
			if (!cameraobject.activeSelf && savednotifications.Value)
			{
				Notifications.SendNotification("Action camera is turned off, camera modifications will not take affect.", 2f, Color.red);
				MelonLogger.Msg("Action camera is turned off, camera modifications will not take affect.");
			}
		}
		if (!alreadywarnedabtplrhead)
		{
			alreadywarnedabtplrhead = true;
			if (!((Renderer)bodysmr).enabled && savednotifications.Value)
			{
				Notifications.SendNotification("Show Player Head does not support custom avatars.", 1f, Color.red);
				MelonLogger.Msg("Show Player Head does not support custom avatars.");
			}
		}
	}

	public override void OnUpdate()
	{
		if (shouldlookat && (Object)(object)cameraobject != (Object)null && (Object)(object)parentbackup != (Object)null)
		{
			cameraobject.transform.LookAt(parentbackup);
		}
		if ((Object)(object)cameraobject != (Object)null && !cameraobject.activeSelf && savedhead.Value)
		{
			if ((Object)(object)brettface != (Object)null)
			{
				brettface.SetActive(false);
			}
			if ((Object)(object)bretthaircap != (Object)null)
			{
				bretthaircap.SetActive(false);
			}
			if ((Object)(object)bretthaircards != (Object)null)
			{
				bretthaircards.SetActive(false);
			}
		}
		if ((Object)(object)actioncamera != (Object)null && actioncamera.fieldOfView == 0f)
		{
			actioncamera.fieldOfView = setfov;
		}
		if ((Object)(object)brettbody != (Object)null && (Object)(object)bodysmr != (Object)null && !((Renderer)bodysmr).enabled)
		{
			if ((Object)(object)brettface != (Object)null)
			{
				brettface.SetActive(false);
			}
			if ((Object)(object)bretthaircap != (Object)null)
			{
				bretthaircap.SetActive(false);
			}
			if ((Object)(object)bretthaircards != (Object)null)
			{
				bretthaircards.SetActive(false);
			}
		}
	}

	public override void OnSceneWasInitialized(int buildIndex, string sceneName)
	{
		hfghjgjfgfj();
	}

	public override void OnApplicationStart()
	{
		MelonLogger.Msg("Mod started!");
	}
}