@@ -49,6 +49,9 @@ public partial class MainForm : Form
49
49
[ DllImport ( "user32.dll" ) ]
50
50
private static extern int SetWindowLong ( IntPtr hWnd , int nIndex , int dwNewLong ) ;
51
51
52
+ [ DllImport ( "User32.dll" ) ]
53
+ private static extern bool GetLastInputInfo ( ref LASTINPUTINFO Dummy ) ;
54
+
52
55
private const int GWL_EXSTYLE = - 20 ;
53
56
private const int WS_EX_LAYERED = 0x80000 ;
54
57
@@ -70,6 +73,12 @@ private enum ShowWindowCommands : int
70
73
Maximized = 3 ,
71
74
}
72
75
76
+ internal struct LASTINPUTINFO
77
+ {
78
+ public uint cbSize ;
79
+ public uint dwTime ;
80
+ }
81
+
73
82
private static readonly int WH_KEYBOARD_LL = 13 ;
74
83
private static readonly int WM_KEYUP = 0x101 ;
75
84
private static readonly int WH_MOUSE_LL = 14 ;
@@ -80,7 +89,6 @@ private enum ShowWindowCommands : int
80
89
private static LowLevelProc _proc_mouse = null ;
81
90
private static IntPtr hhook_keyboard = IntPtr . Zero ;
82
91
private static IntPtr hhook_mouse = IntPtr . Zero ;
83
- private static System . Windows . Forms . Timer hooktimer = null ;
84
92
private static System . Drawing . Point point = new System . Drawing . Point ( 0 , 0 ) ;
85
93
private static int nFlags = 0x0 ;
86
94
private static Overlay overlay_info = new Overlay ( true ) ;
@@ -90,6 +98,7 @@ private enum ShowWindowCommands : int
90
98
private static CancellationTokenSource cts_compare = new CancellationTokenSource ( ) ;
91
99
private static Control press_key_control = null ;
92
100
private static Scalar linecolor = new Scalar ( 90 , 89 , 82 ) ;
101
+ private static long idle_time = 3600000 ;
93
102
94
103
public MainForm ( )
95
104
{
@@ -102,7 +111,6 @@ public MainForm()
102
111
InitializeComponent ( ) ;
103
112
SettingUI ( ) ;
104
113
SetHook ( ) ;
105
- SetHookTimer ( ) ;
106
114
overlay_info . Owner = this ;
107
115
overlay_info . Show ( ) ;
108
116
overlay_compare . Owner = this ;
@@ -131,17 +139,26 @@ private void SettingUI()
131
139
TransParent_Text . Text = Program . settings [ "Overlay_Transparent" ] ;
132
140
133
141
TrayIcon . Visible = true ;
142
+ check_idle_time . Start ( ) ;
134
143
}
135
144
136
145
private void MainForm_load ( object sender , EventArgs e )
137
146
{
138
147
//not use
139
148
}
140
-
141
149
private void SetHook ( )
150
+ {
151
+ SetHook ( false ) ;
152
+ }
153
+
154
+ private void SetHook ( bool force )
142
155
{
143
156
try
144
157
{
158
+ if ( force )
159
+ {
160
+ UnHook ( ) ;
161
+ }
145
162
if ( hhook_keyboard == IntPtr . Zero )
146
163
{
147
164
_proc_keyboard = hookKeyboardProc ;
@@ -157,23 +174,6 @@ private void SetHook()
157
174
}
158
175
}
159
176
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
-
177
177
private void setMouseHook ( )
178
178
{
179
179
if ( hhook_mouse == IntPtr . Zero )
@@ -281,10 +281,21 @@ private IntPtr hookMouseProc(int code, IntPtr wParam, IntPtr lParam)
281
281
return CallNextHookEx ( hhook_mouse , code , ( int ) wParam , lParam ) ;
282
282
}
283
283
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
+
284
297
private void CloseApp ( )
285
298
{
286
- hooktimer . Stop ( ) ;
287
- hooktimer . Dispose ( ) ;
288
299
UnHook ( ) ;
289
300
TrayIcon . Dispose ( ) ;
290
301
CloseItemInfo ( ) ;
@@ -696,25 +707,20 @@ private void FindItemInfo(Item item, bool isiteminfo, CancellationToken cts_one)
696
707
{
697
708
if ( temp_node . InnerText . Trim ( ) . Equals ( "General data" ) )
698
709
{
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 )
701
713
{
702
714
for ( int n = 0 ; n < temp_node_list . Count ; n ++ )
703
715
{
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" ) )
706
717
{
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 ) )
709
720
{
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 ) )
713
722
{
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 ) ;
718
724
}
719
725
}
720
726
break ;
@@ -744,7 +750,22 @@ private void FindItemInfo(Item item, bool isiteminfo, CancellationToken cts_one)
744
750
}
745
751
}
746
752
}
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
+ }
748
769
}
749
770
}
750
771
}
@@ -1024,5 +1045,21 @@ private void RandomItem_CheckedChanged(object sender, EventArgs e)
1024
1045
{
1025
1046
Program . settings [ "RandomItem" ] = ( sender as CheckBox ) . Checked . ToString ( ) ;
1026
1047
}
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
+ }
1027
1064
}
1028
1065
}
0 commit comments