Decompiled source of MiniJump v0.0.0

MiniJump.dll

Decompiled a month 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.Logging;
using CG;
using CG.Game;
using CG.Game.SpaceObjects.Controllers;
using CG.Input;
using CG.Ship.Modules;
using CG.Space;
using Gameplay.SpacePlatforms;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.ModMessages;
using VoidManager.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("MiniJump")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MiniJump")]
[assembly: AssemblyTitle("MiniJump")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 MiniJump
{
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.minijump";

		internal const string PLUGIN_NAME = "MiniJump";

		internal const string PLUGIN_VERSION = "0.0.0";
	}
	[BepInPlugin("id107.minijump", "MiniJump", "0.0.0")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "id107.minijump");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.minijump is loaded!");
		}
	}
	internal class Configs
	{
		public const int jumpCooldownSeconds = 90;

		internal static ConfigEntry<KeyCode> miniJumpKeybind;

		internal static ConfigEntry<bool> allowJumpConfig;

		internal static void Load(BepinPlugin plugin)
		{
			miniJumpKeybind = ((BaseUnityPlugin)plugin).Config.Bind<KeyCode>("MiniJump", "MiniJumpKey", (KeyCode)103, (ConfigDescription)null);
			allowJumpConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("MiniJump", "AllowJump", true, (ConfigDescription)null);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		public override string Name()
		{
			return "Mini Jump";
		}

		public override void Draw()
		{
			GUITools.DrawCheckbox("Allow mini jump", ref Configs.allowJumpConfig);
			GUITools.DrawChangeKeybindButton("Mini jump keybind", ref Configs.miniJumpKeybind);
		}
	}
	internal class Jump
	{
		private static readonly FieldInfo playerShipSpacePlatformField = AccessTools.Field(typeof(AbstractPlayerControlledShip), "playerShipSpacePlatform");

		internal static DateTime lastJumpTime = DateTime.MinValue;

		private static bool InVoid
		{
			get
			{
				ClientGame current = ClientGame.Current;
				object obj;
				if (current == null)
				{
					obj = null;
				}
				else
				{
					AbstractPlayerControlledShip playerShip = current.PlayerShip;
					if (playerShip == null)
					{
						obj = null;
					}
					else
					{
						GameObject gameObject = ((AbstractCloneStarObject)playerShip).GameObject;
						obj = ((gameObject != null) ? gameObject.GetComponent<VoidJumpSystem>() : null);
					}
				}
				VoidJumpSystem val = (VoidJumpSystem)obj;
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				VoidJumpState activeState = val.ActiveState;
				if (activeState is VoidJumpTravellingStable || activeState is VoidJumpTravellingUnstable || activeState is VoidJumpInterdiction || activeState is VoidJumpApproachingDestination || activeState is VoidJumpSpinningDown)
				{
					return true;
				}
				return false;
			}
		}

		internal static int CooldownRemaining()
		{
			int num = (int)(lastJumpTime.AddSeconds(90.0) - DateTime.Now).TotalSeconds;
			if (num > 0)
			{
				return num;
			}
			return 0;
		}

		internal static void CheckDoJump(object sender, EventArgs e)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (!Tools.PlayerShipExists || InVoid)
			{
				return;
			}
			InputService instance = ServiceBase<InputService>.Instance;
			if (instance == null)
			{
				return;
			}
			CursorVisibilityControl cursorVisibilityControl = instance.CursorVisibilityControl;
			if (((cursorVisibilityControl != null) ? new bool?(cursorVisibilityControl.IsCursorShown) : null) != false || (int)Configs.miniJumpKeybind.Value == 0 || !UnityInput.Current.GetKeyDown(Configs.miniJumpKeybind.Value))
			{
				return;
			}
			AbstractPlayerControlledShip playerShip = ClientGame.Current.PlayerShip;
			ChairBase chair = ((Component)playerShip).GetComponentInChildren<Helm>().Chair;
			TakeoverChair val = (TakeoverChair)(object)((chair is TakeoverChair) ? chair : null);
			if (val.IsAvailable || !((MonoBehaviourPun)val).photonView.AmOwner)
			{
				return;
			}
			VoidDriveModule componentInChildren = ((AbstractCloneStarObject)playerShip).GameObject.GetComponentInChildren<VoidDriveModule>();
			if (!componentInChildren.IsFullyCharged)
			{
				Messaging.Notification("Void drive not charged", 8000L, false);
				return;
			}
			int num = CooldownRemaining();
			if (num > 0)
			{
				Messaging.Notification($"Mini Jump on cooldown for {num} seconds", 8000L, false);
			}
			else if (PhotonNetwork.IsMasterClient)
			{
				if (Configs.allowJumpConfig.Value)
				{
					DoJump();
				}
			}
			else
			{
				MessageHandler.RequestJump();
			}
		}

		internal static void DoJump()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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)
			ClientGame current = ClientGame.Current;
			AbstractPlayerControlledShip val = ((current != null) ? current.PlayerShip : null);
			VoidDriveModule componentInChildren = ((AbstractCloneStarObject)val).GameObject.GetComponentInChildren<VoidDriveModule>();
			componentInChildren.StopEnginesCharging();
			MovingSpacePlatform val2 = (MovingSpacePlatform)playerShipSpacePlatformField.GetValue(val);
			Vector3 val3 = val2.Rotation * Vector3.forward;
			AccelerateThenJump(val2, val3 * 50f, val3 * 4500f, 20);
		}

		private static void AccelerateThenJump(MovingSpacePlatform platform, Vector3 velocityIncrease, Vector3 jumpDistance, int durationTicks)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			MovingSpacePlatform obj = platform;
			((SpacePlatform)obj).Velocity = ((SpacePlatform)obj).Velocity + velocityIncrease;
			if (durationTicks > 0)
			{
				Tools.DelayDo((Action)delegate
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000d: Unknown result type (might be due to invalid IL or missing references)
					AccelerateThenJump(platform, velocityIncrease, jumpDistance, durationTicks - 1);
				}, 1.0);
			}
			else
			{
				MovingSpacePlatform obj2 = platform;
				obj2.CorrectedPosition += jumpDistance;
				MessageHandler.NotifyJump();
			}
		}
	}
	internal class MessageHandler : ModMessage
	{
		private enum MessageType
		{
			request,
			approve,
			deny,
			notify
		}

		private const int version = 2;

		public override void Handle(object[] arguments, Player sender)
		{
			if (arguments.Length < 2)
			{
				return;
			}
			if ((int)arguments[0] != 2)
			{
				BepinPlugin.Log.LogInfo((object)$"Expected version {2}, got {(int)arguments[0]}");
				return;
			}
			switch ((MessageType)arguments[1])
			{
			case MessageType.request:
			{
				if (!PhotonNetwork.IsMasterClient)
				{
					break;
				}
				if (!Configs.allowJumpConfig.Value)
				{
					DenyJump(sender, 0);
					break;
				}
				int num2 = Jump.CooldownRemaining();
				if (num2 == 0)
				{
					ApproveJump(sender);
				}
				else
				{
					DenyJump(sender, num2);
				}
				break;
			}
			case MessageType.approve:
				if (sender == PhotonNetwork.MasterClient)
				{
					Jump.DoJump();
				}
				break;
			case MessageType.deny:
				if (sender == PhotonNetwork.MasterClient && arguments.Length >= 3)
				{
					int num = (int)arguments[2];
					if (num == 0)
					{
						Messaging.Notification("Mini Jump currently disabled by host", 8000L, false);
					}
					else
					{
						Messaging.Notification($"Mini Jump on cooldown for {num} seconds", 8000L, false);
					}
				}
				break;
			case MessageType.notify:
				Jump.lastJumpTime = DateTime.Now;
				break;
			}
		}

		internal static void RequestJump()
		{
			if (!PhotonNetwork.IsMasterClient)
			{
				ModMessage.Send("id107.minijump", ModMessage.GetIdentifier(typeof(MessageHandler)), (ReceiverGroup)2, new object[2]
				{
					2,
					MessageType.request
				}, false);
			}
		}

		internal static void ApproveJump(Player sender)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				ModMessage.Send("id107.minijump", ModMessage.GetIdentifier(typeof(MessageHandler)), sender, new object[2]
				{
					2,
					MessageType.approve
				}, false);
			}
		}

		internal static void DenyJump(Player sender, int cooldown)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				ModMessage.Send("id107.minijump", ModMessage.GetIdentifier(typeof(MessageHandler)), sender, new object[3]
				{
					2,
					MessageType.deny,
					cooldown
				}, false);
			}
		}

		internal static void NotifyJump()
		{
			ModMessage.Send("id107.minijump", ModMessage.GetIdentifier(typeof(MessageHandler)), (ReceiverGroup)1, new object[2]
			{
				2,
				MessageType.notify
			}, false);
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)4;

		public override string Author => "18107";

		public override string Description => "Allows the ship to make a short range jump within a system";

		public VoidManagerPlugin()
		{
			Events.Instance.LateUpdate += Jump.CheckDoJump;
		}
	}
}