Decompiled source of ProgressionGear v1.2.0

ProgressionGear.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using System.Text.Json.Serialization;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using GTFO.API.JSON.Converters;
using GTFO.API.Utilities;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using LocalProgression;
using LocalProgression.Data;
using MTFO.API;
using MTFO.Ext.PartialData.JsonConverters;
using Microsoft.CodeAnalysis;
using Player;
using ProgressionGear.Dependencies;
using ProgressionGear.JSON;
using ProgressionGear.Patches;
using ProgressionGear.ProgressionLock;
using ProgressionGear.Utils;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ProgressionGear")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e413d595613ec2218c3ac79d3203509e7f044c13")]
[assembly: AssemblyProduct("ProgressionGear")]
[assembly: AssemblyTitle("ProgressionGear")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ProgressionGear
{
	internal static class Configuration
	{
		private static readonly ConfigFile _configFile;

		public static bool DisableProgression { get; set; }

		static Configuration()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			_configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "ProgressionGear.cfg"), true);
			BindAll(_configFile);
		}

		public static void Init()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			LiveEdit.CreateListener(Paths.ConfigPath, "ProgressionGear.cfg", false).FileChanged += new LiveEditEventHandler(OnFileChanged);
		}

		private static void OnFileChanged(LiveEditEventArgs _)
		{
			_configFile.Reload();
			DisableProgression = (bool)_configFile["Override", "Disable Progression Locks"].BoxedValue;
		}

		private static void BindAll(ConfigFile config)
		{
			DisableProgression = config.Bind<bool>("Override", "Disable Progression Locks", DisableProgression, "Disables progression-locking for weapons.").Value;
		}
	}
	[BepInPlugin("Dinorush.ProgressionGear", "ProgressionGear", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal sealed class EntryPoint : BasePlugin
	{
		public const string MODNAME = "ProgressionGear";

		public override void Load()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			PWLogger.Log("Loading ProgressionGear");
			Harmony val = new Harmony("ProgressionGear");
			val.PatchAll();
			if (!LocalProgressionWrapper.HasLocalProgression)
			{
				val.PatchAll(typeof(PageRundownPatches_NoLP));
			}
			if (EOSWrapper.HasEOS)
			{
				val.PatchAll(typeof(RundownManagerPatches_EOS));
			}
			Configuration.Init();
			GearToggleManager.Current.Init();
			ProgressionLockManager.Current.Init();
			PWLogger.Log("Loaded ProgressionGear");
		}
	}
}
namespace ProgressionGear.Utils
{
	internal class DictListEnumerator<T> : IEnumerator<T>, IDisposable, IEnumerator
	{
		private readonly IEnumerator<List<T>> _valueEnumerator;

		private List<T>? _curList;

		private int _index;

		private T? _current;

		public T Current => _current;

		object IEnumerator.Current => Current;

		internal DictListEnumerator(Dictionary<string, List<T>> data)
		{
			_valueEnumerator = data.Values.GetEnumerator();
			if (_valueEnumerator.MoveNext())
			{
				_curList = _valueEnumerator.Current;
			}
			_index = -1;
		}

		public void Dispose()
		{
		}

		public bool MoveNext()
		{
			if (_curList == null || ++_index >= _curList.Count)
			{
				if (!_valueEnumerator.MoveNext())
				{
					return false;
				}
				_curList = _valueEnumerator.Current;
				_index = 0;
			}
			_current = _curList[_index];
			return true;
		}

		public void Reset()
		{
			_valueEnumerator.Reset();
			if (_valueEnumerator.MoveNext())
			{
				_curList = _valueEnumerator.Current;
			}
			_index = -1;
		}
	}
	internal static class GearIDRangeExtensions
	{
		public static uint GetOfflineID(this GearIDRange gearIDRange)
		{
			string playfabItemInstanceId = gearIDRange.PlayfabItemInstanceId;
			if (!playfabItemInstanceId.Contains("OfflineGear_ID_"))
			{
				PWLogger.Error("Find PlayfabItemInstanceId without substring 'OfflineGear_ID_'! " + playfabItemInstanceId);
				return 0u;
			}
			try
			{
				return uint.Parse(playfabItemInstanceId.Substring("OfflineGear_ID_".Length));
			}
			catch
			{
				PWLogger.Error("Caught exception while trying to parse persistentID of PlayerOfflineGearDB from GearIDRange, which means itemInstanceId could be ill-formated");
				return 0u;
			}
		}
	}
	internal static class MTFOUtil
	{
		public const string PLUGIN_GUID = "com.dak.MTFO";

		public const BindingFlags PUBLIC_STATIC = BindingFlags.Static | BindingFlags.Public;

		public static string GameDataPath { get; private set; }

		public static string CustomPath { get; private set; }

		public static bool HasCustomContent { get; private set; }

		public static bool IsLoaded { get; private set; }

		static MTFOUtil()
		{
			GameDataPath = string.Empty;
			CustomPath = string.Empty;
			HasCustomContent = false;
			IsLoaded = false;
			if (!((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue("com.dak.MTFO", out var value))
			{
				return;
			}
			try
			{
				Assembly obj = ((value == null) ? null : value.Instance?.GetType()?.Assembly) ?? null;
				if ((object)obj == null)
				{
					throw new Exception("Assembly is Missing!");
				}
				Type obj2 = obj.GetTypes().First((Type t) => t.Name == "ConfigManager") ?? throw new Exception("Unable to Find ConfigManager Class");
				FieldInfo field = obj2.GetField("GameDataPath", BindingFlags.Static | BindingFlags.Public);
				FieldInfo field2 = obj2.GetField("CustomPath", BindingFlags.Static | BindingFlags.Public);
				FieldInfo? field3 = obj2.GetField("HasCustomContent", BindingFlags.Static | BindingFlags.Public);
				if ((object)field == null)
				{
					throw new Exception("Unable to Find Field: GameDataPath");
				}
				if ((object)field2 == null)
				{
					throw new Exception("Unable to Find Field: CustomPath");
				}
				if ((object)field3 == null)
				{
					throw new Exception("Unable to Find Field: HasCustomContent");
				}
				GameDataPath = (string)field.GetValue(null);
				CustomPath = (string)field2.GetValue(null);
				HasCustomContent = (bool)field3.GetValue(null);
				IsLoaded = true;
			}
			catch (Exception value2)
			{
				PWLogger.Log($"Exception thrown while reading path from DataDumper (MTFO): \n{value2}");
			}
		}
	}
	internal static class PWLogger
	{
		private static ManualLogSource logger = Logger.CreateLogSource("ProgressionGear");

		public static void Log(string format, params object[] args)
		{
			Log(string.Format(format, args));
		}

		public static void Log(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)8, (object)str);
			}
		}

