using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FatsunMonitors")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Fatsun Software Lethal Company Monitors Mod")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("FatsunMonitors")]
[assembly: AssemblyTitle("FatsunMonitors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
[module: UnverifiableCode]
namespace FatSunLCMods;
public class CompanyMonitor : MonoBehaviour
{
public TextMeshPro textContainer;
public Terminal terminal;
public void Start()
{
textContainer = ((Component)this).GetComponentInChildren<TextMeshPro>();
terminal = Object.FindObjectOfType<Terminal>();
}
public void Update()
{
if (!((Object)(object)textContainer == (Object)null) && !((Object)(object)terminal == (Object)null) && !((Object)(object)TimeOfDay.Instance == (Object)null) && !((Object)(object)StartOfRound.Instance == (Object)null))
{
UpdateMonitorText();
}
}
private void UpdateMonitorText()
{
GrabbableObject[] itemsOnCounter = ScrapUtil.GetItemsOnCounter();
if (itemsOnCounter != null)
{
float num = 0f;
float num2 = 0f;
GrabbableObject[] array = itemsOnCounter;
foreach (GrabbableObject val in array)
{
num2 += (float)val.scrapValue;
}
num = num2 * StartOfRound.Instance.companyBuyingRate;
float num3 = TimeOfDay.Instance?.profitQuota ?? 0;
float num4 = TimeOfDay.Instance?.quotaFulfilled ?? 0;
float num5 = num3 - num4 - num;
float num6 = terminal.groupCredits;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("QUOTA: $" + num4.ToString("N0") + "/$" + num3.ToString("N0"));
stringBuilder.AppendLine("ON DESK: $" + num.ToString("N0"));
stringBuilder.AppendLine("REMAINING: $" + num5.ToString("N0"));
stringBuilder.AppendLine("CREDITS: $" + num6.ToString("N0"));
((TMP_Text)textContainer).text = stringBuilder.ToString();
}
}
}
internal class ConfigUtil
{
private static ConfigUtil instance;
public bool ShipMonitorEnabled { get; set; }
public bool CompanyMonitorEnabled { get; set; }
public bool ShowPoster { get; set; }
public static ConfigUtil getInstance()
{
if (instance == null)
{
instance = new ConfigUtil();
}
return instance;
}
public static string GetAssetPath()
{
PluginInfo obj = Chainloader.PluginInfos["FatsunMonitors"];
string path = ((obj != null) ? obj.Location : null);
string directoryName = Path.GetDirectoryName(path);
return Path.Combine(directoryName, "fatsunlcmods");
}
}
[BepInPlugin("FatsunMonitors", "FatsunMonitors", "0.0.1")]
public class FatsunMonitorPlugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private void Awake()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
InitializeConfig();
Harmony val = new Harmony("FatsunMonitors");
val.PatchAll(typeof(PatchDepositItemsDesk));
val.PatchAll(typeof(PatchStartOfRound));
Log.LogInfo((object)"Plugin FatsunMonitors is loaded!");
}
private void InitializeConfig()
{
ConfigUtil instance = ConfigUtil.getInstance();
instance.ShipMonitorEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShipMonitorEnabled", true, "Enable monitor on ship").Value;
instance.CompanyMonitorEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CompanyMonitorEnabled", true, "Enable monitor on company moon").Value;
instance.ShowPoster = ((BaseUnityPlugin)this).Config.Bind<bool>("Extra", "ShowPoster", false, "Show a fun FatSun Software poster to brighten your ship!").Value;
}
}
[HarmonyPatch(typeof(DepositItemsDesk))]
public class PatchDepositItemsDesk
{
[HarmonyPostfix]
[HarmonyPatch("AddObjectToDeskClientRpc")]
private static void PatchAddObjectToDeskClientRpc(DepositItemsDesk __instance)
{
FatsunMonitorPlugin.Log.LogInfo((object)"Called PatchAddObjectToDeskClientRpc");
FatsunMonitorPlugin.Log.LogInfo((object)$"{__instance?.itemsOnCounter.Count}");
if (!((Object)(object)__instance == (Object)null) && __instance.itemsOnCounter.Count > 0)
{
int totalValue = 0;
__instance.itemsOnCounter.ForEach(delegate(GrabbableObject item)
{
totalValue += item.scrapValue;
});
FatsunMonitorPlugin.Log.LogInfo((object)((float)totalValue * StartOfRound.Instance.companyBuyingRate));
FatsunMonitorPlugin.Log.LogInfo((object)$"Diff: {TimeOfDay.Instance.profitQuota - TimeOfDay.Instance.quotaFulfilled - totalValue}");
CompanyMonitor companyMonitor = Object.FindObjectOfType<CompanyMonitor>();
if (!((Object)(object)companyMonitor == (Object)null))
{
}
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class PatchStartOfRound
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void PatchStart()
{
FatsunMonitorPlugin.Log.LogInfo((object)"PatchStartOfRound.PatchStart()");
if (!((Object)(object)Object.FindAnyObjectByType<ShipSupplementalMonitor>() != (Object)null))
{
AddCompanyMonitor();
AddSupplementalMonitor();
if (ConfigUtil.getInstance().ShowPoster)
{
AddFatsunPoster();
}
}
}
[HarmonyPostfix]
[HarmonyPatch("SceneManager_OnLoadComplete1")]
public static void PatchSceneManager_OnLoadComplete1()
{
FatsunMonitorPlugin.Log.LogInfo((object)"PatchStartOfRound.SceneManager_OnLoadComplete1()");
AddCompanyMonitor();
}
[HarmonyPostfix]
[HarmonyPatch("ArriveAtLevel")]
private static void PatchArriveAtLevel()
{
FatsunMonitorPlugin.Log.LogInfo((object)"PatchStartOfRound.PatchArriveAtLevel()");
ScrapUtil.GeneratePreviousScrapList();
}
private static void AddSupplementalMonitor()
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
if (!ConfigUtil.getInstance().ShipMonitorEnabled)
{
return;
}
AssetBundle val = AssetBundle.LoadFromFile(ConfigUtil.GetAssetPath());
if ((Object)(object)val == (Object)null)
{
FatsunMonitorPlugin.Log.LogInfo((object)"Couldn't load AssetBundle");
return;
}
GameObject val2 = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall");
if ((Object)(object)val2 == (Object)null)
{
FatsunMonitorPlugin.Log.LogInfo((object)"Couldn't find MonitorWall object to attach company monitor to");
return;
}
GameObject val3 = val.LoadAsset<GameObject>("CompanyMonitor");
GameObject val4 = Object.Instantiate<GameObject>(val3, val2.transform);
val4.transform.localPosition = new Vector3(-0.1903f, -1.5865f, 0.8942f);
val4.transform.eulerAngles = new Vector3(0f, 357.5999f, 0f);
val4.transform.localScale = new Vector3(0.01f, 0.5f, 0.6f);
val4.AddComponent<ShipSupplementalMonitor>();
val.Unload(false);
}
private static void AddCompanyMonitor()
{
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
if (!ConfigUtil.getInstance().CompanyMonitorEnabled)
{
return;
}
CompanyMonitor companyMonitor = Object.FindObjectOfType<CompanyMonitor>();
FatsunMonitorPlugin.Log.LogInfo((object)$"AddCompanyMonitor: {StartOfRound.Instance?.currentLevel.PlanetName} -- Monitor: {(Object)(object)companyMonitor != (Object)null}");
if (StartOfRound.Instance?.currentLevel.PlanetName == "71 Gordion" && (Object)(object)companyMonitor == (Object)null)
{
AssetBundle val = AssetBundle.LoadFromFile(ConfigUtil.GetAssetPath());
if (!((Object)(object)val == (Object)null))
{
GameObject val2 = GameObject.Find("Environment");
GameObject val3 = val.LoadAsset<GameObject>("CompanyMonitor");
GameObject val4 = Object.Instantiate<GameObject>(val3, val2.transform);
val4.transform.localPosition = new Vector3(-11.0091f, -7.731f, -11.0183f);
val4.transform.eulerAngles = new Vector3(0f, 180f, 2.5f);
val4.transform.localScale = new Vector3(0.5f, 0.8f, 0.8f);
val4.AddComponent<CompanyMonitor>();
val.Unload(false);
}
}
else if (StartOfRound.Instance?.currentLevel.PlanetName != "71 Gordion" && (Object)(object)companyMonitor != (Object)null)
{
Object.Destroy((Object)(object)((Component)companyMonitor).gameObject);
}
}
private static void AddFatsunPoster()
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
if (!ConfigUtil.getInstance().ShowPoster)
{
return;
}
GameObject val = GameObject.Find("FatsunPoster");
if (!((Object)(object)val != (Object)null))
{
AssetBundle val2 = AssetBundle.LoadFromFile(ConfigUtil.GetAssetPath());
if (!((Object)(object)val2 == (Object)null))
{
GameObject val3 = GameObject.Find("Environment/HangarShip");
GameObject val4 = val2.LoadAsset<GameObject>("FatsunPoster");
GameObject val5 = Object.Instantiate<GameObject>(val4, val3.transform);
val5.transform.localPosition = new Vector3(6.2941f, 2.8326f, -3.3282f);
val5.transform.eulerAngles = new Vector3(90f, 270f, 0f);
val5.transform.localScale = new Vector3(0.01f, 0.6655f, 0.8782f);
((Object)val5).name = "FatsunPoster";
val2.Unload(false);
}
}
}
}
public class PlanetSummary
{
public string planetName;
public string planetNumber;
public string planetShortName;
public string riskLevelString;
public int riskLevelIndex;
public LevelWeatherType currentWeather;
public float costToFlyTo;
}
internal class PlanetUtil
{
private class PlanetRiskComparer : IComparer<PlanetSummary>
{
int IComparer<PlanetSummary>.Compare(PlanetSummary x, PlanetSummary y)
{
return x.riskLevelIndex - y.riskLevelIndex;
}
}
private static readonly Dictionary<string, int> RiskIndex = new Dictionary<string, int>
{
{ "Safe", 0 },
{ "D", 1 },
{ "C", 2 },
{ "B", 3 },
{ "A", 4 },
{ "S", 5 },
{ "S+", 6 },
{ "S++", 7 }
};
private static Dictionary<string, TerminalNode> planetNodes = new Dictionary<string, TerminalNode>();
public static PlanetSummary[] GetPlanetInfo()
{
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
if (planetNodes.Count <= 0)
{
TerminalNode[] array = Resources.FindObjectsOfTypeAll<TerminalNode>();
TerminalNode[] array2 = array;
foreach (TerminalNode val in array2)
{
if (((Object)val).name.EndsWith("route"))
{
planetNodes.Add(((Object)val).name, val);
}
}
}
SelectableLevel[] array3 = StartOfRound.Instance?.levels;
if (array3 == null)
{
return null;
}
List<PlanetSummary> list = new List<PlanetSummary>();
SelectableLevel[] array4 = array3;
foreach (SelectableLevel val2 in array4)
{
PlanetSummary planetSummary = new PlanetSummary();
planetSummary.planetName = val2.PlanetName;
planetSummary.riskLevelString = val2.riskLevel;
planetSummary.riskLevelIndex = RiskIndex[val2.riskLevel];
planetSummary.currentWeather = val2.currentWeather;
planetSummary.planetNumber = val2.PlanetName.Split(' ')[0];
planetSummary.planetShortName = val2.PlanetName.Split(' ')[1];
string key = planetSummary.planetNumber + "route";
if (planetNodes.ContainsKey(key))
{
planetSummary.costToFlyTo = planetNodes[key].itemCost;
}
list.Add(planetSummary);
}
PlanetSummary[] array5 = list.ToArray();
Array.Sort(array5, new PlanetRiskComparer());
return array5;
}
}
public class ScrapUtil
{
public static List<int> previousScrapIds = new List<int>();
public static GrabbableObject[] GetItemsOnCounter()
{
if ((Object)(object)TimeOfDay.Instance == (Object)null)
{
return null;
}
Terminal val = Object.FindObjectOfType<Terminal>();
if ((Object)(object)val == (Object)null)
{
return null;
}
GameObject val2 = GameObject.Find("DepositCounter/DoorAndHookAnim/");
if ((Object)(object)val2 == (Object)null)
{
return null;
}
return val2.GetComponentsInChildren<GrabbableObject>();
}
public static GrabbableObject[] GetItemsOnShip()
{
GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
List<GrabbableObject> list = new List<GrabbableObject>();
GrabbableObject[] array2 = array;
foreach (GrabbableObject val in array2)
{
if (val.itemProperties.isScrap)
{
Transform parent = ((Component)val).transform.parent;
if ((((parent != null) ? ((Object)parent).name : null) ?? "").StartsWith("HangarShip"))
{
list.Add(val);
}
}
}
return list.ToArray();
}
public static void GeneratePreviousScrapList()
{
GrabbableObject[] itemsOnShip = GetItemsOnShip();
previousScrapIds = new List<int>();
GrabbableObject[] array = itemsOnShip;
foreach (GrabbableObject val in array)
{
previousScrapIds.Add(((Object)val).GetInstanceID());
}
}
}
public class ShipSupplementalMonitor : MonoBehaviour
{
public TextMeshPro textContainer;
public Transform elevatorTransform;
public Terminal terminal;
public void Start()
{
textContainer = ((Component)this).GetComponentInChildren<TextMeshPro>();
elevatorTransform = GameObject.Find("Environment/HangarShip").transform;
terminal = Object.FindObjectOfType<Terminal>();
}
public void Update()
{
UpdateTerminalText();
}
private void UpdateTerminalText()
{
if ((Object)(object)textContainer == (Object)null || (Object)(object)TimeOfDay.Instance == (Object)null)
{
return;
}
List<GrabbableObject> list = new List<GrabbableObject>();
float num = TimeOfDay.Instance?.profitQuota ?? 0;
float num2 = TimeOfDay.Instance?.quotaFulfilled ?? 0;
float num3 = num - num2;
float num4 = terminal.groupCredits;
float num5 = 0f;
float num6 = 0f;
int num7 = 0;
float num8 = 0f;
int num9 = 0;
int num10 = 0;
float num11 = 0f;
bool flag = StartOfRound.Instance?.inShipPhase ?? true;
string text = StartOfRound.Instance?.currentLevel.PlanetName ?? "";
if ((Object)(object)RoundManager.Instance != (Object)null)
{
num5 = RoundManager.Instance.totalScrapValueInLevel;
num6 = 0f;
GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
GrabbableObject[] array2 = array;
foreach (GrabbableObject val in array2)
{
if (!val.itemProperties.isScrap)
{
continue;
}
Transform parent = ((Component)val).transform.parent;
if (!(((parent != null) ? ((Object)parent).name : null) ?? "").StartsWith("HangarShip"))
{
num9++;
continue;
}
num10++;
num8 += (float)val.scrapValue;
if (!ScrapUtil.previousScrapIds.Contains(((Object)val).GetInstanceID()))
{
num7++;
num6 += (float)val.scrapValue;
}
}
num11 = num5 - num6;
}
float num12 = num - num2 - num8;
num12 = Mathf.Max(num12, 0f);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("<align=\"right\"><size=50%>" + CalculateTimeOfDay() + "</size></align>");
stringBuilder.AppendLine("QUOTA: $" + num2.ToString("N0") + " / $" + num.ToString("N0"));
stringBuilder.AppendLine("REMAINING: $" + num3.ToString("N0"));
stringBuilder.AppendLine("CREDITS: $" + num4.ToString("N0"));
stringBuilder.AppendLine($"SHIP SCRAP VAL: ${num8} ({num10})");
stringBuilder.AppendLine($"SCRAP TO QUOTA: ${num12}");
if (!flag)
{
if (text != "71 Gordion")
{
stringBuilder.AppendLine($"SCRAP (COLL): ${num6} ({num7}) / ${num5}");
stringBuilder.AppendLine($"SCRAP (REM): ${num11} ({num9})");
}
}
else
{
stringBuilder.AppendLine();
stringBuilder.AppendLine("<size=50%>MOONS:");
stringBuilder.AppendLine("======");
stringBuilder.AppendLine(GetMoonsListing());
stringBuilder.AppendLine("</size>");
}
for (int j = 0; j < terminal.itemSalesPercentages.Length; j++)
{
if (terminal.itemSalesPercentages[j] < 100)
{
int num13 = terminal.itemSalesPercentages[j];
int num14 = 100 - num13;
Item val2 = terminal.buyableItemsList[j];
stringBuilder.AppendLine(string.Format("<size=50%><color=\"yellow\">{0} ({1}% OFF)! -- ${2}</color></size>", val2.itemName, num14, ((double)(val2.creditsWorth * num13) / 100.0).ToString("N0")));
}
}
((TMP_Text)textContainer).text = stringBuilder.ToString();
}
private string CalculateTimeOfDay()
{
float normalizedTimeOfDay = TimeOfDay.Instance.normalizedTimeOfDay;
float num = TimeOfDay.Instance.numberOfHours;
string text = "";
int num2 = (int)((double)normalizedTimeOfDay * (60.0 * (double)num)) + 360;
int num3 = (int)Mathf.Floor((float)(num2 / 60));
if (num3 >= 24)
{
return "12:00\nAM";
}
text = ((num3 >= 12) ? " PM" : " AM");
if (num3 > 12)
{
num3 %= 12;
}
int num4 = num2 % 60;
return $"{num3:00}:{num4:00}" + text;
}
private string GetMoonsListing()
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Invalid comparison between Unknown and I4
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
float num = terminal.groupCredits;
PlanetSummary[] planetInfo = PlanetUtil.GetPlanetInfo();
StringBuilder stringBuilder = new StringBuilder();
PlanetSummary[] array = planetInfo;
foreach (PlanetSummary planetSummary in array)
{
if (!(planetSummary.planetName == "71 Gordion"))
{
StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.Append(planetSummary.planetShortName ?? "");
if ((int)planetSummary.currentWeather != -1)
{
stringBuilder2.Append($" ({planetSummary.currentWeather})");
}
if (planetSummary.costToFlyTo > 0f)
{
stringBuilder2.Append($" | ${planetSummary.costToFlyTo}");
}
if (planetSummary.costToFlyTo > num)
{
stringBuilder2 = new StringBuilder("<s>" + stringBuilder2.ToString() + "</s>");
}
stringBuilder.AppendLine(stringBuilder2.ToString());
}
}
return stringBuilder.ToString();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "FatsunMonitors";
public const string PLUGIN_NAME = "FatsunMonitors";
public const string PLUGIN_VERSION = "0.0.1";
}