Skip to content

Commit

Permalink
Reworked how traders are loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadMaj committed Sep 1, 2024
1 parent 68807eb commit bb78ab9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
19 changes: 18 additions & 1 deletion Patches/QuickSell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
using static System.Collections.Specialized.BitVector32;
using TMPro;
using QuickSell.Patches;
using SPT.Reflection.Utils;

namespace QuickSell.Patches
{
// This is the main patch handling most of the logic

internal class ContextMenuPatch : ModulePatch // all patches must inherit ModulePatch
{
private static TraderClass[] traders = null;

protected override MethodBase GetTargetMethod()
{
return typeof(SimpleContextMenu).GetMethod(nameof(SimpleContextMenu.method_0)).MakeGenericMethod(typeof(EItemInfoButton));
Expand Down Expand Up @@ -190,9 +193,14 @@ public static Action<ItemMarketPrices> FleaCallbackFactory(Item item, ItemMarket
// Returns Trader with best offer of null if unsellable
private static TraderClass selectTrader(Item item)
{
if (traders == null)
{
forceReloadTraders();
}

TraderClass best = null;
int bestOffer = 0;
foreach (var trader in Singleton<MenuUI>.Instance.TraderScreensGroup.IEnumerable_0)
foreach (var trader in traders)
{
var price = trader.GetUserItemPrice(item);

Expand Down Expand Up @@ -221,5 +229,14 @@ private static void PlaySellSound()
Singleton<GUISounds>.Instance.PlayUISound(EUISoundType.TradeOperationComplete);
}

private static void forceReloadTraders()
{
var app = ClientAppUtils.GetMainApp();

var mainMenu = (MainMenuController) typeof(TarkovApplication).GetField("mainMenuController", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(app);
var iSession = (ISession)typeof(MainMenuController).GetField("iSession", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(mainMenu);
traders = iSession.Traders.Where(new Func<TraderClass, bool>(MainMenuController.Class1271.class1271_0.method_4)).ToArray<TraderClass>();
}

}
}
2 changes: 1 addition & 1 deletion Patches/TraderLoadingPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static bool Prefix(MainMenuController __instance, EMenuType screen, bool
{
if (screen == EMenuType.Player)
{
__instance.method_34();
//__instance.method_34();
__instance.method_35();
}

Expand Down
16 changes: 13 additions & 3 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@
namespace QuickSell
{

[BepInPlugin("QuickSell.UniqueGUID", "QuickSell", "1.0.1")]
[BepInPlugin("QuickSell.UniqueGUID", "QuickSell", "1.0.2")]
public class Plugin : BaseUnityPlugin
{


public static bool EnableQuickSellFlea = true;
public static bool EnableQuickSellTraders = true;
public static bool ShowConfirmationDialog = true;
public static string[] TradersBlacklist = new string[] { };

public static double AvgPricePercent = 100;

public static string TraderSellKey = "B";
public static string FleaSellKey = "N";

public static bool IgnoreFleaCapacity = false;

public static ManualLogSource LogSource;
public MainMenuController mmController;

private void Awake()
{
Expand Down

0 comments on commit bb78ab9

Please sign in to comment.