Skip to content

Commit bfa8544

Browse files
committedOct 9, 2021
1.11 update
1 parent b657825 commit bfa8544

File tree

4 files changed

+85
-37
lines changed

4 files changed

+85
-37
lines changed
 

‎MainForm.Designer.cs

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

‎MainForm.cs

+73-36
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public partial class MainForm : Form
4949
[DllImport("user32.dll")]
5050
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
5151

52+
[DllImport("User32.dll")]
53+
private static extern bool GetLastInputInfo(ref LASTINPUTINFO Dummy);
54+
5255
private const int GWL_EXSTYLE = -20;
5356
private const int WS_EX_LAYERED = 0x80000;
5457

@@ -70,6 +73,12 @@ private enum ShowWindowCommands : int
7073
Maximized = 3,
7174
}
7275

76+
internal struct LASTINPUTINFO
77+
{
78+
public uint cbSize;
79+
public uint dwTime;
80+
}
81+
7382
private static readonly int WH_KEYBOARD_LL = 13;
7483
private static readonly int WM_KEYUP = 0x101;
7584
private static readonly int WH_MOUSE_LL = 14;
@@ -80,7 +89,6 @@ private enum ShowWindowCommands : int
8089
private static LowLevelProc _proc_mouse = null;
8190
private static IntPtr hhook_keyboard = IntPtr.Zero;
8291
private static IntPtr hhook_mouse = IntPtr.Zero;
83-
private static System.Windows.Forms.Timer hooktimer = null;
8492
private static System.Drawing.Point point = new System.Drawing.Point(0, 0);
8593
private static int nFlags = 0x0;
8694
private static Overlay overlay_info = new Overlay(true);
@@ -90,6 +98,7 @@ private enum ShowWindowCommands : int
9098
private static CancellationTokenSource cts_compare = new CancellationTokenSource();
9199
private static Control press_key_control = null;
92100
private static Scalar linecolor = new Scalar(90, 89, 82);
101+
private static long idle_time = 3600000;
93102

94103
public MainForm()
95104
{
@@ -102,7 +111,6 @@ public MainForm()
102111
InitializeComponent();
103112
SettingUI();
104113
SetHook();
105-
SetHookTimer();
106114
overlay_info.Owner = this;
107115
overlay_info.Show();
108116
overlay_compare.Owner = this;
@@ -131,17 +139,26 @@ private void SettingUI()
131139
TransParent_Text.Text = Program.settings["Overlay_Transparent"];
132140

133141
TrayIcon.Visible = true;
142+
check_idle_time.Start();
134143
}
135144

