Decompiled source of LDBTool v3.0.1

LDBTool.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using xiaoye97.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("xiaoye97, CommonAPI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Library that allows mods to add and edit Proto data. Also allows you to see Proto data, config ID\\u0027s of mod Protos and change localized strings")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LDBTool")]
[assembly: AssemblyTitle("LDBTool")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace xiaoye97
{
	public static class LDBTool
	{
		public static Action PreAddDataAction;

		public static Action PostAddDataAction;

		public static Action<Proto> EditDataAction;

		internal static bool Finshed;

		internal static List<List<Proto>> PreToAdd = new List<List<Proto>>();

		internal static List<List<Proto>> PostToAdd = new List<List<Proto>>();

		internal static List<List<Proto>> TotalDict = new List<List<Proto>>();

		private static List<Dictionary<string, ConfigEntry<int>>> IDDict = new List<Dictionary<string, ConfigEntry<int>>>();

		private static List<Dictionary<string, ConfigEntry<int>>> GridIndexDict = new List<Dictionary<string, ConfigEntry<int>>>();

		private static Dictionary<string, ConfigEntry<string>> ZHCNDict = new Dictionary<string, ConfigEntry<string>>();

		private static Dictionary<string, ConfigEntry<string>> ENUSDict = new Dictionary<string, ConfigEntry<string>>();

		private static Dictionary<string, ConfigEntry<string>> FRFRDict = new Dictionary<string, ConfigEntry<string>>();

		private static Dictionary<int, Dictionary<int, int>> BuildBarDict = new Dictionary<int, Dictionary<int, int>>();

		private static ConfigFile CustomID = new ConfigFile(Paths.ConfigPath + "/LDBTool/LDBTool.CustomID.cfg", true);

		private static ConfigFile CustomGridIndex = new ConfigFile(Paths.ConfigPath + "/LDBTool/LDBTool.CustomGridIndex.cfg", true);

		private static ConfigFile CustomStringZHCN = new ConfigFile(Paths.ConfigPath + "/LDBTool/LDBTool.CustomLocalization.ZHCN.cfg", true);

		private static ConfigFile CustomStringENUS = new ConfigFile(Paths.ConfigPath + "/LDBTool/LDBTool.CustomLocalization.ENUS.cfg", true);

		private static ConfigFile CustomStringFRFR = new ConfigFile(Paths.ConfigPath + "/LDBTool/LDBTool.CustomLocalization.FRFR.cfg", true);

		public static void SetBuildBar(int category, int index, int itemId)
		{
			if (category < 1 || category > 12)
			{
				LDBToolPlugin.logger.LogWarning((object)"SetBuildBar Fail. category must be between 1 and 12.");
			}
			else if (index < 1 || index > 12)
			{
				LDBToolPlugin.logger.LogWarning((object)"SetBuildBar Fail. index must be between 1 and 12.");
			}
			else if (UIBuildMenu.staticLoaded && Finshed)
			{
				ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(itemId);
				if (val != null)
				{
					UIBuildMenu.protos[category, index] = val;
					LDBToolPlugin.logger.LogInfo((object)$"Set build bar at {category},{index} ID:{((Proto)val).ID} name:{Localization.Translate(((Proto)val).Name)}");
				}
				else
				{
					LDBToolPlugin.logger.LogWarning((object)$"SetBuildBar Fail. ItemProto with ID {itemId} not found.");
				}
			}
			else
			{
				if (!BuildBarDict.ContainsKey(category))
				{
					BuildBarDict.Add(category, new Dictionary<int, int>());
				}
				BuildBarDict[category][index] = itemId;
			}
		}

		public static void PreAddProto(Proto proto)
		{
			int index = ProtoIndex.GetIndex(((object)proto).GetType());
			if (!PreToAdd[index].Contains(proto))
			{
				Bind(proto);
				PreToAdd[index].Add(proto);
				TotalDict[index].Add(proto);
			}
		}

		[Obsolete("Please use PreAddProto(Proto proto)")]
		public static void PreAddProto(ProtoType protoType, Proto proto)
		{
			PreAddProto(proto);
		}

		public static void PostAddProto(Proto proto)
		{
			int index = ProtoIndex.GetIndex(((object)proto).GetType());
			if (!PostToAdd[index].Contains(proto))
			{
				Bind(proto);
				PostToAdd[index].Add(proto);
				TotalDict[index].Add(proto);
			}
		}

		[Obsolete("Please use PostAddProto(Proto proto)")]
		public static void PostAddProto(ProtoType protoType, Proto proto)
		{
			PostAddProto(proto);
		}

		internal static void Init()
		{
			for (int i = 0; i <= ProtoIndex.GetProtosCount(); i++)
			{
				PreToAdd.Add(new List<Proto>());
				PostToAdd.Add(new List<Proto>());
				TotalDict.Add(new List<Proto>());
				IDDict.Add(new Dictionary<string, ConfigEntry<int>>());
				GridIndexDict.Add(new Dictionary<string, ConfigEntry<int>>());
			}
		}

		internal static void SetBuildBar()
		{
			foreach (KeyValuePair<int, Dictionary<int, int>> item in BuildBarDict)
			{
				foreach (KeyValuePair<int, int> item2 in item.Value)
				{
					ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(item2.Value);
					if (val != null)
					{
						UIBuildMenu.protos[item.Key, item2.Key] = val;
						LDBToolPlugin.logger.LogInfo((object)$" Set build bar at {item.Key},{item2.Key} ID:{((Proto)val).ID} name:{Localization.Translate(((Proto)val).Name)}");
					}
					else
					{
						LDBToolPlugin.logger.LogWarning((object)$"SetBuildBar Fail. ItemProto with ID {item2.Value} not found.");
					}
				}
			}
		}

		private static void Bind(Proto proto)
		{
			IdBind(proto);
			GridIndexBind(proto);
		}

		private static void IdBind(Proto proto)
		{
			int index = ProtoIndex.GetIndex(proto);
			ConfigEntry<int> val = CustomID.Bind<int>(ProtoIndex.GetProtoName(proto), proto.Name, proto.ID, (ConfigDescription)null);
			proto.ID = val.Value;
			if (IDDict[index].ContainsKey(proto.Name))
			{
				LDBToolPlugin.logger.LogError((object)$"[CustomID] ID:{proto.ID} Name:{proto.Name} There is a conflict, please check.");
			}
			else
			{
				IDDict[index].Add(proto.Name, val);
			}
		}

		private static void GridIndexBind(Proto proto)
		{
			ConfigEntry<int> val = null;
			ItemProto val2 = (ItemProto)(object)((proto is ItemProto) ? proto : null);
			if (val2 != null)
			{
				val = CustomGridIndex.Bind<int>(ProtoIndex.GetProtoName(proto), ((Proto)val2).ID.ToString(), 0, $"Default Grid Index = {val2.GridIndex}\nItem Name = {((Proto)val2).Name}");
				if (val.Value != 0)
				{
					val2.GridIndex = val.Value;
				}
			}
			else
			{
				RecipeProto val3 = (RecipeProto)(object)((proto is RecipeProto) ? proto : null);
				if (val3 != null)
				{
					val = CustomGridIndex.Bind<int>(ProtoIndex.GetProtoName(proto), ((Proto)val3).ID.ToString(), 0, $"Default Grid Index = {val3.GridIndex}\nRecipe Name = {((Proto)val3).Name}");
					if (val.Value != 0)
					{
						val3.GridIndex = val.Value;
					}
				}
			}
			if (val != null)
			{
				int index = ProtoIndex.GetIndex(proto);
				if (GridIndexDict[index].ContainsKey(proto.Name))
				{
					LDBToolPlugin.logger.LogError((object)$"[CustomGridIndex] ID:{proto.ID} Name:{proto.Name} There is a conflict, please check.");
				}
				else
				{
					GridIndexDict[index].Add(proto.Name, val);
				}
			}
		}

		internal static void AddProtos(List<List<Proto>> datas)
		{
			Type[] allProtoTypes = ProtoIndex.GetAllProtoTypes();
			for (int i = 0; i < allProtoTypes.Length; i++)
			{
				Type protoType = allProtoTypes[i];
				PropertyInfo propertyInfo = typeof(LDB).GetProperties().First(delegate(PropertyInfo property)
				{
					Type type = typeof(ProtoSet<>).MakeGenericType(protoType);
					return type.IsAssignableFrom(property.PropertyType);
				});
				MethodInfo method = typeof(LDBTool).GetMethod("AddProtosToSet", AccessTools.all);
				MethodInfo methodInfo = method.MakeGenericMethod(protoType);
				object value = propertyInfo.GetValue(null);
				methodInfo.Invoke(null, new object[2]
				{
					value,
					datas[i]
				});
			}
		}

		private static void AddProtosToSet<T>(ProtoSet<T> protoSet, List<Proto> protos) where T : Proto
		{
			T[] dataArray = protoSet.dataArray;
			((ProtoTable)protoSet).Init(dataArray.Length + protos.Count);
			for (int i = 0; i < dataArray.Length; i++)
			{
				protoSet.dataArray[i] = dataArray[i];
			}
			for (int j = 0; j < protos.Count; j++)
			{
				ref T reference = ref protoSet.dataArray[dataArray.Length + j];
				Proto obj = protos[j];
				reference = (T)(object)((obj is T) ? obj : null);
				Proto obj2 = protos[j];
				ItemProto val = (ItemProto)(object)((obj2 is ItemProto) ? obj2 : null);
				if (val != null)
				{
					val.index = dataArray.Length + j;
				}
				if (protos[j] is RecipeProto)
				{
					Proto obj3 = protos[j];
					RecipeProto val2 = (RecipeProto)(object)((obj3 is RecipeProto) ? obj3 : null);
					if (val2.preTech != null)
					{
						ArrayAddItem(ref val2.preTech.UnlockRecipes, ((Proto)val2).ID);
						ArrayAddItem(ref val2.preTech.unlockRecipeArray, val2);
					}
				}
				LDBToolPlugin.logger.LogInfo((object)$"Add {protos[j].ID} {Localization.Translate(protos[j].Name)} to {((object)protoSet).GetType().Name}.");
			}
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			for (int k = 0; k < protoSet.dataArray.Length; k++)
			{
				((Proto)protoSet.dataArray[k]).sid = ((Proto)protoSet.dataArray[k]).SID;
				dictionary[((Proto)protoSet.dataArray[k]).ID] = k;
			}
			protoSet.dataIndices = dictionary;
		}

		private static void ArrayAddItem<T>(ref T[] array, T item)
		{
			List<T> list = array.ToList();
			list.Add(item);
			array = list.ToArray();
		}
	}
	[BepInPlugin("me.xiaoye97.plugin.Dyson.LDBTool", "LDBTool", "3.0.1")]
	public class LDBToolPlugin : BaseUnityPlugin
	{
		public const string MODNAME = "LDBTool";

		public const string MODGUID = "me.xiaoye97.plugin.Dyson.LDBTool";

		public const string VERSION = "3.0.1";

		internal static ManualLogSource logger;

		internal static ConfigEntry<bool> ShowProto;

		internal static ConfigEntry<KeyCode> ShowProtoHotKey;

		internal static ConfigEntry<KeyCode> ShowItemProtoHotKey;

		internal static ConfigEntry<KeyCode> ShowRecipeProtoHotKey;

		internal static UIItemTip lastTip;

		private void Awake()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			ProtoIndex.InitIndex();
			LDBTool.Init();
			ShowProto = ((BaseUnityPlugin)this).Config.Bind<bool>("config", "ShowProto", false, "是否开启数据显示");
			ShowProtoHotKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("config", "ShowProtoHotKey", (KeyCode)286, "呼出界面的快捷键");
			ShowItemProtoHotKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("config", "ShowItemProtoHotKey", (KeyCode)105, "显示物品的Proto");
			ShowRecipeProtoHotKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("config", "ShowRecipeProtoHotKey", (KeyCode)114, "显示配方的Proto");
			Harmony val = new Harmony("me.xiaoye97.plugin.Dyson.LDBTool");
			val.PatchAll(Assembly.GetExecutingAssembly());
			logger.LogInfo((object)"LDBTool is loaded successfully!");
		}

		private void Update()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			if (!ShowProto.Value)
			{
				return;
			}
			if (Input.GetKeyDown(ShowProtoHotKey.Value))
			{
				ProtoDataUI.Show = !ProtoDataUI.Show;
			}
			if (SupportsHelper.UnityExplorerInstalled)
			{
				if (Input.GetKeyDown(ShowItemProtoHotKey.Value))
				{
					TryShowItemProto();
				}
				if (Input.GetKeyDown(ShowRecipeProtoHotKey.Value))
				{
					TryShowRecipeProto();
				}
			}
		}

		private void OnGUI()
		{
			if (ShowProto.Value && ProtoDataUI.Show)
			{
				ProtoDataUI.OnGUI();
			}
		}

		internal static void TryShowItemProto()
		{
			if (!ShowProto.Value || !((Object)(object)lastTip != (Object)null) || lastTip.showingItemId == 0)
			{
				return;
			}
			ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(lastTip.showingItemId);
			if (val != null)
			{
				RUEHelper.ShowProto((Proto)(object)val);
				return;
			}
			RecipeProto val2 = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(-lastTip.showingItemId);
			if (val2 != null)
			{
				int[] results = val2.Results;
				foreach (int num in results)
				{
					ItemProto proto = ((ProtoSet<ItemProto>)(object)LDB.items).Select(num);
					RUEHelper.ShowProto((Proto)(object)proto);
				}
			}
		}

		internal static void TryShowRecipeProto()
		{
			if (!ShowProto.Value || !((Object)(object)lastTip != (Object)null) || lastTip.showingItemId == 0)
			{
				return;
			}
			ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(lastTip.showingItemId);
			if (val != null)
			{
				foreach (RecipeProto recipe in val.recipes)
				{
					RUEHelper.ShowProto((Proto)(object)recipe);
				}
				return;
			}
			RecipeProto proto = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(-lastTip.showingItemId);
			RUEHelper.ShowProto((Proto)(object)proto);
		}
	}
	public static class MethedEx
	{
		[Obsolete("Please don't use this method. Instead use CommonAPI.")]
		public static T Copy<T>(this T obj) where T : class
		{
			Type type = obj.GetType();
			object obj2 = Activator.CreateInstance(type);
			FieldInfo[] fields = type.GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (!fieldInfo.IsLiteral && !fieldInfo.IsStatic)
				{
					Traverse.Create(obj2).Field(fieldInfo.Name).SetValue(Traverse.Create((object)obj).Field(fieldInfo.Name).GetValue());
				}
			}
			PropertyInfo[] properties = type.GetProperties();
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (propertyInfo.CanWrite && propertyInfo.CanRead)
				{
					Traverse.Create(obj2).Property(propertyInfo.Name, (object[])null).SetValue(Traverse.Create((object)obj).Property(propertyInfo.Name, (object[])null).GetValue());
				}
			}
			return obj2 as T;
		}
	}
	public static class ProtoIndex
	{
		private static Dictionary<Type, int> index = new Dictionary<Type, int>();

		private static Type[] protoTypes;

		internal static void InitIndex()
		{
			LDBToolPlugin.logger.LogDebug((object)"Generating Proto type list:");
			protoTypes = (from domainAssembly in AppDomain.CurrentDomain.GetAssemblies()
				from assemblyType in GetTypesSafe(domainAssembly)
				where assemblyType != null && typeof(Proto).IsAssignableFrom(assemblyType) && assemblyType != typeof(Proto)
				select assemblyType).ToArray();
			for (int i = 0; i < protoTypes.Length; i++)
			{
				index.Add(protoTypes[i], i);
				LDBToolPlugin.logger.LogDebug((object)("Found Proto type: " + protoTypes[i].FullName));
			}
		}

		private static Type[] GetTypesSafe(Assembly assembly)
		{
			try
			{
				return assembly.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				return ex.Types;
			}
		}

		public static int GetProtosCount()
		{
			return index.Count;
		}

		public static int GetIndex(Proto proto)
		{
			return GetIndex(((object)proto).GetType());
		}

		public static int GetIndex(Type type)
		{
			if (!typeof(Proto).IsAssignableFrom(type))
			{
				throw new ArgumentException("Can't get index because type " + type.FullName + " does not extend Proto type.");
			}
			if (index.ContainsKey(type))
			{
				return index[type];
			}
			throw new ArgumentException("Unknown Proto type: " + type.FullName);
		}

		public static Type GetProtoTypeAt(int num)
		{
			return protoTypes[num];
		}

		public static string GetProtoName(Proto proto)
		{
			return ((object)proto).GetType().Name.Replace("Proto", "");
		}

		public static string[] GetProtoNames()
		{
			return protoTypes.Select((Type type) => type.Name.Replace("Proto", "")).ToArray();
		}

		internal static Type[] GetAllProtoTypes()
		{
			return protoTypes;
		}
	}
	[Obsolete("Use methods that don't have this type as parameter")]
	public enum ProtoType
	{
		AdvisorTip,
		Audio,
		EffectEmitter,
		Item,
		Model,
		Player,
		Recipe,
		String,
		Tech,
		Theme,
		Tutorial,
		Vege,
		Vein
	}
}
namespace xiaoye97.UI
{
	public static class ProtoDataUI
	{
		public static bool Show;

