Skip to content

Commit 0c71679

Browse files
authored
Merge pull request #4 from Zotikus1001/main
A few improvements, bug fixes, restored ballistics functionality.
2 parents b1aa9d4 + 1841128 commit 0c71679

11 files changed

+1334
-194
lines changed

App.config

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
1010
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
1111
</dependentAssembly>
12+
<dependentAssembly>
13+
<assemblyIdentity name="System.Drawing.Common" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
14+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
15+
</dependentAssembly>
16+
<dependentAssembly>
17+
<assemblyIdentity name="IronSoftware.Drawing.Common" publicKeyToken="8d7e55c97b3e9835" culture="neutral" />
18+
<bindingRedirect oldVersion="0.0.0.0-2022.11.10457.0" newVersion="2022.11.10457.0" />
19+
</dependentAssembly>
20+
<dependentAssembly>
21+
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
22+
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
23+
</dependentAssembly>
24+
<dependentAssembly>
25+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
26+
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
27+
</dependentAssembly>
1228
</assemblyBinding>
1329
</runtime>
1430
</configuration>

Item.cs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class Item
2020
public String buy_from_trader;
2121
public String buy_from_trader_price;
2222
public String last_updated;
23+
public String profit;
24+
public String banned_from_flea;
2325

2426
public String needs;
2527
public String bartersandcrafts;

MainForm.Designer.cs

+104-89
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainForm.cs

+238-41
Large diffs are not rendered by default.

Overlay.cs

+656-22
Large diffs are not rendered by default.

Program.cs

+139-23
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
using System.Diagnostics;
44
using System.Drawing;
55
using System.IO;
6-
using System.Text.Json;
6+
using System.Net.Http;
77
using System.Text.RegularExpressions;
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using System.Windows.Forms;
11+
using Newtonsoft.Json;
1112

1213
namespace TarkovPriceViewer
1314
{
1415
static class Program
1516
{
17+
public static bool UsingAPI = true;
18+
1619
private static MainForm main = null;
1720
public static Dictionary<String, String> settings = new Dictionary<String, String>();
1821
public static readonly List<Item> itemlist = new List<Item>();
@@ -29,21 +32,27 @@ static class Program
2932
public static readonly String appname = "EscapeFromTarkov";
3033
public static readonly String loading = "Loading...";
3134
public static readonly String notfound = "Item Name Not Found.";
32-
public static readonly String noflea = "Item not Found on Flea.";
33-
public static readonly String notfinishloading = "Wait for Loading Data. Please Check Your Internet, and Check Tarkov Wiki Site.";
35+
public static readonly String waitingForTooltip = "Loading";
36+
public static readonly String noflea = "Item not Found on the Flea Market.";
37+
public static readonly String notfinishloading = "Ballistics Data not finished loading. \nPlease try again or check your Internet connection.";
38+
public static readonly String notfinishloadingAPI = "API not finished loading. \nPlease try again or check your Internet connection.";
3439
public static readonly String presscomparekey = "Please Press Compare Key.";
3540
public static bool finishloadingballistics = false;
41+
public static bool finishloadingAPI = false;
3642
public static readonly String wiki = "https://escapefromtarkov.fandom.com/wiki/";
43+
public static readonly String tarkov_dev = "https://tarkov.dev/";
3744
public static readonly String tarkovmarket = "https://tarkov-market.com/item/";
3845
public static readonly String official = "https://www.escapefromtarkov.com/";
39-
public static readonly String github = "https://github.com/hwangshkr/TarkovPriceViewer";
40-
public static readonly String checkupdate = "https://github.com/hwangshkr/TarkovPriceViewer/raw/main/README.md";
46+
public static readonly String github = "https://github.com/Zotikus1001/TarkovPriceViewer";
47+
public static readonly String checkupdate = "https://github.com/Zotikus1001/TarkovPriceViewer/raw/main/README.md";
4148
public static readonly char rouble = '₽';
4249
public static readonly char dollar = '$';
4350
public static readonly char euro = '€';
4451
public static readonly char[] splitcur = new char[] { rouble, dollar, euro };
4552
public static readonly Regex inraid_filter = new Regex(@"in raid");
4653
public static readonly Regex money_filter = new Regex(@"([\d,]+[₽\$€]|[₽\$€][\d,]+)");
54+
public static DateTime APILastUpdated = DateTime.Now.AddHours(-5);
55+
public static TarkovAPI.Data tarkovAPI;
4756

4857
/// <summary>
4958
/// 해당 애플리케이션의 주 진입점입니다.
@@ -65,14 +74,25 @@ static void Main()
6574
}
6675
catch (Exception ex)
6776
{
68-
Debug.WriteLine(ex.Message);
77+
Debug.WriteLine("Error 15: " + ex.Message);
6978
}
7079
}
7180
ThreadPool.SetMinThreads(10, 10);
7281
ThreadPool.SetMaxThreads(20, 20);
7382
Task task = Task.Factory.StartNew(() => getBallistics());
83+
7484
LoadSettings();
75-
getItemList();
85+
86+
if (UsingAPI)
87+
{
88+
if (File.Exists(@"Resources\TarkovAPI.json"))
89+
APILastUpdated = File.GetLastWriteTime(@"Resources\TarkovAPI.json");
90+
91+
Task task2 = Task.Factory.StartNew(() => UpdateItemListAPI());
92+
}
93+
else
94+
getItemList();
95+
7696
main = new MainForm();
7797
if (Convert.ToBoolean(settings["MinimizetoTrayWhenStartup"]))
7898
{
@@ -96,18 +116,113 @@ private static void getItemList()
96116
{
97117
String[] spl = textValue[i].Split('\t');
98118
Item item = new Item();
99-
item.name_display = spl[0].Trim();
100-
item.name_display2 = spl[2].Trim();
119+
item.name_display = spl[0].Trim(); //Column 1
120+
item.name_display2 = spl[2].Trim(); //Column 3
101121
item.name_compare = item.name_display.ToLower().ToCharArray();
102122
item.name_compare2 = item.name_display2.ToLower().ToCharArray();
103-
item.market_address = spl[1].Replace(" ", "_").Trim();
104-
item.wiki_address = spl[0].Replace(" ", "_").Trim();
123+
item.market_address = spl[1].Replace(" ", "_").Trim(); //Column 2
124+
item.wiki_address = spl[0].Replace(" ", "_").Trim(); //Column 1
105125
itemlist.Add(item);
106126
}
107127
}
108128
Debug.WriteLine("itemlist Count : " + itemlist.Count);
109129
}
110130

