using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using RoR2;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ExponentialItemsReloaded")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExponentialItemsReloaded")]
[assembly: AssemblyTitle("ExponentialItemsReloaded")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 ExponentialItemsReloaded
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.bentley.exponentialitemsreloaded", "ExponentialItemsReloaded", "1.0.0")]
public class ExponentialItemsReloadedPlugin : BaseUnityPlugin
{
public const string PluginGUID = "com.bentley.exponentialitemsreloaded";
public const string PluginName = "ExponentialItemsReloaded";
public const string PluginVersion = "1.0.0";
private static ArtifactDef exponentialArtifactDef;
private static ConfigEntry<int> maxStack;
private static ConfigEntry<int> baseSize;
private static ConfigEntry<bool> affectTierless;
private static ConfigEntry<bool> affectEquipment;
private static bool suppressExponentialHook;
private Sprite LoadSprite(string fileName)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), fileName);
if (!File.Exists(text))
{
((BaseUnityPlugin)this).Logger.LogError((object)("Icon file not found: " + text));
return null;
}
byte[] array = File.ReadAllBytes(text);
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, array);
return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
}
public void Awake()
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: 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
maxStack = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Stack Size", 4096, "Maximum item stack count this mod will try to reach.");
baseSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Base Size", 2, "Exponential base. 2 gives 1,2,4,8... 3 gives 1,3,9,27...");
affectTierless = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Affect Tierless Items", false, "Usually safer off. Some hidden/itemless tokens are tierless and can be weird.");
affectEquipment = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Affect Equipment", false, "Placeholder safety option. Inventory.GiveItem should not normally affect equipment.");
RegisterArtifact();
Inventory.GiveItem_ItemIndex_int += new hook_GiveItem_ItemIndex_int(Inventory_GiveItem_ItemIndex_int);
Inventory.GiveItem_ItemDef_int += new hook_GiveItem_ItemDef_int(Inventory_GiveItem_ItemDef_int);
GenericPickupController.AttemptGrant += new hook_AttemptGrant(GenericPickupController_AttemptGrant);
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} loaded. Artifact registered: {1}", "ExponentialItemsReloaded", (Object)(object)exponentialArtifactDef != (Object)null));
}
private void RegisterArtifact()
{
LanguageAPI.Add("ARTIFACT_EXPONENTIALITEMS_NAME", "Artifact of Exponents");
LanguageAPI.Add("ARTIFACT_EXPONENTIALITEMS_DESC", "Items stack exponentially instead of one at a time.");
exponentialArtifactDef = ScriptableObject.CreateInstance<ArtifactDef>();
exponentialArtifactDef.cachedName = "ExponentialItems";
exponentialArtifactDef.nameToken = "ARTIFACT_EXPONENTIALITEMS_NAME";
exponentialArtifactDef.descriptionToken = "ARTIFACT_EXPONENTIALITEMS_DESC";
Sprite smallIconSelectedSprite = LoadSprite("icon_selected.png");
Sprite smallIconDeselectedSprite = LoadSprite("icon_deselected.png");
exponentialArtifactDef.smallIconSelectedSprite = smallIconSelectedSprite;
exponentialArtifactDef.smallIconDeselectedSprite = smallIconDeselectedSprite;
ContentAddition.AddArtifactDef(exponentialArtifactDef);
}
private static Sprite CreateIcon(Color color)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Expected O, but got Unknown
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
for (int i = 0; i < 128; i++)
{
for (int j = 0; j < 128; j++)
{
float num = (float)j - 64f;
float num2 = (float)i - 64f;
float num3 = Mathf.Sqrt(num * num + num2 * num2) / 64f;
bool flag = num3 > 0.72f && num3 < 0.86f;
bool flag2 = num3 < 0.48f;
val.SetPixel(j, i, (flag || flag2) ? color : Color.clear);
}
}
val.Apply();
return Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 100f);
}
private void Inventory_GiveItem_ItemIndex_int(orig_GiveItem_ItemIndex_int orig, Inventory self, ItemIndex itemIndex, int count)
{
//IL_0091: 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)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
try
{
if (suppressExponentialHook || !ShouldApply(self, itemIndex, count))
{
orig.Invoke(self, itemIndex, count);
return;
}
int itemCountPermanent = self.GetItemCountPermanent(itemIndex);
int nextTargetStack = GetNextTargetStack(itemCountPermanent);
if (nextTargetStack <= itemCountPermanent)
{
orig.Invoke(self, itemIndex, count);
return;
}
int num = Math.Max(1, nextTargetStack - itemCountPermanent);
suppressExponentialHook = true;
try
{
orig.Invoke(self, itemIndex, num);
}
finally
{
suppressExponentialHook = false;
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)ex);
orig.Invoke(self, itemIndex, count);
}
}
private void Inventory_GiveItem_ItemDef_int(orig_GiveItem_ItemDef_int orig, Inventory self, ItemDef itemDef, int count)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
if ((Object)(object)itemDef == (Object)null)
{
orig.Invoke(self, itemDef, count);
return;
}
Inventory_GiveItem_ItemIndex_int((orig_GiveItem_ItemIndex_int)delegate(Inventory inventory, ItemIndex itemIndex, int itemCount)
{
orig.Invoke(inventory, itemDef, itemCount);
}, self, itemDef.itemIndex, count);
}
private void GenericPickupController_AttemptGrant(orig_AttemptGrant orig, GenericPickupController self, CharacterBody body)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: 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_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Invalid comparison between Unknown and I4
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
Inventory val = (Object.op_Implicit((Object)(object)body) ? body.inventory : null);
PickupIndex pickupIndex = self.pickupIndex;
PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
ItemIndex val2 = (ItemIndex)((pickupDef == null) ? (-1) : ((int)pickupDef.itemIndex));
int num = (((Object)(object)val != (Object)null && (int)val2 != -1) ? val.GetItemCountPermanent(val2) : 0);
orig.Invoke(self, body);
try
{
if ((Object)(object)val == (Object)null || (int)val2 == -1 || suppressExponentialHook || !ShouldApplyItem(val, val2))
{
return;
}
int itemCountPermanent = val.GetItemCountPermanent(val2);
if (itemCountPermanent <= num)
{
return;
}
int nextTargetStack = GetNextTargetStack(num);
if (nextTargetStack <= itemCountPermanent)
{
return;
}
suppressExponentialHook = true;
try
{
val.GiveItemPermanent(val2, nextTargetStack - itemCountPermanent);
}
finally
{
suppressExponentialHook = false;
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)ex);
}
}
private static int GetNextTargetStack(int current)
{
int num = Math.Max(1, baseSize.Value);
int num2 = Math.Max(1, maxStack.Value);
if (current <= 0 || num <= 1 || current >= num2)
{
return current;
}
double y = Math.Floor(Math.Log(current, num)) + 1.0;
return (int)Math.Min(num2, Math.Pow(num, y));
}
private static bool ShouldApplyItem(Inventory self, ItemIndex itemIndex)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Invalid comparison between Unknown and I4
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Invalid comparison between Unknown and I4
if ((Object)(object)self == (Object)null || (int)itemIndex == -1)
{
return false;
}
if ((Object)(object)RunArtifactManager.instance == (Object)null || (Object)(object)exponentialArtifactDef == (Object)null)
{
return false;
}
if (!RunArtifactManager.instance.IsArtifactEnabled(exponentialArtifactDef))
{
return false;
}
ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex);
if ((Object)(object)itemDef == (Object)null)
{
return false;
}
if (!affectTierless.Value && (int)itemDef.tier == 5)
{
return false;
}
return true;
}
private static bool ShouldApply(Inventory self, ItemIndex itemIndex, int count)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (count != 1)
{
return false;
}
return ShouldApplyItem(self, itemIndex);
}
}
}