Decompiled source of AutoLightOn v1.0.1

BepInEx/plugins/OldMarket.AutoLightOn.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using OldMarket.AutoLights;
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("OldMarket.AutoLightOn")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OldMarket.AutoLightOn")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("aa406097-aeca-4de9-82fd-4ef29bc914d6")]
[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")]
[HarmonyPatch(typeof(GameManager))]
internal static class GameManager_AutoLights_Patch
{
	[HarmonyPostfix]
	[HarmonyPatch("LoadWorldServer")]
	private static void Post_LoadWorldServer(GameManager __instance)
	{
		if (!((NetworkBehaviour)__instance).IsServer || !__instance.IsWorldLoaded())
		{
			return;
		}
		try
		{
			BlockLightMasterSwitch val = Object.FindObjectOfType<BlockLightMasterSwitch>();
			if ((Object)(object)val != (Object)null)
			{
				val.ToggleLightsServerRpc();
				return;
			}
			BlockLight[] array = Object.FindObjectsOfType<BlockLight>();
			if (array == null || array.Length == 0)
			{
				return;
			}
			BlockLight[] array2 = array;
			foreach (BlockLight val2 in array2)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					val2.ToggleLightServerRpc();
				}
			}
		}
		catch (Exception arg)
		{
			ManualLogSource log = AutoLightsPlugin.Log;
			if (log != null)
			{
				log.LogError((object)$"AutoLights: failed to toggle lights after world load: {arg}");
			}
		}
	}
}
namespace OldMarket.AutoLights;

[BepInPlugin("OldMarket.AutoLightOn", "OldMarket Auto LightOn", "1.0.1")]
public class AutoLightsPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "OldMarket.AutoLightOn";

	public const string PluginName = "OldMarket Auto LightOn";

	public const string PluginVersion = "1.0.1";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		try
		{
			Harmony val = new Harmony("OldMarket.AutoLightOn");
			val.PatchAll();
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"AutoLights: failed to apply Harmony patches: {arg}");
		}
	}
}