Decompiled source of ShakePlugin v1.1.0

ShakePlugin.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using ModdingTales;
using Unity.Mathematics;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ShakePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShakePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("ShakePlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.shake", "Shake Plug-In", "1.1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ShakePlugin : BaseUnityPlugin
{
	public static class Utility
	{
		public static void PostOnMainPage(BaseUnityPlugin plugin)
		{
			string text = "Lord Ashes" + ("Lord Ashes".ToUpper().EndsWith("S") ? "'" : "'s");
			ModdingUtils.AddPluginToMenuList(plugin, text);
		}

		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}
	}

	public const string Name = "Shake Plug-In";

	public const string Guid = "org.lordashes.plugins.shake";

	public const string Version = "1.1.0.0";

	public const string Author = "Lord Ashes";

	private int shakeCounter = 0;

	private int shakeIntervalCounter = 0;

	private CutsceneData cameraRestorePoint = default(CutsceneData);

	private CutsceneData shakePoint = default(CutsceneData);

	private Random random = new Random();

	private ConfigEntry<KeyboardShortcut> triggerKey { get; set; }

	private ConfigEntry<int> settingShakeIndifference { get; set; }

	private ConfigEntry<int> settingShakeMaxDeflection { get; set; }

	private ConfigEntry<int> settingShakeFramesDuration { get; set; }

	private ConfigEntry<bool> settingsMakeLogEntries { get; set; }

	private void Awake()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)("Share Assets Plugin: " + ((object)this).GetType().AssemblyQualifiedName + " Active."));
		triggerKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Shake Camera", new KeyboardShortcut((KeyCode)280, Array.Empty<KeyCode>()), (ConfigDescription)null);
		settingShakeIndifference = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Shake Indifference", 5, (ConfigDescription)null);
		settingShakeMaxDeflection = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Shake Max Distance", 10, (ConfigDescription)null);
		settingShakeFramesDuration = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Shake Frames Duration", 100, (ConfigDescription)null);
		settingsMakeLogEntries = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "Make Log Entries", false, (ConfigDescription)null);
		AssetDataPlugin.Subscribe("org.lordashes.plugins.shake", (Action<DatumChange>)ShakeRequest);
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	private void Update()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (!Utility.isBoardLoaded())
		{
			return;
		}
		KeyboardShortcut value = triggerKey.Value;
		if (((KeyboardShortcut)(ref value)).IsUp())
		{
			if (LocalClient.IsInGmMode)
			{
				AssetDataPlugin.SendInfo("org.lordashes.plugins.shake", "Shake It Baby! (" + DateTime.UtcNow.ToString() + ")");
			}
			else
			{
				SystemMessage.DisplayInfoText("Players Can't Shake It Like The GM Can!", 2.5f, 0f);
			}
		}
	}

	private void OnGUI()
	{
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		if (shakeCounter <= 0)
		{
			return;
		}
		if (settingsMakeLogEntries.Value)
		{
			Debug.Log((object)("Shake Plugin: Shake Count = " + shakeCounter + ", Shake Indifference Count = " + shakeIntervalCounter));
		}
		if (shakeIntervalCounter > 0)
		{
			shakeIntervalCounter--;
		}
		else
		{
			if (settingsMakeLogEntries.Value)
			{
				Debug.Log((object)"Shake Plugin: Shake!");
			}
			LegacyCutsceneSetup cutsceneSetup = CameraController.CutsceneSetup;
			shakePoint.Position = float3.op_Implicit(new Vector3(cameraRestorePoint.Position.x + (float)random.Next(-1 * settingShakeMaxDeflection.Value, settingShakeMaxDeflection.Value) / 100f, cameraRestorePoint.Position.y + (float)random.Next(-1 * settingShakeMaxDeflection.Value, settingShakeMaxDeflection.Value) / 100f, cameraRestorePoint.Position.z + (float)random.Next(-1 * settingShakeMaxDeflection.Value, settingShakeMaxDeflection.Value) / 100f));
			cutsceneSetup.PreviewCutsceneState(shakePoint);
			shakeIntervalCounter = settingShakeIndifference.Value;
		}
		shakeCounter--;
		if (shakeCounter == 0)
		{
			if (settingsMakeLogEntries.Value)
			{
				Debug.Log((object)"Shake Plugin: Shake Complete. Restoring Camera");
			}
			LegacyCutsceneSetup cutsceneSetup2 = CameraController.CutsceneSetup;
			cutsceneSetup2.PreviewCutsceneState(cameraRestorePoint);
		}
	}

	private void ShakeRequest(DatumChange obj)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		if (settingsMakeLogEntries.Value)
		{
			Debug.Log((object)"Shake Plugin: Shake Request");
		}
		if (shakeCounter == 0)
		{
			if (settingsMakeLogEntries.Value)
			{
				Debug.Log((object)"Shake Plugin: Create Shake");
			}
			shakeCounter = settingShakeFramesDuration.Value;
			shakeIntervalCounter = settingShakeIndifference.Value;
			cameraRestorePoint = CameraController.CutsceneSetup.GetCutsceneState();
			shakePoint = new CutsceneData
			{
				Guid = cameraRestorePoint.Guid,
				HidePlaneHeight = cameraRestorePoint.HidePlaneHeight,
				Position = float3.op_Implicit(Vector3.zero),
				RotationEuler = cameraRestorePoint.RotationEuler,
				TiltEuler = cameraRestorePoint.TiltEuler,
				Zoom = cameraRestorePoint.Zoom
			};
		}
		else
		{
			if (settingsMakeLogEntries.Value)
			{
				Debug.Log((object)"Shake Plugin: Extend Current Shake");
			}
			shakeCounter = settingShakeFramesDuration.Value;
			shakeIntervalCounter = settingShakeIndifference.Value;
		}
	}
}