Decompiled source of UCustomPrefabs Fixes v1.0.0

UCustomPrefabs_Fixes.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("UCustomPrefabs Fixes")]
[assembly: AssemblyProduct("UCustomPrefabs Fixes")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 Kilian.PeakCompatibilityFixes
{
	[BepInPlugin("kilian.peak.compatibilityfixes", "UCustomPrefabs Fixes", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private static GameObject compatibleBookmarkPrefab;

		private static readonly Dictionary<string, Texture> passportTextures = new Dictionary<string, Texture>();

		private static readonly Dictionary<string, string> passportIconNames = new Dictionary<string, string>
		{
			{ "get_EmptyIcon", "Empty" },
			{ "get_NoPreferenceIcon", "NoPreferenceIcon" },
			{ "get_CustomCharacterIcon", "CustomCharacterPassportIcon" },
			{ "get_CustomSkeletonIcon", "CustomSkeletonPassportIcon" },
			{ "get_CustomChickenIcon", "CustomChickenPassportIcon" }
		};

		private static Button restoredBookmark;

		private static PassportManager bookmarkOwner;

		public const string Id = "kilian.peak.compatibilityfixes";

		internal static ManualLogSource Log;

		private Harmony harmony;

		internal static Type Helper;

		internal static Type ConfigHelper;

		internal static MethodInfo IsSpecial;

		internal static MethodInfo SwitchTab;

		private static bool reportedRuntimeError;

		private bool RestorePassportAssets()
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0176: Expected O, but got Unknown
			//IL_0187: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Expected O, but got Unknown
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			try
			{
				object? value = AccessTools.Property(Helper, "CustomBookmarkPrefab").GetValue(null, null);
				if (Object.op_Implicit((Object)((value is GameObject) ? value : null)))
				{
					Log.LogInfo((object)"Original passport assets already readable; keeping original bundle.");
					return true;
				}
				string[] array = new string[7] { "BookmarkBlue", "BookmarkRed", "Empty", "NoPreferenceIcon", "CustomCharacterPassportIcon", "CustomSkeletonPassportIcon", "CustomChickenPassportIcon" };
				foreach (string text in array)
				{
					passportTextures.Add(text, (Texture)(object)LoadOriginalTexture(text));
				}
				GameObject val = new GameObject("Alpha_OriginalPassportAssets");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
				GameObject val2 = new GameObject("BookmarkButton", new Type[3]
				{
					typeof(RectTransform),
					typeof(CanvasRenderer),
					typeof(Button)
				})
				{
					layer = 5
				};
				RectTransform val3 = (RectTransform)val2.transform;
				((Transform)val3).SetParent(val.transform, false);
				Vector2 anchorMin = (val3.anchorMax = new Vector2(0.5f, 0.5f));
				val3.anchorMin = anchorMin;
				val3.pivot = new Vector2(0f, 0.5f);
				val3.sizeDelta = new Vector2(59.1f, 59.1f);
				val3.anchoredPosition = Vector2.zero;
				CreateOriginalImage(val3, "RawImage_Blue", "BookmarkBlue", active: false);
				RawImage targetGraphic = CreateOriginalImage(val3, "RawImage_Red", "BookmarkRed", active: true);
				Button component = val2.GetComponent<Button>();
				((Selectable)component).targetGraphic = (Graphic)(object)targetGraphic;
				((Selectable)component).interactable = true;
				compatibleBookmarkPrefab = val2;
				harmony.Patch((MethodBase)AccessTools.PropertyGetter(Helper, "CustomBookmarkPrefab"), new HarmonyMethod(AccessTools.Method(typeof(Plugin), "OriginalBookmarkPrefabPrefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				foreach (string key in passportIconNames.Keys)
				{
					harmony.Patch((MethodBase)AccessTools.Method(Helper, key, (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(Plugin), "OriginalPassportIconPrefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				object? value2 = AccessTools.Property(Helper, "CustomBookmarkPrefab").GetValue(null, null);
				if (!Object.op_Implicit((Object)((value2 is GameObject) ? value2 : null)))
				{
					throw new InvalidOperationException("Patched original prefab getter returned null.");
				}
				Log.LogInfo((object)"Original passport resource rebuilt with current Unity components: 3 original objects, 7 original textures; API prefab lookup verified.");
				return true;
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Original passport resource rebuild failed: " + ex));
				return false;
			}
		}

		private static Texture2D LoadOriginalTexture(string name)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			string text = "Alpha.OriginalPassport." + name + ".png";
			using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				throw new InvalidOperationException("Missing original texture: " + text);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, memoryStream.ToArray(), false))
			{
				throw new InvalidOperationException("Cannot decode original texture: " + name);
			}
			((Object)val).name = name;
			((Object)val).hideFlags = (HideFlags)32;
			return val;
		}

		private static RawImage CreateOriginalImage(RectTransform parent, string name, string texture, bool active)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_004f: 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)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(RawImage)
			});
			val.layer = 5;
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)parent, false);
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.sizeDelta = Vector2.zero;
			val2.anchoredPosition = Vector2.zero;
			RawImage component = val.GetComponent<RawImage>();
			component.texture = passportTextures[texture];
			((Graphic)component).color = Color.white;
			((Graphic)component).raycastTarget = true;
			val.SetActive(active);
			return component;
		}

		private static bool OriginalBookmarkPrefabPrefix(ref GameObject __result)
		{
			__result = compatibleBookmarkPrefab;
			return false;
		}

		private static bool OriginalPassportIconPrefix(MethodBase __originalMethod, ref Texture __result)
		{
			__result = passportTextures[passportIconNames[__originalMethod.Name]];
			return false;
		}

		private static void EnsureOriginalBookmark(PassportManager manager)
		{
			//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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Expected O, but got Unknown
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Expected O, but got Unknown
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)restoredBookmark) && (Object)(object)bookmarkOwner == (Object)(object)manager)
			{
				return;
			}
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(Helper, "BookmarkButton");
				object? value = fieldInfo.GetValue(null);
				Button val = (Button)((value is Button) ? value : null);
				Transform parent = ((Component)manager.tabs[0]).transform.parent.parent.parent.parent;
				RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if (!Object.op_Implicit((Object)(object)val2))
				{
					throw new InvalidOperationException("Cannot locate native passport page.");
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					Button[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Button>(true);
					foreach (Button val3 in componentsInChildren)
					{
						if (((Object)val3).name.StartsWith("BookmarkButton", StringComparison.Ordinal))
						{
							val = val3;
							break;
						}
					}
					if (!Object.op_Implicit((Object)(object)val))
					{
						object? value2 = AccessTools.Property(Helper, "CustomBookmarkPrefab").GetValue(null, null);
						object? obj = ((value2 is GameObject) ? value2 : null);
						if (!Object.op_Implicit((Object)obj))
						{
							throw new InvalidOperationException("Original BookmarkButton prefab is unavailable.");
						}
						val = Object.Instantiate<GameObject>((GameObject)obj, (Transform)(object)val2, false).GetComponent<Button>();
						if (!Object.op_Implicit((Object)(object)val))
						{
							throw new InvalidOperationException("Original bookmark has no Button component.");
						}
						Log.LogInfo((object)"Recovered original BookmarkButton prefab from UCustomPrefabsAPI.");
					}
					fieldInfo.SetValue(null, val);
				}
				Transform transform = ((Component)val).transform;
				RectTransform val4 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				((Transform)val4).SetParent((Transform)(object)val2, false);
				Vector2 anchorMin = (val4.anchorMax = new Vector2(1f, 0.66f));
				val4.anchorMin = anchorMin;
				val4.pivot = new Vector2(0f, 0.5f);
				val4.anchoredPosition = new Vector2(-40f, 0f);
				((Transform)val4).localScale = Vector3.one;
				((Transform)val4).localRotation = Quaternion.identity;
				((Component)val).gameObject.SetActive(true);
				((Behaviour)val).enabled = true;
				((Selectable)val).interactable = true;
				Graphic[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Graphic>(true);
				foreach (Graphic obj2 in componentsInChildren2)
				{
					((Component)obj2).gameObject.layer = ((Component)val2).gameObject.layer;
					((Behaviour)obj2).enabled = true;
					obj2.color = Color.white;
					obj2.material = null;
					obj2.raycastTarget = true;
				}
				((Component)val).gameObject.layer = ((Component)val2).gameObject.layer;
				val.onClick = new ButtonClickedEvent();
				((UnityEvent)val.onClick).AddListener((UnityAction)delegate
				{
					HandleOriginalBookmarkClick(manager);
				});
				((Transform)val4).SetAsLastSibling();
				Transform val6 = ((Transform)val4).Find("RawImage_Red");
				Transform val7 = ((Transform)val4).Find("RawImage_Blue");
				RawImage val8 = (Object.op_Implicit((Object)(object)val6) ? ((Component)val6).GetComponent<RawImage>() : null);
				RawImage val9 = (Object.op_Implicit((Object)(object)val7) ? ((Component)val7).GetComponent<RawImage>() : null);
				Log.LogInfo((object)("Original bookmark graphics: red=" + ((Object.op_Implicit((Object)(object)val8) && Object.op_Implicit((Object)(object)val8.texture)) ? ((Object)val8.texture).name : "MISSING") + "; blue=" + ((Object.op_Implicit((Object)(object)val9) && Object.op_Implicit((Object)(object)val9.texture)) ? ((Object)val9.texture).name : "MISSING")));
				restoredBookmark = val;
				bookmarkOwner = manager;
				Canvas componentInParent = ((Component)val2).GetComponentInParent<Canvas>();
				ManualLogSource log = Log;
				string[] obj3 = new string[12]
				{
					"Original bookmark restored: parent=",
					((Object)val2).name,
					"; canvas=",
					Object.op_Implicit((Object)(object)componentInParent) ? ((Object)componentInParent).name : "MISSING",
					"; rect=",
					null,
					null,
					null,
					null,
					null,
					null,
					null
				};
				Rect rect = val4.rect;
				obj3[5] = ((object)((Rect)(ref rect)).size/*cast due to .constrained prefix*/).ToString();
				obj3[6] = "; anchor=";
				obj3[7] = ((object)val4.anchorMin/*cast due to .constrained prefix*/).ToString();
				obj3[8] = "; active=";
				obj3[9] = ((Component)val).gameObject.activeInHierarchy.ToString();
				obj3[10] = "; layer=";
				obj3[11] = ((Component)val).gameObject.layer.ToString();
				log.LogInfo((object)string.Concat(obj3));
			}
			catch (Exception ex)
			{
				restoredBookmark = null;
				bookmarkOwner = null;
				Log.LogError((object)("Failed to restore original passport bookmark: " + ex));
			}
		}

		private static void UpdateOriginalBookmark(bool custom)
		{
			if (Object.op_Implicit((Object)(object)restoredBookmark))
			{
				Transform val = ((Component)restoredBookmark).transform.Find("RawImage_Blue");
				Transform val2 = ((Component)restoredBookmark).transform.Find("RawImage_Red");
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
				{
					Log.LogError((object)"Original bookmark is missing its red or blue graphic.");
					return;
				}
				((Component)val).gameObject.SetActive(custom);
				((Component)val2).gameObject.SetActive(!custom);
				((Selectable)restoredBookmark).targetGraphic = (Graphic)(object)((Component)(custom ? val : val2)).GetComponent<RawImage>();
				((Component)restoredBookmark).gameObject.SetActive(true);
			}
		}

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("kilian.peak.compatibilityfixes");
			if (AccessTools.Method(typeof(PlayerCustomizationDummy), "UpdateDummy", new Type[1] { typeof(Player) }, (Type[])null) == null || AccessTools.Method(typeof(PassportManager), "SetActiveButton", new Type[1] { typeof(bool) }, (Type[])null) == null)
			{
				Log.LogError((object)"Unsupported passport API: no changes applied.");
				return;
			}
			DisableLegacyPagination();
			Helper = AccessTools.TypeByName("UCustomPrefabsAPI.Peak.Utils.PassportHelper");
			ConfigHelper = AccessTools.TypeByName("UCustomPrefabsAPI.PhotonUtils.Networking.PlayerConfigHelper");
			Type type = AccessTools.TypeByName("UCustomPrefabsAPI.Peak.PassportPatch");
			if (Helper == null || ConfigHelper == null || type == null)
			{
				Log.LogInfo((object)"UCustomPrefabsAPI.Peak not loaded: model bridge not needed.");
				return;
			}
			RestorePassportAssets();
			IsSpecial = AccessTools.Method(Helper, "IsSpecialCustomization", (Type[])null, (Type[])null);
			SwitchTab = AccessTools.Method(Helper, "SwitchToCustomTab", (Type[])null, (Type[])null);
			if (IsSpecial == null || SwitchTab == null)
			{
				Log.LogError((object)"Unknown custom model API: model bridge not installed.");
				return;
			}
			Replace(type, "OpenTab_Prefix_Patch", "OpenTab", new Type[1] { typeof(Type) }, "OpenTabPrefix");
			Replace(type, "SetOption_Prefix_Patch", "SetOption", new Type[2]
			{
				typeof(CustomizationOption),
				typeof(int)
			}, "SetOptionPrefix");
			Replace(type, "SetActiveButton_Prefix_Patch", "SetActiveButton", new Type[1] { typeof(bool) }, "SetActiveButtonPrefix");
			harmony.Patch((MethodBase)AccessTools.Method(typeof(PassportManager), "SetButtons", new Type[1] { typeof(bool) }, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(Plugin), "SetButtonsPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Log.LogInfo((object)"Passport model bridge installed. UpdateDummy(player) and selected model paging supported.");
		}

		private void Replace(Type patchType, string oldName, string targetName, Type[] args, string newName)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(PassportManager), targetName, args, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(patchType, oldName, (Type[])null, (Type[])null);
			MethodInfo methodInfo3 = AccessTools.Method(typeof(Plugin), newName, (Type[])null, (Type[])null);
			if (methodInfo == null || methodInfo2 == null || methodInfo3 == null)
			{
				throw new MissingMethodException("Cannot safely replace " + targetName);
			}
			harmony.Unpatch((MethodBase)methodInfo, methodInfo2);
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo3), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Log.LogInfo((object)("Replaced UCustomPrefabsAPI passport prefix: " + targetName));
		}

		private void DisableLegacyPagination()
		{
			if (AccessTools.Method(typeof(PassportManager), "PageNext", (Type[])null, (Type[])null) == null || AccessTools.Method(typeof(PassportManager), "PagePrev", (Type[])null, (Type[])null) == null)
			{
				return;
			}
			int num = 0;
			string[] array = new string[2] { "Awake", "OpenTab" };
			foreach (string text in array)
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(PassportManager), text, (Type[])null, (Type[])null);
				Patches patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo);
				if (patchInfo == null)
				{
					continue;
				}
				foreach (Patch postfix in patchInfo.Postfixes)
				{
					if (!(postfix.PatchMethod.DeclaringType.Assembly.GetName().Name != "PassportPagination"))
					{
						harmony.Unpatch((MethodBase)methodInfo, postfix.PatchMethod);
						num++;
					}
				}
			}
			Log.LogInfo((object)("Legacy PassportPagination hooks removed: " + num + "; using native PEAK pagination."));
		}

		private static bool Special(Type type, out int kind)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[2] { type, null };
			bool result = (bool)IsSpecial.Invoke(null, array);
			kind = ((array[1] != null) ? Convert.ToInt32(array[1]) : 0);
			return result;
		}

		private static object Read(object obj, string name)
		{
			if (obj == null)
			{
				return null;
			}
			FieldInfo fieldInfo = AccessTools.Field(obj.GetType(), name);
			if (fieldInfo != null)
			{
				return fieldInfo.GetValue(obj);
			}
			PropertyInfo propertyInfo = AccessTools.Property(obj.GetType(), name);
			if (!(propertyInfo == null))
			{
				return propertyInfo.GetValue(obj, null);
			}
			return null;
		}

		private static string SelectedTemplate(int kind)
		{
			MethodInfo methodInfo = AccessTools.Method(ConfigHelper, "TryGetConfigHandler", new Type[2]
			{
				typeof(Character),
				ConfigHelper.MakeByRefType()
			}, (Type[])null);
			if (methodInfo == null || !Object.op_Implicit((Object)(object)Character.localCharacter))
			{
				return "";
			}
			object[] array = new object[2]
			{
				Character.localCharacter,
				null
			};
			if (!(bool)methodInfo.Invoke(null, array) || array[1] == null)
			{
				return "";
			}
			return (Read(array[1], kind switch
			{
				1 => "CurrentSkeletonTemplate", 
				0 => "CurrentCharacterTemplate", 
				_ => "CurrentChickenTemplate", 
			}) as string) ?? "";
		}

		private static void Report(Exception ex)
		{
			if (!reportedRuntimeError)
			{
				reportedRuntimeError = true;
				Log.LogError((object)("Passport bridge failed; please send this LogOutput.log: " + ex));
			}
		}

		private static bool OpenTabPrefix(PassportManager __instance, Type __0)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_004f: 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)
			int kind;
			bool flag = Special(__0, out kind);
			try
			{
				SwitchTab.Invoke(null, new object[1] { __0 });
			}
			catch (Exception ex)
			{
				Report(ex);
				if (!flag)
				{
					return true;
				}
				return false;
			}
			EnsureOriginalBookmark(__instance);
			UpdateOriginalBookmark(flag);
			if (!flag)
			{
				return true;
			}
			__instance.activeType = __0;
			AccessTools.Method(typeof(PassportManager), "CameraOut", (Type[])null, (Type[])null).Invoke(__instance, null);
			__instance.SetButtons(true);
			__instance.dummy.UpdateDummy((Player)null);
			Log.LogInfo((object)("Original model page opened: kind=" + kind + "; options=" + Singleton<Customization>.Instance.GetList(__0).Length));
			return false;
		}

		private static void HandleOriginalBookmarkClick(PassportManager manager)
		{
			try
			{
				Log.LogInfo((object)"Original passport bookmark clicked.");
				AccessTools.Method(Helper, "TogglePassportBookmark", (Type[])null, (Type[])null).Invoke(null, null);
			}
			catch (Exception ex)
			{
				Report(ex);
			}
		}

		private static bool SetOptionPrefix(PassportManager __instance, CustomizationOption __0)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)__0))
			{
				return true;
			}
			if (!Special(__0.type, out var kind))
			{
				return true;
			}
			object obj = Read(__0, "TemplateID");
			if (!(obj is string))
			{
				return true;
			}
			try
			{
				string text = kind switch
				{
					1 => "SetSkeletonTemplate", 
					0 => "SetCharacterTemplate", 
					_ => "SetChickenTemplate", 
				};
				AccessTools.Method(ConfigHelper, text, (Type[])null, (Type[])null).Invoke(null, new object[1] { obj });
				AccessTools.Method(typeof(PassportManager), "SetActiveButton", new Type[1] { typeof(bool) }, (Type[])null).Invoke(__instance, new object[1] { false });
				__instance.dummy.UpdateDummy((Player)null);
				Log.LogInfo((object)("Original model selection applied: " + obj));
			}
			catch (Exception ex)
			{
				Report(ex);
			}
			return false;
		}

		private static void SetButtonsPostfix(PassportManager __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (Special(__instance.activeType, out var _))
			{
				int __result = 0;
				SetActiveButtonPrefix(__instance, __0: false, ref __result);
			}
		}

		private static bool SetActiveButtonPrefix(PassportManager __instance, bool __0, ref int __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if (!Special(__instance.activeType, out var kind))
			{
				return true;
			}
			try
			{
				string b = SelectedTemplate(kind);
				CustomizationOption[] list = Singleton<Customization>.Instance.GetList(__instance.activeType);
				int num = 0;
				string value = "";
				for (int i = 0; i < list.Length; i++)
				{
					if (Object.op_Implicit((Object)(object)list[i]) && string.Equals((Read(list[i], "TemplateID") as string) ?? "", b, StringComparison.Ordinal))
					{
						num = i;
						value = (Read(list[i], "DisplayName") as string) ?? "";
						break;
					}
				}
				__result = num;
				int num2 = (int)Read(__instance, "buttonsPerPage");
				int num3 = ((__0 && num2 > 0) ? (num / num2) : ((int)Read(__instance, "page")));
				PassportButton[] buttons = __instance.buttons;
				foreach (PassportButton val in buttons)
				{
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.border))
					{
						int num4 = Convert.ToInt32(Read(val, "currentIndex") ?? ((object)(-1)));
						((Graphic)val.border).color = ((num4 == num && num4 >= num3 * num2 && num4 < (num3 + 1) * num2) ? __instance.activeBorderColor : __instance.inactiveBorderColor);
					}
				}
				object value2 = AccessTools.Field(Helper, "Custom_Name_Display").GetValue(null);
				if (value2 != null)
				{
					AccessTools.Property(value2.GetType(), "text").SetValue(value2, value, null);
				}
			}
			catch (Exception ex)
			{
				Report(ex);
				__result = 0;
			}
			return false;
		}
	}
}