This commit is contained in:
Anonymous275 2020-06-13 01:06:36 +03:00
parent 7d3898568d
commit d3af7f1d5d
8 changed files with 103 additions and 6051 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
project(BeamMP-Launcher)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
file(GLOB source_files
"src/*.cpp" "src/include/*.h"
@ -11,4 +11,4 @@ file(GLOB source_files
add_executable(BeamMP-Launcher ${source_files})
target_link_libraries(BeamMP-Launcher discord-rpc libcurl_a zlibstatic)
target_link_libraries(BeamMP-Launcher ws2_32 urlmon discord-rpc libcurl_a zlibstatic)

View File

@ -29,8 +29,6 @@ void StartSync(const std::string &Data){
std::string Parse(const std::string& Data){
char Code = Data.substr(0,1).at(0), SubCode = 0;
if(Data.length() > 1)SubCode = Data.substr(1,1).at(0);
////std::cout << "Code : " << Code << std::endl;
////std::cout << "Data : " << Data.substr(1) << std::endl;
switch (Code){
case 'A':
return Data.substr(0,1);

View File

@ -1,9 +1,6 @@
////
//// Created by Anonymous275 on 3/3/2020.
////
#define ENET_IMPLEMENTATION
#include <condition_variable>
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <iostream>
@ -14,7 +11,6 @@
int ClientID = -1;
extern int DEFAULT_PORT;
std::chrono::time_point<std::chrono::steady_clock> PingStart,PingEnd;
extern std::vector<std::string> GlobalInfo;
bool TCPTerminate = false;
bool Terminate = false;
bool CServer = true;
@ -43,25 +39,21 @@ void ServerSend(const std::string&Data, bool Rel){
char C = 0;
bool Ack = false;
if(Data.length() > 3)C = Data.at(0);
if (C == 'O' || C == 'T')Ack = true;
if (C == 'O' || C == 'T' || C == 'C')Ack = true;
if(Ack || Rel){
if(Ack || Data.length() > 1000)SendLarge(Data);
else TCPSend(Data);
}else UDPSend(Data);
if (MPDEV && Data.length() > 1000) {
std::cout << "(Launcher->Server) Bytes sent: " << Data.length()
<< " : "
<< Data.substr(0, 10)
<< Data.substr(Data.length() - 10) << std::endl;
std::cout << "(Launcher->Server) Bytes sent: " + std::to_string(Data.length()) + " : "
+ Data.substr(0, 10)
+ Data.substr(Data.length() - 10) + "\n";
}else if(MPDEV && C == 'Z'){
//std::cout << "(Game->Launcher) : " << Data << std::endl;
}
}
void NameRespond(){
std::string Packet = "NR" + GlobalInfo.at(0)+":"+GlobalInfo.at(2);
ServerSend(Packet,true);
}
void AutoPing(){
while(!Terminate){
@ -85,9 +77,6 @@ void ServerParser(const std::string& Data){
PingEnd = std::chrono::high_resolution_clock::now();
ping = std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd-PingStart).count();
return;
case 'N':
if(SubCode == 'R')NameRespond();
return;
case 'M':
MStatus = Data;
UlStatus = "Uldone";

View File

@ -7,7 +7,7 @@
#include <WS2tcpip.h>
#include <thread>
#pragma comment (lib, "ws2_32.lib")
extern std::string UlStatus;
extern bool Terminate;
extern bool MPDEV;
SOCKET TCPSock;
@ -80,6 +80,7 @@ void TCPClientMain(const std::string& IP,int Port){
RetCode = connect(TCPSock, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
if(RetCode != 0)
{
UlStatus = "UlConnection Failed!";
std::cout << "Client: connect failed! Error code: " << WSAGetLastError() << std::endl;
closesocket(TCPSock);
WSACleanup();

View File

@ -2,17 +2,19 @@
/// Created by Anonymous275 on 4/11/2020
///
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <WS2tcpip.h>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <filesystem>
#include <iostream>
#include <fstream>
#include <string>
#include <thread>
#include <vector>
namespace fs = std::experimental::filesystem;
extern std::vector<std::string> GlobalInfo;
void Exit(const std::string& Msg);
namespace fs = std::filesystem;
extern std::string UlStatus;
extern bool Terminate;
extern bool MPDEV;
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
@ -21,139 +23,107 @@ std::vector<std::string> Split(const std::string& String,const std::string& deli
std::string token,s = String;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
Val.push_back(token);
if(!token.empty())Val.push_back(token);
s.erase(0, pos + delimiter.length());
}
Val.push_back(s);
if(!s.empty())Val.push_back(s);
return Val;
}
std::string STCPRecv(SOCKET socket){
char buf[65535];
int len = 65535;
void STCPSend(SOCKET socket,const std::string&Data){
if(socket == INVALID_SOCKET){
Terminate = true;
return;
}
int BytesSent = send(socket, Data.c_str(), int(Data.length())+1, 0);
if (BytesSent == 0){
if(MPDEV)std::cout << "(TCP) Connection closing..." << std::endl;
Terminate = true;
return;
}
else if (BytesSent < 0) {
if(MPDEV)std::cout << "(TCP) send failed with error: " << WSAGetLastError() << std::endl;
closesocket(socket);
Terminate = true;
return;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
std::pair<char*,int> STCPRecv(SOCKET socket){
char buf[64000];
int len = 64000;
ZeroMemory(buf, len);
int BytesRcv = recv(socket, buf, len,0);
if (BytesRcv == 0){
std::cout << "(TCP) Connection closing..." << std::endl;
return "";
Terminate = true;
return std::make_pair((char*)"",0);
}
else if (BytesRcv < 0) {
std::cout << "(TCP) recv failed with error: " << WSAGetLastError() << std::endl;
closesocket(socket);
return "";
Terminate = true;
return std::make_pair((char*)"",0);
}
return std::string(buf);
char* Ret = new char[BytesRcv];
memcpy_s(Ret,BytesRcv,buf,BytesRcv);
ZeroMemory(buf, len);
return std::make_pair(Ret,BytesRcv);
}
extern bool Terminate;
void SyncResources(SOCKET TCPSock){
if(MPDEV)std::cout << "SyncResources Called" << std::endl;
std::string FileList;
void CheckForDir(){
struct stat info{};
if(stat( "Resources", &info) != 0){
_wmkdir(L"Resources");
}
/*WSADATA wsaData;
SOCKET SendingSocket;
SOCKADDR_IN ServerAddr;
int RetCode;
int BytesSent, nlen;
WSAStartup(514, &wsaData); //2.2
SendingSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(SendingSocket == -1)
{
if(MPDEV)printf("Client: socket() failed! Error code: %d\n", WSAGetLastError());
WSACleanup();
}
void SyncResources(SOCKET Sock){
if(MPDEV)std::cout << "SyncResources Called" << std::endl;
CheckForDir();
STCPSend(Sock,"NR" + GlobalInfo.at(0)+":"+GlobalInfo.at(2));
STCPSend(Sock,"SR");
char* Res = STCPRecv(Sock).first;
if(strlen(Res) == 0){
STCPSend(Sock,"Done");
return;
}
std::vector<std::string> list = Split(std::string(Res), ";");
std::vector<std::string> FNames(list.begin(), list.begin() + (list.size() / 2));
std::vector<std::string> FSizes(list.begin() + (list.size() / 2), list.end());
list.clear();
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_port = htons(Port);
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
struct stat info{};
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
std::string a;
int pos = FN->find_last_of('/');
if (pos != std::string::npos) {
a = "Resources" + FN->substr(pos);
} else continue;
char *Data;
RetCode = connect(SendingSocket, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
if(RetCode != 0)
{
if(MPDEV)std::cout <<"Client: connect() failed! Error code: " << WSAGetLastError() << std::endl;
closesocket(SendingSocket);
WSACleanup();
return;
}
getsockname(SendingSocket, (SOCKADDR *)&ServerAddr, (int *)sizeof(ServerAddr));
BytesSent = send(SendingSocket, "a", 1, 0);
std::string File, Response, toSend, Data = STCPRecv(SendingSocket);
std::cout << Data << std::endl;
if (!Data.empty()) {
std::vector<std::string> list = Split(Data, ";");
std::vector<std::string> FileNames(list.begin(), list.begin() + (list.size() / 2));
std::vector<std::string> FileSizes(list.begin() + (list.size() / 2), list.end());
list.clear();
int index = 0;
for (const std::string &a : FileNames) {
if (a.empty() || a.length() < 2)continue;
if (stat(a.c_str(), &info) == 0) {
if (fs::file_size(a) == std::stoi(FileSizes.at(index))) {
index++;
continue;
} else remove(a.c_str());
}
std::ofstream LFS;
LFS.open(a.c_str());
LFS.close();
toSend = "b" + a;
send(SendingSocket, toSend.c_str(), toSend.length(), 0);
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
do {
Data = STCPRecv(SendingSocket);
if (Data.empty()) {
File.clear();
break;
}
if (Data.find("Cannot Open") != std::string::npos) {
File.clear();
break;
}
LFS << Data;
float per = LFS.tellp() / std::stof(FileSizes.at(index)) * 100;
std::string Percent = std::to_string(truncf(per * 10) / 10);
UlStatus = "UlDownloading Resource: " + a.substr(a.find_last_of('/')) + " (" +
Percent.substr(0, Percent.find('.') + 2) + "%)";
} while (LFS.tellp() != std::stoi(FileSizes.at(index)));
LFS.close();
File.clear();
if (stat(a.c_str(), &info) == 0) {
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
if (fs::file_size(a) == std::stoi(*FS)) {
continue;
} else remove(a.c_str());
}
toSend = "M";
send(SendingSocket, toSend.c_str(), toSend.length(), 0);
Data = STCPRecv(SendingSocket);
MStatus = "M" + Data;
CheckForDir();
std::ofstream LFS;
STCPSend(Sock, "f" + *FN);
do {
auto Pair = STCPRecv(Sock);
Data = Pair.first;
if (strcmp(Data, "Cannot Open") == 0 || Terminate)break;
if(!LFS.is_open()){
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
}
LFS.write(Data, Pair.second);
float per = LFS.tellp() / std::stof(*FS) * 100;
std::string Percent = std::to_string(truncf(per * 10) / 10);
UlStatus = "UlDownloading Resource: " + a.substr(a.find_last_of('/')) + " (" +
Percent.substr(0, Percent.find('.') + 2) + "%)";
} while (LFS.tellp() != std::stoi(*FS));
LFS.close();
}
UlStatus = "Uldone";
STCPSend(Sock,"Done");
std::cout << "Done!" << std::endl;
if(BytesSent == SOCKET_ERROR)
if(MPDEV)printf("Client: send() error %d.\n", WSAGetLastError());
if( shutdown(SendingSocket, SD_SEND) != 0)
if(MPDEV)printf("Client: Well, there is something wrong with the shutdown() The error code: %d\n", WSAGetLastError());
if(closesocket(SendingSocket) != 0)
if(MPDEV)printf("Client: Cannot close \"SendingSocket\" socket. Error code: %d\n", WSAGetLastError());
if(WSACleanup() != 0)
if(MPDEV)printf("Client: WSACleanup() failed!...\n");
*/
}

View File

@ -3,7 +3,6 @@
///
#include <filesystem>
#include <Windows.h>
#include <iostream>
#include <string>
#include <vector>
#include <array>
@ -16,7 +15,7 @@ void Exit(const std::string& Msg);
int TraceBack = 0;
std::vector<std::string> SData;
std::string Result;
std::string HTA(const std::string& hex)
{
@ -113,8 +112,8 @@ std::string QueryKey(HKEY hKey,int ID)
std::string data = reinterpret_cast<const char *const>(buffer);
std::string key = achValue;
switch (ID){
case 1: if(key == HTA("537465616d50617468") && data.find(HTA("737465616d")) != std::string::npos)return data;break;
case 2: if(key == HTA("4e616d65") && data == HTA("4265616d4e472e6472697665"))return data; break;
case 1: if(key == HTA("537465616d50617468"))return data;break;
case 2: if(key == HTA("4e616d65") && data == HTA("4265616d4e472e6472697665"))return data;break;
case 3: return data.substr(0,data.length()-2);
case 4: if(key == HTA("75736572706174685f6f76657272696465"))return data;
default: break;
@ -125,7 +124,7 @@ 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)) {
int pos = entry.path().filename().string().find('.');
@ -153,6 +152,7 @@ void Check(){
HKEY_CURRENT_USER\\Software\Valve\Steam\Apps\284160
HKEY_CLASSES_ROOT\\beamng\\DefaultIcon */
//Sandbox Scramble technique
std::string Result;
std::string K1 = HTA("536f6674776172655c56616c76655c537465616d");
std::string K2 = HTA("536f6674776172655c56616c76655c537465616d5c417070735c323834313630");
std::string K3 = HTA("6265616d6e675c44656661756c7449636f6e");
@ -205,6 +205,7 @@ void Check(){
MSG1.clear();
MSG2.clear();
MSG3.clear();
Result.clear();
RegCloseKey(hKey);
}

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,6 @@
#include <vector>
#include <thread>
#pragma comment(lib, "urlmon.lib")
void 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);
@ -85,7 +84,7 @@ int main(int argc, char* argv[]){
const unsigned long long NPos = std::string::npos;
struct stat info{};
system("cls");
std::string ver = "1.3", link, HTTP_Result;
std::string ver = "1.31", link, HTTP_Result;
SetWindowTextA(GetConsoleWindow(),("BeamMP Launcher v" + ver).c_str());
std::thread t1(Discord_Main);
t1.detach();