Decompiled source of AlwaysHalloween v5.0.0

BepInEx/plugins/AlwaysHalloween/AlwaysHalloween.dll

Decompiled 16 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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("REPOJP")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("5.0.0.0")]
[assembly: AssemblyInformationalVersion("5.0.0")]
[assembly: AssemblyProduct("AlwaysHalloween")]
[assembly: AssemblyTitle("AlwaysHalloween")]
[assembly: AssemblyVersion("5.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
	[CompilerGenerated]
	[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;
		}
	}
}
namespace REPOJP.AlwaysHalloween
{
	[BepInPlugin("REPOJP.AlwaysHalloween", "AlwaysHalloween", "5.0.0")]
	public sealed class AlwaysHalloweenPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "REPOJP.AlwaysHalloween";

		public const string PluginName = "AlwaysHalloween";

		public const string PluginVersion = "5.0.0";

		private Harmony? harmony;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			harmony = new Harmony("REPOJP.AlwaysHalloween");
			try
			{
				harmony.PatchAll(typeof(AlwaysHalloweenPlugin).Assembly);
				HalloweenActivation.EnsureLocal(GameManager.instance);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"AlwaysHalloween 5.0.0 loaded. Halloween is enabled in solo play and in rooms you host.");
			}
			catch (Exception arg)
			{
				harmony.UnpatchSelf();
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("Could not enable {0}; its patches have been removed. {1}", "AlwaysHalloween", arg));
			}
		}

		private void OnDestroy()
		{
			Harmony? obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	internal static class HalloweenActivation
	{
		internal static void EnsureLocal(GameManager? manager)
		{
			if (Object.op_Implicit((Object)(object)manager) && manager.gameMode != 1)
			{
				SetHalloween(manager);
			}
		}

		internal static void EnsureHostBeforeSync(bool loadingDone)
		{
			if (!loadingDone)
			{
				GameManager instance = GameManager.instance;
				if (Object.op_Implicit((Object)(object)instance) && instance.gameMode == 1 && PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
				{
					SetHalloween(instance);
				}
			}
		}

		private static void SetHalloween(GameManager manager)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)manager.currentGameEvent != 1)
			{
				manager.GameEventSet((GameEvents)1);
			}
		}
	}
	[HarmonyPatch(typeof(GameManager), "CheckForSeasonalEvent")]
	internal static class SeasonalEventPatch
	{
		[HarmonyPostfix]
		private static void Postfix(GameManager __instance)
		{
			HalloweenActivation.EnsureLocal(__instance);
		}
	}
	[HarmonyPatch(typeof(GameManager), "SetGameMode")]
	internal static class GameModePatch
	{
		[HarmonyPostfix]
		private static void Postfix(GameManager __instance)
		{
			HalloweenActivation.EnsureLocal(__instance);
		}
	}
	[HarmonyPatch(typeof(NetworkManager), "Update")]
	internal static class HostSeasonalSyncPatch
	{
		[HarmonyPrefix]
		private static void Prefix(bool ___LoadingDone)
		{
			HalloweenActivation.EnsureHostBeforeSync(___LoadingDone);
		}
	}
}