Make sell to flea on shift alt click

This commit is contained in:
2024-07-17 23:18:47 +02:00
parent cf23b39353
commit 8a4718d64c
4 changed files with 117 additions and 6 deletions

3
.gitignore vendored
View File

@@ -398,4 +398,5 @@ FodyWeavers.xsd
# JetBrains Rider # JetBrains Rider
*.sln.iml *.sln.iml
/libs /libs
.idea

View File

@@ -13,9 +13,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using UIFixes.util;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
using FleaRequirement = GClass1859;
namespace UIFixes; namespace UIFixes;
@@ -174,6 +176,8 @@ public static class MultiSelectPatches
public class ItemViewClickPatch : ModulePatch public class ItemViewClickPatch : ModulePatch
{ {
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return AccessTools.Method(typeof(GridItemView), nameof(GridItemView.OnClick)); 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 shiftDown = Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift);
bool altDown = Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt); bool altDown = Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt);
if (shiftDown && altDown) {
SellAllToFlea();
}
if (ctrlDown && !shiftDown && !altDown) if (ctrlDown && !shiftDown && !altDown)
{ {
QuickMove(__instance, ___ItemUiContext, ___ItemController); QuickMove(__instance, ___ItemUiContext, ___ItemController);
@@ -205,7 +213,7 @@ public static class MultiSelectPatches
if (shiftDown) if (shiftDown)
{ {
// Nothing to do, mousedown handled it. // Nothing to do, mousedown handled it.
return true; 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 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 // like the dumb assholes they are
public class TradingTableGetHighlightColorPatch : ModulePatch 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 // 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 class AllowFindSameSpotPatch : ModulePatch
{ {
public static bool DisableItemAddressEquals = false; public static bool DisableItemAddressEquals = false;

View File

@@ -15,8 +15,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<PathToSPT Condition="'$(Configuration)'=='Debug'">..\..\..\..\SPT\3.9.2-debug</PathToSPT> <PathToSPT>C:\Games\Escape from Tarkov\Escape from Tarkov</PathToSPT>
<PathToSPT Condition="'$(Configuration)'=='Release'">..\..\..\..\SPT\3.9.2</PathToSPT>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -83,6 +82,18 @@
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" /> <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Remove="lib\**" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="lib\**" />
</ItemGroup>
<ItemGroup>
<None Remove="lib\**" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command='if $(ConfigurationName) == Debug ( <Exec Command='if $(ConfigurationName) == Debug (
xcopy /F /Y "$(TargetPath)" "$(ProjectDir)$(PathToSPT)\BepInEx\plugins\" xcopy /F /Y "$(TargetPath)" "$(ProjectDir)$(PathToSPT)\BepInEx\plugins\"

65
util/FleaCache.cs Normal file
View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using SPT.Common.Http;
namespace UIFixes.util {
internal static class FleaPriceCache {
static Dictionary<string, CachePrice> cache = new Dictionary<string, CachePrice>();
public static double? FetchPrice(string templateId) {
if (cache.ContainsKey(templateId)) {
double secondsSinceLastUpdate = (DateTime.Now - cache[templateId].lastUpdate).TotalSeconds;
if (secondsSinceLastUpdate > 300)
return QueryAndTryUpsertPrice(templateId, true);
return cache[templateId].price;
}
return QueryAndTryUpsertPrice(templateId, false);
}
private static string QueryPrice(string templateId) {
return RequestHandler.PostJson("/LootValue/GetItemLowestFleaPrice",
JsonConvert.SerializeObject(new FleaPriceRequest(templateId)));
}
private static double? QueryAndTryUpsertPrice(string templateId, bool update) {
string response = QueryPrice(templateId);
bool hasPlayerFleaPrice = !(string.IsNullOrEmpty(response) || response == "null");
if (hasPlayerFleaPrice) {
double price = double.Parse(response);
if (update)
cache[templateId].Update(price);
else
cache[templateId] = new CachePrice(price);
return price;
}
return null;
}
}
public class FleaPriceRequest {
public string templateId;
public FleaPriceRequest(string templateId) => this.templateId = templateId;
}
internal class CachePrice {
public double price { get; private set; }
public DateTime lastUpdate { get; private set; }
public CachePrice(double price) {
this.price = price;
lastUpdate = DateTime.Now;
}
public void Update(double price) {
this.price = price;
lastUpdate = DateTime.Now;
}
}
}