Decompiled source of Corporate Restructure v1.0.6

BepInEx/plugins/CorporateRestructure.dll

Decompiled 10 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 System.Text;
using BepInEx;
using BepInEx.Configuration;
using CorporateRestructure.Component;
using CorporateRestructure.Patch;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CorporateRestructure")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CorporateRestructure")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("91760104-3647-46D9-988A-6D5B72EA80C6")]
[assembly: AssemblyFileVersion("1.0.6")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.6.0")]
namespace CorporateRestructure
{
	[BepInPlugin("jamil.corporate_restructure", "Corporate Restructure", "1.0.6")]
	public class CorporateRestructure : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("jamil.corporate_restructure");

		public static ConfigFile config;

		public static CorporateRestructure Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Corporate Restructure -> loading");
				Instance = this;
				config = ((BaseUnityPlugin)this).Config;
				CorporateConfig.Initialize();
				Instance.Patch();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Corporate Restructure -> complete");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Corporate Restructure -> Awoke a second time?");
			}
		}

		private void Patch()
		{
			Instance._harmony.PatchAll(typeof(MonitorPatch));
			Instance._harmony.PatchAll(typeof(WeatherPatch));
		}
	}
	public class CorporateConfig
	{
		public const string Guid = "jamil.corporate_restructure";

		public const string Name = "Corporate Restructure";

		public const string Version = "1.0.6";

		public static ConfigEntry<bool> HideWeather { get; private set; }

		public static void Initialize()
		{
			HideWeather = CorporateRestructure.config.Bind<bool>("General", "HideWeather", false, "Disables Weather from the navigation screen, and Terminal");
		}
	}
}
namespace CorporateRestructure.Patch
{
	internal class DevPatch
	{
	}
	internal class MonitorPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		private static void Initialize()
		{
			InitializeMonitorCluster();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")]
		private static void PlayerHasRevivedServerRpc()
		{
			LootMonitor.UpdateMonitor();
			CreditMonitor.UpdateMonitor();
			DayMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HUDManager), "ApplyPenalty")]
		private static void ApplyPenalty()
		{
			CreditMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(DepositItemsDesk), "SellAndDisplayItemProfits")]
		private static void SellLoot()
		{
			CreditMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay), "SyncNewProfitQuotaClientRpc")]
		private static void OvertimeBonus()
		{
			CreditMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesClientRpc")]
		private static void RefreshLootForClientOnStart()
		{
			LootMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		private static void OnPlayerConenct()
		{
			CreditMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay), "MoveTimeOfDay")]
		private static void RefreshClock()
		{
			TimeMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "GrabObjectClientRpc")]
		private static void RefreshLootOnPickupClient(bool grabValidated, NetworkObjectReference grabbedObject)
		{
			NetworkObject val = default(NetworkObject);
			if (((NetworkObjectReference)(ref grabbedObject)).TryGet(ref val, (NetworkManager)null))
			{
				GrabbableObject componentInChildren = ((Component)val).gameObject.GetComponentInChildren<GrabbableObject>();
				if (componentInChildren.isInShipRoom | componentInChildren.isInElevator)
				{
					LootMonitor.UpdateMonitor();
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "ThrowObjectClientRpc")]
		private static void RefreshLootOnThrowClient(bool droppedInElevator, bool droppedInShipRoom, Vector3 targetFloorPosition, NetworkObjectReference grabbedObject)
		{
			if (droppedInShipRoom || droppedInElevator)
			{
				LootMonitor.UpdateMonitor();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "ChangeLevelClientRpc")]
		private static void SwitchPlanets()
		{
			CreditMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Terminal), "SyncGroupCreditsClientRpc")]
		private static void RefreshMoney()
		{
			CreditMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "EndOfGameClientRpc")]
		private static void RefreshDay()
		{
			DayMonitor.UpdateMonitor();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "StartGame")]
		private static void StartGame()
		{
			DayMonitor.UpdateMonitor();
		}

		private static void InitializeMonitorCluster()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Expected O, but got Unknown
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube/Canvas (1)/MainContainer" ?? "");
			GameObject val2 = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube/Canvas (1)/MainContainer" + "/HeaderText");
			Object.Destroy((Object)(object)GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube/Canvas (1)/MainContainer" + "/BG"));
			GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube/Canvas (1)/MainContainer" + "/HeaderText (1)");
			Object.Destroy((Object)(object)GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube/Canvas (1)/MainContainer" + "/BG (1)"));
			GameObject val3 = new GameObject("lootMonitor");
			val3.transform.parent = val.transform;
			val3.transform.position = val.transform.position;
			val3.transform.localPosition = val.transform.localPosition;
			val3.transform.localScale = Vector3.one;
			val3.transform.rotation = Quaternion.Euler(Vector3.zero);
			GameObject obj = Object.Instantiate<GameObject>(val2, val3.transform);
			((Object)obj).name = "lootMonitorText";
			obj.transform.localPosition = new Vector3(-95f, 450f, 220f);
			obj.transform.rotation = Quaternion.Euler(new Vector3(-20f, 90f, 0f));
			obj.AddComponent<LootMonitor>();
			GameObject val4 = new GameObject("timeMonitor");
			val4.transform.parent = val.transform;
			val4.transform.position = val.transform.position;
			val4.transform.localPosition = val.transform.localPosition;
			val4.transform.localScale = Vector3.one;
			val4.transform.rotation = Quaternion.Euler(Vector3.zero);
			GameObject obj2 = Object.Instantiate<GameObject>(val2, val4.transform);
			((Object)obj2).name = "timeMonitorText";
			obj2.transform.localPosition = new Vector3(-95f, 450f, -250f);
			obj2.transform.rotation = Quaternion.Euler(new Vector3(-20f, 90f, 0f));
			obj2.AddComponent<TimeMonitor>();
			GameObject val5 = new GameObject("creditMonitor");
			val5.transform.parent = val.transform;
			val5.transform.position = val.transform.position;
			val5.transform.localPosition = val.transform.localPosition;
			val5.transform.localScale = Vector3.one;
			val5.transform.rotation = Quaternion.Euler(Vector3.zero);
			GameObject obj3 = Object.Instantiate<GameObject>(val2, val5.transform);
			((Object)obj3).name = "creditMonitorText";
			obj3.transform.localPosition = new Vector3(-198f, 450f, -750f);
			obj3.transform.rotation = Quaternion.Euler(new Vector3(-20f, 117f, 0f));
			obj3.AddComponent<CreditMonitor>();
			GameObject val6 = new GameObject("dayMonitor");
			val6.transform.parent = val.transform;
			val6.transform.position = val.transform.position;
			val6.transform.localPosition = val.transform.localPosition;
			val6.transform.localScale = Vector3.one;
			val6.transform.rotation = Quaternion.Euler(Vector3.zero);
			GameObject obj4 = Object.Instantiate<GameObject>(val2, val6.transform);
			((Object)obj4).name = "dayMonitorText";
			obj4.transform.localPosition = new Vector3(-413f, 450f, -1185f);
			obj4.transform.rotation = Quaternion.Euler(new Vector3(-21f, 117f, 0f));
			obj4.AddComponent<DayMonitor>();
		}
	}
	internal class WeatherPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "SetMapScreenInfoToCurrentLevel")]
		private static void ColorWeather(ref TextMeshProUGUI ___screenLevelDescription, ref SelectableLevel ___currentLevel)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("Orbiting: " + ___currentLevel.PlanetName + "\n");
			stringBuilder.Append("Weather: " + FormatWeather(___currentLevel.currentWeather) + "\n");
			stringBuilder.Append(___currentLevel.LevelDescription ?? "");
			((TMP_Text)___screenLevelDescription).text = stringBuilder.ToString();
		}

		private static string FormatWeather(LevelWeatherType currentWeather)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected I4, but got Unknown
			string text = "FFFFFF";
			if (CorporateConfig.HideWeather.Value)
			{
				return "<color=#" + text + ">UNKNOWN</color>";
			}
			switch (currentWeather - -1)
			{
			case 0:
			case 1:
				text = "69FF6B";
				break;
			case 2:
			case 4:
				text = "FFDC00";
				break;
			case 3:
			case 5:
				text = "FF9300";
				break;
			case 6:
				text = "FF0000";
				break;
			}
			return "<color=#" + text + ">" + ((object)(LevelWeatherType)(ref currentWeather)).ToString() + "</color>";
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Terminal), "TextPostProcess")]
		private static string HideWeatherConditions(string __result)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (CorporateConfig.HideWeather.Value)
			{
				foreach (LevelWeatherType value in Enum.GetValues(typeof(LevelWeatherType)))
				{
					LevelWeatherType val = value;
					__result = __result.Replace("(" + ((object)(LevelWeatherType)(ref val)).ToString() + ")", "");
				}
			}
			return __result;
		}
	}
}
namespace CorporateRestructure.Component
{
	public class DayMonitor : MonoBehaviour
	{
		private static StartOfRound _startOfRound;