		public static void Warning(string format, params object[] args)
		{
			Warning(string.Format(format, args));
		}

		public static void Warning(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)4, (object)str);
			}
		}

		public static void Error(string format, params object[] args)
		{
			Error(string.Format(format, args));
		}

		public static void Error(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)2, (object)str);
			}
		}

		public static void Debug(string format, params object[] args)
		{
			Debug(string.Format(format, args));
		}

		public static void Debug(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)32, (object)str);
			}
		}
	}
	internal static class StringExtensions
	{
		public static T ToEnum<T>(this string? value, T defaultValue) where T : struct
		{
			if (string.IsNullOrEmpty(value))
			{
				return defaultValue;
			}
			if (!Enum.TryParse<T>(value.Replace(" ", null), ignoreCase: true, out var result))
			{
				return defaultValue;
			}
			return result;
		}
	}
}
namespace ProgressionGear.Patches
{
	[HarmonyPatch]
	internal static class GearManagerPatches
	{
		[HarmonyPatch(typeof(GearManager), "SetupGearInOfflineMode")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_SetupGearInOfflineMode()
		{
			//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)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected I4, but got Unknown
			GearLockManager.Current.VanillaGearManager = GearManager.Current;
			foreach (var gearSlot in GearLockManager.Current.GearSlots)
			{
				InventorySlot item = gearSlot.inventorySlot;
				Dictionary<uint, GearIDRange> item2 = gearSlot.loadedGears;
				Enumerator<GearIDRange> enumerator2 = ((Il2CppArrayBase<List<GearIDRange>>)(object)GearManager.Current.m_gearPerSlot)[(int)item].GetEnumerator();
				while (enumerator2.MoveNext())
				{
					GearIDRange current2 = enumerator2.Current;
					uint offlineID = current2.GetOfflineID();
					item2.TryAdd(offlineID, current2);
				}
			}
			GearToggleManager.Current.ResetRelatedIDs();
		}
	}
	[HarmonyPatch]
	internal static class PageRundownPatches
	{
		[HarmonyPatch(typeof(CM_PageRundown_New), "PlaceRundown")]
		[HarmonyPatch(typeof(CM_PageRundown_New), "OnEnable")]
		[HarmonyAfter(new string[] { "Inas.LocalProgression" })]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_RundownUpdate()
		{
			GearLockManager.Current.SetupAllowedGearsForActiveRundown();
		}
	}
	internal static class PageRundownPatches_NoLP
	{
		[HarmonyPatch(typeof(CM_PageRundown_New), "SetIconStatus")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_IconUpdate(CM_ExpeditionIcon_New icon, string mainFinishCount, string secondFinishCount, string thirdFinishCount, string allFinishedCount)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			ProgressionData progressionData = new ProgressionData();
			if (mainFinishCount != "-")
			{
				progressionData.MainCompletionCount = int.Parse(mainFinishCount);
			}
			if (secondFinishCount != "-")
			{
				progressionData.SecondaryCompletionCount = int.Parse(secondFinishCount);
			}
			if (thirdFinishCount != "-")
			{
				progressionData.ThirdCompletionCount = int.Parse(thirdFinishCount);
			}
			if (allFinishedCount != "-")
			{
				progressionData.AllCompletionCount = int.Parse(allFinishedCount);
			}
			ProgressionWrapper.UpdateNativeProgression(icon.Tier, icon.ExpIndex, progressionData);
		}
	}
	[HarmonyPatch]
	internal static class PlayerLobbyBarPatches
	{
		public static GameObject? SwapButton;

		private static CM_InventorySlotItem? _cachedItem;

		[HarmonyPatch(typeof(CM_PlayerLobbyBar), "UpdateWeaponWindowInfo")]
		[HarmonyPrefix]
		private static void Pre_LoadoutHeaderSelected(CM_PlayerLobbyBar __instance)
		{
			_cachedItem = __instance.selectedWeaponSlotItem;
		}

		[HarmonyPatch(typeof(CM_PlayerLobbyBar), "UpdateWeaponWindowInfo")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_LoadoutHeaderSelected(CM_PlayerLobbyBar __instance, InventorySlot slot)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			BackpackItem val = default(BackpackItem);
			if ((Object)(object)_cachedItem != (Object)(object)__instance.selectedWeaponSlotItem || !PlayerBackpackManager.TryGetItem(__instance.m_player, slot, ref val) || val.GearIDRange == null)
			{
				return;
			}
			uint offlineID = val.GearIDRange.GetOfflineID();
			if (!GearToggleManager.Current.TryGetRelatedIDs(offlineID, out List<uint> relatedIDs))
			{
				return;
			}
			foreach (iScrollWindowContent item in (Il2CppArrayBase<iScrollWindowContent>)(object)__instance.m_popupScrollWindow.ContentItems)
			{
				CM_InventorySlotItem val2 = ((Il2CppObjectBase)item).TryCast<CM_InventorySlotItem>();
				if (relatedIDs.Contains(val2.m_gearID.GetOfflineID()))
				{
					val2.IsPicked = true;
					val2.LoadData(val.GearIDRange, true, true);
					__instance.OnWeaponSlotItemSelected(val2);
					_cachedItem = __instance.selectedWeaponSlotItem;
					break;
				}
			}
		}

