Decompiled source of CrimsonQuest v0.1.1

CrimsonQuest.dll

Decompiled 2 months ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using Bloody.Core;
using Bloody.Core.API.v1;
using Bloody.Core.GameData.v1;
using Bloody.Core.Helper.v1;
using Bloody.Core.Models.v1;
using Bloody.Core.Models.v1.Base;
using CrimsonQuest.DB;
using CrimsonQuest.DB.Models;
using CrimsonQuest.Hooks;
using CrimsonQuest.Structs;
using CrimsonQuest.Utils;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("CrimsonQuest")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Created with VRising.ModTemplate, you should edit this.")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+2.Branch.master.Sha.e4f418229e735217357662fc0e3d7a6af30f1758")]
[assembly: AssemblyProduct("CrimsonQuest")]
[assembly: AssemblyTitle("CrimsonQuest")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
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.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace CrimsonQuest
{
	[BepInPlugin("CrimsonQuest", "CrimsonQuest", "0.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[Reloadable]
	public class Plugin : BasePlugin, IRunOnInitialized
	{
		private Harmony _harmony;

		public static ManualLogSource LogInstance { get; private set; }

		public static Settings Settings { get; private set; }

		public static SystemsCore SystemsCore { get; private set; }

		public override void Load()
		{
			LogInstance = ((BasePlugin)this).Log;
			Settings = new Settings(((BasePlugin)this).Config);
			Settings.InitConfig();
			if (!VWorld.IsServer)
			{
				((BasePlugin)this).Log.LogWarning((object)"This plugin is a server-only plugin.");
			}
			CommandRegistry.RegisterAll();
		}

		public void OnGameInitialized()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			if (!VWorld.IsClient)
			{
				_harmony = new Harmony("CrimsonQuest");
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
				CrimsonCore.InitializeAfterLoaded();
				SystemsCore = Core.SystemsCore;
				EventsHandlerSystem.OnDeathVBlood += new DeathVbloodEventHandler(CrimsonCore.Quest.UpdateVBloodQuestProgress);
				EventsHandlerSystem.OnDeath += new DeathEventHandler(CrimsonCore.Quest.UpdatePVPKillQuestProgress);
				ManualLogSource log = ((BasePlugin)this).Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CrimsonQuest");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
				}
				log.LogInfo(val);
			}
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CrimsonQuest";

		public const string PLUGIN_NAME = "CrimsonQuest";

		public const string PLUGIN_VERSION = "0.1.1";
	}
}
namespace CrimsonQuest.Utils
{
	internal static class CrimsonCore
	{
		public static ManualLogSource Log = Plugin.LogInstance;

		private static bool _hasInitialized = false;

		public static World Server { get; } = VWorld.Server;


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


		public static QuestService Quest { get; internal set; }

		public static PlayerDatabase PlayerData { get; internal set; }

		public static Database QuestData { get; internal set; }

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

		internal static void InitializeAfterLoaded()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			if (!_hasInitialized)
			{
				QuestData = new Database();
				PlayerData = new PlayerDatabase();
				Quest = new QuestService();
				ResetScheduler.StartTimer();
				_hasInitialized = true;
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("InitializeAfterLoaded");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" completed");
				}
				log.LogInfo(val);
			}
		}
	}
	internal class QuestService
	{
		public void GetQuest(UserModel player, QuestProgressModel progress, QuestGiverModel giver)
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: 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_017f: Unknown result type (might be due to invalid IL or missing references)
			if (giver.QuestType == QuestType.DAILY)
			{
				if (progress.CompletedDaily + progress.DailyQuests.Count >= Plugin.Settings.MAX_DAILY.Value || progress.DailyQuests.Count >= Plugin.Settings.ACTIVE_DAILY.Value)
				{
					return;
				}
				if (giver.GetRandomQuest(player, progress, out var quest))
				{
					progress.DailyQuests.Add(new QuestSlot(quest, giver.Name));
					ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(((EntityModel)player).Entity), $"You've accepted the <color=#ffc905>{quest.Name}</color>: {quest.Description}.");
				}
				else
				{
					ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(((EntityModel)player).Entity), "I have no quests to give you at this time...");
				}
			}
			if (giver.QuestType == QuestType.WEEKLY)
			{
				if (progress.CompletedWeekly + progress.WeeklyQuests.Count >= Plugin.Settings.MAX_WEEKLY.Value || progress.WeeklyQuests.Count >= Plugin.Settings.ACTIVE_WEEKLY.Value)
				{
					return;
				}
				if (giver.GetRandomQuest(player, progress, out var quest2))
				{
					progress.WeeklyQuests.Add(new QuestSlot(quest2, giver.Name));
					ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(((EntityModel)player).Entity), $"You've accepted the <color=#ffc905>{quest2.Name}</color>: {quest2.Description}.");
				}
				else
				{
					ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(((EntityModel)player).Entity), "I have no quests to give you at this time...");
				}
			}
			CrimsonCore.PlayerData.UpdatePlayer(player, progress);
		}

		public void CompleteGiverQuests(UserModel player, QuestProgressModel progress, QuestGiverModel targetGiver)
		{
			foreach (QuestSlot weeklyQuest in progress.WeeklyQuests)
			{
				if (!(weeklyQuest.QuestGiverName != targetGiver.Name))
				{
					CompleteGiverQuest(weeklyQuest, player, progress, targetGiver);
				}
			}
			foreach (QuestSlot dailyQuest in progress.DailyQuests)
			{
				if (!(dailyQuest.QuestGiverName != targetGiver.Name))
				{
					CompleteGiverQuest(dailyQuest, player, progress, targetGiver);
				}
			}
			CrimsonCore.PlayerData.UpdatePlayer(player, progress);
		}

		private void CompleteGiverQuest(QuestSlot slot, UserModel player, QuestProgressModel progress, QuestGiverModel targetGiver)
		{
			//IL_004a: 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_006b: 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)
			if (slot.QuestInProgress.Target.Type != QuestTargetType.MobKill || !slot.CheckForCompletion(out var _, out var _) || slot.isCompleted)
			{
				return;
			}
			foreach (Reward reward in slot.QuestInProgress.Rewards)
			{
				UserSystem.TryAddInventoryItemOrDrop(((EntityModel)player).Entity, new PrefabGUID(reward.GUID), reward.Quantity);
				ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(((EntityModel)player).Entity), "You have completed the quest <color=#ffc905>" + slot.QuestInProgress.Name + "</color>.");
			}
			slot.SetComplete();
		}

		public void UpdateMobQuestProgress(UserModel player, QuestProgressModel progress, PrefabGUID mob)
		{
			if (progress.WeeklyQuests.Count != 0)
			{
				for (int i = 0; i <= progress.WeeklyQuests.Count; i++)
				{
					if (progress.WeeklyQuests[i].QuestInProgress.Target.Type == QuestTargetType.MobKill && progress.WeeklyQuests[i].QuestInProgress.Target.GUID == ((PrefabGUID)(ref mob)).GuidHash)
					{
						QuestSlot questSlot = progress.WeeklyQuests[i];
						questSlot.IncrementProgress();
						progress.WeeklyQuests[i] = questSlot;
						CheckProgress(progress.WeeklyQuests[i], player);
					}
				}
			}
			if (progress.DailyQuests.Count != 0)
			{
				for (int j = 0; j <= progress.DailyQuests.Count; j++)
				{
					if (progress.DailyQuests[j].QuestInProgress.Target.Type == QuestTargetType.MobKill && progress.DailyQuests[j].QuestInProgress.Target.GUID == ((PrefabGUID)(ref mob)).GuidHash)
					{
						QuestSlot questSlot2 = progress.DailyQuests[j];
						questSlot2.IncrementProgress();
						progress.DailyQuests[j] = questSlot2;
						CheckProgress(progress.DailyQuests[j], player);
					}
				}
			}
			CrimsonCore.PlayerData.UpdatePlayer(player, progress);
		}

		public void UpdateVBloodQuestProgress(VBloodSystem __instance, NativeList<VBloodConsumed> deathEvents)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0034: 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_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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			Enumerator<VBloodConsumed> enumerator = deathEvents.GetEnumerator();
			while (enumerator.MoveNext())
			{
				VBloodConsumed current = enumerator.Current;
				if (!((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(current.Target))
				{
					continue;
				}
				PlayerCharacter componentData = ((EntityManager)(ref entityManager)).GetComponentData<PlayerCharacter>(current.Target);
				User componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<User>(componentData.UserEntity);
				UserModel userByCharacterName = GameData.Users.GetUserByCharacterName(((object)(FixedString64Bytes)(ref componentData2.CharacterName)).ToString());
				if (!CrimsonCore.PlayerData.GetProgressForUser(userByCharacterName, out var progress))
				{
					continue;
				}
				if (progress.WeeklyQuests.Count != 0)
				{
					for (int i = 0; i <= progress.WeeklyQuests.Count; i++)
					{
						if (progress.WeeklyQuests[i].QuestInProgress.Target.Type == QuestTargetType.VBloodKill && progress.WeeklyQuests[i].QuestInProgress.Target.GUID == current.Source._Value)
						{
							QuestSlot questSlot = progress.WeeklyQuests[i];
							questSlot.IncrementProgress();
							progress.WeeklyQuests[i] = questSlot;
							CheckProgress(progress.WeeklyQuests[i], userByCharacterName);
						}
					}
				}
				if (progress.DailyQuests.Count != 0)
				{
					for (int j = 0; j <= progress.DailyQuests.Count; j++)
					{
						if (progress.DailyQuests[j].QuestInProgress.Target.Type == QuestTargetType.VBloodKill && progress.DailyQuests[j].QuestInProgress.Target.GUID == current.Source._Value)
						{
							QuestSlot questSlot2 = progress.DailyQuests[j];
							questSlot2.IncrementProgress();
							progress.DailyQuests[j] = questSlot2;
							CheckProgress(progress.DailyQuests[j], userByCharacterName);
						}
					}
				}
				CrimsonCore.PlayerData.UpdatePlayer(userByCharacterName, progress);
			}
		}

		public void UpdatePVPKillQuestProgress(DeathEventListenerSystem __instance, NativeArray<DeathEvent> deathEvents)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0034: 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_0046: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//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)
			EntityManager entityManager = VWorld.Server.EntityManager;
			Enumerator<DeathEvent> enumerator = deathEvents.GetEnumerator();
			while (enumerator.MoveNext())
			{
				DeathEvent current = enumerator.Current;
				if (!((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(current.Died) || !((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(current.Killer))
				{
					continue;
				}
				PlayerCharacter componentData = ((EntityManager)(ref entityManager)).GetComponentData<PlayerCharacter>(current.Killer);
				User componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<User>(componentData.UserEntity);
				UserModel userByCharacterName = GameData.Users.GetUserByCharacterName(((object)(FixedString64Bytes)(ref componentData2.CharacterName)).ToString());
				if (!CrimsonCore.PlayerData.GetProgressForUser(userByCharacterName, out var progress))
				{
					continue;
				}
				if (progress.WeeklyQuests.Count != 0)
				{
					for (int i = 0; i <= progress.WeeklyQuests.Count; i++)
					{
						if (progress.WeeklyQuests[i].QuestInProgress.Target.Type == QuestTargetType.PlayerKill)
						{
							QuestSlot questSlot = progress.WeeklyQuests[i];
							questSlot.IncrementProgress();
							progress.WeeklyQuests[i] = questSlot;
							CheckProgress(progress.WeeklyQuests[i], userByCharacterName);
						}
					}
				}
				if (progress.DailyQuests.Count != 0)
				{
					for (int j = 0; j <= progress.DailyQuests.Count; j++)
					{
						if (progress.DailyQuests[j].QuestInProgress.Target.Type == QuestTargetType.PlayerKill)
						{
							QuestSlot questSlot2 = progress.DailyQuests[j];
							questSlot2.IncrementProgress();
							progress.DailyQuests[j] = questSlot2;
							CheckProgress(progress.DailyQuests[j], userByCharacterName);
						}
					}
				}
				CrimsonCore.PlayerData.UpdatePlayer(userByCharacterName, progress);
			}
		}

		private void CheckProgress(QuestSlot slot, UserModel player)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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)
			if (slot.CheckForCompletion(out var current, out var goal))
			{
				ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(((EntityModel)player).Entity), $"You have completed the quest <color=#ffc905>{slot.QuestInProgress.Name}</color>. Return to <color=#ffc905>{slot.QuestGiverName}</color>!");
			}
			else
			{
				ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(((EntityModel)player).Entity), $"<color=#ffc905>{slot.QuestInProgress.Name}</color> Progress: <color=#ffc905>{current}/{goal}</color>!");
			}
		}
	}
}
namespace CrimsonQuest.Structs
{
	public struct QuestArea
	{
		public float3 Center { get; set; }