131+
public static async void UpdateItemListAPI()
132+
{
133+
if (UsingAPI)
134+
{
135+
//If Outdated by 15 minutes.
136+
if ((DateTime.Now - APILastUpdated).TotalMinutes >= 15)
137+
{
138+
try
139+
{
140+
Debug.WriteLine("\n--> Updating API...");
141+
142+
var data = new Dictionary<string, string>()
143+
{
144+
{"query", "{\r\n items {\r\n name\r\n types\r\n lastLowPrice\r\n avg24hPrice\r\n updated\r\n fleaMarketFee\r\n link\r\n wikiLink\r\n width\r\n height\r\n properties {\r\n ... on ItemPropertiesAmmo {\r\n caliber\r\n damage\r\n projectileCount\r\n penetrationPower\r\n armorDamage\r\n fragmentationChance\r\n ammoType\r\n }\r\n ... on ItemPropertiesWeapon {\r\n caliber\r\n ergonomics\r\n defaultRecoilVertical\r\n defaultRecoilHorizontal\r\n defaultWidth\r\n defaultHeight\r\n defaultAmmo {\r\n name\r\n }\r\n }\r\n }\r\n sellFor {\r\n currency\r\n priceRUB\r\n vendor {\r\n name\r\n ... on TraderOffer {\r\n minTraderLevel\r\n }\r\n }\r\n }\r\n buyFor {\r\n currency\r\n priceRUB\r\n vendor {\r\n name\r\n ... on TraderOffer {\r\n minTraderLevel\r\n }\r\n }\r\n }\r\n usedInTasks {\r\n name\r\n trader {\r\n name\r\n }\r\n map {\r\n name\r\n }\r\n minPlayerLevel\r\n traderLevelRequirements {\r\n level\r\n }\r\n }\r\n }\r\n}"}
145+
};
146+
147+
using (var httpClient = new HttpClient())
148+
{
149+
//Http response message
150+
var httpResponse = await httpClient.PostAsJsonAsync("https://api.tarkov.dev/graphql", data);
151+
//Response content
152+
string responseContent = await httpResponse.Content.ReadAsStringAsync();
153+
154+
int index = responseContent.IndexOf("{\"data\":");
155+
if (index != -1)
156+
{
157+
responseContent = responseContent.Remove(index, 8);
158+
responseContent = responseContent.Remove(responseContent.Length - 1, 1);
159+
}
160+
161+
//Prettify JSON (Produces a larger file)
162+
//responseContent = JToken.Parse(responseContent).ToString();
163+
164+
tarkovAPI = JsonConvert.DeserializeObject<TarkovAPI.Data>(responseContent);
165+
APILastUpdated = DateTime.Now;
166+
finishloadingAPI = true;
167+
Debug.WriteLine("\n--> API Updated!");
168+
File.WriteAllText(@"Resources\TarkovAPI.json", responseContent);
169+
}
170+
}
171+
catch (Exception ex)
172+
{
173+
//MessageBox.Show("--> Error trying to update Tarkov API: " + ex.Message);
174+
Thread.Sleep(500);
175+
UpdateItemListAPI();
176+
}
177+
}
178+
else if (tarkovAPI == null)
179+
{
180+
try
181+
{
182+
string responseContent = File.ReadAllText(@"Resources\TarkovAPI.json");
183+
tarkovAPI = JsonConvert.DeserializeObject<TarkovAPI.Data>(responseContent);
184+
Debug.WriteLine("\nAPI Loaded from local File! \n" + LastUpdated(APILastUpdated));
185+
finishloadingAPI = true;
186+
}
187+
catch (Exception ex)
188+
{
189+
//MessageBox.Show("\n--> Error trying to load Tarkov API from local file: " + ex.Message);
190+
Thread.Sleep(500);
191+
UpdateItemListAPI();
192+
}
193+
}
194+
else
195+
Debug.WriteLine("--> No need to update API! \n--> " + LastUpdated(APILastUpdated) + "\n");
196+
}
197+
}
198+
199+
public static string LastUpdated(DateTime time)
200+
{
201+
TimeSpan elapsed = DateTime.Now - time;
202+
203+
if (elapsed.TotalHours < 1)
204+
{
205+
if (elapsed.TotalMinutes < 1)
206+
return $"Updated: {(int)elapsed.TotalMinutes} minute ago";
207+
else
208+
return $"Updated: {(int)elapsed.TotalMinutes} minutes ago";
209+
}
210+
else if (elapsed.TotalDays < 1)
211+
{
212+
if (elapsed.TotalHours < 2)
213+
return $"Updated: {(int)elapsed.TotalHours} hour ago";
214+
else
215+
return $"Updated: {(int)elapsed.TotalHours} hours ago";
216+
}
217+
else
218+
{
219+
if(elapsed.TotalDays <= 1)
220+
return $"Updated: {(int)elapsed.TotalDays} day ago";
221+
else
222+
return $"Updated: {(int)elapsed.TotalDays} days ago";
223+
}
224+
}
225+
111226
public static void LoadSettings()
112227
{
113228
try
@@ -119,16 +234,16 @@ public static void LoadSettings()
119234
String text = File.ReadAllText(setting_path);
120235
try
121236
{
122-
settings = JsonSerializer.Deserialize<Dictionary<String, String>>(text);
123-
} catch (JsonException je)
237+
settings = System.Text.Json.JsonSerializer.Deserialize<Dictionary<String, String>>(text);
238+
} catch (System.Text.Json.JsonException je)
124239
{
125-
Debug.WriteLine(je.Message);
240+
Debug.WriteLine("Error 11: " + je.Message);
126241
text = "{}";
127-
settings = JsonSerializer.Deserialize<Dictionary<String, String>>(text);
242+
settings = System.Text.Json.JsonSerializer.Deserialize<Dictionary<String, String>>(text);
128243
}
129244
String st;
130245
settings.Remove("Version");//force
131-
settings.Add("Version", "v1.18");//force
246+
settings.Add("Version", "v1.22");//force
132247
if (!settings.TryGetValue("MinimizetoTrayWhenStartup", out st))
133248
{
134249
settings.Add("MinimizetoTrayWhenStartup", "false");
@@ -188,7 +303,7 @@ public static void LoadSettings()
188303
}
189304
catch (Exception e)
190305
{
191-
Debug.WriteLine(e.Message);
306+
Debug.WriteLine("Error 12: " + e.Message);
192307
}
193308
}
194309

