Decompiled source of SellInShipPlus v1.0.1

SellInShipPlus.dll

Decompiled 5 months ago
using System.Collections.Generic;
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 Unity.Netcode;
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("SellInShipPlus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SellInShipPlus")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dfd825ea-56e7-4244-a4b7-a0c8a408d1cf")]
[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 SellInShipPlus;

[BepInPlugin("SellInShipPlus", "SellInShipPlus", "1.0.1")]
public class SellInShipPlus : BaseUnityPlugin
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("ThrowObjectServerRpc")]
		private static void ThrowObjectServerRpcPatch(PlayerControllerB __instance, ref NetworkObjectReference grabbedObject, bool droppedInElevator, bool droppedInShipRoom)
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)RoundManager.Instance).IsHost)
			{
				return;
			}
			if (ItemNameDisplay == null)
			{
				ItemNameDisplay = new Dictionary<string, string>();
				foreach (Item items in StartOfRound.Instance.allItemsList.itemsList)
				{
					ConfigEntry<string> val = ((BaseUnityPlugin)Instance).Config.Bind<string>("ItemDisplay", items.itemName, items.itemName, (ConfigDescription)null);
					if (!ItemNameDisplay.ContainsKey(items.itemName))
					{
						ItemNameDisplay.Add(items.itemName, val.Value);
					}
				}
			}
			NetworkObject val2 = null;
			NetworkObjectReference val3 = grabbedObject;
			if (!((NetworkObjectReference)(ref val3)).TryGet(ref val2, (NetworkManager)null))
			{
				return;
			}
			GrabbableObject component = ((Component)val2).GetComponent<GrabbableObject>();
			if (RoundManager.Instance.currentLevel.sceneName != "CompanyBuilding" || !StartOfRound.Instance.shipHasLanded)
			{
				return;
			}
			TimeOfDay instance = TimeOfDay.Instance;
			if (instance.quotaFulfilled > instance.profitQuota || !((Object)(object)component.playerHeldBy == (Object)null && component.itemProperties.isScrap && droppedInShipRoom))
			{
				return;
			}
			string item = component.itemProperties.itemName.ToLower().Replace(" ", "");
			if (NoShellItem2.Contains(item))
			{
				return;
			}
			string text = component.itemProperties.itemName;
			if (ItemNameDisplay.ContainsKey(text))
			{
				text = ItemNameDisplay[text];
			}
			if (component.scrapValue == 0)
			{
				if (LanguageConfig.Value == Language.简体中文)
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=green>[" + __instance.playerUsername + "] 将 <color=yellow>" + text + "</color> 免费送给了老板</color>", -1);
				}
				else
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=green>[" + __instance.playerUsername + "] gave the <color=yellow>" + text + "</color> to the boss as a free gift.</color>", -1);
				}
			}
			else if (LanguageConfig.Value == Language.简体中文)
			{
				HUDManager.Instance.AddTextToChatOnServer($"<color=green>[{__instance.playerUsername}] 出售 <color=yellow>{text}</color> 赚取了{component.scrapValue}元</color>", -1);
			}
			else
			{
				HUDManager.Instance.AddTextToChatOnServer($"<color=green>[{__instance.playerUsername}] sold <color=yellow>{text}</color> earned ${component.scrapValue}</color>", -1);
			}
			DepositItemsDesk val4 = Object.FindObjectOfType<DepositItemsDesk>();
			val4.AddObjectToDeskServerRpc(NetworkObjectReference.op_Implicit(((Component)component).gameObject.GetComponent<NetworkObject>()));
			val4.SellItemsOnServer();
		}
	}

	public enum Language
	{
		简体中文,
		English
	}

	private const string modName = "SellInShipPlus";

	private const string modVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("chuxia.SellInShipPlus");

	private static SellInShipPlus Instance;

	internal ManualLogSource mls;

	public static ConfigEntry<string> NoShellItem { get; private set; }

	public static ConfigEntry<Language> LanguageConfig { get; private set; }

	public static List<string> NoShellItem2 { get; private set; }

	public static Dictionary<string, string> ItemNameDisplay { get; set; }

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		harmony.PatchAll();
		mls = ((BaseUnityPlugin)this).Logger;
		LanguageConfig = ((BaseUnityPlugin)this).Config.Bind<Language>("Setting", "Language", Language.简体中文, "Language Setting");
		NoShellItem = ((BaseUnityPlugin)this).Config.Bind<string>("Setting", "NoSellItem", string.Join(",", new List<string>
		{
			"Ammo", "Boombox", "Jetpack", "Homemade flashbang", "Mapper", "Pro-flashlight", "Radar-booster", "Shotgun", "Shovel", "Stun grenade",
			"TZP-Inhalant", "Walkie-talkie", "Zap gun"
		}), (LanguageConfig.Value == Language.简体中文) ? "不出售的物品" : "NoShellItem");
		NoShellItem2 = (from x in NoShellItem.Value.Split(new char[1] { ',' })
			select x.ToLower().Replace(" ", "")).ToList();
		mls.LogInfo((object)"Plugin SellInShip is loaded!");
	}
}