		private static Rect winRect = new Rect(0f, 0f, 500f, 800f);

		private static int selectIndex;

		private static string[] protoTypeNames = ProtoIndex.GetProtoNames();

		public static ISkin Skin;

		private static int SelectIndex
		{
			get
			{
				return selectIndex;
			}
			set
			{
				if (selectIndex != value)
				{
					selectIndex = value;
					ProtoSetEx.needSearch = true;
				}
			}
		}

		public static void OnGUI()
		{
			//IL_001b: 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)
			//IL_003b: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (Skin != null)
			{
				GUI.skin = Skin.GetSkin();
			}
			winRect = GUILayout.Window(3562532, winRect, new WindowFunction(WindowFunc), "ProtoData", Array.Empty<GUILayoutOption>());
		}

		public static void WindowFunc(int id)
		{
			if (Skin != null)
			{
				GUI.skin = Skin.GetSkin();
			}
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
			SelectIndex = GUILayout.SelectionGrid(SelectIndex, protoTypeNames, 10, Array.Empty<GUILayoutOption>());
			GUILayout.Space(20f);
			if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }))
			{
				Show = false;
			}
			GUILayout.EndHorizontal();
			Type selectedType = ProtoIndex.GetProtoTypeAt(selectIndex);
			PropertyInfo propertyInfo = typeof(LDB).GetProperties().First(delegate(PropertyInfo property)
			{
				Type type = typeof(ProtoSet<>).MakeGenericType(selectedType);
				return type.IsAssignableFrom(property.PropertyType);
			});
			object value = propertyInfo.GetValue(null);
			MethodInfo methodInfo = typeof(ProtoSetEx).GetMethod("ShowSet", AccessTools.all).MakeGenericMethod(selectedType);
			methodInfo.Invoke(null, new object[1] { value });
			GUILayout.EndVertical();
			GUI.DragWindow();
		}
	}
	public static class ProtoSetEx
	{
		private static Vector2 sv;

		private static Dictionary<Type, int> selectPages;

		private static string search;

		public static bool needSearch;

		private static List<Proto> searchResultList;

		private static string Search
		{
			get
			{
				return search;
			}
			set
			{
				if (search != value)
				{
					search = value;
					needSearch = true;
				}
			}
		}

		static ProtoSetEx()
		{
			selectPages = new Dictionary<Type, int>();
			search = "";
			needSearch = true;
			searchResultList = new List<Proto>();
			PropertyInfo[] properties = typeof(LDB).GetProperties();
			foreach (PropertyInfo propertyInfo in properties)
			{
				Type type = propertyInfo.PropertyType;
				if (!type.IsConstructedGenericType)
				{
					type = type.BaseType;
				}
				Type key = type.GetGenericArguments()[0];
				selectPages.Add(key, 0);
			}
		}

		private static void SearchLDB<T>(ProtoSet<T> protoSet) where T : Proto
		{
			searchResultList.Clear();
			if ((Object)(object)protoSet != (Object)null)
			{
				T[] dataArray = protoSet.dataArray;
				foreach (T val in dataArray)
				{
					if (Search == "" || ((Proto)val).ID.ToString().Contains(Search) || ((Proto)val).Name.Contains(Search) || Localization.Translate(((Proto)val).Name).Contains(Search))
					{
						searchResultList.Add((Proto)(object)val);
					}
				}
			}
			needSearch = false;
		}

		public static void ShowSet<T>(ProtoSet<T> protoSet) where T : Proto
		{
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			if (ProtoDataUI.Skin != null)
			{
				GUI.skin = ProtoDataUI.Skin.GetSkin();
			}
			GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
			Search = GUILayout.TextField(Search, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			if (needSearch)
			{
				SearchLDB<T>(protoSet);
			}
			GUILayout.Label($"Page {selectPages[typeof(T)] + 1} / {searchResultList.Count / 100 + 1}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			if (GUILayout.Button("-", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(20f) }))
			{
				selectPages[typeof(T)]--;
			}
			if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(20f) }))
			{
				selectPages[typeof(T)]++;
			}
			if (selectPages[typeof(T)] < 0)
			{
				selectPages[typeof(T)] = searchResultList.Count / 100;
			}
			else if (selectPages[typeof(T)] > searchResultList.Count / 100)
			{
				selectPages[typeof(T)] = 0;
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("index", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
			GUILayout.Label("ID", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
			GUILayout.Label("Name", Array.Empty<GUILayoutOption>());
			GUILayout.Label("TranslateName", Array.Empty<GUILayoutOption>());
			if (SupportsHelper.UnityExplorerInstalled)
			{
				GUILayout.Label("Show Data", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) });
			}
			GUILayout.EndHorizontal();
			sv = GUILayout.BeginScrollView(sv, Array.Empty<GUILayoutOption>());
			for (int i = selectPages[typeof(T)] * 100; i < Mathf.Min(selectPages[typeof(T)] * 100 + 100, searchResultList.Count); i++)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label($"{i}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
				if (searchResultList[i] != null)
				{
					GUILayout.Label($"{searchResultList[i].ID}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
					GUILayout.Label(searchResultList[i].Name ?? "", Array.Empty<GUILayoutOption>());
					GUILayout.Label(Localization.Translate(searchResultList[i].name) ?? "", Array.Empty<GUILayoutOption>());
					if (SupportsHelper.UnityExplorerInstalled && GUILayout.Button("Show Data", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
					{
						ShowItem showItem = new ShowItem(searchResultList[i]);
						showItem.Show();
					}
				}
				else
				{
					GUILayout.Label("null", Array.Empty<GUILayoutOption>());
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			GUILayout.EndVertical();
		}
	}
	public static class RUEHelper
	{
		public static void ShowProto(Proto proto)
		{
			if (proto != null)
			{
				ShowItem showItem = new ShowItem(proto);
				showItem.Show();
			}
		}
	}
	public class ShowItem
	{
		private object proto;

		public ShowItem(object proto)
		{
			this.proto = proto;
		}

		public void Show()
		{
			if (SupportsHelper.UnityExplorerInstalled)
			{
				SupportsHelper.inspectMethod.Invoke(null, new object[2] { proto, null });
			}
		}
	}
	public static class SupportsHelper
	{
		internal static readonly Type unityExplorerType;

		internal static readonly MethodInfo inspectMethod;

		public static bool UnityExplorerInstalled
		{
			get
			{
				if (unityExplorerType != null)
				{
					return inspectMethod != null;
				}
				return false;
			}
		}

		static SupportsHelper()
		{
			unityExplorerType = AccessTools.TypeByName("UnityExplorer.InspectorManager");
			if (unityExplorerType != null)
			{
				inspectMethod = unityExplorerType.GetMethods().First((MethodInfo info) => info.Name == "Inspect" && info.GetParameters().Length == 2);
			}
		}
	}
	public interface ISkin
	{
		GUISkin GetSkin();
	}
}
namespace xiaoye97.Patches
{
	[HarmonyPatch]
	public static class GameHistoryData_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameHistoryData), "Import")]
		private static void HistoryPatch(GameHistoryData __instance)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			foreach (Proto item in LDBTool.TotalDict[ProtoIndex.GetIndex(typeof(RecipeProto))])
			{
				RecipeProto val = (RecipeProto)(object)((item is RecipeProto) ? item : null);
				if (val.preTech != null && __instance.TechState(((Proto)val.preTech).ID).unlocked && !__instance.RecipeUnlocked(((Proto)val).ID))
				{
					__instance.UnlockRecipe(((Proto)val).ID);
				}
			}
		}
	}
	[HarmonyPatch]
	public static class UITip_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIItemTip), "SetTip")]
		private static void ItemTipPatch(UIItemTip __instance, int itemId)
		{
			if (LDBToolPlugin.ShowProto.Value)
			{
				Text nameText = __instance.nameText;
				nameText.text += $" {itemId}";
				LDBToolPlugin.lastTip = __instance;
			}
		}
	}
	[HarmonyPatch]
	public static class VFPreload_Patch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
		private static void VFPreloadPrePatch()
		{
			if (!LDBTool.Finshed)
			{
				LDBToolPlugin.logger.LogInfo((object)"Pre Loading...");
				if (LDBTool.PreAddDataAction != null)
				{
					LDBTool.PreAddDataAction();
					LDBTool.PreAddDataAction = null;
				}
				LDBTool.AddProtos(LDBTool.PreToAdd);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
		private static void VFPreloadPostPatch()
		{
			if (LDBTool.Finshed)
			{
				return;
			}
			LDBToolPlugin.logger.LogInfo((object)"Post Loading...");
			if (LDBTool.PostAddDataAction != null)
			{
				LDBTool.PostAddDataAction();
				LDBTool.PostAddDataAction = null;
			}
			LDBTool.AddProtos(LDBTool.PostToAdd);
			if (LDBTool.EditDataAction != null)
			{
				PropertyInfo[] properties = typeof(LDB).GetProperties();
				foreach (PropertyInfo propertyInfo in properties)
				{
					Type type = propertyInfo.PropertyType;
					if (!type.IsConstructedGenericType)
					{
						type = type.BaseType;
					}
					Type type2 = type.GetGenericArguments()[0];
					object value = propertyInfo.GetValue(null);
					MethodInfo methodInfo = typeof(VFPreload_Patch).GetMethod("EditAllProtos", AccessTools.all).MakeGenericMethod(type2);
					methodInfo.Invoke(null, new object[1] { value });
				}
			}
			GameMain.iconSet.loaded = false;
			GameMain.iconSet.Create();
			LDBTool.SetBuildBar();
			LDBTool.Finshed = true;
			LDBToolPlugin.logger.LogInfo((object)"Done.");
		}

		private static void EditAllProtos<T>(ProtoSet<T> protoSet) where T : Proto
		{
			T[] dataArray = protoSet.dataArray;
			foreach (T val in dataArray)
			{
				if (val != null)
				{
					try
					{
						LDBTool.EditDataAction((Proto)(object)val);
					}
					catch (Exception ex)
					{
						LDBToolPlugin.logger.LogWarning((object)$"Edit Error: ID:{((Proto)val).ID} Type:{((object)val).GetType().Name} {ex.Message}");
					}
				}
			}
		}
	}
}