Decompiled source of ShipCam Pro v0.3.0

kruft.ShipCamPro.dll

Decompiled 2 weeks 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.Unity.IL2CPP;
using Bossa.Cinematika;
using Bossa.Cinematika.Controllers;
using Bossa.Dynamika.Character;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using WildSkies.Input;
using WildSkies.Player;
using WildSkies.ShipParts;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("kruft")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Saves the 3rd-person toggle state and allows the camera to zoom, wrap around, and lock in place.")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+81c388268d416e809ea4a81f49fd4aeb73964ea6")]
[assembly: AssemblyProduct("ShipCam Pro")]
[assembly: AssemblyTitle("kruft.ShipCamPro")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/kruftt/LostSkiesMods/tree/main/ShipCamPro")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ShipCamPro
{
	internal class ShipCamProPatch
	{
		private const float SCROLL_SENSITIVITY = 0.1f;

		private const float MIN_ZOOM_DISTANCE = 2f;

		private static bool _isOnTurret = false;

		private static bool _isLooking = false;

		private static bool _hasTurned = false;

		private static bool _releaseCamera = false;

		private static bool _thirdPerson = false;

		private static float _zoom = 5f;

		private static float _angleX = 0f;

		private static float _angleY = 0f;

		private static Vector3 OFFSET_BASE = new Vector3(0f, 0f, -1f);

		private static Vector3 _thirdPersonOffset => OFFSET_BASE * _zoom;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LocalPlayer), "DropInteraction")]
		private static void ResetRemoteAiming(LocalPlayer __instance)
		{
			_isOnTurret = false;
			UserControlShip userControlShip = __instance._userControlShip;
			userControlShip._isRemoteAiming = false;
			ShipWeapon currentRemoteWeapon = userControlShip._currentRemoteWeapon;
			if ((Object)(object)currentRemoteWeapon != (Object)null)
			{
				currentRemoteWeapon.SetPilot((DynamikaCharacter)null);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(LocalPlayer), "PilotTurret")]
		private static void IsOnTurret(LocalPlayer __instance)
		{
			_isOnTurret = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LocalPlayer), "TakeControlOfShip")]
		private static void ApplyThirdPersonState(LocalPlayer __instance, Helm helm)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			_isOnTurret = false;
			PilotCinematikaController controller = __instance._cameraManager.GetController<PilotCinematikaController>();
			if (_thirdPerson && !controller.ThirdPerson)
			{
				controller.ThirdPersonToggle();
			}
			Settings currentSettings = controller.CurrentSettings;
			Vector3 thirdPersonOffset = _thirdPersonOffset;
			if (ShipCamProPlugin.cameraWrap.Value)
			{
				currentSettings._xWrap = true;
			}
			currentSettings._thirdPersonOffset = thirdPersonOffset;
			currentSettings._thirdPersonOffsetLowY = thirdPersonOffset;
			currentSettings._thirdPersonOffsetHighY = thirdPersonOffset;
			currentSettings._maxAngles.y = 89f;
			currentSettings._minAngles.y = -89f;
			controller.CurrentSettings = currentSettings;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PilotCinematikaController), "ThirdPersonToggle")]
		private static void ThirdPersonToggle(PilotCinematikaController __instance)
		{
			_thirdPerson = __instance.ThirdPerson;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PilotCinematikaController), "UpdateInput")]
		private static void StoreTargetAngles(PilotCinematikaController __instance, CameraInputState iState)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			_angleX = __instance._targetAngles.x;
			_angleY = __instance._targetAngles.y;
			float y = ((InputControl<Vector2>)(object)Mouse.current.scroll).ReadValue().y;
			if (y != 0f)
			{
				_zoom = Mathf.Clamp(_zoom - _zoom * y * 0.1f, 2f, ShipCamProPlugin.maxZoom.Value);
				Vector3 thirdPersonOffset = _thirdPersonOffset;
				Settings currentSettings = __instance.CurrentSettings;
				currentSettings._thirdPersonOffset = thirdPersonOffset;
				currentSettings._thirdPersonOffsetLowY = thirdPersonOffset;
				currentSettings._thirdPersonOffsetHighY = thirdPersonOffset;
				__instance.CurrentSettings = currentSettings;
			}
			if (iState.LookEnable)
			{
				if (!_isLooking)
				{
					_isLooking = true;
					_hasTurned = false;
					_releaseCamera = false;
				}
				else if (iState.Look != Vector2.zero)
				{
					_hasTurned = true;
				}
			}
			else if (_isLooking)
			{
				if (!_hasTurned)
				{
					_releaseCamera = true;
				}
				_hasTurned = false;
				_isLooking = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPriority(100)]
		[HarmonyPatch(typeof(PilotCinematikaController), "UpdateInput")]
		private static void RestoreTargetAngles(PilotCinematikaController __instance, CameraInputState iState)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (_thirdPerson && !_isOnTurret && !iState.LookEnable && ShipCamProPlugin.cameraLock.Value && !_releaseCamera)
			{
				__instance._targetAngles = new Vector2(_angleX, _angleY);
			}
		}
	}
	[BepInPlugin("kruft.ShipCamPro", "ShipCam Pro", "0.3.0")]
	public class ShipCamProPlugin : BasePlugin
	{
		public static ConfigEntry<bool> cameraLock;

		public static ConfigEntry<bool> cameraWrap;

		public static ConfigEntry<float> maxZoom;

		public override void Load()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("kruft.ShipCamPro").PatchAll(typeof(ShipCamProPatch));
			cameraLock = ((BasePlugin)this).Config.Bind<bool>("General", "Lock_Camera", true, "Lock the free-look camera in place.");
			cameraWrap = ((BasePlugin)this).Config.Bind<bool>("General", "Wrap_Camera", true, "Allow the camera to wrap around.");
			maxZoom = ((BasePlugin)this).Config.Bind<float>("General", "Max_Zoom", 120f, "Maximum zoom distance.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "kruft.ShipCamPro";

		public const string PLUGIN_NAME = "ShipCam Pro";

		public const string PLUGIN_VERSION = "0.3.0";
	}
}