From 15fe18262fcee8f49b8e40f583590fc27e8e2eb4 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:20:34 -0700 Subject: [PATCH] Using ___fields properly, fixing mail null ref --- Patches/EditBuildScreenPatch.cs | 2 +- Patches/MailReceiveAllPatch.cs | 2 +- Patches/ScrollPatches.cs | 95 ++++++++++++++++----------------- Patches/TransferConfirmPatch.cs | 2 +- Patches/WeaponZoomPatch.cs | 15 +++--- 5 files changed, 56 insertions(+), 60 deletions(-) diff --git a/Patches/EditBuildScreenPatch.cs b/Patches/EditBuildScreenPatch.cs index 1cc11f6..f6ff868 100644 --- a/Patches/EditBuildScreenPatch.cs +++ b/Patches/EditBuildScreenPatch.cs @@ -1,7 +1,7 @@ using Aki.Reflection.Patching; +using EFT.UI; using System; using System.Reflection; -using EFT.UI; using System.Threading.Tasks; namespace UIFixes diff --git a/Patches/MailReceiveAllPatch.cs b/Patches/MailReceiveAllPatch.cs index 740c40a..14e8055 100644 --- a/Patches/MailReceiveAllPatch.cs +++ b/Patches/MailReceiveAllPatch.cs @@ -1,7 +1,7 @@ using Aki.Reflection.Patching; +using EFT.UI.Chat; using System; using System.Reflection; -using EFT.UI.Chat; namespace UIFixes { diff --git a/Patches/ScrollPatches.cs b/Patches/ScrollPatches.cs index 754879e..3898e10 100644 --- a/Patches/ScrollPatches.cs +++ b/Patches/ScrollPatches.cs @@ -7,7 +7,6 @@ using HarmonyLib; using System; using System.Collections.Generic; using System.Reflection; -using System.Reflection.Emit; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; @@ -58,6 +57,45 @@ namespace UIFixes } } + // LightScrollers don't expose heights that I can see, so just fudge it with fake OnScroll events + protected static void HandleInput(LightScroller lightScroller) + { + if (lightScroller != null) + { + if (Settings.UseHomeEnd.Value) + { + if (Input.GetKeyDown(KeyCode.Home)) + { + lightScroller.SetScrollPosition(0f); + } + if (Input.GetKeyDown(KeyCode.End)) + { + lightScroller.SetScrollPosition(1f); + } + } + + if (Settings.RebindPageUpDown.Value) + { + if (Input.GetKeyDown(KeyCode.PageUp)) + { + var eventData = new PointerEventData(EventSystem.current) + { + scrollDelta = new Vector2(0f, 25f) + }; + lightScroller.OnScroll(eventData); + } + if (Input.GetKeyDown(KeyCode.PageDown)) + { + var eventData = new PointerEventData(EventSystem.current) + { + scrollDelta = new Vector2(0f, -25f) + }; + lightScroller.OnScroll(eventData); + } + } + } + } + protected static IEnumerable RemovePageUpDownHandling(IEnumerable instructions) { foreach (var instruction in instructions) @@ -92,10 +130,9 @@ namespace UIFixes } [PatchPrefix] - private static void Prefix(SimpleStashPanel __instance) + private static void Prefix(SimpleStashPanel __instance, ScrollRect ____stashScroll) { - ScrollRect stashScroll = Traverse.Create(__instance).Field("_stashScroll").GetValue(); - HandleInput(stashScroll); + HandleInput(____stashScroll); } [PatchTranspiler] @@ -119,11 +156,9 @@ namespace UIFixes } [PatchPrefix] - private static void Prefix(TraderDealScreen __instance) + private static void Prefix(TraderDealScreen __instance, TraderDealScreen.ETraderMode ___etraderMode_0, ScrollRect ____traderScroll, ScrollRect ____stashScroll) { - TraderDealScreen.ETraderMode mode = Traverse.Create(__instance).Field("etraderMode_0").GetValue(); - ScrollRect traderScroll = Traverse.Create(__instance).Field(mode == TraderDealScreen.ETraderMode.Purchase ? "_traderScroll" : "_stashScroll").GetValue(); - HandleInput(traderScroll); + HandleInput(___etraderMode_0 == TraderDealScreen.ETraderMode.Purchase ? ____traderScroll : ____stashScroll); } [PatchTranspiler] @@ -147,46 +182,11 @@ namespace UIFixes } [PatchPrefix] - private static void Prefix(OfferViewList __instance) + private static void Prefix(OfferViewList __instance, LightScroller ____scroller) { - LightScroller scroller = Traverse.Create(__instance).Field("_scroller").GetValue(); - // Different kind of scroller - I don't see a way to get the rects. // New approach: faking scroll events - if (scroller != null) - { - if (Settings.UseHomeEnd.Value) - { - if (Input.GetKeyDown(KeyCode.Home)) - { - scroller.SetScrollPosition(0f); - } - if (Input.GetKeyDown(KeyCode.End)) - { - scroller.SetScrollPosition(1f); - } - } - - if (Settings.RebindPageUpDown.Value) - { - if (Input.GetKeyDown(KeyCode.PageUp)) - { - var eventData = new PointerEventData(EventSystem.current) - { - scrollDelta = new Vector2(0f, 25f) - }; - scroller.OnScroll(eventData); - } - if (Input.GetKeyDown(KeyCode.PageDown)) - { - var eventData = new PointerEventData(EventSystem.current) - { - scrollDelta = new Vector2(0f, -25f) - }; - scroller.OnScroll(eventData); - } - } - } + HandleInput(____scroller); } [PatchTranspiler] @@ -210,10 +210,9 @@ namespace UIFixes } [PatchPrefix] - private static void Prefix(MessagesContainer __instance) + private static void Prefix(MessagesContainer __instance, LightScroller ____scroller) { - ScrollRect scroller = Traverse.Create(__instance).Field("_scroller").GetValue(); - HandleInput(scroller); + HandleInput(____scroller); } [PatchTranspiler] diff --git a/Patches/TransferConfirmPatch.cs b/Patches/TransferConfirmPatch.cs index f0c7fe5..5535c56 100644 --- a/Patches/TransferConfirmPatch.cs +++ b/Patches/TransferConfirmPatch.cs @@ -1,7 +1,7 @@ using Aki.Reflection.Patching; +using EFT.UI; using System; using System.Reflection; -using EFT.UI; using System.Threading.Tasks; namespace UIFixes diff --git a/Patches/WeaponZoomPatch.cs b/Patches/WeaponZoomPatch.cs index af1d787..6ea817b 100644 --- a/Patches/WeaponZoomPatch.cs +++ b/Patches/WeaponZoomPatch.cs @@ -2,7 +2,6 @@ using EFT.InventoryLogic; using EFT.UI; using EFT.UI.WeaponModding; -using HarmonyLib; using System; using System.Reflection; using UnityEngine.EventSystems; @@ -27,9 +26,8 @@ namespace UIFixes } [PatchPrefix] - private static void Prefix(EditBuildScreen __instance) + private static void Prefix(EditBuildScreen __instance, WeaponPreview ____weaponPreview) { - WeaponPreview weaponPreview = Traverse.Create(__instance).Field("_weaponPreview").GetValue(); if (ScrollTrigger == null) { ScrollTrigger = __instance.gameObject.AddComponent(); @@ -37,9 +35,9 @@ namespace UIFixes ScrollTrigger.OnOnScroll += (PointerEventData eventData) => { - if (weaponPreview != null && __instance != null) + if (____weaponPreview != null && __instance != null) { - weaponPreview.Zoom(eventData.scrollDelta.y * 0.12f); + ____weaponPreview.Zoom(eventData.scrollDelta.y * 0.12f); __instance.UpdatePositions(); } }; @@ -56,9 +54,8 @@ namespace UIFixes } [PatchPrefix] - private static void Prefix(WeaponModdingScreen __instance) + private static void Prefix(WeaponModdingScreen __instance, WeaponPreview ____weaponPreview) { - WeaponPreview weaponPreview = Traverse.Create(__instance).Field("_weaponPreview").GetValue(); if (ScrollTrigger == null) { ScrollTrigger = __instance.gameObject.AddComponent(); @@ -66,9 +63,9 @@ namespace UIFixes ScrollTrigger.OnOnScroll += (PointerEventData eventData) => { - if (weaponPreview != null && __instance != null) + if (____weaponPreview != null && __instance != null) { - weaponPreview.Zoom(eventData.scrollDelta.y * 0.12f); + ____weaponPreview.Zoom(eventData.scrollDelta.y * 0.12f); __instance.UpdatePositions(); } };