Decompiled source of ItemResistUpgrade v1.0.2

ItemResistUpgrade.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MoreUpgrades.Classes;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CarefulUpgrade")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CarefulUpgrade")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7cb998b0-02aa-4eee-92fa-7ca8822e7a50")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ItemResistUpgrade
{
	[BepInPlugin("sandwich.itemResistUpgrade", "ItemResistUpgrade", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin instance;

		internal const string modGUID = "sandwich.itemResistUpgrade";

		private const string modName = "ItemResistUpgrade";

		private const string modVersion = "1.0.2";

		internal static ConfigEntry<float> configPower;

		private readonly Harmony harmony = new Harmony("sandwich.itemResistUpgrade");

		internal ManualLogSource mls;

		protected void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("ItemResistUpgrade");
			string text = "Item Resist";
			string value = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Upgrade Name", text, "The name to use for the upgrade.").Value;
			configPower = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Item Resist Upgrade Power", 0.8f, "The multiplier of item resist per upgrade on an item (Lower is stronger)");
			float value2 = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Minimum Price", 4000f, "The minimum base price of the upgrade.").Value;
			float value3 = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Maximum Price", 6000f, "The maximum base price of the upgrade.").Value;
			int value4 = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Shop Amount Maximum", 2, "The maximum amount of times the upgrade can appear in the shop.").Value;
			string text2 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "itemresistbundle");
			AssetBundle val = AssetBundle.LoadFromFile(text2);
			Item val2 = val.LoadAsset<Item>(text);
			GameObject val3 = val.LoadAsset<GameObject>(text + " Prefab");
			List<string> list = new List<string> { "Enabled", "Starting Amount", "Allow Team Upgrades" };
			MoreUpgradesLib.Register("sandwich.itemResistUpgrade", val2, val3, value, 1000, value4, value2, value3, 0, list);
			mls.LogInfo((object)"ItemResistUpgrade is loaded");
			harmony.PatchAll();
		}
	}
}
namespace ItemResistUpgrade.Patches
{
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector))]
	internal class PhysGrabObjectImpactDetectorPatch
	{
		[HarmonyPatch("Break")]
		[HarmonyPrefix]
		private static void Break(PhysGrabObjectImpactDetector __instance, ref float valueLost)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0101: 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_0108: Expected O, but got Unknown
			//IL_010e: Expected O, but got Unknown
			PhysGrabObject val = (PhysGrabObject)AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "physGrabObject").GetValue(__instance);
			List<PhysGrabber> playerGrabbing = val.playerGrabbing;
			if (playerGrabbing != null && playerGrabbing.Count > 0)
			{
				List<string> list = playerGrabbing.Select((PhysGrabber player) => SemiFunc.PlayerGetSteamID(player.playerAvatar)).ToList();
				IReadOnlyList<UpgradeItem> upgradeItemsByMod = MoreUpgradesLib.GetUpgradeItemsByMod("sandwich.itemResistUpgrade");
				if (upgradeItemsByMod.Count <= 0)
				{
					return;
				}
				int num = 0;
				foreach (string item in list)
				{
					int amount = upgradeItemsByMod[0].GetAmount(item);
					num = Math.Max(num, amount);
				}
				valueLost = ReduceValueLost(valueLost, num);
				return;
			}
			PlayerAvatar val2 = (PlayerAvatar)AccessTools.Field(typeof(PhysGrabObject), "lastPlayerGrabbing").GetValue(val);
			PlayerAvatar val3 = val2;
			if ((Object)val2 != (Object)null)
			{
				string text = SemiFunc.PlayerGetSteamID(val3);
				IReadOnlyList<UpgradeItem> upgradeItemsByMod2 = MoreUpgradesLib.GetUpgradeItemsByMod("sandwich.itemResistUpgrade");
				int upgradeTotal = 0;
				if (upgradeItemsByMod2.Count > 0)
				{
					upgradeTotal = upgradeItemsByMod2[0].GetAmount(text);
				}
				valueLost = ReduceValueLost(valueLost, upgradeTotal);
			}
		}

		private static float ReduceValueLost(float valueLost, int upgradeTotal)
		{
			float num = (float)Math.Pow(Plugin.configPower.Value, upgradeTotal);
			return valueLost * num;
		}
	}
}