		[HarmonyPatch(typeof(CM_PlayerLobbyBar), "ShowWeaponSelectionPopup")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_LoadoutMenuOpened(CM_PlayerLobbyBar __instance)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			CM_PlayerLobbyBar __instance2 = __instance;
			CM_ScrollWindowInfoBox infoBox = __instance2.m_popupScrollWindow.InfoBox;
			SwapButton = Object.Instantiate<GameObject>(((Component)CM_PageLoadout.Current.m_copyLobbyIdButton).gameObject, ((Component)infoBox).transform);
			CM_Item component = SwapButton.GetComponent<CM_Item>();
			((TMP_Text)((Il2CppArrayBase<TextMeshPro>)(object)component.m_texts)[0]).SetText("Switch Gear", true);
			((Component)component).transform.localPosition = new Vector3(-300f, -320f, -1f);
			component.OnBtnPressCallback = null;
			component.OnBtnPressCallback += Action<int>.op_Implicit((Action<int>)delegate
			{
				CM_InventorySlotItem val = __instance2.selectedWeaponSlotItem ?? _cachedItem;
				if (!((Object)(object)val == (Object)null))
				{
					uint offlineID = val.m_gearID.GetOfflineID();
					List<uint> relatedIDs = GearToggleManager.Current.GetRelatedIDs(offlineID);
					uint value = relatedIDs[(relatedIDs.IndexOf(offlineID) + 1) % relatedIDs.Count];
					GearIDRange val2 = default(GearIDRange);
					if (GearManager.TryGetGear("OfflineGear_ID_" + value, ref val2))
					{
						val.LoadData(val2, true, true);
						__instance2.OnWeaponSlotItemSelected(val);
					}
					else
					{
						PWLogger.Error($"Couldn't swap to next weapon ({value}) in toggle list!");
					}
				}
			});
			if ((Object)(object)__instance2.selectedWeaponSlotItem != (Object)null)
			{
				Post_LoadoutItemSelected(__instance2.selectedWeaponSlotItem);
			}
		}

		[HarmonyPatch(typeof(CM_PlayerLobbyBar), "OnWeaponSlotItemSelected")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_LoadoutItemSelected(CM_InventorySlotItem slotItem)
		{
			if (!((Object)(object)SwapButton == (Object)null))
			{
				uint offlineID = slotItem.m_gearID.GetOfflineID();
				SwapButton.SetActive(GearToggleManager.Current.HasRelatedIDs(offlineID));
			}
		}
	}
	internal static class RundownManagerPatches_EOS
	{
		[HarmonyPatch(typeof(RundownManager), "SetActiveExpedition")]
		[HarmonyAfter(new string[] { "Inas.ExtraObjectiveSetup" })]
		[HarmonyPostfix]
		private static void Post_RundownManager_SetActiveExpedition(pActiveExpedition expPackage)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)expPackage.tier != 99)
			{
				GearLockManager.Current.LockGearForActiveRundown();
			}
		}
	}
}
namespace ProgressionGear.JSON
{
	public sealed class ProgressionLockDataConverter : JsonConverter<ProgressionLockData>
	{
		public override ProgressionLockData? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			throw new JsonException("ProgressionLockData doesn't have a custom read!");
		}

		public override void Write(Utf8JsonWriter writer, ProgressionLockData? value, JsonSerializerOptions options)
		{
			if (value != null)
			{
				writer.WriteStartObject();
				writer.WritePropertyName("Unlock");
				JsonSerializer.Serialize(writer, value.Unlock, options);
				writer.WritePropertyName("Lock");
				JsonSerializer.Serialize(writer, value.Lock, options);
				writer.WritePropertyName("OfflineIDs");
				JsonSerializer.Serialize(writer, value.OfflineIDs, options);
				writer.WriteNumber("Priority", value.Priority);
				writer.WriteString("Name", value.Name);
				writer.WriteEndObject();
			}
		}
	}
	public sealed class ProgressionRequirementConverter : JsonConverter<ProgressionRequirement>
	{
		public override ProgressionRequirement? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			ProgressionRequirement progressionRequirement = new ProgressionRequirement();
			if (ParseRequirement(ref reader, progressionRequirement, options))
			{
				return progressionRequirement;
			}
			if (reader.TokenType != JsonTokenType.StartObject)
			{
				throw new JsonException("Expected progression requirement to be a tier, level layout ID, or object");
			}
			while (reader.Read())
			{
				if (reader.TokenType == JsonTokenType.EndObject)
				{
					return progressionRequirement;
				}
				if (reader.TokenType != JsonTokenType.PropertyName)
				{
					throw new JsonException("Expected PropertyName token");
				}
				string? @string = reader.GetString();
				reader.Read();
				switch (@string.ToLowerInvariant().Replace(" ", ""))
				{
				case "levellayout":
				case "requirement":
				case "levelid":
				case "tier":
				case "level":
				case "levellayoutid":
					ParseRequirement(ref reader, progressionRequirement, options);
					break;
				case "high":
				case "main":
					progressionRequirement.Main = reader.GetBoolean();
					break;
				case "extreme":
				case "secondary":
					progressionRequirement.Secondary = reader.GetBoolean();
					break;
				case "overload":
					progressionRequirement.Overload = reader.GetBoolean();
					break;
				case "all":
				case "pe":
				case "prisonerefficiency":
					progressionRequirement.All = reader.GetBoolean();
					break;
				case "penobooster":
				case "allnobooster":
				case "prisonerefficiencynobooster":
					progressionRequirement.AllNoBooster = reader.GetBoolean();
					break;
				}
			}
			throw new JsonException("Expected EndObject token");
		}

		private static bool ParseRequirement(ref Utf8JsonReader reader, ProgressionRequirement req, JsonSerializerOptions options)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			if (reader.TokenType == JsonTokenType.Null)
			{
				return true;
			}
			if (reader.TokenType == JsonTokenType.String)
			{
				req.Tier = reader.GetString().ToEnum<eRundownTier>((eRundownTier)99);
				if ((int)req.Tier == 99)
				{
					req.LevelLayoutID = JsonSerializer.Deserialize<uint>(ref reader, options);
				}
				return true;
			}
			if (reader.TokenType == JsonTokenType.Number)
			{
				req.LevelLayoutID = reader.GetUInt32();
				return true;
			}
			return false;
		}

		public override void Write(Utf8JsonWriter writer, ProgressionRequirement? value, JsonSerializerOptions options)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			//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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (value == null)
			{
				return;
			}
			if (value.LevelLayoutID == 0 && (int)value.Tier == 99)
			{
				writer.WriteNullValue();
				return;
			}
			eRundownTier tier;
			if (value.Main && !value.Secondary && !value.Overload && !value.All)
			{
				if (value.LevelLayoutID != 0)
				{
					writer.WriteNumberValue(value.LevelLayoutID);
					return;
				}
				tier = value.Tier;
				writer.WriteStringValue(((object)(eRundownTier)(ref tier)).ToString());
				return;
			}
			writer.WriteStartObject();
			writer.WritePropertyName("Level");
			if (value.LevelLayoutID != 0)
			{
				writer.WriteNumberValue(value.LevelLayoutID);
			}
			else
			{
				tier = value.Tier;
				writer.WriteStringValue(((object)(eRundownTier)(ref tier)).ToString());
			}
			writer.WriteBoolean("Main", value.Main);
			writer.WriteBoolean("Secondary", value.Secondary);
			writer.WriteBoolean("Overload", value.Overload);
			writer.WriteBoolean("All", value.All);
			writer.WriteBoolean("AllNoBooster", value.AllNoBooster);
			writer.WriteEndObject();
		}
	}
	public static class PWJson
	{
		private static readonly JsonSerializerOptions _readSettings;

		private static readonly JsonSerializerOptions _writeSettings;

		static PWJson()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			_readSettings = new JsonSerializerOptions
			{
				ReadCommentHandling = JsonCommentHandling.Skip,
				IncludeFields = true,
				PropertyNameCaseInsensitive = true,
				WriteIndented = true,
				IgnoreReadOnlyProperties = true
			};
			_writeSettings = new JsonSerializerOptions(_readSettings);
			_readSettings.Converters.Add(new JsonStringEnumConverter());
			_readSettings.Converters.Add((JsonConverter)new LocalizedTextConverter());
			_readSettings.Converters.Add(new ProgressionRequirementConverter());
			PartialDataWrapper.AddIDConverter(_readSettings.Converters);
			foreach (JsonConverter converter in _readSettings.Converters)
			{
				_writeSettings.Converters.Add(converter);
			}
			_writeSettings.Converters.Add(new ProgressionLockDataConverter());
		}

		public static T? Deserialize<T>(string json)
		{
			return JsonSerializer.Deserialize<T>(json, _readSettings);
		}

		public static object? Deserialize(Type type, string json)
		{
			return JsonSerializer.Deserialize(json, type, _readSettings);
		}

		public static string Serialize<T>(T value)
		{
			return JsonSerializer.Serialize(value, _writeSettings);
		}
	}
}
namespace ProgressionGear.ProgressionLock
{
	public sealed class GearToggleData
	{
		public List<uint> OfflineIDs { get; set; } = new List<uint>();


