Decompiled source of Quads Mission Haul v0.1.1

plugins/MissionHaul/MissionHaul.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json.Linq;
using Pigeon.Movement;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was partially or fully created with the assistance of Generative AI.")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic")]
[assembly: AssemblyCompany("MissionHaul")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2d8a83feadd983ac149b3d1ce53f5cc1a93d1d4f")]
[assembly: AssemblyProduct("MissionHaul")]
[assembly: AssemblyTitle("MissionHaul")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MissionHaul
{
	[HarmonyPatch(typeof(MissionRewardsWindow), "SetRewards")]
	internal static class RecordMission
	{
		private static void Prefix(List<RewardInfo> rewards, MissionState completed)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Session.Record(rewards, completed);
		}

		private static void Postfix(MissionRewardsWindow __instance, List<RewardInfo> rewards)
		{
			SessionPanel.Remove(__instance);
			if (Plugin.ShowSession.Value)
			{
				Tally tally = (Session.Testing ? Session.Sample(rewards) : Session.Current);
				int resources = rewards.Count((RewardInfo r) => r.reward is PlayerResource);
				int upgrades = rewards.Count((RewardInfo r) => r.reward is UpgradeInstance);
				if (tally.Missions >= 2)
				{
					((MonoBehaviour)__instance).StartCoroutine(SessionPanel.Show(__instance, tally, resources, upgrades));
				}
			}
		}
	}
	[HarmonyPatch(typeof(ResourceUI), "SetCount")]
	internal static class ShowTotal
	{
		private static void Postfix(ResourceUI __instance, int count, char prefix)
		{
			if (Plugin.ShowTotals.Value && !SessionPanel.Building && prefix == '+' && __instance.resource != null && PlayerData.Instance != null && !((Object)(object)((Component)__instance).GetComponentInParent<MissionRewardsWindow>() == (Object)null))
			{
				int resource = PlayerData.Instance.GetResource(__instance.resource);
				TextMeshProUGUI count2 = __instance.GetCount();
				((TMP_Text)count2).textWrappingMode = (TextWrappingModes)0;
				((TMP_Text)count2).overflowMode = (TextOverflowModes)0;
				((TMP_Text)count2).verticalAlignment = (VerticalAlignmentOptions)256;
				((TMP_Text)count2).SetText("+" + count + "\n<size=70%><color=#B8C2CC>→ " + resource + "</color></size>");
			}
		}
	}
	internal static class SessionPanel
	{
		public static bool Building;

		private const string PanelName = "MissionHaulSession";

		public static IEnumerator Show(MissionRewardsWindow window, Tally session, int resources, int upgrades)
		{
			float waited = 0f;
			while (waited < 15f && (Object)(object)window != (Object)null && ((Behaviour)window).isActiveAndEnabled && !AllShown(window, resources, upgrades))
			{
				waited += Time.unscaledDeltaTime;
				yield return null;
			}
			yield return null;
			if ((Object)(object)window == (Object)null || !((Behaviour)window).isActiveAndEnabled)
			{
				yield break;
			}
			try
			{
				Build(window, session);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Mission Haul: the session panel didn't build: " + ex));
			}
			finally
			{
				Building = false;
			}
		}

		public static void Remove(MissionRewardsWindow window)
		{
			Transform[] componentsInChildren = ((Component)window).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name == "MissionHaulSession")
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}

		private static bool AllShown(MissionRewardsWindow window, int resources, int upgrades)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if (((Transform)window.resourceParent).childCount < resources || ((Transform)window.upgradeParent).childCount < upgrades)
			{
				return false;
			}
			foreach (Transform item in (Transform)window.resourceParent)
			{
				if (!((Component)item).gameObject.activeSelf)
				{
					return false;
				}
			}
			foreach (Transform item2 in (Transform)window.upgradeParent)
			{
				if (!((Component)item2).gameObject.activeSelf)
				{
					return false;
				}
			}
			return true;
		}

		private static void Build(MissionRewardsWindow window, Tally session)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			RectTransform resourceParent = window.resourceParent;
			RectTransform upgradeParent = window.upgradeParent;
			RectTransform val = (RectTransform)((Transform)resourceParent).parent;
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			float num = float.MaxValue;
			float num2 = 0f;
			float num3 = 0f;
			RectTransform[] array2 = (RectTransform[])(object)new RectTransform[2] { resourceParent, upgradeParent };
			foreach (RectTransform val2 in array2)
			{
				foreach (RectTransform item in (Transform)val2)
				{
					RectTransform val3 = item;
					if (((Component)val3).gameObject.activeInHierarchy)
					{
						val3.GetWorldCorners(array);
						Vector3 val4 = ((Transform)val).InverseTransformPoint(array[0]);
						Vector3 val5 = ((Transform)val).InverseTransformPoint(array[1]);
						num = Mathf.Min(num, val4.y);
						if ((Object)(object)val2 == (Object)(object)resourceParent)
						{
							num2 = Mathf.Max(num2, val5.y - val4.y);
						}
					}
				}
			}
			if (((Transform)resourceParent).childCount > 1)
			{
				num3 = Mathf.Abs(((Transform)val).InverseTransformPoint(((Transform)resourceParent).GetChild(1).position).x - ((Transform)val).InverseTransformPoint(((Transform)resourceParent).GetChild(0).position).x);
			}
			Vector3 val6 = ((Transform)val).InverseTransformPoint(((Transform)resourceParent).position);
			if (num == float.MaxValue)
			{
				resourceParent.GetWorldCorners(array);
				num = ((Transform)val).InverseTransformPoint(array[0]).y;
			}
			if (num2 <= 0f)
			{
				Rect rect = resourceParent.rect;
				num2 = ((Rect)(ref rect)).height;
			}
			if (num3 <= 0f)
			{
				num3 = num2 * 1.2f;
			}
			if (Plugin.LogLayout.Value)
			{
				Plugin.Log.LogInfo((object)$"Mission Haul layout (column space): rewards at {val6}, upgrades {((Transform)upgradeParent).childCount}, bottom {num}, item height {num2}, step {num3}");
			}
			RectTransform component = new GameObject("MissionHaulSession", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)val, false);
			((Transform)component).localRotation = Quaternion.identity;
			((Transform)component).localScale = Vector3.one;
			((Transform)component).localPosition = new Vector3(val6.x, num - num2 * 1.5f, 0f);
			float num4 = num2;
			float num5 = num3 * 1.15f;
			TMP_Text style = (TMP_Text)(((object)((IEnumerable<TMP_Text>)((Component)window).GetComponentsInChildren<TMP_Text>(true)).FirstOrDefault((Func<TMP_Text, bool>)((TMP_Text t) => t.text.Trim().ToUpperInvariant() == "REWARDS"))) ?? ((object)window.missionText));
			float y = 0f;
			string text = ((session.Failed + session.Aborted == 0) ? "" : $" <size=70%><color=#B8C2CC>({session.Completed} DONE, {session.Failed + session.Aborted} NOT)</color></size>");
			Text(component, style, $"ALL {session.Missions} MISSIONS THIS SESSION" + text, 1f, ref y);
			y -= num4 * 0.35f;
			List<KeyValuePair<PlayerResource, int>> list = (from r in session.Resources
				where r.Value > 0
				orderby Array.IndexOf(Global.Instance.PlayerResources, r.Key)
				select r).ToList();
			if (list.Count > 0)
			{
				Building = true;
				Vector2 val8 = default(Vector2);
				for (int num6 = 0; num6 < list.Count; num6++)
				{
					ResourceUI obj = Object.Instantiate<ResourceUI>(window.resourceInfo, (Transform)(object)component);
					((Component)obj).gameObject.SetActive(true);
					obj.Setup(list[num6].Key, list[num6].Value, false, '+');
					RectTransform val7 = (RectTransform)((Component)obj).transform;
					((Vector2)(ref val8))..ctor(0.5f, 1f);
					val7.anchorMax = val8;
					val7.anchorMin = val8;
					((Transform)val7).localPosition = new Vector3(((float)num6 - (float)(list.Count - 1) * 0.5f) * num5, y - num4 * 0.5f, 0f);
				}
				Building = false;
				y -= num4 * 2.6f;
			}
			List<string> list2 = new List<string>();
			if (session.Upgrades.Count > 0 || session.Skins > 0)
			{
				list2.Add("UPGRADES  " + string.Join("  ·  ", session.Upgrades.Reverse().Select(delegate(KeyValuePair<Rarity, int> u)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0013: Unknown result type (might be due to invalid IL or missing references)
					ref RarityData rarity = ref Global.GetRarity(u.Key);
					return $"<color=#{ColorUtility.ToHtmlStringRGB(rarity.color)}>{u.Value} {((RarityData)(ref rarity)).Name.ToUpperInvariant()}</color>";
				}).Concat((session.Skins <= 0) ? new string[0] : new string[1] { string.Format("{0} {1}", session.Skins, (session.Skins == 1) ? "SKIN" : "SKINS") })));
			}
			if (session.CharacterXP + session.GearXP > 0)
			{
				list2.Add($"XP  +{session.CharacterXP:N0} <size=70%><color=#B8C2CC>CHARACTER</color></size>  ·  +{session.GearXP:N0} <size=70%><color=#B8C2CC>GEAR</color></size>");
			}
			foreach (string item2 in list2)
			{
				Text(component, style, item2, 0.7f, ref y);
			}
		}

		private static void Text(RectTransform panel, TMP_Text style, string text, float scale, ref float y)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Line", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)panel, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val2).font = style.font;
			((TMP_Text)val2).fontSharedMaterial = style.fontSharedMaterial;
			((TMP_Text)val2).fontSize = style.fontSize * scale;
			((Graphic)val2).color = Color.white;
			((TMP_Text)val2).alignment = (TextAlignmentOptions)258;
			((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
			((Graphic)val2).raycastTarget = false;
			((TMP_Text)val2).SetText(text);
			RectTransform val3 = (RectTransform)val.transform;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0.5f, 1f);
			val3.anchorMax = val4;
			val3.anchorMin = val4;
			val3.sizeDelta = new Vector2(1200f, ((TMP_Text)val2).fontSize * 1.4f);
			((Transform)val3).localPosition = new Vector3(0f, y, 0f);
			y -= ((TMP_Text)val2).fontSize * 1.5f;
		}
	}
	[BepInPlugin("quadslab.mycopunk.missionhaul", "Quad's Mission Haul", "0.1.1")]
	[BepInProcess("Mycopunk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "quadslab.mycopunk.missionhaul";

		public const string Title = "Quad's Mission Haul";

		public const string Version = "0.1.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ShowTotals;

		internal static ConfigEntry<bool> ShowSession;

		internal static ConfigEntry<bool> TestKey;

		internal static ConfigEntry<bool> LogLayout;

		private Harmony harmony;

		private float nextFileCheck;

		private void Awake()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ShowTotals = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowTotals", true, "On the mission reward screen, show where each resource stands now beside what you earned: \"+40 -> 1226\".");
			ShowSession = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowSession", true, "On the mission reward screen, show what you've earned this session (since the game started) below this mission's rewards.");
			LogLayout = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogLayout", false, "Write where the reward screen's parts are to the BepInEx log (for fixing the layout).");
			TestKey = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "TestKey", false, "F8 in the hub opens the mission reward screen with sample rewards (never counted in your session). (A file BepInEx\\missionhaul-test.txt does the same, for automated tests.)");
			harmony = new Harmony("quadslab.mycopunk.missionhaul");
			harmony.PatchAll(typeof(Plugin).Assembly);
			Session.Load();
			Log.LogInfo((object)"Quad's Mission Haul 0.1.1 loaded");
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		private void Update()
		{
			if (!TestKey.Value)
			{
				return;
			}
			bool flag = Keyboard.current != null && ((ButtonControl)Keyboard.current.f8Key).wasPressedThisFrame;
			if (Time.unscaledTime >= nextFileCheck)
			{
				nextFileCheck = Time.unscaledTime + 0.5f;
				string path = Path.Combine(Paths.BepInExRootPath, "missionhaul-test.txt");
				if (File.Exists(path))
				{
					try
					{
						File.Delete(path);
					}
					catch (Exception)
					{
					}
					flag = true;
				}
			}
			if (flag)
			{
				OpenTestScreen();
			}
		}

		private static void OpenTestScreen()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)PlayerLook.Instance == (Object)null || (Object)(object)GameManager.Instance == (Object)null || (Object)(object)Global.Instance == (Object)null)
			{
				Log.LogInfo((object)"Mission Haul: the test screen works once you're in the game");
				return;
			}
			if (!LevelData.IsHub)
			{
				Log.LogInfo((object)"Mission Haul: the test screen only opens in the hub");
				return;
			}
			try
			{
				List<RewardInfo> list = new List<RewardInfo>
				{
					new RewardInfo((object)Player.LocalPlayer.Character, 1234)
				};
				PlayerResource[] playerResources = Global.Instance.PlayerResources;
				for (int i = 0; i < playerResources.Length && i < 5; i++)
				{
					list.Add(new RewardInfo((object)playerResources[i], 12 * (i + 1) + 7));
				}
				if (Player.LocalPlayer.Gear.Length != 0)
				{
					IUpgradable prefab = ((IUpgradable)Player.LocalPlayer.Gear[0]).Prefab;
					if (prefab != null)
					{
						list.Add(new RewardInfo((object)prefab, 345));
					}
				}
				List<UpgradeInstance> upgrades = new List<UpgradeInstance>();
				PlayerData.QueryUpgrades((Action<UpgradeInstance>)delegate(UpgradeInstance u)
				{
					if (upgrades.Count < 3 && u != null)
					{
						upgrades.Add(u);
					}
				});
				foreach (UpgradeInstance item in upgrades)
				{
					list.Add(new RewardInfo((object)item));
				}
				list.Sort();
				Session.Testing = true;
				((MissionRewardsWindow)GameManager.Instance.OpenPopupWindowFromPrefab((Window)(object)Global.Instance.MissionRewardsWindow, false, true)).SetRewards(Global.Instance.Missions[0], Global.Instance.DefaultMissionContainer, list, (MissionState)0, 0);
				Log.LogInfo((object)$"Mission Haul: test reward screen open ({upgrades.Count} of your upgrades shown)");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Mission Haul: the test screen didn't open: " + ex));
			}
			finally
			{
				Session.Testing = false;
			}
		}
	}
	internal sealed class Tally
	{
		public int Missions;

		public int Completed;

		public int Failed;

		public int Aborted;

		public int CharacterXP;

		public int GearXP;

		public int Skins;

		public readonly Dictionary<PlayerResource, int> Resources = new Dictionary<PlayerResource, int>();

		public readonly SortedDictionary<Rarity, int> Upgrades = new SortedDictionary<Rarity, int>();

		public void Add(List<RewardInfo> rewards, MissionState state)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			Missions++;
			if ((int)state == 0)
			{
				Completed++;
			}
			else if ((int)state == 1)
			{
				Failed++;
			}
			else
			{
				Aborted++;
			}
			foreach (RewardInfo reward2 in rewards)
			{
				object reward = reward2.reward;
				if (!(reward is Character))
				{
					if (!(reward is IUpgradable))
					{
						PlayerResource val = (PlayerResource)((reward is PlayerResource) ? reward : null);
						if (val == null)
						{
							UpgradeInstance val2 = (UpgradeInstance)((reward is UpgradeInstance) ? reward : null);
							if (val2 != null)
							{
								if (val2.Upgrade.IsSkin())
								{
									Skins++;
									continue;
								}
								UpgradeInstance val3 = val2;
								Upgrades.TryGetValue(val3.Upgrade.Rarity, out var value);
								Upgrades[val3.Upgrade.Rarity] = value + 1;
							}
						}
						else
						{
							Resources.TryGetValue(val, out var value2);
							Resources[val] = value2 + reward2.amount;
						}
					}
					else
					{
						GearXP += reward2.amount;
					}
				}
				else
				{
					CharacterXP += reward2.amount;
				}
			}
		}
	}
	internal static class Session
	{
		public static bool Testing;

		public static readonly Tally Current = new Tally();

		private static string FilePath => Path.Combine(Paths.CachePath, "missionhaul-session.json");

		private static string Launch
		{
			get
			{
				Process currentProcess = Process.GetCurrentProcess();
				return currentProcess.Id + "@" + currentProcess.StartTime.ToUniversalTime().Ticks;
			}
		}

		public static Tally Sample(List<RewardInfo> rewards)
		{
			Tally tally = new Tally();
			tally.Add(rewards, (MissionState)0);
			tally.Add(rewards, (MissionState)0);
			tally.Add(rewards, (MissionState)1);
			return tally;
		}

		public static void Record(List<RewardInfo> rewards, MissionState state)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (!Testing && rewards != null && rewards == Global.rewardInfoBuffer)
			{
				Current.Add(rewards, state);
				Plugin.Log.LogInfo((object)$"Mission Haul: mission {Current.Missions} ({state}) recorded");
				Save();
			}
		}

		private static void Save()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_014d: Expected O, but got Unknown
			try
			{
				JObject val = new JObject
				{
					["launch"] = JToken.op_Implicit(Launch),
					["missions"] = JToken.op_Implicit(Current.Missions),
					["completed"] = JToken.op_Implicit(Current.Completed),
					["failed"] = JToken.op_Implicit(Current.Failed),
					["aborted"] = JToken.op_Implicit(Current.Aborted),
					["characterXP"] = JToken.op_Implicit(Current.CharacterXP),
					["gearXP"] = JToken.op_Implicit(Current.GearXP),
					["skins"] = JToken.op_Implicit(Current.Skins),
					["resources"] = (JToken)new JObject((object)((IEnumerable<KeyValuePair<PlayerResource, int>>)Current.Resources).Select((Func<KeyValuePair<PlayerResource, int>, JProperty>)((KeyValuePair<PlayerResource, int> r) => new JProperty(((Object)r.Key).name, (object)r.Value)))),
					["upgrades"] = (JToken)new JObject((object)((IEnumerable<KeyValuePair<Rarity, int>>)Current.Upgrades).Select((Func<KeyValuePair<Rarity, int>, JProperty>)((KeyValuePair<Rarity, int> u) => new JProperty(((object)u.Key/*cast due to .constrained prefix*/).ToString(), (object)u.Value))))
				};
				File.WriteAllText(FilePath, ((object)val).ToString());
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Mission Haul: couldn't save the session: " + ex.Message));
			}
		}

		public static void Load()
		{
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!File.Exists(FilePath))
				{
					return;
				}
				JObject val = JObject.Parse(File.ReadAllText(FilePath));
				if ((string)val["launch"] != Launch)
				{
					return;
				}
				Current.Missions = (int)val["missions"];
				Current.Completed = (int)val["completed"];
				Current.Failed = (int)val["failed"];
				Current.Aborted = (int)val["aborted"];
				Current.CharacterXP = (int)val["characterXP"];
				Current.GearXP = (int)val["gearXP"];
				Current.Skins = ((int?)val["skins"]).GetValueOrDefault();
				if ((Object)(object)Global.Instance != (Object)null)
				{
					foreach (JProperty r in ((JObject)val["resources"]).Properties())
					{
						PlayerResource val2 = ((IEnumerable<PlayerResource>)Global.Instance.PlayerResources).FirstOrDefault((Func<PlayerResource, bool>)((PlayerResource p) => (Object)(object)p != (Object)null && ((Object)p).name == r.Name));
						if ((Object)(object)val2 != (Object)null)
						{
							Current.Resources[val2] = (int)r.Value;
						}
					}
				}
				foreach (JProperty item in ((JObject)val["upgrades"]).Properties())
				{
					if (Enum.TryParse<Rarity>(item.Name, out Rarity result))
					{
						Current.Upgrades[result] = (int)item.Value;
					}
				}
				Plugin.Log.LogInfo((object)$"Mission Haul: this session's {Current.Missions} mission(s) picked up again");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Mission Haul: couldn't read the saved session: " + ex.Message));
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}