Decompiled source of BonusSlot v1.0.0

BonusSlotMod.dll

Decompiled 3 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BonusSlotMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BonusSlotMod")]
[assembly: AssemblyTitle("BonusSlotMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BonusSlotMod;

[BepInPlugin("yourname.bonusslot", "Bonus Slot", "1.0.0")]
public class BonusSlotPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "yourname.bonusslot";

	public const string PluginName = "Bonus Slot";

	public const string PluginVersion = "1.0.0";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		new Harmony("yourname.bonusslot").PatchAll();
		Log.LogInfo((object)"Bonus Slot v1.0.0 загружен. ВАЖНО: этот мод должен быть установлен у ВСЕХ игроков в лобби, включая хоста — иначе сломается синхронизация инвентаря.");
	}
}
internal static class BonusSlotConstants
{
	public const int BonusSlotIndex = 4;
}
[HarmonyPatch(typeof(PlayerInventory), "Awake")]
internal static class PlayerInventory_Awake_Patch
{
	[HarmonyPostfix]
	private static void Postfix(PlayerInventory __instance)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		if (__instance.slots.Length <= 4)
		{
			Array.Resize(ref __instance.slots, 5);
			__instance.slots[4] = new InventorySlot(4, __instance);
			BonusSlotPlugin.Log.LogDebug((object)$"Инвентарь {((Object)((Component)__instance).gameObject).name}: добавлен бонусный слот #{4}");
		}
	}
}
[HarmonyPatch]
internal static class PlayerInventory_TryAddItem_Patch
{
	private static MethodBase TargetMethod()
	{
		return AccessTools.Method(typeof(PlayerInventory), "TryAddItem", new Type[2]
		{
			typeof(ItemDescriptor),
			typeof(InventorySlot).MakeByRefType()
		}, (Type[])null);
	}

	private static void Postfix(PlayerInventory __instance, ItemDescriptor item, ref InventorySlot slot, ref bool __result)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_0020: Invalid comparison between Unknown and I4
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: 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)
		if (!__result && !((Object)(object)item.item == (Object)null) && (int)item.item.itemType != 2 && (int)item.item.itemType != 3)
		{
			InventorySlot val = __instance.slots[4];
			if (!((Object)(object)val.ItemInSlot.item != (Object)null))
			{
				val.Add(item);
				slot = val;
				__result = true;
				BonusSlotPlugin.Log.LogInfo((object)("'" + ((Object)item.item).name + "' помещён во временный бонусный слот"));
			}
		}
	}
}
[HarmonyPatch(typeof(PlayerItems), "ChangeToSlot")]
internal static class PlayerItems_ChangeToSlot_Patch
{
	[HarmonyPrefix]
	private static void Prefix(PlayerItems __instance, int slotID, Player ___player)
	{
		if (__instance.m_displayingSlot == 4 && slotID != 4 && !((Object)(object)___player == (Object)null) && !((Object)(object)___player.data.currentItem == (Object)null))
		{
			__instance.DropItem(4, true);
		}
	}
}