		public string Name { get; set; } = string.Empty;

	}
	public sealed class GearToggleManager
	{
		public static readonly GearToggleManager Current = new GearToggleManager();

		private readonly Dictionary<string, List<GearToggleData>> _fileToData = new Dictionary<string, List<GearToggleData>>();

		private readonly Dictionary<uint, List<uint>> _relatedIDs = new Dictionary<uint, List<uint>>();

		private readonly LiveEditListener _liveEditListener;

		private void FileChanged(LiveEditEventArgs e)
		{
			LiveEditEventArgs e2 = e;
			PWLogger.Warning("LiveEdit File Changed: " + e2.FullPath);
			LiveEdit.TryReadFileContent(e2.FullPath, (Action<string>)delegate(string content)
			{
				ReadFileContent(e2.FullPath, content);
			});
		}

		private void FileDeleted(LiveEditEventArgs e)
		{
			PWLogger.Warning("LiveEdit File Removed: " + e.FullPath);
			_fileToData.Remove(e.FullPath);
			ResetRelatedIDs();
		}

		private void FileCreated(LiveEditEventArgs e)
		{
			LiveEditEventArgs e2 = e;
			PWLogger.Warning("LiveEdit File Created: " + e2.FullPath);
			LiveEdit.TryReadFileContent(e2.FullPath, (Action<string>)delegate(string content)
			{
				ReadFileContent(e2.FullPath, content);
			});
		}

		private void ReadFileContent(string file, string content)
		{
			_fileToData.Remove(file);
			List<GearToggleData> list = null;
			try
			{
				list = PWJson.Deserialize<List<GearToggleData>>(content);
			}
			catch (JsonException ex)
			{
				PWLogger.Error("Error parsing progression lock json " + file);
				PWLogger.Error(ex.Message);
			}
			if (list != null)
			{
				_fileToData[file] = list;
				ResetRelatedIDs();
			}
		}

		private GearToggleManager()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			string text = Path.Combine(MTFOPathAPI.CustomPath, "ProgressionGear", "GearToggle");
			if (!Directory.Exists(text))
			{
				PWLogger.Log("No directory detected. Creating " + text + "/Template.json");
				Directory.CreateDirectory(text);
				StreamWriter streamWriter = File.CreateText(Path.Combine(text, "Template.json"));
				streamWriter.WriteLine(PWJson.Serialize(new List<GearToggleData>
				{
					new GearToggleData()
				}));
				streamWriter.Flush();
				streamWriter.Close();
			}
			else
			{
				PWLogger.Log("Directory detected. " + text);
			}
			foreach (string item in Directory.EnumerateFiles(text, "*.json", SearchOption.AllDirectories))
			{
				string content = File.ReadAllText(item);
				ReadFileContent(item, content);
			}
			_liveEditListener = LiveEdit.CreateListener(text, "*.json", true);
			_liveEditListener.FileCreated += new LiveEditEventHandler(FileCreated);
			_liveEditListener.FileChanged += new LiveEditEventHandler(FileChanged);
			_liveEditListener.FileDeleted += new LiveEditEventHandler(FileDeleted);
		}

		internal void Init()
		{
		}

		public bool IsVisibleID(uint id)
		{
			if (_relatedIDs.TryGetValue(id, out List<uint> value))
			{
				return value[0] == id;
			}
			return true;
		}

