using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using On.RoR2;
using R2API;
using RoR2;
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("ConfigurableBenthic")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ConfigurableBenthic")]
[assembly: AssemblyTitle("ConfigurableBenthic")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ConfigurableBenthic;
public enum OverspillBonus
{
None,
PlusOne,
Duplicate
}
public enum SelectMethod
{
Random,
LeastStacks,
MostStacks
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.kking117.ConfigurableBenthic", "ConfigurableBenthic", "1.1.0")]
public class MainPlugin : BaseUnityPlugin
{
public const string MODUID = "com.kking117.ConfigurableBenthic";
public const string MODNAME = "ConfigurableBenthic";
public const string MODTOKEN = "KKING117_CONFIGBENTHIC_";
public const string MODVERSION = "1.1.0";
public static int Config_BaseCount = 3;
public static int Config_StackCount = 3;
public static string Config_BlackList = "";
public static bool Config_WholeStack = true;
public static SelectMethod Config_Select_Method = SelectMethod.Random;
public static bool Config_Select_PreferScrap = false;
public static bool Config_Select_AllowVoid = false;
public static bool Config_Select_AllowSelf = true;
public static bool Config_RefreshOnUpgrade;
public static bool Config_Overspill_Enable = false;
public static OverspillBonus Config_Overspill_Bonus = OverspillBonus.PlusOne;
private static bool NewDesc = false;
public static List<ItemDef> BanList;
private void Awake()
{
ReadConfig();
if (Config_BaseCount != 3 || Config_StackCount != 3)
{
UpdateText();
}
Hooks();
}
private static void Hooks()
{
//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
ItemCatalog.Init += new hook_Init(ItemCatalog_Init);
CharacterMaster.TryCloverVoidUpgrades += new hook_TryCloverVoidUpgrades(CloverVoidUpgrade);
}
private static void UpdateText()
{
string text = $"<style=cIsUtility>Upgrades {Config_BaseCount}</style> <style=cStack>(+{Config_StackCount} per stack)</style> random items to items of the next <style=cIsUtility>higher rarity</style> at the <style=cIsUtility>start of each stage</style>. <style=cIsVoid>Corrupts all 57 Leaf Clovers</style>.";
LanguageAPI.Add("KKING117_CONFIGBENTHIC_ITEM_CLOVERVOID_DESC", text);
NewDesc = true;
}
private static void ItemCatalog_Init(orig_Init orig)
{
//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_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Invalid comparison between Unknown and I4
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
orig.Invoke();
if (NewDesc)
{
Items.CloverVoid.descriptionToken = "KKING117_CONFIGBENTHIC_ITEM_CLOVERVOID_DESC";
}
BanList = new List<ItemDef>();
string[] array = Config_BlackList.Split(',');
for (int i = 0; i < array.Length; i++)
{
array[i] = array[i].Trim();
ItemIndex val = ItemCatalog.FindItemIndex(array[i]);
if ((int)val > -1)
{
ItemDef itemDef = ItemCatalog.GetItemDef(val);
if (Object.op_Implicit((Object)(object)itemDef))
{
BanList.Add(itemDef);
}
}
}
}
private static void CloverVoidUpgrade(orig_TryCloverVoidUpgrades orig, CharacterMaster self)
{
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Invalid comparison between Unknown and I4
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Invalid comparison between Unknown and I4
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
if (!NetworkServer.active)
{
return;
}
int itemCount = self.inventory.GetItemCount(Items.CloverVoid);
if (itemCount <= 0)
{
return;
}
int num = Config_BaseCount + Math.Max(0, itemCount - 1) * Config_StackCount;
if (num <= 0)
{
return;
}
List<ItemIndex> andSortInventory = GetAndSortInventory(self);
int num2 = 0;
int num3 = 0;
int num4 = 0;
List<ItemIndex> list = new List<ItemIndex>();
while (num2 < num && num3 < andSortInventory.Count)
{
bool flag = false;
ItemDef itemDef = ItemCatalog.GetItemDef(andSortInventory[num3]);
ItemDef val = null;
List<ItemIndex> upgradeList = GetUpgradeList(itemDef);
if (upgradeList != null && upgradeList.Count > 0)
{
Util.ShuffleList<ItemIndex>(upgradeList, self.cloverVoidRng);
upgradeList.Sort(CompareTags);
val = ItemCatalog.GetItemDef(upgradeList[0]);
}
if ((Object)(object)val != (Object)null)
{
num4 = 0;
num2++;
int num5 = 0;
int num6 = 1;
if ((int)itemDef.tier == 2 || (int)itemDef.tier == 8)
{
if (Config_Overspill_Bonus == OverspillBonus.PlusOne)
{
num5 = 1;
}
if (Config_Overspill_Bonus == OverspillBonus.Duplicate)
{
num6 = 2;
}
}
if (Config_WholeStack)
{
int itemCount2 = self.inventory.GetItemCount(itemDef);
int num7 = itemCount2 * num6 + num5;
self.inventory.GiveItem(val, num7);
self.inventory.RemoveItem(itemDef, itemCount2);
andSortInventory.RemoveAt(num3);
}
else
{
int num8 = num6 + num5;
self.inventory.GiveItem(val, num8);
self.inventory.RemoveItem(itemDef, 1);
if (self.inventory.GetItemCount(itemDef) < 1)
{
andSortInventory.RemoveAt(num3);
}
}
num3 = -1;
CharacterMasterNotificationQueue.PushItemTransformNotification(self, itemDef.itemIndex, val.itemIndex, (TransformationType)2);
if (Config_Select_PreferScrap && (val.ContainsTag((ItemTag)10) || val.ContainsTag((ItemTag)14)))
{
flag = true;
}
if (Config_Select_Method > SelectMethod.Random && Config_WholeStack)
{
if (andSortInventory.Count < 1)
{
num4++;
if (num4 > 3)
{
break;
}
flag = true;
}
}
else
{
flag = true;
}
if (flag)
{
andSortInventory = GetAndSortInventory(self);
}
}
num3++;
int CompareTags(ItemIndex lhs, ItemIndex rhs)
{
//IL_0005: 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)
int num9 = 0;
int num10 = 0;
ItemDef itemDef2 = ItemCatalog.GetItemDef(lhs);
ItemDef itemDef3 = ItemCatalog.GetItemDef(rhs);
if (itemDef.ContainsTag((ItemTag)1))
{
if (itemDef2.ContainsTag((ItemTag)1))
{
num9 = 1;
}
if (itemDef3.ContainsTag((ItemTag)1))
{
num10 = 1;
}
}
if (itemDef.ContainsTag((ItemTag)2))
{
if (itemDef2.ContainsTag((ItemTag)2))
{
num9 = 1;
}
if (itemDef3.ContainsTag((ItemTag)2))
{
num10 = 1;
}
}
if (itemDef.ContainsTag((ItemTag)3))
{
if (itemDef2.ContainsTag((ItemTag)3))
{
num9 = 1;
}
if (itemDef3.ContainsTag((ItemTag)3))
{
num10 = 1;
}
}
return num10 - num9;
}
}
if (num2 > 0)
{
GameObject bodyInstanceObject = self.bodyInstanceObject;
if (Object.op_Implicit((Object)(object)bodyInstanceObject))
{
Util.PlaySound("Play_item_proc_extraLife", bodyInstanceObject);
}
}
}
private static List<ItemIndex> GetAndSortInventory(CharacterMaster master)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
List<ItemIndex> itemList = new List<ItemIndex>(master.inventory.itemAcquisitionOrder);
itemList = RemoveClutter(itemList);
if (master.cloverVoidRng == null)
{
master.cloverVoidRng = new Xoroshiro128Plus(Run.instance.seed);
}
switch (Config_Select_Method)
{
case SelectMethod.LeastStacks:
itemList = SortItemList_ByLowest(itemList, master);
break;
case SelectMethod.MostStacks:
itemList = SortItemList_ByHighest(itemList, master);
break;
default:
Util.ShuffleList<ItemIndex>(itemList, master.cloverVoidRng);
break;
}
if (Config_Select_PreferScrap)
{
itemList = SortItemList_ByScrap(itemList);
}
return itemList;
}
private static List<ItemIndex> RemoveClutter(List<ItemIndex> itemList)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < itemList.Count; i++)
{
ItemDef itemDef = ItemCatalog.GetItemDef(itemList[i]);
if (Object.op_Implicit((Object)(object)itemDef) && !IsItemUpgradeable(itemDef))
{
itemList.RemoveAt(i);
i--;
}
}
return itemList;
}
private static List<ItemIndex> RemoveClutter_PickupList(List<PickupIndex> pickupList)
{
//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_0016: 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)
List<ItemIndex> list = new List<ItemIndex>();
for (int i = 0; i < pickupList.Count; i++)
{
PickupIndex val = pickupList[i];
ItemDef itemDef = ItemCatalog.GetItemDef(((PickupIndex)(ref val)).itemIndex);
if (Object.op_Implicit((Object)(object)itemDef) && (BanList == null || !BanList.Contains(itemDef)))
{
list.Add(itemDef.itemIndex);
}
}
return list;
}
private static List<ItemIndex> GetUpgradeList(ItemDef oldItemDef)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Invalid comparison between Unknown and I4
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Invalid comparison between Unknown and I4
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Invalid comparison between Unknown and I4
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Invalid comparison between Unknown and I4
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Invalid comparison between Unknown and I4
List<ItemIndex> result = null;
if ((int)oldItemDef.tier == 2)
{
return RemoveClutter_PickupList(Run.instance.availableTier1DropList);
}
if ((int)oldItemDef.tier == 1)
{
return RemoveClutter_PickupList(Run.instance.availableTier3DropList);
}
if ((int)oldItemDef.tier == 0)
{
return RemoveClutter_PickupList(Run.instance.availableTier2DropList);
}
if ((int)oldItemDef.tier == 8)
{
return RemoveClutter_PickupList(Run.instance.availableVoidTier1DropList);
}
if ((int)oldItemDef.tier == 7)
{
return RemoveClutter_PickupList(Run.instance.availableVoidTier3DropList);
}
if ((int)oldItemDef.tier == 6)
{
return RemoveClutter_PickupList(Run.instance.availableVoidTier2DropList);
}
return result;
}
private static bool IsItemUpgradeable(ItemDef item)
{
//IL_0023: 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_0031: Invalid comparison between Unknown and I4
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Invalid comparison between Unknown and I4
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Invalid comparison between Unknown and I4
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Invalid comparison between Unknown and I4
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Invalid comparison between Unknown and I4
if (!Config_Select_AllowSelf && (Object)(object)item == (Object)(object)Items.CloverVoid)
{
return false;
}
if ((int)item.tier == 0 || (int)item.tier == 1)
{
return true;
}
if ((int)item.tier == 2 && Config_Overspill_Enable)
{
return true;
}
if (Config_Select_AllowVoid)
{
if ((int)item.tier == 6 || (int)item.tier == 7)
{
return true;
}
if ((int)item.tier == 8 && Config_Overspill_Enable)
{
return true;
}
}
return false;
}
private static List<ItemIndex> SortItemList_ByLowest(List<ItemIndex> itemList, CharacterMaster master)
{
itemList.Sort(CompareStackSize);
return itemList;
int CompareStackSize(ItemIndex lhs, ItemIndex rhs)
{
//IL_000c: 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)
int itemCount = master.inventory.GetItemCount(lhs);
int itemCount2 = master.inventory.GetItemCount(rhs);
return itemCount - itemCount2;
}
}
private static List<ItemIndex> SortItemList_ByHighest(List<ItemIndex> itemList, CharacterMaster master)
{
itemList.Sort(CompareStackSize);
return itemList;
int CompareStackSize(ItemIndex lhs, ItemIndex rhs)
{
//IL_000c: 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)
int itemCount = master.inventory.GetItemCount(lhs);
int itemCount2 = master.inventory.GetItemCount(rhs);
return itemCount2 - itemCount;
}
}
private static List<ItemIndex> SortItemList_ByScrap(List<ItemIndex> itemList)
{
itemList.Sort(ByIsScrap);
return itemList;
static int ByIsScrap(ItemIndex lhs, ItemIndex rhs)
{
//IL_0005: 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)
int num = 0;
int num2 = 0;
ItemDef itemDef = ItemCatalog.GetItemDef(lhs);
ItemDef itemDef2 = ItemCatalog.GetItemDef(rhs);
if (itemDef.ContainsTag((ItemTag)14))
{
num = 2;
}
else if (itemDef.ContainsTag((ItemTag)10))
{
num = 1;
}
if (itemDef2.ContainsTag((ItemTag)14))
{
num2 = 2;
}
else if (itemDef2.ContainsTag((ItemTag)10))
{
num2 = 1;
}
return num2 - num;
}
}
private void ReadConfig()
{
Config_BaseCount = ((BaseUnityPlugin)this).Config.Bind<int>("Stacking", "Base Upgrade Count", 3, "How many items to upgrade at a single stack.").Value;
Config_StackCount = ((BaseUnityPlugin)this).Config.Bind<int>("Stacking", "Stack Upgrade Count", 3, "How many items to upgrade for each additional stack.").Value;
Config_BlackList = ((BaseUnityPlugin)this).Config.Bind<string>("Upgrading", "Upgrade Blacklist", "", "Prevents upgrading into these specific items. (Example = Clover, ExtraLife, MoreMissile)").Value;
Config_WholeStack = ((BaseUnityPlugin)this).Config.Bind<bool>("Upgrading", "Upgrade Entire Stack", true, "Should the entire stack get upgraded or a single instance of the selected item?").Value;
Config_Select_Method = ((BaseUnityPlugin)this).Config.Bind<SelectMethod>("Item Selection", "Selection Method", SelectMethod.Random, "The method to use when selecting items for upgrading.").Value;
Config_Select_PreferScrap = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Selection", "Prioritise Scrap", false, "Should Scrap have priority over the selection method?").Value;
Config_Select_AllowVoid = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Selection", "Allow Void", false, "Allow Void items to be selected for upgrading?").Value;
Config_Select_AllowSelf = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Selection", "Allow Self", false, "Allow Benthic Bloom to be selected for upgrading?").Value;
Config_Overspill_Enable = ((BaseUnityPlugin)this).Config.Bind<bool>("Overflow", "Enable", false, "Allows Legendary items to be selected and 'upgraded' into Common items.").Value;
Config_Overspill_Bonus = ((BaseUnityPlugin)this).Config.Bind<OverspillBonus>("Overflow", "Bonus Gain", OverspillBonus.PlusOne, "Gain extra items when 'upgrading' an item.").Value;
}
}