Decompiled source of Disregard Early Voting v1.0.2

NicholaScott.LethalCompany.ControlDeathVoting.dll

Decompiled 11 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 HarmonyLib;
using NicholaScott.BepInEx.Utils.Configuration;
using NicholaScott.BepInEx.Utils.Instancing;
using NicholaScott.BepInEx.Utils.Patching;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NicholaScott.LethalCompany.ControlDeathVoting")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NicholaScott.LethalCompany.ControlDeathVoting")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("A319A87A-6846-4876-8B42-C043875E31CF")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NicholaScott.LethalCompany.ControlDeathVoting;

[BepInDependency("NicholaScott.BepInEx.Utils", "1.2.0")]
[BepInPlugin("NicholaScott.LethalCompany.ControlDeathVoting", "Control Death Voting", "1.0.2")]
public class ControlDeathVoting : BaseUnityPlugin
{
	public struct Configuration
	{
		public enum VoteType
		{
			Vanilla,
			MoreThanOne,
			NoVoting
		}

		[ConfigEntryDefinition(Description = "Vanilla changes nothing. MoreThanOne requires at least 2 votes to leave. NoVoting disables early ship voting entirely.")]
		public VoteType VoteHandling;

		[ConfigEntryDefinition(Description = "Multiplied by the default value of time to wait once a successful vote is cast before the ship leaves.")]
		public float ScaleShipLeaveDelay;
	}

	public void Awake()
	{
		Singleton<ControlDeathVoting>.Instance = this;
		Singleton<ControlDeathVoting, Configuration>.Configuration = Extensions.BindStruct<Configuration>(((BaseUnityPlugin)this).Config, new Configuration
		{
			VoteHandling = Configuration.VoteType.MoreThanOne,
			ScaleShipLeaveDelay = 1f
		});
		Extensions.PatchAttribute<Production>(Assembly.GetExecutingAssembly(), ((BaseUnityPlugin)this).Info.Metadata.GUID, (Action<object>)((BaseUnityPlugin)this).Logger.LogInfo);
	}
}
[Production]
public static class VotingPatches
{
	[HarmonyPatch(typeof(TimeOfDay), "SetShipLeaveEarlyServerRpc")]
	[HarmonyPrefix]
	public static bool IgnoreVotesIfServer(TimeOfDay __instance)
	{
		ControlDeathVoting.Configuration configuration = Singleton<ControlDeathVoting, ControlDeathVoting.Configuration>.Configuration;
		switch (configuration.VoteHandling)
		{
		case ControlDeathVoting.Configuration.VoteType.Vanilla:
			return true;
		case ControlDeathVoting.Configuration.VoteType.MoreThanOne:
			__instance.votesForShipToLeaveEarly++;
			if (__instance.votesForShipToLeaveEarly > 1 && __instance.votesForShipToLeaveEarly >= StartOfRound.Instance.connectedPlayersAmount + 1 - StartOfRound.Instance.livingPlayers)
			{
				__instance.SetShipLeaveEarlyClientRpc(__instance.normalizedTimeOfDay + 0.1f * configuration.ScaleShipLeaveDelay, __instance.votesForShipToLeaveEarly);
			}
			else
			{
				__instance.AddVoteForShipToLeaveEarlyClientRpc();
			}
			return false;
		case ControlDeathVoting.Configuration.VoteType.NoVoting:
			__instance.votesForShipToLeaveEarly++;
			__instance.AddVoteForShipToLeaveEarlyClientRpc();
			return false;
		default:
			return false;
		}
	}
}