		public bool HasRelatedIDs(uint id)
		{
			return _relatedIDs.ContainsKey(id);
		}

		public List<uint>? GetRelatedIDs(uint id)
		{
			return _relatedIDs.GetValueOrDefault(id);
		}

		public bool TryGetRelatedIDs(uint id, [MaybeNullWhen(false)] out List<uint> relatedIDs)
		{
			return _relatedIDs.TryGetValue(id, out relatedIDs);
		}

		public List<GearToggleData> GetData()
		{
			List<GearToggleData> list2 = new List<GearToggleData>(_fileToData.Values.Sum((List<GearToggleData> list) => list.Count));
			IEnumerator<GearToggleData> enumerator = GetEnumerator();
			while (enumerator.MoveNext())
			{
				list2.Add(enumerator.Current);
			}
			return list2;
		}

		public IEnumerator<GearToggleData> GetEnumerator()
		{
			return new DictListEnumerator<GearToggleData>(_fileToData);
		}

		public void RemoveFromRelatedIDs(uint id)
		{
			if (_relatedIDs.TryGetValue(id, out List<uint> value))
			{
				value.Remove(id);
				if (value.Count == 1)
				{
					_relatedIDs.Remove(value[0]);
				}
				_relatedIDs.Remove(id);
			}
		}

		public void ResetRelatedIDs()
		{
			_relatedIDs.Clear();
			HashSet<uint> hashSet = new HashSet<uint>();
			IEnumerator<GearToggleData> enumerator = GetEnumerator();
			while (enumerator.MoveNext())
			{
				GearToggleData current = enumerator.Current;
				if (current.OfflineIDs.Count <= 1)
				{
					continue;
				}
				List<uint> list = new List<uint>(current.OfflineIDs.Count);
				foreach (uint offlineID in current.OfflineIDs)
				{
					if (hashSet.Add(offlineID))
					{
						list.Add(offlineID);
						continue;
					}
					PWLogger.Warning($"Duplicate ID {offlineID} detected in toggle data. Removed from {current.Name}");
				}
				if (list.Count <= 1)
				{
					continue;
				}
				RemoveInvalidGear(list, current.Name);
				if (list.Count <= 1)
				{
					continue;
				}
				foreach (uint item in list)
				{
					_relatedIDs[item] = list;
				}
			}
		}

