Decompiled source of QuickerVote v1.0.2

QuickerVote.dll

Decompiled 6 months 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 BepInEx.Logging;
using HarmonyLib;
using TMPro;
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("QuickerVote")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("QuickerVote")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8b6b7379-43f3-4894-9b33-a38d5774e7d7")]
[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 QuickerVote;

[BepInPlugin("Swaggies.QuickerVote", "QuickerVote", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
	private const string _guid = "Swaggies.QuickerVote";

	private const string _name = "QuickerVote";

	private const string _ver = "1.0.2";

	private readonly Harmony harmony = new Harmony("Swaggies.QuickerVote");

	private static Plugin Instance;

	private static ManualLogSource logga;

	public static ConfigEntry<float> timerMax;

	private static float patchedVoteToLeaveEarlyTimer;

	private static bool votedThisGame;

	private void Awake()
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		logga = Logger.CreateLogSource("Swaggies.QuickerVote");
		harmony.PatchAll(typeof(Plugin));
		logga.LogInfo((object)"QuickerVote up and running.");
		timerMax = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TimeToCastVote", 1f, new ConfigDescription("How long in seconds you need to hold RMB for your vote to be cast.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 3f), Array.Empty<object>()));
	}

	[HarmonyPatch(typeof(HUDManager), "Update")]
	[HarmonyPostfix]
	private static void HUDUpdatePatch(ref HUDManager __instance, ref float ___holdButtonToEndGameEarlyHoldTime)
	{
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		___holdButtonToEndGameEarlyHoldTime = 0f;
		if (StartOfRound.Instance.inShipPhase)
		{
			votedThisGame = false;
		}
		else
		{
			if (!GameNetworkManager.Instance.localPlayerController.isPlayerDead || StartOfRound.Instance.shipIsLeaving || !StartOfRound.Instance.currentLevel.planetHasTime || TimeOfDay.Instance.shipLeavingAlertCalled || votedThisGame)
			{
				return;
			}
			MovementActions movement = __instance.playerActions.Movement;
			if (!((MovementActions)(ref movement)).PingScan.IsPressed())
			{
				patchedVoteToLeaveEarlyTimer = 0f;
				((TMP_Text)__instance.holdButtonToEndGameEarlyText).text = (StartOfRound.Instance.localPlayerUsingController ? "Tell autopilot ship to leave early : [R-trigger] (Hold)" : "Tell autopilot ship to leave early : [RMB] (Hold)");
				return;
			}
			patchedVoteToLeaveEarlyTimer += Time.deltaTime;
			float num = Mathf.Clamp(patchedVoteToLeaveEarlyTimer / timerMax.Value, 0f, 1f);
			((TMP_Text)__instance.holdButtonToEndGameEarlyText).text = $"Tell autopilot ship to leave early : Voting... <size=120%>{Math.Floor(num * 100f)}%</size>";
			__instance.holdButtonToEndGameEarlyMeter.fillAmount = num;
			if (num >= 1f)
			{
				votedThisGame = true;
				TimeOfDay.Instance.VoteShipToLeaveEarly();
				((TMP_Text)__instance.holdButtonToEndGameEarlyText).text = "Voted for ship to leave early.";
				___holdButtonToEndGameEarlyHoldTime = 999f;
			}
		}
	}
}