Decompiled source of VRisingDiscordBotCompanion v0.6.3

v-rising-discord-bot-companion.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
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 HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.IO;
using Il2CppSystem.Net;
using Il2CppSystem.Security.Claims;
using Il2CppSystem.Security.Principal;
using Il2CppSystem.Text.RegularExpressions;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
using v_rising_discord_bot_companion.activity;
using v_rising_discord_bot_companion.character;
using v_rising_discord_bot_companion.game;
using v_rising_discord_bot_companion.killfeed;
using v_rising_discord_bot_companion.query;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("v-rising-discord-bot-companion")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A companion mod for DarkAtra/v-rising-discord-bot.")]
[assembly: AssemblyFileVersion("0.6.3.0")]
[assembly: AssemblyInformationalVersion("0.6.3+42b2e57dc12d9238a5a24171f338ceda46beba89")]
[assembly: AssemblyProduct("v-rising-discord-bot-companion")]
[assembly: AssemblyTitle("v-rising-discord-bot-companion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.3.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]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[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;
		}
	}
	[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 v_rising_discord_bot_companion
{
	public static class ListUtils
	{
		public static List<T> Convert<T>(DynamicBuffer<T> buffer) where T : unmanaged
		{
			//IL_0008: 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)
			List<T> list = new List<T>();
			Enumerator<T> enumerator = buffer.GetEnumerator();
			while (enumerator.MoveNext())
			{
				T current = enumerator.Current;
				list.Add(current);
			}
			return list;
		}

		public static List<T> Convert<T>(NativeArray<T> array) where T : unmanaged
		{
			//IL_0008: 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)
			List<T> list = new List<T>();
			Enumerator<T> enumerator = array.GetEnumerator();
			while (enumerator.MoveNext())
			{
				T current = enumerator.Current;
				list.Add(current);
			}
			return list;
		}
	}
	[BepInPlugin("v-rising-discord-bot-companion", "v-rising-discord-bot-companion", "0.6.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[Reloadable]
	public class Plugin : BasePlugin
	{
		private Harmony? _harmony;

		private Component? _queryDispatcher;

		private PluginConfig? _pluginConfig;

		private ConfigEntry<string> _basicAuthUsers;

		public static ManualLogSource Logger { get; private set; }

		public static Plugin Instance { get; private set; }

		public Plugin()
		{
			Instance = this;
			Logger = ((BasePlugin)this).Log;
			_basicAuthUsers = ((BasePlugin)this).Config.Bind<string>("Authentication", "BasicAuthUsers", "", "A list of comma separated username:password entries that are allowed to query the HTTP API.");
		}

		public override void Load()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val;
			if (!VWorld.IsServer)
			{
				ManualLogSource log = ((BasePlugin)this).Log;
				val = new BepInExInfoLogInterpolatedStringHandler(45, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("v-rising-discord-bot-companion");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" must be installed on the server side.");
				}
				log.LogInfo(val);
				return;
			}
			ManualLogSource log2 = ((BasePlugin)this).Log;
			val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("v-rising-discord-bot-companion");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.6.3");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log2.LogInfo(val);
			ClassInjector.RegisterTypeInIl2Cpp<QueryDispatcher>();
			_queryDispatcher = (Component?)(object)((BasePlugin)this).AddComponent<QueryDispatcher>();
			_harmony = new Harmony("v-rising-discord-bot-companion");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		public override bool Unload()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			if ((Object)(object)_queryDispatcher != (Object)null)
			{
				Object.Destroy((Object)(object)_queryDispatcher);
			}
			_pluginConfig = null;
			return true;
		}

		public PluginConfig GetPluginConfig()
		{
			PluginConfig valueOrDefault = _pluginConfig.GetValueOrDefault();
			if (!_pluginConfig.HasValue)
			{
				valueOrDefault = ParsePluginConfig();
				_pluginConfig = valueOrDefault;
			}
			return _pluginConfig.Value;
		}

		private PluginConfig ParsePluginConfig()
		{
			List<BasicAuthUser> list = new List<BasicAuthUser>();
			string[] array = _basicAuthUsers.Value.Split(",");
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(":", 2);
				if (array2.Length == 2)
				{
					list.Add(new BasicAuthUser(array2[0].Trim(), array2[1].Trim()));
				}
			}
			return new PluginConfig(list);
		}
	}
	public readonly record struct PluginConfig(List<BasicAuthUser> BasicAuthUsers);
	public readonly record struct BasicAuthUser(string Username, string Password);
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "v-rising-discord-bot-companion";

		public const string PLUGIN_NAME = "v-rising-discord-bot-companion";

		public const string PLUGIN_VERSION = "0.6.3";
	}
}
namespace v_rising_discord_bot_companion.query
{
	public class AsyncQuery<T> : Query
	{
		private readonly Func<T> _action;

