switched to normal filesystem + crash fixes

This commit is contained in:
Anonymous275 2020-12-26 22:52:01 +02:00
parent 757ac6303b
commit ab2a58bf42
5 changed files with 43 additions and 52 deletions

View File

@ -21,7 +21,7 @@
#include <vector>
#include <future>
namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem;
std::string ListOfMods;
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
std::vector<std::string> Val;
@ -126,11 +126,10 @@ char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){
}
char* File = new char[Size];
uint64_t Rcv = 0;
int32_t Temp;
do{
int Len = int(Size-Rcv);
if(Len > 1000000)Len = 1000000;
Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
if(Temp < 1){
info(std::to_string(Temp));
UUl("Socket Closed Code 1");
@ -153,6 +152,7 @@ SOCKET InitDSock(){
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN ServerAddr;
if(DSock < 1){
KillSocket(DSock);
Terminate = true;
return 0;
}
@ -244,6 +244,7 @@ void SyncResources(SOCKET Sock){
}
if(!FNames.empty())info("Syncing...");
SOCKET DSock = InitDSock();
uint64_t ModSize;
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
auto pos = FN->find_last_of('/');
if (pos != std::string::npos) {
@ -252,7 +253,8 @@ void SyncResources(SOCKET Sock){
Pos++;
if (fs::exists(a)) {
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
if (fs::file_size(a) == std::stoi(*FS)){
ModSize = std::stoull(*FS);
if (fs::file_size(a) == ModSize){
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
try {
@ -284,7 +286,7 @@ void SyncResources(SOCKET Sock){
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
Data = MultiDownload(Sock,DSock,std::stoull(*FS), Name);
Data = MultiDownload(Sock,DSock,ModSize, Name);
if(Terminate)break;
UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName);
@ -295,7 +297,7 @@ void SyncResources(SOCKET Sock){
LFS.close();
}
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
}while(fs::file_size(a) != ModSize && !Terminate);
if(!Terminate){
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
fs::create_directory(GetGamePath() + "mods/multiplayer");

View File

@ -13,6 +13,7 @@
#include <sstream>
#include <string>
#include <thread>
#include <ShlDisp.h>
#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383
@ -124,11 +125,10 @@ std::string QueryKey(HKEY hKey,int ID){
delete [] buffer;
return "";
}
namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem;
void FileList(std::vector<std::string>&a,const std::string& Path){
for (const auto &entry : fs::directory_iterator(Path)) {
auto pos = entry.path().filename().string().find('.');
if (pos != std::string::npos) {
if (!entry.is_directory()) {
a.emplace_back(entry.path().string());
}else FileList(a,entry.path().string());
}
@ -241,18 +241,22 @@ void LegitimacyCheck(){
std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
HKEY hKey;
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 1);
if(Result.empty())Exit(1);
if(fs::exists(Result)){
if(!Find("284160.json",Result))Exit(2);
if(!Find("284160.json", Result))Exit(2);
if(FindHack(Result))SteamExit(1);
}else Exit(3);
T = Result;
Result.clear();
TraceBack++;
}else Exit(4);
K1.clear();
RegCloseKey(hKey);
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);

View File

@ -40,6 +40,11 @@ std::string GetFail(const std::string& R){
}
std::string Login(const std::string& fields){
if(fields == "LO"){
LoginAuth = false;
UpdateKey(nullptr);
return "";
}
info("Attempting to authenticate...");
std::string Buffer = PostHTTP("https://auth.beammp.com/userlogin", fields);
json::Document d;
@ -47,6 +52,7 @@ std::string Login(const std::string& fields){
if(Buffer == "-1"){
return GetFail("Failed to communicate with the auth system!");
}
if (Buffer.find('{') == -1 || d.HasParseError()) {
return GetFail("Invalid answer from authentication servers, please try again later!");
}

View File

@ -19,7 +19,7 @@
extern int TraceBack;
bool Dev = false;
namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem;
std::string GetEN(){
return "BeamMP-Launcher.exe";
}
@ -27,7 +27,7 @@ std::string GetVer(){
return "1.80";
}
std::string GetPatch(){
return ".2";
return ".3";
}
void ReLaunch(int argc,char*args[]){
std::string Arg;
@ -182,7 +182,7 @@ void InitLauncher(int argc, char* argv[]) {
CheckName(argc, argv);
CheckLocalKey(); //will replace RequestRole
Discord_Main();
Dev = true;
//Dev = true;
//RequestRole();
CustomPort(argc, argv);
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
@ -190,47 +190,25 @@ void InitLauncher(int argc, char* argv[]) {
void PreGame(int argc, char* argv[],const std::string& GamePath){
info("Game Version : " + CheckVer(GamePath));
std::string DUI = R"(BeamNG\settings\uiapps-layouts.json)";
std::string GS = R"(BeamNG\settings\game-settings.ini)";
std::string link = "https://beammp.com/client-ui-data";
bool fallback = false;
int i;
if(!fs::exists(DUI)){
info("Downloading default ui data...");
i = Download(link,DUI,true);
if(i != -1){
fallback = true;
remove(DUI.c_str());
link = "https://backup1.beammp.com/client-ui-data";
i = Download(link,DUI,true);
if(i != -1) {
error("Failed to download code : " + std::to_string(i));
std::this_thread::sleep_for(std::chrono::seconds(3));
ReLaunch(argc, argv);
}
}
info("Download Complete!");
}
if(!fs::exists(GS)) {
info("Downloading default game settings...");
if(fallback)link = "https://backup1.beammp.com/client-settings-data";
else link = "https://beammp.com/client-settings-data";
Download(link, GS,true);
info("Download Complete!");
}
if(!Dev) {
info("Downloading mod...");
if(fallback)link = "https://backup1.beammp.com/builds/client";
else link ="https://beammp.com/builds/client";
if(!fs::exists(GetGamePath() + "mods")){
fs::create_directory(GetGamePath() + "mods");
//if(fallback)link = "https://backup1.beammp.com/builds/client";
std::string link = "https://beammp.com/builds/client";
try {
if (!fs::exists(GetGamePath() + "mods")) {
fs::create_directory(GetGamePath() + "mods");
}
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
fs::create_directory(GetGamePath() + "mods/multiplayer");
}
}catch(std::exception&e){
fatal(e.what());
}
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
fs::create_directory(GetGamePath() + "mods/multiplayer");
}
Download(link, GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true);
Download(link, GetGamePath() + R"(mods/multiplayer/BeamMP.zip)", true);
info("Download Complete!");
}
/*debug("Name : " + GetDName());
debug("Discriminator : " + GetDTag());
debug("Unique ID : " + GetDID());*/

View File

@ -8,13 +8,14 @@
#include "Network/network.h"
#include "Security/Init.h"
#include "Startup.h"
#include <thread>
#include <iostream>
#include <thread>
[[noreturn]] void flush(){
while(true){
std::cout.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
@ -24,7 +25,7 @@ int main(int argc, char* argv[]) {
th.detach();
#endif
InitLauncher(argc,argv);
CheckDir(argc,argv);
//CheckDir(argc,argv);
LegitimacyCheck();
PreGame(argc,argv,GetGameDir());
InitGame(GetGameDir());