16 Commits

Author SHA1 Message Date
Tixx
a2789a8524 Bump version to v2.7.0 2025-10-20 22:39:36 +02:00
Tixx
6f84b56f1b Bump version 2025-09-27 20:47:14 +02:00
Tixx
6f5197217c Workaround bom header (#211)
This PR removes the utf8 bom encoding header which was causing issues.
This PR also adds support for unicode characters in the terminal on
windows.

For context it looks like the BeamNG launcher only encodes it with the
utf8 header, which is what it's currently removing.

---

By creating this pull request, I understand that code that is AI
generated or otherwise automatically generated may be rejected without
further discussion.
I declare that I fully understand all code I pushed into this PR, and
wrote all this code myself and own the rights to this code.
2025-09-27 20:14:10 +02:00
Tixx
d1d2b3414b Adjust ini parser (#212)
This PR removes mid-line ini comments which were causing issue because
users had `#` and `;` in their file path.

---

By creating this pull request, I understand that code that is AI
generated or otherwise automatically generated may be rejected without
further discussion.
I declare that I fully understand all code I pushed into this PR, and
wrote all this code myself and own the rights to this code.
2025-09-27 20:08:13 +02:00
Tixx
a669557726 Make logger stdout cross platform again 2025-09-21 21:54:24 +02:00
Tixx
be1f5c04f7 Remove mid-line ini comments 2025-09-21 21:49:40 +02:00
Tixx
1209ff88e2 Support unicode in windows terminal 2025-09-21 21:39:57 +02:00
Tixx
c40af681bf Strip bom encoding 2025-09-21 21:39:38 +02:00
Tixx
c03b1d5946 Bump version to v2.6.3 2025-09-17 09:20:21 +02:00
Tixx
5e73c7bce2 Check outdated registry entry for GameDir 2025-09-17 09:19:50 +02:00
Tixx
386f471362 Fix includes for linux build 2025-09-16 20:16:28 +02:00
Tixx
6c3bfda23b Bump version to v2.6.2 2025-09-16 20:09:56 +02:00
Tixx
5737e27bf3 Use ini instead of registry for game dir 2025-09-16 20:07:57 +02:00
Tixx
1860c0aef1 Fix userfolder on linux (hopefully) 2025-09-16 20:07:26 +02:00
Tixx
9d20b678f9 Bump version to v2.6.1 2025-09-16 17:53:29 +02:00
Tixx
be7594039e Fix updating logic 2025-09-16 17:52:30 +02:00
8 changed files with 85 additions and 35 deletions

View File

@@ -38,6 +38,7 @@ extern std::string MStatus;
extern std::string UlStatus;
extern std::string PublicKey;
extern std::string PrivateKey;
extern std::string magic;
int KillSocket(uint64_t Dead);
void UUl(const std::string& R);
void UDPSend(std::string Data);

View File

@@ -21,12 +21,14 @@
#define beammp_fs_string std::wstring
#define beammp_fs_char wchar_t
#define beammp_wide(str) L##str
#define beammp_stdout std::wcout
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#define beammp_fs_string std::string
#define beammp_fs_char char
#define beammp_wide(str) str
#define beammp_stdout std::cout
#endif
namespace Utils {
@@ -120,13 +122,6 @@ namespace Utils {
if (line.empty() || line[0] == ';' || line[0] == '#')
continue;
for (auto& c : line) {
if (c == '#' || c == ';') {
line = line.substr(0, &c - &line[0]);
break;
}
}
auto invalidLineLog = [&]{
debug("Invalid INI line: " + line);
debug("Surrounding lines: \n" +

View File

@@ -122,10 +122,10 @@ std::filesystem::path GetGamePath() {
struct passwd* pw = getpwuid(getuid());
std::string homeDir = pw->pw_dir;
std::string Path = homeDir + "/.local/share/BeamNG.drive/";
std::string Path = homeDir + "/.local/share/BeamNG/BeamNG.drive/";
std::string Ver = CheckVer(GetGameDir());
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
Path += Ver + "/";
Path += "current/";
return Path;
}
#endif

View File

@@ -57,36 +57,36 @@ void addToLog(const std::wstring& Line) {
}
void info(const std::string& toPrint) {
std::string Print = getDate() + "[INFO] " + toPrint + "\n";
std::cout << Print;
beammp_stdout << Utils::ToWString(Print);
addToLog(Print);
}
void debug(const std::string& toPrint) {
std::string Print = getDate() + "[DEBUG] " + toPrint + "\n";
if (options.verbose) {
std::cout << Print;
beammp_stdout << Utils::ToWString(Print);
}
addToLog(Print);
}
void warn(const std::string& toPrint) {
std::string Print = getDate() + "[WARN] " + toPrint + "\n";
std::cout << Print;
beammp_stdout << Utils::ToWString(Print);
addToLog(Print);
}
void error(const std::string& toPrint) {
std::string Print = getDate() + "[ERROR] " + toPrint + "\n";
std::cout << Print;
beammp_stdout << Utils::ToWString(Print);
addToLog(Print);
}
void fatal(const std::string& toPrint) {
std::string Print = getDate() + "[FATAL] " + toPrint + "\n";
std::cout << Print;
beammp_stdout << Utils::ToWString(Print);
addToLog(Print);
std::this_thread::sleep_for(std::chrono::seconds(5));
std::exit(1);
}
void except(const std::string& toPrint) {
std::string Print = getDate() + "[EXCEP] " + toPrint + "\n";
std::cout << Print;
beammp_stdout << Utils::ToWString(Print);
addToLog(Print);
}

View File

@@ -33,6 +33,7 @@ bool GConnected = false;
bool CServer = true;
SOCKET CSocket = -1;
SOCKET GSocket = -1;
std::string magic;
int KillSocket(uint64_t Dead) {
if (Dead == (SOCKET)-1) {
@@ -218,6 +219,8 @@ void ParserAsync(std::string_view Data) {
MStatus = Data;
UlStatus = "Uldone";
return;
case 'U':
magic = Data.substr(1);
default:
break;
}

View File

@@ -93,6 +93,8 @@ 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);
if (!magic.empty())
UDPSend(magic);
GameSend("P" + std::to_string(ClientID));
TCPSend("H", TCPSock);
UDPSend("p");

View File

@@ -7,6 +7,7 @@
#include <filesystem>
#if defined(_WIN32)
#include <shlobj_core.h>
#elif defined(__linux__)
#include "vdf_parser.hpp"
#include <pwd.h>
@@ -162,24 +163,70 @@ void FileList(std::vector<std::string>& a, const std::string& Path) {
}
void LegitimacyCheck() {
#if defined(_WIN32)
std::wstring Result;
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
HKEY hKey;
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
if (dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 3);
if (Result.empty()) {
debug("Failed to QUERY key HKEY_CURRENT_USER\\Software\\BeamNG\\BeamNG.drive");
lowExit(3);
}
GameDir = Result;
} else {
debug("Failed to OPEN key HKEY_CURRENT_USER\\Software\\BeamNG\\BeamNG.drive");
lowExit(4);
wchar_t* appDataPath = new wchar_t[MAX_PATH];
HRESULT result = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath);
if (!SUCCEEDED(result)) {
fatal("Cannot get Local Appdata directory");
}
K3.clear();
Result.clear();
RegCloseKey(hKey);
auto BeamNGAppdataPath = std::filesystem::path(appDataPath) / "BeamNG";
if (const auto beamngIniPath = BeamNGAppdataPath / "BeamNG.Drive.ini"; exists(beamngIniPath)) {
if (std::ifstream beamngIni(beamngIniPath); beamngIni.is_open()) {
std::string contents((std::istreambuf_iterator(beamngIni)), std::istreambuf_iterator<char>());
beamngIni.close();
if (contents.size() >= 3 && (unsigned char)contents[0] == 0xEF && (unsigned char)contents[1] == 0xBB && (unsigned char)contents[2] == 0xBF) {
contents = contents.substr(3);
}
auto ini = Utils::ParseINI(contents);
if (ini.empty())
lowExit(3);
else
debug("Successfully parsed BeamNG.Drive.ini");
if (ini.contains("installPath")) {
std::wstring installPath = Utils::ToWString(std::get<std::string>(ini["installPath"]));
installPath.erase(0, installPath.find_first_not_of(L" \t"));
if (installPath = std::filesystem::path(Utils::ExpandEnvVars(installPath)); std::filesystem::exists(installPath)) {
GameDir = installPath;
debug(L"GameDir from BeamNG.Drive.ini: " + installPath);
} else {
lowExit(4);
}
} else {
lowExit(5);
}
}
} else {
std::wstring Result;
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
HKEY hKey;
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
if (dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 3);
if (Result.empty()) {
debug("Failed to QUERY key HKEY_CURRENT_USER\\Software\\BeamNG\\BeamNG.drive");
lowExit(6);
}
GameDir = Result;
debug(L"GameDir from registry: " + Result);
} else {
debug("Failed to OPEN key HKEY_CURRENT_USER\\Software\\BeamNG\\BeamNG.drive");
lowExit(7);
}
K3.clear();
Result.clear();
RegCloseKey(hKey);
}
delete[] appDataPath;
#elif defined(__linux__)
struct passwd* pw = getpwuid(getuid());
std::filesystem::path homeDir = pw->pw_dir;

View File

@@ -84,7 +84,7 @@ beammp_fs_string GetEN() {
}
std::string GetVer() {
return "2.6";
return "2.7";
}
std::string GetPatch() {
return ".0";
@@ -215,7 +215,7 @@ void CheckForUpdates(const std::string& CV) {
"https://backend.beammp.com/builds/launcher?download=true"
"&pk="
+ PublicKey + "&branch=" + Branch,
beammp_wide("new_") + BP, LatestHash);
GetBP() / (beammp_wide("new_") + GetEN()), LatestHash);
std::error_code ec;
fs::remove(Back, ec);
if (ec == std::errc::permission_denied) {
@@ -224,7 +224,7 @@ void CheckForUpdates(const std::string& CV) {
} else {
fs::rename(BP, Back);
}
fs::rename(beammp_wide("new_") + BP, BP);
fs::rename(GetBP() / (beammp_wide("new_") + GetEN()), BP);
URelaunch();
#endif
} else {
@@ -269,6 +269,8 @@ void LinuxPatch() {
void InitLauncher() {
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout), _O_U8TEXT);
debug("Launcher Version : " + GetVer() + GetPatch());
CheckName();
LinuxPatch();