		private static TextMeshProUGUI _textMesh;

		private static EndOfGameStats _stats;

		public void Start()
		{
			_startOfRound = StartOfRound.Instance;
			_textMesh = ((Component)this).GetComponent<TextMeshProUGUI>();
			_stats = _startOfRound.gameStats;
			if (!((NetworkBehaviour)_startOfRound).IsHost)
			{
				((TMP_Text)_textMesh).text = "DAY:\n?";
			}
			else
			{
				UpdateMonitor();
			}
		}

		public static void UpdateMonitor()
		{
			((TMP_Text)_textMesh).text = $"DAY:\n{_stats.daysSpent}";
		}
	}
	public class LootMonitor : MonoBehaviour
	{
		private static LootMonitor _lootMonitor;

		private static TextMeshProUGUI _textMesh;

		private static GameObject _ship;

		public void Start()
		{
			_lootMonitor = this;
			_textMesh = ((Component)this).GetComponent<TextMeshProUGUI>();
			((TMP_Text)_textMesh).text = "LOOT:\n$NaN";
			_ship = GameObject.Find("/Environment/HangarShip");
			UpdateMonitor();
		}

		public static void UpdateMonitor()
		{
			float num = Calculate();
			((TMP_Text)_textMesh).text = $"LOOT:\n${num}";
		}

