Decompiled source of SellYourStuff v1.0.1

SellYourStuff.dll

Decompiled 10 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using SellYourStuff.Patches;
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("SellYourStuff")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SellYourStuff")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("be25d89d-f866-45bd-808b-723b2d0aa1f8")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SellYourStuff
{
	[BepInPlugin("Axeron.SellYourStuff", "SellYourStuff", "1.0.1.0")]
	public class SellYourStuffModBase : BaseUnityPlugin
	{
		private const string modGUID = "Axeron.SellYourStuff";

		private const string modName = "SellYourStuff";

		private const string modVersion = "1.0.1.0";

		private readonly Harmony harmony = new Harmony("Axeron.SellYourStuff");

		internal ManualLogSource mls;

		private static SellYourStuffModBase Instance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Axeron.SellYourStuff");
			mls.LogInfo((object)"SellYourStuff plugin loaded. Version 1.0.1.0");
			harmony.PatchAll(typeof(SellYourStuffModBase));
			harmony.PatchAll(typeof(ItemPatch));
			harmony.PatchAll(typeof(SellPatch));
		}
	}
}
namespace SellYourStuff.Patches
{
	internal class PatchableItemsList
	{
		protected static readonly List<string> PatchableItems = new List<string>
		{
			"Flashlight", "Extension ladder", "Lockpicker", "Jetpack", "Pro-flashlight", "TZP-Inhalant", "Stun grenade", "Boombox", "Spray paint", "Shovel",
			"Walkie-talkie", "Zap gun", "Radar-booster"
		};
	}
	[HarmonyPatch(typeof(DepositItemsDesk))]
	internal class SellPatch : PatchableItemsList
	{
		[HarmonyPatch("PlaceItemOnCounter")]
		private static void Prefix(DepositItemsDesk __instance, [HarmonyArgument(0)] PlayerControllerB playerWhoTriggered)
		{
			if ((Object)(object)playerWhoTriggered != (Object)null)
			{
				GrabbableObject currentlyHeldObjectServer = playerWhoTriggered.currentlyHeldObjectServer;
				if ((Object)(object)currentlyHeldObjectServer != (Object)null && (Object)(object)currentlyHeldObjectServer.itemProperties != (Object)null && PatchableItemsList.PatchableItems.Contains(currentlyHeldObjectServer.itemProperties.itemName))
				{
					currentlyHeldObjectServer.itemProperties.isScrap = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class ItemPatch : PatchableItemsList
	{
		private const int NodeType = 2;

		private const int MinRange = 3;

		private const int MaxRange = 12;

		private const int creatureScanId = -1;

		private const bool requiresLineOfSight = false;

		[HarmonyPatch("Start")]
		private static void Postfix(GrabbableObject __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.itemProperties != (Object)null && PatchableItemsList.PatchableItems.Contains(__instance.itemProperties.itemName))
			{
				TryAddScanNode(__instance);
				__instance.itemProperties.isScrap = true;
				TrySetScrapValue(__instance);
				__instance.itemProperties.isScrap = false;
			}
		}

		private static void TrySetScrapValue(GrabbableObject __instance)
		{
			try
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				for (int i = 0; i < Object.FindObjectOfType<Terminal>().buyableItemsList.Length; i++)
				{
					if (val.buyableItemsList[i].itemName == __instance.itemProperties.itemName)
					{
						int num = val.itemSalesPercentages[i];
						__instance.SetScrapValue(__instance.itemProperties.creditsWorth * num / 200);
					}
				}
			}
			catch
			{
				Debug.LogError((object)"Item not found in the current terminal store or other error occured");
			}
		}

		private static void TryAddScanNode(GrabbableObject __instance)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				object headerText = ((Component)__instance).gameObject.GetComponentInChildren<ScanNodeProperties>().headerText;
			}
			catch
			{
				GameObject gameObject = ((Component)Object.FindObjectOfType<ScanNodeProperties>()).gameObject;
				if ((Object)(object)gameObject != (Object)null)
				{
					GameObject val = Object.Instantiate<GameObject>(gameObject, ((Component)__instance).transform.position, Quaternion.Euler(Vector3.zero), ((Component)__instance).transform);
					ScanNodeProperties component = val.GetComponent<ScanNodeProperties>();
					if ((Object)(object)component != (Object)null)
					{
						component.headerText = __instance.itemProperties.itemName;
						component.nodeType = 2;
						component.minRange = 3;
						component.maxRange = 12;
						component.requiresLineOfSight = false;
						component.creatureScanID = -1;
					}
				}
				else
				{
					Debug.LogError((object)"Couldn't create scanNode for object");
				}
			}
		}
	}
}