		public Status Status { get; private set; }

		public T? Data { get; private set; }

		public Exception? Exception { get; private set; }

		public AsyncQuery(Func<T> action)
		{
			Status = Status.PENDING;
			_action = action;
		}

		public void Invoke()
		{
			try
			{
				Data = _action();
				Status = Status.SUCCESSFUL;
			}
			catch (Exception exception)
			{
				Exception = exception;
				Status = Status.FAILED;
			}
		}
	}
	public interface Query
	{
		void Invoke();
	}
	public class QueryDispatcher : MonoBehaviour
	{
		public static QueryDispatcher Instance;

		private readonly Queue<Query> _pendingQueries = new Queue<Query>();

		private void Awake()
		{
			Instance = this;
		}

		private void Update()
		{
			if (_pendingQueries.Count > 0)
			{
				_pendingQueries.Dequeue().Invoke();
			}
		}

		public AsyncQuery<T> Dispatch<T>(Func<T> query)
		{
			AsyncQuery<T> asyncQuery = new AsyncQuery<T>(query);
			_pendingQueries.Enqueue(asyncQuery);
			return asyncQuery;
		}
	}
	public enum Status
	{
		PENDING,
		SUCCESSFUL,
		FAILED
	}
}
namespace v_rising_discord_bot_companion.killfeed
{
	public readonly record struct Player(string Name, int GearLevel);
	public readonly record struct PvpKill(Player Killer, Player Victim, DateTime Occurred);
	[HarmonyPatch(typeof(VampireDownedServerEventSystem))]
	public class VampireDownedServerEventSystemPatches
	{
		private static readonly List<PvpKill> _pvpKills = new List<PvpKill>();

		public static List<PvpKill> getPvpKills()
		{
			removeExpiredPvpKills();
			return _pvpKills;
		}

