mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 15:36:10 +00:00
more cleanup
This commit is contained in:
parent
49dd577c36
commit
4b9742553a
@ -1 +0,0 @@
|
||||
4baf8552-5a00-4b18-89e2-d3a9bef18ad0
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/18/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/16/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 11/27/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 4/2/2020.
|
||||
///
|
||||
|
@ -1,5 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 7/20/2020
|
||||
///
|
||||
#pragma once
|
||||
void MemoryInit();
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/18/2020
|
||||
///
|
||||
|
@ -1,16 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 7/16/2020
|
||||
///
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "Xor.h"
|
||||
struct RSA{
|
||||
int n = 0;
|
||||
int e = 0;
|
||||
int d = 0;
|
||||
};
|
||||
std::string RSA_D(const std::string& Data,int d, int n);
|
||||
std::string RSA_E(const std::string& Data,int e, int n);
|
||||
std::string LocalEnc(const std::string& Data);
|
||||
std::string LocalDec(const std::string& Data);
|
||||
RSA* GenKey();
|
@ -1,6 +1,9 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/19/2020
|
||||
///
|
||||
#pragma once
|
||||
extern unsigned long GamePID;
|
||||
void SecureMods();
|
||||
|
@ -1,11 +1,15 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/18/2020
|
||||
///
|
||||
#pragma once
|
||||
#include <string>
|
||||
void PreGame(int argc, char* argv[],const std::string& GamePath);
|
||||
void InitGame(const std::string& Dir,const std::string&Current);
|
||||
std::string CheckVer(const std::string &path);
|
||||
void InitGame(const std::string& Dir);
|
||||
std::string GetGameDir();
|
||||
void LegitimacyCheck();
|
||||
void CheckLocalKey();
|
@ -1,130 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 8/11/2020
|
||||
///
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <cstdarg>
|
||||
|
||||
#define BEGIN_NAMESPACE(x) namespace x {
|
||||
#define END_NAMESPACE }
|
||||
|
||||
BEGIN_NAMESPACE(XorCompileTime)
|
||||
|
||||
constexpr auto time = __TIME__;
|
||||
constexpr auto seed = static_cast<int>(time[7]) + static_cast<int>(time[6]) * 10 + static_cast<int>(time[4]) * 60 + static_cast<int>(time[3]) * 600 + static_cast< int >(time[1]) * 3600 + static_cast< int >(time[0]) * 36000;
|
||||
|
||||
// 1988, Stephen Park and Keith Miller
|
||||
// "Random Number Generators: Good Ones Are Hard To Find", considered as "minimal standard"
|
||||
// Park-Miller 31 bit pseudo-random number generator, implemented with G. Carta's optimisation:
|
||||
// with 32-bit math and without division
|
||||
|
||||
template <int N>
|
||||
struct RandomGenerator{
|
||||
private:
|
||||
static constexpr unsigned a = 16807; // 7^5
|
||||
static constexpr unsigned m = 2147483647; // 2^31 - 1
|
||||
|
||||
static constexpr unsigned s = RandomGenerator< N - 1 >::value;
|
||||
static constexpr unsigned lo = a * (s & 0xFFFFu); // Multiply lower 16 bits by 16807
|
||||
static constexpr unsigned hi = a * (s >> 16u); // Multiply higher 16 bits by 16807
|
||||
static constexpr unsigned lo2 = lo + ((hi & 0x7FFFu) << 16u); // Combine lower 15 bits of hi with lo's upper bits
|
||||
static constexpr unsigned hi2 = hi >> 15u; // Discard lower 15 bits of hi
|
||||
static constexpr unsigned lo3 = lo2 + hi;
|
||||
|
||||
public:
|
||||
static constexpr unsigned max = m;
|
||||
static constexpr unsigned value = lo3 > m ? lo3 - m : lo3;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RandomGenerator< 0 >{
|
||||
static constexpr unsigned value = seed;
|
||||
};
|
||||
|
||||
template <int N, int M>
|
||||
struct RandomInt{
|
||||
static constexpr auto value = RandomGenerator< N + 1 >::value % M;
|
||||
};
|
||||
|
||||
template <int N>
|
||||
struct RandomChar{
|
||||
static const char value = static_cast< char >(1 + RandomInt< N, 0x7F - 1 >::value);
|
||||
};
|
||||
|
||||
template <size_t N, int K, typename Char>
|
||||
struct XorString{
|
||||
private:
|
||||
const char _key;
|
||||
std::array< Char, N + 1 > _encrypted;
|
||||
|
||||
constexpr Char enc(Char c) const{
|
||||
return c ^ _key;
|
||||
}
|
||||
|
||||
Char dec(Char c) const{
|
||||
return c ^ _key;
|
||||
}
|
||||
|
||||
public:
|
||||
template <size_t... Is>
|
||||
constexpr __forceinline XorString(const Char* str, std::index_sequence< Is... >) : _key(RandomChar< K >::value), _encrypted{ enc(str[Is])... }
|
||||
{}
|
||||
|
||||
__forceinline decltype(auto) decrypt(){
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
_encrypted[i] = dec(_encrypted[i]);
|
||||
}
|
||||
_encrypted[N] = '\0';
|
||||
return _encrypted.data();
|
||||
}
|
||||
};
|
||||
|
||||
static auto w_printf = [](const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf_s(fmt, args);
|
||||
va_end(args);
|
||||
};
|
||||
|
||||
static auto w_printf_s = [](const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf_s(fmt, args);
|
||||
va_end(args);
|
||||
};
|
||||
|
||||
/*static auto w_sprintf = [](char* buf, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
};*/
|
||||
|
||||
/*static auto w_sprintf_ret = [](char* buf, const char* fmt, ...) {
|
||||
int ret;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
ret = vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
};*/
|
||||
|
||||
static auto w_sprintf_s = [](char* buf, size_t buf_size, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf_s(buf, buf_size, fmt, args);
|
||||
va_end(args);
|
||||
};
|
||||
|
||||
static auto w_sprintf_s_ret = [](char* buf, size_t buf_size, const char* fmt, ...) {
|
||||
int ret;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
ret = vsprintf_s(buf, buf_size, fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
};
|
||||
#define Sec( s ) []{ constexpr XorCompileTime::XorString< sizeof(s)/sizeof(char) - 1, __COUNTER__, char > expr( s, std::make_index_sequence< sizeof(s)/sizeof(char) - 1>() ); return expr; }().decrypt()
|
||||
#define SecW( s ) []{ constexpr XorCompileTime::XorString< sizeof(s)/sizeof(wchar_t) - 1, __COUNTER__, wchar_t > expr( s, std::make_index_sequence< sizeof(s)/sizeof(wchar_t) - 1>() ); return expr; }().decrypt()
|
||||
END_NAMESPACE
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/18/2020
|
||||
///
|
||||
@ -5,6 +9,7 @@
|
||||
#include <string>
|
||||
void InitLauncher(int argc, char* argv[]);
|
||||
void CheckDir(int argc,char* args[]);
|
||||
std::string GetGamePath();
|
||||
std::string GetVer();
|
||||
std::string GetEN();
|
||||
extern bool Dev;
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/24/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/15/2020
|
||||
///
|
||||
|
@ -1,8 +1,11 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/16/2020
|
||||
///
|
||||
#include "Discord/discord_rpc.h"
|
||||
#include "Security/Enc.h"
|
||||
#include "Logger.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
@ -20,14 +23,14 @@ void updateDiscordPresence(){
|
||||
//char buffer[256];
|
||||
DiscordRichPresence discordPresence;
|
||||
memset(&discordPresence, 0, sizeof(discordPresence));
|
||||
std::string P = Sec("Playing with friends!");
|
||||
std::string P = "Playing with friends!"; ///to be revisited
|
||||
discordPresence.state = P.c_str();
|
||||
//sprintf(buffer, "Frustration level: %d", FrustrationLevel);
|
||||
//discordPresence.details = buffer;
|
||||
discordPresence.startTimestamp = StartTime;
|
||||
//discordPresence.endTimestamp = time(0) + 5 * 60;
|
||||
std::string L = Sec("mainlogo");
|
||||
discordPresence.largeImageKey = L.c_str();
|
||||
|
||||
discordPresence.largeImageKey = "mainlogo";
|
||||
//discordPresence.smallImageKey = "logo";
|
||||
//discordPresence.partyId = "party1234";
|
||||
//discordPresence.partySize = 1;
|
||||
@ -44,9 +47,9 @@ void updateDiscordPresence(){
|
||||
}
|
||||
void handleDiscordReady(const DiscordUser* User){
|
||||
DiscordInfo = new DInfo{
|
||||
LocalEnc(User->username),
|
||||
LocalEnc(User->discriminator),
|
||||
LocalEnc(User->userId)
|
||||
User->username,
|
||||
User->discriminator,
|
||||
User->userId
|
||||
};
|
||||
}
|
||||
void discordInit(){
|
||||
@ -58,8 +61,7 @@ void discordInit(){
|
||||
handlers.joinGame = handleDiscordJoin;
|
||||
handlers.spectateGame = handleDiscordSpectate;
|
||||
handlers.joinRequest = handleDiscordJoinRequest;*/
|
||||
std::string a = Sec("629743237988352010");
|
||||
Discord_Initialize(a.c_str(), &handlers, 1,nullptr);
|
||||
Discord_Initialize("629743237988352010", &handlers, 1,nullptr);
|
||||
}
|
||||
[[noreturn]] void Loop(){
|
||||
StartTime = time(nullptr);
|
||||
@ -75,52 +77,35 @@ void discordInit(){
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void SecurityLoop(){
|
||||
std::string t,t1,t2;
|
||||
while(true){
|
||||
if(DiscordInfo != nullptr){
|
||||
if(t.empty()){
|
||||
t = LocalDec(DiscordInfo->Name);
|
||||
t1 = LocalDec(DiscordInfo->Tag);
|
||||
t2 = LocalDec(DiscordInfo->DID);
|
||||
}else if(t2 != LocalDec(DiscordInfo->DID) ||
|
||||
t != LocalDec(DiscordInfo->Name) || t1 != LocalDec(DiscordInfo->Tag))DiscordInfo = nullptr;
|
||||
}else if(!t.empty())DiscordInfo->DID.clear();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
}
|
||||
void DMain(){
|
||||
auto*S = new std::thread(SecurityLoop);
|
||||
S->detach();
|
||||
delete S;
|
||||
discordInit();
|
||||
Loop();
|
||||
}
|
||||
std::string GetDName(){
|
||||
return LocalDec(DiscordInfo->Name);
|
||||
return DiscordInfo->Name;
|
||||
}
|
||||
std::string GetDTag(){
|
||||
return LocalDec(DiscordInfo->Tag);
|
||||
return DiscordInfo->Tag;
|
||||
}
|
||||
std::string GetDID(){
|
||||
return LocalDec(DiscordInfo->DID);
|
||||
return DiscordInfo->DID;
|
||||
}
|
||||
void DAboard(){
|
||||
DiscordInfo = nullptr;
|
||||
}
|
||||
void ErrorAboard(){
|
||||
error(Sec("Discord timeout! please start the discord app and try again after 30 secs"));
|
||||
error("Discord timeout! please start the discord app and try again after 30 secs");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
exit(6);
|
||||
}
|
||||
void Discord_Main(){
|
||||
std::thread t1(DMain);
|
||||
t1.detach();
|
||||
info(Sec("Connecting to discord client..."));
|
||||
/*info("Connecting to discord client...");
|
||||
int C = 0;
|
||||
while(DiscordInfo == nullptr && C < 80){
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
C++;
|
||||
}
|
||||
if(DiscordInfo == nullptr)ErrorAboard();
|
||||
if(DiscordInfo == nullptr)ErrorAboard();*/
|
||||
}
|
||||
|
@ -1,74 +1,68 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/19/2020
|
||||
///
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include "Startup.h"
|
||||
#include <ShlObj.h>
|
||||
#include "Logger.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
unsigned long GamePID = 0;
|
||||
std::string QueryKey(HKEY hKey,int ID);
|
||||
void DeleteKey(){
|
||||
std::string GetGamePath(){
|
||||
static std::string Path;
|
||||
if(!Path.empty())return Path;
|
||||
|
||||
HKEY hKey;
|
||||
LPCTSTR sk = Sec("Software\\BeamNG\\BeamNG.drive");
|
||||
RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||
RegDeleteValueA(hKey, Sec("userpath_override"));
|
||||
}
|
||||
std::string Write(const std::string&Path){
|
||||
HKEY hKey;
|
||||
LPCTSTR sk = Sec("Software\\BeamNG\\BeamNG.drive");
|
||||
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
||||
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||
if (openRes != ERROR_SUCCESS){
|
||||
fatal(Sec("Please launch the game at least once"));
|
||||
fatal("Please launch the game at least once");
|
||||
}
|
||||
std::string Query = QueryKey(hKey,4);
|
||||
LONG setRes = RegSetValueEx(hKey, Sec("userpath_override"), 0, REG_SZ, (LPBYTE)Path.c_str(), DWORD(Path.size()));
|
||||
if(setRes != ERROR_SUCCESS){
|
||||
fatal(Sec("Failed to launch the game")); //not fatal later
|
||||
Path = QueryKey(hKey,4);
|
||||
|
||||
if(Path.empty()){
|
||||
CoInitialize(nullptr);
|
||||
wchar_t * path = nullptr;
|
||||
SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, (PWSTR *)(&path));
|
||||
CoTaskMemFree(path);
|
||||
std::wstring ws(path);
|
||||
std::string s(ws.begin(), ws.end());
|
||||
Path = s;
|
||||
Path += "\\BeamNG.drive\\";
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
return Query;
|
||||
|
||||
return Path;
|
||||
}
|
||||
void RollBack(const std::string&Val,int T){
|
||||
std::this_thread::sleep_for(std::chrono::seconds(T));
|
||||
if(!Val.empty()){
|
||||
if(Write(Val) == Val)DeleteKey();
|
||||
}else DeleteKey();
|
||||
}
|
||||
std::string Restore;
|
||||
void OnExit(){
|
||||
RollBack(Restore,0);
|
||||
}
|
||||
void StartGame(std::string Dir,std::string Current){
|
||||
Current = Current.substr(0,Current.find_last_of('\\')) + Sec("\\BeamNG\\");
|
||||
|
||||
void StartGame(std::string Dir){
|
||||
BOOL bSuccess = FALSE;
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFO si = {0};
|
||||
si.cb = sizeof(si);
|
||||
std::string BaseDir = Dir + Sec("\\Bin64");
|
||||
Dir += Sec(R"(\Bin64\BeamNG.drive.x64.exe)");
|
||||
std::string BaseDir = Dir +"\\Bin64";
|
||||
Dir += R"(\Bin64\BeamNG.drive.x64.exe)";
|
||||
bSuccess = CreateProcessA(Dir.c_str(), nullptr, nullptr, nullptr, TRUE, 0, nullptr, BaseDir.c_str(), &si, &pi);
|
||||
if (bSuccess){
|
||||
info(Sec("Game Launched!"));
|
||||
info("Game Launched!");
|
||||
GamePID = pi.dwProcessId;
|
||||
Restore = Write(Current);
|
||||
atexit(OnExit);
|
||||
std::thread RB(RollBack,Restore,7);
|
||||
RB.detach();
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
error(Sec("Game Closed! launcher closing soon"));
|
||||
RollBack(Restore,0);
|
||||
error("Game Closed! launcher closing soon");
|
||||
}else{
|
||||
error(Sec("Failed to Launch the game! launcher closing soon"));
|
||||
RollBack(Write(Current),0);
|
||||
error("Failed to Launch the game! launcher closing soon");
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
exit(2);
|
||||
}
|
||||
void InitGame(const std::string& Dir,const std::string&Current){
|
||||
void InitGame(const std::string& Dir){
|
||||
if(!Dev){
|
||||
std::thread Game(StartGame, Dir, Current);
|
||||
std::thread Game(StartGame, Dir);
|
||||
Game.detach();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
Copyright (c) 2020 BeamMP-Server & BeamMP-Launcher Developers.
|
||||
BeamMP Server code is not in the public domain and is not free software. One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries. Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/17/2020
|
||||
///
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include "Startup.h"
|
||||
#include "Logger.h"
|
||||
#include <fstream>
|
||||
@ -40,47 +42,47 @@ std::string getDate() {
|
||||
}
|
||||
void InitLog(){
|
||||
std::ofstream LFS;
|
||||
LFS.open (Sec("Launcher.log"));
|
||||
LFS.open ("Launcher.log");
|
||||
if(!LFS.is_open()){
|
||||
error(Sec("logger file init failed!"));
|
||||
error("logger file init failed!");
|
||||
}else LFS.close();
|
||||
}
|
||||
void addToLog(const std::string& Line){
|
||||
std::ofstream LFS;
|
||||
LFS.open(Sec("Launcher.log"), std::ios_base::app);
|
||||
LFS.open("Launcher.log", std::ios_base::app);
|
||||
LFS << Line.c_str();
|
||||
LFS.close();
|
||||
}
|
||||
void info(const std::string& toPrint) {
|
||||
std::string Print = getDate() + Sec("[INFO] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + "[INFO] " + toPrint + "\n";
|
||||
std::cout << Print;
|
||||
addToLog(Print);
|
||||
}
|
||||
void debug(const std::string& toPrint) {
|
||||
if(!Dev)return;
|
||||
std::string Print = getDate() + Sec("[DEBUG] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + "[DEBUG] " + toPrint + "\n";
|
||||
std::cout << Print;
|
||||
addToLog(Print);
|
||||
}
|
||||
void warn(const std::string& toPrint){
|
||||
std::string Print = getDate() + Sec("[WARN] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + "[WARN] " + toPrint + "\n";
|
||||
std::cout << Print;
|
||||
addToLog(Print);
|
||||
}
|
||||
void error(const std::string& toPrint) {
|
||||
std::string Print = getDate() + Sec("[ERROR] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + "[ERROR] " + toPrint + "\n";
|
||||
std::cout << Print;
|
||||
addToLog(Print);
|
||||
}
|
||||
void fatal(const std::string& toPrint) {
|
||||
std::string Print = getDate() + Sec("[FATAL] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + "[FATAL] " + toPrint + "\n";
|
||||
std::cout << Print;
|
||||
addToLog(Print);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
_Exit(-1);
|
||||
}
|
||||
void except(const std::string& toPrint) {
|
||||
std::string Print = getDate() + Sec("[EXCEP] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + "[EXCEP] " + toPrint + "\n";
|
||||
std::cout << Print;
|
||||
addToLog(Print);
|
||||
}
|
||||
|
@ -1,235 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 5/5/2020
|
||||
///
|
||||
|
||||
#include "Memory.hpp"
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
|
||||
int Memory::GetProcessId(const std::string& processName) {
|
||||
SetLastError(0);
|
||||
PROCESSENTRY32 pe32;
|
||||
HANDLE hSnapshot = nullptr;
|
||||
GetLastError();
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
|
||||
if(Process32First(hSnapshot,&pe32)) {
|
||||
do {
|
||||
if(processName == pe32.szExeFile)
|
||||
break;
|
||||
} while(Process32Next(hSnapshot, &pe32));
|
||||
}
|
||||
|
||||
if(hSnapshot != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(hSnapshot);
|
||||
int err = GetLastError();
|
||||
|
||||
if (err != 0)
|
||||
return 0;
|
||||
return pe32.th32ProcessID;
|
||||
}
|
||||
|
||||
long long Memory::GetModuleBase(HANDLE processHandle, const std::string &sModuleName){
|
||||
HMODULE *hModules = nullptr;
|
||||
char szBuf[50];
|
||||
DWORD cModules;
|
||||
long long dwBase = -1;
|
||||
|
||||
EnumProcessModulesEx(processHandle, hModules, 0, &cModules,LIST_MODULES_ALL);
|
||||
hModules = new HMODULE[cModules/sizeof(HMODULE)];
|
||||
|
||||
if(EnumProcessModulesEx(processHandle, hModules, cModules/sizeof(HMODULE), &cModules,LIST_MODULES_ALL)) {
|
||||
for(size_t i = 0; i < cModules/sizeof(HMODULE); i++) {
|
||||
if(GetModuleBaseName(processHandle, hModules[i], szBuf, sizeof(szBuf))) {
|
||||
if(sModuleName == szBuf) {
|
||||
dwBase = (long long)hModules[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete[] hModules;
|
||||
return dwBase;
|
||||
}
|
||||
|
||||
void PrintAllBases(HANDLE processHandle){
|
||||
HMODULE *hModules = nullptr;
|
||||
char szBuf[50];
|
||||
DWORD cModules;
|
||||
EnumProcessModulesEx(processHandle, hModules, 0, &cModules,LIST_MODULES_ALL);
|
||||
hModules = new HMODULE[cModules/sizeof(HMODULE)];
|
||||
if(EnumProcessModulesEx(processHandle, hModules, cModules/sizeof(HMODULE), &cModules,LIST_MODULES_ALL)) {
|
||||
for(size_t i = 0; i < cModules/sizeof(HMODULE); i++) {
|
||||
if(GetModuleBaseName(processHandle, hModules[i], szBuf, sizeof(szBuf))) {
|
||||
if(hModules[i] != nullptr){
|
||||
std::cout << szBuf << " : " << hModules[i] << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] hModules;
|
||||
}
|
||||
|
||||
BOOL Memory::SetPrivilege(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege){
|
||||
TOKEN_PRIVILEGES tp;
|
||||
LUID luid;
|
||||
|
||||
if (!LookupPrivilegeValue(nullptr, lpszPrivilege, &luid)) {
|
||||
//printf("LookupPrivilegeValue error: %u\n", GetLastError() );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
tp.PrivilegeCount = 1;
|
||||
tp.Privileges[0].Luid = luid;
|
||||
if (bEnablePrivilege)
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
else
|
||||
tp.Privileges[0].Attributes = 0;
|
||||
|
||||
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES) nullptr, (PDWORD) nullptr)) {
|
||||
//printf("AdjustTokenPrivileges error: %u\n", GetLastError() );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
|
||||
//printf("The token does not have the specified privilege. \n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
BOOL Memory::GetDebugPrivileges() {
|
||||
HANDLE hToken = nullptr;
|
||||
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
|
||||
return FALSE; //std::cout << "OpenProcessToken() failed, error\n>> " << GetLastError() << std::endl;
|
||||
//else std::cout << "OpenProcessToken() is OK, got the handle!" << std::endl;
|
||||
|
||||
if(!SetPrivilege(hToken, SE_DEBUG_NAME, TRUE))
|
||||
return FALSE; //std::cout << "Failed to enable privilege, error:\n>> " << GetLastError() << std::endl;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
int Memory::ReadInt(HANDLE processHandle, long long address) {
|
||||
if (address == -1)
|
||||
return -1;
|
||||
int buffer = 0;
|
||||
SIZE_T NumberOfBytesToRead = sizeof(buffer); //this is equal to 4
|
||||
SIZE_T NumberOfBytesActuallyRead;
|
||||
BOOL success = ReadProcessMemory(processHandle, (LPCVOID)address, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
|
||||
if (!success || NumberOfBytesActuallyRead != NumberOfBytesToRead) {
|
||||
//std::cout << "Memory Error!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
long long Memory::ReadLong(HANDLE processHandle, long long address) {
|
||||
if (address == -1)
|
||||
return -1;
|
||||
long long buffer = 0;
|
||||
SIZE_T NumberOfBytesToRead = sizeof(buffer);
|
||||
SIZE_T NumberOfBytesActuallyRead;
|
||||
BOOL success = ReadProcessMemory(processHandle, (LPCVOID)address, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
|
||||
if (!success || NumberOfBytesActuallyRead != NumberOfBytesToRead) {
|
||||
//std::cout << "Memory Error!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
int Memory::GetPointerAddress(HANDLE processHandle, long long startAddress, int offsets[], int offsetCount) {
|
||||
if (startAddress == -1)
|
||||
return -1;
|
||||
int ptr = ReadInt(processHandle, startAddress);
|
||||
for (int i=0; i<offsetCount-1; i++) {
|
||||
ptr+=offsets[i];
|
||||
ptr = ReadInt(processHandle, ptr);
|
||||
}
|
||||
ptr+=offsets[offsetCount-1];
|
||||
return ptr;
|
||||
}
|
||||
long long Memory::GetPointerAddressLong(HANDLE processHandle, long long startAddress, std::vector<int> offsets) {
|
||||
if (startAddress == -1)
|
||||
return -1;
|
||||
long long ptr = ReadLong(processHandle, startAddress);
|
||||
for (int i=0; i< offsets.size()-1; i++) {
|
||||
ptr+=offsets[i];
|
||||
ptr = ReadLong(processHandle, ptr);
|
||||
}
|
||||
ptr+=offsets[offsets.size()-1];
|
||||
return ptr;
|
||||
}
|
||||
int Memory::ReadPointerInt(HANDLE processHandle, long long startAddress, std::vector<int> offsets) {
|
||||
if (startAddress == -1)
|
||||
return -1;
|
||||
return ReadInt(processHandle, GetPointerAddressLong(processHandle, startAddress, std::move(offsets)));
|
||||
}
|
||||
long long Memory::ReadPointerLong(HANDLE processHandle, long long startAddress, std::vector<int> offsets) {
|
||||
if (startAddress == -1)
|
||||
return -1;
|
||||
return ReadLong(processHandle, GetPointerAddressLong(processHandle, startAddress, std::move(offsets)));
|
||||
}
|
||||
|
||||
float Memory::ReadFloat(HANDLE processHandle, long long address) {
|
||||
if (address == -1)
|
||||
return -1;
|
||||
float buffer = 0.0;
|
||||
SIZE_T NumberOfBytesToRead = sizeof(buffer); //this is equal to 4
|
||||
SIZE_T NumberOfBytesActuallyRead;
|
||||
BOOL success = ReadProcessMemory(processHandle, (LPCVOID)address, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
|
||||
if (!success || NumberOfBytesActuallyRead != NumberOfBytesToRead)
|
||||
return -1;
|
||||
return buffer;
|
||||
}
|
||||
void Memory::WriteFloat(HANDLE processHandle, long long address,float Value) {
|
||||
if (address == -1)
|
||||
return;
|
||||
SIZE_T NumberOfBytesToWrite = sizeof(Value); //this is equal to 4
|
||||
SIZE_T NumberOfBytesWritten;
|
||||
BOOL Write = WriteProcessMemory(processHandle, LPVOID(address), &Value, NumberOfBytesToWrite, &NumberOfBytesWritten);
|
||||
}
|
||||
double Memory::ReadDouble(HANDLE processHandle, long long address) {
|
||||
if (address == -1)
|
||||
return -1;
|
||||
double buffer = 0.0;
|
||||
SIZE_T NumberOfBytesToRead = sizeof(buffer); //this is equal to 8
|
||||
SIZE_T NumberOfBytesActuallyRead;
|
||||
BOOL success = ReadProcessMemory(processHandle, (LPCVOID)address, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
|
||||
if (!success || NumberOfBytesActuallyRead != NumberOfBytesToRead)
|
||||
return -1;
|
||||
return buffer;
|
||||
}
|
||||
float Memory::ReadPointerFloat(HANDLE processHandle, long long startAddress, std::vector<int> offsets) {
|
||||
if (startAddress == -1)
|
||||
return -1;
|
||||
return ReadFloat(processHandle, GetPointerAddressLong(processHandle, startAddress, std::move(offsets)));
|
||||
}
|
||||
double Memory::ReadPointerDouble(HANDLE processHandle, long long startAddress, int offsets[], int offsetCount) {
|
||||
if (startAddress == -1)
|
||||
return -1;
|
||||
return ReadDouble(processHandle, GetPointerAddress(processHandle, startAddress, offsets, offsetCount));
|
||||
}
|
||||
std::string Memory::ReadText(HANDLE processHandle, long long address) {
|
||||
if (address == -1)
|
||||
return "-1";
|
||||
char buffer = 1;
|
||||
char* stringToRead = new char[128];
|
||||
SIZE_T NumberOfBytesToRead = sizeof(buffer);
|
||||
SIZE_T NumberOfBytesActuallyRead;
|
||||
int i = 0;
|
||||
while (buffer != 0) {
|
||||
BOOL success = ReadProcessMemory(processHandle, (LPCVOID)address, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
|
||||
if (!success || NumberOfBytesActuallyRead != NumberOfBytesToRead)
|
||||
return "-1";
|
||||
stringToRead[i] = buffer;
|
||||
i++;
|
||||
address++;
|
||||
}
|
||||
return stringToRead;
|
||||
}
|
||||
std::string Memory::ReadPointerText(HANDLE processHandle, long long startAddress, std::vector<int> offsets) {
|
||||
if (startAddress == -1)
|
||||
return "-1";
|
||||
return ReadText(processHandle, GetPointerAddressLong(processHandle, startAddress, std::move(offsets)));
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 5/5/2020
|
||||
///
|
||||
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <TlHelp32.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <psapi.h>
|
||||
|
||||
class Memory{
|
||||
public:
|
||||
DWORD PID = 0;
|
||||
int GetProcessId(const std::string& processName);
|
||||
long long ReadLong(HANDLE processHandle, long long address);
|
||||
long long ReadPointerLong(HANDLE processHandle, long long startAddress, std::vector<int> offsets);
|
||||
long long GetPointerAddressLong(HANDLE processHandle, long long startAddress, std::vector<int> offsets);
|
||||
long long GetModuleBase(HANDLE processHandle, const std::string&sModuleName);
|
||||
BOOL SetPrivilege(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege);
|
||||
BOOL GetDebugPrivileges();
|
||||
int ReadInt(HANDLE processHandle, long long address);
|
||||
int GetPointerAddress(HANDLE processHandle, long long startAddress, int offsets[], int offsetCount);
|
||||
int ReadPointerInt(HANDLE processHandle, long long startAddress, std::vector<int> offsets);
|
||||
float ReadFloat(HANDLE processHandle, long long address);
|
||||
void WriteFloat(HANDLE processHandle, long long address,float Value);
|
||||
double ReadDouble(HANDLE processHandle, long long address);
|
||||
float ReadPointerFloat(HANDLE processHandle, long long startAddress, std::vector<int> offsets);
|
||||
double ReadPointerDouble(HANDLE processHandle, long long startAddress, int offsets[], int offsetCount);
|
||||
std::string ReadText(HANDLE processHandle, long long address);
|
||||
std::string ReadPointerText(HANDLE processHandle, long long startAddress, std::vector<int> offsets);
|
||||
};
|
@ -1,55 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 6/17/2020
|
||||
///
|
||||
#include "Network/network.h"
|
||||
#include "Security/Game.h"
|
||||
#include "Security/Enc.h"
|
||||
#include "Memory.hpp"
|
||||
#include "Startup.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
Memory Game;
|
||||
std::string GameVer(HANDLE processHandle, long long Address){
|
||||
//lib_Beam
|
||||
Address += 0x1B0688;
|
||||
std::vector<int> Off = {0x0,0xBF0};
|
||||
return Game.ReadPointerText(processHandle,Address,Off);
|
||||
}
|
||||
std::string LoadedMap(HANDLE processHandle, long long Address){
|
||||
//lib_Beam
|
||||
//History : 0x1B0688
|
||||
Address += 0x1A1668;
|
||||
std::vector<int> Off = {0x140,0x0};
|
||||
return Game.ReadPointerText(processHandle,Address,Off);
|
||||
}
|
||||
std::string Tolower(std::string data){
|
||||
for(char&c : data){
|
||||
c = char(tolower(c));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
void MemoryInit(){
|
||||
if(Dev)return;
|
||||
Game.PID = GamePID;
|
||||
if(Game.PID == 0)exit(4);
|
||||
HANDLE processHandle;
|
||||
long long ExeBase; //BeamNG.drive.x64.exe
|
||||
long long Lib1 = 0x180000000; //libbeamng.x64.dll Contains Vehicle Data
|
||||
Game.GetDebugPrivileges();
|
||||
processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, Game.PID);
|
||||
ExeBase = Game.GetModuleBase(processHandle, "BeamNG.drive.x64.exe");
|
||||
|
||||
std::string Map,Temp;
|
||||
while(true){
|
||||
Map = LoadedMap(processHandle,Lib1);
|
||||
if(!Map.empty() && Map != "-1" && Map.find("/info.json") != -1 && Map != Temp){
|
||||
if(Tolower(MStatus).find(Tolower(Map)) == -1){
|
||||
exit(5);
|
||||
}
|
||||
Temp = Map;
|
||||
}
|
||||
Map.clear();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
}
|
@ -1,14 +1,17 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/20/2020
|
||||
///
|
||||
#include "Network/network.h"
|
||||
#include "Security/Init.h"
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include "Curl/http.h"
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include "Startup.h"
|
||||
#include "Memory.h"
|
||||
#include "Logger.h"
|
||||
#include <charconv>
|
||||
#include <thread>
|
||||
@ -19,11 +22,10 @@ std::set<std::string>* ConfList = nullptr;
|
||||
bool TCPTerminate = false;
|
||||
int DEFAULT_PORT = 4444;
|
||||
bool Terminate = false;
|
||||
bool LoginAuth = false;
|
||||
std::string UlStatus;
|
||||
std::string MStatus;
|
||||
bool once = false;
|
||||
bool ModLoaded;
|
||||
bool LoginAuth = false;
|
||||
int ping = -1;
|
||||
|
||||
void StartSync(const std::string &Data){
|
||||
@ -43,7 +45,7 @@ void StartSync(const std::string &Data){
|
||||
ping = -1;
|
||||
std::thread GS(TCPGameServer,IP,std::stoi(Data.substr(Data.find(':')+1)));
|
||||
GS.detach();
|
||||
info(Sec("Connecting to server"));
|
||||
info("Connecting to server");
|
||||
}
|
||||
void Parse(std::string Data,SOCKET CSocket){
|
||||
char Code = Data.at(0), SubCode = 0;
|
||||
@ -118,16 +120,11 @@ void Parse(std::string Data,SOCKET CSocket){
|
||||
if(!Data.empty() && CSocket != -1){
|
||||
int res = send(CSocket, (Data+"\n").c_str(), int(Data.size())+1, 0);
|
||||
if(res < 0){
|
||||
debug(Sec("(Core) send failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
debug("(Core) send failed with error: " + std::to_string(WSAGetLastError()));
|
||||
}
|
||||
}
|
||||
}
|
||||
void GameHandler(SOCKET Client){
|
||||
if (!once){
|
||||
std::thread Memory(MemoryInit);
|
||||
Memory.detach();
|
||||
once = true;
|
||||
}
|
||||
|
||||
int32_t Size,Temp,Rcv;
|
||||
char Header[10] = {0};
|
||||
@ -144,7 +141,7 @@ void GameHandler(SOCKET Client){
|
||||
}while(Header[Rcv++] != '>');
|
||||
if(Temp < 1)break;
|
||||
if(std::from_chars(Header,&Header[Rcv],Size).ptr[0] != '>'){
|
||||
debug(Sec("(Core) Invalid lua Header -> ") + std::string(Header,Rcv));
|
||||
debug("(Core) Invalid lua Header -> " + std::string(Header,Rcv));
|
||||
break;
|
||||
}
|
||||
std::string Ret(Size,0);
|
||||
@ -161,16 +158,16 @@ void GameHandler(SOCKET Client){
|
||||
Respond.detach();
|
||||
}while(Temp > 0);
|
||||
if (Temp == 0) {
|
||||
debug(Sec("(Core) Connection closing"));
|
||||
debug("(Core) Connection closing");
|
||||
} else {
|
||||
debug(Sec("(Core) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
debug("(Core) recv failed with error: " + std::to_string(WSAGetLastError()));
|
||||
}
|
||||
NetReset();
|
||||
KillSocket(Client);
|
||||
}
|
||||
void localRes(){
|
||||
MStatus = " ";
|
||||
UlStatus = Sec("Ulstart");
|
||||
UlStatus = "Ulstart";
|
||||
if(ConfList != nullptr){
|
||||
ConfList->clear();
|
||||
delete ConfList;
|
||||
@ -179,13 +176,13 @@ void localRes(){
|
||||
ConfList = new std::set<std::string>;
|
||||
}
|
||||
void CoreMain() {
|
||||
debug(Sec("Core Network on start!"));
|
||||
debug("Core Network on start!");
|
||||
WSADATA wsaData;
|
||||
SOCKET LSocket,CSocket;
|
||||
struct addrinfo *res = nullptr;
|
||||
struct addrinfo hints{};
|
||||
int iRes = WSAStartup(514, &wsaData); //2.2
|
||||
if (iRes)debug(Sec("WSAStartup failed with error: ") + std::to_string(iRes));
|
||||
if (iRes)debug("WSAStartup failed with error: " + std::to_string(iRes));
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
@ -193,20 +190,20 @@ void CoreMain() {
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
iRes = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT).c_str(), &hints, &res);
|
||||
if (iRes){
|
||||
debug(Sec("(Core) addr info failed with error: ") + std::to_string(iRes));
|
||||
debug("(Core) addr info failed with error: " + std::to_string(iRes));
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
LSocket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
if (LSocket == -1){
|
||||
debug(Sec("(Core) socket failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
debug("(Core) socket failed with error: " + std::to_string(WSAGetLastError()));
|
||||
freeaddrinfo(res);
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
iRes = bind(LSocket, res->ai_addr, int(res->ai_addrlen));
|
||||
if (iRes == SOCKET_ERROR) {
|
||||
error(Sec("(Core) bind failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
error("(Core) bind failed with error: " + std::to_string(WSAGetLastError()));
|
||||
freeaddrinfo(res);
|
||||
KillSocket(LSocket);
|
||||
WSACleanup();
|
||||
@ -214,7 +211,7 @@ void CoreMain() {
|
||||
}
|
||||
iRes = listen(LSocket, SOMAXCONN);
|
||||
if (iRes == SOCKET_ERROR) {
|
||||
debug(Sec("(Core) listen failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
debug("(Core) listen failed with error: " + std::to_string(WSAGetLastError()));
|
||||
freeaddrinfo(res);
|
||||
KillSocket(LSocket);
|
||||
WSACleanup();
|
||||
@ -223,13 +220,13 @@ void CoreMain() {
|
||||
do{
|
||||
CSocket = accept(LSocket, nullptr, nullptr);
|
||||
if (CSocket == -1) {
|
||||
error(Sec("(Core) accept failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
||||
continue;
|
||||
}
|
||||
localRes();
|
||||
info(Sec("Game Connected!"));
|
||||
info("Game Connected!");
|
||||
GameHandler(CSocket);
|
||||
warn(Sec("Game Reconnecting..."));
|
||||
warn("Game Reconnecting...");
|
||||
}while(CSocket);
|
||||
KillSocket(LSocket);
|
||||
WSACleanup();
|
||||
@ -237,7 +234,7 @@ void CoreMain() {
|
||||
int Handle(EXCEPTION_POINTERS *ep){
|
||||
char* hex = new char[100];
|
||||
sprintf_s(hex,100, "%lX", ep->ExceptionRecord->ExceptionCode);
|
||||
except(Sec("(Core) Code : ") + std::string(hex));
|
||||
except("(Core) Code : " + std::string(hex));
|
||||
delete [] hex;
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 9/25/2020
|
||||
///
|
||||
@ -5,19 +9,19 @@
|
||||
#include <string>
|
||||
#include <winsock.h>
|
||||
#include "Logger.h"
|
||||
#include "Security/Enc.h"
|
||||
|
||||
std::string GetAddr(const std::string&IP){
|
||||
if(IP.find_first_not_of("0123456789.") == -1)return IP;
|
||||
WSADATA wsaData;
|
||||
hostent *host;
|
||||
if(WSAStartup(514, &wsaData) != 0){
|
||||
error(Sec("WSA Startup Failed!"));
|
||||
error("WSA Startup Failed!");
|
||||
WSACleanup();
|
||||
return "";
|
||||
}
|
||||
host = gethostbyname(IP.c_str());
|
||||
if(!host){
|
||||
error(Sec("DNS lookup failed! on ") + IP);
|
||||
error("DNS lookup failed! on " + IP);
|
||||
WSACleanup();
|
||||
return "DNS";
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/25/2020
|
||||
///
|
||||
#include "Network/network.h"
|
||||
#include "Security/Init.h"
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include "Logger.h"
|
||||
@ -20,23 +24,23 @@ SOCKET GSocket = -1;
|
||||
|
||||
int KillSocket(uint64_t Dead){
|
||||
if(Dead == (SOCKET)-1){
|
||||
debug(Sec("Kill socket got -1 returning..."));
|
||||
debug("Kill socket got -1 returning...");
|
||||
return 0;
|
||||
}
|
||||
shutdown(Dead,SD_BOTH);
|
||||
int a = closesocket(Dead);
|
||||
if(a != 0){
|
||||
warn(Sec("Failed to close socket!"));
|
||||
warn("Failed to close socket!");
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
bool CheckBytes(uint32_t Bytes){
|
||||
if(Bytes == 0){
|
||||
debug(Sec("(Proxy) Connection closing"));
|
||||
debug("(Proxy) Connection closing");
|
||||
return false;
|
||||
}else if(Bytes < 0){
|
||||
debug(Sec("(Proxy) send failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
debug("(Proxy) send failed with error: " + std::to_string(WSAGetLastError()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -80,7 +84,7 @@ void ServerSend(std::string Data, bool Rel){
|
||||
}else UDPSend(Data);
|
||||
|
||||
if (DLen > 1000) {
|
||||
debug(Sec("(Launcher->Server) Bytes sent: ") + std::to_string(Data.length()) + " : "
|
||||
debug("(Launcher->Server) Bytes sent: " + std::to_string(Data.length()) + " : "
|
||||
+ Data.substr(0, 10)
|
||||
+ Data.substr(Data.length() - 10));
|
||||
}else if(C == 'Z'){
|
||||
@ -92,20 +96,20 @@ void NetReset(){
|
||||
TCPTerminate = false;
|
||||
GConnected = false;
|
||||
Terminate = false;
|
||||
UlStatus = Sec("Ulstart");
|
||||
UlStatus = "Ulstart";
|
||||
MStatus = " ";
|
||||
if(UDPSock != (SOCKET)(-1)){
|
||||
debug(Sec("Terminating UDP Socket : ") + std::to_string(TCPSock));
|
||||
debug("Terminating UDP Socket : " + std::to_string(TCPSock));
|
||||
KillSocket(UDPSock);
|
||||
}
|
||||
UDPSock = -1;
|
||||
if(TCPSock != (SOCKET)(-1)){
|
||||
debug(Sec("Terminating TCP Socket : ") + std::to_string(TCPSock));
|
||||
debug("Terminating TCP Socket : " + std::to_string(TCPSock));
|
||||
KillSocket(TCPSock);
|
||||
}
|
||||
TCPSock = -1;
|
||||
if(GSocket != (SOCKET)(-1)){
|
||||
debug(Sec("Terminating GTCP Socket : ") + std::to_string(GSocket));
|
||||
debug("Terminating GTCP Socket : " + std::to_string(GSocket));
|
||||
KillSocket(GSocket);
|
||||
}
|
||||
GSocket = -1;
|
||||
@ -118,7 +122,7 @@ SOCKET SetupListener(){
|
||||
WSADATA wsaData;
|
||||
int iRes = WSAStartup(514, &wsaData); //2.2
|
||||
if (iRes != 0) {
|
||||
error(Sec("(Proxy) WSAStartup failed with error: ") + std::to_string(iRes));
|
||||
error("(Proxy) WSAStartup failed with error: " + std::to_string(iRes));
|
||||
return -1;
|
||||
}
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
@ -128,19 +132,19 @@ SOCKET SetupListener(){
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
iRes = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT+1).c_str(), &hints, &result);
|
||||
if (iRes != 0) {
|
||||
error(Sec("(Proxy) info failed with error: ") + std::to_string(iRes));
|
||||
error("(Proxy) info failed with error: " + std::to_string(iRes));
|
||||
WSACleanup();
|
||||
}
|
||||
GSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
|
||||
if (GSocket == -1) {
|
||||
error(Sec("(Proxy) socket failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
error("(Proxy) socket failed with error: " + std::to_string(WSAGetLastError()));
|
||||
freeaddrinfo(result);
|
||||
WSACleanup();
|
||||
return -1;
|
||||
}
|
||||
iRes = bind(GSocket, result->ai_addr, (int) result->ai_addrlen);
|
||||
if (iRes == SOCKET_ERROR) {
|
||||
error(Sec("(Proxy) bind failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
error("(Proxy) bind failed with error: " + std::to_string(WSAGetLastError()));
|
||||
freeaddrinfo(result);
|
||||
KillSocket(GSocket);
|
||||
WSACleanup();
|
||||
@ -149,7 +153,7 @@ SOCKET SetupListener(){
|
||||
freeaddrinfo(result);
|
||||
iRes = listen(GSocket, SOMAXCONN);
|
||||
if (iRes == SOCKET_ERROR) {
|
||||
error(Sec("(Proxy) listen failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
error("(Proxy) listen failed with error: " + std::to_string(WSAGetLastError()));
|
||||
KillSocket(GSocket);
|
||||
WSACleanup();
|
||||
return -1;
|
||||
@ -158,7 +162,7 @@ SOCKET SetupListener(){
|
||||
}
|
||||
void AutoPing(){
|
||||
while(!Terminate){
|
||||
ServerSend(Sec("p"),false);
|
||||
ServerSend("p",false);
|
||||
PingStart = std::chrono::high_resolution_clock::now();
|
||||
std::this_thread::sleep_for(std::chrono::seconds (1));
|
||||
}
|
||||
@ -197,10 +201,10 @@ void NetMain(const std::string& IP, int Port){
|
||||
void TCPGameServer(const std::string& IP, int Port){
|
||||
GSocket = SetupListener();
|
||||
while (!TCPTerminate && GSocket != -1){
|
||||
debug(Sec("MAIN LOOP OF GAME SERVER"));
|
||||
debug("MAIN LOOP OF GAME SERVER");
|
||||
GConnected = false;
|
||||
if(!CServer){
|
||||
warn(Sec("Connection still alive terminating"));
|
||||
warn("Connection still alive terminating");
|
||||
NetReset();
|
||||
TCPTerminate = true;
|
||||
Terminate = true;
|
||||
@ -212,10 +216,10 @@ void TCPGameServer(const std::string& IP, int Port){
|
||||
}
|
||||
CSocket = accept(GSocket, nullptr, nullptr);
|
||||
if (CSocket == -1) {
|
||||
debug(Sec("(Proxy) accept failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
debug("(Proxy) accept failed with error: " + std::to_string(WSAGetLastError()));
|
||||
break;
|
||||
}
|
||||
debug(Sec("(Proxy) Game Connected!"));
|
||||
debug("(Proxy) Game Connected!");
|
||||
GConnected = true;
|
||||
if(CServer){
|
||||
std::thread t1(NetMain, IP, Port);
|
||||
@ -235,7 +239,7 @@ void TCPGameServer(const std::string& IP, int Port){
|
||||
}while(Header[Rcv++] != '>');
|
||||
if(Temp < 1 || TCPTerminate)break;
|
||||
if(std::from_chars(Header,&Header[Rcv],Size).ptr[0] != '>'){
|
||||
debug(Sec("(Game) Invalid lua Header -> ") + std::string(Header,Rcv));
|
||||
debug("(Game) Invalid lua Header -> " + std::string(Header,Rcv));
|
||||
break;
|
||||
}
|
||||
std::string Ret(Size,0);
|
||||
@ -250,12 +254,12 @@ void TCPGameServer(const std::string& IP, int Port){
|
||||
ServerSend(Ret,false);
|
||||
|
||||
}while(Temp > 0 && !TCPTerminate);
|
||||
if(Temp == 0)debug(Sec("(Proxy) Connection closing"));
|
||||
else debug(Sec("(Proxy) recv failed error : ") + std::to_string(WSAGetLastError()));
|
||||
if(Temp == 0)debug("(Proxy) Connection closing");
|
||||
else debug("(Proxy) recv failed error : " + std::to_string(WSAGetLastError()));
|
||||
}
|
||||
TCPTerminate = true;
|
||||
GConnected = false;
|
||||
Terminate = true;
|
||||
if(CSocket != SOCKET_ERROR)KillSocket(CSocket);
|
||||
debug(Sec("END OF GAME SERVER"));
|
||||
debug("END OF GAME SERVER");
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/18/2020
|
||||
///
|
||||
|
||||
#include "Security/Game.h"
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
@ -42,7 +46,7 @@ int progress_bar (void *bar, double t, double d){
|
||||
nb_bar = 25;
|
||||
progress_bar_adv = round(d/t*nb_bar);
|
||||
std::cout<<"\r";
|
||||
std::cout<<Sec("Progress : [ ");
|
||||
std::cout<< "Progress : [ ";
|
||||
if(t!=0)std::cout<<round(d/t*100);else std::cout<<0;
|
||||
std::cout << "% ] [";
|
||||
int i;
|
||||
@ -60,7 +64,7 @@ struct File {
|
||||
static size_t my_fwrite(void *buffer,size_t size,size_t nmemb,void *stream){
|
||||
auto *out = (struct File*)stream;
|
||||
if(!out->stream) {
|
||||
fopen_s(&out->stream,out->filename,Sec("wb"));
|
||||
fopen_s(&out->stream,out->filename,"wb");
|
||||
if(!out->stream)return -1;
|
||||
}
|
||||
return fwrite(buffer, size, nmemb, out->stream);
|
||||
@ -84,7 +88,6 @@ int Download(const std::string& URL,const std::string& Path,bool close){
|
||||
if(res != CURLE_OK)return res;
|
||||
}
|
||||
if(file.stream)fclose(file.stream);
|
||||
if(!close)SecureMods();
|
||||
std::cout << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 4/11/2020
|
||||
///
|
||||
|
||||
#include "Network/network.h"
|
||||
#include "Security/Init.h"
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include <WS2tcpip.h>
|
||||
#include <filesystem>
|
||||
#include "Startup.h"
|
||||
@ -101,8 +104,8 @@ std::string Auth(SOCKET Sock){
|
||||
}
|
||||
|
||||
void UpdateUl(bool D,const std::string&msg){
|
||||
if(D)UlStatus = "UlDownloading Resource: " + msg;
|
||||
else UlStatus = "UlLoading Resource: " + msg;
|
||||
if(D)UlStatus = "UlDownloading Resource " + msg;
|
||||
else UlStatus = "UlLoading Resource " + msg;
|
||||
}
|
||||
|
||||
void AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name){
|
||||
@ -244,10 +247,13 @@ void SyncResources(SOCKET Sock){
|
||||
if (fs::exists(a)) {
|
||||
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
|
||||
if (fs::file_size(a) == std::stoi(*FS)){
|
||||
UpdateUl(false,"(" + std::to_string(Pos) + "/" + std::to_string(Amount) + "): " + a.substr(a.find_last_of('/')));
|
||||
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 {
|
||||
fs::copy_file(a, "BeamNG/mods" + a.substr(a.find_last_of('/')),
|
||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
||||
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
||||
}
|
||||
fs::copy_file(a, GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/')),
|
||||
fs::copy_options::overwrite_existing);
|
||||
} catch (std::exception& e) {
|
||||
error("Failed copy to the mods folder! " + std::string(e.what()));
|
||||
@ -271,12 +277,12 @@ void SyncResources(SOCKET Sock){
|
||||
break;
|
||||
}
|
||||
|
||||
std::string Name = "(" + std::to_string(Pos) + "/" + std::to_string(Amount) + "): " + FName;
|
||||
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
||||
|
||||
Data = MultiDownload(Sock,DSock,std::stoull(*FS), Name);
|
||||
|
||||
if(Terminate)break;
|
||||
UpdateUl(false,"("+std::to_string(Pos)+"/"+std::to_string(Amount)+"): "+FName);
|
||||
UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName);
|
||||
std::ofstream LFS;
|
||||
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
|
||||
if (LFS.is_open()) {
|
||||
@ -286,7 +292,12 @@ void SyncResources(SOCKET Sock){
|
||||
|
||||
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
|
||||
KillSocket(DSock);
|
||||
if(!Terminate)fs::copy_file(a,"BeamNG/mods"+FName, fs::copy_options::overwrite_existing);
|
||||
if(!Terminate){
|
||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
||||
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
||||
}
|
||||
fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing);
|
||||
}
|
||||
WaitForConfirm();
|
||||
}
|
||||
if(!Terminate){
|
||||
|
@ -1,9 +1,13 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 5/8/2020
|
||||
///
|
||||
#include "Zlib/Compressor.h"
|
||||
#include "Network/network.h"
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include <WS2tcpip.h>
|
||||
#include "Logger.h"
|
||||
#include <string>
|
||||
@ -20,7 +24,7 @@ void UDPSend(std::string Data){
|
||||
}
|
||||
std::string Packet = char(ClientID+1) + std::string(":") + Data;
|
||||
int sendOk = sendto(UDPSock, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)ToServer, sizeof(*ToServer));
|
||||
if (sendOk == SOCKET_ERROR)error(Sec("Error Code : ") + std::to_string(WSAGetLastError()));
|
||||
if (sendOk == SOCKET_ERROR)error("Error Code : " + std::to_string(WSAGetLastError()));
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +55,7 @@ void UDPRcv(){
|
||||
void UDPClientMain(const std::string& IP,int Port){
|
||||
WSADATA data;
|
||||
if (WSAStartup(514, &data)){
|
||||
error(Sec("Can't start Winsock!"));
|
||||
error("Can't start Winsock!");
|
||||
return;
|
||||
}
|
||||
delete ToServer;
|
||||
@ -60,6 +64,7 @@ void UDPClientMain(const std::string& IP,int Port){
|
||||
ToServer->sin_port = htons(Port);
|
||||
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
||||
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
GameSend("P"+std::to_string(ClientID));
|
||||
TCPSend("H",TCPSock);
|
||||
UDPSend("p");
|
||||
while(!Terminate)UDPRcv();
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 5/8/2020
|
||||
///
|
||||
@ -8,7 +12,7 @@
|
||||
#include <iostream>
|
||||
#include <WS2tcpip.h>
|
||||
#include <Zlib/Compressor.h>
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include "Network/network.h"
|
||||
|
||||
|
||||
@ -119,7 +123,7 @@ void TCPClientMain(const std::string& IP,int Port){
|
||||
TCPSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if(TCPSock == -1){
|
||||
printf(Sec("Client: socket failed! Error code: %d\n"), WSAGetLastError());
|
||||
printf("Client: socket failed! Error code: %d\n", WSAGetLastError());
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/18/2020
|
||||
///
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <Windows.h>
|
||||
#include "Logger.h"
|
||||
@ -19,7 +23,7 @@ std::string GameDir;
|
||||
void lowExit(int code){
|
||||
TraceBack = 0;
|
||||
std::string msg =
|
||||
Sec("Failed to find the game please launch it. Report this if the issue persists code ");
|
||||
"Failed to find the game please launch it. Report this if the issue persists code ";
|
||||
error(msg+std::to_string(code));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
exit(2);
|
||||
@ -27,7 +31,7 @@ void lowExit(int code){
|
||||
void Exit(int code){
|
||||
TraceBack = 0;
|
||||
std::string msg =
|
||||
Sec("Sorry. We do not support cracked copies report this if you believe this is a mistake code ");
|
||||
"Sorry. We do not support cracked copies report this if you believe this is a mistake code ";
|
||||
error(msg+std::to_string(code));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
exit(3);
|
||||
@ -35,7 +39,7 @@ void Exit(int code){
|
||||
void SteamExit(int code){
|
||||
TraceBack = 0;
|
||||
std::string msg =
|
||||
Sec("Illegal steam modifications detected report this if you believe this is a mistake code ");
|
||||
"Illegal steam modifications detected report this if you believe this is a mistake code ";
|
||||
error(msg+std::to_string(code));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
exit(4);
|
||||
@ -87,7 +91,7 @@ std::string QueryKey(HKEY hKey,int ID){
|
||||
cbName = MAX_KEY_LENGTH;
|
||||
retCode = RegEnumKeyEx(hKey, i,achKey,&cbName,nullptr,nullptr,nullptr,&ftLastWriteTime);
|
||||
if (retCode == ERROR_SUCCESS){
|
||||
if(strcmp(achKey,Sec("Steam App 284160")) == 0){
|
||||
if(strcmp(achKey,"Steam App 284160") == 0){
|
||||
return achKey;
|
||||
}
|
||||
}
|
||||
@ -105,13 +109,13 @@ 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 == Sec("SteamExe")){
|
||||
case 1: if(key == "SteamExe"){
|
||||
auto p = data.find_last_of('/');
|
||||
if(p != std::string::npos)return data.substr(0,p);
|
||||
}break;
|
||||
case 2: if(key == Sec("Name") && data == Sec("BeamNG.drive"))return data;break;
|
||||
case 3: if(key == Sec("rootpath"))return data;break;
|
||||
case 4: if(key == Sec("userpath_override"))return data;
|
||||
case 2: if(key == "Name" && data == "BeamNG.drive")return data;break;
|
||||
case 3: if(key == "rootpath")return data;break;
|
||||
case 4: if(key == "userpath_override")return data;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -131,7 +135,7 @@ void FileList(std::vector<std::string>&a,const std::string& Path){
|
||||
}
|
||||
bool Find(const std::string& FName,const std::string& Path){
|
||||
std::vector<std::string> FS;
|
||||
FileList(FS,Path+Sec("/userdata"));
|
||||
FileList(FS,Path+"/userdata");
|
||||
for(std::string&a : FS){
|
||||
if(a.find(FName) != std::string::npos){
|
||||
FS.clear();
|
||||
@ -146,8 +150,8 @@ bool FindHack(const std::string& Path){
|
||||
for (const auto &entry : fs::directory_iterator(Path)) {
|
||||
std::string Name = entry.path().filename().string();
|
||||
for(char&c : Name)c = char(tolower(c));
|
||||
if(Name == Sec("steam.exe"))s = false;
|
||||
if(Name.find(Sec("greenluma")) != -1)return true;
|
||||
if(Name == "steam.exe")s = false;
|
||||
if(Name.find("greenluma") != -1)return true;
|
||||
Name.clear();
|
||||
}
|
||||
return s;
|
||||
@ -209,7 +213,7 @@ std::string GetManifest(const std::string& Man){
|
||||
f.seekg(0, std::ios_base::beg);
|
||||
f.read(&vec[0], fileSize);
|
||||
f.close();
|
||||
std::string ToFind = Sec("\"LastOwner\"\t\t\"");
|
||||
std::string ToFind = "\"LastOwner\"\t\t\"";
|
||||
int pos = int(vec.find(ToFind));
|
||||
if(pos != -1){
|
||||
pos += int(ToFind.length());
|
||||
@ -219,10 +223,10 @@ std::string GetManifest(const std::string& Man){
|
||||
}
|
||||
bool IDCheck(std::string Man, std::string steam){
|
||||
bool a = false,b = true;
|
||||
int pos = int(Man.rfind(Sec("steamapps")));
|
||||
int pos = int(Man.rfind("steamapps"));
|
||||
if(pos == -1)Exit(5);
|
||||
Man = Man.substr(0,pos+9) + Sec("/appmanifest_284160.acf");
|
||||
steam += Sec("/config/loginusers.vdf");
|
||||
Man = Man.substr(0,pos+9) + "/appmanifest_284160.acf";
|
||||
steam += "/config/loginusers.vdf";
|
||||
if(fs::exists(Man) && fs::exists(steam)){
|
||||
for(const std::string&ID : GetID(steam)){
|
||||
if(ID == GetManifest(Man))b = false;
|
||||
@ -233,16 +237,16 @@ bool IDCheck(std::string Man, std::string steam){
|
||||
}
|
||||
void LegitimacyCheck(){
|
||||
std::string Result,T;
|
||||
std::string K1 = Sec("Software\\Valve\\Steam");
|
||||
std::string K2 = Sec("Software\\Valve\\Steam\\Apps\\284160");
|
||||
std::string K3 = Sec("Software\\BeamNG\\BeamNG.drive");
|
||||
std::string K1 = R"(Software\Valve\Steam)";
|
||||
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(Sec("284160.json"),Result))Exit(2);
|
||||
if(!Find("284160.json",Result))Exit(2);
|
||||
if(FindHack(Result))SteamExit(1);
|
||||
}else Exit(3);
|
||||
T = Result;
|
||||
@ -273,15 +277,14 @@ void LegitimacyCheck(){
|
||||
if(TraceBack < 3)exit(-1);
|
||||
}
|
||||
std::string CheckVer(const std::string &dir){
|
||||
std::string vec,temp,Path = dir + Sec("\\integrity.json");
|
||||
std::string temp,Path = dir + "\\integrity.json";
|
||||
std::ifstream f(Path.c_str(), std::ios::binary);
|
||||
f.seekg(0, std::ios_base::end);
|
||||
std::streampos fileSize = f.tellg();
|
||||
vec.resize(size_t(fileSize) + 1);
|
||||
f.seekg(0, std::ios_base::beg);
|
||||
f.read(&vec[0], fileSize);
|
||||
int Size = int(std::filesystem::file_size(Path));
|
||||
std::string vec(Size,0);
|
||||
f.read(&vec[0], Size);
|
||||
f.close();
|
||||
vec = vec.substr(vec.find_last_of(Sec("version")),vec.find_last_of('"'));
|
||||
|
||||
vec = vec.substr(vec.find_last_of("version"),vec.find_last_of('"'));
|
||||
for(const char &a : vec){
|
||||
if(isdigit(a) || a == '.')temp+=a;
|
||||
}
|
||||
|
@ -1,117 +0,0 @@
|
||||
#include "Security/Enc.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
|
||||
int LocalKeys[] = {7406809,6967,4810803}; //n e d
|
||||
|
||||
int log_power(int n,unsigned int p, int mod){
|
||||
int result = 1;
|
||||
for (; p; p >>= 1u){
|
||||
if (p & 1u)result = int((1LL * result * n) % mod);
|
||||
n = int((1LL * n * n) % mod);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int Rand(){
|
||||
std::random_device r;
|
||||
std::default_random_engine e1(r());
|
||||
std::uniform_int_distribution<int> uniform_dist(1, 5000);
|
||||
return uniform_dist(e1);
|
||||
}
|
||||
|
||||
bool rabin_miller(int n){
|
||||
bool ok = true;
|
||||
for (int i = 1; i <= 5 && ok; i++) {
|
||||
int a = Rand() + 1;
|
||||
int result = log_power(a, n - 1, n);
|
||||
ok &= (result == 1);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
int generate_prime(){
|
||||
int generated = Rand();
|
||||
while (!rabin_miller(generated))generated = Rand();
|
||||
return generated;
|
||||
}
|
||||
int gcd(int a, int b){
|
||||
while (b){
|
||||
int r = a % b;
|
||||
a = b;
|
||||
b = r;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
int generate_coprime(int n){
|
||||
int generated = Rand();
|
||||
while (gcd(n, generated) != 1)generated = Rand();
|
||||
return generated;
|
||||
}
|
||||
|
||||
std::pair<int, int> euclid_extended(int a, int b) {
|
||||
if(!b)return {1, 0};
|
||||
auto result = euclid_extended(b, a % b);
|
||||
return {result.second, result.first - (a / b) * result.second};
|
||||
}
|
||||
|
||||
int modular_inverse(int n, int mod){
|
||||
int inverse = euclid_extended(n, mod).first;
|
||||
while(inverse < 0)inverse += mod;
|
||||
return inverse;
|
||||
}
|
||||
|
||||
RSA* GenKey(){
|
||||
int p, q;
|
||||
p = generate_prime();
|
||||
q = generate_prime();
|
||||
int n = p * q;
|
||||
int phi = (p -1) * (q - 1);
|
||||
int e = generate_coprime(phi);
|
||||
int d = modular_inverse(e, phi);
|
||||
return new RSA{n,e,d};
|
||||
}
|
||||
int Enc(int value,int e,int n){
|
||||
return log_power(value, e, n);
|
||||
}
|
||||
|
||||
int Dec(int value,int d,int n){
|
||||
return log_power(value, d, n);
|
||||
}
|
||||
std::string LocalEnc(const std::string& Data){
|
||||
std::stringstream stream;
|
||||
for(const char&c : Data){
|
||||
stream << std::hex << Enc(uint8_t(c),LocalKeys[1],LocalKeys[0]) << "g";
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
std::string LocalDec(const std::string& Data){
|
||||
std::stringstream ss(Data);
|
||||
std::string token,ret;
|
||||
while (std::getline(ss, token, 'g')) {
|
||||
if(token.find_first_not_of(Sec("0123456789abcdef")) != std::string::npos)return "";
|
||||
int c = std::stoi(token, nullptr, 16);
|
||||
ret += char(Dec(c,LocalKeys[2],LocalKeys[0]));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string RSA_E(const std::string& Data,int e, int n){
|
||||
std::stringstream stream;
|
||||
for(const char&c : Data){
|
||||
stream << std::hex << Enc(uint8_t(c),e,n) << "g";
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string RSA_D(const std::string& Data, int d, int n){
|
||||
std::stringstream ss(Data);
|
||||
std::string token,ret;
|
||||
while (std::getline(ss, token, 'g')) {
|
||||
if(token.find_first_not_of(Sec("0123456789abcdef")) != std::string::npos)return "";
|
||||
int c = std::stoi(token, nullptr, 16);
|
||||
ret += char(Dec(c,d,n));
|
||||
}
|
||||
return ret;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 7/19/2020
|
||||
///
|
||||
#include "Security/Enc.h"
|
||||
#include <windows.h>
|
||||
#include "Security/Game.h"
|
||||
#include <filesystem>
|
||||
#include <RestartManager.h>
|
||||
#include "Logger.h"
|
||||
#include <thread>
|
||||
|
||||
namespace fs = std::experimental::filesystem;
|
||||
void CheckDirs(){
|
||||
for (auto& p : fs::directory_iterator(Sec("BeamNG\\mods"))) {
|
||||
if(fs::is_directory(p.path()))exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
bool BeamLoad(PCWSTR pszFile){
|
||||
bool Ret = false;
|
||||
DWORD dwSession;
|
||||
WCHAR szSessionKey[CCH_RM_SESSION_KEY+1] = {0};
|
||||
DWORD dwError = RmStartSession(&dwSession, 0, szSessionKey);
|
||||
if (dwError == ERROR_SUCCESS) {
|
||||
dwError = RmRegisterResources(dwSession, 1, &pszFile,
|
||||
0, nullptr, 0, nullptr);
|
||||
if (dwError == ERROR_SUCCESS) {
|
||||
DWORD dwReason;
|
||||
UINT nProcInfoNeeded;
|
||||
UINT nProcInfo = 10;
|
||||
RM_PROCESS_INFO rgpi[10];
|
||||
dwError = RmGetList(dwSession, &nProcInfoNeeded,&nProcInfo, rgpi, &dwReason);
|
||||
if (dwError == ERROR_SUCCESS) {
|
||||
if(nProcInfo == 1){
|
||||
std::string AppName(50,0);
|
||||
size_t N;
|
||||
wcstombs_s(&N,&AppName[0],50, rgpi[0].strAppName, 50);
|
||||
if(!AppName.find(Sec("BeamNG.drive")) && GamePID == rgpi[0].Process.dwProcessId){
|
||||
Ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RmEndSession(dwSession);
|
||||
}
|
||||
return Ret;
|
||||
}
|
||||
void ContinuousCheck(fs::file_time_type last){
|
||||
std::string path = Sec(R"(BeamNG\mods\BeamMP.zip)");
|
||||
int i = 0;
|
||||
while(fs::exists(path) && last == fs::last_write_time(path)){
|
||||
if(!BeamLoad(SecW(L"BeamNG\\mods\\BeamMP.zip"))) {
|
||||
if (i < 120)i++;
|
||||
else {
|
||||
error(Sec("Mod did not load! launcher closing soon"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
exit(0);
|
||||
}
|
||||
}else i = 0;
|
||||
CheckDirs();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(800));
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void SecureMods(){
|
||||
fs::file_time_type last = fs::last_write_time(Sec(R"(BeamNG\mods\BeamMP.zip)"));
|
||||
auto* HandleCheck = new std::thread(ContinuousCheck,last);
|
||||
HandleCheck->detach();
|
||||
delete HandleCheck;
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 11/26/2020
|
||||
///
|
||||
|
132
src/Startup.cpp
132
src/Startup.cpp
@ -1,13 +1,18 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/16/2020
|
||||
///
|
||||
#include "Discord/discord_info.h"
|
||||
#include "Network/network.h"
|
||||
#include "Security/Init.h"
|
||||
#include "Security/Enc.h"
|
||||
|
||||
#include "Curl/http.h"
|
||||
#include <curl/curl.h>
|
||||
#include <filesystem>
|
||||
#include "Startup.h"
|
||||
#include <iostream>
|
||||
#include "Logger.h"
|
||||
#include <thread>
|
||||
@ -30,8 +35,8 @@ void ReLaunch(int argc,char*args[]){
|
||||
Arg += " ";
|
||||
Arg += args[c-1];
|
||||
}
|
||||
system(Sec("cls"));
|
||||
ShellExecute(nullptr,Sec("runas"),GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||
system("cls");
|
||||
ShellExecute(nullptr,"runas",GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||
ShowWindow(GetConsoleWindow(),0);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
exit(1);
|
||||
@ -42,7 +47,7 @@ void URelaunch(int argc,char* args[]){
|
||||
Arg += " ";
|
||||
Arg += args[c-1];
|
||||
}
|
||||
ShellExecute(nullptr,Sec("open"),GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||
ShellExecute(nullptr,"open",GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||
ShowWindow(GetConsoleWindow(),0);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
exit(1);
|
||||
@ -57,73 +62,75 @@ void CheckName(int argc,char* args[]){
|
||||
URelaunch(argc,args);
|
||||
}
|
||||
}
|
||||
|
||||
/// Deprecated
|
||||
void RequestRole(){
|
||||
auto NPos = std::string::npos;
|
||||
std::string HTTP_Result = HTTP_REQUEST(Sec("https://beammp.com/entitlement?did=")+GetDID()+Sec("&t=l"),443);
|
||||
std::string HTTP_Result = HTTP_REQUEST("https://beammp.com/entitlement?did="+GetDID()+"&t=l",443);
|
||||
if(HTTP_Result == "-1"){
|
||||
HTTP_Result = HTTP_REQUEST(Sec("https://backup1.beammp.com/entitlement?did=")+GetDID()+Sec("&t=l"),443);
|
||||
HTTP_Result = HTTP_REQUEST("https://backup1.beammp.com/entitlement?did="+GetDID()+"&t=l",443);
|
||||
if(HTTP_Result == "-1") {
|
||||
fatal(Sec("Sorry Backend System Outage! Don't worry it will back on soon!"));
|
||||
fatal("Sorry Backend System Outage! Don't worry it will back on soon!");
|
||||
}
|
||||
}
|
||||
if(HTTP_Result.find(Sec("\"MDEV\"")) != NPos || HTTP_Result.find(Sec("\"CON\"")) != NPos){
|
||||
if(HTTP_Result.find("\"MDEV\"") != NPos || HTTP_Result.find("\"CON\"") != NPos){
|
||||
if(GetDID() != "125792589621231616"){
|
||||
Dev = true;
|
||||
}
|
||||
}
|
||||
if(HTTP_Result.find(Sec("Error")) != NPos){
|
||||
fatal(Sec("Sorry You need to be in the official BeamMP Discord to proceed! https://discord.gg/beammp"));
|
||||
if(HTTP_Result.find("Error") != NPos){
|
||||
fatal("Sorry You need to be in the official BeamMP Discord to proceed! https://discord.gg/beammp");
|
||||
}
|
||||
info(Sec("Client Connected!"));
|
||||
info("Client Connected!");
|
||||
}
|
||||
|
||||
void CheckForUpdates(int argc,char*args[],const std::string& CV){
|
||||
std::string link = Sec("https://beammp.com/builds/launcher?version=true");
|
||||
std::string link = "https://beammp.com/builds/launcher?version=true";
|
||||
std::string HTTP = HTTP_REQUEST(link,443);
|
||||
bool fallback = false;
|
||||
if(HTTP.find_first_of("0123456789") == std::string::npos){
|
||||
link = Sec("https://backup1.beammp.com/builds/launcher?version=true");
|
||||
link = "https://backup1.beammp.com/builds/launcher?version=true";
|
||||
HTTP = HTTP_REQUEST(link,443);
|
||||
fallback = true;
|
||||
if(HTTP.find_first_of("0123456789") == std::string::npos) {
|
||||
fatal(Sec("Primary Servers Offline! sorry for the inconvenience!"));
|
||||
fatal("Primary Servers Offline! sorry for the inconvenience!");
|
||||
}
|
||||
}
|
||||
if(fallback){
|
||||
link = Sec("https://backup1.beammp.com/builds/launcher?download=true");
|
||||
}else link = Sec("https://beammp.com/builds/launcher?download=true");
|
||||
link = "https://backup1.beammp.com/builds/launcher?download=true";
|
||||
}else link = "https://beammp.com/builds/launcher?download=true";
|
||||
|
||||
struct stat buffer{};
|
||||
std::string Back = Sec("BeamMP-Launcher.back");
|
||||
std::string Back = "BeamMP-Launcher.back";
|
||||
if(stat(Back.c_str(), &buffer) == 0)remove(Back.c_str());
|
||||
if(HTTP > CV){
|
||||
system(Sec("cls"));
|
||||
info(Sec("Update found!"));
|
||||
info(Sec("Updating..."));
|
||||
if(std::rename(GetEN().c_str(), Back.c_str()))error(Sec("failed creating a backup!"));
|
||||
system("cls");
|
||||
info("Update found!");
|
||||
info("Updating...");
|
||||
if(std::rename(GetEN().c_str(), Back.c_str()))error("failed creating a backup!");
|
||||
int i = Download(link, GetEN(),true);
|
||||
if(i != -1){
|
||||
error(Sec("Launcher Update failed! trying again... code : ") + std::to_string(i));
|
||||
error("Launcher Update failed! trying again... code : " + std::to_string(i));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
int i2 = Download(link, GetEN(),true);
|
||||
if(i2 != -1){
|
||||
error(Sec("Launcher Update failed! code : ") + std::to_string(i2));
|
||||
error("Launcher Update failed! code : " + std::to_string(i2));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
ReLaunch(argc,args);
|
||||
}
|
||||
}
|
||||
URelaunch(argc,args);
|
||||
}else{
|
||||
info(Sec("Version is up to date"));
|
||||
info("Version is up to date");
|
||||
}
|
||||
TraceBack++;
|
||||
}
|
||||
void CheckDir(int argc,char*args[]){
|
||||
std::string CDir = args[0];
|
||||
std::string MDir = Sec("BeamNG\\mods");
|
||||
if(!fs::is_directory(Sec("BeamNG"))){
|
||||
if(!fs::create_directory(Sec("BeamNG"))){
|
||||
error(Sec("Cannot Create BeamNG Directory! Retrying..."));
|
||||
std::string MDir = "BeamNG\\mods";
|
||||
if(!fs::is_directory("BeamNG")){
|
||||
if(!fs::create_directory("BeamNG")){
|
||||
error("Cannot Create BeamNG Directory! Retrying...");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
ReLaunch(argc,args);
|
||||
}
|
||||
@ -132,26 +139,26 @@ void CheckDir(int argc,char*args[]){
|
||||
int c = 0;
|
||||
for (auto& p : fs::directory_iterator(MDir))c++;
|
||||
if(c > 2) {
|
||||
warn(std::to_string(c-1) + Sec(" local mods will be wiped! Close this window if you don't want that!"));
|
||||
warn(std::to_string(c-1) + " local launcher mods will be wiped! Close this window if you don't want that!");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(15));
|
||||
}
|
||||
try{
|
||||
fs::remove_all(MDir);
|
||||
} catch (...) {
|
||||
error(Sec("Please close the game and try again"));
|
||||
error("Please close the game and try again");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if(fs::is_directory(MDir) && !Dev)ReLaunch(argc,args);
|
||||
if(!fs::create_directory(MDir) && !Dev){
|
||||
error(Sec("Cannot Create Mods Directory! Retrying..."));
|
||||
error("Cannot Create Mods Directory! Retrying...");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
ReLaunch(argc,args);
|
||||
}
|
||||
if(!fs::is_directory(Sec("BeamNG\\settings"))){
|
||||
if(!fs::create_directory(Sec("BeamNG\\settings"))){
|
||||
error(Sec("Cannot Create Settings Directory! Retrying..."));
|
||||
if(!fs::is_directory("BeamNG\\settings")){
|
||||
if(!fs::create_directory("BeamNG\\settings")){
|
||||
error("Cannot Create Settings Directory! Retrying...");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
ReLaunch(argc,args);
|
||||
}
|
||||
@ -163,63 +170,70 @@ void CustomPort(int argc, char* argv[]){
|
||||
if(Port.find_first_not_of("0123456789") == std::string::npos){
|
||||
if(std::stoi(Port) > 1000){
|
||||
DEFAULT_PORT = std::stoi(Port);
|
||||
warn(Sec("Running on custom port : ") + std::to_string(DEFAULT_PORT));
|
||||
warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
|
||||
}
|
||||
}
|
||||
if(argc > 2)Dev = false;
|
||||
}
|
||||
}
|
||||
void InitLauncher(int argc, char* argv[]) {
|
||||
system(Sec("cls"));
|
||||
system("cls");
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
SetConsoleTitleA((Sec("BeamMP Launcher v") + std::string(GetVer()) + GetPatch()).c_str());
|
||||
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
||||
InitLog();
|
||||
CheckName(argc, argv);
|
||||
CheckLocalKey(); //will replace DiscordMain
|
||||
CheckLocalKey(); //will replace RequestRole
|
||||
Discord_Main();
|
||||
RequestRole();
|
||||
//RequestRole();
|
||||
Dev = true;
|
||||
CustomPort(argc, argv);
|
||||
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
||||
}
|
||||
|
||||
void PreGame(int argc, char* argv[],const std::string& GamePath){
|
||||
info(Sec("Game Version : ") + CheckVer(GamePath));
|
||||
std::string DUI = Sec(R"(BeamNG\settings\uiapps-layouts.json)");
|
||||
std::string GS = Sec(R"(BeamNG\settings\game-settings.ini)");
|
||||
std::string link = Sec("https://beammp.com/client-ui-data");
|
||||
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(Sec("Downloading default ui data..."));
|
||||
info("Downloading default ui data...");
|
||||
i = Download(link,DUI,true);
|
||||
if(i != -1){
|
||||
fallback = true;
|
||||
remove(DUI.c_str());
|
||||
link = Sec("https://backup1.beammp.com/client-ui-data");
|
||||
link = "https://backup1.beammp.com/client-ui-data";
|
||||
i = Download(link,DUI,true);
|
||||
if(i != -1) {
|
||||
error(Sec("Failed to download code : ") + std::to_string(i));
|
||||
error("Failed to download code : " + std::to_string(i));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
ReLaunch(argc, argv);
|
||||
}
|
||||
}
|
||||
info(Sec("Download Complete!"));
|
||||
info("Download Complete!");
|
||||
}
|
||||
if(!fs::exists(GS)) {
|
||||
info(Sec("Downloading default game settings..."));
|
||||
if(fallback)link = Sec("https://backup1.beammp.com/client-settings-data");
|
||||
else link = Sec("https://beammp.com/client-settings-data");
|
||||
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(Sec("Download Complete!"));
|
||||
info("Download Complete!");
|
||||
}
|
||||
if(!Dev) {
|
||||
info(Sec("Downloading mod..."));
|
||||
if(fallback)link = Sec("https://backup1.beammp.com/builds/client?did=") + GetDID();
|
||||
else link = Sec("https://beammp.com/builds/client?did=") + GetDID();
|
||||
Download(link, Sec(R"(BeamNG\mods\BeamMP.zip)"), false);
|
||||
info(Sec("Download Complete!"));
|
||||
info("Downloading mod...");
|
||||
if(fallback)link = "https://backup1.beammp.com/builds/client?did=258329053910663168";
|
||||
else link ="https://beammp.com/builds/client?did=258329053910663168";
|
||||
if(!fs::exists(GetGamePath() + "mods")){
|
||||
fs::create_directory(GetGamePath() + "mods");
|
||||
}
|
||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
||||
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
||||
}
|
||||
Download(link, GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true);
|
||||
info("Download Complete!");
|
||||
}
|
||||
debug(Sec("Name : ") + GetDName());
|
||||
debug(Sec("Discriminator : ") + GetDTag());
|
||||
debug(Sec("Unique ID : ") + GetDID());
|
||||
/*debug("Name : " + GetDName());
|
||||
debug("Discriminator : " + GetDTag());
|
||||
debug("Unique ID : " + GetDID());*/
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/16/2020
|
||||
///
|
||||
@ -23,6 +27,6 @@ int main(int argc, char* argv[]) {
|
||||
CheckDir(argc,argv);
|
||||
LegitimacyCheck();
|
||||
PreGame(argc,argv,GetGameDir());
|
||||
InitGame(GetGameDir(),argv[0]);
|
||||
InitGame(GetGameDir());
|
||||
CoreNetwork();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user