-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
211 lines (182 loc) · 7.7 KB
/
Program.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using AutoAccept_CSGO4.HideChecker;
using AutoAccept_CSGO4.TelegramBot;
namespace AutoAccept_CSGO4
{
internal class Program
{
private const uint LEFTMOUSE_CLICKDOWN = 0x0002;
private const uint LEFTMOUSE_CLICKUP = 0x0004;
private TelegramBotHandler telegramBotHandler;
[DllImport("user32.dll")]
private static extern void mouse_event(uint dwflags, uint dx, uint dy, uint dwData, uint dwExtraInf);
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int x, int y);
public static async Task Main(string[] args)
{
Console.WriteLine(@"
_____ _____ _____ _____ ___ _ ___ _
/ __ \/ ___| __ \ _ | / _ \ | | / _ \ | |
| / \/\ `--.| | \/ | | |______/ /_\ \_ _| |_ ___ / /_\ \ ___ ___ ___ _ __ | |_
| | `--. \ | __| | | |______| _ | | | | __/ _ \| _ |/ __/ __/ _ \ '_ \| __|
| \__/\/\__/ / |_\ \ \_/ / | | | | |_| | || (_) | | | | (_| (_| __/ |_) | |_
\____/\____/ \____/\___/ \_| |_/\__,_|\__\___/\_| |_/\___\___\___| .__/ \__|
| |
|_|
______ _ _ _ __ _____ _____ ___
| ___ \ ____ | | (_) | | / | / __ \|____ | / |
| |_/ /_ _ / __ \ __| | __ ___ ___ __| | __ _ _ __ _ __ ___ _ _ ___ `| | `' / /' / / / /| |
| ___ \ | | | / / _` |/ _` |/ _` \ \ / / |/ _` |/ _` | '__| '__/ _ \| | | |/ _ \ | | / / \ \/ /_| |
| |_/ / |_| | | | (_| | (_| | (_| |\ V /| | (_| | (_| | | | | | (_) | |_| | (_) || |_./ /___.___/ /\___ |
\____/ \__, | \ \__,_|\__,_|\__,_| \_/ |_|\__,_|\__,_|_| |_| \___/ \__, |\___/\___/\_____/\____/ |_/
__/ | \____/ __/ |
|___/ |___/
");
await new Program().Init(args);
}
private async Task Init(string[] args)
{
while (true)
{
try
{
await StartDecision();
}
catch (Exception e)
{
Console.WriteLine("An error has occurred Restarting..." + e.Message);
}
}
}
private async Task StartDecision()
{
Console.WriteLine(
"1- Start bot with Telegram notifications\n" +
"2- Start bot without Telegram notifications\n" +
(TelegramBotHandler.HasTelegramToken() ? "3- Delete telegram token\n" : "")
);
var input = Console.ReadLine();
switch (input)
{
case "1":
await HandleTelegramTokenBeforeInitialization();
break;
case "2":
Console.WriteLine("Starting bot without Telegram notifications...");
await BeginSearch();
break;
case "3" when TelegramBotHandler.HasTelegramToken():
TelegramBotHandler.DeleteTelegramToken();
Console.WriteLine("Token deleted");
break;
default:
Console.WriteLine("Invalid input");
break;
}
await StartDecision();
}
private async Task HandleTelegramTokenBeforeInitialization()
{
telegramBotHandler = new TelegramBotHandler();
if (TelegramBotHandler.HasTelegramToken())
{
await telegramBotHandler.InitializeTelegramBot();
Console.WriteLine("Starting bot with Telegram notifications...");
}
else
{
Console.WriteLine("Enter your telegram bot token:");
var token = Console.ReadLine();
if (!String.IsNullOrEmpty(token))
{
TelegramBotHandler.SetTelegramToken(token);
await telegramBotHandler.InitializeTelegramBot();
Console.WriteLine("Starting bot with Telegram notifications...");
}
else
{
Console.WriteLine("Invalid token");
return;
}
}
await BeginSearch();
}
private async Task BeginSearch()
{
while (true)
{
Thread.Sleep(100);
var csgoOpenChecker = new CsgoOpenChecker();
if (csgoOpenChecker.MinimizedCheck() == -1)
{
Console.WriteLine("Open csgo to start");
}
else if (csgoOpenChecker.MinimizedCheck() == 1)
{
Console.WriteLine("Maximize CSGO");
}
while (csgoOpenChecker.MinimizedCheck() != 0)
{
Thread.Sleep(300);
}
await SearchPixel();
Thread.Sleep(100);
}
}
private async Task SearchPixel()
{
var counter = 0;
var exitLoop = false;
Console.WriteLine("Searching button...");
var color = Color.FromArgb(76, 175, 80);
var color2 = Color.FromArgb(90, 203, 94);
var bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
var graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
for (var x = 0; x < bitmap.Width && !exitLoop; x++)
{
for (var y = 0; y < bitmap.Height; y++)
{
var searchPixel = bitmap.GetPixel(x, y);
if (searchPixel == color || searchPixel == color2)
{
if (counter >= 9000)
{
Thread.Sleep(200);
SetCursorPos(x, y);
await ClickFunc(x, y);
exitLoop = true;
break;
}
counter++;
}
}
}
}
private async Task ClickFunc(int x, int y)
{
Console.WriteLine("Clicking...");
SetCursorPos(x, y);
mouse_event(LEFTMOUSE_CLICKDOWN, 0, 0, 0, 0);
mouse_event(LEFTMOUSE_CLICKUP, 0, 0, 0, 0);
if (telegramBotHandler != null && telegramBotHandler.isInitialized)
{
try
{
Console.WriteLine("Sending notification...");
await telegramBotHandler.SendMatchFoundToAllClients();
}
catch (Exception e)
{
Console.WriteLine("Error sending notification: " + e.Message);
}
}
Thread.Sleep(200);
}
}
}