From 8a4718d64cdd4e079de9c29ebe890442ee77f26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Wed, 17 Jul 2024 23:18:47 +0200 Subject: [PATCH] Make sell to flea on shift alt click --- .gitignore | 3 +- Patches/MultiSelectPatches.cs | 40 +++++++++++++++++++-- UIFixes.csproj | 15 ++++++-- util/FleaCache.cs | 65 +++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 util/FleaCache.cs diff --git a/.gitignore b/.gitignore index 97ea84d..c15ec8f 100644 --- a/.gitignore +++ b/.gitignore @@ -398,4 +398,5 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml -/libs \ No newline at end of file +/libs +.idea diff --git a/Patches/MultiSelectPatches.cs b/Patches/MultiSelectPatches.cs index af99c0c..93080c3 100644 --- a/Patches/MultiSelectPatches.cs +++ b/Patches/MultiSelectPatches.cs @@ -13,9 +13,11 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; +using UIFixes.util; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; +using FleaRequirement = GClass1859; namespace UIFixes; @@ -174,6 +176,8 @@ public static class MultiSelectPatches public class ItemViewClickPatch : ModulePatch { + private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession(); + protected override MethodBase GetTargetMethod() { return AccessTools.Method(typeof(GridItemView), nameof(GridItemView.OnClick)); @@ -191,6 +195,10 @@ public static class MultiSelectPatches bool shiftDown = Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift); bool altDown = Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt); + if (shiftDown && altDown) { + SellAllToFlea(); + } + if (ctrlDown && !shiftDown && !altDown) { QuickMove(__instance, ___ItemUiContext, ___ItemController); @@ -205,7 +213,7 @@ public static class MultiSelectPatches if (shiftDown) { - // Nothing to do, mousedown handled it. + // Nothing to do, mousedown handled it. return true; } @@ -274,6 +282,32 @@ public static class MultiSelectPatches } } } + + public static void SellAllToFlea() { + foreach (DragItemContext selectedItemContext in MultiSelect.SortedItemContexts()) { + try { + SellToFlea(selectedItemContext.Item); + } + catch (Exception e) { + Console.WriteLine("Oopsie!"); + Console.WriteLine(e); + } + } + } + + private static void SellToFlea(Item item) { + double? fleaPrice = FleaPriceCache.FetchPrice(item.TemplateId); + Console.WriteLine("Flea price for " + item.Name + ":" + fleaPrice); + + if (fleaPrice.HasValue) { + var req = new FleaRequirement { + count = (int)(fleaPrice.Value * 1.4), + _tpl = "5449016a4bdc2d6f028b456f" + }; + Console.WriteLine("Selling " + item.Name + " for " + req.count + " roubl"); + Session.RagFair.AddOffer(false, [item.Id], [req], null); + } + } } public class ContextActionsPatch : ModulePatch @@ -1110,7 +1144,7 @@ public static class MultiSelectPatches } } - // Reimplement this method because BSG ignores the operation that is passed in and re-does the entire logic, + // Reimplement this method because BSG ignores the operation that is passed in and re-does the entire logic, // like the dumb assholes they are public class TradingTableGetHighlightColorPatch : ModulePatch { @@ -1217,7 +1251,7 @@ public static class MultiSelectPatches } // This is an insane way of doing this, but inside of the above method, I want ItemAddress.Equals to always return false, to allow - // same place moves. + // same place moves. public class AllowFindSameSpotPatch : ModulePatch { public static bool DisableItemAddressEquals = false; diff --git a/UIFixes.csproj b/UIFixes.csproj index 915d242..dd139ca 100644 --- a/UIFixes.csproj +++ b/UIFixes.csproj @@ -15,8 +15,7 @@ - ..\..\..\..\SPT\3.9.2-debug - ..\..\..\..\SPT\3.9.2 + C:\Games\Escape from Tarkov\Escape from Tarkov @@ -83,6 +82,18 @@ + + + + + + + + + + + +