Decompiled source of SellTracker v1.2.1

BepInEx/plugins/SellTracker.dll

Decompiled 11 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SellTracker")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SellTracker")]
[assembly: AssemblyTitle("SellTracker")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SellTracker;

[BepInPlugin("NutNutty.SellTracker", "Sell Tracker", "1.2.1")]
public class SellTracker : BaseUnityPlugin
{
	public ConfigEntry<string> SellTrackerColorConfig;

	public ConfigEntry<string> SellPercentageColorConfig;

	public static Color SellTrackerColor;

	public static Color SellPercentageColor;

	public void Awake()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		SellTrackerColorConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "SellTrackerColor", "#FF0000", "The hex color of the sell tracker text (use a site like https://htmlcolorcodes.com to generate a hex code)");
		SellPercentageColorConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "SellPercentageColor", "#FF0000", "The hex color of the sell percentage text (use a site like https://htmlcolorcodes.com to generate a hex code)");
		ColorUtility.TryParseHtmlString(SellTrackerColorConfig.Value, ref SellTrackerColor);
		ColorUtility.TryParseHtmlString(SellPercentageColorConfig.Value, ref SellPercentageColor);
		new Harmony("SellTracker").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Sell Tracker plugin loaded!");
	}
}
public class Patches
{
	[HarmonyPatch(typeof(DisplayCompanyBuyingRate))]
	public class DisplayCompanyBuyingRatePatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		public static bool OverwriteText(ref DisplayCompanyBuyingRate __instance)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			int num = TimeOfDay.Instance.quotaFulfilled + calculatedValue;
			((TMP_Text)__instance.displayText).text = $"PROFIT QUOTA: {num}/{TimeOfDay.Instance.profitQuota}";
			((TMP_Text)__instance.displayText).color = SellTracker.SellTrackerColor;
			((TMP_Text)__instance.displayText).fontSize = 28f;
			return false;
		}
	}

	[HarmonyPatch(typeof(DepositItemsDesk))]
	public class DepositItemsDeskPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("AddObjectToDeskClientRpc")]
		public static void FetchValue(ref DepositItemsDesk __instance)
		{
			if (!NetworkManager.Singleton.IsServer && NetworkManager.Singleton.IsClient)
			{
				object value = Traverse.Create((object)__instance).Field("lastObjectAddedToDesk").GetValue();
				NetworkObject val = (NetworkObject)((value is NetworkObject) ? value : null);
				__instance.itemsOnCounter.Add(((Component)val).GetComponentInChildren<GrabbableObject>());
			}
			int num = 0;
			for (int i = 0; i < __instance.itemsOnCounter.Count; i++)
			{
				if (__instance.itemsOnCounter[i].itemProperties.isScrap)
				{
					num += __instance.itemsOnCounter[i].scrapValue;
				}
			}
			calculatedValue = (int)((float)num * StartOfRound.Instance.companyBuyingRate);
		}

		[HarmonyPostfix]
		[HarmonyPatch("SellItemsClientRpc")]
		public static void ClearValue(ref DepositItemsDesk __instance)
		{
			if (!NetworkManager.Singleton.IsServer && NetworkManager.Singleton.IsClient)
			{
				__instance.itemsOnCounter.Clear();
			}
			calculatedValue = 0;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void CreateScreen()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			Scene sceneByName = SceneManager.GetSceneByName("CompanyBuilding");
			if (((Scene)(ref sceneByName)).IsValid())
			{
				GameObject val = Object.Instantiate<GameObject>(GameObject.Find("/Cube"));
				GameObject val2 = Object.Instantiate<GameObject>(GameObject.Find("/Canvas"));
				SceneManager.MoveGameObjectToScene(val, sceneByName);
				SceneManager.MoveGameObjectToScene(val2, sceneByName);
				Transform transform = val.transform;
				transform.position += new Vector3(0f, 0f, -3f);
				Transform transform2 = val2.transform;
				transform2.position += new Vector3(0f, 0f, -3f);
				Object.Destroy((Object)(object)val2.GetComponentInChildren<DisplayCompanyBuyingRate>());
				TextMeshProUGUI componentInChildren = val2.GetComponentInChildren<TextMeshProUGUI>();
				((TMP_Text)componentInChildren).text = $"{Mathf.RoundToInt(StartOfRound.Instance.companyBuyingRate * 100f)}%";
				((TMP_Text)componentInChildren).color = SellTracker.SellPercentageColor;
				((TMP_Text)componentInChildren).fontSize = 64.37f;
			}
		}
	}

	public static int calculatedValue;
}