Decompiled source of ChestRecipeRevealer v1.0.1

ChestRecipeRevealer.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 ChestRevealer
{
	[BepInPlugin("com.oopas.chestreciperevealer", "ChestRecipeRevealer", "1.0.1")]
	public class ChestRevealer : BaseUnityPlugin
	{
		public const string PluginGuid = "com.oopas.chestreciperevealer";

		public const string PluginName = "ChestRecipeRevealer";

		public const string PluginVersion = "1.0.1";

		public static ManualLogSource Log;

		public static int Radius;

		public static string Blacklist;

		public static string BlockItemTypes;

		public static bool SkipPrivateChests;

		public static bool Enabled;

		private Scanner _scanner;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			ConfigEntry<float> val = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Radius", 8f, "Rayon (m) autour du joueur dans lequel les conteneurs sont scannés");
			ConfigEntry<string> val2 = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Blacklist", "", "Item IDs (separés par ,) a ne jamais decouvrir via ce mod");
			ConfigEntry<string> val3 = ((BaseUnityPlugin)this).Config.Bind<string>("General", "BlockItemTypes", "Trophy", "Types d'items a ignorer (noms de l'enum ItemType, séparés par ,) - Trophy = trophées de boss");
			ConfigEntry<bool> val4 = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SkipPrivateChests", true, "Ignorer les coffres prives (privacy=Private) dont tu n'es pas l'owner");
			ConfigEntry<bool> val5 = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Active le mod");
			Radius = Mathf.RoundToInt(val.Value);
			Blacklist = val2.Value;
			BlockItemTypes = val3.Value;
			SkipPrivateChests = val4.Value;
			Enabled = val5.Value;
			_scanner = ((Component)this).gameObject.AddComponent<Scanner>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} actif (radius={2}m). Config: {3}", "ChestRecipeRevealer", "1.0.1", Radius, ((BaseUnityPlugin)this).Config.ConfigFilePath));
		}
	}
	[DisallowMultipleComponent]
	public class Scanner : MonoBehaviour
	{
		private const float Interval = 0.5f;

		private float _timer;

		private HashSet<string> _blacklist = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		private HashSet<ItemType> _blockedTypes = new HashSet<ItemType>();

		private void Awake()
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			string[] array = ChestRevealer.Blacklist.Split(new char[1] { ',' });
			foreach (string text in array)
			{
				string text2 = text.Trim();
				if (text2.Length > 0)
				{
					_blacklist.Add(text2);
				}
			}
			string[] array2 = ChestRevealer.BlockItemTypes.Split(new char[1] { ',' });
			foreach (string text3 in array2)
			{
				string text4 = text3.Trim();
				if (text4.Length != 0)
				{
					if (Enum.TryParse<ItemType>(text4, ignoreCase: true, out ItemType result))
					{
						_blockedTypes.Add(result);
					}
					else
					{
						ChestRevealer.Log.LogWarning((object)("BlockItemTypes: type inconnu '" + text4 + "' (ignoré)"));
					}
				}
			}
			ChestRevealer.Log.LogInfo((object)($"Filtres: {_blockedTypes.Count} type(s) bloqué(s)" + ((_blacklist.Count > 0) ? $", {_blacklist.Count} id(s) blacklist" : "")));
		}

		private void Update()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Invalid comparison between Unknown and I4
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			if (!ChestRevealer.Enabled)
			{
				return;
			}
			_timer += Time.deltaTime;
			if (_timer < 0.5f)
			{
				return;
			}
			_timer = 0f;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			Vector3 position = ((Component)localPlayer).transform.position;
			float num = ChestRevealer.Radius * ChestRevealer.Radius;
			Container[] array = Resources.FindObjectsOfTypeAll<Container>();
			Container[] array2 = array;
			foreach (Container val in array2)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Vector3 position2 = ((Component)val).transform.position;
				Vector3 val2 = position2 - position;
				if (((Vector3)(ref val2)).sqrMagnitude > num || (ChestRevealer.SkipPrivateChests && (int)val.m_privacy == 0 && !val.IsOwner()))
				{
					continue;
				}
				Inventory inventory = val.GetInventory();
				if (inventory == null)
				{
					continue;
				}
				List<ItemData> allItems;
				try
				{
					allItems = inventory.GetAllItems();
				}
				catch
				{
					continue;
				}
				if (allItems == null)
				{
					continue;
				}
				foreach (ItemData item in allItems)
				{
					if (item != null)
					{
						SharedData shared = item.m_shared;
						if (shared != null && !string.IsNullOrEmpty(shared.m_name) && !_blockedTypes.Contains(shared.m_itemType) && !_blacklist.Contains(shared.m_name))
						{
							localPlayer.AddKnownItem(item);
						}
					}
				}
			}
		}
	}
}