		private static void removeExpiredPvpKills()
		{
			_pvpKills.RemoveAll((PvpKill pvpKill) => DateTime.UtcNow > pvpKill.Occurred.AddMinutes(10.0));
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnUpdate")]
		public static void Postfix(VampireDownedServerEventSystem __instance)
		{
			//IL_0001: 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_000d: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			_ = __instance.__query_1174204813_0;
			EntityQuery _query_1174204813_ = __instance.__query_1174204813_0;
			Enumerator<Entity> enumerator = ((EntityQuery)(ref _query_1174204813_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
			while (enumerator.MoveNext())
			{
				handleDownedEntity(enumerator.Current);
			}
			removeExpiredPvpKills();
		}

		private static void handleDownedEntity(Entity entity)
		{
			//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_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_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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0091: 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_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)
			Entity val = default(Entity);
			VampireDownedServerEventSystem.TryFindRootOwner(entity, 1, VWorld.Server.EntityManager, ref val);
			EntityManager entityManager = VWorld.Server.EntityManager;
			VampireDownedBuff val2 = default(VampireDownedBuff);
			((EntityManager)(ref entityManager)).TryGetComponentData<VampireDownedBuff>(entity, ref val2);
			Entity val3 = default(Entity);
			VampireDownedServerEventSystem.TryFindRootOwner(val2.Source, 1, VWorld.Server.EntityManager, ref val3);
			entityManager = VWorld.Server.EntityManager;
			if (((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(val3))
			{
				entityManager = VWorld.Server.EntityManager;
				if (((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(val) && !((Entity)(ref val)).Equals(val3))
				{
					VCharacter vCharacter = VCharacter.from(val3);
					VCharacter vCharacter2 = VCharacter.from(val);
					List<PvpKill> pvpKills = _pvpKills;
					PlayerCharacter character = vCharacter.Character;
					Player killer = new Player(((object)(FixedString64Bytes)(ref character.Name)).ToString(), vCharacter.getGearLevel());
					character = vCharacter2.Character;
					pvpKills.Add(new PvpKill(killer, new Player(((object)(FixedString64Bytes)(ref character.Name)).ToString(), vCharacter2.getGearLevel()), DateTime.UtcNow));
				}
			}
		}
	}
}
namespace v_rising_discord_bot_companion.game
{
	public readonly record struct VCharacter(PlayerCharacter Character, Entity CharacterEntity)
	{
		public static VCharacter from(VUser vUser)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return from(vUser.User.LocalCharacter._Entity);
		}

		public static VCharacter from(Entity characterEntity)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			return new VCharacter(((EntityManager)(ref entityManager)).GetComponentData<PlayerCharacter>(characterEntity), characterEntity);
		}

		public int getGearLevel()
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			Equipment componentData = ((EntityManager)(ref entityManager)).GetComponentData<Equipment>(CharacterEntity);
			return (int)((Equipment)(ref componentData)).GetFullLevel();
		}

		[CompilerGenerated]
		private bool PrintMembers(StringBuilder builder)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			builder.Append("Character = ");
			PlayerCharacter character = Character;
			builder.Append(((object)(PlayerCharacter)(ref character)).ToString());
			builder.Append(", CharacterEntity = ");
			Entity characterEntity = CharacterEntity;
			builder.Append(((object)(Entity)(ref characterEntity)).ToString());
			return true;
		}
	}
	public readonly record struct VPlayer(VUser VUser, VCharacter? VCharacter)
	{
		public static VPlayer from(Entity userEntity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			VUser vUser = VUser.from(userEntity);
			EntityManager entityManager = VWorld.Server.EntityManager;
			if (((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity).LocalCharacter._Entity == Entity.Null)
			{
				return new VPlayer(vUser, null);
			}
			return new VPlayer(vUser, v_rising_discord_bot_companion.game.VCharacter.from(vUser));
		}

		public static List<VPlayer> GetAllPlayers()
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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)
			EntityManager entityManager = VWorld.Server.EntityManager;
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			return ListUtils.Convert<Entity>(((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2))).Select(from).ToList();
		}

		public bool HasCharacter()
		{
			return VCharacter.HasValue;
		}
	}
	public readonly record struct VUser(User User, Entity UserEntity)
	{
		public static VUser from(Entity userEntity)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			return new VUser(((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity), userEntity);
		}

		[CompilerGenerated]
		private bool PrintMembers(StringBuilder builder)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			builder.Append("User = ");
			User user = User;
			builder.Append(((object)(User)(ref user)).ToString());
			builder.Append(", UserEntity = ");
			Entity userEntity = UserEntity;
			builder.Append(((object)(Entity)(ref userEntity)).ToString());
			return true;
		}
	}
}
namespace v_rising_discord_bot_companion.command
{
	[HarmonyPatch(typeof(HttpServiceReceiveThread))]
	public class HttpReceiveServicePatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("IsAllowed")]
		public static bool IsAllowed(HttpListenerContext context, ref bool __result)
		{
			if (Plugin.Instance.GetPluginConfig().BasicAuthUsers.Count <= 0)
			{
				return true;
			}
			BasicAuthUser? basicAuthUser = ParseBasicAuthUser(context);
			if (!basicAuthUser.HasValue)
			{
				__result = false;
				return false;
			}
			__result = IsAuthorized(basicAuthUser.Value);
			return __result;
		}

		private static BasicAuthUser? ParseBasicAuthUser(HttpListenerContext context)
		{
			context.ParseAuthentication((AuthenticationSchemes)8);
			if (context.user == null)
			{
				return null;
			}
			GenericPrincipal obj = ((Il2CppObjectBase)context.user).TryCast<GenericPrincipal>();
			HttpListenerBasicIdentity val = ((obj != null) ? ((Il2CppObjectBase)obj.m_identity).TryCast<HttpListenerBasicIdentity>() : null);
			if (val == null)
			{
				return null;
			}
			string name = ((ClaimsIdentity)val).Name;
			string password = val.password;
			if (name == null || password == null)
			{
				return null;
			}
			return new BasicAuthUser(name, password);
		}

