-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathExtensions.cs
49 lines (40 loc) · 1.25 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using SPT.Reflection.Utils;
using Comfort.Common;
using EFT;
using EFT.InventoryLogic;
using System.Reflection;
namespace LootValue
{
internal static class NumberExtensions
{
public static string FormatNumber(this int s)
{
if (s > 1000)
return $"{string.Format("{0:0.0}", (double)s / 1000)}k";
return s.ToString();
}
public static string FormatNumber(this double s)
{
if (s > 1000)
return $"{string.Format("{0:0.0}", s / 1000)}k";
return s.ToString();
}
}
internal static class TraderClassExtensions
{
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
private static readonly FieldInfo SupplyDataField =
typeof(TraderClass).GetField("supplyData_0", BindingFlags.NonPublic | BindingFlags.Instance);
public static SupplyData GetSupplyData(this TraderClass trader) =>
SupplyDataField.GetValue(trader) as SupplyData;
public static void SetSupplyData(this TraderClass trader, SupplyData supplyData) =>
SupplyDataField.SetValue(trader, supplyData);
public static async void UpdateSupplyData(this TraderClass trader)
{
Result<SupplyData> result = await Session.GetSupplyData(trader.Id);
if (result.Failed)
return;
trader.SetSupplyData(result.Value);
}
}
}