Decompiled source of AutoScrapper v0.4.0

AutoScrapper.dll

Decompiled a week 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.Bootstrap;
using BepInEx.Configuration;
using On.RoR2;
using On.RoR2.UI.MainMenu;
using R2API;
using R2API.Networking;
using R2API.Networking.Interfaces;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using RoR2.ContentManagement;
using RoR2.UI.MainMenu;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("AutoScrapper")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AutoScrapper")]
[assembly: AssemblyTitle("AutoScrapper")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace AutoScrapper;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("TheAshenWolf.AutoScrapper", "AutoScrapper", "0.3.0")]
public class AutoScrapper : BaseUnityPlugin
{
	public const string PLUGIN_GUID = "TheAshenWolf.AutoScrapper";

	public const string PLUGIN_AUTHOR = "TheAshenWolf";

	public const string PLUGIN_NAME = "AutoScrapper";

	public const string PLUGIN_VERSION = "0.3.0";

	public AutoScrapperConfig config;

	private bool _configInitialized = false;

	[Client]
	private void Awake()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		MainMenuController.Awake += new hook_Awake(MainMenuController_Awake);
		Interactor.AttemptInteraction += new hook_AttemptInteraction(Interactor_AttemptInteraction);
		NetworkingAPI.RegisterMessageType<ScrapSync>();
	}

	[Client]
	private void OnDestroy()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		MainMenuController.Awake -= new hook_Awake(MainMenuController_Awake);
		Interactor.AttemptInteraction -= new hook_AttemptInteraction(Interactor_AttemptInteraction);
	}

	[Client]
	private void MainMenuController_Awake(orig_Awake orig, MainMenuController self)
	{
		orig.Invoke(self);
		if (!_configInitialized)
		{
			config = new AutoScrapperConfig();
			_configInitialized = true;
		}
	}

	[Client]
	private void Interactor_AttemptInteraction(orig_AttemptInteraction orig, Interactor self, GameObject interactable)
	{
		//IL_009e: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: 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)
		if (!config.ModEnabled)
		{
			orig.Invoke(self, interactable);
			return;
		}
		if (((Object)interactable).name.StartsWith("Scrapper"))
		{
			CharacterBody component = ((Component)self).GetComponent<CharacterBody>();
			if ((Object)(object)component == (Object)null)
			{
				Debug.LogWarning((object)"AutoScrapper: Local body is null. Cannot scrap items automatically.");
				orig.Invoke(self, interactable);
				return;
			}
			Inventory inventory = component.inventory;
			bool flag = false;
			ScrapperReportCount scrapperReportCount = default(ScrapperReportCount);
			Dictionary<ItemIndex, int> itemsToRemove = new Dictionary<ItemIndex, int>();
			for (int num = inventory.itemAcquisitionOrder.Count - 1; num >= 0; num--)
			{
				ItemIndex val = inventory.itemAcquisitionOrder[num];
				int itemCountPermanent = inventory.GetItemCountPermanent(val);
				if (itemCountPermanent != 0)
				{
					int num2 = ((!config.ScrapEverything) ? config.GetLimit(val) : 0);
					if (num2 > -1)
					{
						ItemDef itemDef = ItemCatalog.GetItemDef(val);
						int count = itemCountPermanent - num2;
						if (ScrapItem(itemsToRemove, itemDef, count))
						{
							scrapperReportCount.Add(itemDef.tier, count);
							flag = true;
						}
					}
				}
			}
			if (flag)
			{
				NetMessageExtensions.Send((INetMessage)(object)new ScrapSync(component.networkIdentity.netId, itemsToRemove), (NetworkDestination)2);
				if (config.KeepScrapperClosed)
				{
					return;
				}
			}
		}
		orig.Invoke(self, interactable);
	}

	[Client]
	private bool ScrapItem(Dictionary<ItemIndex, int> itemsToRemove, ItemDef itemDef, int count)
	{
		//IL_0014: 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_006c: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Invalid comparison between Unknown and I4
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		if (count <= 0)
		{
			return false;
		}
		if (Utility.IsScrap(itemDef.itemIndex))
		{
			return false;
		}
		if (!itemDef.canRemove)
		{
			return false;
		}
		if (itemDef.isConsumed)
		{
			return false;
		}
		if (Utility.BLACKLIST.Contains(((Object)itemDef).name))
		{
			return false;
		}
		ItemTier tier = itemDef.tier;
		ItemIndex scrapItemIndex = Utility.GetScrapItemIndex(tier);
		if ((int)scrapItemIndex == -1)
		{
			return false;
		}
		itemsToRemove.Add(itemDef.itemIndex, count);
		return true;
	}
}
public class AutoScrapperConfig
{
	private ConfigFile[] _configs;

