mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +00:00
v1.48
This commit is contained in:
parent
2c93c953ec
commit
9da17ae73a
@ -21,9 +21,11 @@ extern std::string ListOfMods;
|
||||
bool Confirm = false;
|
||||
void Reset();
|
||||
std::set<std::string> Conf;
|
||||
|
||||
void StartSync(const std::string &Data){
|
||||
UlStatus = "UlLoading...";
|
||||
Terminate = false;
|
||||
TCPTerminate = false;
|
||||
Conf.clear();
|
||||
std::thread t1(ProxyThread,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
||||
//std::thread t1(ProxyThread,"127.0.0.1",30814);
|
||||
|
@ -12,15 +12,12 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
extern bool Dev;
|
||||
extern char*EName;
|
||||
static const char* APPLICATION_ID = "629743237988352010";
|
||||
static int64_t StartTime;
|
||||
static int SendPresence = 1;
|
||||
static std::vector<std::string> LocalInfo;
|
||||
|
||||
std::vector<std::string> GetDiscordInfo(){
|
||||
return LocalInfo;
|
||||
}
|
||||
|
||||
std::vector<std::string> GlobalInfo;
|
||||
std::string hta(const std::string& hex);
|
||||
static void updateDiscordPresence()
|
||||
{
|
||||
if (SendPresence) {
|
||||
@ -48,15 +45,28 @@ static void updateDiscordPresence()
|
||||
}
|
||||
}
|
||||
|
||||
std::string ATH(const std::string& text){
|
||||
std::string hex;
|
||||
for (const char&c : text) {
|
||||
int des = (int)c;
|
||||
char*C = new char[5]{0};
|
||||
_itoa_s(des,C,5,16);
|
||||
hex += C;
|
||||
delete[] C;
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
static void handleDiscordReady(const DiscordUser* connectedUser)
|
||||
{
|
||||
/*printf("\nDiscord: connected to user %s#%s - %s\n",
|
||||
connectedUser->username,
|
||||
connectedUser->discriminator,
|
||||
connectedUser->userId);*/
|
||||
LocalInfo.emplace_back(connectedUser->username);
|
||||
LocalInfo.emplace_back(connectedUser->discriminator);
|
||||
LocalInfo.emplace_back(connectedUser->userId);
|
||||
GlobalInfo.emplace_back(connectedUser->username);
|
||||
GlobalInfo.emplace_back(ATH(connectedUser->discriminator));
|
||||
GlobalInfo.emplace_back(ATH(connectedUser->userId));
|
||||
GlobalInfo.emplace_back(connectedUser->userId);
|
||||
}
|
||||
|
||||
static void handleDiscordDisconnected(int errcode, const char* message)
|
||||
@ -112,6 +122,7 @@ static void handleDiscordJoinRequest(const DiscordUser* request)
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
static void discordInit()
|
||||
{
|
||||
DiscordEventHandlers handlers;
|
||||
@ -122,7 +133,7 @@ static void discordInit()
|
||||
handlers.joinGame = handleDiscordJoin;
|
||||
handlers.spectateGame = handleDiscordSpectate;
|
||||
handlers.joinRequest = handleDiscordJoinRequest;
|
||||
Discord_Initialize(APPLICATION_ID, &handlers, 1, NULL);
|
||||
Discord_Initialize(APPLICATION_ID, &handlers, 1,nullptr);
|
||||
}
|
||||
|
||||
[[noreturn]] static void Loop()
|
||||
@ -139,14 +150,37 @@ static void discordInit()
|
||||
Discord_UpdateConnection();
|
||||
#endif
|
||||
Discord_RunCallbacks();
|
||||
if(LocalInfo.empty()){
|
||||
if(GlobalInfo.empty()){
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||
}else std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
}
|
||||
}
|
||||
void SystemExec(const std::string& cmd);
|
||||
[[noreturn]] void SecurityLoop(){
|
||||
static std::string t;
|
||||
static std::string t1;
|
||||
static std::string t2;
|
||||
t.clear();
|
||||
t1.clear();
|
||||
t2.clear();
|
||||
while(true){
|
||||
if(!GlobalInfo.empty() && GlobalInfo.size() == 4){
|
||||
if(t.empty()){
|
||||
t = GlobalInfo.at(0);
|
||||
t1 = GlobalInfo.at(1);
|
||||
t2 = GlobalInfo.at(2);
|
||||
}else if(t2 != ATH(GlobalInfo.at(3)) || t != GlobalInfo.at(0) ||
|
||||
t1 != GlobalInfo.at(1) || t2 != GlobalInfo.at(2))exit(0);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Discord_Main()
|
||||
{
|
||||
auto*S = new std::thread(SecurityLoop);
|
||||
S->detach();
|
||||
discordInit();
|
||||
Loop();
|
||||
Discord_Shutdown();
|
||||
|
@ -13,6 +13,7 @@
|
||||
extern std::vector<std::string> GlobalInfo;
|
||||
void Exit(const std::string& Msg);
|
||||
namespace fs = std::experimental::filesystem;
|
||||
std::string HTA(const std::string& hex);
|
||||
extern std::string UlStatus;
|
||||
extern bool TCPTerminate;
|
||||
extern bool Terminate;
|
||||
@ -85,12 +86,12 @@ void WaitForConfirm(){
|
||||
Confirm = false;
|
||||
}
|
||||
|
||||
extern char* ver;
|
||||
void SyncResources(SOCKET Sock){
|
||||
std::cout << "Checking Resources..." << std::endl;
|
||||
std::string HandShakeVer = "1.46";
|
||||
CheckForDir();
|
||||
STCPSend(Sock,"NR" + GlobalInfo.at(0) + ":" +GlobalInfo.at(2));
|
||||
STCPSend(Sock,"VC" + HandShakeVer);
|
||||
STCPSend(Sock,HTA("4e52") + GlobalInfo.at(0) + ":" + HTA(GlobalInfo.at(2)));
|
||||
STCPSend(Sock,std::string("5643")+ver);
|
||||
auto Res = STCPRecv(Sock);
|
||||
std::string msg = Res.first;
|
||||
if(msg.size() < 2 || msg.substr(0,2) != "WS"){
|
||||
|
@ -28,6 +28,7 @@ std::string HTA(const std::string& hex)
|
||||
}
|
||||
return ascii;
|
||||
}
|
||||
|
||||
LONG OpenKey(HKEY root,const char* path,PHKEY hKey){
|
||||
return RegOpenKeyEx(root, reinterpret_cast<LPCSTR>(path), 0, KEY_READ, hKey);
|
||||
}
|
||||
|
@ -4,39 +4,56 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
|
||||
int Download(const std::string& URL,const std::string& path);
|
||||
std::string HTTP_REQUEST(const std::string&url,int port);
|
||||
std::string HTA(const std::string& hex);
|
||||
void SystemExec(const std::string& cmd);
|
||||
void WinExec(const std::string& cmd);
|
||||
void Exit(const std::string& Msg);
|
||||
void URelaunch(int argc,char* args[]);
|
||||
void ReLaunch(int argc,char*args[]);
|
||||
void Exit(const std::string& Msg);
|
||||
extern char*EName;
|
||||
std::string hta(const std::string& hex)
|
||||
{
|
||||
std::string ascii;
|
||||
for (size_t i = 0; i < hex.length(); i += 2)
|
||||
{
|
||||
std::string part = hex.substr(i, 2);
|
||||
char ch = char(stoul(part, nullptr, 16));
|
||||
ascii += ch;
|
||||
}
|
||||
return ascii;
|
||||
}
|
||||
|
||||
void CheckForUpdates(int argc,char*args[],const std::string& CV){
|
||||
std::string link = "https://beamng-mp.com/builds/launcher?version=true";
|
||||
std::string link = hta("68747470733a2f2f6265616d6e672d6d702e636f6d2f6275696c64732f6c61756e636865723f76657273696f6e3d74727565");
|
||||
//https://beamng-mp.com/builds/launcher?version=true
|
||||
std::string HTTP = HTTP_REQUEST(link,443);
|
||||
link = "https://beamng-mp.com/builds/launcher?download=true";
|
||||
if(HTTP.find_first_of("0123456789") == std::string::npos){
|
||||
Exit("Primary Servers Offline! sorry for the inconvenience!");
|
||||
}
|
||||
link = hta("68747470733a2f2f6265616d6e672d6d702e636f6d2f6275696c64732f6c61756e636865723f646f776e6c6f61643d74727565");
|
||||
//https://beamng-mp.com/builds/launcher?download=true
|
||||
|
||||
struct stat buffer{};
|
||||
if(stat ("BeamMP-Launcher.back", &buffer) == 0)remove("BeamMP-Launcher.back");
|
||||
std::string Back = hta("4265616d4d502d4c61756e636865722e6261636b");
|
||||
//BeamMP-Launcher.back
|
||||
if(stat(Back.c_str(), &buffer) == 0)remove(Back.c_str());
|
||||
if(HTTP > CV){
|
||||
system("cls");
|
||||
std::cout << "Update found!" << std::endl;
|
||||
std::cout << "Updating..." << std::endl;
|
||||
SystemExec("rename BeamMP-Launcher.exe BeamMP-Launcher.back>nul");
|
||||
if(int i = Download(link, "BeamMP-Launcher.exe") != -1){
|
||||
SystemExec("rename "+hta(EName)+" "+Back+">nul");
|
||||
if(int i = Download(link, hta(EName)) != -1){
|
||||
std::cout << "Launcher Update failed! trying again... code : " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
if(int i2 = Download(link, "BeamMP-Launcher.exe") != -1){
|
||||
if(int i2 = Download(link, hta(EName)) != -1){
|
||||
std::cout << "Launcher Update failed! code : " << i2 << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
ReLaunch(argc,args);
|
||||
}
|
||||
|
||||
}
|
||||
WinExec("BeamMP-Launcher.exe");
|
||||
exit(1);
|
||||
URelaunch(argc,args);
|
||||
}else{
|
||||
std::cout << "Version is up to date" << std::endl;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
#define CURL_STATICLIB
|
||||
#include "curl/curl.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
void Exit(const std::string& Msg);
|
||||
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
|
72
src/main.cpp
72
src/main.cpp
@ -14,17 +14,19 @@ int Download(const std::string& URL,const std::string& OutFileName);
|
||||
void StartGame(const std::string&ExeDir,const std::string&Current);
|
||||
std::string HTTP_REQUEST(const std::string&url,int port);
|
||||
void CheckForUpdates(int argc,char*args[],const std::string& CV);
|
||||
std::vector<std::string> GetDiscordInfo();
|
||||
char*EName = (char*)"4265616d4d502d4c61756e636865722e657865";
|
||||
extern std::vector<std::string> GlobalInfo;
|
||||
std::string HTA(const std::string& hex);
|
||||
extern std::vector<std::string> SData;
|
||||
std::vector<std::string> GlobalInfo;
|
||||
std::string getHardwareID();
|
||||
char* ver = (char*)"1.46";
|
||||
char* ver = (char*)"312e3438"; //1.48
|
||||
int DEFAULT_PORT = 4444;
|
||||
void Discord_Main();
|
||||
bool Dev = false;
|
||||
void ProxyStart();
|
||||
void ExitError();
|
||||
void Check();
|
||||
|
||||
void SystemExec(const std::string& cmd){
|
||||
system(cmd.c_str());
|
||||
}
|
||||
@ -46,16 +48,12 @@ void ReLaunch(int argc,char*args[]){
|
||||
Arg += args[c-1];
|
||||
}
|
||||
system("cls");
|
||||
ShellExecute(nullptr,"runas","BeamMP-Launcher.exe",Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||
ShellExecute(nullptr,"runas",HTA(EName).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||
exit(1);
|
||||
}
|
||||
std::string CheckDir(int argc,char*args[]){
|
||||
struct stat info{};
|
||||
std::string DN = "BeamMP-Launcher.exe",CDir = args[0],FN = CDir.substr(CDir.find_last_of('\\')+1);
|
||||
if(FN != DN){
|
||||
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
||||
SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
||||
}
|
||||
std::string CDir = args[0];
|
||||
if(stat("BeamNG",&info)){
|
||||
SystemExec("mkdir BeamNG>nul");
|
||||
if(stat("BeamNG",&info))ReLaunch(argc,args);
|
||||
@ -82,23 +80,48 @@ std::string CheckVer(const std::string &path){
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
std::string HTA(const std::string& hex);
|
||||
|
||||
void URelaunch(int argc,char* args[]){
|
||||
std::string Arg;
|
||||
for(int c = 2; c <= argc; c++){
|
||||
Arg += " ";
|
||||
Arg += args[c-1];
|
||||
}
|
||||
ShellExecute(nullptr,"open",HTA(EName).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void CheckName(int argc,char* args[]){
|
||||
struct stat info{};
|
||||
std::string DN = HTA(EName),CDir = args[0],FN = CDir.substr(CDir.find_last_of('\\')+1);
|
||||
if(FN != DN){
|
||||
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
||||
if(stat(DN.c_str(),&info)==0)ReLaunch(argc,args);
|
||||
SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
||||
URelaunch(argc,args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
const unsigned long long NPos = std::string::npos;
|
||||
struct stat info{};
|
||||
system("cls");
|
||||
SetWindowTextA(GetConsoleWindow(),("BeamMP Launcher v" + HTA(ver)).c_str());
|
||||
CheckName(argc,argv);
|
||||
DWORD prev_mode;
|
||||
GetConsoleMode(GetCurrentProcess(), &prev_mode);
|
||||
SetConsoleMode(GetCurrentProcess(), ENABLE_EXTENDED_FLAGS | (prev_mode & ~ENABLE_QUICK_EDIT_MODE));
|
||||
|
||||
std::string link, HTTP_Result;
|
||||
SetWindowTextA(GetConsoleWindow(),("BeamMP Launcher v" + std::string(ver)).c_str());
|
||||
std::thread t1(Discord_Main);
|
||||
t1.detach();
|
||||
std::cout << "Connecting to discord client..." << std::endl;
|
||||
while(GlobalInfo.empty()){
|
||||
GlobalInfo = GetDiscordInfo();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
|
||||
while(GlobalInfo.empty())std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
std::cout << "Client Connected!" << std::endl;
|
||||
link = "https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2);
|
||||
link = HTA("68747470733a2f2f6265616d6e672d6d702e636f6d2f656e7469746c656d656e743f6469643d")+
|
||||
HTA(GlobalInfo.at(2));
|
||||
//https://beamng-mp.com/entitlement?did=
|
||||
HTTP_Result = HTTP_REQUEST(link,443);
|
||||
/*if (HTTP_Result.find("\"MOD\"") == NPos && HTTP_Result.find("\"EA\"") == NPos){
|
||||
if (HTTP_Result.find("\"SUPPORT\"") == NPos && HTTP_Result.find("\"YT\"") == NPos){
|
||||
@ -110,9 +133,9 @@ int main(int argc, char* argv[]){
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(-1);
|
||||
}
|
||||
if(HTTP_Result.find("\"MDEV\"") != NPos)Dev = true;
|
||||
if(HTTP_Result.find(HTA("224d44455622")) != NPos)Dev = true;
|
||||
std::string Path = CheckDir(argc,argv);
|
||||
std::thread CFU(CheckForUpdates,argc,argv,std::string(ver));
|
||||
std::thread CFU(CheckForUpdates,argc,argv,HTA(ver));
|
||||
CFU.join();
|
||||
|
||||
if(argc > 1){
|
||||
@ -132,7 +155,6 @@ int main(int argc, char* argv[]){
|
||||
delete Sec;
|
||||
if(SData.size() != 3)ExitError();
|
||||
std::string GamePath = SData.at(2);
|
||||
if(Dev)std::cout << "You own BeamNG on this machine!" << std::endl;
|
||||
std::cout << "Game Version : " << CheckVer(GamePath) << std::endl;
|
||||
std::string ExeDir = GamePath.substr(0,GamePath.find_last_of('\\')) + R"(\Bin64\BeamNG.drive.x64.exe)";
|
||||
std::string DUI = Path + R"(\settings\uiapps-layouts.json)";
|
||||
@ -154,7 +176,9 @@ int main(int argc, char* argv[]){
|
||||
GS.clear();
|
||||
if(!Dev){
|
||||
std::cout << "Downloading mod..." << std::endl;
|
||||
link = "https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2);
|
||||
//https://beamng-mp.com/builds/client?did=
|
||||
link = HTA("68747470733a2f2f6265616d6e672d6d702e636f6d2f6275696c64732f636c69656e743f6469643d")
|
||||
+HTA(GlobalInfo.at(2));
|
||||
Download(link,Path + R"(\mods\BeamMP.zip)");
|
||||
std::cout << "Download Complete!" << std::endl;
|
||||
link.clear();
|
||||
@ -162,9 +186,9 @@ int main(int argc, char* argv[]){
|
||||
Game.detach();
|
||||
}else{
|
||||
std::cout << "Name : " << GlobalInfo.at(0) << std::endl;
|
||||
std::cout << "Discriminator : " << GlobalInfo.at(1) << std::endl;
|
||||
std::cout << "Unique ID : " << GlobalInfo.at(2) << std::endl;
|
||||
std::cout << "HWID : " << getHardwareID() << std::endl;
|
||||
std::cout << "Discriminator : " << HTA(GlobalInfo.at(1)) << std::endl;
|
||||
std::cout << "Unique ID : " << HTA(GlobalInfo.at(2)) << std::endl;
|
||||
//std::cout << "HWID : " << getHardwareID() << std::endl;
|
||||
std::cout << "you have : " << HTTP_Result << std::endl;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user