mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-06 15:56:26 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09abe75fbb | ||
|
|
b45e4b40f2 | ||
|
|
15d1539a92 | ||
|
|
14a5f47549 | ||
|
|
584998277d |
@@ -10,7 +10,6 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
unsigned long GamePID = 0;
|
unsigned long GamePID = 0;
|
||||||
@@ -36,7 +35,9 @@ std::string GetGamePath(){
|
|||||||
Path = QueryKey(hKey,5);
|
Path = QueryKey(hKey,5);
|
||||||
Path += "\\BeamNG.drive\\";
|
Path += "\\BeamNG.drive\\";
|
||||||
}
|
}
|
||||||
Path += CheckVer(GetGameDir()) + "\\";
|
std::string Ver = CheckVer(GetGameDir());
|
||||||
|
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
|
||||||
|
Path += Ver + "\\";
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include <fstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
#include "Json.h"
|
||||||
|
|
||||||
extern int TraceBack;
|
extern int TraceBack;
|
||||||
bool Dev = false;
|
bool Dev = false;
|
||||||
@@ -26,7 +28,7 @@ std::string GetVer(){
|
|||||||
return "2.0";
|
return "2.0";
|
||||||
}
|
}
|
||||||
std::string GetPatch(){
|
std::string GetPatch(){
|
||||||
return ".2";
|
return ".4";
|
||||||
}
|
}
|
||||||
std::string GetEP(char*P){
|
std::string GetEP(char*P){
|
||||||
static std::string Ret = [&](){
|
static std::string Ret = [&](){
|
||||||
@@ -120,20 +122,75 @@ void CustomPort(int argc, char* argv[]){
|
|||||||
if(argc > 2)Dev = true;
|
if(argc > 2)Dev = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LinuxPatch(){
|
||||||
|
HKEY hKey = nullptr;
|
||||||
|
LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Wine)", 0, KEY_READ, &hKey);
|
||||||
|
if (result != ERROR_SUCCESS || getenv("USER") == nullptr)return;
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
info("Wine/Proton Detected! If you are on windows delete HKEY_CURRENT_USER\\Software\\Wine in regedit");
|
||||||
|
info("Applying patches...");
|
||||||
|
|
||||||
|
result = RegCreateKey(HKEY_CURRENT_USER, R"(Software\Valve\Steam\Apps\284160)", &hKey);
|
||||||
|
|
||||||
|
if (result != ERROR_SUCCESS){
|
||||||
|
fatal(R"(failed to create HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = RegSetValueEx(hKey, "Name", 0, REG_SZ, (BYTE*)"BeamNG.drive", 12);
|
||||||
|
|
||||||
|
if (result != ERROR_SUCCESS){
|
||||||
|
fatal(R"(failed to create the value "Name" under HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
std::string Path = R"(Z:\home\)" + std::string(getenv("USER")) + R"(\.steam\steam\Steam.exe)";
|
||||||
|
|
||||||
|
if(!fs::exists(Path)) {
|
||||||
|
std::ofstream ofs(Path);
|
||||||
|
if (!ofs.is_open()) {
|
||||||
|
fatal("Failed to create file \"" + Path + "\"");
|
||||||
|
return;
|
||||||
|
} else ofs.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
result = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Valve\Steam)", 0, KEY_ALL_ACCESS, &hKey);
|
||||||
|
if (result != ERROR_SUCCESS){
|
||||||
|
fatal(R"(failed to open HKEY_CURRENT_USER\Software\Valve\Steam)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = RegSetValueEx(hKey, "SteamExe", 0, REG_SZ, (BYTE*)Path.c_str(), Path.size());
|
||||||
|
|
||||||
|
if (result != ERROR_SUCCESS){
|
||||||
|
fatal(R"(failed to create the value "Name" under HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
info("Patched!");
|
||||||
|
}
|
||||||
|
|
||||||
void InitLauncher(int argc, char* argv[]) {
|
void InitLauncher(int argc, char* argv[]) {
|
||||||
system("cls");
|
system("cls");
|
||||||
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
||||||
InitLog();
|
InitLog();
|
||||||
CheckName(argc, argv);
|
CheckName(argc, argv);
|
||||||
|
LinuxPatch();
|
||||||
CheckLocalKey();
|
CheckLocalKey();
|
||||||
ConfigInit();
|
ConfigInit();
|
||||||
CustomPort(argc, argv);
|
CustomPort(argc, argv);
|
||||||
Discord_Main();
|
Discord_Main();
|
||||||
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t DirCount(const std::filesystem::path& path){
|
size_t DirCount(const std::filesystem::path& path){
|
||||||
return (size_t)std::distance(std::filesystem::directory_iterator{path}, std::filesystem::directory_iterator{});
|
return (size_t)std::distance(std::filesystem::directory_iterator{path}, std::filesystem::directory_iterator{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckMP(const std::string& Path) {
|
void CheckMP(const std::string& Path) {
|
||||||
if (!fs::exists(Path))return;
|
if (!fs::exists(Path))return;
|
||||||
size_t c = DirCount(fs::path(Path));
|
size_t c = DirCount(fs::path(Path));
|
||||||
@@ -154,8 +211,40 @@ void CheckMP(const std::string& Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EnableMP(){
|
||||||
|
std::string File(GetGamePath() + "mods/db.json");
|
||||||
|
if(!fs::exists(File))return;
|
||||||
|
std::ifstream db(File);
|
||||||
|
if(db.is_open()) {
|
||||||
|
auto Size = fs::file_size(File);
|
||||||
|
std::string Data(Size, 0);
|
||||||
|
db.read(&Data[0], Size);
|
||||||
|
db.close();
|
||||||
|
json::Document d;
|
||||||
|
d.Parse(Data.c_str());
|
||||||
|
if(Data.at(0) != '{' || d.HasParseError()){
|
||||||
|
//error("Failed to parse " + File); //TODO illegal formatting
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!d["mods"].IsNull() && !d["mods"]["multiplayerbeammp"].IsNull()){
|
||||||
|
d["mods"]["multiplayerbeammp"]["active"] = true;
|
||||||
|
rapidjson::StringBuffer buffer;
|
||||||
|
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||||
|
d.Accept(writer);
|
||||||
|
std::ofstream ofs(File);
|
||||||
|
if(ofs.is_open()){
|
||||||
|
ofs << buffer.GetString();
|
||||||
|
ofs.close();
|
||||||
|
}else{
|
||||||
|
error("Failed to write " + File);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PreGame(const std::string& GamePath){
|
void PreGame(const std::string& GamePath){
|
||||||
const std::string CurrVer("0.22.1.0");
|
const std::string CurrVer("0.22.2.0");
|
||||||
std::string GameVer = CheckVer(GamePath);
|
std::string GameVer = CheckVer(GamePath);
|
||||||
info("Game Version : " + GameVer);
|
info("Game Version : " + GameVer);
|
||||||
if(GameVer < CurrVer){
|
if(GameVer < CurrVer){
|
||||||
@@ -171,6 +260,7 @@ void PreGame(const std::string& GamePath){
|
|||||||
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
||||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
|
EnableMP();
|
||||||
}catch(std::exception&e){
|
}catch(std::exception&e){
|
||||||
fatal(e.what());
|
fatal(e.what());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::thread th(flush);
|
std::thread th(flush);
|
||||||
|
|||||||
Reference in New Issue
Block a user