Decompiled source of RaidForge v1.0.0

RaidForge.dll

Decompiled 2 days ago
using System;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using Bloodstone.Hooks;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProjectM;
using Unity.Collections;
using Unity.Entities;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Darrean #Inility ")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Allows you to start raids and end raids with a command, and set the times of raid on any day not just weekend or weekdays.")]
[assembly: AssemblyFileVersion("0.1.10.0")]
[assembly: AssemblyInformationalVersion("0.1.10+1.Branch.main.Sha.c33d0879382e1a0da34861ec55914ba7e637a80e")]
[assembly: AssemblyProduct("RaidForge")]
[assembly: AssemblyTitle("RaidForge")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.10.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.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]
	[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 RaidForge
{
	public class RaidCommand
	{
		[Command("raidon", "Immediately turn raids ON (one-time).", null, null, null, true)]
		public void RaidOn(ChatCommandContext ctx)
		{
			VrisingRaidToggler.EnableRaids(RaidForgePlugin.Logger);
			ctx.Reply("[RaidForge] Raids turned ON now. Next schedule boundary may revert it if we're outside the window.");
		}

		[Command("raidoff", "Immediately turn raids OFF. If inside today's window, skip the rest of that window.", null, null, null, true)]
		public void RaidOff(ChatCommandContext ctx)
		{
			VrisingRaidToggler.DisableRaids(RaidForgePlugin.Logger);
			RaidtimeManager.SkipCurrentWindowIfAny();
			ctx.Reply("[RaidForge] Raids turned OFF. If we were in a window, that window is skipped for today.");
		}

		[Command("raidtime", "Shows the current server date/time and day-of-week.", null, null, null, true)]
		public void RaidTime(ChatCommandContext ctx)
		{
			DateTime now = DateTime.Now;
			ctx.Reply($"[RaidForge] Server time: {now:F} (DayOfWeek={now.DayOfWeek}).");
		}

		[Command("raidt", "Shows the next scheduled time raids will turn ON automatically.", null, null, null, false)]
		public void RaidNextOnTime(ChatCommandContext ctx)
		{
			DateTime? nextOnTime = RaidtimeManager.GetNextOnTime(DateTime.Now);
			if (!nextOnTime.HasValue)
			{
				ctx.Reply("[RaidForge] No further raid-on time found in the next 7 days.");
				return;
			}
			ctx.Reply($"[RaidForge] Next scheduled ON time: {nextOnTime.Value:F}");
		}
	}
	[BepInPlugin("RaidForge", "RaidForge Mod", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class RaidForgePlugin : BasePlugin
	{
		public static ManualLogSource Logger;

		private Harmony _harmony;

		public static RaidForgePlugin Instance { get; private set; }

		public override void Load()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			Instance = this;
			Logger = ((BasePlugin)this).Log;
			Logger.LogInfo((object)"[RaidForge] Plugin is loading...");
			Raidschedule.Initialize(((BasePlugin)this).Config);
			_ = Raidschedule.OverrideMode.Value;
			_ = Raidschedule.RaidCheckInterval.Value;
			((BasePlugin)this).Config.Save();
			CommandRegistry.RegisterAll();
			_harmony = new Harmony("com.myserver.RaidForge");
			_harmony.PatchAll();
			Chat.OnChatMessage += new ChatEventHandler(HandleReloadCommand);
			Logger.LogInfo((object)"[RaidForge] Plugin load finished. Using Vivox OnUpdate patch for scheduling.");
		}

		public override bool Unload()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Logger.LogInfo((object)"[RaidForge] Unloading plugin...");
			Chat.OnChatMessage -= new ChatEventHandler(HandleReloadCommand);
			CommandRegistry.UnregisterAssembly();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}

		private void HandleReloadCommand(VChatEvent ev)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (!(ev.Message == "!reload") || !ev.User.IsAdmin)
			{
				return;
			}
			Logger.LogInfo((object)"[RaidForge] Reload command received...");
			try
			{
				((BasePlugin)this).Config.Reload();
				((BasePlugin)this).Config.Save();
				Raidschedule.Initialize(((BasePlugin)this).Config);
				Raidschedule.LoadFromConfig();
				RaidtimeManager.ReloadFromConfig(immediate: true);
				VExtensions.SendSystemMessage(ev.User, "<color=#00FF00>RaidForge config reloaded successfully.</color>");
				Logger.LogInfo((object)"[RaidForge] Config reloaded via !reload command.");
			}
			catch (Exception ex)
			{
				VExtensions.SendSystemMessage(ev.User, "<color=#FF0000>Failed to reload config:</color> " + ex.Message);
				ManualLogSource logger = Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RaidForge] Error reloading config: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	public static class Raidschedule
	{
		public static ConfigEntry<string> OverrideMode;

		public static ConfigEntry<int> RaidCheckInterval;

		public static ConfigEntry<string> MondayStart;

		public static ConfigEntry<string> MondayEnd;

		public static ConfigEntry<string> TuesdayStart;

		public static ConfigEntry<string> TuesdayEnd;

		public static ConfigEntry<string> WednesdayStart;

		public static ConfigEntry<string> WednesdayEnd;

		public static ConfigEntry<string> ThursdayStart;

		public static ConfigEntry<string> ThursdayEnd;

		public static ConfigEntry<string> FridayStart;

		public static ConfigEntry<string> FridayEnd;

		public static ConfigEntry<string> SaturdayStart;

		public static ConfigEntry<string> SaturdayEnd;

		public static ConfigEntry<string> SundayStart;

		public static ConfigEntry<string> SundayEnd;

		public static Dictionary<DayOfWeek, Raidwindow> Windows { get; private set; } = new Dictionary<DayOfWeek, Raidwindow>();


		public static void Initialize(ConfigFile config)
		{
			if (OverrideMode == null)
			{
				OverrideMode = config.Bind<string>("RaidSchedule", "OverrideMode", "Normal", "ForceOn => always on, ForceOff => always off, Normal => day-of-week scheduling.");
				RaidCheckInterval = config.Bind<int>("RaidSchedule", "RaidCheckInterval", 5, "How often (in seconds) we do reflection checks. If you want near-instant toggles, set to 1. You may not want to change this");
				MondayStart = config.Bind<string>("RaidSchedule", "MondayStart", "20:00:00", "Monday start time");
				MondayEnd = config.Bind<string>("RaidSchedule", "MondayEnd", "22:00:00", "Monday end time");
				TuesdayStart = config.Bind<string>("RaidSchedule", "TuesdayStart", "20:00:00", "Tuesday start time");
				TuesdayEnd = config.Bind<string>("RaidSchedule", "TuesdayEnd", "22:00:00", "Tuesday end time");
				WednesdayStart = config.Bind<string>("RaidSchedule", "WednesdayStart", "20:00:00", "Wed start time");
				WednesdayEnd = config.Bind<string>("RaidSchedule", "WednesdayEnd", "22:00:00", "Wed end time");
				ThursdayStart = config.Bind<string>("RaidSchedule", "ThursdayStart", "20:00:00", "Thu start time");
				ThursdayEnd = config.Bind<string>("RaidSchedule", "ThursdayEnd", "22:00:00", "Thu end time");
				FridayStart = config.Bind<string>("RaidSchedule", "FridayStart", "20:00:00", "Fri start time");
				FridayEnd = config.Bind<string>("RaidSchedule", "FridayEnd", "22:00:00", "Fri end time");
				SaturdayStart = config.Bind<string>("RaidSchedule", "SaturdayStart", "20:00:00", "Sat start time");
				SaturdayEnd = config.Bind<string>("RaidSchedule", "SaturdayEnd", "22:00:00", "Sat end time");
				SundayStart = config.Bind<string>("RaidSchedule", "SundayStart", "20:00:00", "Sun start time");
				SundayEnd = config.Bind<string>("RaidSchedule", "SundayEnd", "22:00:00", "Sun end time");
				LoadFromConfig();
			}
		}

		public static void LoadFromConfig()
		{
			Windows.Clear();
			ParseDay(DayOfWeek.Monday, MondayStart.Value, MondayEnd.Value);
			ParseDay(DayOfWeek.Tuesday, TuesdayStart.Value, TuesdayEnd.Value);
			ParseDay(DayOfWeek.Wednesday, WednesdayStart.Value, WednesdayEnd.Value);
			ParseDay(DayOfWeek.Thursday, ThursdayStart.Value, ThursdayEnd.Value);
			ParseDay(DayOfWeek.Friday, FridayStart.Value, FridayEnd.Value);
			ParseDay(DayOfWeek.Saturday, SaturdayStart.Value, SaturdayEnd.Value);
			ParseDay(DayOfWeek.Sunday, SundayStart.Value, SundayEnd.Value);
		}

		private static void ParseDay(DayOfWeek day, string startStr, string endStr)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			if (TimeSpan.TryParse(startStr, out var result) && TimeSpan.TryParse(endStr, out var result2))
			{
				if (!(result == TimeSpan.Zero) || !(result2 == TimeSpan.Zero))
				{
					if (result2 == TimeSpan.Zero && result != TimeSpan.Zero)
					{
						result2 = new TimeSpan(24, 0, 0);
					}
					Windows[day] = new Raidwindow
					{
						Day = day,
						Start = result,
						End = result2
					};
				}
				return;
			}
			ManualLogSource logger = RaidForgePlugin.Logger;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(39, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Raidschedule] Invalid time for ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<DayOfWeek>(day);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(startStr);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(endStr);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
			}
			logger.LogWarning(val);
		}
	}
	public static class RaidtimeManager
	{
		public enum RaidMode
		{
			ForceOn,
			ForceOff,
			Normal
		}

		private static bool _initialized;

		private static RaidMode _currentMode = RaidMode.Normal;

		private static int _intervalSec = 30;

		private static DateTime _lastCheckTime = DateTime.MinValue;

		private static bool _skipWindow;

		private static DayOfWeek _skipDay;

		private static TimeSpan _skipStart;

		private static TimeSpan _skipEnd;

		public static void Initialize()
		{
			_initialized = false;
		}

		public static void Dispose()
		{
			_initialized = false;
			_skipWindow = false;
		}

		public static void OnServerTick()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			if (!_initialized)
			{
				_initialized = true;
				LoadConfig();
				_lastCheckTime = DateTime.Now;
				ManualLogSource logger = RaidForgePlugin.Logger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(43, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RaidtimeManager] Initialized. intervalSec=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_intervalSec);
				}
				logger.LogInfo(val);
			}
			DateTime now = DateTime.Now;
			double totalSeconds = (now - _lastCheckTime).TotalSeconds;
			if (!(totalSeconds < (double)_intervalSec))
			{
				_lastCheckTime = now;
				CheckAndToggleRaidMode();
			}
		}

		public static void ReloadFromConfig(bool immediate = false)
		{
			LoadConfig();
			if (immediate)
			{
				_lastCheckTime = DateTime.Now - TimeSpan.FromSeconds(_intervalSec);
				CheckAndToggleRaidMode();
			}
		}

		private static void LoadConfig()
		{
			string value = Raidschedule.OverrideMode.Value;
			if (value.Equals("ForceOn", StringComparison.OrdinalIgnoreCase) || value.Equals("AlwaysOn", StringComparison.OrdinalIgnoreCase))
			{
				_currentMode = RaidMode.ForceOn;
			}
			else if (value.Equals("ForceOff", StringComparison.OrdinalIgnoreCase))
			{
				_currentMode = RaidMode.ForceOff;
			}
			else
			{
				_currentMode = RaidMode.Normal;
			}
			_intervalSec = Raidschedule.RaidCheckInterval.Value;
			if (_intervalSec < 1)
			{
				_intervalSec = 1;
			}
		}

		private static void CheckAndToggleRaidMode()
		{
			if (_currentMode == RaidMode.ForceOn)
			{
				VrisingRaidToggler.EnableRaids(RaidForgePlugin.Logger);
				return;
			}
			if (_currentMode == RaidMode.ForceOff)
			{
				VrisingRaidToggler.DisableRaids(RaidForgePlugin.Logger);
				return;
			}
			DateTime now = DateTime.Now;
			DayOfWeek dayOfWeek = now.DayOfWeek;
			TimeSpan timeOfDay = now.TimeOfDay;
			if (_skipWindow && dayOfWeek != _skipDay)
			{
				_skipWindow = false;
			}
			if (_skipWindow && dayOfWeek == _skipDay && timeOfDay >= _skipStart && timeOfDay <= _skipEnd)
			{
				VrisingRaidToggler.DisableRaids(RaidForgePlugin.Logger);
				return;
			}
			if (_skipWindow && (dayOfWeek != _skipDay || timeOfDay > _skipEnd))
			{
				_skipWindow = false;
			}
			if (Raidschedule.Windows.TryGetValue(dayOfWeek, out var value))
			{
				if (timeOfDay >= value.Start && timeOfDay <= value.End)
				{
					VrisingRaidToggler.EnableRaids(RaidForgePlugin.Logger);
				}
				else
				{
					VrisingRaidToggler.DisableRaids(RaidForgePlugin.Logger);
				}
			}
			else
			{
				VrisingRaidToggler.DisableRaids(RaidForgePlugin.Logger);
			}
		}

		public static void SkipCurrentWindowIfAny()
		{
			if (_currentMode == RaidMode.Normal)
			{
				DateTime now = DateTime.Now;
				DayOfWeek dayOfWeek = now.DayOfWeek;
				TimeSpan timeOfDay = now.TimeOfDay;
				if (Raidschedule.Windows.TryGetValue(dayOfWeek, out var value) && timeOfDay >= value.Start && timeOfDay <= value.End)
				{
					_skipWindow = true;
					_skipDay = dayOfWeek;
					_skipStart = value.Start;
					_skipEnd = value.End;
				}
			}
		}

		public static DateTime? GetNextOnTime(DateTime now)
		{
			for (int i = 0; i < 7; i++)
			{
				DateTime dateTime = now.Date.AddDays(i);
				DayOfWeek dayOfWeek = dateTime.DayOfWeek;
				if (Raidschedule.Windows.TryGetValue(dayOfWeek, out var value))
				{
					DateTime dateTime2 = dateTime + value.Start;
					DateTime dateTime3 = dateTime + value.End;
					if ((i != 0 || !(now >= dateTime2) || !(now <= dateTime3)) && dateTime2 > now)
					{
						return dateTime2;
					}
				}
			}
			return null;
		}
	}
	public static class RaidTogglerReflection
	{
		private static bool _initialized;

		private static FieldInfo _settingsField;

		private static FieldInfo _castleDamageModeField;

		public static void EnableRaid(ManualLogSource logger)
		{
			logger.LogInfo((object)"[RaidForge] Attempting to set raids ON => CastleDamageMode.Always");
			bool flag = SetCastleDamageMode("Always", logger);
			bool flag2 = SetServerGameBalanceCastleDamage("Always", logger);
			if (!flag || !flag2)
			{
				logger.LogWarning((object)"[RaidForge] Could not fully enable raids!");
			}
		}

		public static void DisableRaid(ManualLogSource logger)
		{
			logger.LogInfo((object)"[RaidForge] Attempting to set raids OFF => CastleDamageMode.TimeRestricted");
			bool flag = SetCastleDamageMode("TimeRestricted", logger);
			bool flag2 = SetServerGameBalanceCastleDamage("TimeRestricted", logger);
			if (!flag || !flag2)
			{
				logger.LogWarning((object)"[RaidForge] Could not fully disable raids!");
			}
		}

		public static string? GetCurrentCastleDamageMode(ManualLogSource logger)
		{
			World server = VWorld.Server;
			if (server == null)
			{
				logger.LogError((object)"[RaidForge] No VWorld.Server, can't read CastleDamageMode!");
				return null;
			}
			ServerGameSettingsSystem existingSystemManaged = server.GetExistingSystemManaged<ServerGameSettingsSystem>();
			if (existingSystemManaged == null)
			{
				logger.LogError((object)"[RaidForge] No ServerGameSettingsSystem found!");
				return null;
			}
			InitializeReflection(existingSystemManaged, logger);
			if (_settingsField == null || _castleDamageModeField == null)
			{
				logger.LogError((object)"[RaidForge] No ._Settings or .CastleDamageMode discovered via reflection!");
				return null;
			}
			object value = _settingsField.GetValue(existingSystemManaged);
			if (value == null)
			{
				logger.LogError((object)"[RaidForge] ._Settings object is null!");
				return null;
			}
			return _castleDamageModeField.GetValue(value)?.ToString();
		}

		private static bool SetCastleDamageMode(string enumValue, ManualLogSource logger)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			World server = VWorld.Server;
			if (server == null)
			{
				logger.LogError((object)"[RaidForge] VWorld.Server is null, can't set CastleDamageMode!");
				return false;
			}
			ServerGameSettingsSystem existingSystemManaged = server.GetExistingSystemManaged<ServerGameSettingsSystem>();
			if (existingSystemManaged == null)
			{
				logger.LogError((object)"[RaidForge] No ServerGameSettingsSystem found!");
				return false;
			}
			InitializeReflection(existingSystemManaged, logger);
			if (_settingsField == null || _castleDamageModeField == null)
			{
				logger.LogError((object)"[RaidForge] Could not find ._Settings or .CastleDamageMode in reflection!");
				return false;
			}
			object value = _settingsField.GetValue(existingSystemManaged);
			if (value == null)
			{
				logger.LogError((object)"[RaidForge] ._Settings is null!");
				return false;
			}
			object value2 = Enum.Parse(_castleDamageModeField.FieldType, enumValue);
			_castleDamageModeField.SetValue(value, value2);
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(63, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RaidForge] Set ._Settings.CastleDamageMode => ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(enumValue);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" via reflection.");
			}
			logger.LogInfo(val);
			return true;
		}

		private static bool SetServerGameBalanceCastleDamage(string enumValue, ManualLogSource logger)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0074: 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_007d: 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_00b1: 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)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(55, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RaidForge] Also updating ServerGameBalanceSettings => ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(enumValue);
			}
			logger.LogInfo(val);
			World server = VWorld.Server;
			if (server == null)
			{
				logger.LogError((object)"[RaidForge] No VWorld.Server, can't update SGB!");
				return false;
			}
			EntityManager entityManager = server.EntityManager;
			EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadWrite<ServerGameBalanceSettings>() });
			NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				if (val3.Length < 1)
				{
					logger.LogWarning((object)"[RaidForge] No entity with ServerGameBalanceSettings found!");
					return false;
				}
				Entity val4 = val3[0];
				ServerGameBalanceSettings componentData = ((EntityManager)(ref entityManager)).GetComponentData<ServerGameBalanceSettings>(val4);
				Type type = ((object)componentData.CastleDamageMode).GetType();
				object obj = Enum.Parse(type, enumValue);
				componentData.CastleDamageMode = (CastleDamageMode)obj;
				((EntityManager)(ref entityManager)).SetComponentData<ServerGameBalanceSettings>(val4, componentData);
				val = new BepInExInfoLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RaidForge] Updated SGB.CastleDamageMode => ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(enumValue);
				}
				logger.LogInfo(val);
				return true;
			}
			finally
			{
				val3.Dispose();
			}
		}

		private static void InitializeReflection(ServerGameSettingsSystem sgsSystem, ManualLogSource logger)
		{
			if (_initialized)
			{
				return;
			}
			_initialized = true;
			Type type = ((object)sgsSystem).GetType();
			_settingsField = type.GetField("_Settings", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (_settingsField == null)
			{
				logger.LogError((object)"[RaidForge] No field named '_Settings' in ServerGameSettingsSystem. We'll try fallback...");
				_settingsField = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((FieldInfo f) => f.Name.ToLower().Contains("settings"));
			}
			if (_settingsField == null)
			{
				logger.LogError((object)"[RaidForge] Still no field with 'settings' in name!");
				return;
			}
			Type fieldType = _settingsField.FieldType;
			_castleDamageModeField = fieldType.GetField("CastleDamageMode", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (_castleDamageModeField == null)
			{
				logger.LogError((object)"[RaidForge] Could not find 'CastleDamageMode' in the _Settings object!");
			}
			else
			{
				logger.LogInfo((object)"[RaidForge] Reflection found ._Settings + .CastleDamageMode fields!");
			}
		}
	}
	public class Raidwindow
	{
		public DayOfWeek Day { get; set; }

		public TimeSpan Start { get; set; }

		public TimeSpan End { get; set; }
	}
	[HarmonyPatch(typeof(VivoxConnectionSystem), "OnUpdate")]
	public static class VivoxPatch
	{
		[HarmonyPostfix]
		public static void Postfix(VivoxConnectionSystem __instance)
		{
			RaidtimeManager.OnServerTick();
		}
	}
	public static class VrisingRaidToggler
	{
		private static bool _scanned;

		private static FieldInfo _settingsField;

		private static FieldInfo _castleDamageField;

		public static void EnableRaids(ManualLogSource logger)
		{
			bool flag = SetCastleDamageMode("Always");
			bool flag2 = SetServerGameBalanceCastleDamage("Always");
		}

		public static void DisableRaids(ManualLogSource logger)
		{
			bool flag = SetCastleDamageMode("Never");
			bool flag2 = SetServerGameBalanceCastleDamage("Never");
		}

		private static bool SetCastleDamageMode(string val)
		{
			World server = VWorld.Server;
			if (server == null)
			{
				return false;
			}
			ServerGameSettingsSystem existingSystemManaged = server.GetExistingSystemManaged<ServerGameSettingsSystem>();
			if (existingSystemManaged == null)
			{
				return false;
			}
			if (!_scanned)
			{
				_scanned = true;
				FindCastleDamageField(existingSystemManaged);
			}
			if (_settingsField == null || _castleDamageField == null)
			{
				return false;
			}
			object value = _settingsField.GetValue(existingSystemManaged);
			if (value == null)
			{
				return false;
			}
			try
			{
				object value2 = Enum.Parse(_castleDamageField.FieldType, val);
				_castleDamageField.SetValue(value, value2);
				return true;
			}
			catch
			{
				return false;
			}
		}

		private static bool SetServerGameBalanceCastleDamage(string val)
		{
			//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_002a: 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)
			//IL_0034: 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_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_0047: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			World server = VWorld.Server;
			if (server == null)
			{
				return false;
			}
			EntityManager entityManager = server.EntityManager;
			EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadWrite<ServerGameBalanceSettings>() });
			NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				if (val3.Length == 0)
				{
					return false;
				}
				Entity val4 = val3[0];
				ServerGameBalanceSettings componentData = ((EntityManager)(ref entityManager)).GetComponentData<ServerGameBalanceSettings>(val4);
				Type type = ((object)componentData.CastleDamageMode).GetType();
				object obj = Enum.Parse(type, val);
				componentData.CastleDamageMode = (CastleDamageMode)obj;
				((EntityManager)(ref entityManager)).SetComponentData<ServerGameBalanceSettings>(val4, componentData);
				return true;
			}
			finally
			{
				val3.Dispose();
			}
		}

		private static void FindCastleDamageField(ServerGameSettingsSystem sgsSystem)
		{
			Type type = ((object)sgsSystem).GetType();
			FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				if (!fieldInfo.Name.ToLower().Contains("settings"))
				{
					continue;
				}
				object value = fieldInfo.GetValue(sgsSystem);
				if (value != null)
				{
					FieldInfo field = value.GetType().GetField("CastleDamageMode", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null)
					{
						_settingsField = fieldInfo;
						_castleDamageField = field;
						return;
					}
				}
			}
			FieldInfo[] array2 = fields;
			foreach (FieldInfo fieldInfo2 in array2)
			{
				object value2 = fieldInfo2.GetValue(sgsSystem);
				if (value2 != null)
				{
					FieldInfo field2 = value2.GetType().GetField("CastleDamageMode", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field2 != null)
					{
						_settingsField = fieldInfo2;
						_castleDamageField = field2;
						break;
					}
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "RaidForge";

		public const string PLUGIN_NAME = "RaidForge";

		public const string PLUGIN_VERSION = "0.1.10";
	}
}