Decompiled source of ItemsHighlightConfigurator v1.0.0

plugins\NovaGC-ItemsHighlightConfigurator\ItemsHighlightConfigurator.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ItemsHighlightConfigurator.Controllers;
using ItemsHighlightConfigurator.Models.Exceptions;
using ItemsHighlightConfigurator.Services;
using ItemsHighlightConfigurator.Utils;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using RoR2.ContentManagement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ItemsHighlightConfigurator")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+08ae5606d2a9c1aa6e8a2ada4d6cb231f07f842b")]
[assembly: AssemblyProduct("ItemsHighlightConfigurator")]
[assembly: AssemblyTitle("ItemsHighlightConfigurator")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ItemsHighlightConfigurator
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("NovaGC.ItemsHighlightConfigurator", "ItemsHighlightConfigurator", "1.0.0")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class ItemsHighlightConfiguratorPlugin : BaseUnityPlugin
	{
		public const string Guid = "NovaGC.ItemsHighlightConfigurator";

		public const string Author = "NovaGC";

		public const string Name = "ItemsHighlightConfigurator";

		public const string Version = "1.0.0";

		public TierColorConfigsController ConfigsController { get; private set; }

		public void Awake()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			ConfigsController = new TierColorConfigsController(((BaseUnityPlugin)this).Config);
			ItemTierCatalog.Init += new hook_Init(OnItemTierCatalogInit);
			ModSettingsManager.SetModDescription("Меняет цвет обводки предметов");
		}

		private void OnItemTierCatalogInit(orig_Init orig)
		{
			orig.Invoke();
			ConfigsController.Init();
		}
	}
}
namespace ItemsHighlightConfigurator.Utils
{
	public static class ColorConfigUtils
	{
		public static TierColorSyncController SyncColorConfig(this ConfigEntry<Color> config, ItemTier tier)
		{
			//IL_0000: 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)
			ItemTierDef itemTierDef = ItemTierCatalog.GetItemTierDef(tier);
			if (itemTierDef == null)
			{
				throw new ArgumentException("Unsupported tier", "tier");
			}
			return new TierColorSyncController(config, itemTierDef.colorIndex, tier);
		}

		public static void RegisterConfigOption(this ConfigEntry<Color> config)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new ColorOption(config));
		}
	}
}
namespace ItemsHighlightConfigurator.Services
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			ManualLogSource logSource2 = _logSource;
			if (logSource2 != null)
			{
				logSource2.Dispose();
			}
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}
namespace ItemsHighlightConfigurator.Models.Exceptions
{
	public class DuplicateTierException : Exception
	{
		[CompilerGenerated]
		private ItemTier <tier>P;

		public override string Message => $"{<tier>P} config already registered";

		public DuplicateTierException(ItemTier tier)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			<tier>P = tier;
			base..ctor();
		}
	}
}
namespace ItemsHighlightConfigurator.Controllers
{
	public class TierColorConfigsController : IDisposable
	{
		private readonly Dictionary<ItemTier, TierColorSyncController> _syncControllers = new Dictionary<ItemTier, TierColorSyncController>();

		private readonly Dictionary<ItemTier, Color> _originalTierColors = new Dictionary<ItemTier, Color>();

		public ConfigFile PluginConfigFile { get; set; }

		public ReadOnlyDictionary<ItemTier, Color> OriginalTierColors => new ReadOnlyDictionary<ItemTier, Color>(_originalTierColors);

		public TierColorConfigsController(ConfigFile pluginConfigFile)
		{
			PluginConfigFile = pluginConfigFile;
		}

		public void Init()
		{
			ItemTierDef[] itemTierDefs = ContentManager.itemTierDefs;
			foreach (ItemTierDef tierDef in itemTierDefs)
			{
				try
				{
					CreateTierColorConfigs(tierDef);
				}
				catch (Exception data)
				{
					Log.Error(data);
				}
			}
		}

		private void CreateTierColorConfigs(ItemTierDef tierDef)
		{
			//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_0013: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_009a: 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_00ed: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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)
			ItemTier tier = tierDef.tier;
			if (_syncControllers.ContainsKey(tier))
			{
				throw new DuplicateTierException(tier);
			}
			Color32 originalColor = ColorCatalog.GetColor(tierDef.colorIndex);
			ConfigEntry<Color> config = PluginConfigFile.Bind<Color>("Items", $"{tier} color", Color32.op_Implicit(originalColor), $"Цвет обводки для предметов класса {tier}");
			ConfigEntry<Color> originalColorConfig = PluginConfigFile.Bind<Color>("Items", $"{tier} original color", Color32.op_Implicit(originalColor), $"[НЕИЗМЕНЯЕМОЕ] Оригинальный цвет обводки для предметов класса {tier}");
			originalColorConfig.Value = Color32.op_Implicit(originalColor);
			originalColorConfig.SettingChanged += delegate
			{
				//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)
				originalColorConfig.Value = Color32.op_Implicit(originalColor);
			};
			config.RegisterConfigOption();
			originalColorConfig.RegisterConfigOption();
			TierColorSyncController value = config.SyncColorConfig(tier);
			_syncControllers.Add(tier, value);
			_originalTierColors.Add(tier, Color32.op_Implicit(originalColor));
		}

		public void Dispose()
		{
			foreach (TierColorSyncController value in _syncControllers.Values)
			{
				value.Dispose();
			}
		}
	}
	public class TierColorSyncController : IDisposable
	{
		private readonly ConfigEntry<Color> _config;

		private readonly ColorIndex _index;

		private readonly ItemTier _tier;

		private int ColorIndex => (int)_index;

		public TierColorSyncController(ConfigEntry<Color> config, ColorIndex index, ItemTier tier)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			_config = config;
			_index = index;
			_tier = tier;
			if (ColorIndex < 0 || ColorIndex >= ColorCatalog.indexToColor32.Length)
			{
				throw new ArgumentOutOfRangeException("index", string.Format("{0} must be in range [0,{1}]", "index", ColorCatalog.indexToColor32.Length));
			}
			InitSynchronization();
		}

		private void InitSynchronization()
		{
			//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)
			ColorCatalog.indexToColor32[ColorIndex] = Color32.op_Implicit(_config.Value);
			_config.SettingChanged += OnColorChanged;
		}

		private void UpdatePickupsColor()
		{
			//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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Color value = _config.Value;
			ColorCatalog.indexToColor32[ColorIndex] = Color32.op_Implicit(value);
			foreach (PickupDef item in PickupCatalog.allPickups.Where((PickupDef x) => x.itemTier == _tier))
			{
				item.baseColor = value;
			}
		}

		private void OnColorChanged(object sender, EventArgs e)
		{
			UpdatePickupsColor();
		}

		public void Dispose()
		{
			_config.SettingChanged -= OnColorChanged;
		}
	}
}