		private static float Calculate()
		{
			return (from x in _ship.GetComponentsInChildren<GrabbableObject>()
				where x.itemProperties.isScrap && !x.isPocketed && !x.isHeld
				select x).Sum((GrabbableObject x) => x.scrapValue);
		}
	}
	public class CreditMonitor : MonoBehaviour
	{
		private static Terminal _terminal;

		private static TextMeshProUGUI _textMesh;

		public void Start()
		{
			_terminal = Object.FindObjectOfType<Terminal>();
			_textMesh = ((Component)this).GetComponent<TextMeshProUGUI>();
			UpdateMonitor();
		}

		public static void UpdateMonitor()
		{
			((TMP_Text)_textMesh).text = $"CREDITS:\n${_terminal.groupCredits}";
		}
	}
	public class TimeMonitor : MonoBehaviour
	{
		private static TextMeshProUGUI _textMesh;

		private static TextMeshProUGUI _timeMesh;

		public void Start()
		{
			_textMesh = ((Component)this).GetComponent<TextMeshProUGUI>();
			_timeMesh = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/ProfitQuota/Container/Box/TimeNumber").GetComponent<TextMeshProUGUI>();
			((TMP_Text)_textMesh).text = "TIME:\n7:30\nAM";
		}

		public static void UpdateMonitor()
		{
			((TMP_Text)_textMesh).text = "TIME:\n" + ((TMP_Text)_timeMesh).text;
		}
	}
}