		public float Radius { get; set; }

		public QuestArea(float3 _center, float _radius)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Center = _center;
			Radius = _radius;
		}

		public static QuestArea FromPos(float3 pos, float radius)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return new QuestArea(pos, radius);
		}

		public readonly bool InQuestArea(float3 pos)
		{
			//IL_0000: 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_0012: 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)
			float num = pos.x - Center.x;
			float num2 = pos.z - Center.z;
			return num * num + num2 * num2 <= Radius * Radius;
		}

		public readonly bool InQuestArea(Entity entity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			LocalToWorld val = ECSExtensions.Read<LocalToWorld>(entity);
			return InQuestArea(((LocalToWorld)(ref val)).Position);
		}
	}
	public readonly struct Settings
	{
		private readonly ConfigFile CONFIG;

		private readonly ConfigEntry<bool> ENABLE_MOD;

		public readonly ConfigEntry<int> MAX_DAILY;

		public readonly ConfigEntry<int> MAX_WEEKLY;

		public readonly ConfigEntry<int> ACTIVE_DAILY;

		public readonly ConfigEntry<int> ACTIVE_WEEKLY;

		public readonly ConfigEntry<int> DAY_OF_RESET;

		public readonly ConfigEntry<int> TIME_OF_RESET;

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

		public Settings(ConfigFile config)
		{
			CONFIG = config;
			ENABLE_MOD = CONFIG.Bind<bool>("Config", "EnableMod", true, "Enable or disable quest system");
			MAX_DAILY = CONFIG.Bind<int>("Config", "MaxDailies", 5, "The max amount of daily quests a player can complete in one day");
			MAX_WEEKLY = CONFIG.Bind<int>("Config", "MaxWeeklies", 3, "The max amount of weekly quests a player can complete in a week");
			ACTIVE_DAILY = CONFIG.Bind<int>("Config", "ActiveDaily", 3, "The amount of active/in-progress dailies quests the player can have at once");
			ACTIVE_WEEKLY = CONFIG.Bind<int>("Config", "ActiveWeekly", 3, "The amount of active/in-progress weekly quests the player can have at once");
			DAY_OF_RESET = CONFIG.Bind<int>("Config", "ResetDay", 1, "The day weeklies reset, 0 - Sunday, 1 - Monday, and so on.");
			TIME_OF_RESET = CONFIG.Bind<int>("Config", "ResetTime", 0, "The hour on which Daily & Weekly resets in 24-hour time (0-23)");
		}

		public void InitConfig()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			WriteConfig();
			ManualLogSource logInstance = Plugin.LogInstance;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(13, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Mod enabled: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(ENABLE_MOD.Value);
			}
			logInstance.LogInfo(val);
		}

		public void WriteConfig()
		{
			if (!Directory.Exists(CONFIG_PATH))
			{
				Directory.CreateDirectory(CONFIG_PATH);
			}
		}

		public bool GetActiveSystem(Systems type)
		{
			if (type == Systems.ENABLE)
			{
				return ENABLE_MOD.Value;
			}
			return false;
		}
	}
	public enum Systems
	{
		ENABLE
	}
}
namespace CrimsonQuest.Hooks
{
	[HarmonyPatch]
	public class ActionSchedulerPatch
	{
		public static int CurrentFrameCount = 0;

