Decompiled source of TempItemsTooShort v1.1.1

TempItemsTooShort.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using IL.RoR2.Items;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API;
using RoR2;

[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("TempItemsTooShort")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TempItemsTooShort")]
[assembly: AssemblyTitle("TempItemsTooShort")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 TempItemsTooShort
{
	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);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("acanthi.TempItemsTooShort", "TempItemsTooShort", "1.0.0")]
	public class TempItemsTooShort : BaseUnityPlugin
	{
		public const string PluginGUID = "acanthi.TempItemsTooShort";

		public const string PluginAuthor = "acanthi";

		public const string PluginName = "TempItemsTooShort";

		public const string PluginVersion = "1.0.0";

		private static ItemDef myItemDef;

		public static float extendDuration;

		public static int duplicatorExtendDuration;

		public static bool duplicatorDescriptionChanges;

		public void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			InitConfig();
			TempItemsStorage.SetDecayDurationServer += new hook_SetDecayDurationServer(TempItemsStorage_SetDecayDurationServer);
			DuplicatorBehavior.CalculateNewItemDecayDuration += new Manipulator(DuplicateItemBehavior_CalculateNewItemDecayDuration);
			if (duplicatorDescriptionChanges)
			{
				LanguageAPI.Add("ITEM_DUPLICATOR_DESC", "<style=cIsUtility>Picking up an item</style> gives you a <style=cIsTemporary>temporary copy</style> of itself. Temporary items last an additional <style=cIsDamage>" + (10 + duplicatorExtendDuration) + " <style=cStack>(+" + (10 + duplicatorExtendDuration) + " per stack)</style> seconds</style>.", "en");
			}
		}

		private void InitConfig()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			extendDuration = ((BaseUnityPlugin)this).Config.Bind<float>("TempItemsTooShort", "Extend Duration", 40f, new ConfigDescription("How many extra seconds should Temporary Items last? (Negative values can be used to reduce the timer.)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-70f, 4800f), Array.Empty<object>())).Value;
			duplicatorExtendDuration = ((BaseUnityPlugin)this).Config.Bind<int>("TempItemsTooShort", "Substandard Duplicator Extra Duration", 30, new ConfigDescription("How many extra seconds should Substandard Duplicator give? (You shouldn't use negative values here....)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 4800), Array.Empty<object>())).Value;
			duplicatorDescriptionChanges = ((BaseUnityPlugin)this).Config.Bind<bool>("TempItemsTooShort", "Substandard Duplicator Enable Description Changes", true, "Changes the description of Substandard Duplicator to match the extra duration. Might cause compat issues.").Value;
		}

		private void TempItemsStorage_SetDecayDurationServer(orig_SetDecayDurationServer orig, ref TempItemsStorage self, float newDecayDuration)
		{
			newDecayDuration += extendDuration;
			orig.Invoke(ref self, newDecayDuration);
		}

		private void DuplicateItemBehavior_CalculateNewItemDecayDuration(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			int num = default(int);
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, ref num)
			}))
			{
				val.Index += 1;
				val.EmitDelegate<Func<int, int>>((Func<int, int>)AddDuplicatorTime);
			}
			else
			{
				Log.Error(((MemberReference)il.Method).Name + " IL Hook failed!");
			}
		}

		public static int AddDuplicatorTime(int input)
		{
			return input + duplicatorExtendDuration;
		}
	}
}