Decompiled source of CloseMarketPauseTime v1.0.0

BepInEx/plugins/CloseMarketPauseTime.dll

Decompiled 3 weeks ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AzureSky;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CloseMarketPauseTime")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CloseMarketPauseTime")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("06331326-81F5-490C-9740-5A3738692672")]
[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")]
[BepInPlugin("com.lan.CloseMarketPauseTime", "关店暂停时间", "1.0.0")]
public class CloseMarketPauseTime : BaseUnityPlugin
{
	private static readonly FieldInfo _m_timeProgressionStep = AccessTools.Field(typeof(AzureTimeController), "m_timeProgressionStep");

	private static bool isPause = false;

	private static readonly FieldInfo _isLightOn = AccessTools.Field(typeof(BlockLight), "isLightOn");

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		Harmony val = new Harmony("com.lan.CloseMarketPauseTime");
		val.PatchAll(typeof(CloseMarketPauseTime));
		Debug.LogWarning((object)"关店暂停时间 --作者:她说缝上都不给我");
		GameObject val2 = new GameObject("MarketStateMonitor");
		((Object)val2).hideFlags = (HideFlags)61;
		val2.AddComponent<MarketStateMonitor>();
	}

	public static void OnMarketStateChanged(bool isOpen)
	{
		if (isOpen && isPause)
		{
			GameManager.Instance.azureTimeController.PlayTimeAgain();
			isPause = false;
			GameManager.Instance.ShowNotificationClientRpc("<b><color=lightblue><size=+5>成功恢复时间(Resume Time)</size></color></b>", true, 5f, false);
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GameManager))]
	[HarmonyPatch("ServerUpdateTimeline")]
	private static bool Prefix(GameManager __instance)
	{
		if (!((NetworkBehaviour)__instance).NetworkManager.IsServer)
		{
			return true;
		}
		if ((double)__instance.GetTimelineValue() <= 6.1)
		{
			isPause = false;
			return true;
		}
		if (!__instance.IsMarketOpen() && (double)__instance.GetTimelineValue() > 6.1 && !isPause)
		{
			__instance.azureTimeController.PauseTime();
			isPause = true;
			GameManager.Instance.ShowNotificationClientRpc("<b><color=lightblue><size=+5>成功暂停时间(Pause Time)</size></color></b>", true, 5f, false);
			return false;
		}
		return true;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameManager))]
	[HarmonyPatch("OnTimelineChanged")]
	private static void Postfix(GameManager __instance, float previous, float current)
	{
		if ((double)current > 6.03 || (double)current < 6.01)
		{
			return;
		}
		List<BlockLight> list = Object.FindObjectsOfType<BlockLight>().ToList();
		foreach (BlockLight item in list)
		{
			NetworkVariable<bool> val = (NetworkVariable<bool>)_isLightOn.GetValue(item);
			if (!val.Value)
			{
				val.Value = true;
			}
		}
	}
}
public class MarketStateMonitor : MonoBehaviour
{
	private bool lastMarketState = false;

	private void Update()
	{
		if (GameManager.Instance != null)
		{
			bool flag = GameManager.Instance.IsMarketOpen();
			if (flag != lastMarketState)
			{
				lastMarketState = flag;
				CloseMarketPauseTime.OnMarketStateChanged(flag);
			}
		}
	}
}