		private void RemoveInvalidGear(List<uint> relatedIDs, string name)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GearLockManager.Current.VanillaGearManager == (Object)null)
			{
				return;
			}
			foreach (var (value, dictionary) in GearLockManager.Current.GearSlots)
			{
				if (!dictionary.ContainsKey(relatedIDs[0]))
				{
					continue;
				}
				for (int num = relatedIDs.Count - 1; num >= 1; num--)
				{
					uint num2 = relatedIDs[num];
					if (!dictionary.ContainsKey(num2))
					{
						PWLogger.Warning($"ID {num2} removed from toggle data {name} since it is not of type {value}");
						relatedIDs.RemoveAt(num);
					}
				}
			}
		}
	}
	public sealed class GearLockManager
	{
		private struct PriorityLockData
		{
			public int priority;

			public bool locked;

			public bool explicitLock;
		}

		private readonly HashSet<uint> _lockedGearIds = new HashSet<uint>();

		internal readonly List<(InventorySlot inventorySlot, Dictionary<uint, GearIDRange> loadedGears)> GearSlots = new List<(InventorySlot, Dictionary<uint, GearIDRange>)>
		{
			((InventorySlot)1, new Dictionary<uint, GearIDRange>()),
			((InventorySlot)2, new Dictionary<uint, GearIDRange>()),
			((InventorySlot)10, new Dictionary<uint, GearIDRange>()),
			((InventorySlot)3, new Dictionary<uint, GearIDRange>())
		};

		public static GearLockManager Current { get; private set; } = new GearLockManager();


		public GearManager? VanillaGearManager { get; internal set; }

		private void ConfigRundownGears()
		{
			if (Configuration.DisableProgression)
			{
				return;
			}
			_lockedGearIds.Clear();
			GearToggleManager.Current.ResetRelatedIDs();
			IEnumerator<ProgressionLockData> enumerator = ProgressionLockManager.Current.GetEnumerator();
			Dictionary<uint, PriorityLockData> dictionary = new Dictionary<uint, PriorityLockData>();
			while (enumerator.MoveNext())
			{
				ProgressionLockData current = enumerator.Current;
				foreach (uint offlineID in current.OfflineIDs)
				{
					PriorityLockData priorityLockData = default(PriorityLockData);
					priorityLockData.priority = current.Priority;
					priorityLockData.locked = IsGearLocked(current);
					priorityLockData.explicitLock = IsLockExplicit(current);
					PriorityLockData value = priorityLockData;
					if (!dictionary.TryGetValue(offlineID, out var value2) || ((!value2.explicitLock || value.explicitLock) && value2.priority <= value.priority))
					{
						dictionary.Add(offlineID, value);
					}
				}
			}
			foreach (KeyValuePair<uint, PriorityLockData> item in dictionary.Where((KeyValuePair<uint, PriorityLockData> kv) => kv.Value.locked))
			{
				_lockedGearIds.Add(item.Key);
				GearToggleManager.Current.RemoveFromRelatedIDs(item.Key);
			}
		}

		private void ClearLoadedGears()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected I4, but got Unknown
			foreach (var gearSlot in GearSlots)
			{
				((Il2CppArrayBase<List<GearIDRange>>)(object)VanillaGearManager.m_gearPerSlot)[(int)gearSlot.inventorySlot].Clear();
			}
		}

		public bool IsGearAllowed(uint id)
		{
			return !_lockedGearIds.Contains(id);
		}

		private void AddGearForCurrentRundown()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected I4, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			foreach (var gearSlot in GearSlots)
			{
				InventorySlot item = gearSlot.inventorySlot;
				Dictionary<uint, GearIDRange> item2 = gearSlot.loadedGears;
				List<GearIDRange> val = ((Il2CppArrayBase<List<GearIDRange>>)(object)VanillaGearManager.m_gearPerSlot)[(int)item];
				if (item2.Count == 0)
				{
					PWLogger.Debug($"No gear has been loaded for {item}.");
					continue;
				}
				foreach (uint key in item2.Keys)
				{
					if (IsGearAllowed(key))
					{
						val.Add(item2[key]);
					}
				}
				if (val.Count == 0)
				{
					PWLogger.Error($"No gear is allowed for {item}, there must be at least 1 allowed gear!");
					val.Add(item2.First().Value);
				}
			}
		}

		private void ResetPlayerSelectedGears()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected I4, but got Unknown
			VanillaGearManager.RescanFavorites();
			foreach (var gearSlot in GearSlots)
			{
				int num = (int)gearSlot.inventorySlot;
				if (((Il2CppArrayBase<GearIDRange>)(object)VanillaGearManager.m_lastEquippedGearPerSlot)[num] != null)
				{
					PlayerBackpackManager.EquipLocalGear(((Il2CppArrayBase<GearIDRange>)(object)VanillaGearManager.m_lastEquippedGearPerSlot)[num]);
				}
				else if (((Il2CppArrayBase<List<GearIDRange>>)(object)VanillaGearManager.m_favoriteGearPerSlot)[num].Count > 0)
				{
					PlayerBackpackManager.EquipLocalGear(((Il2CppArrayBase<List<GearIDRange>>)(object)VanillaGearManager.m_favoriteGearPerSlot)[num][0]);
				}
				else if (((Il2CppArrayBase<List<GearIDRange>>)(object)VanillaGearManager.m_gearPerSlot)[num].Count > 0)
				{
					PlayerBackpackManager.EquipLocalGear(((Il2CppArrayBase<List<GearIDRange>>)(object)VanillaGearManager.m_gearPerSlot)[num][0]);
				}
			}
		}

		private void RemoveToggleGears()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected I4, but got Unknown
			foreach (var gearSlot in GearSlots)
			{
				List<GearIDRange> val = ((Il2CppArrayBase<List<GearIDRange>>)(object)VanillaGearManager.m_gearPerSlot)[(int)gearSlot.inventorySlot];
				for (int num = val.Count - 1; num >= 0; num--)
				{
					if (!GearToggleManager.Current.IsVisibleID(val[num].GetOfflineID()))
					{
						val.RemoveAt(num);
					}
				}
			}
		}

		internal void SetupAllowedGearsForActiveRundown()
		{
			if (ProgressionWrapper.UpdateReferences())
			{
				ConfigRundownGears();
				ClearLoadedGears();
				AddGearForCurrentRundown();
				ResetPlayerSelectedGears();
				RemoveToggleGears();
			}
		}

		internal void LockGearForActiveRundown()
		{
			if (ProgressionWrapper.UpdateReferences())
			{
				ReapplyGearLocks();
				ResetPlayerSelectedGears();
				RemoveToggleGears();
			}
		}

		private void ReapplyGearLocks()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected I4, but got Unknown
			foreach (var gearSlot in GearSlots)
			{
				InventorySlot item = gearSlot.inventorySlot;
				Dictionary<uint, GearIDRange> item2 = gearSlot.loadedGears;
				List<GearIDRange> val = ((Il2CppArrayBase<List<GearIDRange>>)(object)VanillaGearManager.m_gearPerSlot)[(int)item];
				HashSet<uint> hashSet = new HashSet<uint>(item2.Keys);
				for (int num = val.Count - 1; num >= 0; num--)
				{
					uint offlineID = val[num].GetOfflineID();
					if (!IsGearAllowed(offlineID))
					{
						val.RemoveAt(num);
					}
					hashSet.Remove(offlineID);
				}
				foreach (uint item3 in hashSet)
				{
					GearToggleManager.Current.RemoveFromRelatedIDs(item3);
				}
			}
		}

		private static bool IsGearLocked(ProgressionLockData data)
		{
			if (!data.Unlock.Any() || data.Unlock.All(IsComplete))
			{
				if (data.Lock.Any())
				{
					return data.Lock.All(IsComplete);
				}
				return false;
			}
			return true;
		}

		private static bool IsLockExplicit(ProgressionLockData data)
		{
			if (!data.Unlock.All(IsComplete))
			{
				if (data.Lock.Any())
				{
					return data.Lock.All(IsComplete);
				}
				return false;
			}
			return true;
		}

		private static bool IsComplete(ProgressionRequirement req)
		{
			return ProgressionWrapper.IsComplete(req);
		}
	}
	public sealed class ProgressionData
	{
		public string ExpeditionKey { get; set; } = string.Empty;


		public int MainCompletionCount { get; set; }

		public int SecondaryCompletionCount { get; set; }

		public int ThirdCompletionCount { get; set; }

		public int AllCompletionCount { get; set; }

		public int NoBoosterAllClearCount { get; set; }

		public ProgressionData()
		{
		}

		public ProgressionData(string key, int main, int secondary, int third, int all, int noBooster)
		{
			ExpeditionKey = key;
			MainCompletionCount = main;
			SecondaryCompletionCount = secondary;
			ThirdCompletionCount = third;
			AllCompletionCount = all;
			NoBoosterAllClearCount = noBooster;
		}
	}
	public sealed class ProgressionLockData
	{
		public static readonly ProgressionLockData[] Template = new ProgressionLockData[2]
		{
			new ProgressionLockData
			{
				Unlock = new List<ProgressionRequirement>
				{
					new ProgressionRequirement
					{
						LevelLayoutID = 420u
					},
					new ProgressionRequirement
					{
						Tier = (eRundownTier)2
					},
					new ProgressionRequirement
					{
						LevelLayoutID = 10u,
						Main = true,
						Secondary = true
					},
					new ProgressionRequirement
					{
						Tier = (eRundownTier)1,
						Main = false,
						All = true
					}
				},
				Lock = new List<ProgressionRequirement>
				{
					new ProgressionRequirement
					{
						Tier = (eRundownTier)3
					}
				},
				OfflineIDs = new List<uint> { 0u },
				Priority = 0,
				Name = "Example"
			},
			new ProgressionLockData
			{
				Name = "Empty Example"
			}
		};

		public List<ProgressionRequirement> UnlockLayoutIDs { get; set; } = new List<ProgressionRequirement>();


		public List<ProgressionRequirement> UnlockTiers { get; set; } = new List<ProgressionRequirement>();


		public List<ProgressionRequirement> Unlock { get; set; } = new List<ProgressionRequirement>();


		public List<ProgressionRequirement> LockLayoutIDs { get; set; } = new List<ProgressionRequirement>();


		public List<ProgressionRequirement> LockTiers { get; set; } = new List<ProgressionRequirement>();


		public List<ProgressionRequirement> Lock { get; set; } = new List<ProgressionRequirement>();


		public List<uint> OfflineIDs { get; set; } = new List<uint>();


		public int Priority { get; set; }

		public string Name { get; set; } = string.Empty;

	}
	public sealed class ProgressionLockManager
	{
		public static readonly ProgressionLockManager Current = new ProgressionLockManager();

		private readonly Dictionary<string, List<ProgressionLockData>> _fileToData = new Dictionary<string, List<ProgressionLockData>>();

		private readonly LiveEditListener _liveEditListener;

		private void FileChanged(LiveEditEventArgs e)
		{
			LiveEditEventArgs e2 = e;
			PWLogger.Warning("LiveEdit File Changed: " + e2.FullPath);
			LiveEdit.TryReadFileContent(e2.FullPath, (Action<string>)delegate(string content)
			{
				ReadFileContent(e2.FullPath, content);
			});
		}

		private void FileDeleted(LiveEditEventArgs e)
		{
			PWLogger.Warning("LiveEdit File Removed: " + e.FullPath);
			_fileToData.Remove(e.FullPath);
		}

		private void FileCreated(LiveEditEventArgs e)
		{
			LiveEditEventArgs e2 = e;
			PWLogger.Warning("LiveEdit File Created: " + e2.FullPath);
			LiveEdit.TryReadFileContent(e2.FullPath, (Action<string>)delegate(string content)
			{
				ReadFileContent(e2.FullPath, content);
			});
		}

		private void ReadFileContent(string file, string content)
		{
			_fileToData.Remove(file);
			List<ProgressionLockData> list = null;
			try
			{
				list = PWJson.Deserialize<List<ProgressionLockData>>(content);
			}
			catch (JsonException ex)
			{
				PWLogger.Error("Error parsing progression lock json " + file);
				PWLogger.Error(ex.Message);
			}
			if (list == null)
			{
				return;
			}
			foreach (ProgressionLockData item in list)
			{
				if (!item.Unlock.Any())
				{
					item.Unlock.AddRange(item.UnlockLayoutIDs);
					item.Unlock.AddRange(item.UnlockTiers);
					item.UnlockLayoutIDs.Clear();
					item.UnlockTiers.Clear();
				}
				if (!item.Lock.Any())
				{
					item.Lock.AddRange(item.LockLayoutIDs);
					item.Lock.AddRange(item.LockTiers);
					item.LockLayoutIDs.Clear();
					item.LockTiers.Clear();
				}
			}
			_fileToData[file] = list;
		}

		private ProgressionLockManager()
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			string text = Path.Combine(MTFOPathAPI.CustomPath, "ProgressionGear", "ProgressionLocks");
			if (!Directory.Exists(text))
			{
				PWLogger.Log("No directory detected. Creating " + text + "/Template.json");
				Directory.CreateDirectory(text);
				StreamWriter streamWriter = File.CreateText(Path.Combine(text, "Template.json"));
				streamWriter.WriteLine(PWJson.Serialize(ProgressionLockData.Template));
				streamWriter.Flush();
				streamWriter.Close();
			}
			else
			{
				PWLogger.Log("Directory detected. " + text);
			}
			foreach (string item in Directory.EnumerateFiles(text, "*.json", SearchOption.AllDirectories))
			{
				string content = File.ReadAllText(item);
				ReadFileContent(item, content);
			}
			_liveEditListener = LiveEdit.CreateListener(text, "*.json", true);
			_liveEditListener.FileCreated += new LiveEditEventHandler(FileCreated);
			_liveEditListener.FileChanged += new LiveEditEventHandler(FileChanged);
			_liveEditListener.FileDeleted += new LiveEditEventHandler(FileDeleted);
		}

		internal void Init()
		{
		}

		public List<ProgressionLockData> GetLockData()
		{
			List<ProgressionLockData> list2 = new List<ProgressionLockData>(_fileToData.Values.Sum((List<ProgressionLockData> list) => list.Count));
			IEnumerator<ProgressionLockData> enumerator = GetEnumerator();
			while (enumerator.MoveNext())
			{
				list2.Add(enumerator.Current);
			}
			return list2;
		}

		public IEnumerator<ProgressionLockData> GetEnumerator()
		{
			return new DictListEnumerator<ProgressionLockData>(_fileToData);
		}
	}
	public sealed class ProgressionRequirement
	{
		public eRundownTier Tier { get; set; } = (eRundownTier)99;


		public uint LevelLayoutID { get; set; }

		public bool Main { get; set; } = true;


		public bool Secondary { get; set; }

		public bool Overload { get; set; }

		public bool All { get; set; }

		public bool AllNoBooster { get; set; }

		public bool Complete(ProgressionData data)
		{
			if ((!AllNoBooster || data.NoBoosterAllClearCount > 0) && (!All || data.AllCompletionCount > 0) && (!Main || data.MainCompletionCount > 0) && (!Secondary || data.SecondaryCompletionCount > 0))
			{
				if (Overload)
				{
					return data.ThirdCompletionCount > 0;
				}
				return true;
			}
			return false;
		}
	}
	public static class ProgressionWrapper
	{
		private struct ExpeditionKey
		{
			public eRundownTier tier;

			public int expIndex;
		}

		private static readonly Dictionary<uint, ExpeditionKey> _layoutToExpedition;

		private static readonly Dictionary<eRundownTier, List<ExpeditionKey>> _tierExpeditionKeys;

		private static readonly Dictionary<eRundownTier, List<ProgressionData>> _nativeProgression;

		public static uint CurrentRundownID { get; private set; }

		static ProgressionWrapper()
		{
			_layoutToExpedition = new Dictionary<uint, ExpeditionKey>();
			_tierExpeditionKeys = new Dictionary<eRundownTier, List<ExpeditionKey>>
			{
				{
					(eRundownTier)1,
					new List<ExpeditionKey>()
				},
				{
					(eRundownTier)2,
					new List<ExpeditionKey>()
				},
				{
					(eRundownTier)3,
					new List<ExpeditionKey>()
				},
				{
					(eRundownTier)4,
					new List<ExpeditionKey>()
				},
				{
					(eRundownTier)5,
					new List<ExpeditionKey>()
				}
			};
			_nativeProgression = new Dictionary<eRundownTier, List<ProgressionData>>();
			CurrentRundownID = 0u;
		}

		private static uint ActiveRundownID()
		{
			string activeRundownKey = RundownManager.ActiveRundownKey;
			uint result = default(uint);
			if (!RundownManager.RundownProgressionReady || !RundownManager.TryGetIdFromLocalRundownKey(activeRundownKey, ref result))
			{
				return 0u;
			}
			return result;
		}

		public static bool UpdateReferences()
		{
			uint num = ActiveRundownID();
			if (num == 0)
			{
				return false;
			}
			if (CurrentRundownID == num)
			{
				return true;
			}
			CurrentRundownID = num;
			_layoutToExpedition.Clear();
			RundownDataBlock block = GameDataBlockBase<RundownDataBlock>.GetBlock(CurrentRundownID);
			AddTierLayouts((eRundownTier)1, block.TierA);
			AddTierLayouts((eRundownTier)2, block.TierB);
			AddTierLayouts((eRundownTier)3, block.TierC);
			AddTierLayouts((eRundownTier)4, block.TierD);
			AddTierLayouts((eRundownTier)5, block.TierE);
			return true;
		}

		internal static void UpdateNativeProgression(eRundownTier tier, int expIndex, ProgressionData data)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			UpdateReferences();
			if (!_nativeProgression.ContainsKey(tier))
			{
				_nativeProgression[tier] = new List<ProgressionData>(5);
			}
			List<ProgressionData> list = _nativeProgression[tier];
			if (list.Count <= expIndex)
			{
				list.EnsureCapacity(expIndex + 1);
				for (int i = list.Count; i <= expIndex; i++)
				{
					list.Add(new ProgressionData());
				}
			}
			list[expIndex] = data;
		}

		private static void AddTierLayouts(eRundownTier tier, List<ExpeditionInTierData> dataList)
		{
			//IL_0005: 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)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			_tierExpeditionKeys[tier].Clear();
			for (int i = 0; i < dataList.Count; i++)
			{
				ExpeditionInTierData val = dataList[i];
				if (val.Enabled)
				{
					ExpeditionKey expeditionKey = default(ExpeditionKey);
					expeditionKey.tier = tier;
					expeditionKey.expIndex = i;
					ExpeditionKey expeditionKey2 = expeditionKey;
					_layoutToExpedition.Add(val.LevelLayoutData, expeditionKey2);
					_tierExpeditionKeys[tier].Add(expeditionKey2);
				}
			}
		}

		private static ProgressionData GetProgressionData(uint id, eRundownTier tier, int index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (LocalProgressionWrapper.HasLocalProgression)
			{
				return LocalProgressionWrapper.GetProgressionDataLP(id, tier, index);
			}
			if (_nativeProgression.Count == 0)
			{
				return new ProgressionData();
			}
			return _nativeProgression[tier][index];
		}

		public static bool IsComplete(ProgressionRequirement req)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			UpdateReferences();
			if (req.LevelLayoutID != 0)
			{
				if (!_layoutToExpedition.ContainsKey(req.LevelLayoutID))
				{
					return true;
				}
				ExpeditionKey expeditionKey = _layoutToExpedition[req.LevelLayoutID];
				return req.Complete(GetProgressionData(CurrentRundownID, expeditionKey.tier, expeditionKey.expIndex));
			}
			if ((int)req.Tier != 99)
			{
				foreach (ExpeditionKey item in _tierExpeditionKeys[req.Tier])
				{
					if (!req.Complete(GetProgressionData(CurrentRundownID, item.tier, item.expIndex)))
					{
						return false;
					}
				}
			}
			return true;
		}
	}
}
namespace ProgressionGear.Dependencies
{
	internal static class EOSWrapper
	{
		public const string GUID = "Inas.ExtraObjectiveSetup";

