Decompiled source of BetterPaycheck v0.9.0

BetterPaycheck.dll

Decompiled 8 months ago
using System;
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.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BetterPaycheck")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterPaycheck")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7128c731-90f0-445c-bdb6-b647232ca42e")]
[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 BetterPaycheck;

[BepInPlugin("Swaggies.BetterPaycheck", "BetterPaycheck", "0.9.0")]
public class Plugin : BaseUnityPlugin
{
	private class SellingItem
	{
		public string name;

		public int? value = null;

		public SellingItem(string name)
		{
			this.name = name;
		}
	}

	private const string _guid = "Swaggies.BetterPaycheck";

	private const string _name = "BetterPaycheck";

	private const string _ver = "0.9.0";

	private readonly Harmony harmony = new Harmony("Swaggies.BetterPaycheck");

	private static Plugin Instance;

	private static ManualLogSource logginstein;

	private static float buyingRateToShow = 0f;

	private static float targetScrollbarValue = 1f;

	private static float scrollbarScrollingCooldown = 0f;

	private static readonly int sellingItemListLimit = 20;

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		logginstein = Logger.CreateLogSource("Swaggies.BetterPaycheck");
		harmony.PatchAll(typeof(Plugin));
		logginstein.LogInfo((object)"BetterPaycheck up and running.");
	}

	[HarmonyPatch(typeof(HUDManager), "DisplayCreditsEarning")]
	[HarmonyPrefix]
	private static bool PaycheckPatch(ref GrabbableObject[] objectsSold)
	{
		List<SellingItem> list = new List<SellingItem>();
		GrabbableObject[] array = objectsSold;
		foreach (GrabbableObject val in array)
		{
			SellingItem sellingItem = new SellingItem(val.itemProperties.itemName);
			if (val.itemProperties.isScrap)
			{
				sellingItem.value = val.scrapValue;
			}
			list.Add(sellingItem);
		}
		buyingRateToShow = StartOfRound.Instance.companyBuyingRate;
		DisplayNewPaycheck(list.OrderByDescending((SellingItem o) => o.value).ToArray());
		return false;
	}

	private static void DisplayNewPaycheck(SellingItem[] items)
	{
		string text = "";
		int num = 0;
		for (int i = 0; i < items.Length; i++)
		{
			if (i == sellingItemListLimit - 1 && items.Length > sellingItemListLimit)
			{
				int num2 = Mathf.Clamp(items.Length - sellingItemListLimit + 1, 0, 999);
				int num3 = 0;
				for (int j = i; j < items.Length; j++)
				{
					if (items[j].value.HasValue)
					{
						num3 += items[j].value.Value;
					}
				}
				num += num3;
				string text2 = MaximizeStringLength($"...and {num2} more", 22);
				string text3 = "<color=" + GetLineColorByScrapValue(num3) + ">" + ConvertANumberLargerThanMyIQ(num3) + "</color>";
				text = text + "<color=#ff6996ff><i>" + text2 + "</i> =</color> " + text3 + "</color>\n";
				break;
			}
			SellingItem sellingItem = items[i];
			string text4 = MaximizeStringLength(sellingItem.name, 22);
			string text5 = "<color=" + GetLineColorByScrapValue(sellingItem.value) + ">" + ConvertANumberLargerThanMyIQ(sellingItem.value) + "</color>";
			text = text + "<color=#ff6996ff>" + text4 + " =</color> " + text5 + "</color>\n";
			if (sellingItem.value.HasValue)
			{
				num += sellingItem.value.Value;
			}
		}
		if (items.Length < 8)
		{
			for (int k = items.Length; k < 8; k++)
			{
				text += "\n<color=#ffffff00>.</color>";
			}
		}
		((TMP_Text)HUDManager.Instance.moneyRewardsListText).text = text;
		((TMP_Text)HUDManager.Instance.moneyRewardsTotalText).text = "<color=#ffffff>TOTAL: " + ConvertANumberLargerThanMyIQ((int)((float)num * buyingRateToShow)) + "</color>";
		HUDManager.Instance.moneyRewardsAnimator.SetTrigger("showRewards");
		targetScrollbarValue = Mathf.Clamp(1f - ((float)items.Length - 8f) / ((float)sellingItemListLimit - 8f), 0f, 1f);
		HUDManager.Instance.rewardsScrollbar.value = 1f;
		scrollbarScrollingCooldown = 2f;
	}

	[HarmonyPatch(typeof(HUDManager), "Update")]
	[HarmonyPostfix]
	private static void UpdatePatch()
	{
		if (scrollbarScrollingCooldown > 0f)
		{
			scrollbarScrollingCooldown -= Time.deltaTime;
		}
		else if (HUDManager.Instance.rewardsScrollbar.value > targetScrollbarValue)
		{
			Scrollbar rewardsScrollbar = HUDManager.Instance.rewardsScrollbar;
			rewardsScrollbar.value -= Time.deltaTime / 2.75f;
		}
	}

	private static string GetLineColorByScrapValue(int? value)
	{
		if (!value.HasValue)
		{
			return "#696969";
		}
		if (value > 999999)
		{
			return "#ffffff";
		}
		if (value >= 100000)
		{
			return "#ccffff";
		}
		if (value >= 10000)
		{
			return "#6969ff";
		}
		if (value >= 1000)
		{
			return "#9669ff";
		}
		if (value >= 500)
		{
			return "#cc69ff";
		}
		if (value >= 300)
		{
			return "#ff69ff";
		}
		if (value >= 200)
		{
			return "#ff69cc";
		}
		if (value >= 150)
		{
			return "#ff6996";
		}
		if (value >= 120)
		{
			return "#ff6969";
		}
		if (value >= 100)
		{
			return "#ff9669";
		}
		if (value >= 80)
		{
			return "#ffaa69";
		}
		if (value >= 60)
		{
			return "#ffcc69";
		}
		if (value >= 40)
		{
			return "#ffff69";
		}
		if (value >= 25)
		{
			return "#96ff69";
		}
		if (value >= 10)
		{
			return "#69ff96";
		}
		if (value > 0)
		{
			return "#6996ff";
		}
		return "#969696";
	}

	private static string ConvertANumberLargerThanMyIQ(int? initialNumber)
	{
		if (!initialNumber.HasValue)
		{
			return "N/A";
		}
		initialNumber = Mathf.Clamp(initialNumber.Value, 0, 2100000000);
		if ((double?)initialNumber < 1000000.0)
		{
			return $"${initialNumber}";
		}
		int num = 1;
		string text = "this function is inspired by zeekers code <3";
		float num2;
		if ((double?)initialNumber >= 1000000000.0)
		{
			num2 = (float)initialNumber.Value / 1E+09f;
			text = "B";
		}
		else
		{
			num2 = (float)initialNumber.Value / 1000000f;
			text = "M";
		}
		if (num2 < 10f)
		{
			num = 100;
		}
		else if (num2 < 100f)
		{
			num = 10;
		}
		num2 = (float)Math.Floor(num2 * (float)num) / (float)num;
		return num switch
		{
			100 => $"${num2:0.00}{text}", 
			10 => $"${num2:0.0}{text}", 
			_ => $"${num2}{text}", 
		};
	}

	private static string MaximizeStringLength(string text, int targetCharacterCount)
	{
		if (text.Length >= targetCharacterCount)
		{
			return ShortenString(text, targetCharacterCount);
		}
		string text2 = text;
		while (text2.Length < targetCharacterCount)
		{
			text2 += " ";
		}
		return text2;
	}

	private static string ShortenString(string text, int maxCharacterCount)
	{
		if (text.Length <= maxCharacterCount)
		{
			return text;
		}
		return new string(text.Take(maxCharacterCount - 1).ToArray()) + "…";
	}
}