using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Lib;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[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("NoEarlyLeave")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoEarlyLeave")]
[assembly: AssemblyTitle("NoEarlyLeave")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
public class NoEarlyLeaveConfig : SyncedConfig2<NoEarlyLeaveConfig>
{
[field: SyncedEntryField]
public SyncedEntry<string> BlockMode { get; private set; }
[field: SyncedEntryField]
public SyncedEntry<int> HourCanLeave { get; private set; }
[field: SyncedEntryField]
public SyncedEntry<int> PercentageAvailableQuota { get; private set; }
[field: SyncedEntryField]
public SyncedEntry<bool> LastSurvivorEnableEscape { get; private set; }
[field: SyncedEntryField]
public SyncedEntry<bool> DebugLog { get; private set; }
[field: SyncedEntryField]
public SyncedEntry<int> DefaultBeginningHour { get; private set; }
public NoEarlyLeaveConfig(ConfigFile cfg)
: base("com.ZodiacGSK.NoEarlyLeave")
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_005f: Expected O, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Expected O, but got Unknown
//IL_009a: Expected O, but got Unknown
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Expected O, but got Unknown
//IL_00d5: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Expected O, but got Unknown
//IL_0108: Expected O, but got Unknown
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Expected O, but got Unknown
//IL_013b: Expected O, but got Unknown
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Expected O, but got Unknown
//IL_0170: Expected O, but got Unknown
ConfigEntry<string> val = cfg.Bind<string>(new ConfigDefinition("General", "BlockMode"), "TIME_DEPENDANT", new ConfigDescription("The mode the blocking is set on, quota dependant will block the ship if the percentage of available money on the moon is not collected while time dependant will simply block until hour is met. Both enable both mecanics?", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[4] { "DISABLED", "QUOTA_DEPENDANT", "TIME_DEPENDANT", "BOTH" }), Array.Empty<object>()));
BlockMode = new SyncedEntry<string>(val);
ConfigEntry<int> val2 = cfg.Bind<int>(new ConfigDefinition("Quota", "PercentageAvailableQuota"), 50, new ConfigDescription("The percentage of total money on the map that need to be collected (on ship) to escape", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
PercentageAvailableQuota = new SyncedEntry<int>(val2);
ConfigEntry<int> val3 = cfg.Bind<int>(new ConfigDefinition("Time", "HourCanLeave"), 20, new ConfigDescription("The time after it's allowed to leave (24h format ex: 20 = 8pm)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 24), Array.Empty<object>()));
HourCanLeave = new SyncedEntry<int>(val3);
ConfigEntry<bool> val4 = cfg.Bind<bool>(new ConfigDefinition("General", "LastSurvivorEnableEscape"), true, new ConfigDescription("If only one player is alive, can he escape before anyways ?", (AcceptableValueBase)null, Array.Empty<object>()));
LastSurvivorEnableEscape = new SyncedEntry<bool>(val4);
ConfigEntry<bool> val5 = cfg.Bind<bool>(new ConfigDefinition("Debug", "DebugLogs"), false, new ConfigDescription("Enable the debug logs", (AcceptableValueBase)null, Array.Empty<object>()));
DebugLog = new SyncedEntry<bool>(val5);
ConfigEntry<int> val6 = cfg.Bind<int>(new ConfigDefinition("Debug", "DefaultBeginningHour"), 6, new ConfigDescription("The time of the moon when it start. It's HEAVELY recommended to NOT TOUCH IT. This do the math for the conversion of ingame time and actual hour, change it ONLY if you modified when a day start.", (AcceptableValueBase)null, Array.Empty<object>()));
DefaultBeginningHour = new SyncedEntry<int>(val6);
ConfigManager.Register<NoEarlyLeaveConfig>((SyncedConfig2<NoEarlyLeaveConfig>)(object)this);
}
}
[BepInPlugin("com.ZodiacGSK.NoEarlyLeave", "No Early Leave", "1.3.0")]
[BepInDependency("com.sigurd.csync", "5.0.1")]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource MyLogger;
internal static NoEarlyLeaveConfig Config;
private void Awake()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
MyLogger = ((BaseUnityPlugin)this).Logger;
Config = new NoEarlyLeaveConfig(((BaseUnityPlugin)this).Config);
new Harmony("com.ZodiacGSK.NoEarlyLeave").PatchAll();
MyLogger.LogInfo((object)"NoEarlyLeave loaded ! 1.3.0");
}
}
[HarmonyPatch(typeof(StartMatchLever), "PullLever")]
public static class PullLeverPatch
{
private static bool Prefix(StartMatchLever __instance)
{
float num = TimeOfDay.Instance.hour;
int num2 = Plugin.Config.HourCanLeave.Value % 12;
if (num2 == 0)
{
num2 = 12;
}
string arg = ((Plugin.Config.HourCanLeave.Value >= 12) ? "PM" : "AM");
int valueOfAllScrap = StartOfRound.Instance.GetValueOfAllScrap(true, false);
int valueOfAllScrap2 = StartOfRound.Instance.GetValueOfAllScrap(false, false);
int valueOfAllScrap3 = StartOfRound.Instance.GetValueOfAllScrap(true, true);
int valueOfAllScrap4 = StartOfRound.Instance.GetValueOfAllScrap(false, true);
bool num3 = !__instance.playersManager.inShipPhase && StartOfRound.Instance.currentLevel.planetHasTime;
bool flag = num < (float)(Plugin.Config.HourCanLeave.Value - Plugin.Config.DefaultBeginningHour.Value) && (Plugin.Config.BlockMode.Value == "TIME_DEPENDANT" || Plugin.Config.BlockMode.Value == "BOTH");
bool flag2 = StartOfRound.Instance.connectedPlayersAmount + 1 == 1 || !Plugin.Config.LastSurvivorEnableEscape.Value || StartOfRound.Instance.livingPlayers > 1;
bool flag3 = (float)valueOfAllScrap3 / (float)valueOfAllScrap4 * 100f < (float)Plugin.Config.PercentageAvailableQuota.Value && (Plugin.Config.BlockMode.Value == "QUOTA_DEPENDANT" || Plugin.Config.BlockMode.Value == "BOTH");
if (Plugin.Config.DebugLog.LocalValue)
{
Plugin.MyLogger.LogInfo((object)"Scrap values debug:");
Plugin.MyLogger.LogInfo((object)$" Collected scrap value (old+new): {valueOfAllScrap}");
Plugin.MyLogger.LogInfo((object)$" Total scrap value (old+new): {valueOfAllScrap2}");
Plugin.MyLogger.LogInfo((object)$" Collected scrap value (new only): {valueOfAllScrap3}");
Plugin.MyLogger.LogInfo((object)$" Total scrap value (new only): {valueOfAllScrap4}");
Plugin.MyLogger.LogInfo((object)$" TimeInGame: {num}, timeCanLeave: {Plugin.Config.HourCanLeave.Value}, timeleft: {(float)(Plugin.Config.HourCanLeave.Value - Plugin.Config.DefaultBeginningHour.Value) - num}");
}
if (num3 && flag2 && (flag3 || flag))
{
string text = "";
if ((Plugin.Config.BlockMode.Value == "QUOTA_DEPENDANT" || Plugin.Config.BlockMode.Value == "BOTH") && (float)valueOfAllScrap3 / (float)valueOfAllScrap4 * 100f < (float)Plugin.Config.PercentageAvailableQuota.Value)
{
float num4 = (float)valueOfAllScrap4 / 100f * (float)Plugin.Config.PercentageAvailableQuota.Value - (float)valueOfAllScrap3;
text = $"gathering {num4}$ more ";
}
string text2 = "";
if ((Plugin.Config.BlockMode.Value == "TIME_DEPENDANT" || Plugin.Config.BlockMode.Value == "BOTH") && num < (float)(Plugin.Config.HourCanLeave.Value - Plugin.Config.DefaultBeginningHour.Value))
{
text2 = $"{num2}{arg}";
}
string text3 = ((Plugin.Config.BlockMode.Value == "BOTH" && num < (float)(Plugin.Config.HourCanLeave.Value - Plugin.Config.DefaultBeginningHour.Value) && (float)valueOfAllScrap3 / (float)valueOfAllScrap4 * 100f < (float)Plugin.Config.PercentageAvailableQuota.Value) ? "and " : "");
HUDManager.Instance.DisplayTip("Ship Locked", "You are not allowed to leave before " + text + text3 + text2 + "!", false, false, "LC_Tip1");
MethodInfo method = typeof(StartMatchLever).GetMethod("PullLeverAnim", BindingFlags.Instance | BindingFlags.NonPublic);
object[] parameters = new object[1] { false };
method.Invoke(__instance, parameters);
method = typeof(StartMatchLever).GetMethod("CancelStartGame", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(__instance, null);
__instance.triggerScript.hoverTip = "[ Ship locked. ]";
__instance.triggerScript.interactable = true;
return false;
}
return true;
}
}