Decompiled source of Benthic Rebloomed AI Fork v1.2.0

Benthic_Rebloomed_AI_Fork\BenthicRework.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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 BenthicRework
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Braquen.Benthic_Rebloomed", "Benthic_Rebloomed", "1.2.0")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class BenthicRework : BaseUnityPlugin
	{
		private ConfigEntry<int> stacksUpgraded;

		private ConfigEntry<int> itemsAdded;

		private ConfigEntry<bool> upgradeLunars;

		private ConfigEntry<bool> upgradeSelf;

		private ConfigEntry<string> itemBlacklist;

		private ConfigEntry<bool> announceUpgrades;

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

		private string historyPath;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_0117: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected O, but got Unknown
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Expected O, but got Unknown
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Expected O, but got Unknown
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Expected O, but got Unknown
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Expected O, but got Unknown
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "braquen-BenthicRebloomed.cfg"), true);
			stacksUpgraded = val.Bind<int>("Benthic Stats", "Stacks Upgraded", 3, "Number of existing item stacks to boost per Benthic Bloom at the start of each stage. Set to 0 for vanilla behavior.");
			itemsAdded = val.Bind<int>("Benthic Stats", "Items Granted", 2, "Number of copies added to each chosen stack. Set to 0 for vanilla behavior.");
			upgradeLunars = val.Bind<bool>("Allowed Upgrades", "Allow Lunar Upgrades", false, "Let Benthic Bloom add copies to Lunar item stacks.");
			upgradeSelf = val.Bind<bool>("Allowed Upgrades", "Allow Self Upgrade", false, "Let Benthic Bloom add copies of itself. Very powerful.");
			itemBlacklist = val.Bind<string>("Allowed Upgrades", "Item Blacklist", "", "Comma-separated item names or internal IDs that Benthic Bloom must never boost. Example: Crowbar, Soldier's Syringe, CloverVoid. Item names use the host's game language.");
			announceUpgrades = val.Bind<bool>("Reporting", "Show Stage Summary In Chat", true, "Show one short chat summary of the upgraded item stacks for each player at the start of a stage.");
			historyPath = Path.Combine(Paths.ConfigPath, "BenthicRebloomed-history.log");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(stacksUpgraded, new IntSliderConfig
			{
				min = 0,
				max = 100,
				category = "1. Bloom Strength",
				name = "Item stacks boosted per Bloom",
				description = "How many existing item stacks each Benthic Bloom boosts per stage. 0 restores the original Benthic Bloom effect."
			}));
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(itemsAdded, new IntSliderConfig
			{
				min = 0,
				max = 100,
				category = "1. Bloom Strength",
				name = "Copies added to each stack",
				description = "How many extra copies each selected item stack receives. 0 restores the original Benthic Bloom effect."
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(upgradeLunars, new CheckBoxConfig
			{
				category = "2. Item Rules",
				name = "Boost Lunar items",
				description = "Allow Lunar item stacks to receive extra copies. Off by default."
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(upgradeSelf, new CheckBoxConfig
			{
				category = "2. Item Rules",
				name = "Boost Benthic Bloom itself",
				description = "Allow Bloom to increase its own stack count. Extremely strong; off by default."
			}));
			ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(itemBlacklist, new InputFieldConfig
			{
				category = "2. Item Rules",
				name = "Item blacklist",
				description = "These items will never receive extra copies. Separate names or internal IDs with commas, e.g. Crowbar, Soldier's Syringe. Changes apply on the host at the next stage.",
				submitOn = (SubmitEnum)6,
				richText = false
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(announceUpgrades, new CheckBoxConfig
			{
				category = "3. Notifications",
				name = "Show upgrades in chat",
				description = "Post one concise, color-coded upgrade summary per player on each stage transition."
			}));
			ModSettingsManager.SetModDescription("Benthic Bloom adds copies to your existing items instead of replacing them. Pick how many stacks to boost, exclude specific items, and see the results in chat.");
			Sprite val2 = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/DLC1/CloverVoid/texCloverVoidIcon.png").WaitForCompletion();
			if ((Object)(object)val2 != (Object)null)
			{
				ModSettingsManager.SetModIcon(val2);
			}
			itemBlacklist.SettingChanged += delegate
			{
				RefreshBlacklist();
			};
			RefreshBlacklist();
			stacksUpgraded.SettingChanged += delegate
			{
				UpdateText();
			};
			itemsAdded.SettingChanged += delegate
			{
				UpdateText();
			};
			UpdateText();
			CharacterMaster.TryCloverVoidUpgrades += new hook_TryCloverVoidUpgrades(TryCloverVoidUpgrades);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Benthic Rebloomed 1.2.0 hook registered.");
		}

		private void OnDestroy()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			CharacterMaster.TryCloverVoidUpgrades -= new hook_TryCloverVoidUpgrades(TryCloverVoidUpgrades);
		}

		private void RefreshBlacklist()
		{
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			string[] array = (itemBlacklist.Value ?? "").Split(new char[4] { ',', ';', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array.Length; i++)
			{
				string text = NormalizeName(array[i]);
				if (text.Length > 0)
				{
					hashSet.Add(text);
				}
			}
			excludedItems = hashSet;
		}

		private static string NormalizeName(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder(text.Length);
			foreach (char c in text)
			{
				if (char.IsLetterOrDigit(c))
				{
					stringBuilder.Append(char.ToLowerInvariant(c));
				}
			}
			return stringBuilder.ToString();
		}

		private bool IsBlacklisted(ItemDef item)
		{
			if ((Object)(object)item == (Object)null || excludedItems.Count == 0)
			{
				return false;
			}
			if (excludedItems.Contains(NormalizeName(((Object)item).name)))
			{
				return true;
			}
			if (excludedItems.Contains(NormalizeName(item.nameToken)))
			{
				return true;
			}
			return excludedItems.Contains(NormalizeName(Language.GetString(item.nameToken)));
		}

		private void TryCloverVoidUpgrades(orig_TryCloverVoidUpgrades orig, CharacterMaster master)
		{
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Invalid comparison between Unknown and I4
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Invalid comparison between Unknown and I4
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: 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_0275: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				return;
			}
			if (stacksUpgraded.Value <= 0 || itemsAdded.Value <= 0)
			{
				orig.Invoke(master);
				return;
			}
			Inventory inventory = master.inventory;
			if ((Object)(object)inventory == (Object)null)
			{
				orig.Invoke(master);
				return;
			}
			int itemCountPermanent = inventory.GetItemCountPermanent(Items.CloverVoid);
			if (itemCountPermanent <= 0)
			{
				orig.Invoke(master);
				return;
			}
			List<ItemIndex> list = new List<ItemIndex>();
			foreach (ItemIndex item in inventory.itemAcquisitionOrder)
			{
				if (inventory.GetItemCountPermanent(item) > 0)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(item);
					if (!((Object)(object)itemDef == (Object)null) && (item != Items.CloverVoid.itemIndex || upgradeSelf.Value) && (int)itemDef.tier != 5 && ((int)itemDef.tier != 3 || upgradeLunars.Value) && !IsBlacklisted(itemDef))
					{
						list.Add(item);
					}
				}
			}
			if (list.Count == 0)
			{
				return;
			}
			long num = (long)itemCountPermanent * (long)Math.Max(0, stacksUpgraded.Value);
			int num2 = 0;
			Dictionary<ItemIndex, int> dictionary = new Dictionary<ItemIndex, int>();
			List<ItemIndex> list2 = new List<ItemIndex>();
			while (num > 0)
			{
				ItemIndex val = list[num2];
				inventory.GiveItemPermanent(val, itemsAdded.Value);
				if (!dictionary.ContainsKey(val))
				{
					dictionary.Add(val, 0);
					list2.Add(val);
				}
				dictionary[val] += itemsAdded.Value;
				num--;
				num2++;
				if (num2 >= list.Count)
				{
					num2 = 0;
				}
			}
			foreach (ItemIndex item2 in list2)
			{
				CharacterMasterNotificationQueue.PushItemNotification(master, item2);
			}
			GameObject bodyObject = master.GetBodyObject();
			if ((Object)(object)bodyObject != (Object)null)
			{
				Util.PlaySound("Play_item_proc_extraLife", bodyObject);
			}
			int stage = (((Object)(object)Run.instance != (Object)null) ? (Run.instance.stageClearCount + 1) : 0);
			string playerName = GetPlayerName(master);
			StringBuilder stringBuilder = new StringBuilder();
			foreach (ItemIndex item3 in list2)
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append(", ");
				}
				stringBuilder.Append(GetItemName(item3)).Append(" +").Append(dictionary[item3]);
			}
			string text = "[Benthic Bloom] " + playerName + " | Stage " + stage + ": " + stringBuilder;
			((BaseUnityPlugin)this).Logger.LogInfo((object)text);
			try
			{
				File.AppendAllText(historyPath, DateTime.UtcNow.ToString("o") + " " + text + Environment.NewLine);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Unable to write Benthic Bloom history: " + ex.Message));
			}
			if (announceUpgrades.Value)
			{
				string baseToken = MakeChatSummary(playerName, stage, list2, dictionary);
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = baseToken
				});
			}
		}

		private static string GetPlayerName(CharacterMaster master)
		{
			PlayerCharacterMasterController playerCharacterMasterController = master.playerCharacterMasterController;
			if ((Object)(object)playerCharacterMasterController != (Object)null && (Object)(object)playerCharacterMasterController.networkUser != (Object)null && !string.IsNullOrWhiteSpace(playerCharacterMasterController.networkUser.userName))
			{
				return playerCharacterMasterController.networkUser.userName;
			}
			return ((Object)master).name;
		}

		private unsafe static string GetItemName(ItemIndex item)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			ItemDef itemDef = ItemCatalog.GetItemDef(item);
			if (!((Object)(object)itemDef != (Object)null))
			{
				return ((object)(*(ItemIndex*)(&item))/*cast due to .constrained prefix*/).ToString();
			}
			return Language.GetString(itemDef.nameToken);
		}

		private static string EscapeChatText(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return "?";
			}
			value = value.Replace('<', '(').Replace('>', ')').Replace('\r', ' ')
				.Replace('\n', ' ');
			if (value.Length <= 72)
			{
				return value;
			}
			return value.Substring(0, 69) + "...";
		}

		private static string MakeChatSummary(string player, int stage, List<ItemIndex> displayOrder, Dictionary<ItemIndex, int> awarded)
		{
			//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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("<color=#B994FF><b>Benthic Bloom</b></color> ").Append("<color=#B6B6C1>Stage ").Append(stage)
				.Append("</color> | ")
				.Append(EscapeChatText(player))
				.Append(": ");
			int num = Math.Min(4, displayOrder.Count);
			for (int i = 0; i < num; i++)
			{
				if (i > 0)
				{
					stringBuilder.Append(", ");
				}
				ItemIndex val = displayOrder[i];
				stringBuilder.Append("<color=#88E6B6>+").Append(awarded[val]).Append("</color> ")
					.Append(EscapeChatText(GetItemName(val)));
			}
			int num2 = displayOrder.Count - num;
			if (num2 > 0)
			{
				stringBuilder.Append(" <color=#B6B6C1>and ").Append(num2).Append(" more item types</color>");
			}
			return stringBuilder.ToString();
		}

		private void UpdateText()
		{
			if (itemsAdded.Value <= 0 || stacksUpgraded.Value <= 0)
			{
				LanguageAPI.Add("ITEM_CLOVERVOID_DESC", "Upgrades <style=cIsUtility>3</style> <style=cStack>(+3 per stack)</style> random items to items of the next higher rarity at the <style=cIsUtility>start of each stage</style>. <style=cIsVoid>Corrupts all 57 Leaf Clovers</style>.");
				LanguageAPI.Add("ITEM_CLOVERVOID_PICKUP", "Upgrades your items at the start of each stage.");
				return;
			}
			LanguageAPI.Add("ITEM_CLOVERVOID_DESC", "Adds <style=cIsUtility>" + itemsAdded.Value + "</style> copies to each of <style=cIsUtility>" + stacksUpgraded.Value + "</style> <style=cStack>(+" + stacksUpgraded.Value + " per Benthic Bloom)</style> existing item stacks at the <style=cIsUtility>start of each stage</style>. <style=cIsVoid>Corrupts all 57 Leaf Clovers</style>.");
			LanguageAPI.Add("ITEM_CLOVERVOID_PICKUP", "Adds copies to existing items at the start of each stage.");
		}
	}
}