Decompiled source of ShipLeaveTimeConfig v1.0.1

ShipLeaveTimeConfig/ShipLeaveTimeConfig.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Unity.Netcode;
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("ShipLeaveTimeConfig")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShipLeaveTimeConfig")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7006c543-67eb-4664-8003-feba617691b5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ShipLeaveTimeConfig;

[BepInPlugin("yazirushi.ShipLeaveTimeConfig", "ShipLeaveTimeConfig", "1.0.1")]
public class ShipLeaveTimeConfig : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("yazirushi.ShipLeaveTimeConfig");

	internal static ManualLogSource mls;

	public static ConfigEntry<int> ShipLeaveHours;

	public static ConfigEntry<int> ShipLeaveMinutes;

	private void Awake()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		ShipLeaveHours = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "ShipLeaveHours", 23, new ConfigDescription("Departure Time (Hours)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 23), Array.Empty<object>()));
		ShipLeaveMinutes = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "ShipLeaveMinutes", 0, new ConfigDescription("Departure Time (Minutes)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 59), Array.Empty<object>()));
		mls = ((BaseUnityPlugin)this).Logger;
		mls.LogInfo((object)"Starting ShipLeaveTimeConfig...");
		harmony.PatchAll();
	}
}
[HarmonyPatch(typeof(TimeOfDay), "Update")]
public class TimePatch
{
	private static void Postfix(TimeOfDay __instance)
	{
		if (!((Object)(object)NetworkManager.Singleton == (Object)null) && NetworkManager.Singleton.IsHost)
		{
			int num = (int)((__instance.normalizedTimeOfDay + 0.1f) * (60f * (float)__instance.numberOfHours)) + 360;
			int num2 = (int)Mathf.Floor((float)(num / 60));
			int num3 = num % 60;
			if (!__instance.shipLeavingAlertCalled && num2 >= ShipLeaveTimeConfig.ShipLeaveHours.Value && num3 >= ShipLeaveTimeConfig.ShipLeaveMinutes.Value)
			{
				__instance.votesForShipToLeaveEarly = StartOfRound.Instance.connectedPlayersAmount;
				__instance.SetShipLeaveEarlyServerRpc();
			}
		}
	}
}
[HarmonyPatch(typeof(TimeOfDay), "SetShipLeaveEarlyClientRpc")]
public class TextPatch
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		list.RemoveAt(87);
		list.Insert(87, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
		list.Insert(88, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(TextPatch), "VoteCheck", (Type[])null, (Type[])null)));
		return list;
	}

	private static string VoteCheck(TimeOfDay __instance)
	{
		int votesForShipToLeaveEarly = __instance.votesForShipToLeaveEarly;
		int num = StartOfRound.Instance.connectedPlayersAmount + 1;
		if (votesForShipToLeaveEarly >= num)
		{
			return ". A time specified in “ShipLeaveTimeConfig” is approaching, and the autopilot ship will leave early.";
		}
		return ". A vote has been cast, and the autopilot ship will leave early.";
	}
}