136145
private void MainForm_load(object sender, EventArgs e)
137146
{
138147
//not use
139148
}
140-
141149
private void SetHook()
150+
{
151+
SetHook(false);
152+
}
153+
154+
private void SetHook(bool force)
142155
{
143156
try
144157
{
158+
if (force)
159+
{
160+
UnHook();
161+
}
145162
if (hhook_keyboard == IntPtr.Zero)
146163
{
147164
_proc_keyboard = hookKeyboardProc;
@@ -157,23 +174,6 @@ private void SetHook()
157174
}
158175
}
159176

160-
private void SetHookTimer()
161-
{
162-
if (hooktimer == null)
163-
{
164-
Debug.WriteLine("Start rehook Timer.");
165-
hooktimer = new System.Windows.Forms.Timer();
166-
hooktimer.Interval = 5000;
167-
hooktimer.Tick += new EventHandler(HookTimer_Tick);
168-
hooktimer.Start();
169-
}
170-
}
171-
172-
private void HookTimer_Tick(object sender, EventArgs e)
173-
{
174-
SetHook();
175-
}
176-
177177
private void setMouseHook()
178178
{
179179
if (hhook_mouse == IntPtr.Zero)
@@ -281,10 +281,21 @@ private IntPtr hookMouseProc(int code, IntPtr wParam, IntPtr lParam)
281281
return CallNextHookEx(hhook_mouse, code, (int)wParam, lParam);
282282
}
283283

284+
private uint GetIdleTime()
285+
{
286+
LASTINPUTINFO LastUserAction = new LASTINPUTINFO();
287+
LastUserAction.cbSize = (uint)Marshal.SizeOf(LastUserAction);
288+
GetLastInputInfo(ref LastUserAction);
289+
return ((uint)Environment.TickCount - LastUserAction.dwTime);
290+
}
291+
292+
public long GetTickCount()
293+
{
294+
return Environment.TickCount;
295+
}
296+
284297
private void CloseApp()
285298
{
286-
hooktimer.Stop();
287-
hooktimer.Dispose();
288299
UnHook();
289300
TrayIcon.Dispose();
290301
CloseItemInfo();
@@ -696,25 +707,20 @@ private void FindItemInfo(Item item, bool isiteminfo, CancellationToken cts_one)
696707
{
697708
if (temp_node.InnerText.Trim().Equals("General data"))
698709
{
699-
HtmlAgilityPack.HtmlNodeCollection temp_node_list = sub_node_tm.SelectNodes(".//tr");
700-
if (temp_node_list != null)
710+
HtmlAgilityPack.HtmlNodeCollection temp_node_list = sub_node_tm.SelectNodes(".//td[@class='va-infobox-label']");
711+
HtmlAgilityPack.HtmlNodeCollection temp_node_list2 = sub_node_tm.SelectNodes(".//td[@class='va-infobox-content']");
712+
if (temp_node_list != null && temp_node_list2 != null && temp_node_list.Count == temp_node_list2.Count)
701713
{
702714
for (int n = 0; n < temp_node_list.Count; n++)
703715
{
704-
HtmlAgilityPack.HtmlNode temp_node2 = node.SelectSingleNode(".//td[@class='va-infobox-label']");
705-
if (temp_node2 != null && temp_node2.InnerHtml.Trim().Equals("Type"))
716+
if (temp_node_list[n].InnerText.Trim().Contains("Type"))
706717
{
707-
temp_node2 = node.SelectSingleNode(".//td[@class='va-infobox-content']");
708-
if (temp_node2 != null)
718+
item.type = temp_node_list2[n].InnerText.Trim();
719+
if (Program.BEType.Contains(item.type))
709720
{
710-
item.type = temp_node2.InnerHtml.Trim();
711-
if (item.type.Equals("Round") || item.type.Equals("Slug")
712-
|| item.type.Equals("Buckshot") || item.type.Equals("Grenade launcher cartridge"))
721+
if (!Program.blist.TryGetValue(item.name_display, out item.ballistic))
713722
{
714-
if (!Program.blist.TryGetValue(item.name_display, out item.ballistic))
715-
{
716-
Program.blist.TryGetValue(item.name_display2, out item.ballistic);
717-
}
723+
Program.blist.TryGetValue(item.name_display2, out item.ballistic);
718724
}
719725
}
720726
break;
@@ -744,7 +750,22 @@ private void FindItemInfo(Item item, bool isiteminfo, CancellationToken cts_one)
744750
}
745751
}
746752
}
747-
break;
753+
}
754+
else if (temp_node.InnerText.Trim().Equals("Ammunition"))
755+
{
756+
HtmlAgilityPack.HtmlNodeCollection temp_node_list = sub_node_tm.SelectNodes(".//td[@class='va-infobox-label']");
757+
HtmlAgilityPack.HtmlNodeCollection temp_node_list2 = sub_node_tm.SelectNodes(".//td[@class='va-infobox-content']");
758+
if (temp_node_list != null && temp_node_list2 != null && temp_node_list.Count == temp_node_list2.Count)
759+
{
760+
for (int n = 0; n < temp_node_list.Count; n++)
761+
{
762+
if (temp_node_list[n].InnerText.Trim().Contains("Default ammo"))
763+
{
764+
Program.blist.TryGetValue(temp_node_list2[n].InnerText.Trim(), out item.ballistic);
765+
break;
766+
}
767+
}
768+
}
748769
}
749770
}
750771
}
@@ -1024,5 +1045,21 @@ private void RandomItem_CheckedChanged(object sender, EventArgs e)
10241045
{
10251046
Program.settings["RandomItem"] = (sender as CheckBox).Checked.ToString();
10261047
}
1048+
1049+
private void check_idle_time_Tick(object sender, EventArgs e)
1050+
{
1051+
if (GetIdleTime() >= idle_time)
1052+
{
1053+
idle_time += 3600000;
1054+
SetHook(true);
1055+
} else
1056+
{
1057+
if (idle_time > 3600000)
1058+
{
1059+
idle_time = 3600000;
1060+
}
1061+
SetHook();
1062+
}
1063+
}
10271064
}
10281065
}

‎MainForm.resx

+3
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@
411411
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
412412
</value>
413413
</data>
414+
<metadata name="check_idle_time.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
415+
<value>217, 17</value>
416+
</metadata>
414417
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
415418
<value>
416419
AAABAAEAQEAAAAEAIAAoQgAAFgAAACgAAABAAAAAgAAAAAEAIAAAAAAAAEAAAMMOAADDDgAAAAAAAAAA

‎Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static class Program
2424
ColorTranslator.FromHtml("#FB9C0E"),
2525
ColorTranslator.FromHtml("#006400"),
2626
ColorTranslator.FromHtml("#009900") };
27+
public static readonly HashSet<String> BEType = new HashSet<String> { "Round", "Slug", "Buckshot", "Grenade launcher cartridge" };
2728
public static readonly String setting_path = @"settings.json";
2829
public static readonly String appname = "EscapeFromTarkov";
2930
public static readonly String loading = "Loading...";
@@ -127,7 +128,7 @@ public static void LoadSettings()
127128
}
128129
String st;
129130
settings.Remove("Version");//force
130-
settings.Add("Version", "v1.10");//force
131+
settings.Add("Version", "v1.11");//force
131132
if (!settings.TryGetValue("MinimizetoTrayWhenStartup", out st))
132133
{
133134
settings.Add("MinimizetoTrayWhenStartup", "false");

0 commit comments

Comments
 (0)
Please sign in to comment.