Decompiled source of ProactiveChanceDoll v1.0.1

ProactiveChanceDoll.dll

Decompiled a month ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HG.Reflection;
using On.RoR2;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ProactiveChanceDoll")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d880cafcf88bece6af1fbbb17ae86fcb76a70e03")]
[assembly: AssemblyProduct("ProactiveChanceDoll")]
[assembly: AssemblyTitle("ProactiveChanceDoll")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ProactiveChanceDoll;

internal static class ChanceDollSharingHooks
{
	private static bool _hooked = false;

	private static ItemIndex _chanceDollIndex = (ItemIndex)(-1);

	internal static void Hook()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		if (!_hooked)
		{
			ShrineChanceBehavior.AddShrineStack += new hook_AddShrineStack(AddShrineStack);
			_hooked = true;
		}
	}

	internal static void UnHook()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		if (_hooked)
		{
			ShrineChanceBehavior.AddShrineStack -= new hook_AddShrineStack(AddShrineStack);
			_hooked = false;
		}
	}

	private static void AddShrineStack(orig_AddShrineStack orig, ShrineChanceBehavior shrine, Interactor interactor)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		if ((int)_chanceDollIndex == -1)
		{
			_chanceDollIndex = ItemCatalog.FindItemIndex("ExtraShrineItem");
		}
		if (!NetworkServer.active || !Run.instance.IsExpansionEnabled(ItemCatalog.GetItemDef(_chanceDollIndex).requiredExpansion))
		{
			orig.Invoke(shrine, interactor);
			return;
		}
		object obj;
		if (interactor == null)
		{
			obj = null;
		}
		else
		{
			CharacterBody component = ((Component)interactor).GetComponent<CharacterBody>();
			obj = ((component != null) ? component.inventory : null);
		}
		Inventory val = (Inventory)obj;
		if (!Object.op_Implicit((Object)(object)val))
		{
			orig.Invoke(shrine, interactor);
			return;
		}
		int num = PlayerCharacterMasterController.instances.Where(delegate(PlayerCharacterMasterController player)
		{
			CharacterMaster master = player.master;
			return Object.op_Implicit((Object)(object)((master != null) ? master.inventory : null));
		}).Sum((PlayerCharacterMasterController player) => player.master.inventory.GetItemCountEffective(_chanceDollIndex));
		int itemCountEffective = val.GetItemCountEffective(_chanceDollIndex);
		int num2 = num - itemCountEffective;
		if (num2 <= 0)
		{
			orig.Invoke(shrine, interactor);
			return;
		}
		val.GiveItemPermanent(_chanceDollIndex, num2);
		try
		{
			orig.Invoke(shrine, interactor);
		}
		finally
		{
			val.RemoveItemPermanent(_chanceDollIndex, num2);
		}
	}
}
[BepInPlugin("sylvie.proactivechancedoll", "Proactive Chance Doll", "1.0.1")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public sealed class ProactiveChanceDoll : BaseUnityPlugin
{
	private void Awake()
	{
		ChanceDollSharingHooks.Hook();
	}

	private void OnDestroy()
	{
		ChanceDollSharingHooks.UnHook();
	}
}