-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
497 lines (424 loc) · 15.5 KB
/
main.cpp
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
#include <tuple>
#include <queue>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstdint>
#include <sstream>
#include <ostream>
#include <iostream>
#include <algorithm>
#include <filesystem>
#include <string_view>
#include "cmd.cpp"
#include "nini.cpp"
#include "sleep.cpp"
#include "colors.cpp"
#include "str2color.cpp"
#include <ui_main.h>
#include <windows.h>
#pragma comment(lib, "User32.lib")
#pragma comment(lib, "Advapi32.lib")
#include <QtGui/QIcon>
#include <QtCore/QTimer>
#include <QtGui/QPalette>
#include <QtCore/QString>
#include <QtGui/QTextCursor>
#include <QtWidgets/QApplication>
#include <QtWidgets/QStyleFactory>
#include <QtWidgets/QSystemTrayIcon>
#include <QtCore/QPropertyAnimation>
using namespace std::literals;
namespace fs = std::filesystem;
bool KillerRunning = false;
QSystemTrayIcon* tray_icon;
std::queue<QString> print_queue;
std::ostream& operator<< (std::ostream& out, const QString& str)
{
return out << str.toStdString();
}
void print(const auto& ...args)
{
std::stringstream ss;
(ss << ... << args);
print_queue.emplace(ss.str().c_str());
}
void println(const auto& ...args)
{
std::stringstream ss;
(ss << ... << args) << '\n';
print_queue.emplace(ss.str().c_str());
};
void segfault_handler()
{
MessageBox(NULL, L"SegFault! This Shoudn't Happen!\n"
"Please File a Bug report on GitHub Repository.", L"Fatal Error", MB_OK);
}
void cwd2ExePath()
{
char buffer[MAX_PATH];
GetModuleFileNameA(NULL, buffer, MAX_PATH);
auto exepath = std::string(buffer);
auto dirpath = exepath.substr(0, exepath.find_last_of("\\/"));
SetCurrentDirectoryA(dirpath.c_str());
}
bool iAmAdmin()
{
bool IsElevated = false;
HANDLE hToken = NULL;
TOKEN_ELEVATION elevation;
DWORD dwSize;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
goto Cleanup; // if Failed, we treat as False
if (!GetTokenInformation(hToken, TokenElevation, &elevation, sizeof(elevation), &dwSize))
goto Cleanup; // if Failed, we treat as False
IsElevated = elevation.TokenIsElevated;
Cleanup:
if (hToken)
{
CloseHandle(hToken);
hToken = NULL;
}
return IsElevated;
}
void set_app_theme(QApplication& app, Ini::Section& theme)
{
app.setStyle(QStyleFactory::create(theme["ThemeName"]));
auto myPalette = QPalette(); // Create Dark Palette
myPalette.setColor(QPalette::Window, QString_to_Qcolor(theme["BgColor"]));
myPalette.setColor(QPalette::WindowText, QString_to_Qcolor(theme["TextColor"]));
myPalette.setColor(QPalette::Base, QString_to_Qcolor(theme["BaseColor"]));
myPalette.setColor(QPalette::Text, QString_to_Qcolor(theme["EditableTextColor"]));
myPalette.setColor(QPalette::Button, QString_to_Qcolor(theme["ButtonColor"]));
myPalette.setColor(QPalette::ButtonText, QString_to_Qcolor(theme["ButtonTextColor"]));
myPalette.setColor(QPalette::Link, QString_to_Qcolor(theme["LinkColor"]));
myPalette.setColor(QPalette::Highlight, QString_to_Qcolor(theme["SliderColor"]));
app.setPalette(myPalette);
char stylesheet[1024] = "";
auto ToolTipBaseColor = QString_to_Qcolor(theme["ToolTipBaseColor"]);
auto ToolTipTextColor = QString_to_Qcolor(theme["ToolTipTextColor"]);
std::snprintf(stylesheet, sizeof(stylesheet), "QToolTip {color: rgb(%d, %d, %d); background-color: rgb(%d, %d, %d); border: 1px solid grey;}",
ToolTipTextColor.red(), ToolTipTextColor.green(), ToolTipTextColor.blue(), ToolTipBaseColor.red(), ToolTipBaseColor.green(), ToolTipBaseColor.blue());
app.setStyleSheet(stylesheet);
}
void set_app_theme_ex(QApplication& app, const QString& theme_name, QLabel* author_name=nullptr)
{
Ini::File theme;
theme.load("themes/"+theme_name+".blt");
set_app_theme(app, theme["THEME"]);
if (author_name)
author_name->setText(theme["THEME"]["AuthorName"]);
}
void haxx_on()
{
cmd(R"FucK(Reg.exe add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ClipSVC\Parameters" /v "ServiceDll" /t REG_EXPAND_SZ /d "%%SystemRoot%%\System32\ClipSBC.dll" /f)FucK");
cmd(R"FucK(net stop "ClipSVC")FucK");
}
void haxx_off()
{
cmd(R"FucK(Reg.exe add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ClipSVC\Parameters" /v "ServiceDll" /t REG_EXPAND_SZ /d "%%SystemRoot%%\System32\ClipSVC.dll" /f)FucK");
cmd(R"FucK(net start "ClipSVC")FucK");
}
int status()
{
auto s = cmd2(R"FucK(powershell -Command "Get-WindowsErrorReporting")FucK");
std::cout << s << std::endl;
;;;; if (s == "Enabled\r\n" ) return 1;
else if (s == "Disabled\r\n") return 0;
else return 6;
}
void warning(int time_msec)
{
println("Sent Toast Notification!"_cyn);
tray_icon->showMessage("BLauncher: Potential Crash Warning !",
"It is Recomended to Save any Unsaved Progress within 30 Seconds.",
QIcon("./assets/warn.png"), time_msec);
}
void crash_fix()
{
;;;; if (status() == 1)
{
print("Enabling Crash Fix... ");
cmd(R"FucK(powershell -Command "Disable-WindowsErrorReporting")FucK");
status() == 0 ? println("Success")
: println("Failed");
}
else if (status() == 0)
{
print("Disabling Crash Fix... ");
cmd(R"FucK(powershell -Command "Enable-WindowsErrorReporting")FucK");
status() == 1 ? println("Success")
: println("Failed");
}
else if (status() == 6)
{
println("SOMETHING WENT WRONG...");
}
fflush(stdout);
}
void store_fix()
{
println("Applying Store Fix....");
try
{
cmd2(R"FucK(reg import "./assets/Fix_SVC.reg")FucK");
println("PLEASE RESTART YOUR PC FOR CHANGES TO TAKE EFFECT !"_bldgrn);
}
catch (...)
{
println("TRY RUNNING BLAUNCHER AS ADMINISTRATOR !"_bldred);
}
}
void tamer(uint tame1, uint tame2, const Ui::window& ui)
{
KillerRunning = true;
sleep_for(tame1, "s");
while (true)
{
try
{
cmd2("taskkill /f /im ClipSVC.exe");
cmd2("taskkill /f /im RuntimeBroker.exe");
print("DEATH NOTE ISSUED SUCCESSFULLY !\n");
}
catch (...)
{
print("\nOOPS SOMETHING WENT WRONG...\n"_red);
print("TRY RUNNING BLAUNCHER AS ADMINISTRATOR !\n"_bldred);
}
sleep_for(tame2-30, "s");
if (ui.notif_agree->isChecked())
warning(ui.notif_duration->value());
sleep_for(30, "s");
}
}
void check_startup_conditions()
{
if (!iAmAdmin())
{
MessageBox(NULL, L"Please Run this Program as Administrator!", L"Fatal Error", MB_OK);
std::exit(100);
}
if (!fs::exists("themes"))
{
MessageBox(NULL, L"'themes' directory not found, can't launch GUI.", L"Fatal Error", MB_OK);
std::exit(101);
}
if (fs::is_empty("themes"))
{
MessageBox(NULL, L"No valid theme found, can't launch GUI.", L"Fatal Error", MB_OK);
std::exit(102);
}
if (!fs::exists("assets"))
{
MessageBox(NULL, L"'assets' directory not found, this will cause visual glitches or instability.", L"Warning", MB_OK);
}
if (!fs::exists("plugins/platforms/qwindows.dll"))
{
MessageBox(NULL, L"Qt 'windows' platform plugin not found, can't launch GUI.", L"Fatal Error", MB_OK);
std::exit(103);
}
if (!fs::exists("plugins/imageformats/qico.dll"))
{
MessageBox(NULL, L"Qt 'ico' image format plugin not found, this may cause visual glitches or instability.", L"Warning", MB_OK);
}
}
int main(int argc, char* argv[])
{
std::signal(SIGSEGV, segfault_handler);
cwd2ExePath();
check_startup_conditions();
QApplication app(argc, argv);
QSystemTrayIcon tray_icon_obj{};
tray_icon = &tray_icon_obj;
tray_icon->setIcon(QIcon("assets/logo.ico"));
tray_icon->setToolTip("BLauncher is Running!");
tray_icon->show();
std::atexit([]{tray_icon->~QSystemTrayIcon();});
Ui::window ui;
QWidget win;
ui.setupUi(&win);
auto print_handler = [&ui]()
{
while (!print_queue.empty())
{
ui.console->moveCursor(QTextCursor::End);
ui.console->insertHtml(print_queue.front());
print_queue.pop();
ui.console->moveCursor(QTextCursor::End);
}
};
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, print_handler);
timer.start(250/*ms*/);
auto savef = [&]()
{
Ini::File cfg("settings.ini");
cfg["SLIDERS"]["S1"] = QString(std::to_string( ui.slider1 -> value() ).c_str());
cfg["SLIDERS"]["S2"] = QString(std::to_string( ui.slider2 -> value() ).c_str());
cfg["EXTRAS"]["NOTIF_AGREE"] = QString(std::to_string( ui.notif_agree -> isChecked() ).c_str());
cfg["EXTRAS"]["NOTIF_DURATION"] = QString(std::to_string( ui.notif_duration -> value() ).c_str());
cfg["EXTRAS"]["CURRENT_THEME"] = ( ui.comboBox -> currentText()) ;
cfg["WINDOW"]["H_EXPAND"] = QString(std::to_string(win.width() == win.maximumWidth() ).c_str());
cfg["WINDOW"]["V_EXPAND"] = QString(std::to_string(win.height() == win.maximumHeight()).c_str());
};
auto startf = [&]()
{
if (KillerRunning)
{
print("\nKiller is Already Active !"_cyn);
}
else
{
print("\nInitiating Startup....\n"_grn);
uint tame1 = ui.slider1->value() * 1;
uint tame2 = ui.slider2->value() * 60;
try
{
haxx_on();
cmd("explorer.exe shell:AppsFolder/Microsoft.MinecraftUWP_8wekyb3d8bbwe!App");
auto killer = std::thread(tamer, tame1, tame2, ui);
killer.detach();
}
catch (...)
{
println("OOPS SOMETHING WENT WRONG..."_red);
println("TRY RUNNING BLAUNCHER AS ADMINISTRATOR !"_bldred);
}
}
};
auto stopf = [&]()
{
savef(); // save settings.ini before exiting
if (KillerRunning)
{
print("\nStopping Killer....\n");
try
{
haxx_off();
println("Killer Stopped !"_cyn);
println("EXITING PROGRAM...."_bldcyn);
sleep_for(0.2, "s");
std::exit(1);
}
catch (...)
{
println("OOPS SOMETHING WENT WRONG..."_red);
println("EXITING PROGRAM...."_bldred);
sleep_for(2.0, "s");
std::exit(0);
}
}
else
{
print("\nEXITING PROGRAM....\n"_bldcyn);
sleep_for(0.2, "s");
std::exit(1);
}
};
auto expandf1 = [&]()
{
int TargetWidth1, TargetWidth2;
if (win.width() == win.minimumWidth())
{
TargetWidth1 = win.maximumWidth();
TargetWidth2 = ui.console->maximumWidth();
ui.optionb->setText("Hide Options");
}
else
{
TargetWidth1 = win.minimumWidth();
TargetWidth2 = ui.console->minimumWidth();
ui.optionb->setText("Show Options");
}
// need to do it the pointer way to prevent animation
// from going out of scope before it completes
auto animation1 = new QPropertyAnimation(&win, "size");
animation1->setDuration(500);
animation1->setEndValue(QSize(TargetWidth1, win.height()));
animation1->setEasingCurve(QEasingCurve::OutCubic);
animation1->start(QAbstractAnimation::DeleteWhenStopped);
auto animation2 = new QPropertyAnimation(ui.console, "size");
animation2->setDuration(500);
animation2->setEndValue(QSize(TargetWidth2, win.height()));
animation2->setEasingCurve(QEasingCurve::OutCubic);
animation2->start(QAbstractAnimation::DeleteWhenStopped);
};
auto expandf2 = [&]()
{
int TargetHeight;
if (win.height() == win.minimumHeight())
{
TargetHeight = win.maximumHeight();
ui.consoleb->setText("Hide Console");
}
else
{
TargetHeight = win.minimumHeight();
ui.consoleb->setText("Show Console");
}
// need to do it the pointer way to prevent animation
// from going out of scope before it completes
auto animation = new QPropertyAnimation(&win, "size");
animation->setDuration(400);
animation->setEndValue(QSize(win.width(), TargetHeight));
animation->setEasingCurve(QEasingCurve::OutCubic);
animation->start(QAbstractAnimation::DeleteWhenStopped);
};
QObject::connect(ui.fix1b, &QPushButton::clicked, crash_fix);
QObject::connect(ui.fix2b, &QPushButton::clicked, store_fix);
QObject::connect(ui.startb, &QPushButton::clicked, startf);
QObject::connect(ui.optionb, &QPushButton::clicked, expandf1);
QObject::connect(ui.consoleb, &QPushButton::clicked, expandf2);
QApplication::connect(&app, &QApplication::aboutToQuit, stopf);
QObject::connect(ui.DISCORD, &QPushButton::clicked, [](){cmd("start https://discord.gg/5pkSfFF");});
QObject::connect(ui.YOUTUBE, &QPushButton::clicked, [](){cmd("start https://youtube.com/frakod?sub_confirmation=1");});
QObject::connect(ui.slider1, &QSlider::valueChanged, [&](int value)
{
ui.spinbox1->setValue(value);
});
QObject::connect(ui.slider2, &QSlider::valueChanged, [&](int value)
{
ui.spinbox2->setValue(value);
});
QObject::connect(ui.spinbox1, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [&](double value)
{
ui.slider1->setValue(value);
});
QObject::connect(ui.spinbox2, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [&](double value)
{
ui.slider2->setValue(value);
});
for (auto& entry : fs::directory_iterator("themes"))
{
if (entry.is_regular_file() && entry.path().string().ends_with(".blt"))
ui.comboBox->addItem(entry.path().stem().string().c_str());
}
QObject::connect(ui.comboBox, &QComboBox::currentTextChanged, [&](const QString& ThemeName)
{
set_app_theme_ex(app, ThemeName, ui.auth_name);
});
// Loading last used values
if (fs::exists("settings.ini"))
{
Ini::File cfg; cfg.load("settings.ini");
ui.slider1 -> setValue(cfg["SLIDERS"]["S1"].toInt());
ui.slider2 -> setValue(cfg["SLIDERS"]["S2"].toInt());
ui.notif_agree -> setChecked(cfg["EXTRAS"]["NOTIF_AGREE"].toInt());
ui.notif_duration -> setValue(cfg["EXTRAS"]["NOTIF_DURATION"].toInt());
ui.comboBox -> setCurrentText(cfg["EXTRAS"]["CURRENT_THEME"]);
if (cfg["WINDOW"]["H_EXPAND"].toInt())
{
win.resize(win.maximumWidth(), win.height());
ui.console->resize(ui.console->maximumWidth(), ui.console->height());
ui.optionb->setText("Hide Options");
}
if (cfg["WINDOW"]["V_EXPAND"].toInt())
{
win.resize(win.width(), win.maximumHeight());
ui.consoleb->setText("Hide Console");
}
}
set_app_theme_ex(app, ui.comboBox->currentText());
win.show(); return app.exec();
}