Decompiled source of UISellTracker v22.0.3

plugins/UISellTracker.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
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("UISellTracker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UISellTracker")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3fb0aa92-c044-4ff5-b18a-a333e227e343")]
[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 UISellTracker;

internal class Patches
{
	private static GameObject TrackerObject;

	private static TextMeshProUGUI TrackerText;

	private static GameObject OvertimeObject;

	private static TextMeshProUGUI OvertimeText;

	[HarmonyPatch(typeof(DepositItemsDesk), "Start")]
	[HarmonyPostfix]
	private static void PostStart()
	{
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)TrackerObject))
		{
			GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/ValueCounter");
			if (!Object.op_Implicit((Object)(object)val))
			{
				UISellTracker.mls.LogError((object)"beef");
			}
			TrackerObject = Object.Instantiate<GameObject>(val, val.transform.parent, false);
			TrackerObject.transform.Translate(0f, 1f, 0f);
			Vector3 localPosition = TrackerObject.transform.localPosition;
			TrackerObject.transform.localPosition = new Vector3(localPosition.x + 50f, -70f, localPosition.z);
			TrackerText = TrackerObject.GetComponentInChildren<TextMeshProUGUI>();
			OvertimeObject = Object.Instantiate<GameObject>(val, val.transform.parent, false);
			OvertimeObject.transform.Translate(0f, 1f, 0f);
			OvertimeObject.transform.localPosition = new Vector3(localPosition.x + 50f, -90f, localPosition.z);
			OvertimeText = OvertimeObject.GetComponentInChildren<TextMeshProUGUI>();
		}
		((TMP_Text)TrackerText).text = $"QUOTA: ${TimeOfDay.Instance.quotaFulfilled}/{TimeOfDay.Instance.profitQuota}";
		TrackerObject.SetActive(true);
		((TMP_Text)OvertimeText).text = $"OVERTIME: ${Math.Max(0, (TimeOfDay.Instance.quotaFulfilled - TimeOfDay.Instance.profitQuota) / 5 + 15 * TimeOfDay.Instance.daysUntilDeadline)}";
		OvertimeObject.SetActive(true);
	}

	[HarmonyPatch(typeof(DepositItemsDesk), "AddObjectToDeskClientRpc")]
	[HarmonyPostfix]
	private static void PostAddObjectToDeskClientRpc(DepositItemsDesk __instance)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		if (!NetworkManager.Singleton.IsHost)
		{
			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;
		foreach (GrabbableObject item in __instance.itemsOnCounter)
		{
			if (item.itemProperties.isScrap)
			{
				num += item.scrapValue;
			}
		}
		num = (int)((float)num * StartOfRound.Instance.companyBuyingRate);
		((TMP_Text)TrackerText).text = $"QUOTA: ${TimeOfDay.Instance.quotaFulfilled + num}/{TimeOfDay.Instance.profitQuota}";
		((TMP_Text)OvertimeText).text = $"OVERTIME: ${Math.Max(0, (TimeOfDay.Instance.quotaFulfilled + num - TimeOfDay.Instance.profitQuota) / 5 + 15 * TimeOfDay.Instance.daysUntilDeadline)}";
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(DepositItemsDesk), "SellItemsClientRpc")]
	public static void PostSellItemsClientRpc(ref DepositItemsDesk __instance)
	{
		if (!NetworkManager.Singleton.IsHost)
		{
			__instance.itemsOnCounter.Clear();
			((TMP_Text)TrackerText).text = $"QUOTA: ${TimeOfDay.Instance.quotaFulfilled}/{TimeOfDay.Instance.profitQuota}";
			((TMP_Text)OvertimeText).text = $"OVERTIME: ${Math.Max(0, (TimeOfDay.Instance.quotaFulfilled - TimeOfDay.Instance.profitQuota) / 5 + 15 * TimeOfDay.Instance.daysUntilDeadline)}";
		}
	}

	[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
	[HarmonyPrefix]
	private static void PreDisplayNewDeadline()
	{
		if (Object.op_Implicit((Object)(object)TrackerObject))
		{
			TrackerObject.SetActive(false);
		}
		if (Object.op_Implicit((Object)(object)OvertimeObject))
		{
			OvertimeObject.SetActive(false);
		}
	}

	[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
	[HarmonyPostfix]
	public static void PlayerLeave()
	{
		if (Object.op_Implicit((Object)(object)TrackerObject))
		{
			TrackerObject.SetActive(false);
		}
		if (Object.op_Implicit((Object)(object)OvertimeObject))
		{
			OvertimeObject.SetActive(false);
		}
	}
}
[BepInPlugin("slapitnow.uiselltracker", "UISellTracker", "22.0.3")]
public class UISellTracker : BaseUnityPlugin
{
	private const string modGUID = "slapitnow.uiselltracker";

	private const string modName = "UISellTracker";

	private const string modVersion = "22.0.3";

	private readonly Harmony harmony = new Harmony("slapitnow.uiselltracker");

	public static ManualLogSource mls;

	private void Awake()
	{
		mls = Logger.CreateLogSource("slapitnow.uiselltracker");
		harmony.PatchAll(typeof(UISellTracker));
		harmony.PatchAll(typeof(Patches));
		mls.LogInfo((object)"Version 22.0.3 loaded!");
	}
}