Decompiled source of PreselectBacklog v1.0.0

BepInEx/plugins/PreselectBacklog.dll

Decompiled a week 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.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.UI;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("PreselectBacklog")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0.3+0c134903a1c9b4aec30b68e21f6275961508b5bd")]
[assembly: AssemblyProduct("PreselectBacklog")]
[assembly: AssemblyTitle("PreselectBacklog")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
public class PathLineDrawer : MonoBehaviour
{
	public List<Vector3[]> Lines = new List<Vector3[]>();

	private void OnGUI()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		if (!SparrohPlugin.DirectiveWindowActive)
		{
			return;
		}
		Canvas component = ((Component)this).GetComponent<Canvas>();
		if (Lines.Count == 0 || (Object)(object)component == (Object)null || !((Behaviour)component).isActiveAndEnabled || (Object)(object)component.worldCamera == (Object)null)
		{
			return;
		}
		new Material(Shader.Find("Sprites/Default")).SetPass(0);
		GL.PushMatrix();
		GL.LoadPixelMatrix();
		GL.Begin(1);
		GL.Color(Color.yellow);
		Camera worldCamera = component.worldCamera;
		foreach (Vector3[] line in Lines)
		{
			if (line.Length >= 2)
			{
				Vector3 val = worldCamera.WorldToScreenPoint(line[0]);
				Vector3 val2 = worldCamera.WorldToScreenPoint(line[1]);
				val.y = (float)Screen.height - val.y;
				val2.y = (float)Screen.height - val2.y;
				GL.Vertex3(val.x, val.y, 0f);
				GL.Vertex3(val2.x, val2.y, 0f);
			}
		}
		GL.End();
		GL.PopMatrix();
	}
}
[BepInPlugin("sparroh.preselectbacklog", "PreselectBacklog", "1.0.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class SparrohPlugin : BaseUnityPlugin
{
	public const string PluginGUID = "sparroh.preselectbacklog";

	public const string PluginName = "PreselectBacklog";

	public const string PluginVersion = "1.0.0";

	internal static ManualLogSource Logger;

	public static Dictionary<int, List<int>> PreselectedPaths = new Dictionary<int, List<int>>();

	public static bool PreselectMode = false;

	public static bool DirectiveWindowActive = false;

	private InputAction completeCurrentAction;

	private void Awake()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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)
		Logger = ((BaseUnityPlugin)this).Logger;
		LoadPreselectedPaths();
		Harmony val = new Harmony("sparroh.preselectbacklog");
		val.PatchAll(typeof(DirectivePatches));
		Logger.LogInfo((object)"Patched DirectivePatches");
		val.PatchAll(typeof(DirectiveWindowPatches));
		Logger.LogInfo((object)"Patched DirectiveWindowPatches");
		val.PatchAll(typeof(PlayerDataPatches));
		Logger.LogInfo((object)"Patched PlayerDataPatches");
		Logger.LogInfo((object)"PreselectBacklog loaded successfully. Use OnGUI button in directive window to toggle preselect mode, F2 to complete current directive.");
	}

	private void LoadPreselectedPaths()
	{
		string path = Path.Combine(Paths.ConfigPath, "sparroh.preselectbacklog.txt");
		try
		{
			if (!File.Exists(path))
			{
				return;
			}
			string[] array = File.ReadAllLines(path);
			PreselectedPaths.Clear();
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				string[] array3 = array2[i].Split(new char[1] { ',' });
				if (array3.Length == 2 && int.TryParse(array3[0], out var result) && int.TryParse(array3[1], out var result2))
				{
					if (!PreselectedPaths.ContainsKey(result))
					{
						PreselectedPaths[result] = new List<int>();
					}
					PreselectedPaths[result].Add(result2);
				}
			}
			Logger.LogInfo((object)"Loaded preselected paths from file");
		}
		catch (Exception ex)
		{
			Logger.LogError((object)("Error loading preselected paths: " + ex.Message));
		}
	}

	private void SavePreselectedPaths()
	{
		string path = Path.Combine(Paths.ConfigPath, "sparroh.preselectbacklog.txt");
		try
		{
			Directory.CreateDirectory(Paths.ConfigPath);
			List<string> list = new List<string>();
			foreach (KeyValuePair<int, List<int>> preselectedPath in PreselectedPaths)
			{
				foreach (int item in preselectedPath.Value)
				{
					list.Add($"{preselectedPath.Key},{item}");
				}
			}
			File.WriteAllLines(path, list.ToArray());
			Logger.LogInfo((object)"Saved preselected paths to file");
		}
		catch (Exception ex)
		{
			Logger.LogError((object)("Error saving preselected paths: " + ex.Message));
		}
	}

	private static bool CanBeActivatedPrefix(object __instance, ref bool __result)
	{
		if (PreselectMode)
		{
			__result = true;
			return false;
		}
		int currentDirectivePage = PlayerData.Instance.currentDirectivePage;
		if (PreselectedPaths.TryGetValue(currentDirectivePage, out var value))
		{
			DirectiveInstance[] defaultDirectives = PlayerData.Instance.defaultDirectives;
			int num = -1;
			for (int i = 0; i < defaultDirectives.Length; i++)
			{
				if (defaultDirectives[i] == __instance)
				{
					num = i;
					break;
				}
			}
			if (num != -1 && value.Contains(num))
			{
				Logger.LogInfo((object)$"Allowing activation for preselected directive {num} outside preselect mode");
				__result = true;
				return false;
			}
		}
		return true;
	}

	private void Update()
	{
		DirectiveWindowActive = (Object)(object)Object.FindObjectOfType<DirectiveWindow>() != (Object)null;
		int currentDefaultDirective = PlayerData.Instance.currentDefaultDirective;
		if (currentDefaultDirective < 0 || currentDefaultDirective >= PlayerData.Instance.defaultDirectives.Length)
		{
			return;
		}
		DirectiveInstance val = PlayerData.Instance.defaultDirectives[currentDefaultDirective];
		if (!val.IsComplete || val.HasClaimedRewards)
		{
			return;
		}
		int currentDirectivePage = PlayerData.Instance.currentDirectivePage;
		if (PreselectedPaths.TryGetValue(currentDirectivePage, out var value) && value.Contains(currentDefaultDirective))
		{
			Logger.LogInfo((object)"Auto-claiming completed preselected directive");
			MethodInfo method = ((object)val).GetType().GetMethod("ClaimRewards");
			if (method != null)
			{
				method.Invoke(val, null);
			}
		}
	}

	private void OnGUI()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		if (!DirectiveWindowActive)
		{
			return;
		}
		float num = (float)Screen.height - 60f;
		float num2 = 150f;
		float num3 = 50f;
		string text = (PreselectMode ? "Disable Preselect" : "Enable Preselect");
		if (!GUI.Button(new Rect(10f, num, num2, num3), text))
		{
			return;
		}
		PreselectMode = !PreselectMode;
		Logger.LogInfo((object)$"Preselect mode: {PreselectMode}");
		DirectiveWindow val = Object.FindObjectOfType<DirectiveWindow>();
		if ((Object)(object)val != (Object)null)
		{
			val.SetupDirectives(false);
		}
		if (PreselectMode)
		{
			return;
		}
		int currentDirectivePage = PlayerData.Instance.currentDirectivePage;
		if (PreselectedPaths.TryGetValue(currentDirectivePage, out var value) && value.Count > 0)
		{
			int num4 = value[0];
			if (num4 < PlayerData.Instance.defaultDirectives.Length)
			{
				DirectiveInstance val2 = PlayerData.Instance.defaultDirectives[num4];
				if (val2.CanBeActivated())
				{
					val2.Activate();
					PlayerData.Instance.currentDefaultDirective = num4;
					Logger.LogInfo((object)$"Auto-activated first preselected directive {num4}");
				}
			}
		}
		SavePreselectedPaths();
	}

	private void CompleteCurrentDirective()
	{
		try
		{
			Logger.LogInfo((object)"F2 pressed, attempting to complete current directive");
			int num = PlayerData.Instance.currentDefaultDirective;
			Logger.LogInfo((object)$"Current directive index: {num}");
			if (num == -1)
			{
				DirectiveInstance[] defaultDirectives = PlayerData.Instance.defaultDirectives;
				for (int i = 0; i < defaultDirectives.Length; i++)
				{
					if (defaultDirectives[i] != null && defaultDirectives[i].IsActive)
					{
						num = i;
						Logger.LogInfo((object)$"Found active directive at index {i}");
						break;
					}
				}
				if (num == -1)
				{
					Logger.LogError((object)"No active directive found");
					return;
				}
			}
			DirectiveWindow val = Object.FindObjectOfType<DirectiveWindow>();
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)"DirectiveWindow not found");
				return;
			}
			DirectiveButton[] array = (DirectiveButton[])typeof(DirectiveWindow).GetField("directives", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val);
			if (array == null)
			{
				Logger.LogError((object)"Directives field not found or null");
				return;
			}
			if (num < 0 || num >= array.Length)
			{
				Logger.LogError((object)$"CurrentIdx {num} out of range for directives length {array.Length}");
				return;
			}
			DirectiveButton obj = array[num];
			DirectiveInstance val2 = PlayerData.Instance.defaultDirectives[num];
			try
			{
				Logger.LogInfo((object)("Directive type: " + ((object)val2).GetType().FullName));
				Logger.LogInfo((object)"F2: Calling CompleteAllProperties to force completion");
				MethodInfo method = ((object)val2).GetType().GetMethod("CompleteAllProperties", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					method.Invoke(val2, new object[0]);
					Logger.LogInfo((object)"F2: CompleteAllProperties called successfully");
				}
				else
				{
					Logger.LogError((object)"CompleteAllProperties method not found");
				}
				FieldInfo[] fields = ((object)val2).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				foreach (FieldInfo fieldInfo in fields)
				{
					Logger.LogInfo((object)("Directive field: " + fieldInfo.Name + " " + fieldInfo.FieldType.Name));
				}
				PropertyInfo[] properties = ((object)val2).GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				foreach (PropertyInfo propertyInfo in properties)
				{
					Logger.LogInfo((object)("Directive property: " + propertyInfo.Name + " " + propertyInfo.PropertyType.Name));
				}
				foreach (MethodInfo item in from m in ((object)val2).GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy)
					where m.Name.Contains("Complete") || m.Name.Contains("Progress") || m.Name.Contains("Is") || m.Name.Contains("Update") || m.IsPublic
					select m)
				{
					Logger.LogInfo((object)("Directive method: " + item.Name + " " + item.ReturnType.Name));
				}
				FieldInfo[] fields2 = ((object)val2).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				List<FieldInfo> list = new List<FieldInfo>();
				fields = fields2;
				foreach (FieldInfo fieldInfo2 in fields)
				{
					if (fieldInfo2.FieldType.IsEnum)
					{
						list.Add(fieldInfo2);
					}
				}
				foreach (FieldInfo item2 in list)
				{
					Logger.LogInfo((object)("Enum field: " + item2.Name + " " + item2.FieldType.Name));
					try
					{
						foreach (object enumValue in item2.FieldType.GetEnumValues())
						{
							if (enumValue.ToString() == "Completed")
							{
								item2.SetValue(val2, enumValue);
								Logger.LogInfo((object)("Set " + item2.Name + " to Completed"));
								break;
							}
							if (enumValue.ToString() == "Claimed")
							{
								item2.SetValue(val2, enumValue);
								Logger.LogInfo((object)("Set " + item2.Name + " to Claimed"));
								break;
							}
						}
					}
					catch (Exception ex)
					{
						Logger.LogWarning((object)("Failed to set enum field " + item2.Name + ": " + ex.Message));
					}
				}
				FieldInfo field = ((object)val2).GetType().GetField("<IsComplete>k__BackingField", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				if (field != null)
				{
					field.SetValue(val2, true);
					Logger.LogInfo((object)"Set <IsComplete>k__BackingField to true");
				}
				else
				{
					PropertyInfo property = ((object)val2).GetType().GetProperty("IsComplete", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
					if (property != null && property.CanWrite)
					{
						property.SetValue(val2, true);
						Logger.LogInfo((object)"Set IsComplete to true");
					}
					else
					{
						Logger.LogInfo((object)"IsComplete cannot be set");
					}
				}
				FieldInfo field2 = ((object)val2).GetType().GetField("isActive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				if (field2 != null)
				{
					field2.SetValue(val2, true);
					Logger.LogInfo((object)"Set directive isActive to True");
				}
				FieldInfo field3 = ((object)val2).GetType().GetField("hasClaimedRewards", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				if (field3 != null)
				{
					field3.SetValue(val2, false);
					Logger.LogInfo((object)"Set directive hasClaimedRewards to False");
				}
				FieldInfo field4 = ((object)val2).GetType().GetField("properties", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				if (field4 != null && field4.GetValue(val2) is IList list2)
				{
					for (int k = 0; k < list2.Count; k++)
					{
						object obj2 = list2[k];
						if (obj2 != null)
						{
							Logger.LogInfo((object)$"Property {k} type: {obj2.GetType().FullName}");
							fields = obj2.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
							foreach (FieldInfo fieldInfo3 in fields)
							{
								Logger.LogInfo((object)$"Property {k} field: {fieldInfo3.Name} {fieldInfo3.FieldType.Name}");
							}
							properties = obj2.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
							foreach (PropertyInfo propertyInfo2 in properties)
							{
								Logger.LogInfo((object)$"Property {k} property: {propertyInfo2.Name} {propertyInfo2.PropertyType.Name}");
							}
							foreach (MethodInfo item3 in from m in obj2.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy)
								where m.Name.Contains("Complete") || m.Name.Contains("Progress") || m.Name.Contains("Value") || m.Name.Contains("Update") || m.Name.Contains("Is") || m.IsPublic
								select m)
							{
								Logger.LogInfo((object)$"Property {k} method: {item3.Name} {item3.ReturnType.Name}");
							}
						}
						FieldInfo field5 = obj2.GetType().GetField("progress", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
						if (field5 != null)
						{
							if (field5.FieldType == typeof(float))
							{
								field5.SetValue(obj2, 1f);
							}
							else if (field5.FieldType == typeof(int))
							{
								field5.SetValue(obj2, 100);
							}
							Logger.LogInfo((object)$"Set progress to max for objective {k}");
							continue;
						}
						FieldInfo field6 = obj2.GetType().GetField("currentProgress", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
						if (field6 != null)
						{
							if (field6.FieldType == typeof(float))
							{
								field6.SetValue(obj2, 1f);
							}
							else if (field6.FieldType == typeof(int))
							{
								field6.SetValue(obj2, 100);
							}
							Logger.LogInfo((object)$"Set currentProgress to max for objective {k}");
						}
					}
				}
			}
			catch (Exception ex2)
			{
				Logger.LogError((object)("Error setting directive status: " + ex2.Message));
			}
			MethodInfo method2 = typeof(DirectiveButton).GetMethod("ClaimRewards", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method2 == null)
			{
				Logger.LogError((object)"ClaimRewards method not found on DirectiveButton");
				return;
			}
			Logger.LogInfo((object)"F2: Deactivating directive before claiming");
			MethodInfo method3 = ((object)val2).GetType().GetMethod("Deactivate", BindingFlags.Instance | BindingFlags.Public);
			if (method3 != null)
			{
				method3.Invoke(val2, new object[0]);
				Logger.LogInfo((object)"F2: Directive deactivated");
			}
			Logger.LogInfo((object)"F2: Invoking ClaimRewards");
			method2.Invoke(obj, null);
			Logger.LogInfo((object)"F2: ClaimRewards invoked");
			Logger.LogInfo((object)"F2: Re-activating directive");
			MethodInfo method4 = ((object)val2).GetType().GetMethod("Activate", BindingFlags.Instance | BindingFlags.Public);
			if (method4 != null)
			{
				method4.Invoke(val2, new object[0]);
				Logger.LogInfo((object)"F2: Directive re-activated");
			}
			Logger.LogInfo((object)"F2: Final deactivate after claim");
			if (method3 != null)
			{
				method3.Invoke(val2, new object[0]);
				Logger.LogInfo((object)"F2: Directive final deactivated");
			}
			Logger.LogInfo((object)"F2: Completed current directive");
		}
		catch (Exception ex3)
		{
			Logger.LogError((object)("Error completing current directive: " + ex3.Message));
		}
	}
}
[HarmonyPatch]
public static class PlayerDataPatches
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerData), "GetCurrrentDirectiveTier")]
	public static void GetCurrrentDirectiveTierPostfix(ref int __result)
	{
		SparrohPlugin.Logger.LogInfo((object)$"GetCurrrentDirectiveTier called, original result: {__result}, PreselectMode: {SparrohPlugin.PreselectMode}");
		if (SparrohPlugin.PreselectMode)
		{
			__result = 99;
			SparrohPlugin.Logger.LogInfo((object)"Forced return to 99");
		}
	}
}
[HarmonyPatch]
public static class DirectiveWindowPatches
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(DirectiveWindow), "SetupDirectives")]
	public static void SetupDirectivesPostfix(DirectiveWindow __instance, bool animate)
	{
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		SparrohPlugin.Logger.LogInfo((object)"SetupDirectivesPostfix running");
		int currentDirectivePage = PlayerData.Instance.currentDirectivePage;
		Canvas componentInParent = ((Component)__instance).GetComponentInParent<Canvas>();
		PathLineDrawer pathLineDrawer = ((Component)componentInParent).GetComponent<PathLineDrawer>();
		if ((Object)(object)pathLineDrawer == (Object)null)
		{
			pathLineDrawer = ((Component)componentInParent).gameObject.AddComponent<PathLineDrawer>();
		}
		pathLineDrawer.Lines.Clear();
		if (!SparrohPlugin.PreselectedPaths.TryGetValue(currentDirectivePage, out var value))
		{
			return;
		}
		List<int> list = value.OrderBy((int idx) => PlayerData.Instance.defaultDirectives[idx].Tier).ToList();
		DirectiveButton[] array = (DirectiveButton[])typeof(DirectiveWindow).GetField("directives", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance);
		if (array == null)
		{
			return;
		}
		if (SparrohPlugin.PreselectMode)
		{
			foreach (int item in list)
			{
				if (item < array.Length)
				{
					PolygonOutline component = ((Component)array[item]).GetComponent<PolygonOutline>();
					if ((Object)(object)component != (Object)null)
					{
						((OutlineGraphic)component).SetValue(12f);
						((Graphic)component).color = Color.yellow;
					}
				}
			}
		}
		for (int i = 0; i < list.Count - 1; i++)
		{
			int num = list[i];
			int num2 = list[i + 1];
			if (num < array.Length && num2 < array.Length)
			{
				Vector3 position = ((Component)array[num]).transform.position;
				Vector3 position2 = ((Component)array[num2]).transform.position;
				SparrohPlugin.Logger.LogInfo((object)$"Canvas scale: {((Component)componentInParent).transform.lossyScale}, renderMode: {componentInParent.renderMode}, Creating line from {position} to {position2}");
				pathLineDrawer.Lines.Add((Vector3[])(object)new Vector3[2] { position, position2 });
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(DirectiveWindow), "OnOpen")]
	public static void OnOpenPostfix(DirectiveWindow __instance)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		try
		{
			DirectiveInstance[] defaultDirectives = PlayerData.Instance.defaultDirectives;
			if (defaultDirectives.Length != 0)
			{
				MethodInfo method = ((object)defaultDirectives[0]).GetType().GetMethod("CanBeActivated");
				if (method != null)
				{
					new Harmony("sparroh.preselectbacklog.dynamic").Patch((MethodBase)method, new HarmonyMethod(typeof(SparrohPlugin).GetMethod("CanBeActivatedPrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					SparrohPlugin.Logger.LogInfo((object)"Dynamically patched CanBeActivated");
				}
			}
		}
		catch (Exception ex)
		{
			SparrohPlugin.Logger.LogError((object)("Failed to patch CanBeActivated: " + ex.Message));
		}
	}
}
[HarmonyPatch]
public static class DirectivePatches
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(DirectiveButton), "ClaimRewards")]
	public static void OnClaimRewards(DirectiveButton __instance)
	{
		SparrohPlugin.Logger.LogInfo((object)"OnClaimRewards called");
		FieldInfo field = typeof(DirectiveButton).GetField("directive", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null)
		{
			return;
		}
		object value = field.GetValue(__instance);
		if (value == null)
		{
			return;
		}
		int currentDirectivePage = PlayerData.Instance.currentDirectivePage;
		SparrohPlugin.Logger.LogInfo((object)$"OnClaimRewards for page {currentDirectivePage}");
		if (!SparrohPlugin.PreselectedPaths.TryGetValue(currentDirectivePage, out var value2))
		{
			return;
		}
		DirectiveInstance[] defaultDirectives = PlayerData.Instance.defaultDirectives;
		int num = -1;
		for (int i = 0; i < defaultDirectives.Length; i++)
		{
			if (defaultDirectives[i] == value)
			{
				num = i;
				break;
			}
		}
		SparrohPlugin.Logger.LogInfo((object)string.Format("Current directive idx: {0}, in path: {1}", num, value2.Contains(num) ? "yes" : "no"));
		if (num == -1 || !value2.Contains(num))
		{
			return;
		}
		int num2 = value2.IndexOf(num) + 1;
		if (num2 >= value2.Count)
		{
			return;
		}
		int num3 = value2[num2];
		SparrohPlugin.Logger.LogInfo((object)$"Next directive idx: {num3}");
		if (num3 >= defaultDirectives.Length)
		{
			return;
		}
		DirectiveInstance val = defaultDirectives[num3];
		SparrohPlugin.Logger.LogInfo((object)"Calling activate on next directive");
		if (val.CanBeActivated())
		{
			val.Activate();
			if (val.IsDefault())
			{
				PlayerData.Instance.currentDefaultDirective = num3;
			}
			((Component)__instance).GetComponentInParent<DirectiveWindow>().SetupDirectives(true);
			SparrohPlugin.Logger.LogInfo((object)$"Auto-activated directive {num3}");
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(DirectiveButton), "ActivateDirective")]
	public static bool ActivateDirectivePrefix(DirectiveButton __instance)
	{
		if (SparrohPlugin.PreselectMode)
		{
			SparrohPlugin.Logger.LogInfo((object)"ActivateDirectivePrefix called in preselect mode");
			FieldInfo field = typeof(DirectiveButton).GetField("directive", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				return true;
			}
			object value = field.GetValue(__instance);
			if (value == null)
			{
				return true;
			}
			SparrohPlugin.Logger.LogInfo((object)("Directive type in activate: " + value.GetType().FullName));
			PropertyInfo property = value.GetType().GetProperty("Tier");
			if (property == null)
			{
				SparrohPlugin.Logger.LogError((object)"Tier property not found on directive");
				return false;
			}
			int num = (int)property.GetValue(value);
			int currentDirectivePage = PlayerData.Instance.currentDirectivePage;
			if (!SparrohPlugin.PreselectedPaths.ContainsKey(currentDirectivePage))
			{
				SparrohPlugin.PreselectedPaths[currentDirectivePage] = new List<int>();
			}
			List<int> list = SparrohPlugin.PreselectedPaths[currentDirectivePage];
			List<int> list2 = new List<int>();
			foreach (int item in list)
			{
				DirectiveInstance val = PlayerData.Instance.defaultDirectives[item];
				if (val != null)
				{
					PropertyInfo property2 = ((object)val).GetType().GetProperty("Tier");
					if (property2 == null)
					{
						SparrohPlugin.Logger.LogWarning((object)$"Tier property not found on directive {item}");
					}
					else if ((int)property2.GetValue(val) == num)
					{
						list2.Add(item);
					}
				}
			}
			foreach (int item2 in list2)
			{
				list.Remove(item2);
				SparrohPlugin.Logger.LogInfo((object)$"Removed directive {item2} from path (same tier {num})");
			}
			DirectiveInstance[] defaultDirectives = PlayerData.Instance.defaultDirectives;
			for (int i = 0; i < defaultDirectives.Length; i++)
			{
				if (defaultDirectives[i] != value)
				{
					continue;
				}
				if (list.Contains(i))
				{
					break;
				}
				list.Add(i);
				list = list.OrderBy(delegate(int idx)
				{
					DirectiveInstance val2 = PlayerData.Instance.defaultDirectives[idx];
					if (val2 == null)
					{
						return 999;
					}
					PropertyInfo property3 = ((object)val2).GetType().GetProperty("Tier");
					return (property3 == null) ? 999 : ((int)property3.GetValue(val2));
				}).ToList();
				((Component)__instance).GetComponentInParent<DirectiveWindow>().SetupDirectives(true);
				SparrohPlugin.Logger.LogInfo((object)$"Added directive {i} (tier {num}) to preselected path for page {currentDirectivePage}");
				break;
			}
			return false;
		}
		return true;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(DirectiveButton), "Setup")]
	public static void DirectiveButtonSetupPostfix(DirectiveButton __instance, object directive, bool isAnyActive, bool isWaitingToClaim)
	{
		SparrohPlugin.Logger.LogInfo((object)"DirectiveButtonSetupPostfix running");
		if (SparrohPlugin.PreselectMode)
		{
			MethodInfo method = typeof(DirectiveButton).GetMethod("SetupAvailable", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method != null)
			{
				method.Invoke(__instance, null);
			}
			SparrohPlugin.Logger.LogInfo((object)"Forced directive to available state");
		}
	}
}
[CompilerGenerated]
[ExcludeFromCodeCoverage]
internal static class GitVersionInformation
{
	public const string AssemblySemFileVer = "0.0.1.0";

