Decompiled source of TrashItems v1.2.8

TrashItems.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TrashItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TrashItems")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8135d2ba-59ab-4fc3-8fac-3c1e06a67b2f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("1.0.0.0")]
public class WavUtility
{
	private const int BlockSize_16Bit = 2;

	public static AudioClip ToAudioClip(string filePath)
	{
		if (!filePath.StartsWith(Application.persistentDataPath) && !filePath.StartsWith(Application.dataPath))
		{
			Debug.LogWarning((object)"This only supports files that are stored using Unity's Application data path. \nTo load bundled resources use 'Resources.Load(\"filename\") typeof(AudioClip)' method. \nhttps://docs.unity3d.com/ScriptReference/Resources.Load.html");
			return null;
		}
		return ToAudioClip(File.ReadAllBytes(filePath));
	}

	public static AudioClip ToAudioClip(byte[] fileBytes, int offsetSamples = 0, string name = "wav")
	{
		int num = BitConverter.ToInt32(fileBytes, 16);
		FormatCode(BitConverter.ToUInt16(fileBytes, 20));
		ushort num2 = BitConverter.ToUInt16(fileBytes, 22);
		int num3 = BitConverter.ToInt32(fileBytes, 24);
		ushort num4 = BitConverter.ToUInt16(fileBytes, 34);
		int num5 = 20 + num + 4;
		int dataSize = BitConverter.ToInt32(fileBytes, num5);
		float[] array = num4 switch
		{
			8 => Convert8BitByteArrayToAudioClipData(fileBytes, num5, dataSize), 
			16 => Convert16BitByteArrayToAudioClipData(fileBytes, num5, dataSize), 
			24 => Convert24BitByteArrayToAudioClipData(fileBytes, num5, dataSize), 
			32 => Convert32BitByteArrayToAudioClipData(fileBytes, num5, dataSize), 
			_ => throw new Exception(num4 + " bit depth is not supported."), 
		};
		AudioClip obj = AudioClip.Create(name, array.Length, (int)num2, num3, false);
		obj.SetData(array, 0);
		return obj;
	}

	private static float[] Convert8BitByteArrayToAudioClipData(byte[] source, int headerOffset, int dataSize)
	{
		int num = BitConverter.ToInt32(source, headerOffset);
		headerOffset += 4;
		float[] array = new float[num];
		sbyte b = sbyte.MaxValue;
		for (int i = 0; i < num; i++)
		{
			array[i] = (float)(int)source[i] / (float)b;
		}
		return array;
	}

	private static float[] Convert16BitByteArrayToAudioClipData(byte[] source, int headerOffset, int dataSize)
	{
		int num = BitConverter.ToInt32(source, headerOffset);
		headerOffset += 4;
		int num2 = 2;
		int num3 = num / num2;
		float[] array = new float[num3];
		short num4 = short.MaxValue;
		int num5 = 0;
		for (int i = 0; i < num3; i++)
		{
			num5 = i * num2 + headerOffset;
			array[i] = (float)BitConverter.ToInt16(source, num5) / (float)num4;
		}
		return array;
	}

	private static float[] Convert24BitByteArrayToAudioClipData(byte[] source, int headerOffset, int dataSize)
	{
		int num = BitConverter.ToInt32(source, headerOffset);
		headerOffset += 4;
		int num2 = 3;
		int num3 = num / num2;
		int num4 = int.MaxValue;
		float[] array = new float[num3];
		byte[] array2 = new byte[4];
		int num5 = 0;
		for (int i = 0; i < num3; i++)
		{
			num5 = i * num2 + headerOffset;
			Buffer.BlockCopy(source, num5, array2, 1, num2);
			array[i] = (float)BitConverter.ToInt32(array2, 0) / (float)num4;
		}
		return array;
	}

	private static float[] Convert32BitByteArrayToAudioClipData(byte[] source, int headerOffset, int dataSize)
	{
		int num = BitConverter.ToInt32(source, headerOffset);
		headerOffset += 4;
		int num2 = 4;
		int num3 = num / num2;
		int num4 = int.MaxValue;
		float[] array = new float[num3];
		int num5 = 0;
		for (int i = 0; i < num3; i++)
		{
			num5 = i * num2 + headerOffset;
			array[i] = (float)BitConverter.ToInt32(source, num5) / (float)num4;
		}
		return array;
	}

	public static byte[] FromAudioClip(AudioClip audioClip)
	{
		string filepath;
		return FromAudioClip(audioClip, out filepath, saveAsFile: false);
	}

