using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using Steamworks.Data;
using TMPro;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EarlyVoteSettings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+e5cbd81f0600a57dc495868fb6d22c52fdca8366")]
[assembly: AssemblyProduct("EarlyVoteSettings")]
[assembly: AssemblyTitle("EarlyVoteSettings")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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;
}
}
}
internal static class LethalConfigCompat
{
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
internal static void Register(ConfigEntry<bool> boolConfigEntry)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"))
{
LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)boolConfigEntry);
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(boolConfigEntry, false));
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
internal static void Register(ConfigEntry<int> intConfigEntry)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"))
{
LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)intConfigEntry);
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(intConfigEntry, false));
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
internal static void Register(ConfigEntry<float> floatConfigEntry)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"))
{
LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)floatConfigEntry);
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(floatConfigEntry, false));
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
internal static void Register(ConfigEntry<string> stringConfigEntry)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"))
{
LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)stringConfigEntry);
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(stringConfigEntry, false));
}
}
}
namespace EarlyVoteSettings
{
internal static class ConfigSettings
{
private static ConfigEntry<int> _minimumVotes;
private static ConfigEntry<string> _minimumVoteOverridesCsv;
private static ConfigEntry<int> _delayModifier;
private static Dictionary<int, int> _minimumVoteOverrides = new Dictionary<int, int>();
private static readonly int _default_minimumVotes = 2;
private static readonly string _default_minimumVoteOverridesCsv = "2=1";
private static readonly int _default_delayModifier = 100;
internal static int DelayModifier = _default_delayModifier;
internal static int MinimumVotes
{
get
{
int val = _minimumVotes?.Value ?? _default_minimumVotes;
int totalPlayers = GameInfo.GetTotalPlayers();
if (!_minimumVoteOverrides.TryGetValue(totalPlayers, out var value))
{
return Math.Max(1, val);
}
return Math.Max(1, value);
}
}
internal static void Init(BaseUnityPlugin plugin)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
ConfigFile config = plugin.Config;
_minimumVotes = config.Bind<int>("Minimum Votes", "MinimumVotes", _default_minimumVotes, new ConfigDescription("The minimum number of votes required for the ship to leave early. \n\nA vote from every dead player is still required.", (AcceptableValueBase)null, Array.Empty<object>()));
_minimumVoteOverridesCsv = config.Bind<string>("Minimum Votes", "MinimumVoteOverrides", _default_minimumVoteOverridesCsv, new ConfigDescription("(Optional) Exact overrides for MinimumVotes based on total number of players. \n\nExample: \"2=1, 5=3, 32=10\" \n\n— This would set the MinimumVotes to 1 for 2 players, 3 for 5 players, and 10 for 32 players. \n\nAny other number of players will use the normal MinimumVotes value.", (AcceptableValueBase)null, Array.Empty<object>()));
_delayModifier = config.Bind<int>("Early Leave Delay", "DelayModifier", _default_delayModifier, new ConfigDescription("A percentage applied to the ship's delay when leaving early. \n\nBy default, this is set to 100% (the normal delay). \n\nExamples:\nIf this is set to 0, there will be no delay. \nIf this is set to 50, the normal delay will be halved. \nIf this is set to 150, the normal delay will be increased by 50%. \nIf this is set to 300, the normal delay will be tripled.", (AcceptableValueBase)null, Array.Empty<object>()));
LethalConfigCompat.Register(_minimumVotes);
LethalConfigCompat.Register(_minimumVoteOverridesCsv);
LethalConfigCompat.Register(_delayModifier);
_minimumVoteOverridesCsv.SettingChanged += ReparseOverrides;
_delayModifier.SettingChanged += OnDelayModifierSettingChanged;
ReparseOverrides();
UpdateDelayModifier();
}
private static void ReparseOverrides()
{
ReparseOverrides(null, EventArgs.Empty);
}
private static void ReparseOverrides(object _, EventArgs __)
{
_minimumVoteOverrides = ParseOverrides(_minimumVoteOverridesCsv.Value);
}
private static void OnDelayModifierSettingChanged(object sender, EventArgs e)
{
UpdateDelayModifier();
}
private static Dictionary<int, int> ParseOverrides(string csv)
{
Dictionary<int, int> dictionary = new Dictionary<int, int>();
if (string.IsNullOrWhiteSpace(csv))
{
return dictionary;
}
string[] array = Regex.Split(csv.Trim().Trim('"'), "[,\\s;]+");
foreach (string text in array)
{
if (text.Length != 0)
{
string[] array2 = text.Split('=');
if (array2.Length == 2 && int.TryParse(array2[0].Trim(), out var result) && int.TryParse(array2[1].Trim(), out var result2))
{
dictionary[result] = Math.Max(1, result2);
}
}
}
return dictionary;
}
private static void UpdateDelayModifier()
{
DelayModifier = _delayModifier?.Value ?? _default_delayModifier;
}
}
internal static class GameInfo
{
internal static int GetTotalPlayers()
{
//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)
if ((Object)(object)StartOfRound.Instance != (Object)null)
{
return StartOfRound.Instance.connectedPlayersAmount + 1;
}
GameNetworkManager instance = GameNetworkManager.Instance;
if ((Object)(object)instance != (Object)null && instance.currentLobby.HasValue)
{
Lobby value = instance.currentLobby.Value;
return ((Lobby)(ref value)).MemberCount;
}
return 1;
}
}
[BepInPlugin("Azx.EarlyVoteSettings", "Early Vote Settings", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "Azx.EarlyVoteSettings";
public const string PluginName = "Early Vote Settings";
public const string PluginVersion = "1.0.0";
internal static ManualLogSource Log;
internal static Harmony Harmony;
internal static Plugin Instance;
private void Awake()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
Harmony = new Harmony("Azx.EarlyVoteSettings");
ConfigSettings.Init((BaseUnityPlugin)(object)this);
Harmony.PatchAll();
Log.LogInfo((object)"Early Vote Settings 1.0.0 loaded.");
}
internal static bool IsHost()
{
if (Object.op_Implicit((Object)(object)NetworkManager.Singleton))
{
if (!NetworkManager.Singleton.IsServer)
{
return NetworkManager.Singleton.IsHost;
}
return true;
}
return false;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "EarlyVoteSettings";
public const string PLUGIN_NAME = "EarlyVoteSettings";
public const string PLUGIN_VERSION = "0.0.1";
}
}
namespace EarlyVoteSettings.Patches
{
[HarmonyPatch(typeof(TimeOfDay), "SetShipLeaveEarlyServerRpc")]
public static class DelayServerPatch
{
[HarmonyPrefix]
public static bool Prefix(TimeOfDay __instance)
{
NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
{
return false;
}
if (!networkManager.IsServer && !networkManager.IsHost)
{
return true;
}
__instance.votesForShipToLeaveEarly++;
int num = StartOfRound.Instance.connectedPlayersAmount + 1 - StartOfRound.Instance.livingPlayers;
if (__instance.votesForShipToLeaveEarly >= num)
{
float num2 = Mathf.Max(0f, (float)ConfigSettings.DelayModifier) * 0.01f;
float num3 = 0.1f;
float num4 = __instance.normalizedTimeOfDay + num3 * num2;
num4 = Mathf.Min(num4, 0.99f);
__instance.SetShipLeaveEarlyClientRpc(num4, __instance.votesForShipToLeaveEarly);
}
else
{
__instance.AddVoteForShipToLeaveEarlyClientRpc();
}
return false;
}
}
[HarmonyPatch(typeof(TimeOfDay))]
public class VotePatch
{
[HarmonyPatch(typeof(HUDManager))]
public static class VoteHudPatch
{
private static int GetRequiredVotesForDisplay()
{
StartOfRound instance = StartOfRound.Instance;
int val = instance.connectedPlayersAmount + 1 - instance.livingPlayers;
int minimumVotes = ConfigSettings.MinimumVotes;
if (minimumVotes <= 1)
{
return Math.Max(1, val);
}
return Math.Max(minimumVotes, val);
}
[HarmonyPrefix]
[HarmonyPatch("SetShipLeaveEarlyVotesText")]
private static bool ForceMinDenominatorInSetter(HUDManager __instance, int votes)
{
((TMP_Text)__instance.holdButtonToEndGameEarlyVotesText).text = $"({votes}/{GetRequiredVotesForDisplay()} Votes)";
return false;
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void ForceMinDenominatorInUpdate(HUDManager __instance)
{
TextMeshProUGUI holdButtonToEndGameEarlyVotesText = __instance.holdButtonToEndGameEarlyVotesText;
if ((Object)(object)holdButtonToEndGameEarlyVotesText != (Object)null && !string.IsNullOrEmpty(((TMP_Text)holdButtonToEndGameEarlyVotesText).text))
{
int num = (((Object)(object)TimeOfDay.Instance != (Object)null) ? TimeOfDay.Instance.votesForShipToLeaveEarly : 0);
((TMP_Text)holdButtonToEndGameEarlyVotesText).text = $"({num}/{GetRequiredVotesForDisplay()} Votes)";
}
}
}
[HarmonyPatch("SetShipLeaveEarlyServerRpc")]
[HarmonyPrefix]
public static bool OnServerVote(TimeOfDay __instance)
{
if (ConfigSettings.MinimumVotes <= 1 || !((NetworkBehaviour)__instance).IsServer)
{
return true;
}
if (__instance.votesForShipToLeaveEarly + 1 >= ConfigSettings.MinimumVotes)
{
return true;
}
__instance.votesForShipToLeaveEarly++;
__instance.AddVoteForShipToLeaveEarlyClientRpc();
return false;
}
}
}