		public static ConcurrentQueue<Action> actionsToExecuteOnMainThread = new ConcurrentQueue<Action>();

		public static List<Timer> activeTimers;

		[HarmonyPatch(typeof(RandomizedSpawnChainUpdateSystem), "OnUpdate")]
		[HarmonyPostfix]
		public static void Postfix()
		{
			CurrentFrameCount++;
			Action result;
			while (actionsToExecuteOnMainThread.TryDequeue(out result))
			{
				result?.Invoke();
			}
		}

		public static Timer RunActionEveryInterval(Action action, double intervalInSeconds)
		{
			return new Timer(delegate
			{
				actionsToExecuteOnMainThread.Enqueue(action);
			}, null, TimeSpan.FromSeconds(intervalInSeconds), TimeSpan.FromSeconds(intervalInSeconds));
		}

		public static Timer RunActionOnceAfterDelay(Action action, double delayInSeconds)
		{
			Timer timer = null;
			timer = new Timer(delegate
			{
				actionsToExecuteOnMainThread.Enqueue(delegate
				{
					action();
					timer?.Dispose();
				});
			}, null, TimeSpan.FromSeconds(delayInSeconds), Timeout.InfiniteTimeSpan);
			return timer;
		}

		public static Timer RunActionOnceAfterFrames(Action action, int frameDelay)
		{
			int startFrame = CurrentFrameCount;
			Timer timer = null;
			timer = new Timer(delegate
			{
				if (CurrentFrameCount - startFrame >= frameDelay)
				{
					actionsToExecuteOnMainThread.Enqueue(delegate
					{
						action();
					});
					timer?.Dispose();
				}
			}, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(8.0));
			return timer;
		}

		public static Timer RunActionAtTime(Action action, DateTime scheduledTime)
		{
			DateTime now = DateTime.Now;
			TimeSpan timeSpan = scheduledTime - now;
			if (timeSpan.TotalMilliseconds < 0.0)
			{
				return null;
			}
			return RunActionOnceAfterDelay(action, timeSpan.TotalSeconds);
		}

