Decompiled source of AutoBrazier v0.2.0

AutoBrazier.dll

Decompiled a month ago
using System;
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 System.Security;
using System.Security.Permissions;
using AutoBrazier.Server;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using Bloody.Core.API.v1;
using Bloody.Core.GameData.v1;
using Bloody.Core.Models.v1;
using Bloody.Core.Models.v1.Base;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using ProjectM;
using ProjectM.Network;
using ProjectM.Scripting;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("AutoBrazier")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Automatically turns braziers on/off with day/night cycle")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+8.Branch.master.Sha.3adcf7bbc8c33d213ae5af93f271fac17ea4db9e")]
[assembly: AssemblyProduct("AutoBrazier")]
[assembly: AssemblyTitle("AutoBrazier")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
namespace AutoBrazier
{
	internal static class Core
	{
		public const int MAX_REPLY_LENGTH = 509;

		private static bool _hasInitialized = false;

		public static World Server { get; } = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");


		public static EntityManager EntityManager { get; } = Server.EntityManager;


		public static GameDataSystem GameDataSystem { get; } = Server.GetExistingSystemManaged<GameDataSystem>();


		public static PrefabCollectionSystem PrefabCollectionSystem { get; internal set; }

		public static ServerScriptMapper ServerScriptMapper { get; internal set; }

		public static double ServerTime => ServerGameManager.ServerTime;

		public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();

		public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }

		public static ManualLogSource Log { get; } = Plugin._logger;


		public static bool HasInitialized => _hasInitialized;

		public static void LogException(Exception e, [CallerMemberName] string caller = null)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 5, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failure in ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(caller);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nMessage: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.Message);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Inner:");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.Message);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n\nStack: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.StackTrace);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nInner Stack: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.StackTrace);
			}
			log.LogError(val);
		}

		internal static void InitializeAfterLoaded()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			if (!_hasInitialized)
			{
				PrefabCollectionSystem = Server.GetExistingSystemManaged<PrefabCollectionSystem>();
				ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
				ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
				EventsHandlerSystem.OnUserConnected += new OnUserConnectedEventHandler(AutoToggle.PlayerConnected);
				EventsHandlerSystem.OnUserDisconnected += new OnUserDisconnectedEventHandler(AutoToggle.PlayerDisconnected);
				_hasInitialized = true;
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("InitializeAfterLoaded");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" completed");
				}
				log.LogInfo(val);
			}
		}

		private static World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name)
				{
					return current;
				}
			}
			return null;
		}
	}
	[BepInPlugin("AutoBrazier", "AutoBrazier", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[Reloadable]
	public class Plugin : BasePlugin
	{
		public enum LogSystem
		{
			Core
		}

		public static Harmony _harmony;

		public static ConfigEntry<bool> AutoToggleEnabled;

		public static ManualLogSource _logger;

		private void InitConfig()
		{
			AutoToggleEnabled = ((BasePlugin)this).Config.Bind<bool>("Server", "autoToggleEnabled", true, "Turn braziers on when day starts, and off during the night starts, for online players/clans only.");
		}

		public override void Load()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			_logger = ((BasePlugin)this).Log;
			Log("Plugin AutoBrazier version 0.2.0 is Loading!", LogSystem.Core, (LogLevel)16);
			InitConfig();
			if (VWorld.IsServer)
			{
				Patch.Load();
				_harmony = new Harmony("AutoBrazier");
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
				Log("Plugin AutoBrazier version 0.2.0 is loaded!", LogSystem.Core, (LogLevel)16);
			}
			else
			{
				Log("This is a server mod, not client mod.", LogSystem.Core, (LogLevel)4);
			}
		}

		public override bool Unload()
		{
			((BasePlugin)this).Config.Clear();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}

		public void OnGameInitialized()
		{
			if (!HasLoaded())
			{
				Log("Attempt to initialize before everything has loaded.", LogSystem.Core, (LogLevel)16);
			}
			else
			{
				Core.InitializeAfterLoaded();
			}
		}

		private static bool HasLoaded()
		{
			PrefabCollectionSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			if (existingSystemManaged == null)
			{
				return false;
			}
			return existingSystemManaged.SpawnableNameToPrefabGuidDictionary.Count > 0;
		}

		public static void Log(string message, LogSystem system = LogSystem.Core, LogLevel logLevel = 16, bool forceLog = false)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			_logger.Log(logLevel, (object)ToLogMessage(system, message));
		}

		private static string ToLogMessage(LogSystem logSystem, string message)
		{
			return $"{DateTime.Now:u}: [{Enum.GetName(logSystem)}] {message}";
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "AutoBrazier";

		public const string PLUGIN_NAME = "AutoBrazier";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}
namespace AutoBrazier.Utility
{
	public static class ECSExtensions
	{
		public unsafe static void Write<T>(this Entity entity, T componentData) where T : struct
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			byte[] array = StructureToByteArray(componentData);
			int num = Marshal.SizeOf<T>();
			fixed (byte* ptr = array)
			{
				EntityManager entityManager = EntityQueries.EntityManager;
				((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num);
			}
		}

		public static byte[] StructureToByteArray<T>(T structure) where T : struct
		{
			int num = Marshal.SizeOf(structure);
			byte[] array = new byte[num];
			IntPtr intPtr = Marshal.AllocHGlobal(num);
			Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
			Marshal.Copy(intPtr, array, 0, num);
			Marshal.FreeHGlobal(intPtr);
			return array;
		}

		public unsafe static T Read<T>(this Entity entity) where T : struct
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityQueries.EntityManager;
			return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex)));
		}

		public static bool Has<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityQueries.EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public static string LookupName(this PrefabGUID prefabGuid)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			PrefabCollectionSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			object obj;
			if (!existingSystemManaged.PrefabGuidToNameDictionary.ContainsKey(prefabGuid))
			{
				obj = "GUID Not Found";
			}
			else
			{
				string text = existingSystemManaged.PrefabGuidToNameDictionary[prefabGuid];
				PrefabGUID val = prefabGuid;
				obj = text + " " + ((object)(PrefabGUID)(ref val)).ToString();
			}
			return obj.ToString();
		}

		public static void Add<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityQueries.EntityManager;
			((EntityManager)(ref entityManager)).AddComponent(entity, val);
		}

		public static void Remove<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityQueries.EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}
	}
}
namespace AutoBrazier.Server
{
	internal class AutoToggle
	{
		private static TimeOfDay currentTimeOfDay;

