Code cleanup

This commit is contained in:
Tyfon
2024-05-20 02:14:36 -07:00
parent 15a5e120b3
commit 1853233dd3
17 changed files with 154 additions and 193 deletions

View File

@@ -14,14 +14,14 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
MethodInfo method = AccessTools.Method(typeof(InteractionsHandlerClass), "smethod_0");
MethodInfo method = AccessTools.Method(typeof(InteractionsHandlerClass), nameof(InteractionsHandlerClass.smethod_0));
MergeableItemType = method.GetParameters()[2].ParameterType.GetElementType(); // parameter is a ref type, get underlying type
return method;
}
// Reimplementing this entire method to ignore SpawnedInSession for certain types
[PatchPrefix]
private static bool Prefix(IEnumerable<StashGridClass> gridsToPut, Item itemToMerge, ref object mergeableItem, int overrideCount, ref bool __result)
public static bool Prefix(IEnumerable<StashGridClass> gridsToPut, Item itemToMerge, ref object mergeableItem, int overrideCount, ref bool __result)
{
if (!MergeableItemType.IsInstanceOfType(itemToMerge))
{

View File

@@ -32,7 +32,7 @@ namespace UIFixes
}
[PatchPostfix]
private static void Postfix(object __instance, bool ___bool_0)
public static void Postfix(object __instance, bool ___bool_0)
{
if (!___bool_0)
{
@@ -52,11 +52,13 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
// The parent has a Show() so need to be specific
return typeof(HandoverRagfairMoneyWindow).GetMethods().First(m => m.Name == "Show" && m.GetParameters()[0].ParameterType == typeof(Inventory));
return AccessTools.GetDeclaredMethods(typeof(HandoverRagfairMoneyWindow)).First(
m => m.Name == nameof(HandoverRagfairMoneyWindow.Show) &&
m.GetParameters()[0].ParameterType == typeof(Inventory));
}
[PatchPostfix]
private static void Postfix(TMP_InputField ____inputField)
public static void Postfix(TMP_InputField ____inputField)
{
____inputField.contentType = TMP_InputField.ContentType.IntegerNumber;
____inputField.ActivateInputField();

View File

@@ -8,19 +8,20 @@ namespace UIFixes
{
public class DisabledActionsPatch : ModulePatch
{
private static string[] UnimplementedActions = ["Bang & clear", "Flash & clear", "Move in"];
private static readonly string[] UnimplementedActions = ["Bang & clear", "Flash & clear", "Move in"];
protected override MethodBase GetTargetMethod()
{
Type type = typeof(GetActionsClass);
return AccessTools.GetDeclaredMethods(type).FirstOrDefault(x =>
{
var parameters = x.GetParameters();
return x.Name == "GetAvailableActions" && parameters[0].Name == "owner";
return x.Name == nameof(GetActionsClass.GetAvailableActions) && parameters[0].Name == "owner";
});
}
[PatchPostfix]
private static void Postfix(ref ActionsReturnClass __result)
public static void Postfix(ref ActionsReturnClass __result)
{
if (Settings.RemoveDisabledActions.Value && __result != null)
{

View File

@@ -1,5 +1,6 @@
using Aki.Reflection.Patching;
using EFT.UI;
using HarmonyLib;
using System;
using System.Linq;
using System.Reflection;
@@ -25,11 +26,11 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
Type type = typeof(EditBuildScreen).GetNestedTypes().Single(x => x.GetMethod("CloseScreenInterruption") != null); // EditBuildScreen.GClass3126
return type.GetMethod("CloseScreenInterruption");
return AccessTools.Method(type, "CloseScreenInterruption");
}
[PatchPrefix]
private static void Prefix(bool moveForward)
public static void Prefix(bool moveForward)
{
MoveForward = moveForward;
}
@@ -39,12 +40,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(EditBuildScreen);
return type.GetMethod("method_35");
return AccessTools.Method(typeof(EditBuildScreen), nameof(EditBuildScreen.method_35));
}
[PatchPrefix]
private static bool Prefix(ref Task<bool> __result)
public static bool Prefix(ref Task<bool> __result)
{
if (MoveForward && Settings.ShowPresetConfirmations.Value == WeaponPresetConfirmationOption.Always)
{
@@ -56,7 +56,7 @@ namespace UIFixes
return true;
}
__result = Task.FromResult<bool>(true);
__result = Task.FromResult(true);
return false;
}
}

View File

@@ -41,32 +41,30 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ItemSpecificationPanel), "method_5");
return AccessTools.Method(typeof(ItemSpecificationPanel), nameof(ItemSpecificationPanel.method_5));
}
[PatchPostfix]
private static void Postfix(
public static void Postfix(
ItemSpecificationPanel __instance,
Item ___item_0,
CompactCharacteristicPanel ____compactCharTemplate,
Transform ____compactPanel,
SimpleTooltip ___simpleTooltip_0)
{
if (!Settings.ShowModStats.Value || !(___item_0 is Mod))
if (!Settings.ShowModStats.Value || ___item_0 is not Mod)
{
return;
}
bool changed;
var deepAttributes = GetDeepAttributes(___item_0, out changed);
var deepAttributes = GetDeepAttributes(___item_0, out bool changed);
if (!changed)
{
return;
}
var compactPanels = AttributeCompactPanelDictionaryField.GetValue(__instance) as IDisposable;
// Clean up existing one
if (compactPanels != null)
if (AttributeCompactPanelDictionaryField.GetValue(__instance) is IDisposable compactPanels)
{
compactPanels.Dispose();
}
@@ -110,13 +108,13 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
RefreshStaticMethod = AccessTools.Method(typeof(ItemSpecificationPanel), "smethod_1", null, [typeof(CompactCharacteristicPanel)]);
RefreshStaticMethod = AccessTools.Method(typeof(ItemSpecificationPanel), nameof(ItemSpecificationPanel.smethod_1), null, [typeof(CompactCharacteristicPanel)]);
return AccessTools.Method(typeof(ItemSpecificationPanel), "method_6");
return AccessTools.Method(typeof(ItemSpecificationPanel), nameof(ItemSpecificationPanel.method_6));
}
[PatchPrefix]
private static void Prefix(Item compareItem)
public static void Prefix(Item compareItem)
{
if (compareItem == null)
{
@@ -129,26 +127,27 @@ namespace UIFixes
{
float maxDurability = armorComponents.Sum(c => c.Repairable.Durability);
ItemAttributeClass itemAttributeClass = new ItemAttributeClass(EItemAttributeId.ArmorPoints);
itemAttributeClass.Name = EItemAttributeId.ArmorPoints.GetName();
itemAttributeClass.Base = () => maxDurability;
itemAttributeClass.StringValue = () => Math.Round(maxDurability, 1).ToString(CultureInfo.InvariantCulture);
itemAttributeClass.DisplayType = () => EItemAttributeDisplayType.Compact;
var itemAttributeClass = new ItemAttributeClass(EItemAttributeId.ArmorPoints)
{
Name = EItemAttributeId.ArmorPoints.GetName(),
Base = () => maxDurability,
StringValue = () => Math.Round(maxDurability, 1).ToString(CultureInfo.InvariantCulture),
DisplayType = () => EItemAttributeDisplayType.Compact
};
compareItem.Attributes.Insert(0, itemAttributeClass);
}
}
[PatchPostfix]
private static void Postfix(ItemSpecificationPanel __instance, Item compareItem)
public static void Postfix(ItemSpecificationPanel __instance, Item compareItem)
{
if (!Settings.ShowModStats.Value || !(compareItem is Mod))
if (!Settings.ShowModStats.Value || compareItem is not Mod)
{
return;
}
bool changed;
List<ItemAttributeClass> deepAttributes = GetDeepAttributes(compareItem, out changed);
List<ItemAttributeClass> deepAttributes = GetDeepAttributes(compareItem, out bool changed);
if (!changed)
{
return;
@@ -179,7 +178,7 @@ namespace UIFixes
SimpleContextMenuButtonTextField = AccessTools.Field(typeof(ContextMenuButton), "_text");
return AccessTools.Method(typeof(ItemSpecificationPanel), "method_4");
return AccessTools.Method(typeof(ItemSpecificationPanel), nameof(ItemSpecificationPanel.method_4));
}
private static string GetLabel()
@@ -188,9 +187,9 @@ namespace UIFixes
}
[PatchPostfix]
private static void Postfix(ItemSpecificationPanel __instance, ItemInfoInteractionsAbstractClass<EItemInfoButton> contextInteractions, Item ___item_0, InteractionButtonsContainer ____interactionButtonsContainer)
public static void Postfix(ItemSpecificationPanel __instance, ItemInfoInteractionsAbstractClass<EItemInfoButton> contextInteractions, Item ___item_0, InteractionButtonsContainer ____interactionButtonsContainer)
{
if (!(___item_0 is Mod))
if (___item_0 is not Mod)
{
return;
}
@@ -200,25 +199,28 @@ namespace UIFixes
SimpleContextMenuButton toggleButton = null;
Action onClick = () => Settings.ShowModStats.Value = !Settings.ShowModStats.Value;
// Listen to the setting and the work there to handle multiple windows open at once
EventHandler onSettingChanged = (sender, args) =>
void onSettingChanged(object sender, EventArgs args)
{
var text = SimpleContextMenuButtonTextField.GetValue(toggleButton) as TextMeshProUGUI;
text.text = GetLabel();
__instance.method_5(); // rebuild stat panels
};
}
Settings.ShowModStats.SettingChanged += onSettingChanged;
Action createButton = () =>
static void onClick()
{
Settings.ShowModStats.Value = !Settings.ShowModStats.Value;
}
void createButton()
{
Sprite sprite = CacheResourcesPopAbstractClass.Pop<Sprite>("Characteristics/Icons/Modding");
toggleButton = UnityEngine.Object.Instantiate(template, transform, false);
toggleButton.Show(GetLabel(), null, sprite, onClick, null);
____interactionButtonsContainer.method_5(toggleButton); // add to disposable list
};
}
// Subscribe to redraws to recreate when mods get dropped in
contextInteractions.OnRedrawRequired += createButton;
@@ -238,11 +240,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(CompactCharacteristicPanel), "SetValues");
return AccessTools.Method(typeof(CompactCharacteristicPanel), nameof(CompactCharacteristicPanel.SetValues));
}
[PatchPostfix]
private static void Postfix(CompactCharacteristicPanel __instance, TextMeshProUGUI ___ValueText)
public static void Postfix(CompactCharacteristicPanel __instance, TextMeshProUGUI ___ValueText)
{
try
{
@@ -262,14 +264,14 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
RoundToIntMethod = AccessTools.Method(typeof(Mathf), "RoundToInt");
ToStringMethod = AccessTools.Method(typeof(float), "ToString", [typeof(string)]);
RoundToIntMethod = AccessTools.Method(typeof(Mathf), nameof(Mathf.RoundToInt));
ToStringMethod = AccessTools.Method(typeof(float), nameof(float.ToString), [typeof(string)]);
return AccessTools.Method(typeof(CharacteristicPanel), "SetValues");
return AccessTools.Method(typeof(CharacteristicPanel), nameof(CharacteristicPanel.SetValues));
}
[PatchPostfix]
private static void Postfix(CharacteristicPanel __instance, TextMeshProUGUI ___ValueText)
public static void Postfix(CharacteristicPanel __instance, TextMeshProUGUI ___ValueText)
{
try
{
@@ -283,7 +285,7 @@ namespace UIFixes
// This transpiler looks for where it rounds a float to an int, and skips that. Instead it calls ToString("0.0#") on it
[PatchTranspiler]
private static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
{
int skip = 0;
CodeInstruction lastInstruction = null;
@@ -351,18 +353,15 @@ namespace UIFixes
// Completely redo it
if ((EItemAttributeId)attribute.Id == EItemAttributeId.CenterOfImpact)
{
ItemAttributeClass compareAttribute = CompactCharacteristicPanelCompareItemAttributeField.GetValue(panel) as ItemAttributeClass;
if (compareAttribute != null)
if (CompactCharacteristicPanelCompareItemAttributeField.GetValue(panel) is ItemAttributeClass compareAttribute)
{
string currentStringValue = attribute.StringValue();
var moaMatch = Regex.Match(currentStringValue, @"^(\S+)");
float moa;
if (float.TryParse(moaMatch.Groups[1].Value, out moa))
if (float.TryParse(moaMatch.Groups[1].Value, out float moa))
{
string compareStringValue = compareAttribute.StringValue();
moaMatch = Regex.Match(compareStringValue, @"^(\S+)");
float compareMoa;
if (float.TryParse(moaMatch.Groups[1].Value, out compareMoa))
if (float.TryParse(moaMatch.Groups[1].Value, out float compareMoa))
{
float delta = compareMoa - moa;
string final = currentStringValue;
@@ -384,9 +383,8 @@ namespace UIFixes
var match = Regex.Match(text, @" %\(([+-].*)\)");
if (match.Success)
{
float value;
// If this fails to parse, I don't know what it is, leave it be
if (float.TryParse(match.Groups[1].Value, out value))
if (float.TryParse(match.Groups[1].Value, out float value))
{
string sign = value > 0 ? "+" : "";
string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? IncreasingColorHex : DecreasingColorHex;
@@ -408,9 +406,8 @@ namespace UIFixes
match = Regex.Match(text, @"(\S)%\(([+-].*)\)");
if (match.Success)
{
float value;
// If this fails to parse, I don't know what it is, leave it be
if (float.TryParse(match.Groups[2].Value, out value))
if (float.TryParse(match.Groups[2].Value, out float value))
{
string sign = value > 0 ? "+" : "";
string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? IncreasingColorHex : DecreasingColorHex;
@@ -423,9 +420,8 @@ namespace UIFixes
match = Regex.Match(text, @"\(([+-].*)\)");
if (match.Success)
{
float value;
// If this fails to parse, I don't know what it is, leave it be
if (float.TryParse(match.Groups[1].Value, out value))
if (float.TryParse(match.Groups[1].Value, out float value))
{
string sign = value > 0 ? "+" : "";
string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? IncreasingColorHex : DecreasingColorHex;
@@ -471,7 +467,7 @@ namespace UIFixes
private static IEnumerable<ItemAttributeClass> CombineAttributes(IList<ItemAttributeClass> first, IList<ItemAttributeClass> second)
{
foreach (EItemAttributeId id in first.Select(a => a.Id).Union(second.Select(a => a.Id)))
foreach (EItemAttributeId id in first.Select(a => a.Id).Union(second.Select(a => a.Id)).Select(v => (EItemAttributeId)v))
{
// Need to cast the id since it's of type Enum for some reason
var attribute = first.FirstOrDefault(a => (EItemAttributeId)a.Id == id);

View File

@@ -35,11 +35,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(StretchArea), "OnDrag");
return AccessTools.Method(typeof(StretchArea), nameof(StretchArea.OnDrag));
}
[PatchPostfix]
private static void Postfix(LayoutElement ___layoutElement_0)
public static void Postfix(LayoutElement ___layoutElement_0)
{
if (!Settings.RememberInspectSize.Value || ___layoutElement_0.GetComponent<ItemSpecificationPanel>() == null)
{
@@ -62,11 +62,11 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ItemSpecificationPanel), "Show");
return AccessTools.Method(typeof(ItemSpecificationPanel), nameof(ItemSpecificationPanel.Show));
}
[PatchPrefix]
private static void Prefix(LayoutElement ___layoutElement_0)
public static void Prefix(LayoutElement ___layoutElement_0)
{
if (Settings.RememberInspectSize.Value)
{
@@ -75,7 +75,7 @@ namespace UIFixes
}
[PatchPostfix]
private static void Postfix(ItemSpecificationPanel __instance, LayoutElement ___layoutElement_0)
public static void Postfix(ItemSpecificationPanel __instance, LayoutElement ___layoutElement_0)
{
if (Settings.LockInspectPreviewSize.Value)
{
@@ -191,7 +191,7 @@ namespace UIFixes
LayoutRebuilder.ForceRebuildLayoutImmediate(layoutRect);
layoutRect.CorrectPositionResolution(default(MarginsStruct));
layoutRect.CorrectPositionResolution(default);
}
}
@@ -217,11 +217,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ItemUiContext), "Inspect");
return AccessTools.Method(typeof(ItemUiContext), nameof(ItemUiContext.Inspect));
}
[PatchPostfix]
private static void Postfix(List<InputNode> ____children)
public static void Postfix(List<InputNode> ____children)
{
var inspectWindow = ____children.Last();
if (inspectWindow != null)

View File

@@ -1,5 +1,6 @@
using Aki.Reflection.Patching;
using EFT.UI.Chat;
using HarmonyLib;
using System;
using System.Reflection;
@@ -9,12 +10,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(ChatMessageSendBlock);
return type.GetMethod("Show", BindingFlags.Public | BindingFlags.Instance);
return AccessTools.Method(typeof(ChatMessageSendBlock), nameof(ChatMessageSendBlock.Show));
}
[PatchPrefix]
private static void Prefix(DialogueClass dialogue)
public static void Prefix(DialogueClass dialogue)
{
// Force this false will recalculate each time. This is less than ideal, but the way the code is structured makes it very difficult to do correctly.
dialogue.HasMessagesWithRewards = false;

View File

@@ -15,7 +15,7 @@ namespace UIFixes
private static FieldInfo ProductionPanelSearch;
private static FieldInfo SubstrateContentLayoutField;
private static Dictionary<string, string> LastSearches = [];
private static readonly Dictionary<string, string> LastSearches = [];
public static void Enable()
{
@@ -45,7 +45,7 @@ namespace UIFixes
}
[PatchPostfix]
private static void Postfix(ProductionPanel.Class1631 __instance, GClass1923 scheme, ProduceView view)
public static void Postfix(ProductionPanel.Class1631 __instance, GClass1923 scheme, ProduceView view)
{
var searchField = ProductionPanelSearch.GetValue(__instance.productionPanel_0) as ValidationInputField;
if (searchField.text.Length > 0 && scheme.endProduct.LocalizedName().IndexOf(searchField.text, StringComparison.InvariantCultureIgnoreCase) < 0)
@@ -61,21 +61,20 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ProductionPanel), "ShowContents");
return AccessTools.Method(typeof(ProductionPanel), nameof(ProductionPanel.ShowContents));
}
[PatchPrefix]
private static void Prefix(ProductionPanel __instance, ValidationInputField ____searchInputField)
public static void Prefix(ProductionPanel __instance, ValidationInputField ____searchInputField)
{
string lastSearch;
if (LastSearches.TryGetValue(__instance.AreaData.ToString(), out lastSearch))
if (LastSearches.TryGetValue(__instance.AreaData.ToString(), out string lastSearch))
{
____searchInputField.text = lastSearch;
}
}
[PatchPostfix]
private static void Postfix(ProductionPanel __instance, ValidationInputField ____searchInputField)
public static void Postfix(ProductionPanel __instance, ValidationInputField ____searchInputField)
{
// Force it to render immediately, at full height, even if the search filtering would reduce the number of children
if (__instance.method_4().Count() > 2)
@@ -96,13 +95,13 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ProductionPanel), "method_4");
return AccessTools.Method(typeof(ProductionPanel), nameof(ProductionPanel.method_4));
}
// Working with GClasses directly here, because this would be a nightmare with reflection
// Copied directly from method_4
[PatchPrefix]
private static bool Prefix(ref IEnumerable<GClass1923> __result, ProductionPanel __instance, GClass1922[] ___gclass1922_0, ValidationInputField ____searchInputField)
public static bool Prefix(ref IEnumerable<GClass1923> __result, ProductionPanel __instance, GClass1922[] ___gclass1922_0, ValidationInputField ____searchInputField)
{
__result = ___gclass1922_0.OfType<GClass1923>().Where(scheme => !scheme.locked)
.OrderBy(scheme => scheme.endProduct.LocalizedName().Contains(____searchInputField.text) ? 0 : 1) // search-matching items first
@@ -119,11 +118,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ProductionPanel), "method_9");
return AccessTools.Method(typeof(ProductionPanel), nameof(ProductionPanel.method_9));
}
[PatchPrefix]
private static void Prefix(ProductionPanel __instance)
public static void Prefix(ProductionPanel __instance)
{
__instance.method_8(); // update sort order
}
@@ -134,11 +133,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ProductionPanel), "Close");
return AccessTools.Method(typeof(ProductionPanel), nameof(ProductionPanel.Close));
}
[PatchPrefix]
private static void Prefix(ProductionPanel __instance, ValidationInputField ____searchInputField)
public static void Prefix(ProductionPanel __instance, ValidationInputField ____searchInputField)
{
LastSearches[__instance.AreaData.ToString()] = ____searchInputField.text;
@@ -154,11 +153,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(HideoutScreenOverlay), "ReturnToPreviousState");
return AccessTools.Method(typeof(HideoutScreenOverlay), nameof(HideoutScreenOverlay.ReturnToPreviousState));
}
[PatchPostfix]
private static void Postfix()
public static void Postfix()
{
LastSearches.Clear();
}

View File

@@ -126,23 +126,18 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(SimpleStashPanel);
return type.GetMethod("Update", BindingFlags.Public | BindingFlags.Instance);
return AccessTools.Method(typeof(SimpleStashPanel), nameof(SimpleStashPanel.Update));
}
[PatchPrefix]
private static void Prefix(SimpleStashPanel __instance, ScrollRect ____stashScroll)
{
if (____stashScroll == null)
public static void Prefix(SimpleStashPanel __instance, ScrollRect ____stashScroll)
{
// For some reason, sometimes SimpleStashPanel doesn't have a reference to its own ScrollRect?
____stashScroll = __instance.GetComponentInChildren<ScrollRect>();
}
HandleInput(____stashScroll);
HandleInput(____stashScroll ?? __instance.GetComponentInChildren<ScrollRect>());
}
[PatchTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
{
if (Settings.RebindPageUpDown.Value)
{
@@ -157,18 +152,17 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(TraderDealScreen);
return type.GetMethod("Update", BindingFlags.Public | BindingFlags.Instance);
return AccessTools.Method(typeof(TraderDealScreen), nameof(TraderDealScreen.Update));
}
[PatchPrefix]
private static void Prefix(TraderDealScreen __instance, TraderDealScreen.ETraderMode ___etraderMode_0, ScrollRect ____traderScroll, ScrollRect ____stashScroll)
public static void Prefix(TraderDealScreen.ETraderMode ___etraderMode_0, ScrollRect ____traderScroll, ScrollRect ____stashScroll)
{
HandleInput(___etraderMode_0 == TraderDealScreen.ETraderMode.Purchase ? ____traderScroll : ____stashScroll);
}
[PatchTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
{
if (Settings.RebindPageUpDown.Value)
{
@@ -183,12 +177,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(OfferViewList);
return type.GetMethod("Update", BindingFlags.Public | BindingFlags.Instance);
return AccessTools.Method(typeof(OfferViewList), nameof(OfferViewList.Update));
}
[PatchPrefix]
private static void Prefix(OfferViewList __instance, LightScroller ____scroller)
public static void Prefix(LightScroller ____scroller)
{
HandleInput(____scroller);
}
@@ -209,12 +202,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(MessagesContainer);
return type.GetMethod("Update", BindingFlags.Public | BindingFlags.Instance);
return AccessTools.Method(typeof(MessagesContainer), nameof(MessagesContainer.Update));
}
[PatchPrefix]
private static void Prefix(MessagesContainer __instance, LightScroller ____scroller)
public static void Prefix(LightScroller ____scroller)
{
HandleInput(____scroller);
}
@@ -235,12 +227,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(ScrollRectNoDrag);
return type.GetMethod("OnScroll");
return AccessTools.Method(typeof(ScrollRectNoDrag), nameof(ScrollRectNoDrag.OnScroll)); //type.GetMethod("OnScroll");
}
[PatchPrefix]
private static void Prefix(PointerEventData data)
public static void Prefix(PointerEventData data)
{
data.scrollDelta *= Settings.MouseScrollMulti.Value;
}

View File

@@ -39,11 +39,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(SimpleStashPanel), "Show");
return AccessTools.Method(typeof(SimpleStashPanel), nameof(SimpleStashPanel.Show));
}
[PatchPostfix]
private static void Postfix(SimpleStashPanel __instance)
public static void Postfix(SimpleStashPanel __instance)
{
SynchronizeScrollRect(__instance);
}
@@ -53,13 +53,13 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(TraderDealScreen), "method_3");
return AccessTools.Method(typeof(TraderDealScreen), nameof(TraderDealScreen.method_3));
}
// TraderDealScreen is a monstrosity that loads multiple times and isn't done loading when Show() is done
// method_3 shows the stash grid, if method_5() returned true
[PatchPostfix]
private static void Postfix(TraderDealScreen __instance, ScrollRect ____stashScroll)
public static void Postfix(TraderDealScreen __instance, ScrollRect ____stashScroll)
{
if (__instance.method_5())
{
@@ -72,11 +72,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(AddOfferWindow), "Show");
return AccessTools.Method(typeof(AddOfferWindow), nameof(AddOfferWindow.Show));
}
[PatchPostfix]
private static void Postfix(AddOfferWindow __instance)
public static void Postfix(AddOfferWindow __instance)
{
SynchronizeScrollRect(__instance);
}