		public static void RunActionOnMainThread(Action action)
		{
			actionsToExecuteOnMainThread.Enqueue(delegate
			{
				action();
			});
		}
	}
	[HarmonyPatch]
	internal class QuestHooks
	{
		[HarmonyPatch(typeof(OnKillSystem), "OnUpdate")]
		[HarmonyPrefix]
		public static void OnUpdate_KillMobs(OnKillSystem __instance)
		{
			//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_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_0025: 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_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_0046: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00b6: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Settings.GetActiveSystem(Systems.ENABLE))
			{
				return;
			}
			EntityQuery _query_1438746367_ = __instance.__query_1438746367_0;
			Enumerator<Entity> enumerator = ((EntityQuery)(ref _query_1438746367_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
			PlayerCharacter val2 = default(PlayerCharacter);
			while (enumerator.MoveNext())
			{
				DeathEvent val = ECSExtensions.Read<DeathEvent>(enumerator.Current);
				EntityManager entityManager = VWorld.Server.EntityManager;
				if (((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(val.Died))
				{
					continue;
				}
				entityManager = VWorld.Server.EntityManager;
				if (!((EntityManager)(ref entityManager)).HasComponent<PrefabGUID>(val.Died))
				{
					continue;
				}
				entityManager = VWorld.Server.EntityManager;
				if (!((EntityManager)(ref entityManager)).HasComponent<VBloodUnit>(val.Died))
				{
					entityManager = VWorld.Server.EntityManager;
					if (((EntityManager)(ref entityManager)).TryGetComponentData<PlayerCharacter>(val.Killer, ref val2))
					{
						PrefabGUID mob = ECSExtensions.Read<PrefabGUID>(val.Died);
						UserModel player = GameData.Users.FromEntity(val2.UserEntity);
						CrimsonCore.PlayerData.GetProgressForUser(player, out var progress);
						CrimsonCore.Quest.UpdateMobQuestProgress(player, progress, mob);
					}
				}
			}
		}
	}
	internal class ResetScheduler
	{
		public static Action action;

		public static DateTime lastDateMinute = DateTime.Now;

		private static DayOfWeek DayOfWeekly;

		private static int TargetHour;

		private static void CheckResets()
		{
			DateTime now = DateTime.Now;
			if (now.Hour == TargetHour && now.Minute == 0)
			{
				if (now.DayOfWeek != DayOfWeekly)
				{
					CrimsonCore.PlayerData.Reset();
				}
				else
				{
					CrimsonCore.PlayerData.Reset(weekly: true);
				}
			}
		}

		public static void StartTimer()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			switch (Plugin.Settings.DAY_OF_RESET.Value)
			{
			case 0:
				DayOfWeekly = DayOfWeek.Sunday;
				break;
			case 1:
				DayOfWeekly = DayOfWeek.Monday;
				break;
			case 2:
				DayOfWeekly = DayOfWeek.Tuesday;
				break;
			case 3:
				DayOfWeekly = DayOfWeek.Wednesday;
				break;
			case 4:
				DayOfWeekly = DayOfWeek.Thursday;
				break;
			case 5:
				DayOfWeekly = DayOfWeek.Friday;
				break;
			case 6:
				DayOfWeekly = DayOfWeek.Saturday;
				break;
			}
			TargetHour = Plugin.Settings.TIME_OF_RESET.Value;
			ManualLogSource logInstance = Plugin.LogInstance;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(70, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Start Reset Timer for CrimsonQuest | Reset Hour: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(TargetHour);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" | Weekly Reset Day: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(DayOfWeekly.ToString());
			}
			logInstance.LogInfo(val);
			action = delegate
			{
				DateTime now = DateTime.Now;
				if (lastDateMinute.ToString("HH:mm") != now.ToString("HH:mm"))
				{
					CheckResets();
				}
				ActionSchedulerPatch.RunActionOnceAfterFrames(action, 60);
			};
			ActionSchedulerPatch.RunActionOnceAfterFrames(action, 60);
		}
	}
}
namespace CrimsonQuest.DB
{
	internal class Database
	{
		public static readonly string ConfigPath = Path.Combine(Paths.ConfigPath, "CrimsonQuest");

		public static string QuestGiverFile = Path.Combine(ConfigPath, "quest_givers.json");

		public static string QuestsFile = Path.Combine(ConfigPath, "quest_list.json");

		public List<QuestGiverModel> QuestGivers { get; set; }

		private List<QuestModel> Quests { get; set; }

		public List<QuestModel> DailyQuests { get; set; }

		public List<QuestModel> WeeklyQuests { get; set; }

		public List<QuestModel> TimedQuests { get; set; }

		public List<QuestModel> StoryQuests { get; set; }

		public List<QuestModel> WorldQuests { get; set; }

		public Database()
		{
			CreateDatabaseFiles();
			LoadDatabase();
		}

		public bool SaveDatabase()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			try
			{
				string contents = JsonSerializer.Serialize(QuestGivers, new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(QuestGiverFile, contents);
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(17, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Save Database: OK");
				}
				logInstance.LogInfo(val);
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance2 = Plugin.LogInstance;
				bool flag2 = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(21, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error Save Database: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				logInstance2.LogError(val2);
				return false;
			}
		}

		public bool LoadDatabase()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			try
			{
				string json = File.ReadAllText(QuestGiverFile);
				QuestGivers = JsonSerializer.Deserialize<List<QuestGiverModel>>(json);
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Load Quest Giver Database: OK");
				}
				logInstance.LogInfo(val);
				string json2 = File.ReadAllText(QuestsFile);
				Quests = JsonSerializer.Deserialize<List<QuestModel>>(json2);
				ManualLogSource logInstance2 = Plugin.LogInstance;
				val = new BepInExInfoLogInterpolatedStringHandler(24, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Load Quests Database: OK");
				}
				logInstance2.LogInfo(val);
				WeeklyQuests = Quests.Where((QuestModel x) => x.Type == QuestType.WEEKLY).ToList();
				DailyQuests = Quests.Where((QuestModel x) => x.Type == QuestType.DAILY).ToList();
				TimedQuests = Quests.Where((QuestModel x) => x.Type == QuestType.TIMED).ToList();
				StoryQuests = Quests.Where((QuestModel x) => x.Type == QuestType.STORY).ToList();
				WorldQuests = Quests.Where((QuestModel x) => x.Type == QuestType.WORLD).ToList();
				ManualLogSource logInstance3 = Plugin.LogInstance;
				val = new BepInExInfoLogInterpolatedStringHandler(39, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded Quests into Category Buckets: OK");
				}
				logInstance3.LogInfo(val);
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance4 = Plugin.LogInstance;
				bool flag2 = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(21, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error Load Database: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				logInstance4.LogError(val2);
				return false;
			}
		}

		public bool CreateDatabaseFiles()
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			if (!Directory.Exists(ConfigPath))
			{
				Directory.CreateDirectory(ConfigPath);
			}
			if (!File.Exists(QuestGiverFile))
			{
				File.WriteAllText(QuestGiverFile, "[]");
			}
			if (!File.Exists(QuestsFile))
			{
				List<QuestModel> list = new List<QuestModel>();
				QuestModel item = new QuestModel(1, "Example Quest", "Kill 5 Forest Wolves", QuestType.DAILY, new QuestTarget(QuestTargetType.MobKill, -1418430647, 5), new Tuple<int, int>(1, 100), new List<Reward>
				{
					new Reward(-1169471531, 1)
				});
				list.Add(item);
				string contents = JsonSerializer.Serialize(list, new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(QuestsFile, contents);
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(25, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Create Quest Database: OK");
				}
				logInstance.LogInfo(val);
			}
			return true;
		}

		public bool GetQuestGiver(string giverName, out QuestGiverModel giver)
		{
			giver = QuestGivers.FirstOrDefault((QuestGiverModel x) => x.Name == giverName);
			if (giver == null)
			{
				return false;
			}
			return true;
		}

		public bool AddQuestGiver(string giverName, int giverGUID, QuestType type, bool immortal, bool canMove, bool autoRespawn)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			if (GetQuestGiver(giverName, out var giver))
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Quest Giver with the name (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(giverName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") already exists.");
				}
				logInstance.LogWarning(val);
				return false;
			}
			giver = new QuestGiverModel();
			giver.Name = giverName;
			giver.PrefabGUID = giverGUID;
			giver.QuestType = type;
			giver.config.Immortal = immortal;
			giver.config.CanMove = canMove;
			giver.config.AutoRespawn = autoRespawn;
			QuestGivers.Add(giver);
			SaveDatabase();
			return true;
		}

		public bool UpdateGiver(QuestGiverModel model)
		{
			if (GetQuestGiver(model.Name, out var giver))
			{
				giver = model;
				SaveDatabase();
				return true;
			}
			return false;
		}

		public bool RemoveGiver(string giverName)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val;
			if (GetQuestGiver(giverName, out var giver))
			{
				if (giver.config.IsEnabled)
				{
					ManualLogSource logInstance = Plugin.LogInstance;
					val = new BepInExWarningLogInterpolatedStringHandler(46, 0, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Please disable giver before attempting removal");
					}
					logInstance.LogWarning(val);
					return false;
				}
				QuestGivers.Remove(giver);
				SaveDatabase();
				return true;
			}
			ManualLogSource logInstance2 = Plugin.LogInstance;
			val = new BepInExWarningLogInterpolatedStringHandler(38, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Unable to find quest giver with name: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(giverName);
			}
			logInstance2.LogWarning(val);
			return false;
		}