		public static bool HasEOS { get; private set; }

		static EOSWrapper()
		{
			HasEOS = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("Inas.ExtraObjectiveSetup");
		}
	}
	internal static class LocalProgressionWrapper
	{
		public const string GUID = "Inas.LocalProgression";

		public static bool HasLocalProgression { get; private set; }

		static LocalProgressionWrapper()
		{
			HasLocalProgression = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("Inas.LocalProgression");
		}

		public static ProgressionData GetProgressionDataLP(uint id, eRundownTier tier, int index)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!HasLocalProgression)
			{
				return new ProgressionData();
			}
			ExpeditionProgressionData expeditionLP = LocalProgressionManager.Current.GetExpeditionLP(id, tier, index);
			return new ProgressionData(expeditionLP.ExpeditionKey, expeditionLP.MainCompletionCount, expeditionLP.SecondaryCompletionCount, expeditionLP.ThirdCompletionCount, expeditionLP.AllClearCount, expeditionLP.NoBoosterAllClearCount);
		}
	}
	internal static class PartialDataWrapper
	{
		public const string GUID = "MTFO.Extension.PartialBlocks";

		public static bool HasPartialData { get; private set; }

		static PartialDataWrapper()
		{
			HasPartialData = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("MTFO.Extension.PartialBlocks");
		}

		public static void AddIDConverter(IList<JsonConverter> list)
		{
			if (HasPartialData)
			{
				Unsafe_AddIDConverter(list);
			}
		}

		private static void Unsafe_AddIDConverter(IList<JsonConverter> list)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			list.Add((JsonConverter)new PersistentIDConverter());
		}
	}
}