Decompiled source of LunarShopPicker v1.0.0

plugins/LunarShopPicker/LunarShopPicker.dll

Decompiled 14 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[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("LunarShopPicker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LunarShopPicker")]
[assembly: AssemblyTitle("LunarShopPicker")]
[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 LunarShopPicker
{
	[BepInPlugin("com.zcode.LunarShopPicker", "LunarShopPicker", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class LunarShopPickerPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.zcode.LunarShopPicker";

		public const string PluginName = "LunarShopPicker";

		public const string PluginVersion = "1.0.0";

		internal static ConfigEntry<bool> Enabled { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Enabled", true, "总开关。开启后,时之隙集市(Bazaar Between Time)的月轮商品(Lunar Buds)购买后掉出 Command 神器式的选择方块,可从全部已解锁月轮物品中任选一件。其他商店与掉落不受影响。");
			Harmony.CreateAndPatchAll(typeof(ShopPickerPatches), (string)null);
			RegisterRiskOfOptions();
			Log.LogInfo((object)"LunarShopPicker v1.0.0 loaded.");
		}

		private void RegisterRiskOfOptions()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(Enabled));
			}
		}
	}
	[HarmonyPatch]
	internal static class ShopPickerPatches
	{
		[HarmonyPatch(typeof(ShopTerminalBehavior), "DropPickup", new Type[] { typeof(bool) })]
		[HarmonyPrefix]
		private static bool ReplaceLunarDropWithChoiceCube(ShopTerminalBehavior __instance, bool isDuplicated)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Invalid comparison between Unknown and I4
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Invalid comparison between Unknown and I4
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			if (!LunarShopPickerPlugin.Enabled.Value || !NetworkServer.active || !IsInBazaar())
			{
				return true;
			}
			UniquePickup val = __instance.CurrentPickup();
			PickupDef pickupDef = PickupCatalog.GetPickupDef(val.pickupIndex);
			if (pickupDef == null || (int)pickupDef.itemTier != 3)
			{
				return true;
			}
			if (__instance.dropAmount <= 0)
			{
				__instance.dropAmount = 1;
			}
			if (__instance.debt <= 0)
			{
				__instance.debt = 1;
			}
			__instance.SetHasBeenPurchased(true);
			UniquePickup pickup = val;
			ItemStorageType storageType = __instance.storageType;
			if ((int)storageType != 2)
			{
				if ((int)storageType == 3)
				{
					pickup.isRental = true;
				}
			}
			else
			{
				pickup.decayValue = 1f;
			}
			Vector3 position = (Object.op_Implicit((Object)(object)__instance.dropTransform) ? __instance.dropTransform : ((Component)__instance).transform).position;
			Vector3 val2 = ((Component)__instance).transform.TransformVector(__instance.dropVelocity);
			for (int i = 0; i < __instance.debt; i++)
			{
				for (int j = 0; j < __instance.dropAmount; j++)
				{
					CreatePickupInfo val3 = new CreatePickupInfo
					{
						rotation = Quaternion.identity
					};
					((CreatePickupInfo)(ref val3)).pickup = pickup;
					val3.position = position;
					val3.duplicated = isDuplicated;
					ref PickupArtifactFlag artifactFlag = ref val3.artifactFlag;
					artifactFlag = (PickupArtifactFlag)((uint)artifactFlag | 1u);
					PickupDropletController.CreatePickupDroplet(val3, position, val2);
				}
			}
			__instance.debt = 0;
			LunarShopPickerPlugin.Log.LogInfo((object)("Lunar bud purchase converted to a choice cube: " + pickupDef.nameToken + " offered as full lunar selection."));
			return false;
		}

		private static bool IsInBazaar()
		{
			SceneDef val = (Object.op_Implicit((Object)(object)SceneInfo.instance) ? SceneInfo.instance.sceneDef : null);
			if ((Object)(object)val != (Object)null)
			{
				return string.Equals(val.baseSceneName, "bazaar", StringComparison.OrdinalIgnoreCase);
			}
			return false;
		}
	}
}