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 GrabToSellInput;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GrabToSellUpdated")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GrabToSellUpdated")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("38926480-47cc-4112-bbd1-ef698c3cdffb")]
[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 GrabToSellUpdated
{
[HarmonyPatch(typeof(HUDManager), "Update")]
internal class HUDPatch
{
private static InputAction switchKeyAction;
private static bool isInCompanyOrGaletry;
static HUDPatch()
{
switchKeyAction = GrabToSellInputActions.Instance.GrabToSellKey;
isInCompanyOrGaletry = false;
Plugin.Instance.whiteList = (from s in Plugin.Instance.whiteListNames.Value.Split(new char[1] { ',' })
select s.ToLower().Trim()).ToArray();
}
[HarmonyPostfix]
public static void Postfix()
{
if (!isInCompanyOrGaletry)
{
return;
}
if (switchKeyAction != null && switchKeyAction.triggered)
{
Plugin.Instance.holdSellMode = !Plugin.Instance.holdSellMode;
string text = (Plugin.Instance.holdSellMode ? "ON" : "OFF");
HUDManager.Instance.DisplayTip("Note:", "Grab To Sell mode " + text + "!", false, false, "LC_Tip1");
}
if (!Plugin.Instance.holdSellMode)
{
return;
}
PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
if ((Object)(object)localPlayerController == (Object)null || localPlayerController.isGrabbingObjectAnimation || localPlayerController.isTypingChat || localPlayerController.inSpecialInteractAnimation || localPlayerController.activatingItem || !localPlayerController.isHoldingObject || !((Object)(object)localPlayerController.currentlyHeldObjectServer != (Object)null))
{
return;
}
GrabbableObject currentlyHeldObjectServer = localPlayerController.currentlyHeldObjectServer;
if (currentlyHeldObjectServer.itemProperties.isScrap && !Plugin.Instance.whiteList.Contains(currentlyHeldObjectServer.itemProperties.itemName.ToLower()))
{
DepositItemsDesk val = Object.FindObjectOfType<DepositItemsDesk>();
if ((Object)(object)val != (Object)null)
{
val.PlaceItemOnCounter(localPlayerController);
}
}
}
[HarmonyPatch(typeof(StartOfRound), "ChangeLevel")]
[HarmonyPostfix]
private static void OnLevelChange()
{
string text = StartOfRound.Instance.currentLevel?.sceneName ?? "";
isInCompanyOrGaletry = text == "CompanyBuilding" || text == "MusemaScene";
if (!isInCompanyOrGaletry && Plugin.Instance.holdSellMode && Plugin.Instance.SwitchOffonLeave.Value)
{
Plugin.Instance.holdSellMode = false;
HUDManager.Instance.DisplayTip("Note", "Grab To Sell mode OFF (left Company)!", false, false, "LC_Tip1");
}
}
}
[BepInPlugin("nexor-kestrel.GrabToSell", "GrabToSellUpdated", "0.0.9")]
public class Plugin : BaseUnityPlugin
{
public const string ModGUID = "nexor-kestrel.GrabToSell";
public const string ModName = "GrabToSellUpdated";
public const string ModVersion = "0.0.9";
private readonly Harmony harmony = new Harmony("nexor-kestrel.GrabToSell");
public ConfigEntry<string> whiteListNames;
public ConfigEntry<bool> SwitchOffonLeave;
public string[] whiteList = Array.Empty<string>();
public bool holdSellMode;
public static Plugin Instance { get; private set; }
public static ManualLogSource Log { get; private set; }
private void Awake()
{
if ((Object)(object)Instance != (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"GrabToSellUpdated already has an active instance!");
return;
}
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
SwitchOffonLeave = ((BaseUnityPlugin)this).Config.Bind<bool>("Grab To Sell Config", "Setting type: Boolean", true, "Auto disable GrabToSell mode when leaving (from Orbit)");
whiteListNames = ((BaseUnityPlugin)this).Config.Bind<string>("Grab To Sell Config", "Whitelist", "kitchen knife, shotgun", "Names are separated by commas.");
whiteList = (from x in whiteListNames.Value.Split(new char[1] { ',' })
select x.Trim().ToLower()).ToArray();
harmony.PatchAll();
Log.LogInfo((object)"GrabToSellUpdated 0.0.9 loaded.");
}
}
}
namespace GrabToSellInput
{
public class GrabToSellInputActions : LcInputActions
{
[InputAction(/*Could not decode attribute arguments.*/)]
public InputAction GrabToSellKey { get; set; }
public static GrabToSellInputActions Instance { get; } = new GrabToSellInputActions();
}
}