using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AutoBrazier.Hooks;
using AutoBrazier.Services;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
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;
using VAMP;
using VAMP.Data;
using VAMP.Services;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AutoBrazier")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Automatically turns braziers on/off with day/night cycle")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+Branch.master.Sha.2b56fd86d2e85ed33db0059fbc958e780a1a6336.2b56fd86d2e85ed33db0059fbc958e780a1a6336")]
[assembly: AssemblyProduct("AutoBrazier")]
[assembly: AssemblyTitle("AutoBrazier")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 AutoBrazier
{
[BepInPlugin("AutoBrazier", "AutoBrazier", "1.1.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
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_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
_logger = ((BasePlugin)this).Log;
InitConfig();
_harmony = new Harmony("AutoBrazier");
_harmony.PatchAll(Assembly.GetExecutingAssembly());
Plugin.OnCoreLoaded = (Action)Delegate.Combine(Plugin.OnCoreLoaded, new Action(Loaded));
Log("Plugin AutoBrazier version 1.1.2 is loaded!", LogSystem.Core, (LogLevel)16);
}
public void Loaded()
{
BonfirePatch.Load();
}
public override bool Unload()
{
((BasePlugin)this).Config.Clear();
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
return true;
}
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 = "1.1.2";
}
}
namespace AutoBrazier.Services
{
internal class AutoToggle
{
private static TimeOfDay currentTimeOfDay;
private static readonly ComponentType[] BrazierComponents = (ComponentType[])(object)new ComponentType[2]
{
ComponentType.ReadOnly(Il2CppType.Of<Bonfire>()),
ComponentType.ReadOnly(Il2CppType.Of<BurnContainer>())
};
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(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_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: 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_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_0043: 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_004c: 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_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
if ((int)currentTimeOfDay == 2)
{
return;
}
IEnumerable<Entity> cachedUsersOnline = PlayerService.GetCachedUsersOnline();
List<Team> list = new List<Team>();
foreach (Entity item in cachedUsersOnline)
{
EntityManager entityManager = Core.Server.EntityManager;
if (((EntityManager)(ref entityManager)).GetComponentData<User>(item).IsConnected)
{
entityManager = Core.Server.EntityManager;
Team componentData = ((EntityManager)(ref entityManager)).GetComponentData<Team>(item);
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 item2 in bonfires)
{
ManualToggle.SetBurning(item2, 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 = 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_003c: 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_0043: 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_004c: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: 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_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: 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)
if ((int)currentTimeOfDay == 2)
{
return;
}
int num = bootstrapSystem._NetEndPointToApprovedUserIndex[player];
Entity userEntity = ((Il2CppArrayBase<ServerClient>)(object)bootstrapSystem._ApprovedUsersLookup)[num].UserEntity;
ServerGameManager serverGameManager;
foreach (Entity item in PlayerService.GetUsersOnline().ToList())
{
serverGameManager = Core.ServerGameManager;
if (((ServerGameManager)(ref serverGameManager)).IsAllies(item, userEntity))
{
return;
}
}
Enumerator<Entity> enumerator2 = 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 = 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;
}
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 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 ManualToggle
{
private static readonly PrefabGUID BoneGuid = Prefabs.Item_Ingredient_Bone;
private static void Toggle(Entity brazier, out bool isBurning)
{
//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_0008: 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)
//IL_0011: 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_0024: 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_002f: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
BurnContainer componentData = ((EntityManager)(ref entityManager)).GetComponentData<BurnContainer>(brazier);
componentData.Enabled = !componentData.Enabled;
entityManager = Core.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_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_0024: 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)
EntityManager entityManager = Core.Server.EntityManager;
BurnContainer componentData = ((EntityManager)(ref entityManager)).GetComponentData<BurnContainer>(brazier);
componentData.Enabled = isBurning;
entityManager = Core.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_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_0036: 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)
Enumerator<Entity> enumerator = braziers.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
EntityManager entityManager = Core.Server.EntityManager;
BurnContainer componentData = ((EntityManager)(ref entityManager)).GetComponentData<BurnContainer>(current);
componentData.Enabled = isBurning;
entityManager = Core.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_00cf: Unknown result type (might be due to invalid IL or missing references)
Entity val = default(Entity);
InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.Server.EntityManager, fromCharacter.Character, ref val, 0);
Entity val2 = default(Entity);
InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.Server.EntityManager, brazier, ref val2, 0);
GameDataSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<GameDataSystem>();
int itemAmount = InventoryUtilities.GetItemAmount<EntityManager>(Core.Server.EntityManager, val, BoneGuid, default(Nullable_Unboxed<int>));
int itemAmount2 = InventoryUtilities.GetItemAmount<EntityManager>(Core.Server.EntityManager, val2, BoneGuid, default(Nullable_Unboxed<int>));
if (itemAmount > 0 && itemAmount2 == 0)
{
int num = default(int);
InventoryUtilities.TryGetItemSlot<EntityManager>(Core.Server.EntityManager, val, BoneGuid, ref num);
InventoryUtilitiesServer.SplitItemStacks(Core.Server.EntityManager, existingSystemManaged.ItemHashLookupMap, val, num);
InventoryUtilitiesServer.TryMoveItem(Core.Server.EntityManager, existingSystemManaged.ItemHashLookupMap, val, num, val2, -1, true, default(Nullable_Unboxed<int>), -1);
}
}
}
}
namespace AutoBrazier.Hooks
{
internal class BonfirePatch
{
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;
if (Plugin.AutoToggleEnabled.Value)
{
Core.StartCoroutine(Check());
}
}
private static IEnumerator Check()
{
while (true)
{
yield return (object)new WaitForSeconds(10f);
if (!Core.hasInitialized)
{
yield return null;
}
if (_dayNightCycleTracker == null)
{
yield return null;
}
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);
}
}
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);
}
}
}
else
{
Plugin.Log("Core.ServerGameManager.HasDayNightCycle = False", Plugin.LogSystem.Core, (LogLevel)4);
}
}
}
}
[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserConnected")]
public static class OnUserConnectedPatch
{
public static void Postfix(ServerBootstrapSystem __instance, NetConnectionId netConnectionId)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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)
if (Core.PlayerService == null)
{
return;
}
try
{
EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
Entity userEntity = ((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num].UserEntity;
((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
AutoToggle.PlayerConnected(__instance, netConnectionId);
}
catch (Exception ex)
{
Plugin.Log(ex.Message, Plugin.LogSystem.Core, (LogLevel)16);
}
}
}
[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserDisconnected")]
public static class OnUserDisconnectedPatch
{
private static void Prefix(ServerBootstrapSystem __instance, NetConnectionId netConnectionId, ConnectionStatusChangeReason connectionStatusReason, string extraData)
{
//IL_0024: 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_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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
if (Core.PlayerService == null)
{
return;
}
try
{
int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
ServerClient val = ((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num];
EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(val.UserEntity);
_ = ((FixedString64Bytes)(ref componentData.CharacterName)).IsEmpty;
AutoToggle.PlayerDisconnected(__instance, netConnectionId, connectionStatusReason, extraData);
}
catch
{
}
}
}
}