@@ -200,12 +315,12 @@ public static void SaveSettings()
200315
{
201316
File.Create(setting_path).Dispose();
202317
}
203-
string jsonString = JsonSerializer.Serialize<Dictionary<String, String>>(settings);
318+
string jsonString = System.Text.Json.JsonSerializer.Serialize<Dictionary<String, String>>(settings);
204319
File.WriteAllText(setting_path, jsonString.Replace(",", ",\n"));
205320
}
206321
catch (Exception e)
207322
{
208-
Debug.WriteLine(e.Message);
323+
Debug.WriteLine("Error 13: " + e.Message);
209324
}
210325
}
211326

@@ -220,9 +335,10 @@ private static void getBallistics()
220335
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
221336
Debug.WriteLine(Program.wiki + "Ballistics");
222337
doc.LoadHtml(wc.DownloadString(Program.wiki + "Ballistics"));
223-
HtmlAgilityPack.HtmlNode node_tm = doc.DocumentNode.SelectSingleNode("//table[@id='trkballtable']");
338+
HtmlAgilityPack.HtmlNode node_tm = doc.DocumentNode.SelectSingleNode("//table[4]"); //table[@id='trkballtable']
224339
HtmlAgilityPack.HtmlNodeCollection nodes = null;
225340
HtmlAgilityPack.HtmlNodeCollection sub_nodes = null;
341+
226342
if (node_tm != null)
227343
{
228344
node_tm = node_tm.SelectSingleNode(".//tbody");
@@ -299,7 +415,7 @@ private static void getBallistics()
299415
}
300416
catch (Exception ex)
301417
{
302-
Debug.WriteLine(ex.Message);
418+
Debug.WriteLine("Error 14: " + ex.Message);
303419
}
304420
damage += " = " + mul;
305421
}
@@ -334,11 +450,11 @@ private static void getBallistics()
334450
}
335451
catch (Exception e)
336452
{
337-
Debug.WriteLine("error with ballistics : " + e.Message);
453+
Debug.WriteLine("Error with Ballistics : " + e.Message);
338454
Thread.Sleep(3000);
339455
}
340456
}
341-
Debug.WriteLine("finish to get ballistics.");
457+
Debug.WriteLine("Finished getting Ballistics!");
342458
}
343459
}
344460
}