		public bool GetQuest(int questID, out QuestModel quest)
		{
			if (Quests.Exists((QuestModel x) => x.ID == questID))
			{
				quest = Quests.FirstOrDefault((QuestModel x) => x.ID == questID);
				return true;
			}
			quest = null;
			return false;
		}
	}
	internal class PlayerDatabase
	{
		public static readonly string ConfigPath = Path.Combine(Paths.ConfigPath, "CrimsonQuest");

		public static string QuestTrackerFile = Path.Combine(ConfigPath, "quest_tracker.json");

		public List<QuestProgressModel> PlayerProgress { get; set; }

		public PlayerDatabase()
		{
			CreateDatabaseFiles();
			LoadDatabase();
		}

		public bool SaveDatabase()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			try
			{
				string contents = JsonSerializer.Serialize(PlayerProgress, new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(QuestTrackerFile, contents);
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(25, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Save Tracker Database: OK");
				}
				logInstance.LogInfo(val);
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance2 = Plugin.LogInstance;
				bool flag2 = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error Save Tracker Database: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				logInstance2.LogError(val2);
				return false;
			}
		}

		public bool LoadDatabase()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			try
			{
				string json = File.ReadAllText(QuestTrackerFile);
				PlayerProgress = JsonSerializer.Deserialize<List<QuestProgressModel>>(json);
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(25, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Load Tracker Database: OK");
				}
				logInstance.LogInfo(val);
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance2 = Plugin.LogInstance;
				bool flag2 = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error Load Tracker Database: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				logInstance2.LogError(val2);
				return false;
			}
		}

		public bool CreateDatabaseFiles()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			if (!Directory.Exists(ConfigPath))
			{
				Directory.CreateDirectory(ConfigPath);
			}
			if (!File.Exists(QuestTrackerFile))
			{
				File.WriteAllText(QuestTrackerFile, "[]");
			}
			ManualLogSource logInstance = Plugin.LogInstance;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Create Tracker Database: OK");
			}
			logInstance.LogInfo(val);
			return true;
		}

		public bool GetProgressForUser(UserModel player, out QuestProgressModel progress)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			ManualLogSource logInstance = Plugin.LogInstance;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(26, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Searching for ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(player.CharacterName);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'s progress.");
			}
			logInstance.LogInfo(val);
			if (PlayerProgress.Exists((QuestProgressModel x) => x.character == player.CharacterName))
			{
				progress = PlayerProgress.FirstOrDefault((QuestProgressModel x) => x.character == player.CharacterName);
				return true;
			}
			progress = new QuestProgressModel(player.CharacterName);
			PlayerProgress.Add(progress);
			SaveDatabase();
			return false;
		}

		public void UpdatePlayer(UserModel player, QuestProgressModel progress)
		{
			if (GetProgressForUser(player, out var _))
			{
				progress.CompletedWeekly += progress.WeeklyQuests.Where((QuestSlot x) => x.isCompleted).Count();
				progress.CompletedDaily += progress.DailyQuests.Where((QuestSlot x) => x.isCompleted).Count();
				progress.WeeklyQuests = progress.WeeklyQuests.Where((QuestSlot x) => !x.isCompleted).ToList();
				progress.DailyQuests = progress.DailyQuests.Where((QuestSlot x) => !x.isCompleted).ToList();
				if (progress.StoryQuest.isCompleted)
				{
					progress.CompletedStories.Add(progress.StoryQuest.QuestInProgress.ID);
					progress.StoryQuest = null;
				}
				SaveDatabase();
			}
		}

		public void Reset(bool weekly = false)
		{
			foreach (QuestProgressModel item in PlayerProgress)
			{
				item.CompletedDaily = 0;
				if (weekly)
				{
					item.CompletedWeekly = 0;
				}
			}
		}
	}
}
namespace CrimsonQuest.DB.Models
{
	internal class ConfigQuestGiverModel
	{
		public bool IsEnabled { get; set; }

		public float X { get; set; }

		public float Z { get; set; }

		public bool Immortal { get; set; }

		public bool CanMove { get; set; }

		public bool AutoRespawn { get; set; }
	}
	internal class QuestGiverModel
	{
		private Entity icontEntity;