	public Dictionary<ItemIndex, ConfigEntry<int>>[] configEntries;

	private ConfigEntry<bool> _keepScrapperClosedConfig;

	private ConfigEntry<bool> _modEnabledConfig;

	private ConfigEntry<bool> _scrapEverythingConfig;

	private ConfigEntry<ProfileOverride> _profileOverrideConfig;

	private ConfigEntry<string>[] _profileNamesConfig;

	private ItemDef[] _whiteItems;

	private ItemDef[] _greenItems;

	private ItemDef[] _redItems;

	private ItemDef[] _yellowItems;

	public bool KeepScrapperClosed => _keepScrapperClosedConfig.Value;

	public bool ModEnabled => _modEnabledConfig.Value;

	public bool ScrapEverything => _scrapEverythingConfig.Value;

	public AutoScrapperConfig()
	{
		_configs = (ConfigFile[])(object)new ConfigFile[4];
		_profileNamesConfig = new ConfigEntry<string>[3];
		SetupConfig();
		if (RiskOfOptionsCompatibility.Enabled)
		{
			RiskOfOptionsCompatibility.SetModDescriptionToken("AUTO_SCRAPPER_MOD_DESCRIPTION");
			RiskOfOptionsCompatibility.SetModIcon();
		}
	}

	private void SetupConfig()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Expected O, but got Unknown
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Expected O, but got Unknown
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Expected O, but got Unknown
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Expected O, but got Unknown
		GatherItems();
		Utility.EnsureConfigCompatibilityWithOldVersion();
		_configs[0] = new ConfigFile(Utility.MAIN_CONFIG_PATH, true);
		for (int i = 1; i < 4; i++)
		{
			_configs[i] = new ConfigFile(Utility.ConfigPath(i), true);
		}
		ConfigFile val = _configs[0];
		_modEnabledConfig = val.Bind<bool>("General", "ModEnabled", true, new ConfigDescription(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_MOD_ENABLED_DESC").SanitizeIfLocalized(RiskOfOptionsCompatibility.SupportsCustomTranslation), (AcceptableValueBase)null, Array.Empty<object>()));
		_keepScrapperClosedConfig = val.Bind<bool>("General", "KeepScrapperClosed", true, new ConfigDescription(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_KEEP_SCRAPPER_CLOSED_DESC").SanitizeIfLocalized(RiskOfOptionsCompatibility.SupportsCustomTranslation), (AcceptableValueBase)null, Array.Empty<object>()));
		_scrapEverythingConfig = val.Bind<bool>("General", "ScrapEverything", false, new ConfigDescription(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_SCRAP_EVERYTHING_DESC").SanitizeIfLocalized(RiskOfOptionsCompatibility.SupportsCustomTranslation), (AcceptableValueBase)null, Array.Empty<object>()));
		_profileOverrideConfig = val.Bind<ProfileOverride>("General", "ProfileOverride", ProfileOverride.None, new ConfigDescription(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_PROFILE_OVERRIDE_DESC").SanitizeIfLocalized(RiskOfOptionsCompatibility.SupportsCustomTranslation), (AcceptableValueBase)null, Array.Empty<object>()));
		for (int j = 0; j < 3; j++)
		{
			_profileNamesConfig[j] = val.Bind<string>("General", "ProfileName_" + (j + 1), "Profile " + (j + 1), new ConfigDescription(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_PROFILE_RENAME_DESC").SanitizeIfLocalized(RiskOfOptionsCompatibility.SupportsCustomTranslation), (AcceptableValueBase)null, Array.Empty<object>()));
		}
		if (RiskOfOptionsCompatibility.Enabled)
		{
			string profileName = GetProfileName(0);
			RiskOfOptionsCompatibility.AddBoolOption(0, _modEnabledConfig, profileName, "AUTO_SCRAPPER_MOD_ENABLED", "AUTO_SCRAPPER_MOD_ENABLED_DESC");
			RiskOfOptionsCompatibility.AddBoolOption(0, _keepScrapperClosedConfig, profileName, "AUTO_SCRAPPER_KEEP_SCRAPPER_CLOSED", "AUTO_SCRAPPER_KEEP_SCRAPPER_CLOSED_DESC");
			RiskOfOptionsCompatibility.AddBoolOption(0, _scrapEverythingConfig, profileName, "AUTO_SCRAPPER_SCRAP_EVERYTHING", "AUTO_SCRAPPER_SCRAP_EVERYTHING_DESC");
			RiskOfOptionsCompatibility.AddDropdownOption<ProfileOverride>(0, _profileOverrideConfig, profileName, "AUTO_SCRAPPER_PROFILE_OVERRIDE", "AUTO_SCRAPPER_PROFILE_OVERRIDE_DESC");
			for (int k = 0; k < 3; k++)
			{
				RiskOfOptionsCompatibility.AddStringOption(0, _profileNamesConfig[k], profileName, "AUTO_SCRAPPER_PROFILE_RENAME", "AUTO_SCRAPPER_PROFILE_RENAME_DESC", requiresRestart: true);
			}
		}
		int capacity = _whiteItems.Length + _greenItems.Length + _redItems.Length + _yellowItems.Length;
		configEntries = new Dictionary<ItemIndex, ConfigEntry<int>>[4];
		for (int l = 0; l < 4; l++)
		{
			configEntries[l] = new Dictionary<ItemIndex, ConfigEntry<int>>(capacity);
		}
		CreateItemGroupConfigs(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_CATEGORY_WHITE_ITEMS"), _whiteItems, configEntries);
		CreateItemGroupConfigs(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_CATEGORY_GREEN_ITEMS"), _greenItems, configEntries);
		CreateItemGroupConfigs(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_CATEGORY_RED_ITEMS"), _redItems, configEntries);
		CreateItemGroupConfigs(Language.english.GetLocalizedStringByToken("AUTO_SCRAPPER_CATEGORY_YELLOW_ITEMS"), _yellowItems, configEntries);
	}

	private void GatherItems()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected I4, but got Unknown
		ItemDef[] itemDefs = ContentManager._itemDefs;
		int num = itemDefs.Length;
		List<ItemDef> list = new List<ItemDef>(num);
		List<ItemDef> list2 = new List<ItemDef>(num);
		List<ItemDef> list3 = new List<ItemDef>(num);
		List<ItemDef> list4 = new List<ItemDef>(num);
		for (int i = 0; i < num; i++)
		{
			ItemDef val = itemDefs[i];
			if (!((Object)(object)val == (Object)null))
			{
				ItemTier tier = val.tier;
				ItemTier val2 = tier;
				switch ((int)val2)
				{
				case 0:
					list.Add(val);
					break;
				case 1:
					list2.Add(val);
					break;
				case 2:
					list3.Add(val);
					break;
				case 4:
					list4.Add(val);
					break;
				}
			}
		}
		_whiteItems = list.ToArray();
		_greenItems = list2.ToArray();
		_redItems = list3.ToArray();
		_yellowItems = list4.ToArray();
	}

	private void CreateItemGroupConfigs(string section, ItemDef[] items, Dictionary<ItemIndex, ConfigEntry<int>>[] itemConfigs)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		section = section.Sanitize();
		int num = items.Length;
		for (int i = 0; i < num; i++)
		{
			ItemDef val = items[i];
			if (!val.canRemove || val.isConsumed || val.hidden || Utility.IsScrap(val.itemIndex))
			{
				continue;
			}
			bool flag = false;
			int j = 0;
			for (int num2 = Utility.BLACKLIST.Length; j < num2; j++)
			{
				if (((Object)val).name == Utility.BLACKLIST[j])
				{
					flag = true;
					break;
				}
			}
			if (flag)
			{
				continue;
			}
			int valueOrDefault = ConfigOverrides.defaultOverrides.GetValueOrDefault(((Object)val).name, -1);
			for (int k = 0; k < 4; k++)
			{
				ConfigEntry<int> val2 = _configs[k].Bind<int>(section, ((Object)val).name, valueOrDefault, Utility.GetConfigDescription(val, RiskOfOptionsCompatibility.SupportsCustomTranslation));
				itemConfigs[k][val.itemIndex] = val2;
				if (RiskOfOptionsCompatibility.Enabled)
				{
					RiskOfOptionsCompatibility.AddIntOption(k, val2, GetProfileName(k), val.nameToken, Utility.CreateDescriptionToken(val));
				}
			}
		}
	}

	public int GetLimit(ItemIndex index)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		return configEntries[(int)_profileOverrideConfig.Value].GetValueOrDefault(index, null)?.Value ?? (-1);
	}

	public string GetProfileName(int profileIndex)
	{
		if (profileIndex == 0)
		{
			return "AutoScrapper";
		}
		return "AutoScrapper | " + _profileNamesConfig[profileIndex - 1].Value;
	}
}
public static class ConfigOverrides
{
	public static Dictionary<string, int> defaultOverrides = new Dictionary<string, int>
	{
		{ "BleedOnHit", 10 },
		{ "CritGlasses", 9 },
		{ "StickyBomb", 20 },
		{ "Bandolier", 3 },
		{ "BonusGoldPackOnKill", 25 },
		{ "EquipmentMagazine", 254 }
	};
}
public enum ProfileOverride
{
	None,
	Profile1,
	Profile2,
	Profile3
}
public static class RiskOfOptionsCompatibility
{
	private static bool? _isEnabled;

	private static bool? _supportsCustomTranslation;

	public static bool Enabled
	{
		get
		{
			bool valueOrDefault = _isEnabled.GetValueOrDefault();
			if (!_isEnabled.HasValue)
			{
				valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
				_isEnabled = valueOrDefault;
			}
			return _isEnabled.Value;
		}
	}

	public static bool SupportsCustomTranslation
	{
		get
		{
			if (!Enabled)
			{
				return false;
			}
			if (!_supportsCustomTranslation.HasValue)
			{
				Version version = Chainloader.PluginInfos["com.rune580.riskofoptions"].Metadata.Version;
				_supportsCustomTranslation = version == Version.Parse("2.8.3");
			}
			return _supportsCustomTranslation.Value;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void SetModDescriptionToken(string descriptionToken)
	{
		ModSettingsManager.SetModDescriptionToken(descriptionToken, "TheAshenWolf.AutoScrapper", "AutoScrapper");
		for (int i = 1; i < 4; i++)
		{
			ModSettingsManager.SetModDescriptionToken("AUTO_SCRAPPER_PROFILE_DESCRIPTION", Utility.GetProfileGUID(i), "AutoScrapper");
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void SetModIcon()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_005a: 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)
		try
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
			string fullName = new DirectoryInfo(directoryName).FullName;
			Texture2D val = new Texture2D(0, 0);
			if (ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(fullName, "icon.png"))))
			{
				Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
				for (int i = 0; i < 4; i++)
				{
					ModSettingsManager.SetModIcon(val2, Utility.GetProfileGUID(i), "AutoScrapper");
				}
			}
			else
			{
				Debug.LogWarning((object)"AutoScrapper: Failed to load icon.png");
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("AutoScrapper: Failed to load icon.png\n" + ex));
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private static void AddOptionCustomTranslation(BaseOption option, int profileIndex, string profileName, string customNameToken, string customDescriptionToken)
	{
		ModSettingsManager.AddOption(option, Utility.GetProfileGUID(profileIndex), profileName, customNameToken, customDescriptionToken);
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private static void AddOptionNoTranslation(BaseOption option, int profileIndex, string profileName)
	{
		ModSettingsManager.AddOption(option, Utility.GetProfileGUID(profileIndex), profileName);
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static BaseOption AddIntOption(int profileIndex, ConfigEntry<int> configEntry, string profileName, string customNameToken, string customDescriptionToken, bool restartRequired = false)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		BaseOption val = (BaseOption)new IntFieldOption(configEntry, restartRequired);
		if (SupportsCustomTranslation)
		{
			AddOptionCustomTranslation(val, profileIndex, profileName, customNameToken, customDescriptionToken);
		}
		else
		{
			AddOptionNoTranslation(val, profileIndex, profileName);
		}
		return val;
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static BaseOption AddBoolOption(int profileIndex, ConfigEntry<bool> configEntry, string profileName, string customNameToken, string customDescriptionToken, bool requiresRestart = false)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		BaseOption val = (BaseOption)new CheckBoxOption(configEntry, requiresRestart);
		if (SupportsCustomTranslation)
		{
			AddOptionCustomTranslation(val, profileIndex, profileName, customNameToken, customDescriptionToken);
		}
		else
		{
			AddOptionNoTranslation(val, profileIndex, profileName);
		}
		return val;
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static BaseOption AddDropdownOption<T>(int profileIndex, ConfigEntry<T> configEntry, string profileName, string customNameToken, string customDescriptionToken, bool requiresRestart = false) where T : Enum
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		BaseOption val = (BaseOption)new ChoiceOption((ConfigEntryBase)(object)configEntry, requiresRestart);
		bool flag = false;
		AddOptionNoTranslation(val, profileIndex, profileName);
		return val;
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static BaseOption AddStringOption(int profileIndex, ConfigEntry<string> configEntry, string profileName, string customNameToken, string customDescriptionToken, bool requiresRestart = false)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		BaseOption val = (BaseOption)new StringInputFieldOption(configEntry, requiresRestart);
		if (SupportsCustomTranslation)
		{
			AddOptionCustomTranslation(val, profileIndex, profileName, customNameToken, customDescriptionToken);
		}
		else
		{
			AddOptionNoTranslation(val, profileIndex, profileName);
		}
		return val;
	}
}
public struct ScrapperReportCount
{
	public int white;

	public int green;

	public int red;

	public int yellow;

	public void Add(ItemTier tier, int count)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: 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_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected I4, but got Unknown
		switch ((int)tier)
		{
		case 0:
			white += count;
			break;
		case 1:
			green += count;
			break;
		case 2:
			red += count;
			break;
		case 4:
			yellow += count;
			break;
		case 3:
			break;
		}
	}

	public List<string> GetReportParts()
	{
		List<string> list = new List<string>(4);
		if (white > 0)
		{
			list.Add(Language.GetStringFormatted((white > 1) ? "AUTO_SCRAPPER_WHITE_ITEMS_PLURAL" : "AUTO_SCRAPPER_WHITE_ITEMS", new object[2] { white, "<color=#FFFFFF>" }));
		}
		if (green > 0)
		{
			list.Add(Language.GetStringFormatted((green > 1) ? "AUTO_SCRAPPER_GREEN_ITEMS_PLURAL" : "AUTO_SCRAPPER_GREEN_ITEMS", new object[2] { green, "<color=#00FF00>" }));
		}
		if (red > 0)
		{
			list.Add(Language.GetStringFormatted((red > 1) ? "AUTO_SCRAPPER_RED_ITEMS_PLURAL" : "AUTO_SCRAPPER_RED_ITEMS", new object[2] { red, "<color=#FF0000>" }));
		}
		if (yellow > 0)
		{
			list.Add(Language.GetStringFormatted((yellow > 1) ? "AUTO_SCRAPPER_YELLOW_ITEMS_PLURAL" : "AUTO_SCRAPPER_YELLOW_ITEMS", new object[2] { yellow, "<color=#FFFF00>" }));
		}
		return list;
	}
}
public class ScrapSync : INetMessage, ISerializableObject
{
	private NetworkInstanceId _networkId;

	private Dictionary<ItemIndex, int> _itemsToRemove;

	public ScrapSync()
	{
		//IL_0009: 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)
		_networkId = NetworkInstanceId.Invalid;
		_itemsToRemove = new Dictionary<ItemIndex, int>();
	}

	public ScrapSync(NetworkInstanceId networkId, Dictionary<ItemIndex, int> itemsToRemove)
	{
		//IL_0009: 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)
		_networkId = networkId;
		_itemsToRemove = itemsToRemove;
	}

	public void Serialize(NetworkWriter writer)
	{
		//IL_0003: 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)
		writer.Write(_networkId);
		writer.Write(_itemsToRemove.Count);
		foreach (KeyValuePair<ItemIndex, int> item in _itemsToRemove)
		{
			NetworkExtensions.Write(writer, item.Key);
			writer.Write(item.Value);
		}
	}

	public void Deserialize(NetworkReader reader)
	{
		//IL_0003: 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_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_0039: Unknown result type (might be due to invalid IL or missing references)
		_networkId = reader.ReadNetworkId();
		int num = reader.ReadInt32();
		_itemsToRemove = new Dictionary<ItemIndex, int>(num);
		for (int i = 0; i < num; i++)
		{
			ItemIndex key = NetworkExtensions.ReadItemIndex(reader);
			int value = reader.ReadInt32();
			_itemsToRemove.Add(key, value);
		}
	}

	public void OnReceived()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: 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_00f7: 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_0143: 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)
		if (!NetworkServer.active)
		{
			return;
		}
		GameObject val = NetworkServer.FindLocalObject(_networkId);
		CharacterBody val2 = ((val != null) ? val.GetComponent<CharacterBody>() : null);
		if ((Object)(object)val2 == (Object)null)
		{
			Debug.LogWarning((object)"AutoScrapper: Local body is null. Cannot scrap items automatically.");
			return;
		}
		Inventory inventory = val2.inventory;
		if ((Object)(object)inventory == (Object)null)
		{
			Debug.LogWarning((object)"AutoScrapper: Local inventory is null. Cannot scrap items automatically.");
			return;
		}
		ScrapperReportCount count = default(ScrapperReportCount);
		foreach (var (val4, num2) in _itemsToRemove)
		{
			count.Add(ItemCatalog.GetItemDef(val4).tier, num2);
			inventory.RemoveItemPermanent(val4, num2);
		}
		if (count.white > 0)
		{
			inventory.GiveItemPermanent(Items.ScrapWhite.itemIndex, count.white);
		}
		if (count.green > 0)
		{
			inventory.GiveItemPermanent(Items.ScrapGreen.itemIndex, count.green);
		}
		if (count.red > 0)
		{
			inventory.GiveItemPermanent(Items.ScrapRed.itemIndex, count.red);
		}
		if (count.yellow > 0)
		{
			inventory.GiveItemPermanent(Items.ScrapYellow.itemIndex, count.yellow);
		}
		Utility.ReportResults(val2.GetUserName(), count);
	}
}
public static class Tokens
{
	public const string MOD_DESCRIPTION = "AUTO_SCRAPPER_MOD_DESCRIPTION";

	public const string AUTOMAGICALLY_SCRAPPED = "AUTO_SCRAPPER_AUTOMAGICALLY_SCRAPPED";

	public const string WHITE_ITEMS = "AUTO_SCRAPPER_WHITE_ITEMS";

	public const string GREEN_ITEMS = "AUTO_SCRAPPER_GREEN_ITEMS";

	public const string RED_ITEMS = "AUTO_SCRAPPER_RED_ITEMS";

	public const string YELLOW_ITEMS = "AUTO_SCRAPPER_YELLOW_ITEMS";

	public const string WHITE_ITEMS_PLURAL = "AUTO_SCRAPPER_WHITE_ITEMS_PLURAL";

	public const string GREEN_ITEMS_PLURAL = "AUTO_SCRAPPER_GREEN_ITEMS_PLURAL";

	public const string RED_ITEMS_PLURAL = "AUTO_SCRAPPER_RED_ITEMS_PLURAL";

	public const string YELLOW_ITEMS_PLURAL = "AUTO_SCRAPPER_YELLOW_ITEMS_PLURAL";

	public const string AND = "AUTO_SCRAPPER_AND";

	public const string PROFILE_DESCRIPTION = "AUTO_SCRAPPER_PROFILE_DESCRIPTION";

	public const string AMOUNT_OF_X_TO_KEEP = "AUTO_SCRAPPER_AMOUNT_OF_X_TO_KEEP";

	public const string NUMBER_EXPLANATION = "AUTO_SCRAPPER_NUMBER_EXPLANATION";

	public const string KEEP_SCRAPPER_CLOSED = "AUTO_SCRAPPER_KEEP_SCRAPPER_CLOSED";

	public const string KEEP_SCRAPPER_CLOSED_DESC = "AUTO_SCRAPPER_KEEP_SCRAPPER_CLOSED_DESC";

	public const string MOD_ENABLED = "AUTO_SCRAPPER_MOD_ENABLED";

	public const string MOD_ENABLED_DESC = "AUTO_SCRAPPER_MOD_ENABLED_DESC";

	public const string SCRAP_EVERYTHING = "AUTO_SCRAPPER_SCRAP_EVERYTHING";

	public const string SCRAP_EVERYTHING_DESC = "AUTO_SCRAPPER_SCRAP_EVERYTHING_DESC";

	public const string PROFILE_OVERRIDE = "AUTO_SCRAPPER_PROFILE_OVERRIDE";

	public const string PROFILE_OVERRIDE_DESC = "AUTO_SCRAPPER_PROFILE_OVERRIDE_DESC";

	public const string PROFILE_RENAME = "AUTO_SCRAPPER_PROFILE_RENAME";

	public const string PROFILE_RENAME_DESC = "AUTO_SCRAPPER_PROFILE_RENAME_DESC";

	public const string CATEGORY_GENERAL = "AUTO_SCRAPPER_CATEGORY_GENERAL";

	public const string CATEGORY_WHITE_ITEMS = "AUTO_SCRAPPER_CATEGORY_WHITE_ITEMS";

	public const string CATEGORY_GREEN_ITEMS = "AUTO_SCRAPPER_CATEGORY_GREEN_ITEMS";

	public const string CATEGORY_RED_ITEMS = "AUTO_SCRAPPER_CATEGORY_RED_ITEMS";

	public const string CATEGORY_YELLOW_ITEMS = "AUTO_SCRAPPER_CATEGORY_YELLOW_ITEMS";
}
public static class Utility
{
	public const string COLOR_TEXT = "<color=#DDDDDD>";

	public const string COLOR_WHITE = "<color=#FFFFFF>";

	public const string COLOR_GREEN = "<color=#00FF00>";

	public const string COLOR_RED = "<color=#FF0000>";

	public const string COLOR_YELLOW = "<color=#FFFF00>";

	public const string COLOR_PLAYER = "<color=#2083fc>";

	public const int ALT_PROFILE_COUNT = 3;

	public const int PROFILE_COUNT = 4;

	public static readonly string OLD_CONFIG_PATH = Paths.ConfigPath + "\\TheAshenWolf.AutoScrapper.cfg";

	public static readonly string MAIN_CONFIG_PATH = Paths.ConfigPath + "\\TheAshenWolf.AutoScrapper\\Main.cfg";

	public static readonly string[] BLACKLIST = new string[1] { "ArtifactKey" };

	public static string ConfigPath(int profileIndex)
	{
		return Paths.ConfigPath + "\\TheAshenWolf.AutoScrapper\\Profile" + profileIndex + ".cfg";
	}

	public static ItemIndex GetScrapItemIndex(ItemTier tier)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected I4, but got Unknown
		//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_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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_005d: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		if (1 == 0)
		{
		}
		ItemIndex result = (ItemIndex)((int)tier switch
		{
			0 => Items.ScrapWhite.itemIndex, 
			1 => Items.ScrapGreen.itemIndex, 
			2 => Items.ScrapRed.itemIndex, 
			4 => Items.ScrapYellow.itemIndex, 
			_ => -1, 
		});
		if (1 == 0)
		{
		}
		return result;
	}

	public static bool IsScrap(ItemIndex index)
	{
		//IL_0001: 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_000e: 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_001b: 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_0028: 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)
		return index == Items.ScrapWhite.itemIndex || index == Items.ScrapGreen.itemIndex || index == Items.ScrapRed.itemIndex || index == Items.ScrapYellow.itemIndex;
	}

	public static string GetFormattedName(ItemDef item)
	{
		//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)
		//IL_0026: Expected I4, but got Unknown
		ItemTier tier = item.tier;
		if (1 == 0)
		{
		}
		string text = (int)tier switch
		{
			0 => "<color=#FFFFFF>", 
			1 => "<color=#00FF00>", 
			2 => "<color=#FF0000>", 
			4 => "<color=#FFFF00>", 
			_ => "<color=#FFFFFF>", 
		};
		if (1 == 0)
		{
		}
		string text2 = text;
		return text2 + Language.GetString(item.nameToken) + "</color>";
	}

	public static void ReportResults(string userName, ScrapperReportCount count)
	{
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Expected O, but got Unknown
		List<string> reportParts = count.GetReportParts();
		int count2 = reportParts.Count;
		if (count2 == 0)
		{
			return;
		}
		string text = "<color=#2083fc>" + userName + "</color> <color=#DDDDDD>" + Language.GetString("AUTO_SCRAPPER_AUTOMAGICALLY_SCRAPPED") + " ";
		if (count2 == 1)
		{
			text = text + reportParts[0] + ".";
		}
		else if (count2 == 2)
		{
			text = text + reportParts[0] + " " + Language.GetString("AUTO_SCRAPPER_AND") + " " + reportParts[1] + ".";
		}
		else if (count2 > 2)
		{
			for (int i = 0; i < count2; i++)
			{
				if (i > 0)
				{
					text = ((i != count2 - 1) ? (text + ", ") : (text + ", " + Language.GetString("AUTO_SCRAPPER_AND") + " "));
				}
				text += reportParts[i];
			}
			text += ".";
		}
		text += "</color>";
		SimpleChatMessage val = new SimpleChatMessage();
		val.baseToken = text;
		Chat.SendBroadcastChat((ChatMessageBase)(object)val);
	}

	public static string GetProfileGUID(int profileIndex)
	{
		if (profileIndex == 0)
		{
			return "TheAshenWolf.AutoScrapper";
		}
		return "TheAshenWolf.AutoScrapper_" + profileIndex;
	}

	public static void EnsureConfigCompatibilityWithOldVersion()
	{
		string directoryName = Path.GetDirectoryName(MAIN_CONFIG_PATH);
		if (!Directory.Exists(directoryName))
		{
			if (directoryName == null)
			{
				throw new DirectoryNotFoundException("AutoScrapper: Config directory path is null");
			}
			Directory.CreateDirectory(directoryName);
		}
		if (File.Exists(OLD_CONFIG_PATH))
		{
			File.Copy(OLD_CONFIG_PATH, MAIN_CONFIG_PATH, overwrite: true);
			File.Delete(OLD_CONFIG_PATH);
		}
	}

	public static string Sanitize(this string text)
	{
		text = Regex.Replace(text, "<.*?>", string.Empty);
		text = text.Replace("\n", string.Empty);
		return text;
	}

	public static string SanitizeIfLocalized(this string text, bool localizationSupported)
	{
		return localizationSupported ? text.Sanitize() : text;
	}

	public static ConfigDescription GetConfigDescription(ItemDef item, bool customTranslationSupported)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		if (customTranslationSupported)
		{
			return new ConfigDescription("Amount of " + ((Object)item).name + " to keep before scrapping. \n0 = scrap all, -1 = don't scrap", (AcceptableValueBase)null, Array.Empty<object>());
		}
		return new ConfigDescription("<color=#DDDDDD>" + Language.GetStringFormatted("AUTO_SCRAPPER_AMOUNT_OF_X_TO_KEEP", new object[1] { GetFormattedName(item) }) + "</color>\r\n\r\n<i>" + Language.GetString(item.descriptionToken) + "</i>\r\n\r\n<color=#DDDDDD>0 = scrap all, -1 = don't scrap</color>", (AcceptableValueBase)null, Array.Empty<object>());
	}

	public static string CreateDescriptionToken(ItemDef item)
	{
		string @string = Language.GetString(item.descriptionToken);
		string formattedName = GetFormattedName(item);
		string stringFormatted = Language.GetStringFormatted("AUTO_SCRAPPER_AMOUNT_OF_X_TO_KEEP", new object[1] { formattedName });
		stringFormatted = stringFormatted + "\n\n<i>" + @string + "</i>";
		stringFormatted = stringFormatted + "\n\n<color=#DDDDDD>" + Language.GetString("AUTO_SCRAPPER_NUMBER_EXPLANATION") + "</color>";
		string text = item.nameToken + "_AUTO_SCRAPPER_DESCRIPTION";
		LanguageAPI.Add(text, stringFormatted, Language.currentLanguageName);
		return text;
	}
}