Decompiled source of ProactiveChanceDoll v1.0.0

ProactiveChanceDoll.dll

Decompiled 8 hours 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+7d7da3d8e627d4292662e8c28a25378652c4a4a6")]
[assembly: AssemblyProduct("ProactiveChanceDoll")]
[assembly: AssemblyTitle("ProactiveChanceDoll")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ProactiveChanceDoll;

internal static class ChanceDollSharingHooks
{
	internal static void Hook()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		ShrineChanceBehavior.AddShrineStack += new hook_AddShrineStack(AddShrineStack);
	}

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

	private static void AddShrineStack(orig_AddShrineStack orig, ShrineChanceBehavior shrine, Interactor interactor)
	{
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Invalid comparison between Unknown and I4
		//IL_00b4: 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)
		if (!NetworkServer.active)
		{
			orig.Invoke(shrine, interactor);
			return;
		}
		CharacterBody val = ((interactor != null) ? ((Component)interactor).GetComponent<CharacterBody>() : null);
		Inventory val2 = ((val != null) ? val.inventory : null);
		ItemIndex chanceDollIndex = ItemCatalog.FindItemIndex("ExtraShrineItem");
		if (!Object.op_Implicit((Object)(object)val2) || (int)chanceDollIndex == -1)
		{
			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 = val2.GetItemCountEffective(chanceDollIndex);
		int num2 = num - itemCountEffective;
		if (num2 <= 0)
		{
			orig.Invoke(shrine, interactor);
			return;
		}
		val2.GiveItemPermanent(chanceDollIndex, num2);
		try
		{
			orig.Invoke(shrine, interactor);
		}
		finally
		{
			val2.RemoveItemPermanent(chanceDollIndex, num2);
		}
	}
}
[BepInPlugin("com.sylvie.proactivechancedoll", "Proactive Chance Doll", "1.0.0")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public sealed class ProactiveChanceDoll : BaseUnityPlugin
{
	private void Awake()
	{
		ChanceDollSharingHooks.Hook();
	}

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