Decompiled source of BUG GBCompat v1.0.2

BUG_GBCompat.dll

Decompiled 15 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CommonAPI.Systems;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProjectGenesis.Patches;
using ProjectGenesis.Utils;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("Check")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GBCompat
{
	internal static class Fixes
	{
		internal const string For = "3.2.3";

		internal static int Replaced = -1;

		private static readonly Dictionary<MethodBase, MethodInfo> Redirects = new Dictionary<MethodBase, MethodInfo>();

		internal static void Apply(Assembly genesis)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			string text = genesis.GetType("ProjectGenesis.ProjectGenesis")?.GetField("VERSION")?.GetValue(null) as string;
			if (text != "3.2.3")
			{
				Plugin.Log.LogInfo((object)("GenesisBook " + text + " is not 3.2.3, nothing patched"));
				return;
			}
			Harmony val = new Harmony("aaa.bug.dsp.gbcompat");
			try
			{
				int num = RedirectAll(val, genesis, typeof(Upstream));
				val.PatchAll(typeof(Additions));
				Replaced = num;
				Plugin.Log.LogInfo((object)$"GenesisBook {text}: {num} patch methods replaced with their corrected versions");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("GenesisBook " + text + " could not be patched, it is left as it is. " + ex));
				try
				{
					val.UnpatchSelf();
				}
				catch (Exception ex2)
				{
					Plugin.Log.LogError((object)("Removing the partial patches failed: " + ex2.Message));
				}
				Redirects.Clear();
			}
		}

		internal static int RedirectAll(Harmony harmony, Assembly genesis, Type replacements)
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			int num = 0;
			Type[] nestedTypes = replacements.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
			foreach (Type type in nestedTypes)
			{
				Type type2 = genesis.GetType("ProjectGenesis.Patches." + type.Name) ?? throw new TypeLoadException("ProjectGenesis.Patches." + type.Name);
				MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
				foreach (MethodInfo methodInfo in methods)
				{
					Type[] array = (from p in methodInfo.GetParameters()
						select p.ParameterType).ToArray();
					MethodInfo methodInfo2 = AccessTools.DeclaredMethod(type2, methodInfo.Name, array, (Type[])null);
					if (methodInfo2 == null || !methodInfo2.IsStatic || methodInfo2.ReturnType != methodInfo.ReturnType)
					{
						throw new MissingMethodException(type2.FullName, methodInfo.Name);
					}
					Redirects[methodInfo2] = methodInfo;
					harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Fixes), "CallReplacement", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
			}
			return num;
		}

		private static IEnumerable<CodeInstruction> CallReplacement(MethodBase original)
		{
			MethodInfo to = Redirects[original];
			for (int i = 0; i < to.GetParameters().Length; i++)
			{
				yield return new CodeInstruction(OpCodes.Ldarg_S, (object)(byte)i);
			}
			yield return new CodeInstruction(OpCodes.Call, (object)to);
			yield return new CodeInstruction(OpCodes.Ret, (object)null);
		}
	}
	internal static class Op
	{
		internal static CodeMatch Br => Any(OpCodes.Br, OpCodes.Br_S);

		internal static CodeMatch BrTrue => Any(OpCodes.Brtrue, OpCodes.Brtrue_S);

		internal static CodeMatch BrFalse => Any(OpCodes.Brfalse, OpCodes.Brfalse_S);

		internal static CodeMatch Beq => Any(OpCodes.Beq, OpCodes.Beq_S);

		internal static CodeMatch BneUn => Any(OpCodes.Bne_Un, OpCodes.Bne_Un_S);

		internal static CodeMatch Bge => Any(OpCodes.Bge, OpCodes.Bge_S);

		internal static CodeMatch BgtUn => Any(OpCodes.Bgt_Un, OpCodes.Bgt_Un_S);

		internal static CodeMatch Add => Any(OpCodes.Add);

		internal static CodeMatch Sub => Any(OpCodes.Sub);

		internal static CodeMatch LdLoc => new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.IsLdloc(i, (LocalBuilder)null)), (string)null);

		private static CodeMatch Any(params OpCode[] codes)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			return new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => codes.Contains(i.opcode)), (string)null);
		}
	}
	[BepInPlugin("aaa.bug.dsp.gbcompat", "BUG_GBCompat", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "aaa.bug.dsp.gbcompat";

		public const string Version = "1.0.2";

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				if (IsGenesisBook(assemblies[i]))
				{
					Log.LogError((object)"GenesisBook was loaded before BUG_GBCompat, so its patches are already in place; nothing changed");
					return;
				}
			}
			AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
		}

		private static void OnAssemblyLoad(object sender, AssemblyLoadEventArgs e)
		{
			if (IsGenesisBook(e.LoadedAssembly))
			{
				AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
				Fixes.Apply(e.LoadedAssembly);
			}
		}

		private static bool IsGenesisBook(Assembly assembly)
		{
			return assembly.GetName().Name == "ProjectGenesis";
		}
	}
	internal static class Upstream
	{
		public static class AddVeinPatches
		{
			public static IEnumerable<CodeInstruction> PlanetAlgorithm_GenerateVeins_ResizeVeinList_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)(sbyte)15, (string)null),
					Op.Bge
				});
				val.SetOperandAndAdvance((object)(sbyte)21);
				return val.InstructionEnumeration();
			}

			public static IEnumerable<CodeInstruction> PlanetAlgorithm_GenerateVeins_RemoveVeinPositionBias_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Expected O, but got Unknown
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Expected O, but got Unknown
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Expected O, but got Unknown
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Expected O, but got Unknown
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[6]
				{
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_7, (object)null, (string)null),
					Op.Beq,
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Vector3), "op_Addition", (Type[])null, (Type[])null), (string)null)
				});
				val.SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop, (object)null)).SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop, (object)null)).SetOpcodeAndAdvance(OpCodes.Br_S);
				return val.InstructionEnumeration();
			}

			public static IEnumerable<CodeInstruction> PlanetAlgorithm_GenerateVeins_RemoveHeightLimit_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Expected O, but got Unknown
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Expected O, but got Unknown
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Expected O, but got Unknown
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Expected O, but got Unknown
				//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fe: Expected O, but got Unknown
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Expected O, but got Unknown
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				//IL_0136: Expected O, but got Unknown
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0152: Expected O, but got Unknown
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Expected O, but got Unknown
				//IL_0175: Unknown result type (might be due to invalid IL or missing references)
				//IL_017b: Expected O, but got Unknown
				//IL_0193: Unknown result type (might be due to invalid IL or missing references)
				//IL_0199: Expected O, but got Unknown
				//IL_0246: Unknown result type (might be due to invalid IL or missing references)
				//IL_024c: Expected O, but got Unknown
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01db: Expected O, but got Unknown
				//IL_0203: Unknown result type (might be due to invalid IL or missing references)
				//IL_0209: Expected O, but got Unknown
				//IL_0211: Unknown result type (might be due to invalid IL or missing references)
				//IL_0217: Expected O, but got Unknown
				//IL_0224: Unknown result type (might be due to invalid IL or missing references)
				//IL_022a: Expected O, but got Unknown
				//IL_027b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0281: Expected O, but got Unknown
				//IL_029e: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a4: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(PlanetRawData), "QueryHeight", (Type[])null, (Type[])null), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsStloc(ci, (LocalBuilder)null)), (string)null)
				});
				CodeMatcher val2 = val.Clone();
				val2.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null)
				});
				Label label = val2.Labels.First();
				val2.MatchForward(false, (CodeMatch[])(object)new CodeMatch[12]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlanetData), "radius"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)1f, (string)null),
					Op.Sub,
					Op.BgtUn,
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
					Op.Sub,
					new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
					Op.Add,
					new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null)
				});
				val.Advance(1);
				if (val2.IsValid)
				{
					CodeInstruction instruction = val.Clone().MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
					{
						Op.LdLoc,
						new CodeMatch((OpCode?)OpCodes.Ldc_I4_7, (object)null, (string)null),
						Op.BneUn
					}).Instruction;
					val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
					{
						new CodeInstruction(instruction.opcode, instruction.operand),
						new CodeInstruction(OpCodes.Ldc_I4_7, (object)null),
						new CodeInstruction(OpCodes.Bne_Un, (object)label)
					});
				}
				else
				{
					val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Br, (object)label)
					});
				}
				val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlanetData), "waterItemId"), (string)null),
					Op.BrFalse
				});
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Pop, (object)null)
				});
				val.SetOpcodeAndAdvance(OpCodes.Br);
				return val.InstructionEnumeration();
			}
		}

		public static class GammaGeneratorPatches
		{
			public static IEnumerable<CodeInstruction> PowerGeneratorComponent_GameTick_Gamma_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "catalystPoint"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Sub, (object)null, (string)null)
				});
				val.Advance(1).SetAndAdvance(OpCodes.Ldc_I4_S, (object)(sbyte)10);
				return val.InstructionEnumeration();
			}
		}

		public static class BirthStarPatches
		{
			public static IEnumerable<CodeInstruction> StarGen_CreateStarPlanets_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Expected O, but got Unknown
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Expected O, but got Unknown
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Expected O, but got Unknown
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Expected O, but got Unknown
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Expected O, but got Unknown
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Expected O, but got Unknown
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					Op.Br,
					new CodeMatch((OpCode?)OpCodes.Ldsfld, (object)AccessTools.Field(typeof(StarGen), "pGas"), (string)null)
				});
				object operand = val.Operand;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
				{
					Op.Br,
					new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(StarData), "spectr"), (string)null),
					Op.BrTrue
				});
				val.Operand = operand;
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[5]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldarg_1, (object)null),
					new CodeInstruction(OpCodes.Ldarg_2, (object)null),
					new CodeInstruction(OpCodes.Ldloc_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(BirthStarPatches), "ModifyBirthStar", (Type[])null, (Type[])null))
				});
				return val.InstructionEnumeration();
			}

			internal static void ModifyBirthStar(GalaxyData galaxy, StarData star, GameDesc gameDesc, DotNet35Random dotNet35Random2)
			{
				star.planetCount = 5;
				star.planets = (PlanetData[])(object)new PlanetData[star.planetCount];
				int[][] array = new int[5][]
				{
					new int[1] { 9 },
					new int[1] { 21 },
					new int[1] { 1 },
					new int[1] { 7 },
					new int[1] { 20 }
				};
				int[] array2 = new int[5] { 0, 0, 2, 2, 0 };
				int[] array3 = new int[5] { 1, 2, 1, 2, 3 };
				int[] array4 = new int[5] { 1, 2, 1, 2, 3 };
				for (int i = 0; i < 5; i++)
				{
					int num = dotNet35Random2.Next();
					int num2 = dotNet35Random2.Next();
					star.planets[i] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, array[i], i, array2[i], array3[i], array4[i], i == 1, num, num2);
				}
			}
		}

		public static class UILootFilterPatches
		{
			private const int DropType = 2;

			private static readonly FieldInfo currentTypeField = AccessTools.Field(typeof(UILootFilter), "currentType");

			private static List<UITabButton> Tabs
			{
				get
				{
					return UILootFilterPatches._tabs;
				}
				set
				{
					UILootFilterPatches._tabs = value;
				}
			}

			public static void Create(UILootFilter __instance)
			{
				//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				TabData[] allTabs = TabSystem.GetAllTabs();
				Tabs = new List<UITabButton>();
				int num = 2;
				TabData[] array = allTabs;
				foreach (TabData val in array)
				{
					if (val != null)
					{
						num = val.tabIndex;
						GameObject obj = Object.Instantiate<GameObject>(TabSystem.GetTabPrefab(), (Transform)(object)__instance.filterTrans, false);
						((RectTransform)obj.transform).anchoredPosition = new Vector2((float)(num * 70 - 54), -72f);
						UITabButton component = obj.GetComponent<UITabButton>();
						Sprite val2 = Resources.Load<Sprite>(val.tabIconPath);
						component.Init(val2, val.tabName, val.tabIndex, (Action<int>)__instance.OnTypeButtonClick);
						Tabs.Add(component);
					}
				}
				((Component)__instance.typeButton3).transform.localPosition = new Vector3((float)((num + 1) * 70 - 54), -40f, 0f);
			}

			public static void OnTypeClicked_Prefix(int type)
			{
				UILootFilter.showAll = type == 2;
			}

			private static IEnumerable<CodeInstruction> RowLength(IEnumerable<CodeInstruction> instructions, int times)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Expected O, but got Unknown
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				for (int i = 0; i < times; i++)
				{
					val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
					{
						new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)(sbyte)14, (string)null)
					});
					val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null)
					}).SetInstructionAndAdvance(Transpilers.EmitDelegate<Func<UILootFilter, int>>((Func<UILootFilter, int>)((UILootFilter filter) => (filter.currentType != 2) ? 17 : 14)));
				}
				return val.InstructionEnumeration();
			}

			public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				return RowLength(instructions, 2);
			}

			public static IEnumerable<CodeInstruction> TestMouseIndex_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				return RowLength(instructions, 4);
			}

			public static IEnumerable<CodeInstruction> UILootFilter_OnBoxMouseDown_currentTypeField_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				return CurrentType(instructions);
			}

			public static IEnumerable<CodeInstruction> UILootFilter_SetMaterialProps_currentTypeField_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				return CurrentType(instructions);
			}

			public static IEnumerable<CodeInstruction> UILootFilter_RefreshIcons_currentTypeField_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				return PickPage(CurrentType(instructions));
			}

			internal static IEnumerable<CodeInstruction> CurrentType(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Expected O, but got Unknown
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[4]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)currentTypeField, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_2, (object)null, (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Blt || i.opcode == OpCodes.Blt_S || i.opcode == OpCodes.Bge || i.opcode == OpCodes.Bge_S), (string)null)
				};
				val.MatchForward(true, array);
				do
				{
					OpCode opcode = val.Opcode;
					opcode = ((opcode == OpCodes.Blt) ? OpCodes.Bne_Un : ((opcode == OpCodes.Blt_S) ? OpCodes.Bne_Un_S : ((!(opcode == OpCodes.Bge)) ? OpCodes.Beq_S : OpCodes.Beq)));
					val.SetOpcodeAndAdvance(opcode);
					val.MatchForward(true, array);
				}
				while (val.IsValid);
				return val.InstructionEnumeration();
			}

			private static IEnumerable<CodeInstruction> PickPage(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Expected O, but got Unknown
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)currentTypeField, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
					Op.Add
				});
				val.Advance(1).SetAndAdvance(OpCodes.Call, (object)AccessTools.Method(typeof(UILootFilterPatches), "GetPickPage", (Type[])null, (Type[])null)).SetAndAdvance(OpCodes.Nop, (object)null)
					.SetAndAdvance(OpCodes.Nop, (object)null);
				return val.InstructionEnumeration();
			}

			internal static int GetPickPage(UILootFilter filter)
			{
				if (filter.currentType >= 2)
				{
					return filter.currentType;
				}
				return filter.currentType + 1;
			}

			public static void RefreshWindow_Postfix(UILootFilter __instance)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				__instance.contentTrans.sizeDelta = ((__instance.currentType == 2) ? new Vector2(644f, 414f) : new Vector2(782f, 322f));
				bool active = !__instance.showDropOnly;
				foreach (UITabButton tab in Tabs)
				{
					((Component)tab).gameObject.SetActive(active);
				}
			}

			public static IEnumerable<CodeInstruction> UILootFilter_SetMaterialProps_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Expected O, but got Unknown
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_8, (object)null, (string)null)
				});
				val.SetOpcodeAndAdvance(OpCodes.Ldc_I4_7);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)14f, (string)null)
				});
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null)
				}).SetInstructionAndAdvance(Transpilers.EmitDelegate<Func<UILootFilter, float>>((Func<UILootFilter, float>)((UILootFilter filter) => (filter.currentType != 2) ? 17f : 14f)));
				return val.InstructionEnumeration();
			}
		}

		public static class UIOptionWindowPatches
		{
			public static void UIOptionWindow_OnRevertButtonClick_Postfix(int idx)
			{
				if (idx == 4 || idx == -1)
				{
					UIOptionWindowPatches.Reset();
				}
			}
		}

		private const sbyte VeinTypeCount = 21;
	}
	internal static class Additions
	{
		private const int DarkFogGravitonLensItem = 1211;

		private const int DarkFogGravitonLensRecipe = 162;

		private const int AccumulatorFull = 2207;

		[HarmonyPatch(typeof(UILootFilter), "_OnUpdate")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> UILootFilter_OnUpdate_currentTypeField_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			return Upstream.UILootFilterPatches.CurrentType(instructions);
		}

		[HarmonyPatch(typeof(UILootFilter), "TestMouseIndex")]
		[HarmonyPostfix]
		private static void UILootFilter_TestMouseIndex_Postfix(ref int ___hoveredIndex, ItemProto[] ___protoArray, Image ___selImage)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (___protoArray != null && ___hoveredIndex >= ___protoArray.Length)
			{
				___hoveredIndex = -1;
				((Graphic)___selImage).rectTransform.anchoredPosition = new Vector2(-1f, 1f);
				((Component)___selImage).gameObject.SetActive(false);
			}
		}

		[HarmonyPatch(typeof(SectorModel), "OnCameraPostRender")]
		[HarmonyPrefix]
		private static bool SectorModel_OnCameraPostRender_Prefix()
		{
			Player mainPlayer = GameMain.mainPlayer;
			if (mainPlayer != null && (Object)(object)mainPlayer.controller != (Object)null)
			{
				return mainPlayer.controller.actionBuild != null;
			}
			return false;
		}

		[HarmonyPatch(typeof(GameMain), "CreateStarmapGPUInstancing")]
		[HarmonyPostfix]
		private static void GameMain_CreateStarmapGPUInstancing_Postfix()
		{
			SectorModel val = GameMain.data?.spaceSector?.model;
			if ((Object)(object)val != (Object)null && val.starmapgpuiManager != null)
			{
				val.starmapgpuiManager = GameMain.starmapgpuiManager;
			}
		}

		[HarmonyPatch(typeof(JsonDataUtils), "ImportJson")]
		[HarmonyPostfix]
		private static void JsonDataUtils_ImportJson_Postfix(int[] tableID)
		{
			int gridIndex = (tableID[1] - 4) * 1000 + 4717;
			if (((ProtoSet<ItemProto>)(object)LDB.items).Exist(1211))
			{
				((ProtoSet<ItemProto>)(object)LDB.items).Select(1211).GridIndex = gridIndex;
			}
			if (((ProtoSet<RecipeProto>)(object)LDB.recipes).Exist(162))
			{
				((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(162).GridIndex = gridIndex;
			}
			if (((ProtoSet<ItemProto>)(object)LDB.items).Exist(2207))
			{
				((ProtoSet<ItemProto>)(object)LDB.items).Select(2207).GridIndex = 2115;
			}
		}
	}
}