Decompiled source of NoCloakShroudBuff v1.0.1

NoCloakShroudBuff.dll

Decompiled 2 weeks ago
using System;
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.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Gameplay.Scripting;
using ProjectM.Network;
using ProjectM.Shared;
using ProjectM.Terrain;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("NoCloakShroudBuff")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Shroud of the Forest protection in the Cursed Forest for players who have killed Ben the Old Wanderer, without the cloak")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+19ac0ff64f6d3d4b69c010f828a20786330d743b")]
[assembly: AssemblyProduct("NoCloakShroudBuff")]
[assembly: AssemblyTitle("NoCloakShroudBuff")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 NoCloakShroudBuff
{
	internal static class Discovery
	{
		public class PlayerWatcher : MonoBehaviour
		{
			private readonly Dictionary<ulong, string> _last = new Dictionary<ulong, string>();

			private float _next;

			public PlayerWatcher(IntPtr ptr)
				: base(ptr)
			{
			}

			private void Update()
			{
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Expected O, but got Unknown
				if (Time.unscaledTime < _next)
				{
					return;
				}
				_next = Time.unscaledTime + (float)Math.Max(1, Plugin.DumpIntervalSeconds.Value);
				World serverWorld = Plugin.ServerWorld;
				if (serverWorld == null || !serverWorld.IsCreated)
				{
					return;
				}
				try
				{
					Scan(serverWorld);
				}
				catch (Exception ex)
				{
					ManualLogSource logger = Plugin.Logger;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Dump: player scan failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					logger.LogError(val);
				}
			}

			private unsafe void Scan(World world)
			{
				//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_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_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_0038: 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_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: 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_0063: 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_006a: 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_0084: 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_0097: 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_0145: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Expected O, but got Unknown
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				//IL_0167: Unknown result type (might be due to invalid IL or missing references)
				//IL_0169: Unknown result type (might be due to invalid IL or missing references)
				//IL_016e: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_021e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dc: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0391: Unknown result type (might be due to invalid IL or missing references)
				//IL_022c: Unknown result type (might be due to invalid IL or missing references)
				//IL_022f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0234: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03db: Unknown result type (might be due to invalid IL or missing references)
				//IL_03df: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_0245: Unknown result type (might be due to invalid IL or missing references)
				//IL_024a: Unknown result type (might be due to invalid IL or missing references)
				//IL_025d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0262: Unknown result type (might be due to invalid IL or missing references)
				//IL_0267: Unknown result type (might be due to invalid IL or missing references)
				//IL_026b: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f7: Expected O, but got Unknown
				//IL_0276: Unknown result type (might be due to invalid IL or missing references)
				//IL_041e: Unknown result type (might be due to invalid IL or missing references)
				//IL_043d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0281: Unknown result type (might be due to invalid IL or missing references)
				//IL_0283: Unknown result type (might be due to invalid IL or missing references)
				//IL_0288: Unknown result type (might be due to invalid IL or missing references)
				//IL_029b: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
				EntityManager entityManager = world.EntityManager;
				PrefabLookupMap lookup = world.GetExistingSystemManaged<PrefabCollectionSystem>()._PrefabLookupMap;
				EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1]
				{
					new ComponentType(Il2CppType.Of<User>(), (AccessMode)1)
				});
				NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
				try
				{
					bool flag = default(bool);
					for (int i = 0; i < val2.Length; i++)
					{
						Entity val3 = val2[i];
						User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(val3);
						if (!componentData.IsConnected)
						{
							continue;
						}
						Entity entityOnServer = ((NetworkedEntity)(ref componentData.LocalCharacter)).GetEntityOnServer();
						if (entityOnServer == Entity.Null || !((EntityManager)(ref entityManager)).Exists(entityOnServer))
						{
							continue;
						}
						string text = ((object)(*(FixedString64Bytes*)(&componentData.CharacterName))/*cast due to .constrained prefix*/).ToString();
						if (!_last.ContainsKey(componentData.PlatformId))
						{
							_last[componentData.PlatformId] = "";
							ManualLogSource logger = Plugin.Logger;
							BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(26, 2, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Dump: ");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(text);
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" unlocked V Bloods: ");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(UnlockedVBloods(entityManager, val3, entityOnServer, Name));
							}
							logger.LogInfo(val4);
						}
						string value = "?";
						if (((EntityManager)(ref entityManager)).HasComponent<CurrentWorldRegion>(entityOnServer))
						{
							value = $"char {((EntityManager)(ref entityManager)).GetComponentData<CurrentWorldRegion>(entityOnServer).CurrentRegion}";
						}
						else if (((EntityManager)(ref entityManager)).HasComponent<CurrentWorldRegion>(val3))
						{
							value = $"user {((EntityManager)(ref entityManager)).GetComponentData<CurrentWorldRegion>(val3).CurrentRegion}";
						}
						string value2 = "-";
						if (((EntityManager)(ref entityManager)).HasComponent<Equipment>(entityOnServer))
						{
							Equipment componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<Equipment>(entityOnServer);
							value2 = Name(componentData2.CloakSlot.SlotId) + " / cosmetic " + Name(componentData2.CloakCosmeticSlot.SlotId);
						}
						List<string> list = new List<string>();
						string value3 = "-";
						if (((EntityManager)(ref entityManager)).HasBuffer<BuffBuffer>(entityOnServer))
						{
							DynamicBuffer<BuffBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<BuffBuffer>(entityOnServer, false);
							for (int j = 0; j < buffer.Length; j++)
							{
								list.Add(Name(buffer[j].PrefabGuid));
								Entity entity = buffer[j].Entity;
								if (((EntityManager)(ref entityManager)).Exists(entity) && ((EntityManager)(ref entityManager)).HasComponent<Script_CurseAreaDebuff_DataShared>(entity))
								{
									Script_CurseAreaDebuff_DataShared componentData3 = ((EntityManager)(ref entityManager)).GetComponentData<Script_CurseAreaDebuff_DataShared>(entity);
									value3 = $"{Name(buffer[j].PrefabGuid)} inArea={componentData3.IsInArea} stacks={componentData3.StackSize}";
								}
							}
						}
						list.Sort(StringComparer.OrdinalIgnoreCase);
						string text2 = $"region={value} cloak={value2} curse={value3} buffs=[{string.Join(", ", list)}]";
						if (!(text2 == _last[componentData.PlatformId]))
						{
							_last[componentData.PlatformId] = text2;
							? val5;
							if (!((EntityManager)(ref entityManager)).HasComponent<LocalToWorld>(entityOnServer))
							{
								val5 = default(float3);
							}
							else
							{
								LocalToWorld componentData4 = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(entityOnServer);
								val5 = ((LocalToWorld)(ref componentData4)).Position;
							}
							float3 val6 = (float3)val5;
							ManualLogSource logger2 = Plugin.Logger;
							BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(15, 4, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Dump: ");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(text);
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" at (");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<float>(val6.x, "F0");
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(", ");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<float>(val6.z, "F0");
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(") ");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(text2);
							}
							logger2.LogInfo(val4);
						}
					}
				}
				finally
				{
					val2.Dispose();
					((EntityQuery)(ref val)).Dispose();
				}
				string Name(PrefabGUID g)
				{
					//IL_000f: Unknown result type (might be due to invalid IL or missing references)
					object obj;
					if (!((PrefabGUID)(ref g)).IsEmpty())
					{
						obj = ((PrefabLookupMap)(ref lookup)).GetName(g);
						if (obj == null)
						{
							return ((PrefabGUID)(ref g)).GuidHash.ToString();
						}
					}
					else
					{
						obj = "-";
					}
					return (string)obj;
				}
			}

			private static string UnlockedVBloods(EntityManager em, Entity userEntity, Entity character, Func<PrefabGUID, string> name)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: 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_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_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_0044: 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_004a: 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_005c: 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_006b: 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_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Unknown result type (might be due to invalid IL or missing references)
				//IL_0129: Unknown result type (might be due to invalid IL or missing references)
				Entity[] array = (Entity[])(object)new Entity[2] { userEntity, character };
				foreach (Entity val in array)
				{
					if (!((EntityManager)(ref em)).HasComponent<ProgressionMapper>(val))
					{
						continue;
					}
					ProgressionMapper componentData = ((EntityManager)(ref em)).GetComponentData<ProgressionMapper>(val);
					Entity entityOnServer = ((NetworkedEntity)(ref componentData.ProgressionEntity)).GetEntityOnServer();
					if (!(entityOnServer == Entity.Null) && ((EntityManager)(ref em)).HasBuffer<UnlockedVBlood>(entityOnServer))
					{
						DynamicBuffer<UnlockedVBlood> buffer = ((EntityManager)(ref em)).GetBuffer<UnlockedVBlood>(entityOnServer, false);
						List<string> list = new List<string>();
						for (int j = 0; j < buffer.Length; j++)
						{
							DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(3, 2);
							defaultInterpolatedStringHandler.AppendFormatted(name(buffer[j].VBlood));
							defaultInterpolatedStringHandler.AppendLiteral(" (");
							UnlockedVBlood val2 = buffer[j];
							defaultInterpolatedStringHandler.AppendFormatted(((PrefabGUID)(ref val2.VBlood)).GuidHash);
							defaultInterpolatedStringHandler.AppendLiteral(")");
							list.Add(defaultInterpolatedStringHandler.ToStringAndClear());
						}
						list.Sort(StringComparer.OrdinalIgnoreCase);
						return $"{list.Count} via {((val == userEntity) ? "user" : "character")}: {string.Join(", ", list)}";
					}
				}
				return "not found (no ProgressionMapper → UnlockedVBlood on user or character)";
			}
		}

		public static void WritePrefabs(World world)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			EntityManager entityManager = world.EntityManager;
			PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>();
			PrefabLookupMap prefabLookupMap = existingSystemManaged._PrefabLookupMap;
			Regex regex = new Regex(Plugin.DumpPattern.Value, RegexOptions.IgnoreCase);
			List<(string, string)> list = new List<(string, string)>();
			NativeKeyValueArrays<PrefabGUID, Entity> keyValueArrays = existingSystemManaged._PrefabGuidToEntityMap.GetKeyValueArrays(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				for (int i = 0; i < keyValueArrays.Length; i++)
				{
					PrefabGUID val = keyValueArrays.Keys[i];
					string text = ((PrefabLookupMap)(ref prefabLookupMap)).GetName(val) ?? "";
					if (regex.IsMatch(text))
					{
						list.Add((text, $"{text}  {((PrefabGUID)(ref val)).GuidHash}\n    {Components(entityManager, keyValueArrays.Values[i])}"));
					}
				}
			}
			finally
			{
				keyValueArrays.Dispose();
			}
			string text2 = Path.Combine(Paths.ConfigPath, "NoCloakShroudBuff");
			Directory.CreateDirectory(text2);
			string text3 = Path.Combine(text2, "prefabs.txt");
			File.WriteAllLines(text3, from r in list.OrderBy<(string, string), string>(((string Name, string Line) r) => r.Name, StringComparer.OrdinalIgnoreCase)
				select r.Line);
			ManualLogSource logger = Plugin.Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(38, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Dump: ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(list.Count);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" prefabs matching '");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(Plugin.DumpPattern.Value);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' written to ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text3);
			}
			logger.LogInfo(val2);
		}

		private static string Components(EntityManager em, Entity entity)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			NativeArray<ComponentType> componentTypes = ((EntityManager)(ref em)).GetComponentTypes(entity, (Allocator)2);
			try
			{
				List<string> list = new List<string>();
				for (int i = 0; i < componentTypes.Length; i++)
				{
					try
					{
						list.Add(((object)componentTypes[i]/*cast due to .constrained prefix*/).ToString());
					}
					catch
					{
						list.Add("?");
					}
				}
				return string.Join(", ", list.OrderBy((string n) => n));
			}
			finally
			{
				componentTypes.Dispose();
			}
		}
	}
	[BepInPlugin("NoCloakShroudBuff", "NoCloakShroudBuff", "1.0.1")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<int> CheckIntervalSeconds;

		internal static ConfigEntry<bool> LogChanges;

		internal static ConfigEntry<bool> Dump;

		internal static ConfigEntry<string> DumpPattern;

		internal static ConfigEntry<int> DumpIntervalSeconds;

		internal static World ServerWorld;

		internal static Plugin Instance;

		private Harmony _harmony;

		public override void Load()
		{
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Instance = this;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Set to false to turn the mod off (everything stays as in the base game).");
			CheckIntervalSeconds = ((BasePlugin)this).Config.Bind<int>("General", "CheckIntervalSeconds", 1, "How often (seconds) online players are checked.");
			LogChanges = ((BasePlugin)this).Config.Bind<bool>("General", "LogChanges", true, "Log a line each time the buff is applied or removed.");
			Dump = ((BasePlugin)this).Config.Bind<bool>("Discovery", "Dump", false, "Write matching prefabs to BepInEx/config/NoCloakShroudBuff/prefabs.txt at start, and log each online player's region, cloak, curse and buffs when they change.");
			DumpPattern = ((BasePlugin)this).Config.Bind<string>("Discovery", "DumpPattern", "Shroud|Curse|Wanderer|Forest|_VBlood$", "Regular expression for the prefab names to write (case-insensitive).");
			DumpIntervalSeconds = ((BasePlugin)this).Config.Bind<int>("Discovery", "DumpIntervalSeconds", 3, "How often online players are checked while Dump is on.");
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val;
			if (!Paths.ProcessName.Equals("VRisingServer", StringComparison.OrdinalIgnoreCase))
			{
				ManualLogSource log = ((BasePlugin)this).Log;
				val = new BepInExInfoLogInterpolatedStringHandler(47, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("NoCloakShroudBuff");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.1");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is a server mod; nothing to do on the client.");
				}
				log.LogInfo(val);
				return;
			}
			_harmony = Harmony.CreateAndPatchAll(typeof(ServerReadyPatch), "NoCloakShroudBuff");
			ManualLogSource log2 = ((BasePlugin)this).Log;
			val = new BepInExInfoLogInterpolatedStringHandler(36, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("NoCloakShroudBuff");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.1");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded on server (Enabled=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(Enabled.Value);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Dump=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(Dump.Value);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
			}
			log2.LogInfo(val);
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}

		internal static void OnServerReady(World world)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				ServerWorld = world;
				ManualLogSource logger = Logger;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Server ready (world ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(world.Name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
				}
				logger.LogInfo(val);
				if (ShroudKeeper.CheckPrefabs(world))
				{
					((BasePlugin)Instance).AddComponent<ShroudKeeper>();
				}
				if (Dump.Value)
				{
					Discovery.WritePrefabs(world);
					((BasePlugin)Instance).AddComponent<Discovery.PlayerWatcher>();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = Logger;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Server-ready handler failed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				logger2.LogError(val2);
			}
		}
	}
	[HarmonyPatch(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate")]
	internal static class ServerReadyPatch
	{
		private static bool _done;

		private static void Postfix(SpawnTeamSystem_OnPersistenceLoad __instance)
		{
			if (_done)
			{
				return;
			}
			World world = ((ComponentSystemBase)__instance).World;
			if (world != null && !(world.Name != "Server"))
			{
				PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>();
				if (existingSystemManaged != null && existingSystemManaged.GameDataInitialized)
				{
					_done = true;
					Plugin.OnServerReady(world);
				}
			}
		}
	}
	public class ShroudKeeper : MonoBehaviour
	{
		internal static readonly PrefabGUID ShroudBuff = new PrefabGUID(1504279833);

		internal static readonly PrefabGUID ShroudCloak = new PrefabGUID(1063517722);

		internal static readonly PrefabGUID Ben = new PrefabGUID(109969450);

		private float _next;

		public ShroudKeeper(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			if (Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + (float)Math.Max(1, Plugin.CheckIntervalSeconds.Value);
			World serverWorld = Plugin.ServerWorld;
			if (serverWorld == null || !serverWorld.IsCreated)
			{
				return;
			}
			try
			{
				CheckPlayers(serverWorld);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(21, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Player check failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}

		private unsafe static void CheckPlayers(World world)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0048: 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_0051: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Expected O, but got Unknown
			EntityManager entityManager = world.EntityManager;
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1]
			{
				new ComponentType(Il2CppType.Of<User>(), (AccessMode)1)
			});
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				bool flag2 = default(bool);
				for (int i = 0; i < val2.Length; i++)
				{
					Entity val3 = val2[i];
					User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(val3);
					if (!componentData.IsConnected)
					{
						continue;
					}
					Entity entityOnServer = ((NetworkedEntity)(ref componentData.LocalCharacter)).GetEntityOnServer();
					if (entityOnServer == Entity.Null || !((EntityManager)(ref entityManager)).Exists(entityOnServer) || WearsCloak(entityManager, entityOnServer))
					{
						continue;
					}
					bool flag = Plugin.Enabled.Value && InCursedForest(entityManager, val3) && KilledBen(entityManager, val3);
					Entity val4 = FindBuff(entityManager, entityOnServer, ShroudBuff);
					string text = ((object)(*(FixedString64Bytes*)(&componentData.CharacterName))/*cast due to .constrained prefix*/).ToString();
					if (flag && val4 == Entity.Null)
					{
						world.GetExistingSystemManaged<DebugEventsSystem>().ApplyBuff(new FromCharacter
						{
							User = val3,
							Character = entityOnServer
						}, new ApplyBuffDebugEvent
						{
							BuffPrefabGUID = ShroudBuff
						});
						if (Plugin.LogChanges.Value)
						{
							ManualLogSource logger = Plugin.Logger;
							BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(58, 1, ref flag2);
							if (flag2)
							{
								((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(text);
								((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(": Shroud of the Forest applied (Cursed Forest, Ben killed)");
							}
							logger.LogInfo(val5);
						}
					}
					else
					{
						if (flag || !(val4 != Entity.Null))
						{
							continue;
						}
						DestroyUtility.Destroy(entityManager, val4, (DestroyDebugReason)13, (string)null, 0);
						if (Plugin.LogChanges.Value)
						{
							ManualLogSource logger2 = Plugin.Logger;
							BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(72, 1, ref flag2);
							if (flag2)
							{
								((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(text);
								((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(": Shroud of the Forest removed (left the Cursed Forest, or mod disabled)");
							}
							logger2.LogInfo(val5);
						}
					}
				}
			}
			finally
			{
				val2.Dispose();
				((EntityQuery)(ref val)).Dispose();
			}
		}

		private static bool WearsCloak(EntityManager em, Entity character)
		{
			//IL_0002: 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_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_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 (((EntityManager)(ref em)).HasComponent<Equipment>(character))
			{
				return ((EntityManager)(ref em)).GetComponentData<Equipment>(character).CloakSlot.SlotId == ShroudCloak;
			}
			return false;
		}

		private static bool InCursedForest(EntityManager em, Entity userEntity)
		{
			//IL_0002: 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_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_0018: Invalid comparison between Unknown and I4
			if (((EntityManager)(ref em)).HasComponent<CurrentWorldRegion>(userEntity))
			{
				return (int)((EntityManager)(ref em)).GetComponentData<CurrentWorldRegion>(userEntity).CurrentRegion == 5;
			}
			return false;
		}

		private static bool KilledBen(EntityManager em, Entity userEntity)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0031: 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_003f: 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_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_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!((EntityManager)(ref em)).HasComponent<ProgressionMapper>(userEntity))
			{
				return false;
			}
			ProgressionMapper componentData = ((EntityManager)(ref em)).GetComponentData<ProgressionMapper>(userEntity);
			Entity entityOnServer = ((NetworkedEntity)(ref componentData.ProgressionEntity)).GetEntityOnServer();
			if (entityOnServer == Entity.Null || !((EntityManager)(ref em)).HasBuffer<UnlockedVBlood>(entityOnServer))
			{
				return false;
			}
			DynamicBuffer<UnlockedVBlood> buffer = ((EntityManager)(ref em)).GetBuffer<UnlockedVBlood>(entityOnServer, false);
			for (int i = 0; i < buffer.Length; i++)
			{
				if (buffer[i].VBlood == Ben)
				{
					return true;
				}
			}
			return false;
		}

		private static Entity FindBuff(EntityManager em, Entity character, PrefabGUID guid)
		{
			//IL_0002: 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_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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_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)
			if (!((EntityManager)(ref em)).HasBuffer<BuffBuffer>(character))
			{
				return Entity.Null;
			}
			DynamicBuffer<BuffBuffer> buffer = ((EntityManager)(ref em)).GetBuffer<BuffBuffer>(character, false);
			for (int i = 0; i < buffer.Length; i++)
			{
				if (buffer[i].PrefabGuid == guid && ((EntityManager)(ref em)).Exists(buffer[i].Entity))
				{
					return buffer[i].Entity;
				}
			}
			return Entity.Null;
		}

		internal static bool CheckPrefabs(World world)
		{
			//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_0016: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			PrefabLookupMap prefabLookupMap = world.GetExistingSystemManaged<PrefabCollectionSystem>()._PrefabLookupMap;
			bool result = true;
			(PrefabGUID, string)[] array = new(PrefabGUID, string)[3]
			{
				(ShroudBuff, "EquipBuff_ShroudOfTheForest"),
				(ShroudCloak, "Item_Cloak_Main_ShroudOfTheForest"),
				(Ben, "CHAR_Villager_CursedWanderer_VBlood")
			};
			bool flag = default(bool);
			for (int i = 0; i < array.Length; i++)
			{
				(PrefabGUID, string) tuple = array[i];
				PrefabGUID item = tuple.Item1;
				string item2 = tuple.Item2;
				string name = ((PrefabLookupMap)(ref prefabLookupMap)).GetName(item);
				if (!(name == item2))
				{
					ManualLogSource logger = Plugin.Logger;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(83, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Prefab ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(((PrefabGUID)(ref item)).GuidHash);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" should be ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item2);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" but is '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(name ?? "missing");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'; the mod stays off. A game update may have changed it.");
					}
					logger.LogWarning(val);
					result = false;
				}
			}
			return result;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoCloakShroudBuff";

		public const string PLUGIN_NAME = "NoCloakShroudBuff";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}