View File

@@ -46,7 +46,7 @@ namespace UIFixes
// The most recent GridItemView that was hovered - needed to forcibly update hover state after swap
private static GridItemView LastHoveredGridItemView;
private static EOwnerType[] BannedOwnerTypes = [EOwnerType.Mail, EOwnerType.Trader];
private static readonly EOwnerType[] BannedOwnerTypes = [EOwnerType.Mail, EOwnerType.Trader];
public static void Enable()
{
@@ -61,7 +61,7 @@ namespace UIFixes
CanAcceptOperationSucceededProperty = AccessTools.Property(CanAcceptOperationType, "Succeeded");
CanAcceptOperationErrorProperty = AccessTools.Property(CanAcceptOperationType, "Error");
SwapOperationType = AccessTools.Method(typeof(InteractionsHandlerClass), "Swap").ReturnType; // GStruct414<GClass2797>
SwapOperationType = AccessTools.Method(typeof(InteractionsHandlerClass), nameof(InteractionsHandlerClass.Swap)).ReturnType; // GStruct414<GClass2797>
SwapOperationToCanAcceptOperationOperator = SwapOperationType.GetMethods().First(m => m.Name == "op_Implicit" && m.ReturnType == CanAcceptOperationType);
GridViewNonInteractableField = AccessTools.Field(typeof(GridView), "_nonInteractable");
@@ -146,8 +146,7 @@ namespace UIFixes
private static bool CouldEverFit(ItemContextClass itemContext, ItemContextAbstractClass containerItemContext)
{
Item item = itemContext.Item;
LootItemClass container = containerItemContext.Item as LootItemClass;
if (container == null)
if (containerItemContext.Item is not LootItemClass container)
{
return false;
}
@@ -171,12 +170,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(ItemView);
return type.GetMethod("OnDrag");
return AccessTools.Method(typeof(ItemView), nameof(ItemView.OnDrag));
}
[PatchPrefix]
private static void Prefix(ItemView __instance)
public static void Prefix(ItemView __instance)
{
SourceContainer = __instance.Container;
}
@@ -188,9 +186,8 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
Type type = typeof(GridView);
GridViewTraderControllerClassField = AccessTools.GetDeclaredFields(type).First(f => f.FieldType == typeof(TraderControllerClass));
return type.GetMethod("CanAccept");
GridViewTraderControllerClassField = AccessTools.GetDeclaredFields(typeof(GridView)).First(f => f.FieldType == typeof(TraderControllerClass));
return AccessTools.Method(typeof(GridView), nameof(GridView.CanAccept));
}
// Essentially doing what happens in StashGridClass.method_6, which checks if any of the squares are already taken
@@ -236,7 +233,7 @@ namespace UIFixes
}
[PatchPostfix]
private static void Postfix(GridView __instance, ItemContextClass itemContext, ItemContextAbstractClass targetItemContext, ref object operation, ref bool __result, Dictionary<string, ItemView> ___dictionary_0)
public static void Postfix(GridView __instance, ItemContextClass itemContext, ItemContextAbstractClass targetItemContext, ref object operation, ref bool __result, Dictionary<string, ItemView> ___dictionary_0)
{
if (!ValidPrerequisites(itemContext, targetItemContext, operation))
{
@@ -254,8 +251,7 @@ namespace UIFixes
}
// Repair kits are special
ItemView targetItemView;
if (___dictionary_0.TryGetValue(targetItem.Id, out targetItemView))
if (___dictionary_0.TryGetValue(targetItem.Id, out ItemView targetItemView))
{
if (targetItemView.CanInteract(itemContext))
{
@@ -328,21 +324,15 @@ namespace UIFixes
// Swap does not do that, because spaghetti, so do it here.
public class SwapOperationRaiseEventsPatch : ModulePatch
{
private static MethodInfo RaiseUnbindItemEvent;
private static Type RaiseUnbindItemEventArgs; // GEventArgs13
protected override MethodBase GetTargetMethod()
{
RaiseUnbindItemEvent = AccessTools.Method(typeof(InventoryControllerClass), "RaiseUnbindItemEvent");
RaiseUnbindItemEventArgs = RaiseUnbindItemEvent.GetParameters()[0].ParameterType;
return AccessTools.Method(SwapOperationType.GenericTypeArguments[0], "RaiseEvents"); // GClass2787
}
[PatchPostfix]
private static void Postfix(TraderControllerClass controller, CommandStatus status, Item ___Item, Item ___Item1)
public static void Postfix(TraderControllerClass controller, CommandStatus status, Item ___Item, Item ___Item1)
{
InventoryControllerClass inventoryController = controller as InventoryControllerClass;
if (status != CommandStatus.Succeed || inventoryController == null || ___Item == null || ___Item1 == null)
if (status != CommandStatus.Succeed || ___Item == null || ___Item1 == null || controller is not InventoryControllerClass inventoryController)
{
return;
}
@@ -378,11 +368,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GridItemView), "OnPointerEnter");
return AccessTools.Method(typeof(GridItemView), nameof(GridItemView.OnPointerEnter));
}
[PatchPostfix]
private static void Postfix(GridItemView __instance)
public static void Postfix(GridItemView __instance)
{
LastHoveredGridItemView = __instance;
}
@@ -394,12 +384,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(ItemContextClass);
return type.GetMethod("CanAccept");
return AccessTools.Method(typeof(ItemContextClass), nameof(ItemContextClass.CanAccept));
}
[PatchPostfix]
private static void Postfix(ItemContextClass __instance, Slot slot, ItemContextAbstractClass targetItemContext, ref object operation, TraderControllerClass itemController, bool simulate, ref bool __result)
public static void Postfix(ItemContextClass __instance, Slot slot, ItemContextAbstractClass targetItemContext, ref object operation, TraderControllerClass itemController, bool simulate, ref bool __result)
{
// targetItemContext here is not the target item, it's the *parent* context, i.e. the owner of the slot
// Do a few more checks
@@ -437,18 +426,17 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(GridItemView);
return type.GetMethod("method_12");
return AccessTools.Method(typeof(GridItemView), nameof(GridItemView.method_12));
}
[PatchPrefix]
private static void Prefix()
public static void Prefix()
{
InHighlight = true;
}
[PatchPostfix]
private static void Postfix()
public static void Postfix()
{
InHighlight = false;
}
@@ -460,18 +448,18 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(SlotView);
return type.GetMethod("method_2");
return AccessTools.Method(typeof(SlotView), nameof(SlotView.method_2));
}
[PatchPrefix]
private static void Prefix()
public static void Prefix()
{
InHighlight = true;
}
[PatchPostfix]
private static void Postfix()
public static void Postfix()
{
InHighlight = false;
}
@@ -488,7 +476,7 @@ namespace UIFixes
}
[PatchPostfix]
private static void Postfix(Item item, ref bool __result)
public static void Postfix(Item item, ref bool __result)
{
LastCheckItemFilterId = item.Id;
LastCheckItemFilterResult = __result;
@@ -501,11 +489,11 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(DraggedItemView), "UpdateTargetUnderCursor");
return AccessTools.Method(typeof(DraggedItemView), nameof(DraggedItemView.UpdateTargetUnderCursor));
}
[PatchPostfix]
private static void Postfix(DraggedItemView __instance, ItemContextAbstractClass itemUnderCursor)
public static void Postfix(DraggedItemView __instance, ItemContextAbstractClass itemUnderCursor)
{
if (SourceContainer is Component sourceComponent)
{

View File

@@ -1,6 +1,6 @@
using Aki.Reflection.Patching;
using EFT.UI.DragAndDrop;
using System;
using HarmonyLib;
using System.Reflection;
namespace UIFixes
@@ -9,18 +9,14 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(QuestItemViewPanel);
return type.GetMethod("method_2");
return AccessTools.Method(typeof(QuestItemViewPanel), nameof(QuestItemViewPanel.method_2));
}
[PatchPostfix]
private static void Postfix(QuestItemViewPanel __instance)
public static void Postfix(QuestItemViewPanel __instance)
{
GridItemView parent = __instance.GetComponentInParent<GridItemView>();
if (parent != null)
{
parent.ShowTooltip();
}
parent?.ShowTooltip();
}
}
}

