Decompiled source of GreenAlienHead v4.0.3

GreenAlienHead.dll

Decompiled 6 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GreenAlienHead.Properties;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using R2API;
using R2API.Utils;
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("GreenAlienHead")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GreenAlienHead")]
[assembly: AssemblyTitle("GreenAlienHead")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace GreenAlienHead
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[R2APISubmoduleDependency(new string[] { "LanguageAPI" })]
	[BepInPlugin("com.Borbo.GreenAlienHead", "Yeah Thats Right Alien Head Is A Green Item Now", "4.0.1")]
	public class Base : BaseUnityPlugin
	{
		public static AssetBundle iconBundle = LoadAssetBundle(Resources.gah);

		private static Sprite greenAlienHeadSprite;

		private float alienHeadNewCooldownFraction = 0.85f;

		private ItemTier headNewTier = (ItemTier)1;

		internal static ConfigFile CustomConfigFile { get; set; }

		public static ConfigEntry<float> CooldownReduction { get; set; }

		public static AssetBundle LoadAssetBundle(byte[] resourceBytes)
		{
			if (resourceBytes == null)
			{
				throw new ArgumentNullException("resourceBytes");
			}
			return AssetBundle.LoadFromMemory(resourceBytes);
		}

		private bool isLoaded(string modguid)
		{
			foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
			{
				string key = pluginInfo.Key;
				PluginInfo value = pluginInfo.Value;
				if (key == modguid)
				{
					return true;
				}
			}
			return false;
		}

		public void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Invalid comparison between Unknown and I4
			CustomConfigFile = new ConfigFile(Paths.ConfigPath + "\\GreenAlienHead.cfg", true);
			CooldownReduction = CustomConfigFile.Bind<float>("Green Alien Head", "Set Cooldown Reduction", (1f - alienHeadNewCooldownFraction) * 100f, "Change the cooldown reduction PERCENT of alien head.");
			alienHeadNewCooldownFraction = 1f - CooldownReduction.Value / 100f;
			greenAlienHeadSprite = iconBundle.LoadAsset<Sprite>("Assets/greenalienhead.png");
			CharacterBody.RecalculateStats += new Manipulator(NerfAlienHeadCdr);
			ItemDef val = LegacyResourcesAPI.Load<ItemDef>("ItemDefs/AlienHead");
			if (Object.op_Implicit((Object)(object)val))
			{
				val.tier = headNewTier;
				val.deprecatedTier = headNewTier;
				if ((int)headNewTier == 1)
				{
					val.pickupIconSprite = greenAlienHeadSprite;
				}
			}
			LanguageAPI.Add("ITEM_ALIENHEAD_DESC", $"<style=cIsUtility>Reduce skill cooldowns</style> by <style=cIsUtility>{CooldownReduction.Value}%</style> <style=cStack>(+{CooldownReduction.Value}% per stack)</style>.");
			Debug.Log((object)$"Green Alien Head Initialized! Cooldowns should now be multiplied by {alienHeadNewCooldownFraction} per stack.");
		}

		private void NerfAlienHeadCdr(ILContext il)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			int alienHeadLocation = 15;
			val.GotoNext((MoveType)0, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "RoR2.RoR2Content/Items", "AlienHead"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount"),
				(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref alienHeadLocation)
			});
			val.GotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, alienHeadLocation)
			});
			val.Index -= 8;
			val.Remove();
			val.Emit(OpCodes.Ldc_R4, alienHeadNewCooldownFraction);
		}
	}
}
namespace GreenAlienHead.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("GreenAlienHead.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] gah
		{
			get
			{
				object @object = ResourceManager.GetObject("gah", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resources()
		{
		}
	}
}