Decompiled source of GrabToSell Without NoSellLimit Dependency v0.0.1

GrabToSell.dll

Decompiled 4 hours ago
using System;
using System.Diagnostics;
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 GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HoldToSell")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HoldToSell")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5833e1b-c172-4f1f-a945-d34035fdc8c0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GrabToSell;

[BepInPlugin("nexor.GrabToSell", "GrabToSell", "0.0.5")]
public class GrabToSell : BaseUnityPlugin
{
	private const string modGUID = "nexor.GrabToSell";

	private const string modName = "GrabToSell";

	private const string modVersion = "0.0.5";

	private readonly Harmony harmony = new Harmony("nexor.GrabToSell");

	public ConfigEntry<string> switchKey;

	public ConfigEntry<string> white_list_name;

	public static GrabToSell Instance;

	public static ManualLogSource Logger;

	public bool hold_sell_mode = false;

	public string[] white_list = null;

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		switchKey = ((BaseUnityPlugin)this).Config.Bind<string>("Grab To Sell Config", "Grab To Sell mode switch key(切换快速售卖模式的按键)", "F11", "Grab To Sell mode only works on company. 快速售卖模式仅在公司有用");
		white_list_name = ((BaseUnityPlugin)this).Config.Bind<string>("Grab To Sell Config", "the item list which will not trigger GrabToSell i.e. an item whitelist, (不会触发 GrabToSell 的物品列表,也就是物品白名单)", "easter egg, kitchen knife, shotgun", "Names are separated by commas. 名字间用逗号隔开");
		Logger = ((BaseUnityPlugin)this).Logger;
		harmony.PatchAll();
		Logger.LogInfo((object)"GrabToSell 0.0.5 loaded.");
	}
}
[HarmonyPatch(typeof(HUDManager), "Update")]
internal class HUDPatch
{
	private static Key switchKey;

	static HUDPatch()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		if (!Enum.TryParse<Key>(GrabToSell.Instance.switchKey.Value, ignoreCase: true, out switchKey))
		{
			switchKey = (Key)104;
		}
		GrabToSell.Instance.white_list = GrabToSell.Instance.white_list_name.Value.Split(new char[1] { ',' });
		for (int i = 0; i < GrabToSell.Instance.white_list.Length; i++)
		{
			GrabToSell.Instance.white_list[i] = GrabToSell.Instance.white_list[i].ToLower().Trim();
		}
	}

	[HarmonyPostfix]
	public static void Postfix()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		if (RoundManager.Instance.currentLevel.sceneName != "CompanyBuilding")
		{
			return;
		}
		if (((ButtonControl)Keyboard.current[switchKey]).wasPressedThisFrame)
		{
			GrabToSell.Instance.hold_sell_mode = !GrabToSell.Instance.hold_sell_mode;
			if (GrabToSell.Instance.hold_sell_mode)
			{
				HUDManager.Instance.DisplayTip("Warning", "Grab To Sell mode ON!", false, false, "LC_Tip1");
			}
			else
			{
				HUDManager.Instance.DisplayTip("Warning", "Grab To Sell mode OFF!", false, false, "LC_Tip1");
			}
		}
		if (GrabToSell.Instance.hold_sell_mode)
		{
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			if (!localPlayerController.isGrabbingObjectAnimation && !localPlayerController.isTypingChat && !localPlayerController.inSpecialInteractAnimation && !localPlayerController.activatingItem && localPlayerController.isHoldingObject && (Object)(object)localPlayerController.currentlyHeldObjectServer != (Object)null && (Object)(object)Object.FindObjectOfType<DepositItemsDesk>() != (Object)null && (Object)(object)localPlayerController.currentlyHeldObjectServer != (Object)null && localPlayerController.currentlyHeldObjectServer.itemProperties.isScrap && !GrabToSell.Instance.white_list.Contains(localPlayerController.currentlyHeldObjectServer.itemProperties.itemName.ToLower()))
			{
				DepositItemsDesk val = Object.FindObjectOfType<DepositItemsDesk>();
				val.PlaceItemOnCounter(localPlayerController);
			}
		}
	}
}