	public static byte[] FromAudioClip(AudioClip audioClip, out string filepath, bool saveAsFile = true, string dirname = "recordings")
	{
		MemoryStream stream = new MemoryStream();
		ushort bitDepth = 16;
		int fileSize = audioClip.samples * audioClip.channels * 2 + 44;
		WriteFileHeader(ref stream, fileSize);
		WriteFileFormat(ref stream, audioClip.channels, audioClip.frequency, bitDepth);
		WriteFileData(ref stream, audioClip, bitDepth);
		byte[] array = stream.ToArray();
		if (saveAsFile)
		{
			filepath = string.Format("{0}/{1}/{2}.{3}", Application.persistentDataPath, dirname, DateTime.UtcNow.ToString("yyMMdd-HHmmss-fff"), "wav");
			Directory.CreateDirectory(Path.GetDirectoryName(filepath));
			File.WriteAllBytes(filepath, array);
		}
		else
		{
			filepath = null;
		}
		stream.Dispose();
		return array;
	}

	private static int WriteFileHeader(ref MemoryStream stream, int fileSize)
	{
		byte[] bytes = Encoding.ASCII.GetBytes("RIFF");
		int num = 0 + WriteBytesToMemoryStream(ref stream, bytes, "ID");
		int value = fileSize - 8;
		int num2 = num + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value), "CHUNK_SIZE");
		byte[] bytes2 = Encoding.ASCII.GetBytes("WAVE");
		return num2 + WriteBytesToMemoryStream(ref stream, bytes2, "FORMAT");
	}

	private static int WriteFileFormat(ref MemoryStream stream, int channels, int sampleRate, ushort bitDepth)
	{
		byte[] bytes = Encoding.ASCII.GetBytes("fmt ");
		int num = 0 + WriteBytesToMemoryStream(ref stream, bytes, "FMT_ID");
		int value = 16;
		int num2 = num + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value), "SUBCHUNK_SIZE");
		ushort value2 = 1;
		int num3 = num2 + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value2), "AUDIO_FORMAT");
		ushort value3 = Convert.ToUInt16(channels);
		int num4 = num3 + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value3), "CHANNELS") + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(sampleRate), "SAMPLE_RATE");
		int value4 = sampleRate * channels * BytesPerSample(bitDepth);
		int num5 = num4 + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value4), "BYTE_RATE");
		ushort value5 = Convert.ToUInt16(channels * BytesPerSample(bitDepth));
		return num5 + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value5), "BLOCK_ALIGN") + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(bitDepth), "BITS_PER_SAMPLE");
	}

	private static int WriteFileData(ref MemoryStream stream, AudioClip audioClip, ushort bitDepth)
	{
		float[] array = new float[audioClip.samples * audioClip.channels];
		audioClip.GetData(array, 0);
		byte[] bytes = ConvertAudioClipDataToInt16ByteArray(array);
		byte[] bytes2 = Encoding.ASCII.GetBytes("data");
		int num = 0 + WriteBytesToMemoryStream(ref stream, bytes2, "DATA_ID");
		int value = Convert.ToInt32(audioClip.samples * audioClip.channels * 2);
		return num + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value), "SAMPLES") + WriteBytesToMemoryStream(ref stream, bytes, "DATA");
	}

	private static byte[] ConvertAudioClipDataToInt16ByteArray(float[] data)
	{
		MemoryStream memoryStream = new MemoryStream();
		int count = 2;
		short num = short.MaxValue;
		for (int i = 0; i < data.Length; i++)
		{
			memoryStream.Write(BitConverter.GetBytes(Convert.ToInt16(data[i] * (float)num)), 0, count);
		}
		byte[] result = memoryStream.ToArray();
		memoryStream.Dispose();
		return result;
	}

	private static int WriteBytesToMemoryStream(ref MemoryStream stream, byte[] bytes, string tag = "")
	{
		int num = bytes.Length;
		stream.Write(bytes, 0, num);
		return num;
	}

	public static ushort BitDepth(AudioClip audioClip)
	{
		return Convert.ToUInt16((float)(audioClip.samples * audioClip.channels) * audioClip.length / (float)audioClip.frequency);
	}

	private static int BytesPerSample(ushort bitDepth)
	{
		return bitDepth / 8;
	}

	private static int BlockSize(ushort bitDepth)
	{
		return bitDepth switch
		{
			32 => 4, 
			16 => 2, 
			8 => 1, 
			_ => throw new Exception(bitDepth + " bit depth is not supported."), 
		};
	}

	private static string FormatCode(ushort code)
	{
		switch (code)
		{
		case 1:
			return "PCM";
		case 2:
			return "ADPCM";
		case 3:
			return "IEEE";
		case 7:
			return "μ-law";
		case 65534:
			return "WaveFormatExtensable";
		default:
			Debug.LogWarning((object)("Unknown wav code format:" + code));
			return "";
		}
	}
}
namespace TrashItems;