README.md

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
# <img width="36" align="center" src="https://user-images.githubusercontent.com/32073152/126047438-2f1b7e59-ca31-43f2-bcf6-00b2f00e408c.png"/> Tarkov Price Viewer v1.18
2-
This program is for newbies. It is especially good to find out the market price in advance when the flea market is not open yet. Currently, only English is available.
1+
# <img width="36" align="center" src="https://user-images.githubusercontent.com/32073152/126047438-2f1b7e59-ca31-43f2-bcf6-00b2f00e408c.png"/> Tarkov Price Viewer v1.22
2+
This Overlay software is meant to help new players.
3+
You can easily distinguish all the strengths and weaknesses of all the ammo in the game.
4+
It is especially good to find out the market price in advance when the flea market is not open yet.
5+
Currently, only English is available.
36

47
Most of the information for this program (names, prices, wiki links, etc.) was provided by the Tarkov Market, and some information (Needs, etc.) was provided by the Tarkov Wiki.
58

69
# How to use
7-
<img src="https://user-images.githubusercontent.com/32073152/130308975-2a380c87-f0d1-4e9e-91e6-cc2381d5d2c0.gif"/>
8-
When the name appears as in the image, press the shortcut key (default: F9). By default, it disappears when you move the mouse, and this can be removed from the settings. It disappears even if you press the shortcut key (default: F10).
10+
<img src="https://i.imgur.com/bluk1dQ.gif"/>
11+
Hover the item and press the shortcut key (default: F9).
12+
By default, it disappears when you move the mouse, and this can be removed from the settings.
13+
It disappears even if you press the shortcut key (default: F10).
914
</br>
1015
</br>
1116
<img src="https://user-images.githubusercontent.com/32073152/130593787-f0979114-46cf-47cb-93f3-2f364195e7e9.gif"/>
@@ -14,12 +19,19 @@ This is the experiential function since version 1.06. You can compare some optio
1419
Sorting function is added since Version 1.08.</br>
1520
</br>
1621
</br>
17-
<img src="https://user-images.githubusercontent.com/32073152/131343945-99a673df-877b-4059-a674-85ea6df966cf.png"/>
18-
Ballistics is added since Version 1.08.
22+
<img src="https://i.imgur.com/iLxEsIc.png"/>
23+
Ballistics added since Version 1.08.
1924
</br>
2025
</br>
21-
<img src="https://user-images.githubusercontent.com/32073152/131344302-57be08bb-b6f1-449a-a653-20544db68630.png"/>
22-
You can set some values for the functions.
26+
<img src="https://i.imgur.com/9POHPgA.png"/>
27+
<img src="https://i.imgur.com/Xru5QA5.png"/>
28+
<img src="https://i.imgur.com/GKyoYLl.png"/>
29+
<img src="https://i.imgur.com/Sn7DPlO.png"/>
30+
Loot Tiers added in v1.21
31+
</br>
32+
</br>
33+
<img src="https://i.imgur.com/GdkE78e.png"/>
34+
You can change the settings how you like.
2335
</br>
2436
</br>
2537
If you got errors, please check you installed .NET Framework 4.7.2 (https://dotnet.microsoft.com/download/dotnet-framework/net472).
@@ -42,3 +54,4 @@ If you got errors, please check you installed .NET Framework 4.7.2 (https://dotn
4254
4. Tarkov Market (https://tarkov-market.com/)
4355
5. Tarkov Wiki (https://escapefromtarkov.fandom.com/wiki/Escape_from_Tarkov_Wiki)
4456
6. Escape from Tarkov(https://www.escapefromtarkov.com/)
57+
7. Tarkov.dev API(https://tarkov.dev/)

0 commit comments

Comments
 (0)