Decompiled source of BetterShipScreens v0.9.0

BetterShipScreens.dll

Decompiled 5 months ago
using System;
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 GameNetcodeStuff;
using HarmonyLib;
using TMPro;
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("BetterShipScreens")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterShipScreens")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5c6aa30e-0827-4446-b7a0-fc02a64efc31")]
[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 BetterShipScreens;

[BepInPlugin("Swaggies.BetterShipScreens", "BetterShipScreens", "0.9.0")]
public class Plugin : BaseUnityPlugin
{
	private const string _guid = "Swaggies.BetterShipScreens";

	private const string _name = "BetterShipScreens";

	private const string _ver = "0.9.0";

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

	private static Plugin Instance;

	private static ManualLogSource loggiswiggins;

	private static int scrapOnShip;

	private static float lastCheckedForShipScrap;

	private static int scrapCollectedThisRound;

	private static int totalScrapAvailableThisRound;

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

	[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
	[HarmonyPostfix]
	private static void OnConnect(ref PlayerControllerB __instance)
	{
		if (!((Object)(object)__instance != (Object)(object)GameNetworkManager.Instance.localPlayerController))
		{
			scrapOnShip = 0;
			lastCheckedForShipScrap = Time.realtimeSinceStartup;
			scrapCollectedThisRound = 0;
			totalScrapAvailableThisRound = 0;
		}
	}

	private static void GetTotalScrapOnShip()
	{
		lastCheckedForShipScrap = Time.realtimeSinceStartup;
		scrapOnShip = GameObject.Find("/Environment/HangarShip").GetComponentsInChildren<GrabbableObject>().ToList()
			.Sum((GrabbableObject item) => item.itemProperties.isScrap ? item.scrapValue : 0);
	}

	private static string GetQuotaDeadline()
	{
		int daysUntilDeadline = TimeOfDay.Instance.daysUntilDeadline;
		string text = $"{daysUntilDeadline}d";
		if (TimeOfDay.Instance.timeUntilDeadline <= 0f)
		{
			text = "NOW";
		}
		string text2 = "#00ffffff";
		if (daysUntilDeadline == 2)
		{
			text2 = "#ffff00ff";
		}
		if (daysUntilDeadline == 1)
		{
			text2 = "#ff6900ff";
		}
		if (daysUntilDeadline == 0)
		{
			text2 = "#ff0000ff";
		}
		return "<color=" + text2 + "><size=70%>" + text + "</size></color>";
	}

	private static int CalculateOvertime()
	{
		int num = TimeOfDay.Instance.daysUntilDeadline - 1;
		return Math.Max(0, (TimeOfDay.Instance.quotaFulfilled - TimeOfDay.Instance.profitQuota) / 5 + num * 15);
	}

	[HarmonyPatch(typeof(StartOfRound), "Update")]
	[HarmonyPostfix]
	private static void UpdateShipScreens(ref StartOfRound __instance)
	{
		if (!((Object)(object)TimeOfDay.Instance == (Object)null))
		{
			TextMeshProUGUI profitQuotaMonitorText = __instance.profitQuotaMonitorText;
			TextMeshProUGUI deadlineMonitorText = __instance.deadlineMonitorText;
			if (Time.realtimeSinceStartup - lastCheckedForShipScrap > 3f)
			{
				GetTotalScrapOnShip();
			}
			((TMP_Text)deadlineMonitorText).text = "QUOTA " + GetQuotaDeadline() + ":\n" + $"  ${TimeOfDay.Instance.profitQuota}\n" + "ON SHIP:\n" + $"  ${scrapOnShip}";
			if (__instance.inShipPhase)
			{
				int groupCredits = Object.FindObjectOfType<Terminal>().groupCredits;
				((TMP_Text)profitQuotaMonitorText).text = "TOTAL:\n" + $"  ${__instance.gameStats.scrapValueCollected + scrapOnShip}\n" + "CREDITS:\n" + $"  ${groupCredits}";
				scrapCollectedThisRound = 0;
				totalScrapAvailableThisRound = 0;
			}
			else if (!__instance.currentLevel.planetHasTime)
			{
				((TMP_Text)profitQuotaMonitorText).text = "PROFIT:\n" + $"  ${TimeOfDay.Instance.quotaFulfilled}\n" + "<size=90%>OVERTIME:</size>\n" + $"  ${CalculateOvertime()}";
			}
			else
			{
				totalScrapAvailableThisRound = (int)RoundManager.Instance.totalScrapValueInLevel;
				((TMP_Text)profitQuotaMonitorText).text = "<size=80%>COLLECTED:</size>\n" + $"  ${scrapCollectedThisRound}\n" + "<size=80%>AVAILABLE:</size>\n" + $"  ${totalScrapAvailableThisRound}";
			}
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "SetItemInElevator")]
	[HarmonyPrefix]
	private static void SetItemInElevator(ref bool droppedInShipRoom, ref GrabbableObject gObject)
	{
		if (gObject.itemProperties.isScrap && gObject.isInShipRoom != droppedInShipRoom)
		{
			if (droppedInShipRoom)
			{
				scrapCollectedThisRound += gObject.scrapValue;
			}
			else if (!gObject.scrapPersistedThroughRounds)
			{
				scrapCollectedThisRound -= gObject.scrapValue;
			}
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "SetItemInElevator")]
	[HarmonyPostfix]
	private static void SetItemInElevatorPostfix()
	{
		GetTotalScrapOnShip();
	}
}