added discord-rpc

This commit is contained in:
Anonymous275
2022-01-18 13:58:49 +02:00
parent 93eb82080c
commit 6e45304aea
10 changed files with 78 additions and 28 deletions

View File

@@ -11,27 +11,28 @@
namespace fs = std::filesystem;
void Launcher::loadConfig() {
if(fs::exists("Launcher.cfg")){
std::ifstream cfg("Launcher.cfg");
if(cfg.is_open()) {
auto Size = fs::file_size("Launcher.cfg");
std::string Buffer(Size, 0);
cfg.read(&Buffer[0], std::streamsize(Size));
cfg.close();
toml::table config = toml::parse(cfg);
LOG(INFO) << "Parsing";
if(config["Port"].is_value()) {
/*auto Port = config["Port"].as_integer()->get();
LOG(INFO) << Port;*/
LOG(INFO) << "Got port";
}
}else LOG(FATAL) << "Failed to open Launcher.cfg!";
if(fs::exists("Launcher.cfg")) {
toml::table config = toml::parse_file("Launcher.cfg");
auto ui = config["UI"];
auto build = config["Build"];
if(ui.is_boolean()) {
EnableUI = ui.as_boolean()->get();
} else LOG(ERROR) << "Failed to get 'UI' boolean from config";
//Default -1 / Release 1 / EA 2 / Dev 3 / Custom 3
if(build.is_string()) {
TargetBuild = build.as_string()->get();
for(char& c : TargetBuild)c = char(tolower(c));
} else LOG(ERROR) << "Failed to get 'Build' string from config";
} else {
std::ofstream cfg("Launcher.cfg");
if(cfg.is_open()){
cfg <<
R"(Port = 4444
R"(UI = true
Build = "Default"
)";
cfg.close();

27
src/Discord.cpp Normal file
View File

@@ -0,0 +1,27 @@
///
/// Created by Anonymous275 on 1/18/22
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
///
#include <discord_rpc.h>
#include "Launcher.h"
void Launcher::richPresence() {
Discord_Initialize("629743237988352010", nullptr, 1,nullptr);
while(!Shutdown) {
DiscordRichPresence discordPresence;
memset(&discordPresence, 0, sizeof(discordPresence));
if(DiscordMessage.empty()) DiscordMessage = "Playing with friends!";
discordPresence.state = DiscordMessage.c_str();
discordPresence.startTimestamp = 0;
discordPresence.largeImageKey = "mainlogo";
Discord_UpdatePresence(&discordPresence);
Discord_RunCallbacks();
std::this_thread::sleep_for(std::chrono::seconds(1));
}
Discord_ClearPresence();
}
void Launcher::runDiscordRPC() {
DiscordRPC = std::thread(&Launcher::richPresence, this);
}

View File

@@ -15,6 +15,12 @@ Launcher::Launcher(int argc, char* argv[]) : DirPath(argv[0]) {
WindowsInit();
}
Launcher::~Launcher() {
if(DiscordRPC.joinable()) {
DiscordRPC.join();
}
}
void Launcher::launchGame() {
ShellExecuteA(nullptr, nullptr, "steam://rungameid/284160", nullptr, nullptr, SW_SHOWNORMAL);
ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
@@ -43,3 +49,4 @@ const std::string& Launcher::getUserRole() {
}

View File

@@ -77,7 +77,7 @@ std::string Launcher::Login(const std::string& fields) {
return GetFail("Invalid message parsing!");
}
void Launcher::checkLocalKey() {
void Launcher::checkKey() {
if(fs::exists("key") && fs::file_size("key") < 100){
std::ifstream Key("key");
if(Key.is_open()) {

View File

@@ -7,7 +7,9 @@
#include "Logger.h"
int main(int argc, char* argv[]) {
Launcher launcher(argc, argv);
launcher.checkLocalKey();
launcher.loadConfig();
launcher.checkKey();
//UI call
return 0;
}