		private static bool IsAuthorized(BasicAuthUser currentBasicAuthUser)
		{
			return Plugin.Instance.GetPluginConfig().BasicAuthUsers.Count((BasicAuthUser it) => it.Username.Equals(currentBasicAuthUser.Username) && it.Password.Equals(currentBasicAuthUser.Password)) == 1;
		}
	}
	public readonly record struct Problem(string Type, string Title);
	[HarmonyPatch(typeof(ServerWebAPISystem))]
	public class ServerWebAPISystemPatches
	{
		private static readonly JsonSerializerOptions _serializeOptions = new JsonSerializerOptions
		{
			DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
			PropertyNamingPolicy = JsonNamingPolicy.CamelCase
		};

		[HarmonyPostfix]
		[HarmonyPatch("OnCreate")]
		public static void OnCreate(ServerWebAPISystem __instance)
		{
			//IL_0041: 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_0021: Expected O, but got Unknown
			//IL_0074: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val;
			if (!SettingsManager.ServerHostSettings.API.Enabled)
			{
				ManualLogSource logger = Plugin.Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(24, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("HTTP API is not enabled.");
				}
				logger.LogInfo(val);
				return;
			}
			__instance._HttpReceiveService.AddRoute(new Route(new Regex("/v-rising-discord-bot/characters"), "GET", BuildAdapter((HttpListenerContext _) => CharacterInfoCommand.GetCharacters())));
			__instance._HttpReceiveService.AddRoute(new Route(new Regex("/v-rising-discord-bot/player-activities"), "GET", BuildAdapter((HttpListenerContext _) => ServerBootstrapSystemPatches.getPlayerActivities())));
			__instance._HttpReceiveService.AddRoute(new Route(new Regex("/v-rising-discord-bot/pvp-kills"), "GET", BuildAdapter((HttpListenerContext _) => VampireDownedServerEventSystemPatches.getPvpKills())));
			ManualLogSource logger2 = Plugin.Logger;
			val = new BepInExInfoLogInterpolatedStringHandler(37, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Added v-rising-discord-bot endpoints.");
			}
			logger2.LogInfo(val);
		}

		private static RequestHandler BuildAdapter(Func<HttpListenerContext, object> commandHandler)
		{
			Func<HttpListenerContext, object> commandHandler2 = commandHandler;
			return DelegateSupport.ConvertDelegate<RequestHandler>((Delegate)(Action<HttpListenerContext>)delegate(HttpListenerContext context)
			{
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Expected O, but got Unknown
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				HttpListenerContext context2 = context;
				AsyncQuery<object> asyncQuery = QueryDispatcher.Instance.Dispatch(() => commandHandler2(context2));
				while (asyncQuery.Status == Status.PENDING)
				{
					Thread.Sleep(25);
				}
				Status status = asyncQuery.Status;
				bool flag = ((status == Status.PENDING || status == Status.FAILED) ? true : false);
				object value;
				if (flag)
				{
					ManualLogSource logger = Plugin.Logger;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(41, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Request with url '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)context2.Request.Url).ToString());
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' failed with message: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(asyncQuery.Exception?.Message);
					}
					logger.LogInfo(val);
					context2.Response.StatusCode = 500;
					value = new Problem("about:blank", "Internal Server Error");
				}
				else
				{
					value = asyncQuery.Data;
				}
				context2.Response.ContentType = "application/json";
				StreamWriter val2 = new StreamWriter(context2.Response.OutputStream);
				((TextWriter)val2).Write(JsonSerializer.Serialize(value, _serializeOptions));
				((TextWriter)val2).Flush();
			});
		}
	}
}
namespace v_rising_discord_bot_companion.character
{
	public static class CharacterInfoCommand
	{
		public static List<CharacterResponse> GetCharacters()
		{
			return (from vPlayer in VPlayer.GetAllPlayers()
				where vPlayer.HasCharacter()
				select vPlayer).Select(delegate(VPlayer player)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_002a: 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_0061: 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_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_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: 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_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				Entity entity = player.VUser.User.ClanEntity._Entity;
				string clan = null;
				EntityManager entityManager = VWorld.Server.EntityManager;
				if (((EntityManager)(ref entityManager)).HasComponent<ClanTeam>(entity))
				{
					ClanTeam componentData = ((EntityManager)(ref entityManager)).GetComponentData<ClanTeam>(entity);
					clan = ((object)(FixedString64Bytes)(ref componentData.Name)).ToString();
				}
				List<VBlood> list = new List<VBlood>();
				Entity val = default(Entity);
				if (ProgressionUtility.TryGetProgressionEntity(entityManager, player.VUser.UserEntity, ref val))
				{
					Enumerator<UnlockedVBlood> enumerator = ((EntityManager)(ref entityManager)).GetBuffer<UnlockedVBlood>(val, false).GetEnumerator();
					while (enumerator.MoveNext())
					{
						UnlockedVBlood current = enumerator.Current;
						Type typeFromHandle = typeof(VBlood);
						PrefabGUID vBlood = current.VBlood;
						if (Enum.IsDefined(typeFromHandle, ((PrefabGUID)(ref vBlood)).GuidHash))
						{
							vBlood = current.VBlood;
							list.Add((VBlood)((PrefabGUID)(ref vBlood)).GuidHash);
						}
					}
				}
				PlayerCharacter character = player.VCharacter.Value.Character;
				return new CharacterResponse(((object)(FixedString64Bytes)(ref character.Name)).ToString(), player.VCharacter.Value.getGearLevel(), clan, list);
			}).ToList();
		}
	}
	public readonly record struct CharacterResponse(string Name, int GearLevel, string? Clan, List<VBlood> KilledVBloods);
	[JsonConverter(typeof(VBloodConverter))]
	public enum VBlood
	{
		[VBloodName("Alpha Wolf")]
		FOREST_WOLF = -1905691330,
		[VBloodName("Errol the Stonebreaker")]
		BANDIT_STONEBREAKER = -2025101517,
		[VBloodName("Keely the Frost Archer")]
		BANDIT_DEADEYE_FROSTARROW = 1124739990,
		[VBloodName("Rufus the Foreman")]
		BANDIT_FOREMAN = 2122229952,
		[VBloodName("Goreswine the Ravager")]
		UNDEAD_BISHOPOFDEATH = 577478542,
		[VBloodName("Grayson the Armourer")]
		BANDIT_STALKER = 1106149033,
		[VBloodName("Nibbles the Putrid Rat")]
		VERMIN_DIRERAT = -2039908510,
		[VBloodName("Lidia the Chaos Archer")]
		BANDIT_DEADEYE_CHAOSARROW = 763273073,
		[VBloodName("Clive the Firestarter")]
		BANDIT_BOMBER = 1896428751,
		[VBloodName("Kodia the Ferocious Bear")]
		FOREST_BEAR_DIRE = -1391546313,
		[VBloodName("Polora the Feywalker")]
		POLOMA = -484556888,
		[VBloodName("Nicholaus the Fallen")]
		UNDEAD_PRIEST = 153390636,
		[VBloodName("Quincey the Bandit King")]
		BANDIT_TOUROK = -1659822956,
		[VBloodName("Beatrice the Tailor")]
		VILLAGER_TAILOR = -1942352521,
		[VBloodName("Tristan the Vampire Hunter")]
		VHUNTER_LEADER = -1449631170,
		[VBloodName("Kriig the Undead General")]
		UNDEAD_LEADER = -1365931036,
		[VBloodName("Christina the Sun Priestess")]
		MILITIA_NUN = -99012450,
		[VBloodName("Vincent the Frostbringer")]
		MILITIA_GUARD = -29797003,
		[VBloodName("Bane the Shadowblade")]
		UNDEAD_INFILTRATOR = 613251918,
		[VBloodName("Grethel the Glassblower")]
		MILITIA_GLASSBLOWER = 910988233,
		[VBloodName("Leandra the Shadow Priestess")]
		UNDEAD_BISHOPOFSHADOWS = 939467639,
		[VBloodName("Maja the Dark Savant")]
		MILITIA_SCRIBE = 1945956671,
		[VBloodName("Terah the Geomancer")]
		GEOMANCER_HUMAN = -1065970933,
		[VBloodName("Meredith the Bright Archer")]
		MILITIA_LONGBOWMAN_LIGHTARROW = 850622034,
		[VBloodName("Jade the Vampire Hunter")]
		VHUNTER_JADE = -1968372384,
		[VBloodName("Raziel the Shepherd")]
		MILITIA_BISHOPOFDUNLEY = -680831417,
		[VBloodName("Frostmaw the Mountain Terror")]
		WENDIGO = 24378719,
		[VBloodName("Octavian the Militia Captain")]
		MILITIA_LEADER = 1688478381,
		[VBloodName("Domina the Blade Dancer")]
		GLOOMROT_VOLTAGE = -1101874342,
		[VBloodName("Angram the Purifier")]
		GLOOMROT_PURIFIER = 106480588,
		[VBloodName("Ziva the Engineer")]
		GLOOMROT_IVA = 172235178,
		[VBloodName("Ungora the Spider Queen")]
		SPIDER_QUEEN = -548489519,
		[VBloodName("Ben the Old Wanderer")]
		VILLAGER_CURSEDWANDERER = 109969450,
		[VBloodName("Foulrot the Soultaker")]
		UNDEAD_ZEALOUSCULTIST = -1208888966,
		[VBloodName("Willfred the Werewolf Chief")]
		WEREWOLFCHIEFTAIN = -1505705712,
		[VBloodName("Albert the Duke of Balaton")]
		CURSED_TOADKING = -203043163,
		[VBloodName("Cyril the Cursed Smith")]
		UNDEAD_CURSEDSMITH = 326378955,
		[VBloodName("Sir Magnus the Overseer")]
		CHURCHOFLIGHT_OVERSEER = -26105228,
		[VBloodName("Mairwyn the Elementalist")]
		ARCHMAGE = -2013903325,
		[VBloodName("Baron du Bouchon the Sommelier")]
		CHURCHOFLIGHT_SOMMELIER = 192051202,
		[VBloodName("Morian the Stormwing Matriarch")]
		HARPY_MATRIARCH = 685266977,
		[VBloodName("Terrorclaw the Ogre")]
		WINTER_YETI = -1347412392,
		[VBloodName("Azariel the Sunbringer")]
		CHURCHOFLIGHT_CARDINAL = 114912615,
		[VBloodName("Henry Blackbrew the Doctor")]
		GLOOMROT_THEPROFESSOR = 814083983,
		[VBloodName("Matka the Curse Weaver")]
		CURSED_WITCH = -910296704,
		[VBloodName("Voltatia the Power Master")]
		GLOOMROT_RAILGUNSERGEANT = 2054432370,
		[VBloodName("Nightmarshal Styx the Sunderer")]
		BATVAMPIRE = 1112948824,
		[VBloodName("Solarus the Immaculate")]
		CHURCHOFLIGHT_PALADIN = -740796338,
		[VBloodName("Adam the Firstborn")]
		GLOOMROT_MONSTER = 1233988687,
		[VBloodName("Gorecrusher the Behemoth")]
		CURSED_MOUNTAINBEAST = -1936575244,
		[VBloodName("Talzur the Winged Horror")]
		MANTICORE = -393555055,
		[VBloodName("Finn")]
		BANDIT_FISHERMAN = -2122682556,
		[VBloodName("Elena")]
		ICE_RANGER = 795262842,
		[VBloodName("Valencia")]
		BLOOD_KNIGHT = 495971434,
		[VBloodName("Cassius")]
		HIGH_LORD = -496360395,
		[VBloodName("Dracula")]
		DRACULA = -327335305,
		[VBloodName("Simon Belmont")]
		VHUNTER = 336560131
	}
	public class VBloodConverter : JsonConverter<VBlood>
	{
		public override VBlood Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			throw new NotImplementedException();
		}

		public override void Write(Utf8JsonWriter writer, VBlood value, JsonSerializerOptions options)
		{
			writer.WriteStringValue(Enum.GetName(typeof(VBlood), value));
		}
	}
	public static class VBloodExtensions
	{
		public static string DisplayName(this VBlood vBlood)
		{
			return vBlood.GetType().GetField(vBlood.ToString()).GetCustomAttribute<VBloodNameAttribute>(inherit: false)
				.DisplayName;
		}
	}
	public class VBloodNameAttribute : Attribute
	{
		public string DisplayName { get; }

		public VBloodNameAttribute(string displayName)
		{
			DisplayName = displayName;
		}
	}
}
namespace v_rising_discord_bot_companion.activity
{
	[JsonConverter(typeof(ActivityTypeConverter))]
	public enum ActivityType
	{
		CONNECTED,
		DISCONNECTED
	}
	public class ActivityTypeConverter : JsonConverter<ActivityType>
	{
		public override ActivityType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			throw new NotImplementedException();
		}

