Decompiled source of Squeakys Item Multiplier v1.0.1

SqueakyItemMultiplier.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using On.RoR2;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SqueakyItemMultiplier")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+301f7c095eae4e68c217d722a9b12a20cbda7c81")]
[assembly: AssemblyProduct("SqueakyItemMultiplier")]
[assembly: AssemblyTitle("SqueakyItemMultiplier")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SqueakyItemMultiplier;

[BepInPlugin("com.squeakysquared.squeakyitemmultiplier", "SqueakyItemMultiplier", "1.0.1")]
public class SqueakyItemMultiplierPlugin : BaseUnityPlugin
{
	private ConfigEntry<int> itemMultiplier;

	private ConfigEntry<bool> enableDebugLogging;

	private ConfigEntry<bool> multiplyLunarItems;

	private ConfigEntry<bool> multiplyVoidItems;

	public void Awake()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogWarning((object)"=== SQUEAKY ITEM MULTIPLIER AWAKE START ===");
		itemMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "ItemMultiplier", 5, new ConfigDescription("Multiplier for items (e.g., 5 means 1 item becomes 5)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, int.MaxValue), Array.Empty<object>()));
		enableDebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugLogging", true, "Enable detailed logging");
		multiplyLunarItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "MultiplyLunarItems", true, "Multiply lunar (blue) items");
		multiplyVoidItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "MultiplyVoidItems", true, "Multiply void (purple) items");
		((BaseUnityPlugin)this).Logger.LogWarning((object)$"=== CONFIG LOADED: Multiplier={itemMultiplier.Value}, Debug={enableDebugLogging.Value} ===");
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} loaded! Multiplier: {2}x", "SqueakyItemMultiplier", "1.0.1", itemMultiplier.Value));
		GenericPickupController.AttemptGrant += new hook_AttemptGrant(OnPickupAttemptGrant);
		((BaseUnityPlugin)this).Logger.LogWarning((object)"=== HOOK REGISTERED ===");
	}

	private void OnPickupAttemptGrant(orig_AttemptGrant orig, GenericPickupController self, CharacterBody body)
	{
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogWarning((object)"=== PICKUP ATTEMPT GRANT CALLED ===");
		if ((Object)(object)body == (Object)null || (Object)(object)self == (Object)null || (Object)(object)body.inventory == (Object)null || itemMultiplier.Value <= 1)
		{
			orig.Invoke(self, body);
			return;
		}
		if (!NetworkServer.active)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Not server, skipping");
			return;
		}
		Inventory inventory = body.inventory;
		Dictionary<ItemIndex, int> dictionary = new Dictionary<ItemIndex, int>();
		GenericStaticEnumerable<ItemIndex, AllItemsEnumerator> allItems = ItemCatalog.allItems;
		AllItemsEnumerator enumerator = allItems.GetEnumerator();
		try
		{
			while (((AllItemsEnumerator)(ref enumerator)).MoveNext())
			{
				ItemIndex current = ((AllItemsEnumerator)(ref enumerator)).Current;
				int itemCountEffective = inventory.GetItemCountEffective(current);
				if (itemCountEffective > 0)
				{
					dictionary[current] = itemCountEffective;
				}
			}
		}
		finally
		{
			((IDisposable)(AllItemsEnumerator)(ref enumerator)).Dispose();
		}
		orig.Invoke(self, body);
		allItems = ItemCatalog.allItems;
		AllItemsEnumerator enumerator2 = allItems.GetEnumerator();
		try
		{
			while (((AllItemsEnumerator)(ref enumerator2)).MoveNext())
			{
				ItemIndex current2 = ((AllItemsEnumerator)(ref enumerator2)).Current;
				int itemCountEffective2 = inventory.GetItemCountEffective(current2);
				int num = (dictionary.ContainsKey(current2) ? dictionary[current2] : 0);
				int num2 = itemCountEffective2 - num;
				if (num2 <= 0)
				{
					continue;
				}
				ItemDef itemDef = ItemCatalog.GetItemDef(current2);
				((BaseUnityPlugin)this).Logger.LogWarning((object)string.Format("=== PICKUP DETECTED: {0}, added {1} ===", ((itemDef != null) ? ((Object)itemDef).name : null) ?? "unknown", num2));
				if (ShouldMultiplyItem(itemDef))
				{
					int num3 = num2 * (itemMultiplier.Value - 1);
					((BaseUnityPlugin)this).Logger.LogWarning((object)$"=== MULTIPLYING: Giving {num3} extra copies ===");
					inventory.GiveItemPermanent(itemDef, num3);
					if (enableDebugLogging.Value)
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)$"Multiplied {itemDef.nameToken} x{itemMultiplier.Value}");
					}
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Item " + ((itemDef != null) ? ((Object)itemDef).name : null) + " filtered out"));
				}
			}
		}
		finally
		{
			((IDisposable)(AllItemsEnumerator)(ref enumerator2)).Dispose();
		}
	}

	private bool ShouldMultiplyItem(ItemDef itemDef)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Invalid comparison between Unknown and I4
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Invalid comparison between Unknown and I4
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Invalid comparison between Unknown and I4
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Invalid comparison between Unknown and I4
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Invalid comparison between Unknown and I4
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Invalid comparison between Unknown and I4
		if ((Object)(object)itemDef == (Object)null || (int)itemDef.tier == 5)
		{
			return false;
		}
		if ((int)itemDef.tier == 3 && !multiplyLunarItems.Value)
		{
			return false;
		}
		if (((int)itemDef.tier == 6 || (int)itemDef.tier == 7 || (int)itemDef.tier == 8 || (int)itemDef.tier == 9) && !multiplyVoidItems.Value)
		{
			return false;
		}
		return !itemDef.ContainsTag((ItemTag)10) && !itemDef.ContainsTag((ItemTag)9);
	}

	public void OnDestroy()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		GenericPickupController.AttemptGrant -= new hook_AttemptGrant(OnPickupAttemptGrant);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"SqueakyItemMultiplier unloaded.");
	}
}
internal static class PluginInfo
{
	public const string PLUGIN_GUID = "com.squeakysquared.squeakyitemmultiplier";

	public const string PLUGIN_NAME = "SqueakyItemMultiplier";

	public const string PLUGIN_VERSION = "1.0.1";
}