Use Single() over First() in reflection to ensure correct match
This commit is contained in:
		@@ -48,10 +48,10 @@ namespace UIFixes
 | 
				
			|||||||
        public static void Enable()
 | 
					        public static void Enable()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // The context menus in the inventory and the trading screen inventory are *completely different code*
 | 
					            // The context menus in the inventory and the trading screen inventory are *completely different code*
 | 
				
			||||||
            InventoryRootInteractionsType = PatchConstants.EftTypes.First(t => t.GetField("HIDEOUT_WEAPON_MODIFICATION_REQUIRED") != null); // GClass3023
 | 
					            InventoryRootInteractionsType = PatchConstants.EftTypes.Single(t => t.GetField("HIDEOUT_WEAPON_MODIFICATION_REQUIRED") != null); // GClass3023
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // GClass3032 - this is nuts to find, have to inspect a static enum array
 | 
					            // GClass3032 - this is nuts to find, have to inspect a static enum array
 | 
				
			||||||
            TradingRootInteractionsType = PatchConstants.EftTypes.First(t =>
 | 
					            TradingRootInteractionsType = PatchConstants.EftTypes.Single(t =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var enumerableField = t.GetField("ienumerable_2", BindingFlags.NonPublic | BindingFlags.Static);
 | 
					                var enumerableField = t.GetField("ienumerable_2", BindingFlags.NonPublic | BindingFlags.Static);
 | 
				
			||||||
                if (enumerableField != null)
 | 
					                if (enumerableField != null)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -442,7 +442,7 @@ namespace UIFixes
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            protected override MethodBase GetTargetMethod()
 | 
					            protected override MethodBase GetTargetMethod()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type type = PatchConstants.EftTypes.First(t => t.GetMethod("CheckItemFilter", BindingFlags.Public | BindingFlags.Static) != null); // GClass2510
 | 
					                Type type = PatchConstants.EftTypes.Single(t => t.GetMethod("CheckItemFilter", BindingFlags.Public | BindingFlags.Static) != null); // GClass2510
 | 
				
			||||||
                return AccessTools.Method(type, "CheckItemFilter");
 | 
					                return AccessTools.Method(type, "CheckItemFilter");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								R.cs
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								R.cs
									
									
									
									
									
								
							@@ -105,7 +105,7 @@ namespace UIFixes
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = typeof(EFT.Hideout.ProductionPanel).GetNestedTypes().First(t => t.GetField("availableSearch") != null); // ProductionPanel.Class1631
 | 
					                Type = typeof(EFT.Hideout.ProductionPanel).GetNestedTypes().Single(t => t.GetField("availableSearch") != null); // ProductionPanel.Class1631
 | 
				
			||||||
                ProductionPanelField = AccessTools.Field(Type, "productionPanel_0");
 | 
					                ProductionPanelField = AccessTools.Field(Type, "productionPanel_0");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -119,7 +119,7 @@ namespace UIFixes
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = PatchConstants.EftTypes.First(t => t.GetField("endProduct") != null); // GClass1923
 | 
					                Type = PatchConstants.EftTypes.Single(t => t.GetField("endProduct") != null); // GClass1923
 | 
				
			||||||
                EndProductField = AccessTools.Field(Type, "endProduct");
 | 
					                EndProductField = AccessTools.Field(Type, "endProduct");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -150,8 +150,8 @@ namespace UIFixes
 | 
				
			|||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = typeof(EFT.UI.ItemSpecificationPanel);
 | 
					                Type = typeof(EFT.UI.ItemSpecificationPanel);
 | 
				
			||||||
                CompactCharacteristicPanelsField = AccessTools.GetDeclaredFields(Type).First(f => typeof(IEnumerable<KeyValuePair<ItemAttributeClass, EFT.UI.CompactCharacteristicPanel>>).IsAssignableFrom(f.FieldType));
 | 
					                CompactCharacteristicPanelsField = AccessTools.GetDeclaredFields(Type).Single(f => typeof(IEnumerable<KeyValuePair<ItemAttributeClass, EFT.UI.CompactCharacteristicPanel>>).IsAssignableFrom(f.FieldType));
 | 
				
			||||||
                CompactCharacteristicDropdownsField = AccessTools.GetDeclaredFields(Type).First(f => typeof(IEnumerable<KeyValuePair<ItemAttributeClass, EFT.UI.CompactCharacteristicDropdownPanel>>).IsAssignableFrom(f.FieldType));
 | 
					                CompactCharacteristicDropdownsField = AccessTools.GetDeclaredFields(Type).Single(f => typeof(IEnumerable<KeyValuePair<ItemAttributeClass, EFT.UI.CompactCharacteristicDropdownPanel>>).IsAssignableFrom(f.FieldType));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                RefreshMethod = AccessTools.Method(Type, nameof(EFT.UI.ItemSpecificationPanel.smethod_1), null, [typeof(EFT.UI.CompactCharacteristicPanel)]);
 | 
					                RefreshMethod = AccessTools.Method(Type, nameof(EFT.UI.ItemSpecificationPanel.smethod_1), null, [typeof(EFT.UI.CompactCharacteristicPanel)]);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -205,7 +205,7 @@ namespace UIFixes
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = PatchConstants.EftTypes.First(t => typeof(ItemAddress).IsAssignableFrom(t) && t.GetProperty("Grid") != null); // GClass2769
 | 
					                Type = PatchConstants.EftTypes.Single(t => typeof(ItemAddress).IsAssignableFrom(t) && t.GetProperty("Grid") != null); // GClass2769
 | 
				
			||||||
                LocationInGridField = AccessTools.Field(Type, "LocationInGrid");
 | 
					                LocationInGridField = AccessTools.Field(Type, "LocationInGrid");
 | 
				
			||||||
                GridProperty = AccessTools.Property(Type, "Grid");
 | 
					                GridProperty = AccessTools.Property(Type, "Grid");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -226,7 +226,7 @@ namespace UIFixes
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = PatchConstants.EftTypes.First(t => typeof(ItemAddress).IsAssignableFrom(t) && t.GetField("Slot") != null); // GClass2767
 | 
					                Type = PatchConstants.EftTypes.Single(t => typeof(ItemAddress).IsAssignableFrom(t) && t.GetField("Slot") != null); // GClass2767
 | 
				
			||||||
                SlotField = AccessTools.Field(Type, "Slot");
 | 
					                SlotField = AccessTools.Field(Type, "Slot");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -247,7 +247,7 @@ namespace UIFixes
 | 
				
			|||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = typeof(EFT.UI.DragAndDrop.GridView);
 | 
					                Type = typeof(EFT.UI.DragAndDrop.GridView);
 | 
				
			||||||
                TraderControllerField = AccessTools.GetDeclaredFields(Type).First(f => f.FieldType == typeof(TraderControllerClass));
 | 
					                TraderControllerField = AccessTools.GetDeclaredFields(Type).Single(f => f.FieldType == typeof(TraderControllerClass));
 | 
				
			||||||
                NonInteractableField = AccessTools.Field(Type, "_nonInteractable");
 | 
					                NonInteractableField = AccessTools.Field(Type, "_nonInteractable");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -280,7 +280,7 @@ namespace UIFixes
 | 
				
			|||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = AccessTools.Method(typeof(InteractionsHandlerClass), nameof(InteractionsHandlerClass.Swap)).ReturnType; // GStruct414<GClass2797>
 | 
					                Type = AccessTools.Method(typeof(InteractionsHandlerClass), nameof(InteractionsHandlerClass.Swap)).ReturnType; // GStruct414<GClass2797>
 | 
				
			||||||
                ImplicitCastToGridViewCanAcceptOperationMethod = Type.GetMethods().First(m => m.Name == "op_Implicit" && m.ReturnType == GridViewCanAcceptOperation.Type);
 | 
					                ImplicitCastToGridViewCanAcceptOperationMethod = Type.GetMethods().Single(m => m.Name == "op_Implicit" && m.ReturnType == GridViewCanAcceptOperation.Type);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            public object ToGridViewCanAcceptOperation() => ImplicitCastToGridViewCanAcceptOperationMethod.Invoke(null, [Value]);
 | 
					            public object ToGridViewCanAcceptOperation() => ImplicitCastToGridViewCanAcceptOperationMethod.Invoke(null, [Value]);
 | 
				
			||||||
@@ -409,7 +409,7 @@ namespace UIFixes
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = PatchConstants.EftTypes.First(t => t.GetMethod("GetAllQuestTemplates") != null); // GClass3212
 | 
					                Type = PatchConstants.EftTypes.Single(t => t.GetMethod("GetAllQuestTemplates") != null); // GClass3212
 | 
				
			||||||
                InstanceProperty = AccessTools.Property(Type, "Instance");
 | 
					                InstanceProperty = AccessTools.Property(Type, "Instance");
 | 
				
			||||||
                GetAllQuestTemplatesMethod = AccessTools.Method(Type, "GetAllQuestTemplates");
 | 
					                GetAllQuestTemplatesMethod = AccessTools.Method(Type, "GetAllQuestTemplates");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -447,7 +447,7 @@ namespace UIFixes
 | 
				
			|||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = typeof(EFT.UI.Ragfair.AddOfferWindow);
 | 
					                Type = typeof(EFT.UI.Ragfair.AddOfferWindow);
 | 
				
			||||||
                RagfairField = AccessTools.GetDeclaredFields(Type).First(t => t.FieldType == typeof(RagFairClass));
 | 
					                RagfairField = AccessTools.GetDeclaredFields(Type).Single(t => t.FieldType == typeof(RagFairClass));
 | 
				
			||||||
                BulkOfferField = AccessTools.Field(Type, "bool_0");
 | 
					                BulkOfferField = AccessTools.Field(Type, "bool_0");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -463,7 +463,7 @@ namespace UIFixes
 | 
				
			|||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = typeof(EFT.UI.ItemUiContext);
 | 
					                Type = typeof(EFT.UI.ItemUiContext);
 | 
				
			||||||
                InventoryControllerField = AccessTools.GetDeclaredFields(Type).First(t => t.FieldType == typeof(InventoryControllerClass));
 | 
					                InventoryControllerField = AccessTools.GetDeclaredFields(Type).Single(t => t.FieldType == typeof(InventoryControllerClass));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            public InventoryControllerClass InventoryController { get { return (InventoryControllerClass)InventoryControllerField.GetValue(Value); } }
 | 
					            public InventoryControllerClass InventoryController { get { return (InventoryControllerClass)InventoryControllerField.GetValue(Value); } }
 | 
				
			||||||
@@ -476,7 +476,7 @@ namespace UIFixes
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = PatchConstants.EftTypes.First(t => t.GetMethod("GetMoneySums", BindingFlags.Public | BindingFlags.Static) != null);
 | 
					                Type = PatchConstants.EftTypes.Single(t => t.GetMethod("GetMoneySums", BindingFlags.Public | BindingFlags.Static) != null);
 | 
				
			||||||
                GetMoneySumsMethod = AccessTools.Method(Type, "GetMoneySums");
 | 
					                GetMoneySumsMethod = AccessTools.Method(Type, "GetMoneySums");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -514,7 +514,7 @@ namespace UIFixes
 | 
				
			|||||||
            public static void InitTypes()
 | 
					            public static void InitTypes()
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Type = typeof(EFT.UI.DragAndDrop.TradingItemView);
 | 
					                Type = typeof(EFT.UI.DragAndDrop.TradingItemView);
 | 
				
			||||||
                TraderAssortmentControllerField = AccessTools.GetDeclaredFields(Type).First(t => t.FieldType == typeof(TraderAssortmentControllerClass));
 | 
					                TraderAssortmentControllerField = AccessTools.GetDeclaredFields(Type).Single(t => t.FieldType == typeof(TraderAssortmentControllerClass));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            public TraderAssortmentControllerClass TraderAssortmentControler { get { return (TraderAssortmentControllerClass)TraderAssortmentControllerField.GetValue(Value); } }
 | 
					            public TraderAssortmentControllerClass TraderAssortmentControler { get { return (TraderAssortmentControllerClass)TraderAssortmentControllerField.GetValue(Value); } }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -96,7 +96,7 @@ namespace UIFixes
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            configEntries.Add(KeepMessagesOpen = config.Bind(
 | 
					            configEntries.Add(KeepMessagesOpen = config.Bind(
 | 
				
			||||||
                GeneralSection,
 | 
					                GeneralSection,
 | 
				
			||||||
                "Keep Messages Window Open After Transfer",
 | 
					                "Keep Messages Window Open",
 | 
				
			||||||
                true,
 | 
					                true,
 | 
				
			||||||
                new ConfigDescription(
 | 
					                new ConfigDescription(
 | 
				
			||||||
                    "After receiving items from a transfer, reopen the messages window where you left off",
 | 
					                    "After receiving items from a transfer, reopen the messages window where you left off",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user