Decompiled source of GreenShell v1.0.1

GreenShell.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GreenShell")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GreenShell")]
[assembly: AssemblyTitle("GreenShell")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 GreenSonorousWhispers
{
	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("Xaidee.GreenShell", "GreenShell", "1.0.0")]
	public class ModPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__ChangeSW;

			public static Manipulator <1>__NerfSW;

			public static Func<bool, bool> <2>__ShouldDropFromChampion;

			public static Func<bool, CharacterMaster, int, bool> <3>__ShouldDropFromElite;
		}

		private static ConfigEntry<bool> _enableBossDrops;

		private static AssetBundle _assetBundle;

		public void Awake()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			_enableBossDrops = ((BaseUnityPlugin)this).Config.Bind<bool>("Green Sonorous Whispers", "EnableBossDrops", false, "Allows Sonorous Whispers to have a chance to drop items from boss/champion kills.");
			string rootPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			_assetBundle = AssetBundle.LoadFromFile(Path.Combine(rootPath, "gsw"));
			if (Directory.Exists(Path.Combine(rootPath, "languages")))
			{
				Language.collectLanguageRootFolders += delegate(List<string> list)
				{
					list.Add(Path.Combine(rootPath, "languages"));
				};
			}
			((ResourceAvailability)(ref ItemCatalog.availability)).CallWhenAvailable((Action)ChangeSW);
			object obj = <>O.<1>__NerfSW;
			if (obj == null)
			{
				Manipulator val = NerfSW;
				<>O.<1>__NerfSW = val;
				obj = (object)val;
			}
			GlobalEventManager.OnCharacterDeath += (Manipulator)obj;
		}

		private static void ChangeSW()
		{
			ItemDef itemDropChanceOnKill = Items.ItemDropChanceOnKill;
			Sprite obj = _assetBundle.LoadAsset<Sprite>("sGreenSonorousWhispers");
			itemDropChanceOnKill.tier = (ItemTier)1;
			if ((Object)(object)obj != (Object)null)
			{
				itemDropChanceOnKill.pickupIconSpriteReference = null;
				itemDropChanceOnKill.pickupIconSprite = _assetBundle.LoadAsset<Sprite>("sGreenSonorousWhispers");
			}
			if (!_enableBossDrops.Value)
			{
				itemDropChanceOnKill.pickupToken += "_NERF";
				itemDropChanceOnKill.descriptionToken += "_NERF";
			}
		}

		private static void NerfSW(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			int num = default(int);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "isChampion")
			}))
			{
				Log.Error("Failed to locate Sonorous Whispers' champion drop check!");
				return;
			}
			Log.Debug("Successfully located Sonorous Whispers' champion drop check.");
			val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)ShouldDropFromChampion);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "get_isElite")
			}))
			{
				Log.Error("Failed to locate Sonorous Whispers' elite drop check!");
				return;
			}
			Log.Debug("Successfully located Sonorous Whispers' elite drop check.");
			val.Emit(OpCodes.Ldloc, 17);
			val.Emit(OpCodes.Ldloc, 107);
			val.EmitDelegate<Func<bool, CharacterMaster, int, bool>>((Func<bool, CharacterMaster, int, bool>)ShouldDropFromElite);
		}

		private static bool ShouldDropFromChampion(bool isChampion)
		{
			if (isChampion)
			{
				return _enableBossDrops.Value;
			}
			return false;
		}

		private static bool ShouldDropFromElite(bool isElite, CharacterMaster attackerMaster, int itemCount)
		{
			if (isElite)
			{
				return Util.CheckRoll(4f + (float)(itemCount - 1), attackerMaster);
			}
			return false;
		}
	}
}