		public string Name { get; set; } = string.Empty;


		public int PrefabGUID { get; set; }

		public List<int> QuestsToGive { get; set; } = new List<int>();


		public QuestType QuestType { get; set; }

		public Entity giverEntity { get; set; }

		public ConfigQuestGiverModel config { get; set; } = new ConfigQuestGiverModel();


		public bool SpawnWithLocation(Entity sender, float3 pos)
		{
			//IL_000e: 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_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_001c: 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_0042: 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)
			SpawnSystem.SpawnUnitWithCallback(sender, new PrefabGUID(PrefabGUID), new float2(pos.x, pos.z), -1f, (Action<Entity>)delegate(Entity e)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//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)
				giverEntity = e;
				config.X = pos.x;
				config.Z = pos.z;
				config.IsEnabled = true;
				ModifyGiver(sender, e);
			});
			AddIcon(giverEntity);
			return true;
		}

		public bool AddQuest(int id)
		{
			if (CrimsonCore.QuestData.GetQuest(id, out var quest))
			{
				if (quest == null)
				{
					return false;
				}
				if (quest.Type == QuestType)
				{
					QuestsToGive.Add(id);
					return true;
				}
			}
			return false;
		}

		public void ModifyGiver(Entity user, Entity giver)
		{
			//IL_000e: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			bool flag2 = default(bool);
			if (config.Immortal)
			{
				bool flag = MakeNPCImmortal(user, giver);
				ManualLogSource logInstance = Plugin.LogInstance;
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(14, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NPC Immortal: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(flag);
				}
				logInstance.LogDebug(val);
			}
			if (!config.CanMove)
			{
				bool flag3 = MakeNPCNotMove(user, giver);
				ManualLogSource logInstance2 = Plugin.LogInstance;
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(13, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NPC Not Move ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(flag3);
				}
				logInstance2.LogDebug(val);
			}
			RenameGiver(giver, Name);
		}

		private void RenameGiver(Entity giver, string newName)
		{
			//IL_0000: 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_000f: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//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_0023: 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)
			if (!ECSExtensions.Has<NameableInteractable>(giver))
			{
				ECSExtensions.Add<NameableInteractable>(giver);
			}
			NameableInteractable val = ECSExtensions.Read<NameableInteractable>(giver);
			val.Name = new FixedString64Bytes(newName);
			ECSExtensions.Write<NameableInteractable>(giver, val);
			CrimsonCore.QuestData.UpdateGiver(this);
		}

		public bool MakeNPCNotMove(Entity user, Entity giver)
		{
			//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_0012: 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_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_0025: 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_002e: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0051: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			PrefabGUID buff_BloodQuality_T01_OLD = Prefabs.Buff_BloodQuality_T01_OLD;
			DebugEventsSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<DebugEventsSystem>();
			ApplyBuffDebugEvent val = new ApplyBuffDebugEvent
			{
				BuffPrefabGUID = buff_BloodQuality_T01_OLD
			};
			FromCharacter val2 = new FromCharacter
			{
				User = user,
				Character = giver
			};
			existingSystemManaged.ApplyBuff(val2, val);
			Entity val3 = default(Entity);
			if (BuffUtility.TryGetBuff(VWorld.Server.EntityManager, giver, PrefabIdentifier.op_Implicit(buff_BloodQuality_T01_OLD), ref val3))
			{
				if (!ECSExtensions.Has<BuffModificationFlagData>(val3))
				{
					ECSExtensions.Add<BuffModificationFlagData>(val3);
				}
				BuffModificationFlagData val4 = ECSExtensions.Read<BuffModificationFlagData>(val3);
				val4.ModificationTypes = 16L;
				ECSExtensions.Write<BuffModificationFlagData>(val3, val4);
				return true;
			}
			return false;
		}

		public bool MakeNPCImmortal(Entity user, Entity giver)
		{
			//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_0012: 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_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_0025: 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_002e: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0051: 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_0065: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			PrefabGUID buff_Manticore_ImmaterialHomePos = Prefabs.Buff_Manticore_ImmaterialHomePos;
			DebugEventsSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<DebugEventsSystem>();
			ApplyBuffDebugEvent val = new ApplyBuffDebugEvent
			{
				BuffPrefabGUID = buff_Manticore_ImmaterialHomePos
			};
			FromCharacter val2 = new FromCharacter
			{
				User = user,
				Character = giver
			};
			existingSystemManaged.ApplyBuff(val2, val);
			Entity val3 = default(Entity);
			if (BuffUtility.TryGetBuff(VWorld.Server.EntityManager, giver, PrefabIdentifier.op_Implicit(buff_Manticore_ImmaterialHomePos), ref val3))
			{
				ECSExtensions.Add<Buff_Persists_Through_Death>(val3);
				if (ECSExtensions.Has<LifeTime>(val3))
				{
					LifeTime val4 = ECSExtensions.Read<LifeTime>(val3);
					val4.Duration = -1f;
					val4.EndAction = (LifeTimeEndAction)0;
					ECSExtensions.Write<LifeTime>(val3, val4);
				}
				if (ECSExtensions.Has<RemoveBuffOnGameplayEvent>(val3))
				{
					ECSExtensions.Remove<RemoveBuffOnGameplayEvent>(val3);
				}
				if (ECSExtensions.Has<RemoveBuffOnGameplayEventEntry>(val3))
				{
					ECSExtensions.Remove<RemoveBuffOnGameplayEventEntry>(val3);
				}
				return true;
			}
			return false;
		}

