mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-03 22:36:14 +00:00
Compare commits
1 Commits
master
...
better-hea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
642dc76a92 |
2
.github/workflows/cmake-linux.yml
vendored
2
.github/workflows/cmake-linux.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
||||
with:
|
||||
vcpkgArguments: 'zlib nlohmann-json openssl cpp-httplib[openssl]'
|
||||
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||
vcpkgGitCommitId: 'b5d1a94fb7f88fd835e360fd23a45a09ceedbf48'
|
||||
vcpkgGitCommitId: '40616a5e954f7be1077ef37db3fbddbd5dcd1ca6'
|
||||
|
||||
- name: Create Build Environment
|
||||
run: cmake -E make_directory ${{github.workspace}}/build-linux
|
||||
|
||||
2
.github/workflows/cmake-windows.yml
vendored
2
.github/workflows/cmake-windows.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
||||
with:
|
||||
vcpkgArguments: 'discord-rpc zlib nlohmann-json openssl cpp-httplib[openssl]'
|
||||
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||
vcpkgGitCommitId: 'b5d1a94fb7f88fd835e360fd23a45a09ceedbf48'
|
||||
vcpkgGitCommitId: '40616a5e954f7be1077ef37db3fbddbd5dcd1ca6'
|
||||
vcpkgTriplet: 'x64-windows-static'
|
||||
|
||||
- name: Create Build Environment
|
||||
|
||||
@@ -227,7 +227,7 @@ void Parse(std::string Data, SOCKET CSocket) {
|
||||
TCPTerminate = true;
|
||||
Data.clear();
|
||||
futures.push_back(std::async(std::launch::async, []() {
|
||||
CoreSend("B" + HTTP::Get("https://backend.beammp.com/servers-info"));
|
||||
// CoreSend("B" + HTTP::Get("https://backend.beammp.com/servers-info"));
|
||||
}));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -20,6 +20,45 @@
|
||||
#include <mutex>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
void WriteHttpDebug(const httplib::Client& client, const std::string& method, const std::string& target, const httplib::Result& result) try {
|
||||
const std::filesystem::path folder = ".https_debug";
|
||||
std::filesystem::create_directories(folder);
|
||||
if (!std::filesystem::exists(folder / "WHAT IS THIS FOLDER.txt")) {
|
||||
std::ofstream ignore { folder / "WHAT IS THIS FOLDER.txt" };
|
||||
ignore << "This folder exists to help debug current issues with the backend. Do not share this folder with anyone but BeamMP staff. It contains detailed logs of any failed http requests." << std::endl;
|
||||
}
|
||||
const auto file = folder / (method + ".json");
|
||||
// 1 MB limit
|
||||
if (std::filesystem::exists(file) && std::filesystem::file_size(file) > 1'000'000) {
|
||||
std::filesystem::rename(file, file.generic_string() + ".bak");
|
||||
}
|
||||
|
||||
std::ofstream of { file, std::ios::app };
|
||||
nlohmann::json js {
|
||||
{ "utc", std::chrono::system_clock::now().time_since_epoch().count() },
|
||||
{ "target", target },
|
||||
{ "client_info", {
|
||||
{ "openssl_verify_result", client.get_openssl_verify_result() },
|
||||
{ "host", client.host() },
|
||||
{ "port", client.port() },
|
||||
{ "socket_open", client.is_socket_open() },
|
||||
{ "valid", client.is_valid() },
|
||||
} },
|
||||
};
|
||||
if (result) {
|
||||
auto value = result.value();
|
||||
js["result"] = {};
|
||||
js["result"]["body"] = value.body;
|
||||
js["result"]["status"] = value.status;
|
||||
js["result"]["headers"] = value.headers;
|
||||
js["result"]["version"] = value.version;
|
||||
js["result"]["location"] = value.location;
|
||||
js["result"]["reason"] = value.reason;
|
||||
}
|
||||
of << js.dump();
|
||||
} catch (const std::exception& e) {
|
||||
error(e.what());
|
||||
}
|
||||
|
||||
static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
|
||||
std::string* Result = reinterpret_cast<std::string*>(userp);
|
||||
@@ -130,118 +169,118 @@ void set_headers(httplib::Response& res) {
|
||||
}
|
||||
|
||||
void HTTP::StartProxy() {
|
||||
std::thread proxy([&]() {
|
||||
httplib::Server HTTPProxy;
|
||||
httplib::Headers headers = {
|
||||
{ "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() },
|
||||
{ "Accept", "*/*" }
|
||||
};
|
||||
httplib::Client backend("https://backend.beammp.com");
|
||||
httplib::Client forum("https://forum.beammp.com");
|
||||
// std::thread proxy([&]() {
|
||||
// httplib::Server HTTPProxy;
|
||||
// httplib::Headers headers = {
|
||||
// { "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() },
|
||||
// { "Accept", "*/*" }
|
||||
// };
|
||||
// httplib::Client backend("https://backend.beammp.com");
|
||||
// httplib::Client forum("https://forum.beammp.com");
|
||||
|
||||
const std::string pattern = ".*";
|
||||
// const std::string pattern = ".*";
|
||||
|
||||
auto handle_request = [&](const httplib::Request& req, httplib::Response& res) {
|
||||
set_headers(res);
|
||||
if (req.has_header("X-BMP-Authentication")) {
|
||||
headers.emplace("X-BMP-Authentication", PrivateKey);
|
||||
}
|
||||
if (req.has_header("X-API-Version")) {
|
||||
headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
|
||||
}
|
||||
// auto handle_request = [&](const httplib::Request& req, httplib::Response& res) {
|
||||
// set_headers(res);
|
||||
// if (req.has_header("X-BMP-Authentication")) {
|
||||
// headers.emplace("X-BMP-Authentication", PrivateKey);
|
||||
// }
|
||||
// if (req.has_header("X-API-Version")) {
|
||||
// headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
|
||||
// }
|
||||
|
||||
const std::vector<std::string> path = Utils::Split(req.path, "/");
|
||||
// const std::vector<std::string> path = Utils::Split(req.path, "/");
|
||||
|
||||
httplib::Result cli_res;
|
||||
const std::string method = req.method;
|
||||
std::string host = "";
|
||||
// httplib::Result cli_res;
|
||||
// const std::string method = req.method;
|
||||
// std::string host = "";
|
||||
|
||||
if (!path.empty())
|
||||
host = path[0];
|
||||
// if (!path.empty())
|
||||
// host = path[0];
|
||||
|
||||
if (host == "backend") {
|
||||
std::string remaining_path = req.path.substr(std::strlen("/backend"));
|
||||
// if (host == "backend") {
|
||||
// std::string remaining_path = req.path.substr(std::strlen("/backend"));
|
||||
|
||||
if (method == "GET")
|
||||
cli_res = backend.Get(remaining_path, headers);
|
||||
else if (method == "POST")
|
||||
cli_res = backend.Post(remaining_path, headers);
|
||||
// if (method == "GET")
|
||||
// cli_res = backend.Get(remaining_path, headers);
|
||||
// else if (method == "POST")
|
||||
// cli_res = backend.Post(remaining_path, headers);
|
||||
|
||||
} else if (host == "avatar") {
|
||||
bool error = false;
|
||||
std::string username;
|
||||
std::string avatar_size = "100";
|
||||
// } else if (host == "avatar") {
|
||||
// bool error = false;
|
||||
// std::string username;
|
||||
// std::string avatar_size = "100";
|
||||
|
||||
if (path.size() > 1) {
|
||||
username = path[1];
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
// if (path.size() > 1) {
|
||||
// username = path[1];
|
||||
// } else {
|
||||
// error = true;
|
||||
// }
|
||||
|
||||
if (path.size() > 2) {
|
||||
try {
|
||||
if (std::stoi(path[2]) > 0)
|
||||
avatar_size = path[2];
|
||||
// if (path.size() > 2) {
|
||||
// try {
|
||||
// if (std::stoi(path[2]) > 0)
|
||||
// avatar_size = path[2];
|
||||
|
||||
} catch (std::exception&) { }
|
||||
}
|
||||
// } catch (std::exception&) { }
|
||||
// }
|
||||
|
||||
httplib::Result summary_res;
|
||||
// httplib::Result summary_res;
|
||||
|
||||
if (!error) {
|
||||
summary_res = forum.Get("/u/" + username + ".json", headers);
|
||||
// if (!error) {
|
||||
// summary_res = forum.Get("/u/" + username + ".json", headers);
|
||||
|
||||
if (!summary_res || summary_res->status != 200) {
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
// if (!summary_res || summary_res->status != 200) {
|
||||
// error = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!error) {
|
||||
try {
|
||||
nlohmann::json d = nlohmann::json::parse(summary_res->body, nullptr, false); // can fail with parse_error
|
||||
// if (!error) {
|
||||
// try {
|
||||
// nlohmann::json d = nlohmann::json::parse(summary_res->body, nullptr, false); // can fail with parse_error
|
||||
|
||||
auto user = d.at("user"); // can fail with out_of_range
|
||||
auto avatar_link_json = user.at("avatar_template"); // can fail with out_of_range
|
||||
// auto user = d.at("user"); // can fail with out_of_range
|
||||
// auto avatar_link_json = user.at("avatar_template"); // can fail with out_of_range
|
||||
|
||||
auto avatar_link = avatar_link_json.get<std::string>();
|
||||
size_t start_pos = avatar_link.find("{size}");
|
||||
if (start_pos != std::string::npos)
|
||||
avatar_link.replace(start_pos, std::strlen("{size}"), avatar_size);
|
||||
// auto avatar_link = avatar_link_json.get<std::string>();
|
||||
// size_t start_pos = avatar_link.find("{size}");
|
||||
// if (start_pos != std::string::npos)
|
||||
// avatar_link.replace(start_pos, std::strlen("{size}"), avatar_size);
|
||||
|
||||
cli_res = forum.Get(avatar_link, headers);
|
||||
// cli_res = forum.Get(avatar_link, headers);
|
||||
|
||||
} catch (std::exception&) {
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
// } catch (std::exception&) {
|
||||
// error = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (error) {
|
||||
cli_res = forum.Get("/user_avatar/forum.beammp.com/user/0/0.png", headers);
|
||||
}
|
||||
// if (error) {
|
||||
// cli_res = forum.Get("/user_avatar/forum.beammp.com/user/0/0.png", headers);
|
||||
// }
|
||||
|
||||
} else {
|
||||
res.set_content("Host not found", "text/plain");
|
||||
return;
|
||||
}
|
||||
// } else {
|
||||
// res.set_content("Host not found", "text/plain");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (cli_res) {
|
||||
res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
|
||||
} else {
|
||||
res.set_content(to_string(cli_res.error()), "text/plain");
|
||||
}
|
||||
};
|
||||
// if (cli_res) {
|
||||
// res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
|
||||
// } else {
|
||||
// res.set_content(to_string(cli_res.error()), "text/plain");
|
||||
// }
|
||||
// };
|
||||
|
||||
HTTPProxy.Get(pattern, [&](const httplib::Request& req, httplib::Response& res) {
|
||||
handle_request(req, res);
|
||||
});
|
||||
// HTTPProxy.Get(pattern, [&](const httplib::Request& req, httplib::Response& res) {
|
||||
// handle_request(req, res);
|
||||
// });
|
||||
|
||||
HTTPProxy.Post(pattern, [&](const httplib::Request& req, httplib::Response& res) {
|
||||
handle_request(req, res);
|
||||
});
|
||||
// HTTPProxy.Post(pattern, [&](const httplib::Request& req, httplib::Response& res) {
|
||||
// handle_request(req, res);
|
||||
// });
|
||||
|
||||
ProxyPort = HTTPProxy.bind_to_any_port("127.0.0.1");
|
||||
debug("HTTP Proxy listening on port " + std::to_string(ProxyPort));
|
||||
HTTPProxy.listen_after_bind();
|
||||
});
|
||||
proxy.detach();
|
||||
// ProxyPort = HTTPProxy.bind_to_any_port("127.0.0.1");
|
||||
// debug("HTTP Proxy listening on port " + std::to_string(ProxyPort));
|
||||
// HTTPProxy.listen_after_bind();
|
||||
// });
|
||||
// proxy.detach();
|
||||
}
|
||||
|
||||
@@ -94,8 +94,7 @@ void UDPClientMain(const std::string& IP, int Port) {
|
||||
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
||||
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (!magic.empty())
|
||||
for (int i = 0; i < 10; i++)
|
||||
UDPSend(magic);
|
||||
UDPSend(magic);
|
||||
GameSend("P" + std::to_string(ClientID));
|
||||
TCPSend("H", TCPSock);
|
||||
UDPSend("p");
|
||||
|
||||
@@ -268,7 +268,7 @@ void LegitimacyCheck() {
|
||||
std::ifstream libraryFolders(libraryFoldersPath);
|
||||
auto root = tyti::vdf::read(libraryFolders);
|
||||
for (auto folderInfo : root.childs) {
|
||||
if ((folderInfo.second->childs["apps"]->attribs).contains("284160") && std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/integrity.json")){
|
||||
if (std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/integrity.json")){
|
||||
GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/";
|
||||
break;
|
||||
}
|
||||
|
||||
323
src/Startup.cpp
323
src/Startup.cpp
@@ -4,6 +4,7 @@
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
||||
#include "zip_file.h"
|
||||
#include <charconv>
|
||||
#include <cstring>
|
||||
@@ -13,9 +14,9 @@
|
||||
#if defined(_WIN32)
|
||||
#elif defined(__linux__)
|
||||
#include <unistd.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <libproc.h>
|
||||
#elif defined (__APPLE__)
|
||||
#include <unistd.h>
|
||||
#include <libproc.h>
|
||||
#endif // __APPLE__
|
||||
#include "Http.h"
|
||||
#include "Logger.h"
|
||||
@@ -83,7 +84,7 @@ beammp_fs_string GetEN() {
|
||||
}
|
||||
|
||||
std::string GetVer() {
|
||||
return "2.8";
|
||||
return "2.7";
|
||||
}
|
||||
std::string GetPatch() {
|
||||
return ".0";
|
||||
@@ -113,7 +114,7 @@ fs::path GetBP(const beammp_fs_char* P) {
|
||||
// should instead be placed in Application Support.
|
||||
proc_pidpath(pid, path, sizeof(path));
|
||||
fspath = std::string(path);
|
||||
#else
|
||||
#else
|
||||
fspath = beammp_fs_string(P);
|
||||
#endif
|
||||
fspath = fs::weakly_canonical(fspath.string() + "/..");
|
||||
@@ -193,215 +194,48 @@ void CheckName() {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <wincrypt.h>
|
||||
#include <wintrust.h>
|
||||
#include <softpub.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma comment(lib, "wintrust.lib")
|
||||
#pragma comment(lib, "crypt32.lib")
|
||||
|
||||
bool CheckThumbprint(std::filesystem::path filepath)
|
||||
{
|
||||
HCERTSTORE hStore = NULL;
|
||||
HCRYPTMSG hMsg = NULL;
|
||||
|
||||
if (!CryptQueryObject(
|
||||
CERT_QUERY_OBJECT_FILE,
|
||||
filepath.wstring().c_str(),
|
||||
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED,
|
||||
CERT_QUERY_FORMAT_FLAG_BINARY,
|
||||
0,
|
||||
NULL, NULL, NULL,
|
||||
&hStore,
|
||||
&hMsg,
|
||||
NULL))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD dwSignerInfo = 0;
|
||||
if (!CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &dwSignerInfo) || dwSignerInfo == 0)
|
||||
return false;
|
||||
|
||||
PCMSG_SIGNER_INFO pSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSignerInfo);
|
||||
if (!CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, pSignerInfo, &dwSignerInfo))
|
||||
{
|
||||
LocalFree(pSignerInfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
CERT_INFO certInfo = {};
|
||||
certInfo.Issuer = pSignerInfo->Issuer;
|
||||
certInfo.SerialNumber = pSignerInfo->SerialNumber;
|
||||
|
||||
PCCERT_CONTEXT pCertContext = CertFindCertificateInStore(
|
||||
hStore,
|
||||
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
|
||||
0,
|
||||
CERT_FIND_SUBJECT_CERT,
|
||||
&certInfo,
|
||||
NULL);
|
||||
|
||||
if (!pCertContext)
|
||||
{
|
||||
LocalFree(pSignerInfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
BYTE hash[64];
|
||||
DWORD hashSize = sizeof(hash);
|
||||
|
||||
bool match = false;
|
||||
if (CertGetCertificateContextProperty(pCertContext, CERT_SHA256_HASH_PROP_ID, hash, &hashSize))
|
||||
{
|
||||
std::string pubKeyData(
|
||||
reinterpret_cast<const char*>(pCertContext->pCertInfo->SubjectPublicKeyInfo.PublicKey.pbData),
|
||||
pCertContext->pCertInfo->SubjectPublicKeyInfo.PublicKey.cbData
|
||||
);
|
||||
|
||||
std::string pubKeyHash = Utils::GetSha256HashReallyFast(pubKeyData, L"PubKey");
|
||||
debug("pub key hash: " + pubKeyHash);
|
||||
|
||||
std::string fileThumbprint;
|
||||
for (DWORD i = 0; i < hashSize; i++)
|
||||
{
|
||||
char buf[3];
|
||||
sprintf_s(buf, "%02x", hash[i]);
|
||||
fileThumbprint += buf;
|
||||
}
|
||||
|
||||
debug("File thumbprint: " +fileThumbprint);
|
||||
debug(filepath);
|
||||
|
||||
if (fileThumbprint == "937f055b713de69416926ed4651d65219a0a0e77d7a78c1932c007e14326da33" && pubKeyHash == "2afad4a5773b0ac449f48350ce0d09c372be0d5bcbaa6d01332ce000baffde99"){
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
|
||||
CertFreeCertificateContext(pCertContext);
|
||||
CertCloseStore(hStore, 0);
|
||||
LocalFree(pSignerInfo);
|
||||
|
||||
return match;
|
||||
}
|
||||
#include <windows.h>
|
||||
#include <wintrust.h>
|
||||
#include <Softpub.h>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#pragma comment(lib, "wintrust")
|
||||
|
||||
bool VerifySignature(const std::filesystem::path& filePath)
|
||||
{
|
||||
std::wstring path = filePath.wstring();
|
||||
|
||||
WINTRUST_FILE_INFO fileInfo = {};
|
||||
fileInfo.cbStruct = sizeof(WINTRUST_FILE_INFO);
|
||||
fileInfo.pcwszFilePath = path.c_str();
|
||||
fileInfo.hFile = NULL;
|
||||
fileInfo.pgKnownSubject = NULL;
|
||||
|
||||
WINTRUST_DATA winTrustData = {};
|
||||
winTrustData.cbStruct = sizeof(WINTRUST_DATA);
|
||||
winTrustData.dwUIChoice = WTD_UI_NONE;
|
||||
winTrustData.dwUnionChoice = WTD_CHOICE_FILE;
|
||||
winTrustData.pFile = &fileInfo;
|
||||
|
||||
winTrustData.dwStateAction = WTD_STATEACTION_VERIFY;
|
||||
|
||||
GUID policyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
|
||||
|
||||
LONG status = WinVerifyTrust(
|
||||
NULL,
|
||||
&policyGUID,
|
||||
&winTrustData
|
||||
);
|
||||
|
||||
debug(filePath);
|
||||
debug("Signature check code: " + std::to_string(status));
|
||||
|
||||
winTrustData.dwStateAction = WTD_STATEACTION_CLOSE;
|
||||
WinVerifyTrust(NULL, &policyGUID, &winTrustData);
|
||||
|
||||
return (status == CERT_E_UNTRUSTEDROOT);
|
||||
}
|
||||
#endif
|
||||
|
||||
void CheckForUpdates(const std::string& CV) {
|
||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
std::string LatestVersion = HTTP::Get(
|
||||
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
// std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
// std::string LatestVersion = HTTP::Get(
|
||||
// "https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
|
||||
std::regex sha256_pattern(R"(^[a-fA-F0-9]{64}$)");
|
||||
std::smatch match;
|
||||
// transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||
// beammp_fs_string BP(GetBP() / GetEN()), Back(GetBP() / beammp_wide("BeamMP-Launcher.back"));
|
||||
|
||||
if (LatestHash.length() != 64 || !std::regex_match(LatestHash, match, sha256_pattern)) {
|
||||
error("Invalid hash from backend, skipping update check.");
|
||||
debug("Launcher hash in question: " + LatestHash);
|
||||
return;
|
||||
}
|
||||
// std::string FileHash = Utils::GetSha256HashReallyFastFile(BP);
|
||||
|
||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||
beammp_fs_string BP(GetBP() / GetEN()), Back(GetBP() / beammp_wide("BeamMP-Launcher.back"));
|
||||
|
||||
std::string FileHash = Utils::GetSha256HashReallyFastFile(BP);
|
||||
|
||||
if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion)))) {
|
||||
if (!options.no_update) {
|
||||
info("Launcher update " + LatestVersion + " found!");
|
||||
#if defined(__linux__)
|
||||
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
|
||||
#else
|
||||
info("Downloading Launcher update " + LatestHash);
|
||||
std::wstring DownloadLocation = GetBP() / (beammp_wide("new_") + GetEN());
|
||||
if (HTTP::Download(
|
||||
"https://backend.beammp.com/builds/launcher?download=true"
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + Branch,
|
||||
DownloadLocation, LatestHash)) {
|
||||
if (!VerifySignature(DownloadLocation) || !CheckThumbprint(DownloadLocation)) {
|
||||
std::error_code ec;
|
||||
fs::remove(DownloadLocation, ec);
|
||||
if (ec) {
|
||||
error("Failed to remove broken launcher update");
|
||||
}
|
||||
throw std::runtime_error("The authenticity of the updated launcher could not be verified, it was corrupted or tampered with.");
|
||||
}
|
||||
|
||||
info("Update signature is valid");
|
||||
|
||||
std::error_code ec;
|
||||
fs::remove(Back, ec);
|
||||
if (ec == std::errc::permission_denied) {
|
||||
error("Failed to remove old backup file: " + ec.message() + ". Using alternative name.");
|
||||
fs::rename(BP, Back + beammp_wide(".") + Utils::ToWString(FileHash.substr(0, 8)));
|
||||
} else {
|
||||
fs::rename(BP, Back);
|
||||
}
|
||||
fs::rename(GetBP() / (beammp_wide("new_") + GetEN()), BP);
|
||||
URelaunch();
|
||||
} else {
|
||||
if (fs::exists(DownloadLocation)) {
|
||||
std::error_code error_code;
|
||||
fs::remove(DownloadLocation, error_code);
|
||||
if (error_code) {
|
||||
error("Failed to remove broken launcher update");
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Failed to download the launcher update! Please try manually updating it, https://docs.beammp.com/FAQ/Update-launcher/");
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
warn("Launcher update was found, but not updating because --no-update or --dev was specified.");
|
||||
}
|
||||
} else
|
||||
info("Launcher version is up to date. Latest version: " + LatestVersion);
|
||||
TraceBack++;
|
||||
// if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion)))) {
|
||||
// if (!options.no_update) {
|
||||
// info("Launcher update " + LatestVersion + " found!");
|
||||
// #if defined(__linux__)
|
||||
// error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
|
||||
// #else
|
||||
// info("Downloading Launcher update " + LatestHash);
|
||||
// HTTP::Download(
|
||||
// "https://backend.beammp.com/builds/launcher?download=true"
|
||||
// "&pk="
|
||||
// + PublicKey + "&branch=" + Branch,
|
||||
// GetBP() / (beammp_wide("new_") + GetEN()), LatestHash);
|
||||
// std::error_code ec;
|
||||
// fs::remove(Back, ec);
|
||||
// if (ec == std::errc::permission_denied) {
|
||||
// error("Failed to remove old backup file: " + ec.message() + ". Using alternative name.");
|
||||
// fs::rename(BP, Back + beammp_wide(".") + Utils::ToWString(FileHash.substr(0, 8)));
|
||||
// } else {
|
||||
// fs::rename(BP, Back);
|
||||
// }
|
||||
// fs::rename(GetBP() / (beammp_wide("new_") + GetEN()), BP);
|
||||
// URelaunch();
|
||||
// #endif
|
||||
// } else {
|
||||
// warn("Launcher update was found, but not updating because --no-update or --dev was specified.");
|
||||
// }
|
||||
// } else
|
||||
// info("Launcher version is up to date. Latest version: " + LatestVersion);
|
||||
// TraceBack++;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
void LinuxPatch() {
|
||||
HKEY hKey = nullptr;
|
||||
@@ -513,51 +347,42 @@ void PreGame(const beammp_fs_string& GamePath) {
|
||||
CheckMP(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||
info(beammp_wide("Game user path: ") + beammp_fs_string(GetGamePath()));
|
||||
|
||||
if (!options.no_download) {
|
||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||
LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
||||
[](auto const& c) -> bool { return !std::isalnum(c); }),
|
||||
LatestHash.end());
|
||||
// if (!options.no_download) {
|
||||
// std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
||||
// transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||
// LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
||||
// [](auto const& c) -> bool { return !std::isalnum(c); }),
|
||||
// LatestHash.end());
|
||||
|
||||
std::regex sha256_pattern(R"(^[a-fA-F0-9]{64}$)");
|
||||
std::smatch match;
|
||||
// try {
|
||||
// if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
|
||||
// fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||
// }
|
||||
// EnableMP();
|
||||
// } catch (std::exception& e) {
|
||||
// fatal(e.what());
|
||||
// }
|
||||
// #if defined(_WIN32)
|
||||
// std::wstring ZipPath(GetGamePath() / LR"(mods\multiplayer\BeamMP.zip)");
|
||||
// #elif defined(__linux__)
|
||||
// // Linux version of the game cant handle mods with uppercase names
|
||||
// std::string ZipPath(GetGamePath() / R"(mods/multiplayer/beammp.zip)");
|
||||
// #endif
|
||||
|
||||
if (LatestHash.length() != 64 || !std::regex_match(LatestHash, match, sha256_pattern)) {
|
||||
error("Invalid hash from backend, skipping mod update check.");
|
||||
debug("Mod hash in question: " + LatestHash);
|
||||
return;
|
||||
}
|
||||
// std::string FileHash = fs::exists(ZipPath) ? Utils::GetSha256HashReallyFastFile(ZipPath) : "";
|
||||
|
||||
try {
|
||||
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
|
||||
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||
}
|
||||
EnableMP();
|
||||
} catch (std::exception& e) {
|
||||
fatal(e.what());
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
std::wstring ZipPath(GetGamePath() / LR"(mods\multiplayer\BeamMP.zip)");
|
||||
#elif defined(__linux__)
|
||||
// Linux version of the game cant handle mods with uppercase names
|
||||
std::string ZipPath(GetGamePath() / R"(mods/multiplayer/beammp.zip)");
|
||||
#endif
|
||||
// if (FileHash != LatestHash) {
|
||||
// info("Downloading BeamMP Update " + LatestHash);
|
||||
// HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||
// "&pk="
|
||||
// + PublicKey + "&branch=" + Branch,
|
||||
// ZipPath, LatestHash);
|
||||
// }
|
||||
|
||||
std::string FileHash = fs::exists(ZipPath) ? Utils::GetSha256HashReallyFastFile(ZipPath) : "";
|
||||
// beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
|
||||
|
||||
if (FileHash != LatestHash) {
|
||||
info("Downloading BeamMP Update " + LatestHash);
|
||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + Branch,
|
||||
ZipPath, LatestHash);
|
||||
}
|
||||
|
||||
beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
|
||||
|
||||
if (fs::is_directory(Target) && !fs::is_directory(Target + beammp_wide("/.git"))) {
|
||||
fs::remove_all(Target);
|
||||
}
|
||||
}
|
||||
// if (fs::is_directory(Target) && !fs::is_directory(Target + beammp_wide("/.git"))) {
|
||||
// fs::remove_all(Target);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user