Decompiled source of NoJiggle v1.1.0

NoJiggle.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was partially or fully created with the assistance of Generative AI: the code was written with Claude and tested in game by the author.")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace NoJiggle;

[BepInPlugin("charles.nojiggle", "NoJiggle", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "charles.nojiggle";

	public const string Version = "1.1.0";

	internal static ConfigEntry<bool> DisableJiggle;

	internal static ConfigEntry<bool> DisableRadarHeadCam;

	private static readonly FieldRef<ManualCameraRenderer, bool> EnableHeadCam = AccessTools.FieldRefAccess<ManualCameraRenderer, bool>("enableHeadMountedCam");

	private void Awake()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		DisableJiggle = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableJigglePhysics", true, "Turn off jiggle physics (dynamic bones) on all player models to save FPS.");
		DisableRadarHeadCam = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableRadarHeadCam", false, "Turn off the head camera view that the ship's radar monitor shows for the player it follows, to save FPS.");
		Harmony val = new Harmony("charles.nojiggle");
		HarmonyMethod val2 = new HarmonyMethod(typeof(Plugin).GetMethod("SkipJiggleUpdate", BindingFlags.Static | BindingFlags.NonPublic));
		int num = 0;
		string[] array = new string[2] { "JigglePhysics.JiggleRigHandler", "JigglePhysicsPlugin.JiggleRigHandler" };
		foreach (string text in array)
		{
			Type type = AccessTools.TypeByName(text);
			MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "UpdateJiggleRigs", (Type[])null, (Type[])null));
			if (methodInfo == null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)(text + " not installed, skipped."));
				continue;
			}
			val.Patch((MethodBase)methodInfo, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			num++;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Patched " + text + ".UpdateJiggleRigs"));
		}
		HarmonyMethod val3 = new HarmonyMethod(typeof(Plugin).GetMethod("HeadCamOff", BindingFlags.Static | BindingFlags.NonPublic));
		val.Patch((MethodBase)AccessTools.Method(typeof(ManualCameraRenderer), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, val3, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(ManualCameraRenderer), "LateUpdate", (Type[])null, (Type[])null), (HarmonyMethod)null, val3, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("NoJiggle 1.1.0 loaded: " + num + " jiggle system(s) patched, jiggle off = " + DisableJiggle.Value + ", radar head cam off = " + DisableRadarHeadCam.Value));
	}

	private static bool SkipJiggleUpdate()
	{
		return !DisableJiggle.Value;
	}

	private static void HeadCamOff(ManualCameraRenderer __instance)
	{
		if (DisableRadarHeadCam.Value)
		{
			EnableHeadCam.Invoke(__instance) = false;
			Camera headMountedCam = __instance.headMountedCam;
			if ((Object)(object)headMountedCam != (Object)null && ((Behaviour)headMountedCam).enabled)
			{
				((Behaviour)headMountedCam).enabled = false;
			}
			RawImage headMountedCamUI = __instance.headMountedCamUI;
			if ((Object)(object)headMountedCamUI != (Object)null && ((Behaviour)headMountedCamUI).enabled)
			{
				((Behaviour)headMountedCamUI).enabled = false;
			}
		}
	}
}