View File

@@ -1,6 +1,6 @@
using Aki.Reflection.Patching;
using EFT.UI;
using System;
using HarmonyLib;
using System.Reflection;
using System.Threading.Tasks;
@@ -10,19 +10,18 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
Type type = typeof(TransferItemsScreen);
return type.GetMethod("method_4", BindingFlags.Public | BindingFlags.Instance);
return AccessTools.Method(typeof(TransferItemsScreen), nameof(TransferItemsScreen.method_4));
}
[PatchPrefix]
private static bool Prefix(ref Task<bool> __result)
public static bool Prefix(ref Task<bool> __result)
{
if (Settings.ShowTransferConfirmations.Value == TransferConfirmationOption.Always)
{
return true;
}
__result = Task.FromResult<bool>(true);
__result = Task.FromResult(true);
return false;
}
}

View File

@@ -2,6 +2,7 @@
using Aki.Reflection.Utils;
using EFT.InputSystem;
using EFT.InventoryLogic;
using HarmonyLib;
using System;
using System.Linq;
using System.Reflection;
@@ -16,12 +17,12 @@ namespace UIFixes
protected override MethodBase GetTargetMethod()
{
ControlSettingsClass = PatchConstants.EftTypes.Single(x => x.GetMethod("GetBoundItemNames") != null); // GClass960
GetKeyNameMethod = ControlSettingsClass.GetMethod("GetKeyName");
return ControlSettingsClass.GetMethod("GetBoundItemNames", BindingFlags.Public | BindingFlags.Instance);
GetKeyNameMethod = AccessTools.Method(ControlSettingsClass, "GetKeyName");
return AccessTools.Method(ControlSettingsClass, "GetBoundItemNames");
}
[PatchPostfix]
private static void Postfix(object __instance, EBoundItem boundItem, ref string __result)
public static void Postfix(object __instance, EBoundItem boundItem, ref string __result)
{
switch(boundItem)
{

View File

@@ -2,6 +2,7 @@
using EFT.InventoryLogic;
using EFT.UI;
using EFT.UI.WeaponModding;
using HarmonyLib;
using System;
using System.Reflection;
using UnityEngine.EventSystems;
@@ -18,22 +19,16 @@ namespace UIFixes
public class EditBuildScreenZoomPatch : ModulePatch
{
private static ScrollTrigger ScrollTrigger;
protected override MethodBase GetTargetMethod()
{
Type type = typeof(EditBuildScreen);
return type.GetMethod("Show", [typeof(Item), typeof(Item), typeof(InventoryControllerClass), typeof(ISession)]);
return AccessTools.Method(typeof(EditBuildScreen), nameof(EditBuildScreen.Show), [typeof(Item), typeof(Item), typeof(InventoryControllerClass), typeof(ISession)]);
}
[PatchPrefix]
private static void Prefix(EditBuildScreen __instance, WeaponPreview ____weaponPreview)
public static void Prefix(EditBuildScreen __instance, WeaponPreview ____weaponPreview)
{
if (ScrollTrigger == null)
{
ScrollTrigger = __instance.gameObject.AddComponent<ScrollTrigger>();
}
ScrollTrigger.OnOnScroll += (PointerEventData eventData) =>
var scrollTrigger = __instance.gameObject.AddComponent<ScrollTrigger>();
scrollTrigger.OnOnScroll += (PointerEventData eventData) =>
{
if (____weaponPreview != null && __instance != null)
{
@@ -46,22 +41,16 @@ namespace UIFixes
public class WeaponModdingScreenZoomPatch : ModulePatch
{
private static ScrollTrigger ScrollTrigger;
protected override MethodBase GetTargetMethod()
{
Type type = typeof(WeaponModdingScreen);
return type.GetMethod("Show", [typeof(Item), typeof(InventoryControllerClass), typeof(LootItemClass[])]);
return AccessTools.Method(typeof(WeaponModdingScreen), nameof(WeaponModdingScreen.Show), [typeof(Item), typeof(InventoryControllerClass), typeof(LootItemClass[])]);
}
[PatchPrefix]
private static void Prefix(WeaponModdingScreen __instance, WeaponPreview ____weaponPreview)
public static void Prefix(WeaponModdingScreen __instance, WeaponPreview ____weaponPreview)
{
if (ScrollTrigger == null)
{
ScrollTrigger = __instance.gameObject.AddComponent<ScrollTrigger>();
}
ScrollTrigger.OnOnScroll += (PointerEventData eventData) =>
var scrollTrigger = __instance.gameObject.AddComponent<ScrollTrigger>();
scrollTrigger.OnOnScroll += (PointerEventData eventData) =>
{
if (____weaponPreview != null && __instance != null)
{

View File

@@ -5,7 +5,7 @@ namespace UIFixes
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
private void Awake()
public void Awake()
{
Settings.Init(Config);

View File

@@ -228,8 +228,7 @@ namespace UIFixes
int settingOrder = configEntries.Count;
foreach (var entry in configEntries)
{
ConfigurationManagerAttributes attributes = entry.Description.Tags[0] as ConfigurationManagerAttributes;
if (attributes != null)
if (entry.Description.Tags[0] is ConfigurationManagerAttributes attributes)
{
attributes.Order = settingOrder;
}