mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-19 23:20:57 +00:00
added discord-rpc
This commit is contained in:
@@ -18,7 +18,7 @@ jobs:
|
|||||||
uses: lukka/run-vcpkg@v7
|
uses: lukka/run-vcpkg@v7
|
||||||
id: runvcpkg
|
id: runvcpkg
|
||||||
with:
|
with:
|
||||||
vcpkgArguments: 'discord-rpc zlib rapidjson openssl'
|
vcpkgArguments: 'zlib openssl'
|
||||||
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||||
vcpkgGitCommitId: '75522bb1f2e7d863078bcd06322348f053a9e33f'
|
vcpkgGitCommitId: '75522bb1f2e7d863078bcd06322348f053a9e33f'
|
||||||
vcpkgTriplet: 'x64-windows-static'
|
vcpkgTriplet: 'x64-windows-static'
|
||||||
|
|||||||
@@ -13,3 +13,6 @@
|
|||||||
[submodule "include/easyloggingpp"]
|
[submodule "include/easyloggingpp"]
|
||||||
path = include/easyloggingpp
|
path = include/easyloggingpp
|
||||||
url = https://github.com/amrayn/easyloggingpp.git
|
url = https://github.com/amrayn/easyloggingpp.git
|
||||||
|
[submodule "include/discord-rpc"]
|
||||||
|
path = include/discord-rpc
|
||||||
|
url = https://github.com/discord/discord-rpc.git
|
||||||
|
|||||||
+5
-5
@@ -16,6 +16,7 @@ if (WIN32)
|
|||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
set(wxUSE_STL ON)
|
set(wxUSE_STL ON)
|
||||||
|
set(BUILD_EXAMPLES OFF)
|
||||||
set(wxBUILD_SHARED OFF)
|
set(wxBUILD_SHARED OFF)
|
||||||
set(build_static_lib ON)
|
set(build_static_lib ON)
|
||||||
set(wxBUILD_MSVC_MULTIPROC ON)
|
set(wxBUILD_MSVC_MULTIPROC ON)
|
||||||
@@ -23,6 +24,7 @@ set(wxBUILD_USE_STATIC_RUNTIME ON)
|
|||||||
|
|
||||||
add_subdirectory(include/wxWidgets)
|
add_subdirectory(include/wxWidgets)
|
||||||
add_subdirectory(include/rapidjson)
|
add_subdirectory(include/rapidjson)
|
||||||
|
add_subdirectory(include/discord-rpc)
|
||||||
add_subdirectory(include/cpp-httplib)
|
add_subdirectory(include/cpp-httplib)
|
||||||
add_subdirectory(include/tomlplusplus)
|
add_subdirectory(include/tomlplusplus)
|
||||||
|
|
||||||
@@ -38,15 +40,13 @@ add_executable(${PROJECT_NAME}
|
|||||||
src/gui/gifs.cpp src/gui/gifs.h
|
src/gui/gifs.cpp src/gui/gifs.h
|
||||||
src/Network/Http.cpp include/Http.h
|
src/Network/Http.cpp include/Http.h
|
||||||
src/Login.cpp src/Config.cpp
|
src/Login.cpp src/Config.cpp
|
||||||
|
src/Discord.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/lib/discord-rpc.lib
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32 wx::net wx::core wx::base)
|
ZLIB::ZLIB discord-rpc OpenSSL::SSL OpenSSL::Crypto ws2_32 wx::net wx::core wx::base)
|
||||||
elseif (UNIX)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s")
|
|
||||||
target_link_libraries(${PROJECT_NAME} wx::net wx::core wx::base)
|
|
||||||
else(WIN32) #MINGW
|
else(WIN32) #MINGW
|
||||||
add_definitions("-D_WIN32_WINNT=0x0600")
|
add_definitions("-D_WIN32_WINNT=0x0600")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
||||||
|
|||||||
+13
-4
@@ -5,27 +5,36 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
class Launcher {
|
class Launcher {
|
||||||
public: //constructors
|
public: //constructors
|
||||||
Launcher(int argc, char* argv[]);
|
Launcher(int argc, char* argv[]);
|
||||||
|
~Launcher();
|
||||||
public: //available functions
|
public: //available functions
|
||||||
std::string Login(const std::string& fields);
|
std::string Login(const std::string& fields);
|
||||||
void checkLocalKey();
|
void runDiscordRPC();
|
||||||
void loadConfig();
|
void loadConfig();
|
||||||
void launchGame();
|
void launchGame();
|
||||||
|
void checkKey();
|
||||||
public: //Getters
|
public: //Getters
|
||||||
const std::string& getFullVersion();
|
const std::string& getFullVersion();
|
||||||
const std::string& getWorkingDir();
|
const std::string& getWorkingDir();
|
||||||
const std::string& getUserRole();
|
const std::string& getUserRole();
|
||||||
const std::string& getVersion();
|
const std::string& getVersion();
|
||||||
private: //functions
|
private: //functions
|
||||||
|
void richPresence();
|
||||||
void WindowsInit();
|
void WindowsInit();
|
||||||
private: //variables
|
private: //variables
|
||||||
std::string DirPath;
|
bool EnableUI = true;
|
||||||
std::string UserRole;
|
bool Shutdown = false;
|
||||||
std::string PublicKey;
|
std::string DirPath{};
|
||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
|
std::string UserRole{};
|
||||||
|
std::string PublicKey{};
|
||||||
|
std::thread DiscordRPC{};
|
||||||
|
std::string DiscordMessage{};
|
||||||
std::string Version{"3.0"};
|
std::string Version{"3.0"};
|
||||||
|
std::string TargetBuild{"default"};
|
||||||
std::string FullVersion{Version + ".0"};
|
std::string FullVersion{Version + ".0"};
|
||||||
};
|
};
|
||||||
|
|||||||
Submodule
+1
Submodule include/discord-rpc added at e4c0c569ec
+17
-16
@@ -11,27 +11,28 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Launcher::loadConfig() {
|
void Launcher::loadConfig() {
|
||||||
if(fs::exists("Launcher.cfg")){
|
if(fs::exists("Launcher.cfg")) {
|
||||||
std::ifstream cfg("Launcher.cfg");
|
toml::table config = toml::parse_file("Launcher.cfg");
|
||||||
if(cfg.is_open()) {
|
auto ui = config["UI"];
|
||||||
auto Size = fs::file_size("Launcher.cfg");
|
auto build = config["Build"];
|
||||||
std::string Buffer(Size, 0);
|
if(ui.is_boolean()) {
|
||||||
cfg.read(&Buffer[0], std::streamsize(Size));
|
EnableUI = ui.as_boolean()->get();
|
||||||
cfg.close();
|
} else LOG(ERROR) << "Failed to get 'UI' boolean from config";
|
||||||
toml::table config = toml::parse(cfg);
|
|
||||||
LOG(INFO) << "Parsing";
|
//Default -1 / Release 1 / EA 2 / Dev 3 / Custom 3
|
||||||
if(config["Port"].is_value()) {
|
if(build.is_string()) {
|
||||||
/*auto Port = config["Port"].as_integer()->get();
|
TargetBuild = build.as_string()->get();
|
||||||
LOG(INFO) << Port;*/
|
for(char& c : TargetBuild)c = char(tolower(c));
|
||||||
LOG(INFO) << "Got port";
|
} else LOG(ERROR) << "Failed to get 'Build' string from config";
|
||||||
}
|
|
||||||
}else LOG(FATAL) << "Failed to open Launcher.cfg!";
|
|
||||||
} else {
|
} else {
|
||||||
std::ofstream cfg("Launcher.cfg");
|
std::ofstream cfg("Launcher.cfg");
|
||||||
if(cfg.is_open()){
|
if(cfg.is_open()){
|
||||||
cfg <<
|
cfg <<
|
||||||
R"(Port = 4444
|
R"(UI = true
|
||||||
Build = "Default"
|
Build = "Default"
|
||||||
)";
|
)";
|
||||||
cfg.close();
|
cfg.close();
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -15,6 +15,12 @@ Launcher::Launcher(int argc, char* argv[]) : DirPath(argv[0]) {
|
|||||||
WindowsInit();
|
WindowsInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Launcher::~Launcher() {
|
||||||
|
if(DiscordRPC.joinable()) {
|
||||||
|
DiscordRPC.join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Launcher::launchGame() {
|
void Launcher::launchGame() {
|
||||||
ShellExecuteA(nullptr, nullptr, "steam://rungameid/284160", nullptr, nullptr, SW_SHOWNORMAL);
|
ShellExecuteA(nullptr, nullptr, "steam://rungameid/284160", nullptr, nullptr, SW_SHOWNORMAL);
|
||||||
ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
|
ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
|
||||||
@@ -43,3 +49,4 @@ const std::string& Launcher::getUserRole() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ std::string Launcher::Login(const std::string& fields) {
|
|||||||
return GetFail("Invalid message parsing!");
|
return GetFail("Invalid message parsing!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::checkLocalKey() {
|
void Launcher::checkKey() {
|
||||||
if(fs::exists("key") && fs::file_size("key") < 100){
|
if(fs::exists("key") && fs::file_size("key") < 100){
|
||||||
std::ifstream Key("key");
|
std::ifstream Key("key");
|
||||||
if(Key.is_open()) {
|
if(Key.is_open()) {
|
||||||
|
|||||||
+3
-1
@@ -7,7 +7,9 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
Launcher launcher(argc, argv);
|
Launcher launcher(argc, argv);
|
||||||
launcher.checkLocalKey();
|
|
||||||
launcher.loadConfig();
|
launcher.loadConfig();
|
||||||
|
launcher.checkKey();
|
||||||
|
//UI call
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user