-
Notifications
You must be signed in to change notification settings - Fork 1
/
afk.cs
145 lines (110 loc) · 3.79 KB
/
afk.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Runtime.InteropServices;
using System.Collections.ObjectModel;
using WindowsInput;
using WindowsInput.Native;
using System.Media;
using System.Collections.Generic;
using System.Diagnostics;
namespace AFKManager
{
class afk
{
Timer AFKTimer;
private Collection<afkTextModel> _afkText = new Collection<afkTextModel>();
private bool isOn { get; set; } = true;
public afk(afkSettings settings)
{
_afkText = settings.afkText;
AFKTimer = new Timer(Convert.ToInt32(settings.Time));
AFKTimer.Elapsed += WriteKey;
AFKTimer.Start();
WriteKey(null, null);
}
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("USER32.DLL")]
static extern IntPtr GetForegroundWindow();
[DllImport("USER32.DLL")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
private static IntPtr GetHandle()
{
return GetForegroundWindow();
}
public static bool GetActiveWindow()
{
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
if (GetWindowText(GetHandle(), Buff, nChars) > 0)
{
if (Buff.ToString() == "Euro Truck Simulator 2 Multiplayer" || Buff.ToString() == "American Truck Simulator Multiplayer")
{
return true;
}
else
{
return false;
}
}
return false;
}
public static bool CheckGame()
{
IntPtr etsHandle = FindWindow("prism3d", "Euro Truck Simulator 2 Multiplayer");
if (etsHandle == IntPtr.Zero)
{
etsHandle = FindWindow("prism3d", "American Truck Simulator Multiplayer");
if (etsHandle != IntPtr.Zero) return true;
return false;
}
else
{
return true;
}
}
public void DestroyTimer()
{
playSound(Properties.Resources.afkStop);
AFKTimer.Dispose();
}
async void WriteKey(object sender, ElapsedEventArgs e)
{
if (!statusOfTruckersMP) return;
if (telemetry.isEtsPaused) return;
if (!isEtsForegroud)
{
playSound(Properties.Resources.afkError);
return;
}
if (isOn)
{
playSound(Properties.Resources.afkStart);
isOn = false;
} else
{
playSound(Properties.Resources.afk);
}
var inputSim = new InputSimulator();
for(int i = 0; i < _afkText.LongCount(); i++)
{
if (!isEtsForegroud) return;
inputSim.Keyboard.KeyPress(VirtualKeyCode.VK_Y);
inputSim.Keyboard.TextEntry(_afkText[i].T);
inputSim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
await Task.Delay(550);
}
}
private void playSound(System.IO.UnmanagedMemoryStream sound)
{
var player = new SoundPlayer(sound);
player.Load();
player.Play();
}
public static bool statusOfTruckersMP { get; set; }
public static bool isEtsForegroud { get; set; }
}
}