	public const string AssemblySemVer = "0.0.1.0";

	public const string BranchName = "master";

	public const string BuildMetaData = "";

	public const string CommitDate = "2025-12-19";

	public const string CommitsSinceVersionSource = "4";

	public const string EscapedBranchName = "master";

	public const string FullBuildMetaData = "Branch.master.Sha.0c134903a1c9b4aec30b68e21f6275961508b5bd";

	public const string FullSemVer = "0.0.1-4";

	public const string InformationalVersion = "0.0.1-4+Branch.master.Sha.0c134903a1c9b4aec30b68e21f6275961508b5bd";

	public const string Major = "0";

	public const string MajorMinorPatch = "0.0.1";

	public const string Minor = "0";

	public const string Patch = "1";

	public const string PreReleaseLabel = "";

	public const string PreReleaseLabelWithDash = "";

	public const string PreReleaseNumber = "4";

	public const string PreReleaseTag = "4";

	public const string PreReleaseTagWithDash = "-4";

	public const string SemVer = "0.0.1-4";

	public const string Sha = "0c134903a1c9b4aec30b68e21f6275961508b5bd";

	public const string ShortSha = "0c13490";

	public const string UncommittedChanges = "10";

	public const string VersionSourceSha = "";

	public const string WeightedPreReleaseNumber = "55004";
}
namespace PreselectBacklog
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PreselectBacklog";

		public const string PLUGIN_NAME = "PreselectBacklog";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}