		public float3 GetPosition()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return new float3(config.X, 0f, config.Z);
		}

		public void AddIcon(Entity giver)
		{
			//IL_000e: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			SpawnSystem.SpawnUnitWithCallback(giver, Prefabs.MapIcon_POI_Discover_Merchant, new float2(config.X, config.Z), -1f, (Action<Entity>)delegate(Entity e)
			{
				//IL_0006: 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_0012: 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_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_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_002c: 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_003e: 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_0044: 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_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: 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)
				icontEntity = e;
				ECSExtensions.Add<MapIconData>(e);
				ECSExtensions.Add<MapIconTargetEntity>(e);
				MapIconTargetEntity val = ECSExtensions.Read<MapIconTargetEntity>(e);
				val.TargetEntity = NetworkedEntity.ServerEntity(giver);
				val.TargetNetworkId = ECSExtensions.Read<NetworkId>(giver);
				ECSExtensions.Write<MapIconTargetEntity>(e, val);
				ECSExtensions.Add<NameableInteractable>(e);
				NameableInteractable val2 = ECSExtensions.Read<NameableInteractable>(e);
				val2.Name = new FixedString64Bytes(Name + "_icon");
				ECSExtensions.Write<NameableInteractable>(e, val2);
			});
		}

		private bool GetIcon(string nameMerchant)
		{
			//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_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_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_001a: 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)
			//IL_0020: 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)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> entitiesByComponentTypes = QueryComponents.GetEntitiesByComponentTypes<NameableInteractable, MapIconData>((EntityQueryOptions)2, false);
			Enumerator<Entity> enumerator = entitiesByComponentTypes.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				NameableInteractable val = ECSExtensions.Read<NameableInteractable>(current);
				if (((FixedString64Bytes)(ref val.Name)).Value == nameMerchant + "_icon")
				{
					icontEntity = current;
					entitiesByComponentTypes.Dispose();
					return true;
				}
			}
			entitiesByComponentTypes.Dispose();
			return false;
		}

		public bool GetEntity(string nameGiver)
		{
			//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_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_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_001a: 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)
			//IL_0020: 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)
			NativeArray<Entity> entitiesByComponentTypes = QueryComponents.GetEntitiesByComponentTypes<NameableInteractable, TradeCost>((EntityQueryOptions)2, false);
			Enumerator<Entity> enumerator = entitiesByComponentTypes.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				NameableInteractable val = ECSExtensions.Read<NameableInteractable>(current);
				if (((FixedString64Bytes)(ref val.Name)).Value == nameGiver)
				{
					giverEntity = current;
					entitiesByComponentTypes.Dispose();
					return true;
				}
			}
			entitiesByComponentTypes.Dispose();
			return false;
		}

		public bool GetRandomQuest(UserModel user, QuestProgressModel progress, out QuestModel quest)
		{
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			quest = null;
			List<QuestModel> source = new List<QuestModel>();
			List<int> InProgressQuests = new List<int>();
			foreach (QuestSlot item in progress.DailyQuests.Concat(progress.WeeklyQuests))
			{
				InProgressQuests.Add(item.QuestInProgress.ID);
			}
			switch (QuestType)
			{
			case QuestType.DAILY:
				source = CrimsonCore.QuestData.DailyQuests.Where((QuestModel x) => x.Type == QuestType.DAILY).ToList();
				break;
			case QuestType.WEEKLY:
				source = CrimsonCore.QuestData.WeeklyQuests.Where((QuestModel x) => x.Type == QuestType.WEEKLY).ToList();
				break;
			}
			source = source.Where((QuestModel x) => !InProgressQuests.Contains(x.ID)).ToList();
			source = source.Where((QuestModel x) => (float)x.MinMaxLevel.Item1 <= user.Equipment.Level).ToList();
			source = source.Where((QuestModel x) => user.Equipment.Level <= (float)x.MinMaxLevel.Item2).ToList();
			if (source.Count == 0)
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(63, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(user.CharacterName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" requested quest of type ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(QuestType.ToString());
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" with item level ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(user.Equipment.Level);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" and found 0 results.");
				}
				logInstance.LogDebug(val);
				return false;
			}
			quest = source[Random.Range(0, source.Count)];
			return true;
		}
	}
	public class QuestModel
	{
		public int ID { get; set; }

		public string Name { get; set; }

		public string Description { get; set; }

		public QuestType Type { get; set; }

		public QuestTarget Target { get; set; }

		public Tuple<int, int> MinMaxLevel { get; set; }

		public List<Reward> Rewards { get; set; }

		public QuestModel(int iD, string name, string description, QuestType type, QuestTarget target, Tuple<int, int> minMaxLevel, List<Reward> rewards)
		{
			ID = iD;
			Name = name;
			Description = description;
			Type = type;
			Target = target;
			MinMaxLevel = minMaxLevel;
			Rewards = rewards;
		}
	}
	public class QuestTarget
	{
		public QuestTargetType Type { get; set; }

		public int GUID { get; set; }

		public int Amount { get; set; }

		public QuestTarget(QuestTargetType type, int guid, int amount)
		{
			Type = type;
			GUID = guid;
			Amount = amount;
		}
	}
	public class Reward
	{
		public int GUID { get; set; }

		public int Quantity { get; set; }

		public Reward(int guid, int quantity)
		{
			GUID = guid;
			Quantity = quantity;
		}
	}
	public enum QuestTargetType
	{
		ItemFetch,
		MobKill,
		PlayerKill,
		VBloodKill
	}
	public enum QuestType
	{
		DAILY,
		WEEKLY,
		TIMED,
		WORLD,
		STORY
	}
	internal class QuestProgressModel
	{
		public int CompletedDaily;

		public int CompletedWeekly;

		public string character { get; set; } = string.Empty;


		public List<QuestSlot> WeeklyQuests { get; set; } = new List<QuestSlot>();


		public List<QuestSlot> DailyQuests { get; set; } = new List<QuestSlot>();


		public QuestSlot TimedQuest { get; set; } = new QuestSlot();


		public QuestSlot StoryQuest { get; set; } = new QuestSlot();


		public List<int> CompletedStories { get; set; } = new List<int>();


		[JsonConstructor]
		public QuestProgressModel()
		{
		}

		public QuestProgressModel(string characterName)
		{
			character = characterName;
			WeeklyQuests = new List<QuestSlot>();
			DailyQuests = new List<QuestSlot>();
			TimedQuest = new QuestSlot();
			StoryQuest = new QuestSlot();
			CompletedStories = new List<int>();
		}
	}
	public class QuestSlot
	{
		public QuestModel QuestInProgress { get; set; }

		public int TargetProgress { get; set; }

		public string QuestGiverName { get; set; }

		public bool isCompleted { get; set; }

		[JsonConstructor]
		public QuestSlot()
		{
		}

		public QuestSlot(QuestModel quest, string giverName)
		{
			QuestInProgress = quest;
			TargetProgress = 0;
			QuestGiverName = giverName;
			isCompleted = false;
		}

		public void IncrementProgress()
		{
			TargetProgress++;
		}

		public bool CheckForCompletion(out int current, out int goal)
		{
			current = TargetProgress;
			goal = QuestInProgress.Target.Amount;
			if (current >= goal)
			{
				return true;
			}
			return false;
		}

		public void SetComplete()
		{
			isCompleted = true;
		}
	}
}
namespace CrimsonQuest.Commands
{
	[CommandGroup("crimsonquest", "cq")]
	internal class QuestGiverCommands
	{
		[Command("list", "l", "List of Quest Givers", null, null, true)]
		public void ListQuestGivers(ChatCommandContext ctx)
		{
			string text = "Quest Givers:\n";
			if (CrimsonCore.QuestData.QuestGivers.Count == 0)
			{
				text += "None exist... create some!";
			}
			else
			{
				foreach (QuestGiverModel questGiver in CrimsonCore.QuestData.QuestGivers)
				{
					text += $"{questGiver.Name} has {questGiver.QuestsToGive.Count} {questGiver.QuestType}\n";
				}
			}
			ctx.Reply(text);
		}

