-
Notifications
You must be signed in to change notification settings - Fork 66
Simple MacOS support #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Simple MacOS support #221
Changes from all commits
4b6522f
2debb1e
3610cff
020b213
6b7b5a1
832b2ae
249f30a
c3972f4
22edfca
76da518
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: CMake MacOS Build | ||
|
|
||
| on: [push, pull_request, workflow_dispatch] | ||
|
|
||
| env: | ||
| BUILD_TYPE: Release | ||
|
|
||
| jobs: | ||
| macos-build: | ||
| runs-on: macos-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| with: | ||
| submodules: 'true' | ||
|
|
||
| - name: Configure macOS SDK | ||
| run: | | ||
| echo "SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV | ||
| echo "MACOSX_DEPLOYMENT_TARGET=11.0" >> $GITHUB_ENV | ||
|
|
||
| - name: Restore artifacts, or run vcpkg, build and cache artifacts | ||
| uses: lukka/run-vcpkg@v7 | ||
| id: runvcpkg | ||
| with: | ||
| vcpkgArguments: 'zlib:arm64-osx nlohmann-json:arm64-osx openssl:arm64-osx cpp-httplib[openssl]:arm64-osx curl:arm64-osx' | ||
| vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg' | ||
| vcpkgGitCommitId: '40616a5e954f7be1077ef37db3fbddbd5dcd1ca6' | ||
|
|
||
| - name: Create Build Environment | ||
| run: cmake -E make_directory ${{github.workspace}}/build-macos | ||
|
|
||
| - name: Configure CMake | ||
| shell: bash | ||
| working-directory: ${{github.workspace}}/build-macos | ||
| run: | | ||
| cmake $GITHUB_WORKSPACE \ | ||
| -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ | ||
| -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake' \ | ||
| -DCMAKE_OSX_ARCHITECTURES=arm64 | ||
|
|
||
| - name: Build | ||
| working-directory: ${{github.workspace}}/build-macos | ||
| shell: bash | ||
| run: cmake --build . --config $BUILD_TYPE | ||
|
|
||
| - name: Archive artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: BeamMP-Launcher | ||
| path: ${{github.workspace}}/build-macos/BeamMP-Launcher |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
|
|
||
| #if defined(_WIN32) | ||
| #include <shlobj.h> | ||
| #elif defined(__linux__) | ||
| #elif defined(__linux__) || defined(__APPLE__) | ||
| #include "vdf_parser.hpp" | ||
| #include <pwd.h> | ||
| #include <spawn.h> | ||
|
|
@@ -128,6 +128,18 @@ std::filesystem::path GetGamePath() { | |
| Path += "current/"; | ||
| return Path; | ||
| } | ||
| #elif defined(__APPLE__) | ||
| std::filesystem::path GetGamePath() { | ||
| // Right now only steam is supported | ||
| struct passwd* pw = getpwuid(getuid()); | ||
| std::string homeDir = pw->pw_dir; | ||
|
|
||
| std::string Path = homeDir + "/Library/Application Support/BeamNG/BeamNG.drive/"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the user data folder always be in this location? |
||
| std::string Ver = CheckVer(GetGameDir()); | ||
| Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1)); | ||
| Path += "current/"; | ||
| return Path; | ||
| } | ||
| #endif | ||
|
|
||
| #if defined(_WIN32) | ||
|
|
@@ -204,9 +216,11 @@ void StartGame(std::string Dir) { | |
| } | ||
| #endif | ||
|
|
||
| #if !defined(__APPLE__) | ||
| void InitGame(const beammp_fs_string& Dir) { | ||
| if (!options.no_launch) { | ||
| std::thread Game(StartGame, Dir); | ||
| Game.detach(); | ||
| } | ||
| } | ||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| #include <filesystem> | ||
| #if defined(_WIN32) | ||
| #include <shlobj_core.h> | ||
| #elif defined(__linux__) | ||
| #elif defined(__linux__) || defined(__APPLE__) | ||
| #include "vdf_parser.hpp" | ||
| #include <pwd.h> | ||
| #include <unistd.h> | ||
|
|
@@ -18,6 +18,7 @@ | |
| #include "Utils.h" | ||
|
|
||
| #include <fstream> | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <thread> | ||
|
|
||
|
|
@@ -38,7 +39,7 @@ void lowExit(int code) { | |
| beammp_fs_string GetGameDir() { | ||
| #if defined(_WIN32) | ||
| return GameDir.substr(0, GameDir.find_last_of('\\')); | ||
| #elif defined(__linux__) | ||
| #elif defined(__linux__) || defined(__APPLE__) | ||
| return GameDir.substr(0, GameDir.find_last_of('/')); | ||
| #endif | ||
| } | ||
|
|
@@ -278,6 +279,38 @@ void LegitimacyCheck() { | |
| error("The game directory was not found."); | ||
| return; | ||
| } | ||
| #elif defined(__APPLE__) | ||
| // On macOS, ask the user to provide the game directory path | ||
| info("Please enter the path to your BeamNG.drive installation directory:"); | ||
| info("Example: /Users/YourName/Library/Application Support/Steam/steamapps/common/BeamNG.drive"); | ||
| std::cout << "Game directory path: "; | ||
|
|
||
| std::string userPath; | ||
| std::getline(std::cin, userPath); | ||
|
Comment on lines
+284
to
+289
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could command line arguments be used instead of this interface? |
||
|
|
||
| // Remove trailing slash if present | ||
| if (!userPath.empty() && (userPath.back() == '/' || userPath.back() == '\\')) { | ||
| userPath.pop_back(); | ||
| } | ||
|
Comment on lines
+291
to
+294
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could std::filesystem::path be used for this instead? |
||
|
|
||
| std::filesystem::path gamePath(userPath); | ||
|
|
||
| // Check if the path exists and contains integrity.json | ||
| if (!std::filesystem::exists(gamePath)) { | ||
| error("The specified path does not exist: " + userPath); | ||
| lowExit(8); | ||
| return; | ||
| } | ||
|
|
||
| std::filesystem::path integrityPath = gamePath / "integrity.json"; | ||
| if (!std::filesystem::exists(integrityPath)) { | ||
| error("The specified path does not appear to be a valid BeamNG.drive installation (integrity.json not found)."); | ||
| lowExit(9); | ||
| return; | ||
| } | ||
|
|
||
| GameDir = gamePath.string() + "/"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could std::filesystem::path be used here as well? |
||
| info("Game directory set to: " + GameDir); | ||
| #endif | ||
| } | ||
| std::string CheckVer(const std::filesystem::path& dir) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,7 +78,7 @@ Version::Version(const std::array<uint8_t, 3>& v) | |
| beammp_fs_string GetEN() { | ||
| #if defined(_WIN32) | ||
| return L"BeamMP-Launcher.exe"; | ||
| #elif defined(__linux__) | ||
| #elif defined(__linux__) || defined(__APPLE__) | ||
| return "BeamMP-Launcher"; | ||
| #endif | ||
| } | ||
|
|
@@ -150,7 +150,7 @@ void URelaunch() { | |
| std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
| exit(1); | ||
| } | ||
| #elif defined(__linux__) | ||
| #elif defined(__linux__) || defined(__APPLE__) | ||
| void ReLaunch() { | ||
| std::string Arg; | ||
| for (int c = 2; c <= options.argc; c++) { | ||
|
|
@@ -181,7 +181,7 @@ void URelaunch() { | |
| void CheckName() { | ||
| #if defined(_WIN32) | ||
| std::wstring DN = GetEN(), CDir = Utils::ToWString(options.executable_name), FN = CDir.substr(CDir.find_last_of('\\') + 1); | ||
| #elif defined(__linux__) | ||
| #elif defined(__linux__) || defined(__APPLE__) | ||
| std::string DN = GetEN(), CDir = options.executable_name, FN = CDir.substr(CDir.find_last_of('/') + 1); | ||
| #endif | ||
| if (FN != DN) { | ||
|
|
@@ -280,7 +280,7 @@ void InitLauncher() { | |
| CheckLocalKey(); | ||
| CheckForUpdates(std::string(GetVer()) + GetPatch()); | ||
| } | ||
| #elif defined(__linux__) | ||
| #elif defined(__linux__) || defined(__APPLE__) | ||
|
|
||
| void InitLauncher() { | ||
| info("BeamMP Launcher v" + GetVer() + GetPatch()); | ||
|
|
@@ -367,8 +367,8 @@ void PreGame(const beammp_fs_string& GamePath) { | |
| } | ||
| #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 | ||
| #elif defined(__linux__) || defined(__APPLE__) | ||
| // Linux and macOS versions of the game cant handle mods with uppercase names | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the mac version the windows version of the game running with a translations layer, making it able to handle uppercase names? |
||
| std::string ZipPath(GetGamePath() / R"(mods/multiplayer/beammp.zip)"); | ||
| #endif | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate on this comment?