Decompiled source of ExponentialItems v2.0.2

ExponentialItems.dll

Decompiled 7 months 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 ArtifactSpace;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ExponentialItems")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExponentialItems")]
[assembly: AssemblyTitle("ExponentialItems")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ExponentialItems
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_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);
		}
	}
	[BepInPlugin("Horse5333.ExponentialItems", "ExponentialItems", "2.0.0")]
	public class Main : BaseUnityPlugin
	{
		private class ExampleArtifact : ArtifactBase
		{
			public override string ArtifactName => "Artifact of Exponentiality";

			public override string ArtifactLangTokenName => "ARTIFACT_OF_EXPONENT";

			public override string ArtifactDescription => "Picking up an item doubles its count";

			public override Sprite ArtifactEnabledIcon => MainAssets.LoadAsset<Sprite>("ExponentArtifactEnabledIcon.png");

			public override Sprite ArtifactDisabledIcon => MainAssets.LoadAsset<Sprite>("ExponentArtifactDisabledIcon.png");

			public override void Init(ConfigFile config)
			{
				CreateConfig(config);
				CreateLang();
				CreateArtifact();
				Hooks();
			}

			private void CreateConfig(ConfigFile config)
			{
				MaxStack = config.Bind<int>("Behavior", "Max Stack Size", 4096, "Determines when to stop adding additional items. Not recommended to set significantly higher");
				Base = config.Bind<int>("Behavior", "Base Size", 2, "Determines the base size to stack items with.\n3 -> 1, 3, 9, 27 ...");
			}

			public override void Hooks()
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				Inventory.GiveItem_ItemIndex_int += new hook_GiveItem_ItemIndex_int(OnGiveItem);
			}

			private void OnGiveItem(orig_GiveItem_ItemIndex_int orig, Inventory self, ItemIndex index, int count = 1)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				if (!base.ArtifactEnabled)
				{
					orig.Invoke(self, index, count);
					return;
				}
				int itemCount = self.GetItemCount(index);
				if (itemCount == 0 || count != 1)
				{
					orig.Invoke(self, index, count);
				}
				else if (itemCount < MaxStack.Value)
				{
					int num = (int)Math.Pow(Base.Value, Math.Floor(Math.Log(itemCount, Base.Value)) + 1.0);
					if (num - itemCount < 1)
					{
						orig.Invoke(self, index, 1);
					}
					else
					{
						orig.Invoke(self, index, num - itemCount);
					}
				}
			}
		}

		public List<ArtifactBase> Artifacts = new List<ArtifactBase>();

		public const string PluginGUID = "Horse5333.ExponentialItems";

		public const string PluginAuthor = "Horse5333";

		public const string PluginName = "ExponentialItems";

		public const string PluginVersion = "2.0.0";

		public static AssetBundle MainAssets;

		public static ConfigEntry<int> Base { get; set; }

		public static ConfigEntry<int> MaxStack { get; set; }

		public bool ValidateArtifact(ArtifactBase artifact, List<ArtifactBase> artifactList)
		{
			bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Artifact: " + artifact.ArtifactName, "Enable Artifact?", true, "Should this artifact appear for selection?").Value;
			if (value)
			{
				artifactList.Add(artifact);
			}
			return value;
		}

		public void Awake()
		{
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ExponentialItems.artifact_assets"))
			{
				MainAssets = AssetBundle.LoadFromStream(stream);
			}
			IEnumerable<Type> enumerable = from type in Assembly.GetExecutingAssembly().GetTypes()
				where !type.IsAbstract && type.IsSubclassOf(typeof(ArtifactBase))
				select type;
			foreach (Type item in enumerable)
			{
				ArtifactBase artifactBase = (ArtifactBase)Activator.CreateInstance(item);
				if (ValidateArtifact(artifactBase, Artifacts))
				{
					artifactBase.Init(((BaseUnityPlugin)this).Config);
				}
			}
			Log.Init(((BaseUnityPlugin)this).Logger);
		}
	}
}
namespace ArtifactSpace
{
	public abstract class ArtifactBase
	{
		public ArtifactDef ArtifactDef;

		public abstract string ArtifactName { get; }

		public abstract string ArtifactLangTokenName { get; }

		public abstract string ArtifactDescription { get; }

		public abstract Sprite ArtifactEnabledIcon { get; }

		public abstract Sprite ArtifactDisabledIcon { get; }

		public bool ArtifactEnabled => RunArtifactManager.instance.IsArtifactEnabled(ArtifactDef);

		public abstract void Init(ConfigFile config);

		protected void CreateLang()
		{
			LanguageAPI.Add("ARTIFACT_" + ArtifactLangTokenName + "_NAME", ArtifactName);
			LanguageAPI.Add("ARTIFACT_" + ArtifactLangTokenName + "_DESCRIPTION", ArtifactDescription);
		}

		protected void CreateArtifact()
		{
			ArtifactDef = ScriptableObject.CreateInstance<ArtifactDef>();
			ArtifactDef.cachedName = "ARTIFACT_" + ArtifactLangTokenName;
			ArtifactDef.nameToken = "ARTIFACT_" + ArtifactLangTokenName + "_NAME";
			ArtifactDef.descriptionToken = "ARTIFACT_" + ArtifactLangTokenName + "_DESCRIPTION";
			ArtifactDef.smallIconSelectedSprite = ArtifactEnabledIcon;
			ArtifactDef.smallIconDeselectedSprite = ArtifactDisabledIcon;
			ContentAddition.AddArtifactDef(ArtifactDef);
		}

		public abstract void Hooks();
	}
}