		[Command("create", null, "<NameOfNPC> [PrefabGUID] [QuestType] [Immortal] [Move] [AutoRespawn]", "Creates a new Quest Giver", null, true)]
		public void CreateQuestGiver(ChatCommandContext ctx, string npcName, int npcPrefab = -1810631919, QuestType npcType = QuestType.DAILY, bool immortal = false, bool canMove = false, bool autoRespawn = true)
		{
			if (CrimsonCore.QuestData.AddQuestGiver(npcName, npcPrefab, npcType, immortal, canMove, autoRespawn))
			{
				ctx.Reply(npcName + " created successfully");
			}
		}

		[Command("spawn", null, "NameOfNPC", "Spawns a quest giver in your location", null, true)]
		public void Spawn(ChatCommandContext ctx, string giverName)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0028: 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_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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (CrimsonCore.QuestData.GetQuestGiver(giverName, out var giver))
			{
				Entity senderUserEntity = ctx.Event.SenderUserEntity;
				EntityManager entityManager = VWorld.Server.EntityManager;
				LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(senderUserEntity);
				float3 position = ((LocalToWorld)(ref componentData)).Position;
				giver.SpawnWithLocation(senderUserEntity, position);
				ctx.Reply("Quest Giver " + giverName + " has spawned.");
			}
			else
			{
				ctx.Reply("Unable to spawn " + giverName);
			}
		}

		[Command("add", null, "QuestID", "Gives the quest to the Giver's list", null, true)]
		public void AddQuestToGiver(ChatCommandContext ctx, string giverName, int id)
		{
			if (CrimsonCore.QuestData.GetQuestGiver(giverName, out var giver))
			{
				if (giver.AddQuest(id))
				{
					ctx.Reply("Successfully added quest to " + giverName);
					return;
				}
				ctx.Reply($"Failed to find quest with id {id}");
			}
		}
	}
	[CommandGroup("crimsonquest", "cq")]
	internal class QuestsCommands
	{
		[Command("dailies", "daily", null, "Shows your current Daily Quests", null, false)]
		public void ListDailyQuests(ChatCommandContext ctx)
		{
			//IL_0006: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			Entity senderUserEntity = ctx.Event.SenderUserEntity;
			UserModel player = GameData.Users.FromEntity(senderUserEntity);
			string text = "Active Daily Quests:\n";
			if (!CrimsonCore.PlayerData.GetProgressForUser(player, out var progress))
			{
				return;
			}
			if (progress.DailyQuests.Count == 0 || progress.DailyQuests == null)
			{
				text += "None";
			}
			else
			{
				foreach (QuestSlot dailyQuest in progress.DailyQuests)
				{
					text = text + dailyQuest.QuestInProgress.Description + "\n";
				}
			}
			ctx.Reply(text);
		}

		[Command("weeklies", "weekly", null, "Shows your current Weekly Quests", null, false)]
		public void ListWeeklyQuests(ChatCommandContext ctx)
		{
			//IL_0006: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			Entity senderUserEntity = ctx.Event.SenderUserEntity;
			UserModel player = GameData.Users.FromEntity(senderUserEntity);
			string text = "Active Weekly Quests:\n";
			if (!CrimsonCore.PlayerData.GetProgressForUser(player, out var progress))
			{
				return;
			}
			if (progress.WeeklyQuests.Count == 0 || progress.WeeklyQuests == null)
			{
				text += "None";
			}
			else
			{
				foreach (QuestSlot weeklyQuest in progress.WeeklyQuests)
				{
					text = text + weeklyQuest.QuestInProgress.Description + "\n";
				}
			}
			ctx.Reply(text);
		}

		[Command("get", "accept", null, "Accepts a quest from the closest giver", null, false)]
		public void GetQuest(ChatCommandContext ctx)
		{
			//IL_0006: 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_0011: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			Entity senderUserEntity = ctx.Event.SenderUserEntity;
			UserModel val = GameData.Users.FromEntity(senderUserEntity);
			bool flag = default(bool);
			foreach (QuestGiverModel questGiver in CrimsonCore.QuestData.QuestGivers)
			{
				if (!QuestArea.FromPos(questGiver.GetPosition(), 5f).InQuestArea(val.Character.Entity))
				{
					ManualLogSource logInstance = Plugin.LogInstance;
					BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(21, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.CharacterName);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is not within 5m of ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(questGiver.Name);
					}
					logInstance.LogDebug(val2);
				}
				else
				{
					CrimsonCore.PlayerData.GetProgressForUser(val, out var progress);
					CrimsonCore.Quest.GetQuest(val, progress, questGiver);
				}
			}
		}

		[Command("complete", null, null, "Turns in a completed quest to the nearest giver", null, false)]
		public void GiveQuest(ChatCommandContext ctx)
		{
			//IL_0006: 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_0011: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			Entity senderUserEntity = ctx.Event.SenderUserEntity;
			UserModel val = GameData.Users.FromEntity(senderUserEntity);
			bool flag = default(bool);
			foreach (QuestGiverModel questGiver in CrimsonCore.QuestData.QuestGivers)
			{
				if (!QuestArea.FromPos(questGiver.GetPosition(), 5f).InQuestArea(val.Character.Entity))
				{
					ManualLogSource logInstance = Plugin.LogInstance;
					BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(21, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.CharacterName);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is not within 5m of ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(questGiver.Name);
					}
					logInstance.LogDebug(val2);
				}
				else
				{
					CrimsonCore.PlayerData.GetProgressForUser(val, out var progress);
					CrimsonCore.Quest.CompleteGiverQuests(val, progress, questGiver);
				}
			}
		}
	}
}