Decompiled source of Nocturnes v0.1.0

Nocturnes.dll

Decompiled 2 years ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Nocturnes.Services;
using ProjectM;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Nocturnes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+9e8a07f3229623fd906526b3ddbf589332c20108")]
[assembly: AssemblyProduct("Nocturnes")]
[assembly: AssemblyTitle("Nocturnes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.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 Nocturnes
{
	internal static class Core
	{
		public class DataStructures
		{
			private static readonly JsonSerializerOptions prettyJsonOptions = new JsonSerializerOptions
			{
				WriteIndented = true,
				IncludeFields = true
			};

			private static Dictionary<ulong, (int Tokens, (DateTime Start, DateTime DailyLogin) TimeData)> playerTokens = new Dictionary<ulong, (int, (DateTime, DateTime))>();

			private static readonly Dictionary<string, string> filePaths = new Dictionary<string, string> { 
			{
				"Tokens",
				JsonFiles.PlayerTokenJsons
			} };

			public static Dictionary<ulong, (int Tokens, (DateTime Start, DateTime DailyLogin) TimeData)> PlayerTokens
			{
				get
				{
					return playerTokens;
				}
				set
				{
					playerTokens = value;
				}
			}

			public static void LoadData<T>(ref Dictionary<ulong, T> dataStructure, string key)
			{
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Expected O, but got Unknown
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Expected O, but got Unknown
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				string path = filePaths[key];
				bool flag = default(bool);
				if (!File.Exists(path))
				{
					File.Create(path).Dispose();
					dataStructure = new Dictionary<ulong, T>();
					ManualLogSource log = Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" file created as it did not exist.");
					}
					log.LogInfo(val);
					return;
				}
				try
				{
					string text = File.ReadAllText(path);
					if (string.IsNullOrWhiteSpace(text))
					{
						dataStructure = new Dictionary<ulong, T>();
						return;
					}
					Dictionary<ulong, T> dictionary = JsonSerializer.Deserialize<Dictionary<ulong, T>>(text, prettyJsonOptions);
					dataStructure = dictionary ?? new Dictionary<ulong, T>();
				}
				catch (IOException ex)
				{
					ManualLogSource log2 = Log;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(31, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error reading ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" data from file: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					log2.LogError(val2);
					dataStructure = new Dictionary<ulong, T>();
				}
				catch (JsonException ex2)
				{
					ManualLogSource log3 = Log;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(47, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("JSON deserialization error when loading ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" data: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
					}
					log3.LogError(val2);
					dataStructure = new Dictionary<ulong, T>();
				}
			}

			public static void LoadPlayerTokens()
			{
				LoadData(ref playerTokens, "Tokens");
			}

			public static void SaveData<T>(Dictionary<ulong, T> data, string key)
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Expected O, but got Unknown
				string path = filePaths[key];
				bool flag = default(bool);
				try
				{
					string contents = JsonSerializer.Serialize(data, prettyJsonOptions);
					File.WriteAllText(path, contents);
				}
				catch (IOException ex)
				{
					ManualLogSource log = Log;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to write ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" data to file: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogError(val);
				}
				catch (JsonException ex2)
				{
					ManualLogSource log2 = Log;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(44, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("JSON serialization error when saving ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" data: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
					}
					log2.LogError(val);
				}
			}

			public static void SavePlayerTokens()
			{
				SaveData(PlayerTokens, "Tokens");
			}
		}

		private static class JsonFiles
		{
			public static readonly string PlayerTokenJsons = Plugin.PlayerTokensPath;
		}

		private static bool hasInitialized;

		private static MonoBehaviour monoBehaviour;

		public static World Server { get; } = GetWorld("Server") ?? throw new Exception("There is no Server world (yet)...");


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


		public static ServerScriptMapper ServerScriptMapper { get; internal set; }

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

		public static GameDataSystem GameDataSystem { get; internal set; }

		public static EntityCommandBufferSystem EntityCommandBufferSystem { get; internal set; }

		public static ManualLogSource Log => Plugin.LogInstance;

		public static NocturneService NocturneService { get; internal set; }

		public static void Initialize()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			if (!hasInitialized)
			{
				ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
				GameDataSystem = Server.GetExistingSystemManaged<GameDataSystem>();
				EntityCommandBufferSystem = Server.GetExistingSystemManaged<EntityCommandBufferSystem>();
				NocturneService = new NocturneService();
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(15, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Nocturnes");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] initialized!");
				}
				log.LogInfo(val);
				hasInitialized = true;
			}
		}

		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 void StartCoroutine(IEnumerator routine)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if ((Object)(object)monoBehaviour == (Object)null)
			{
				GameObject val = new GameObject("Nocturnes");
				monoBehaviour = (MonoBehaviour)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
				Object.DontDestroyOnLoad((Object)(object)val);
			}
			monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}

		public static string ExtractName(string input)
		{
			string[] array = input.Split(' ');
			if (array.Length != 0 && array[0].Contains('_'))
			{
				return array[0].Split('_')[^1];
			}
			return string.Empty;
		}
	}
	public static class ECSExtensions
	{
		private static EntityManager EntityManager { get; } = Core.Server.EntityManager;


		public unsafe static void Write<T>(this Entity entity, T componentData) where T : struct
		{
			//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_003e: 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_0040: 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 = 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 = EntityManager;
			void* componentDataRawRO = ((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex);
			return Marshal.PtrToStructure<T>(new IntPtr(componentDataRawRO));
		}

		public static DynamicBuffer<T> ReadBuffer<T>(this Entity entity) where T : struct
		{
			//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_000f: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.Server.EntityManager;
			return ((EntityManager)(ref entityManager)).GetBuffer<T>(entity, false);
		}

		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 = 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 = Core.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 LogComponentTypes(this Entity entity)
		{
			//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_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_0012: 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_002b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			Enumerator<ComponentType> enumerator = ((EntityManager)(ref entityManager)).GetComponentTypes(entity, (Allocator)2).GetEnumerator();
			Core.Log.LogInfo((object)"===");
			bool flag = default(bool);
			while (enumerator.MoveNext())
			{
				ComponentType current = enumerator.Current;
				ManualLogSource log = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(0, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ComponentType>(current);
				}
				log.LogInfo(val);
			}
			Core.Log.LogInfo((object)"===");
		}

		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 = 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 = EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}
	}
	[BepInPlugin("com.zfolmt.Nocturnes", "Nocturnes", "0.1.0")]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static readonly string ConfigPath = Path.Combine(Paths.ConfigPath, "Nocturnes");

		public static readonly string PlayerTokensPath = Path.Combine(ConfigPath, "PlayerNocturnes");

		private static ConfigEntry<bool> _nocturneSystem;

		private static ConfigEntry<bool> _dailyLogin;

		private static ConfigEntry<int> _dailyReward;

		private static ConfigEntry<int> _dailyQuantity;

		private static ConfigEntry<int> _nocturneReward;

		private static ConfigEntry<int> _nocturneRewardRatio;

		private static ConfigEntry<int> _nocturnePerMinute;

		private static ConfigEntry<int> _updateInterval;

		internal static Plugin Instance { get; private set; }

		public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;

		public static bool TokenSystem => _nocturneSystem.Value;

		public static bool DailyLogin => _dailyLogin.Value;

		public static int DailyReward => _dailyReward.Value;

		public static int DailyQuantity => _dailyQuantity.Value;

		public static int TokenReward => _nocturneReward.Value;

		public static int TokenRewardRatio => _nocturneRewardRatio.Value;

		public static int TokensPerMinute => _nocturnePerMinute.Value;

		public static int UpdateInterval => _updateInterval.Value;

		public override void Load()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			Instance = this;
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			InitConfig();
			CommandRegistry.RegisterAll();
			LoadAllData();
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Nocturnes");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] loaded!");
			}
			log.LogInfo(val);
		}

		private static void InitConfig()
		{
			CreateDirectories(ConfigPath);
			_nocturneSystem = InitConfigEntry("Config", "Nocturnes", defaultValue: false, "Enable or disable Nocturnes.");
			_dailyLogin = InitConfigEntry("Config", "DailyLogin", defaultValue: false, "Enable or disable daily login rewards.");
			_nocturneReward = InitConfigEntry("Config", "NocturnesItemReward", -257494203, "Item prefab for Nocturnes redeeming (crystals default).");
			_dailyReward = InitConfigEntry("Config", "DailyItemReward", -257494203, "Item prefab for daily login (crystals default).");
			_dailyQuantity = InitConfigEntry("Config", "DailyItemQuantity", 50, "Amount rewarded for daily login.");
			_nocturneRewardRatio = InitConfigEntry("Config", "NocturnesRewardFactor", 50, "Nocturnes/reward when redeeming.");
			_nocturnePerMinute = InitConfigEntry("Config", "NocturnesPerMinute", 5, "Nocturnes/minute spent online.");
			_updateInterval = InitConfigEntry("Config", "NocturnesUpdateInterval", 30, "Interval in minutes to update player Nocturnes.");
		}

		private static ConfigEntry<T> InitConfigEntry<T>(string section, string key, T defaultValue, string description)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			ConfigEntry<T> val = ((BasePlugin)Instance).Config.Bind<T>(section, key, defaultValue, description);
			string text = Path.Combine(ConfigPath, "com.zfolmt.Nocturnes.cfg");
			if (File.Exists(text))
			{
				ConfigFile val2 = new ConfigFile(text, true);
				ConfigEntry<T> val3 = default(ConfigEntry<T>);
				if (val2.TryGetEntry<T>(section, key, ref val3))
				{
					val.Value = val3.Value;
				}
			}
			return val;
		}

		private static void CreateDirectories(string path)
		{
			if (!Directory.Exists(path))
			{
				Directory.CreateDirectory(path);
			}
		}

		public override bool Unload()
		{
			((BasePlugin)this).Config.Clear();
			_harmony.UnpatchSelf();
			return true;
		}

		private static void LoadAllData()
		{
			if (_nocturneSystem.Value)
			{
				Core.DataStructures.LoadPlayerTokens();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.zfolmt.Nocturnes";

		public const string PLUGIN_NAME = "Nocturnes";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace Nocturnes.Services
{
	internal class NocturneService
	{
		private static readonly int intervalMinutes = Plugin.UpdateInterval;

		private static readonly int tokensPerMinute = Plugin.TokensPerMinute;

		private static readonly bool tokenSystem = Plugin.TokenSystem;

		private EntityQuery userQuery;

		private readonly IgnorePhysicsDebugSystem tokenMonoBehaviour;

		public NocturneService()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001b: 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_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_004b: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1]
			{
				new ComponentType(Il2CppType.Of<User>(), (AccessMode)1)
			});
			val.Options = (EntityQueryOptions)0;
			EntityQueryDesc val2 = val;
			EntityManager entityManager = Core.EntityManager;
			userQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val2 });
			tokenMonoBehaviour = new GameObject("NocturneService").AddComponent<IgnorePhysicsDebugSystem>();
			if (tokenSystem)
			{
				((MonoBehaviour)tokenMonoBehaviour).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(UpdateLoop()));
			}
		}

		private IEnumerator UpdateLoop()
		{
			WaitForSeconds waitForSeconds = new WaitForSeconds((float)(intervalMinutes * 60));
			while (true)
			{
				yield return waitForSeconds;
				NativeArray<Entity> val = ((EntityQuery)(ref userQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
				DateTime now = DateTime.Now;
				try
				{
					Dictionary<ulong, (int, (DateTime, DateTime))> dictionary = new Dictionary<ulong, (int, (DateTime, DateTime))>();
					Enumerator<Entity> enumerator = val.GetEnumerator();
					while (enumerator.MoveNext())
					{
						Entity current = enumerator.Current;
						User val2 = current.Read<User>();
						if (val2.IsConnected)
						{
							ulong platformId = val2.PlatformId;
							if (Core.DataStructures.PlayerTokens.TryGetValue(platformId, out (int, (DateTime, DateTime)) value))
							{
								TimeSpan timeSpan = now - value.Item2.Item1;
								int item = value.Item1 + timeSpan.Minutes * tokensPerMinute;
								dictionary[platformId] = (item, (now, value.Item2.Item2));
							}
						}
					}
					foreach (KeyValuePair<ulong, (int, (DateTime, DateTime))> item2 in dictionary)
					{
						Core.DataStructures.PlayerTokens[item2.Key] = item2.Value;
					}
					Core.DataStructures.SavePlayerTokens();
				}
				finally
				{
					val.Dispose();
				}
			}
		}
	}
}
namespace Nocturnes.Patches
{
	[HarmonyPatch(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate")]
	public static class InitializationPatch
	{
		[HarmonyPostfix]
		public static void OnUpdatePostfix()
		{
			Core.Initialize();
		}
	}
	[HarmonyPatch]
	public class ServerBootstrapPatches
	{
		private static readonly PrefabGUID dailyReward = new PrefabGUID(Plugin.DailyReward);

		private static readonly int dailyQuantity = Plugin.DailyQuantity;

		private static readonly bool dailyLogin = Plugin.DailyLogin;

		private static readonly int tokensPerMinute = Plugin.TokensPerMinute;

		private static readonly bool tokenSystem = Plugin.TokenSystem;

		[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserConnected")]
		[HarmonyPostfix]
		private static void OnUserConnectedPostix(ServerBootstrapSystem __instance, NetConnectionId netConnectionId)
		{
			//IL_001b: 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_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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_008c: 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_0095: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
			ServerClient val = ((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num];
			Entity userEntity = val.UserEntity;
			EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
			User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
			ulong platformId = componentData.PlatformId;
			if (!tokenSystem)
			{
				return;
			}
			ServerGameManager serverGameManager;
			if (!Core.DataStructures.PlayerTokens.TryGetValue(platformId, out (int, (DateTime, DateTime)) value))
			{
				DateTime now = DateTime.Now;
				value = (0, (now, now));
				Core.DataStructures.PlayerTokens.Add(platformId, value);
				Core.DataStructures.SavePlayerTokens();
				if (!dailyLogin)
				{
					return;
				}
				entityManager = Core.EntityManager;
				if (((EntityManager)(ref entityManager)).Exists(componentData.LocalCharacter._Entity))
				{
					serverGameManager = Core.ServerGameManager;
					if (AddItemResponse.op_Implicit(((ServerGameManager)(ref serverGameManager)).TryAddInventoryItem(componentData.LocalCharacter._Entity, dailyReward, dailyQuantity)))
					{
						string text = $"You've received <color=#00FFFF>{Core.ExtractName(dailyReward.LookupName())}</color>x<color=white>{dailyQuantity}</color> for logging in today!";
						ServerChatUtils.SendSystemMessageToClient(((ComponentSystemBase)__instance).EntityManager, componentData, text);
					}
					else
					{
						InventoryUtilitiesServer.CreateDropItem(Core.EntityManager, componentData.LocalCharacter._Entity, dailyReward, dailyQuantity, default(Entity));
						string text2 = $"You've received <color=#00FFFF>{Core.ExtractName(dailyReward.LookupName())}</color>x<color=white>{dailyQuantity}</color> for logging in today! It dropped on the ground because your inventory was full.";
						ServerChatUtils.SendSystemMessageToClient(((ComponentSystemBase)__instance).EntityManager, componentData, text2);
					}
				}
				return;
			}
			if (dailyLogin && DateTime.Now.Subtract(value.Item2.Item2).Days >= 1)
			{
				serverGameManager = Core.ServerGameManager;
				if (AddItemResponse.op_Implicit(((ServerGameManager)(ref serverGameManager)).TryAddInventoryItem(componentData.LocalCharacter._Entity, dailyReward, dailyQuantity)))
				{
					string text3 = $"You've received <color=#00FFFF>{Core.ExtractName(dailyReward.LookupName())}</color>x<color=white>{dailyQuantity}</color> for logging in today!";
					ServerChatUtils.SendSystemMessageToClient(((ComponentSystemBase)__instance).EntityManager, componentData, text3);
				}
				else
				{
					InventoryUtilitiesServer.CreateDropItem(Core.EntityManager, componentData.LocalCharacter._Entity, dailyReward, dailyQuantity, default(Entity));
					string text4 = $"You've received <color=#00FFFF>{Core.ExtractName(dailyReward.LookupName())}</color>x<color=white>{dailyQuantity}</color> for logging in today! It dropped on the ground because your inventory was full.";
					ServerChatUtils.SendSystemMessageToClient(((ComponentSystemBase)__instance).EntityManager, componentData, text4);
				}
				value = (value.Item1, (value.Item2.Item1, DateTime.Now));
				Core.DataStructures.PlayerTokens[platformId] = value;
				Core.DataStructures.SavePlayerTokens();
			}
			value = (value.Item1, (DateTime.Now, value.Item2.Item2));
			Core.DataStructures.PlayerTokens[platformId] = value;
			Core.DataStructures.SavePlayerTokens();
		}

		[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserDisconnected")]
		[HarmonyPrefix]
		private static void OnUserDisconnectedPreix(ServerBootstrapSystem __instance, NetConnectionId netConnectionId)
		{
			//IL_001b: 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_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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
			ServerClient val = ((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num];
			Entity userEntity = val.UserEntity;
			EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
			User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
			ulong platformId = componentData.PlatformId;
			if (tokenSystem && Core.DataStructures.PlayerTokens.TryGetValue(platformId, out (int, (DateTime, DateTime)) value))
			{
				TimeSpan timeSpan = DateTime.Now - value.Item2.Item1;
				value = (value.Item1 + timeSpan.Minutes * tokensPerMinute, (DateTime.Now, value.Item2.Item2));
				Core.DataStructures.PlayerTokens[platformId] = value;
				Core.DataStructures.SavePlayerTokens();
			}
		}
	}
}
namespace Nocturnes.Commands
{
	public static class NocturneCommands
	{
		private static readonly PrefabGUID tokenReward = new PrefabGUID(Plugin.TokenReward);

		private static readonly int tokenRewardRatio = Plugin.TokenRewardRatio;

		private static readonly int tokensPerMinute = Plugin.TokensPerMinute;

		[Command("redeemNocturnes", "rn", ".rn", "Redeems Nocturnes.", null, false)]
		public static void RedeemNocturnesCommand(ChatCommandContext ctx)
		{
			//IL_0019: 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_0099: 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)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.TokenSystem)
			{
				ctx.Reply("<color=#CBC3E3>Nocturnes</color> are currently disabled.");
				return;
			}
			ulong platformId = ctx.Event.User.PlatformId;
			if (!Core.DataStructures.PlayerTokens.TryGetValue(platformId, out (int, (DateTime, DateTime)) value))
			{
				return;
			}
			if (value.Item1 < tokenRewardRatio)
			{
				ctx.Reply($"You don't have enough <color=#CBC3E3>Nocturnes</color> to redeem. (<color=#FFC0CB>{tokenRewardRatio}</color> minimum)");
				return;
			}
			int num = value.Item1 / tokenRewardRatio;
			int num2 = num * tokenRewardRatio;
			ServerGameManager serverGameManager = Core.ServerGameManager;
			if (AddItemResponse.op_Implicit(((ServerGameManager)(ref serverGameManager)).TryAddInventoryItem(ctx.Event.SenderCharacterEntity, tokenReward, num)))
			{
				value = (value.Item1 - num2, value.Item2);
				Core.DataStructures.PlayerTokens[platformId] = value;
				Core.DataStructures.SavePlayerTokens();
				ctx.Reply($"You've received <color=#00FFFF>{Core.ExtractName(tokenReward.LookupName())}</color>x<color=white>{num}</color> for redeeming <color=#FFC0CB>{num2}</color> <color=#CBC3E3>Nocturnes</color>!");
			}
			else
			{
				value = (value.Item1 - num2, value.Item2);
				Core.DataStructures.PlayerTokens[platformId] = value;
				Core.DataStructures.SavePlayerTokens();
				InventoryUtilitiesServer.CreateDropItem(Core.EntityManager, ctx.Event.SenderCharacterEntity, tokenReward, num, default(Entity));
				ctx.Reply($"You've received <color=#00FFFF>{Core.ExtractName(tokenReward.LookupName())}</color>x<color=white>{num}</color> for redeeming <color=#FFC0CB>{num2}</color> <color=#CBC3E3>Nocturnes</color>! It dropped on the ground because your inventory was full.");
			}
		}

		[Command("getNocturnes", "get n", ".get n", "Shows earned Nocturnes, also updates them.", null, false)]
		public static void GetNocturnesCommand(ChatCommandContext ctx)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.TokenSystem)
			{
				ctx.Reply("<color=#CBC3E3>Nocturnes</color> are currently disabled.");
				return;
			}
			ulong platformId = ctx.Event.User.PlatformId;
			if (Core.DataStructures.PlayerTokens.TryGetValue(platformId, out (int, (DateTime, DateTime)) value))
			{
				TimeSpan timeSpan = DateTime.Now - value.Item2.Item1;
				value = (value.Item1 + timeSpan.Minutes * tokensPerMinute, (DateTime.Now, value.Item2.Item2));
				Core.DataStructures.PlayerTokens[platformId] = value;
				Core.DataStructures.SavePlayerTokens();
				ctx.Reply($"You have <color=#FFC0CB>{value.Item1}</color> <color=#CBC3E3>Nocturnes</color>.");
			}
		}
	}
}