Skip to content

Commit

Permalink
Merge pull request #2 from Simon-12/dev
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Simon-12 authored Jun 21, 2024
2 parents d96b631 + f6e1267 commit 94d2210
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
vanguard-cli/.vscode/
vanguard-cli/CMakePresets.json
build/
vanguard-cli/build-debug/
vanguard-cli/build-release/
CMakeLists.txt.user
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ $Shortcut.Arguments = "--check";
$Shortcut.Save();
```

#### Used Commands
##### Activate
```
sc config vgc start= demand & sc config vgk start= system
powershell Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "Riot Vanguard" -Value "C:\Program Files\Riot Vanguard\vgtray.exe"
```

##### Deactivate
```
sc config vgc start= disabled & sc config vgk start= disabled & net stop vgc & net stop vgk & taskkill /IM vgtray.exe
powershell Remove-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "Riot Vanguard"
```

## vanguard-gui

<img src="./docs/vanguard-gui.gif" width="30%"/>
Expand All @@ -55,5 +68,5 @@ $Shortcut.Save();
- Tested on Windows 11 with Qt version 6.7.0.
- For the portable version download the latest release from [github/vanguard-out/releases](https://github.com/Simon-12/vanguard-out/releases) and unzip it.
- To build from source, you can also download the source code from releases.
- `vanguard-cli`: dependency [github/CLI11](https://github.com/CLIUtils/CLI11) (no Qt required).
- `vanguard-cli`: dependencies [github/CLI11](https://github.com/CLIUtils/CLI11) and [github/mINI](https://github.com/metayeti/mINI) (there is no Qt required).
- `vanguard-gui`: the easiest way is to open `CMakeLists.txt` in your Qt Creator and configure with one of your installed Qt kits.
8 changes: 8 additions & 0 deletions vanguard-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ endif()
# # Alternative if installed
# find_package(CLI11 CONFIG REQUIRED)

# mINI
# set(mINI_INCLUDE_DIR "")
if(DEFINED mINI_INCLUDE_DIR)
include_directories(${mINI_INCLUDE_DIR})
else()
message(WARNING "mINI_INCLUDE_DIR is not defined!")
endif()

add_executable(vanguard-cli main.cpp)
122 changes: 82 additions & 40 deletions vanguard-cli/main.cpp
Original file line number Diff line number Diff line change
@@ -1,89 +1,131 @@
#include <mini/ini.h>
#include <windows.h>

#include <CLI/CLI.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>

namespace fs = std::filesystem;
fs::path STATE_FILE;

#ifdef NDEBUG
const bool DEBUG_MODE = false;
#else
const bool DEBUG_MODE = true;
#endif

void file_write(const bool state) {
// Create file
std::ofstream file(STATE_FILE, std::ios::trunc);
if (!file.is_open()) {
std::cerr << "Error: unable to create state file" << std::endl;
return;
std::string REGISTER_PATH = "HKLM:/Software/Microsoft/Windows/CurrentVersion/Run";
std::wstring_convert<std::codecvt_utf8<wchar_t>> CONVERTER;

class SettingsFile {
public:
SettingsFile(const std::string& path) {
m_file = new mINI::INIFile(path);
m_file->read(m_ini);

if (m_ini.has("settings")) {
auto& settings = m_ini["settings"];

// State
if (settings.has("state")) {
std::string state = settings["state"];
m_state = state.compare("activate") == 0;
} else
m_state = true;

// Tray path
if (settings.has("tray")) {
m_tray = settings["tray"];
if (m_tray.length() == 0) m_tray = read_tray_path();
} else
m_tray = read_tray_path();
} else {
m_state = true;
m_tray = read_tray_path();
}
}

// Write state
std::string content = state ? "activate" : "deactivate";
file << content;
file.close();
return;
}
// Getter
bool state() { return m_state; }
std::string tray() { return m_tray; }

bool file_read() {
// Check file exist
if (!fs::exists(STATE_FILE)) {
file_write(false);
return false;
// Setter
void set_state(const bool state) {
m_state = state;
update_file();
}
void set_tray(const std::string& path) {
m_tray = path;
update_file();
}

// Read file
std::ifstream file(STATE_FILE);
if (!file.is_open()) {
std::cerr << "Error: unable to read state file" << std::endl;
return false;
private:
void update_file() {
m_ini["settings"]["state"] = m_state ? "activate" : "deactivate";
m_ini["settings"]["tray"] = m_tray;
m_file->write(m_ini);
}
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
return content.compare("activate") == 0;
}

std::string read_tray_path() {
std::string cmd = "powershell (Get-ItemProperty -Path " + REGISTER_PATH + ").'Riot Vanguard'";
std::string out;
char buffer[128];
FILE* pipe = _popen(cmd.c_str(), "r");
if (pipe) {
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
out += buffer;
}
_pclose(pipe);
}
return out;
}

mINI::INIFile* m_file;
mINI::INIStructure m_ini;
bool m_state;
std::string m_tray;
};

void run_command(const std::wstring& cmd) {
ShellExecuteW(NULL, L"runas", L"cmd.exe", (L"/c " + cmd).c_str(), NULL, SW_HIDE);
// https://learn.microsoft.com/de-de/windows/win32/api/shellapi/nf-shellapi-shellexecutew
}

void run_activate() {
void run_activate(const std::string& tray) {
if (DEBUG_MODE)
run_command(L"start calc.exe");
else
else {
run_command(L"sc config vgc start= demand & sc config vgk start= system");

run_command(L"powershell Set-ItemProperty -Path " + CONVERTER.from_bytes(REGISTER_PATH) +
L" -Name 'Riot Vanguard' -Value '" + CONVERTER.from_bytes(tray) + L"'");
}
std::cout << "Vanguard State: Active" << std::endl;
}

void run_deactivate() {
if (DEBUG_MODE)
run_command(L"start calc.exe");
else
else {
run_command(
L"sc config vgc start= disabled & sc config vgk start= disabled & net stop vgc & net stop vgk & taskkill /IM "
L"vgtray.exe");

run_command(L"powershell Remove-ItemProperty -Path " + CONVERTER.from_bytes(REGISTER_PATH) + L" -Name 'Riot Vanguard'");
}
std::cout << "Vanguard State: Inactive" << std::endl;
}

int main(int argc, char** argv) {
// Create app
CLI::App app("Command line tool to temporarily stop and disable Riot Vanguard \n");
app.set_version_flag("-v,--version", "vanguard-cli tool 1.0.0");
app.set_version_flag("-v,--version", "vanguard-cli tool 0.2.0");
app.get_formatter()->column_width(50);

// Set state file path
// Settings file
WCHAR buffer[255] = {0};
GetModuleFileNameW(NULL, buffer, 255);
std::filesystem::path app_path(buffer);
STATE_FILE = app_path.parent_path() / "state";
std::filesystem::path settings_path = app_path.parent_path() / "settings.ini";
SettingsFile settings(settings_path.string());

// Option state
bool state = false;
Expand Down Expand Up @@ -116,7 +158,7 @@ int main(int argc, char** argv) {

// Run check
if (check) {
bool file_state = file_read();
bool file_state = settings.state();
if (!file_state) run_deactivate();

return 0; // Exit
Expand All @@ -125,10 +167,10 @@ int main(int argc, char** argv) {
// Change state
if (option_state->count() > 0) {
if (state) {
file_write(true);
run_activate();
settings.set_state(true);
run_activate(settings.tray());
} else {
file_write(false);
settings.set_state(false);
run_deactivate();
}
}
Expand Down
2 changes: 1 addition & 1 deletion vanguard-gui/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ApplicationWindow {

Label {
text: "<font size='+1'><center><b>" + "vanguard-out"
+ "</b></font></center>" + "<center>Version: 0.1.0</center>"
+ "</b></font></center>" + "<center>Version: 0.2.0</center>"
+ "<br>" + "Tool to temporarily stop and disable Riot Vanguard"
font.pointSize: 10
textFormat: Text.RichText
Expand Down
25 changes: 6 additions & 19 deletions vanguard-gui/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void Controller::startController(const QString &path) {
// Paths
QDir dir(path);
m_cliPath = dir.filePath("vanguard-cli.exe");
m_statePath = dir.filePath("state");
m_settingsPath = dir.filePath("settings.ini");

// Autostart path
QProcess process;
Expand All @@ -80,24 +80,11 @@ void Controller::startController(const QString &path) {
}
m_process->setProgram(m_cliPath);

// Check autostart
if (!QFile::exists(m_autoPath + "\\vanguard-cli.lnk")) {
return; // Exit
}

// Check state file
if (dir.exists(m_statePath)) {
// Read state file
QFile file(m_statePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qInfo() << "Error: could not open state file";
m_disabled = true;
return; // Exit
}
QTextStream in(&file);
QString firstLine = in.readLine();
file.close();
m_state = firstLine.startsWith("activate");
// Read settings file
if (dir.exists(m_settingsPath)) {
QSettings settings(m_settingsPath, QSettings::IniFormat);
QString state = settings.value("settings/state").toString();
m_state = state.startsWith("activate");
}
}

Expand Down
4 changes: 2 additions & 2 deletions vanguard-gui/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <QDir>
#include <QFile>
#include <QFileSystemWatcher>
#include <QObject>
#include <QProcess>
#include <QSettings>
#include <QTextStream>

class Controller : public QObject {
Expand Down Expand Up @@ -39,7 +39,7 @@ public slots:
bool m_disabled;
QString m_path;
QString m_cliPath;
QString m_statePath;
QString m_settingsPath;
QString m_autoPath;
QProcess *m_process;
};
Expand Down

0 comments on commit 94d2210

Please sign in to comment.