		public static void OnTimeOfDayChanged(TimeOfDay timeOfDay)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			currentTimeOfDay = timeOfDay;
			if ((int)timeOfDay != 1)
			{
				if ((int)timeOfDay != 2)
				{
					if ((int)timeOfDay != int.MaxValue)
					{
						throw new ArgumentOutOfRangeException("timeOfDay", timeOfDay, null);
					}
				}
				else
				{
					TurnOffAllBonfires();
				}
			}
			else
			{
				TurnOnBonfiresForOnlinePlayersOnly();
			}
		}

		private static void TurnOffAllBonfires()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			ManualToggle.SetBurning(EntityQueries.GetBonfireEntities(), isBurning: false);
		}

		private static void TurnOnBonfiresForOnlinePlayersOnly()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if ((int)currentTimeOfDay == 2)
			{
				return;
			}
			NativeArray<Entity> userEntities = EntityQueries.GetUserEntities();
			List<Team> list = new List<Team>();
			Enumerator<Entity> enumerator = userEntities.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				EntityManager entityManager = VWorld.Server.EntityManager;
				if (((EntityManager)(ref entityManager)).GetComponentData<User>(current).IsConnected)
				{
					entityManager = VWorld.Server.EntityManager;
					Team componentData = ((EntityManager)(ref entityManager)).GetComponentData<Team>(current);
					list.Add(componentData);
				}
			}
			List<Entity> bonfires = GetBonfires(list, isOnlineCheck: true);
			foreach (Entity bonfire in GetBonfires(list, isOnlineCheck: false))
			{
				ManualToggle.SetBurning(bonfire, isBurning: false);
			}
			foreach (Entity item in bonfires)
			{
				ManualToggle.SetBurning(item, isBurning: true);
			}
		}

		public static void PlayerConnected(ServerBootstrapSystem bootstrapSystem, NetConnectionId player)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if ((int)currentTimeOfDay != 1)
			{
				return;
			}
			int num = bootstrapSystem._NetEndPointToApprovedUserIndex[player];
			Entity userEntity = ((Il2CppArrayBase<ServerClient>)(object)bootstrapSystem._ApprovedUsersLookup)[num].UserEntity;
			Enumerator<Entity> enumerator = EntityQueries.GetBonfireEntities().GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				ServerGameManager serverGameManager = Core.ServerGameManager;
				if (((ServerGameManager)(ref serverGameManager)).IsAllies(current, userEntity))
				{
					ManualToggle.SetBurning(current, isBurning: true);
				}
			}
		}

		public static void PlayerDisconnected(ServerBootstrapSystem bootstrapSystem, NetConnectionId player, ConnectionStatusChangeReason reason, string extraData)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if ((int)currentTimeOfDay == 2)
			{
				return;
			}
			int num = bootstrapSystem._NetEndPointToApprovedUserIndex[player];
			Entity userEntity = ((Il2CppArrayBase<ServerClient>)(object)bootstrapSystem._ApprovedUsersLookup)[num].UserEntity;
			ServerGameManager serverGameManager;
			foreach (UserModel item in GameData.Users.Online.ToList())
			{
				serverGameManager = Core.ServerGameManager;
				if (((ServerGameManager)(ref serverGameManager)).IsAllies(((EntityModel)item).Entity, userEntity))
				{
					return;
				}
			}
			Enumerator<Entity> enumerator2 = EntityQueries.GetBonfireEntities().GetEnumerator();
			while (enumerator2.MoveNext())
			{
				Entity current2 = enumerator2.Current;
				serverGameManager = Core.ServerGameManager;
				if (((ServerGameManager)(ref serverGameManager)).IsAllies(current2, userEntity))
				{
					ManualToggle.SetBurning(current2, isBurning: false);
				}
			}
		}

		private static List<Entity> GetBonfires(List<Team> onlineTeams, bool isOnlineCheck)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> bonfireEntities = EntityQueries.GetBonfireEntities();
			List<Entity> list = new List<Entity>();
			List<Entity> list2 = new List<Entity>();
			Enumerator<Entity> enumerator = bonfireEntities.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				EntityManager entityManager = Core.EntityManager;
				Team bonfireTeam = ((EntityManager)(ref entityManager)).GetComponentData<Team>(current);
				if (onlineTeams.Any(delegate(Team onlineTeam)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					//IL_0005: Unknown result type (might be due to invalid IL or missing references)
					//IL_0009: Unknown result type (might be due to invalid IL or missing references)
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					ServerGameManager serverGameManager = Core.ServerGameManager;
					return ((ServerGameManager)(ref serverGameManager)).IsAllies(bonfireTeam, onlineTeam);
				}))
				{
					list.Add(current);
				}
				else
				{
					list2.Add(current);
				}
			}
			if (isOnlineCheck)
			{
				return list;
			}
			return list2;
		}
	}
	internal class DayNightCycleTracker
	{
		public delegate void Event(TimeOfDay timeOfDay);

		private TimeOfDay _previousTimeOfDay;

		public event Event OnTimeOfDayChanged;

		public void Update(DayNightCycle dayNightCycle)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (((DayNightCycle)(ref dayNightCycle)).TimeOfDay != _previousTimeOfDay)
			{
				_previousTimeOfDay = ((DayNightCycle)(ref dayNightCycle)).TimeOfDay;
				this.OnTimeOfDayChanged?.Invoke(((DayNightCycle)(ref dayNightCycle)).TimeOfDay);
			}
		}
	}
	internal class EntityQueries
	{
		private static readonly ComponentType[] BrazierComponents = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly(Il2CppType.Of<Bonfire>()) };

		public static World Server { get; } = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");


		public static EntityManager EntityManager { get; } = Server.EntityManager;


		private static World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name)
				{
					return current;
				}
			}
			return null;
		}

		public static NativeArray<Entity> GetUserEntities()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			return ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}

		public static NativeArray<Entity> GetBonfireEntities()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery(BrazierComponents);
			return ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}
	}
	internal class ManualToggle
	{
		private static readonly PrefabGUID BoneGuid = new PrefabGUID(1821405450);

		private static void Toggle(Entity brazier, out bool isBurning)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			BurnContainer componentData = ((EntityManager)(ref entityManager)).GetComponentData<BurnContainer>(brazier);
			componentData.Enabled = !componentData.Enabled;
			entityManager = VWorld.Server.EntityManager;
			((EntityManager)(ref entityManager)).SetComponentData<BurnContainer>(brazier, componentData);
			isBurning = componentData.Enabled;
		}

		public static void SetBurning(Entity brazier, bool isBurning)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			BurnContainer componentData = ((EntityManager)(ref entityManager)).GetComponentData<BurnContainer>(brazier);
			componentData.Enabled = isBurning;
			entityManager = VWorld.Server.EntityManager;
			((EntityManager)(ref entityManager)).SetComponentData<BurnContainer>(brazier, componentData);
		}

		public static void SetBurning(NativeArray<Entity> braziers, bool isBurning)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<Entity> enumerator = braziers.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				EntityManager entityManager = VWorld.Server.EntityManager;
				BurnContainer componentData = ((EntityManager)(ref entityManager)).GetComponentData<BurnContainer>(current);
				componentData.Enabled = isBurning;
				entityManager = VWorld.Server.EntityManager;
				((EntityManager)(ref entityManager)).SetComponentData<BurnContainer>(current, componentData);
			}
		}

		private static Vector3 ToVector3(LocalToWorld localToWorld)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(((LocalToWorld)(ref localToWorld)).Position.x, ((LocalToWorld)(ref localToWorld)).Position.y, ((LocalToWorld)(ref localToWorld)).Position.z);
		}

		public static void AddBonesIfEmpty(FromCharacter fromCharacter, Entity brazier)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			Entity val = default(Entity);
			InventoryUtilities.TryGetInventoryEntity(VWorld.Server.EntityManager, fromCharacter.Character, ref val, 0);
			Entity val2 = default(Entity);
			InventoryUtilities.TryGetInventoryEntity(VWorld.Server.EntityManager, brazier, ref val2, 0);
			GameDataSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<GameDataSystem>();
			int itemAmount = InventoryUtilities.GetItemAmount(VWorld.Server.EntityManager, val, BoneGuid, default(Nullable_Unboxed<int>));
			int itemAmount2 = InventoryUtilities.GetItemAmount(VWorld.Server.EntityManager, val2, BoneGuid, default(Nullable_Unboxed<int>));
			if (itemAmount > 0 && itemAmount2 == 0)
			{
				int num = default(int);
				InventoryUtilities.TryGetItemSlot(VWorld.Server.EntityManager, val, BoneGuid, ref num);
				InventoryUtilitiesServer.SplitItemStacks(VWorld.Server.EntityManager, existingSystemManaged.ItemHashLookupMap, val, num);
				InventoryUtilitiesServer.TryMoveItem(VWorld.Server.EntityManager, existingSystemManaged.ItemHashLookupMap, val, num, val2, -1, true, default(Nullable_Unboxed<int>));
			}
		}
	}
	[HarmonyPatch(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate")]
	internal class OnLoadPatches
	{
		[HarmonyPostfix]
		public static void OneShot_AfterLoad_InitializationPatch()
		{
			Core.InitializeAfterLoaded();
			Plugin._harmony.Unpatch((MethodBase)typeof(SpawnTeamSystem_OnPersistenceLoad).GetMethod("OnUpdate"), typeof(OnLoadPatches).GetMethod("OneShot_AfterLoad_InitializationPatch"));
		}
	}
	[HarmonyPatch]
	internal class Patch
	{
		private static DayNightCycleTracker _dayNightCycleTracker;

		private const string InitialErrorMessage = "System.InvalidOperationException: GetSingleton<ProjectM.DayNightCycle>() requires that exactly one ProjectM.DayNightCycle exist that match this query, but there are 0.";

		private static byte _currentDay;

		private static bool _isDnInitialized;

		public static void Load()
		{
			_dayNightCycleTracker = new DayNightCycleTracker();
			_dayNightCycleTracker.OnTimeOfDayChanged += AutoToggle.OnTimeOfDayChanged;
		}

		[HarmonyPatch(typeof(BonfireSystemUpdateCloud), "OnUpdate")]
		[HarmonyPostfix]
		private static void OnUpdate(BonfireSystemUpdateCloud __instance)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.AutoToggleEnabled.Value || !Core.HasInitialized)
			{
				Plugin.Log($"Returning because either Plugin.AutoToggleEnabled is False ({Plugin.AutoToggleEnabled.Value}) or Core.HasInitialized is False {Core.HasInitialized})", Plugin.LogSystem.Core, (LogLevel)16);
				return;
			}
			if (Core.ServerGameManager.HasDayNightCycle)
			{
				try
				{
					DayNightCycle dayNightCycle = Core.ServerGameManager.DayNightCycle;
					if (!_isDnInitialized)
					{
						_currentDay = dayNightCycle.GameDateTimeNow.Day;
						_isDnInitialized = true;
						_dayNightCycleTracker.Update(dayNightCycle);
					}
					else
					{
						_currentDay = dayNightCycle.GameDateTimeNow.Day;
						_dayNightCycleTracker.Update(dayNightCycle);
					}
					return;
				}
				catch (Exception ex)
				{
					if (ex.Message.StartsWith("System.InvalidOperationException: GetSingleton<ProjectM.DayNightCycle>() requires that exactly one ProjectM.DayNightCycle exist that match this query, but there are 0."))
					{
						Plugin.Log("DNC singleton not yet ready. This error should only appear on the initial creation/startup of the server.", Plugin.LogSystem.Core, (LogLevel)16);
					}
					else
					{
						Plugin.Log("DayNightCycle: " + ex.Message, Plugin.LogSystem.Core, (LogLevel)16);
					}
					return;
				}
			}
			Plugin.Log("Core.ServerGameManager.HasDayNightCycle = False", Plugin.LogSystem.Core, (LogLevel)4);
		}
	}
}