[BepInPlugin("virtuacode.valheim.trashitems", "Trash Items Mod", "1.2.8")]
internal class TrashItems : BaseUnityPlugin
{
	public enum SoundEffect
	{
		None,
		Sound1,
		Sound2,
		Sound3,
		Random
	}

	public class TrashButton : MonoBehaviour
	{
		private Canvas canvas;

		private GraphicRaycaster raycaster;

		private RectTransform rectTransform;

		private GameObject buttonGo;

		private void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Expected O, but got Unknown
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)InventoryGui.instance == (Object)null))
			{
				Transform transform = ((Component)InventoryGui.instance.m_player).transform;
				RectTransform component = ((Component)this).GetComponent<RectTransform>();
				component.anchoredPosition -= new Vector2(0f, 78f);
				SetText(TrashLabel.Value);
				SetColor(TrashColor.Value);
				Transform obj = ((Component)this).transform.Find("armor_icon");
				if (!Object.op_Implicit((Object)(object)obj))
				{
					LogErr("armor_icon not found!");
				}
				((Component)obj).GetComponent<Image>().sprite = trashSprite;
				((Component)this).transform.SetSiblingIndex(0);
				((Object)((Component)((Component)this).transform).gameObject).name = "Trash";
				buttonGo = new GameObject("ButtonCanvas");
				rectTransform = buttonGo.AddComponent<RectTransform>();
				((Component)rectTransform).transform.SetParent(((Component)((Component)this).transform).transform, true);
				rectTransform.anchoredPosition = Vector2.zero;
				rectTransform.sizeDelta = new Vector2(70f, 74f);
				canvas = buttonGo.AddComponent<Canvas>();
				raycaster = buttonGo.AddComponent<GraphicRaycaster>();
				((UnityEvent)buttonGo.AddComponent<Button>().onClick).AddListener(new UnityAction(TrashItem));
				((Graphic)buttonGo.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
				GameObject val = Object.Instantiate<GameObject>(((Component)transform.Find("selected_frame").GetChild(0)).gameObject, ((Component)this).transform);
				val.GetComponent<Image>().sprite = bgSprite;
				val.transform.SetAsFirstSibling();
				val.GetComponent<RectTransform>().sizeDelta = new Vector2(-8f, 22f);
				val.GetComponent<RectTransform>().anchoredPosition = new Vector2(6f, 7.5f);
				UIGroupHandler val2 = ((Component)this).gameObject.AddComponent<UIGroupHandler>();
				val2.m_groupPriority = 1;
				val2.m_enableWhenActiveAndGamepad = val;
				_gui.m_uiGroups = CollectionExtensions.AddToArray<UIGroupHandler>(_gui.m_uiGroups, val2);
				((Component)this).gameObject.AddComponent<TrashHandler>();
			}
		}

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(DelayedOverrideSorting());
		}

		private IEnumerator DelayedOverrideSorting()
		{
			yield return null;
			if (!((Object)(object)canvas == (Object)null))
			{
				canvas.overrideSorting = true;
				canvas.sortingOrder = 1;
			}
		}

		public void SetText(string text)
		{
			Transform val = ((Component)this).transform.Find("ac_text");
			if (!Object.op_Implicit((Object)(object)val))
			{
				LogErr("ac_text not found!");
			}
			else
			{
				((Component)val).GetComponent<TMP_Text>().text = text;
			}
		}

		public void SetColor(Color color)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)this).transform.Find("ac_text");
			if (!Object.op_Implicit((Object)(object)val))
			{
				LogErr("ac_text not found!");
			}
			else
			{
				((Graphic)((Component)val).GetComponent<TMP_Text>()).color = color;
			}
		}
	}

	public static ConfigEntry<bool> ConfirmDialog;

	public static ConfigEntry<KeyboardShortcut> TrashHotkey;

	public static ConfigEntry<SoundEffect> Sfx;

	public static ConfigEntry<Color> TrashColor;

	public static ConfigEntry<string> TrashLabel;

	public static bool _clickedTrash = false;

	public static bool _confirmed = false;

	public static InventoryGui _gui;

	public static Sprite trashSprite;

	public static Sprite bgSprite;

	public static GameObject dialog;

	public static AudioClip[] sounds = (AudioClip[])(object)new AudioClip[3];

	public static Transform trash;

	public static AudioSource audio;

	public static TrashButton trashButton;

	public static ManualLogSource MyLogger;

	public static void Log(string msg)
	{
		ManualLogSource myLogger = MyLogger;
		if (myLogger != null)
		{
			myLogger.LogInfo((object)msg);
		}
	}

	public static void LogErr(string msg)
	{
		ManualLogSource myLogger = MyLogger;
		if (myLogger != null)
		{
			myLogger.LogError((object)msg);
		}
	}

	public static void LogWarn(string msg)
	{
		ManualLogSource myLogger = MyLogger;
		if (myLogger != null)
		{
			myLogger.LogWarning((object)msg);
		}
	}

	private void Awake()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		MyLogger = ((BaseUnityPlugin)this).Logger;
		ConfirmDialog = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ConfirmDialog", false, "Show confirm dialog");
		Sfx = ((BaseUnityPlugin)this).Config.Bind<SoundEffect>("General", "SoundEffect", SoundEffect.Random, "Sound effect when trashing items");
		TrashHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "TrashHotkey", KeyboardShortcut.Deserialize("Delete"), "Hotkey for destroying items");
		TrashLabel = ((BaseUnityPlugin)this).Config.Bind<string>("General", "TrashLabel", "Trash", "Label for the trash button");
		TrashColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "TrashColor", new Color(1f, 0.8482759f, 0f), "Color for the trash label");
		TrashLabel.SettingChanged += delegate
		{
			if ((Object)(object)trashButton != (Object)null)
			{
				trashButton.SetText(TrashLabel.Value);
			}
		};
		TrashColor.SettingChanged += delegate
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)trashButton != (Object)null)
			{
				trashButton.SetColor(TrashColor.Value);
			}
		};
		Log("TrashItems Loaded!");
		trashSprite = LoadSprite("TrashItems.res.trash.png", new Rect(0f, 0f, 64f, 64f), new Vector2(32f, 32f));
		bgSprite = LoadSprite("TrashItems.res.trashmask.png", new Rect(0f, 0f, 96f, 112f), new Vector2(48f, 56f));
		sounds[0] = LoadAudioClip("TrashItems.res.trash1.wav");
		sounds[1] = LoadAudioClip("TrashItems.res.trash2.wav");
		sounds[2] = LoadAudioClip("TrashItems.res.trash3.wav");
		Harmony.CreateAndPatchAll(typeof(TrashItems), (string)null);
	}

	public static AudioClip LoadAudioClip(string path)
	{
		Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
		using MemoryStream memoryStream = new MemoryStream();
		manifestResourceStream.CopyTo(memoryStream);
		return WavUtility.ToAudioClip(memoryStream.GetBuffer());
	}

	public static Sprite LoadSprite(string path, Rect size, Vector2 pivot, int units = 100)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
		Texture2D val = new Texture2D((int)((Rect)(ref size)).width, (int)((Rect)(ref size)).height, (TextureFormat)4, false, true);
		using MemoryStream memoryStream = new MemoryStream();
		manifestResourceStream.CopyTo(memoryStream);
		ImageConversion.LoadImage(val, memoryStream.ToArray());
		val.Apply();
		return Sprite.Create(val, size, pivot, (float)units);
	}

	[HarmonyPatch(typeof(InventoryGui), "Show")]
	[HarmonyPostfix]
	public static void Show_Postfix(InventoryGui __instance)
	{
		Transform transform = ((Component)InventoryGui.instance.m_player).transform;
		trash = transform.Find("Trash");
		if (!((Object)(object)trash != (Object)null))
		{
			_gui = InventoryGui.instance;
			trash = Object.Instantiate<Transform>(transform.Find("Armor"), transform);
			trashButton = ((Component)trash).gameObject.AddComponent<TrashButton>();
			AudioMixerGroup outputAudioMixerGroup = AudioMan.instance.m_masterMixer.FindMatchingGroups("GUI")[0];
			audio = ((Component)trash).gameObject.AddComponent<AudioSource>();
			audio.playOnAwake = false;
			audio.loop = false;
			audio.outputAudioMixerGroup = outputAudioMixerGroup;
			audio.bypassReverbZones = true;
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	[HarmonyPostfix]
	public static void Postfix()
	{
		OnCancel();
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(InventoryGui), "UpdateItemDrag")]
	public static void UpdateItemDrag_Postfix(InventoryGui __instance, ref GameObject ___m_dragGo, ItemData ___m_dragItem, Inventory ___m_dragInventory, int ___m_dragAmount)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = TrashHotkey.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			_clickedTrash = true;
		}
		if (_clickedTrash && ___m_dragItem != null && ___m_dragInventory.ContainsItem(___m_dragItem))
		{
			if (ConfirmDialog.Value)
			{
				if (!_confirmed)
				{
					ShowConfirmDialog(___m_dragItem, ___m_dragAmount);
					_clickedTrash = false;
					return;
				}
				_confirmed = false;
			}
			if (___m_dragAmount == ___m_dragItem.m_stack)
			{
				((Humanoid)Player.m_localPlayer).RemoveEquipAction(___m_dragItem);
				((Humanoid)Player.m_localPlayer).UnequipItem(___m_dragItem, false);
				___m_dragInventory.RemoveItem(___m_dragItem);
			}
			else
			{
				___m_dragInventory.RemoveItem(___m_dragItem, ___m_dragAmount);
			}
			if ((Object)(object)audio != (Object)null)
			{
				switch (Sfx.Value)
				{
				case SoundEffect.Random:
					audio.PlayOneShot(sounds[Random.Range(0, 3)]);
					break;
				case SoundEffect.Sound1:
					audio.PlayOneShot(sounds[0]);
					break;
				case SoundEffect.Sound2:
					audio.PlayOneShot(sounds[1]);
					break;
				case SoundEffect.Sound3:
					audio.PlayOneShot(sounds[2]);
					break;
				}
			}
			((object)__instance).GetType().GetMethod("SetupDragItem", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[3] { null, null, 0 });
			((object)__instance).GetType().GetMethod("UpdateCraftingPanel", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[1] { false });
		}
		_clickedTrash = false;
	}

	public static void ShowConfirmDialog(ItemData item, int itemAmount)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Expected O, but got Unknown
		if (!((Object)(object)InventoryGui.instance == (Object)null) && !((Object)(object)dialog != (Object)null))
		{
			dialog = Object.Instantiate<GameObject>(((Component)InventoryGui.instance.m_splitPanel).gameObject, ((Component)InventoryGui.instance).transform);
			Button component = ((Component)dialog.transform.Find("win_bkg/Button_ok")).GetComponent<Button>();
			((UnityEventBase)component.onClick).RemoveAllListeners();
			((UnityEvent)component.onClick).AddListener(new UnityAction(OnConfirm));
			((TMP_Text)((Component)component).GetComponentInChildren<TextMeshProUGUI>()).text = "Trash";
			((Graphic)((Component)component).GetComponentInChildren<TextMeshProUGUI>()).color = new Color(1f, 0.2f, 0.1f);
			Button component2 = ((Component)dialog.transform.Find("win_bkg/Button_cancel")).GetComponent<Button>();
			((UnityEventBase)component2.onClick).RemoveAllListeners();
			((UnityEvent)component2.onClick).AddListener(new UnityAction(OnCancel));
			((Component)dialog.transform.Find("win_bkg/Slider")).gameObject.SetActive(false);
			((TMP_Text)((Component)dialog.transform.Find("win_bkg/Text")).GetComponent<TextMeshProUGUI>()).text = Localization.instance.Localize(item.m_shared.m_name);
			((Component)dialog.transform.Find("win_bkg/Icon_bkg/Icon")).GetComponent<Image>().sprite = item.GetIcon();
			((TMP_Text)((Component)dialog.transform.Find("win_bkg/amount")).GetComponent<TextMeshProUGUI>()).text = itemAmount + "/" + item.m_shared.m_maxStackSize;
			dialog.gameObject.SetActive(true);
		}
	}

	public static void OnConfirm()
	{
		_confirmed = true;
		if ((Object)(object)dialog != (Object)null)
		{
			Object.Destroy((Object)(object)dialog);
			dialog = null;
		}
		TrashItem();
	}

	public static void OnCancel()
	{
		_confirmed = false;
		if ((Object)(object)dialog != (Object)null)
		{
			Object.Destroy((Object)(object)dialog);
			dialog = null;
		}
	}

	public static void TrashItem()
	{
		Log("Trash Items clicked!");
		if ((Object)(object)_gui == (Object)null)
		{
			LogErr("_gui is null");
			return;
		}
		_clickedTrash = true;
		((object)_gui).GetType().GetMethod("UpdateItemDrag", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_gui, new object[0]);
	}
}
public class TrashHandler : MonoBehaviour
{
	private UIGroupHandler handler;

	private void Awake()
	{
		handler = ((Component)this).GetComponent<UIGroupHandler>();
		handler.SetActive(false);
	}

	private void Update()
	{
		if (ZInput.GetButtonDown("JoyButtonA") && handler.IsActive)
		{
			TrashItems.TrashItem();
			typeof(InventoryGui).GetMethod("SetActiveGroup", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(InventoryGui.instance, new object[2] { 1, false });
		}
	}
}