		public override void Write(Utf8JsonWriter writer, ActivityType value, JsonSerializerOptions options)
		{
			writer.WriteStringValue(Enum.GetName(typeof(ActivityType), value));
		}
	}
	public readonly record struct PlayerActivity(ActivityType Type, string PlayerName, DateTime Occurred);
	[HarmonyPatch(typeof(ServerBootstrapSystem))]
	public class ServerBootstrapSystemPatches
	{
		private static readonly List<PlayerActivity> _playerActivities = new List<PlayerActivity>();

		public static List<PlayerActivity> getPlayerActivities()
		{
			removeExpiredPlayerActivities();
			return _playerActivities;
		}

		private static void removeExpiredPlayerActivities()
		{
			_playerActivities.RemoveAll((PlayerActivity playerActivity) => DateTime.UtcNow > playerActivity.Occurred.AddMinutes(10.0));
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnUserConnected")]
		public static void OnUserConnected(ServerBootstrapSystem __instance, NetConnectionId netConnectionId)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
			VPlayer vPlayer = VPlayer.from(((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num].UserEntity);
			User user = vPlayer.VUser.User;
			if (!((FixedString64Bytes)(ref user.CharacterName)).IsEmpty)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("OnUserConnected: ");
					user = vPlayer.VUser.User;
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((object)(FixedString64Bytes)(ref user.CharacterName)).ToString());
				}
				logger.LogDebug(val);
				List<PlayerActivity> playerActivities = _playerActivities;
				user = vPlayer.VUser.User;
				playerActivities.Add(new PlayerActivity(ActivityType.CONNECTED, ((object)(FixedString64Bytes)(ref user.CharacterName)).ToString(), DateTime.UtcNow));
				removeExpiredPlayerActivities();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnUserDisconnected")]
		public static void OnUserDisconnected(ServerBootstrapSystem __instance, NetConnectionId netConnectionId, ConnectionStatusChangeReason connectionStatusReason, string extraData)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
			VPlayer vPlayer = VPlayer.from(((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num].UserEntity);
			User user = vPlayer.VUser.User;
			if (!((FixedString64Bytes)(ref user.CharacterName)).IsEmpty)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(20, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("OnUserDisconnected: ");
					user = vPlayer.VUser.User;
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((object)(FixedString64Bytes)(ref user.CharacterName)).ToString());
				}
				logger.LogDebug(val);
				List<PlayerActivity> playerActivities = _playerActivities;
				user = vPlayer.VUser.User;
				playerActivities.Add(new PlayerActivity(ActivityType.DISCONNECTED, ((object)(FixedString64Bytes)(ref user.CharacterName)).ToString(), DateTime.UtcNow));
				removeExpiredPlayerActivities();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("SpawnCharacter")]
		public static void SpawnCharacter(ServerBootstrapSystem __instance, EntityCommandBuffer commandBuffer, Entity prefab, Entity user, Nullable_Unboxed<float3> customSpawnPosition)
		{
			//IL_0000: 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: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			VPlayer vPlayer = VPlayer.from(user);
			ManualLogSource logger = Plugin.Logger;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(16, 1, ref flag);
			User user2;
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("SpawnCharacter: ");
				user2 = vPlayer.VUser.User;
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((object)(FixedString64Bytes)(ref user2.CharacterName)).ToString());
			}
			logger.LogDebug(val);
			List<PlayerActivity> playerActivities = _playerActivities;
			user2 = vPlayer.VUser.User;
			playerActivities.Add(new PlayerActivity(ActivityType.CONNECTED, ((object)(FixedString64Bytes)(ref user2.CharacterName)).ToString(), DateTime.UtcNow));
			removeExpiredPlayerActivities();
		}
	}
}