Skip to content
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

MacOS ARM support <3 #147

Open
wants to merge 107 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
2946cef
Mac Build
enzofrnt Nov 7, 2024
ccde804
fix
enzofrnt Nov 7, 2024
c6eab33
fixes
enzofrnt Nov 7, 2024
f1f02b4
Update linuxfixes.h
enzofrnt Nov 7, 2024
d74da8f
Update linuxfixes.h
enzofrnt Nov 7, 2024
9de4fdc
Update Core.cpp
enzofrnt Nov 7, 2024
1c683c2
Update Core.cpp
enzofrnt Nov 7, 2024
6012257
Go back
enzofrnt Nov 7, 2024
584c02f
fix
enzofrnt Nov 7, 2024
7f1d147
fix
enzofrnt Nov 7, 2024
0975ac8
fix with linux fix
enzofrnt Nov 7, 2024
bec19a3
Update Core.cpp
enzofrnt Nov 7, 2024
86d59a2
Update DNS.cpp
enzofrnt Nov 7, 2024
368d249
fixes
enzofrnt Nov 7, 2024
15ac42e
Update Resources.cpp
enzofrnt Nov 7, 2024
bf8d258
Update VehicleData.cpp
enzofrnt Nov 7, 2024
c26d359
Update Options.h
enzofrnt Nov 7, 2024
45dee97
Update BeamNG.cpp
enzofrnt Nov 7, 2024
cde7a42
fixes
enzofrnt Nov 7, 2024
8039c44
Update GameStart.cpp
enzofrnt Nov 7, 2024
94bb736
force to arm64
enzofrnt Nov 7, 2024
2bca006
verify runnner arch
enzofrnt Nov 7, 2024
e674c16
force arm64
enzofrnt Nov 7, 2024
f28172e
force arm64
enzofrnt Nov 7, 2024
56f4e85
force arm64
enzofrnt Nov 7, 2024
4ae2291
fixes
enzofrnt Nov 7, 2024
822b24b
Merge branch 'ghcw-session-d22d' of https://github.com/enzofrnt/BeamM…
enzofrnt Nov 7, 2024
a6779ed
fix game path research on macos
enzofrnt Nov 8, 2024
fd3dcf7
working
enzofrnt Nov 8, 2024
46eeeb4
fix mac os build warn
enzofrnt Nov 8, 2024
c116cb2
ready
enzofrnt Nov 8, 2024
abc401f
fix windows build
enzofrnt Nov 8, 2024
5a825d0
fix windows build one method was only for mac
enzofrnt Nov 8, 2024
77bd789
MacOS ARM support <3
enzofrnt Nov 8, 2024
3434ece
We should stop the app if we don't find any beamng installation
enzofrnt Nov 11, 2024
1c16b31
We must need to be sure that the path we get is absolut to be able to…
enzofrnt Nov 13, 2024
f574798
Condition on include
enzofrnt Nov 13, 2024
57d2f09
moved toLower to Utils.h
enzofrnt Nov 13, 2024
a96014a
correct BoottlePath -> BottlePath
enzofrnt Nov 13, 2024
1afe74e
BootlePath -> BotlePath
enzofrnt Nov 13, 2024
131114f
no more edition on vdf_parser
enzofrnt Nov 13, 2024
3693b59
Update vdf_parser.hpp
enzofrnt Nov 13, 2024
a4a26fd
add nullptdr at the end of the args
enzofrnt Nov 13, 2024
06b697c
remove useless logs
enzofrnt Nov 13, 2024
7facffc
fix wrong log level
enzofrnt Nov 13, 2024
87ddb95
include algorithm anyway
enzofrnt Nov 13, 2024
bf24e53
GetBottleName using filesystem
enzofrnt Nov 13, 2024
c738795
fix environ
enzofrnt Nov 13, 2024
6ff5e1f
using existing vdf parser
enzofrnt Nov 13, 2024
649d46c
fix include linux fix for MacOS
enzofrnt Nov 13, 2024
4c23152
Update BeamNG.cpp
enzofrnt Nov 13, 2024
02ba91f
Update main.cpp
enzofrnt Nov 13, 2024
e5ec812
Revert "add nullptdr at the end of the args"
enzofrnt Nov 13, 2024
40e62aa
Update vdf_parser.hpp
enzofrnt Nov 13, 2024
99d3a79
Update vdf_parser.hpp
enzofrnt Nov 13, 2024
50b31ef
Improve MacOS support via CrossOver
JxxIT Nov 13, 2024
4d5f538
Forgot to include memory
JxxIT Nov 13, 2024
05eeb63
Exclude the windows and linux builds
JxxIT Nov 13, 2024
50d854d
Readd bottle scanning if the --bottle argument isn't set
JxxIT Nov 15, 2024
e901fcb
Improve the detection of the wine executable
JxxIT Nov 15, 2024
1a7a7ca
Remove the mdfind command
JxxIT Nov 15, 2024
4c230ea
Merge branch 'master' into improve-JxxIT
enzofrnt Nov 15, 2024
61982ed
Merge pull request #2 from JxxIT/master
enzofrnt Nov 15, 2024
4a0f350
Delete .DS_Store
enzofrnt Nov 15, 2024
9d533c1
Revert "Remove the mdfind command"
enzofrnt Nov 15, 2024
5eb3073
bottle option only needed on MacOS
enzofrnt Nov 15, 2024
7178d79
fix retrive wine executable
enzofrnt Nov 15, 2024
d5251ed
iostream not needed here
enzofrnt Nov 15, 2024
0db93a4
Only needed on 
enzofrnt Nov 15, 2024
bc1b97e
Update Resources.cpp
enzofrnt Nov 15, 2024
0b56d46
Merge pull request #3 from enzofrnt/improve-JxxIT
enzofrnt Nov 15, 2024
91b01be
Update BeamNG.cpp
enzofrnt Nov 15, 2024
47ebc7d
Update BeamNG.cpp
enzofrnt Nov 15, 2024
a4c47b2
Fix wine executable with non-default bottles folder
JxxIT Nov 16, 2024
a1bbcf5
Update BeamNG.cpp
enzofrnt Nov 19, 2024
0b685b6
contains
enzofrnt Nov 19, 2024
717ba0a
debug log
enzofrnt Nov 19, 2024
5e702e5
debug log
enzofrnt Nov 19, 2024
025a73f
debug bottle path
enzofrnt Nov 19, 2024
19ef8ad
debug bottles path
enzofrnt Nov 19, 2024
db584ec
try to fix __MINGW32__
enzofrnt Nov 19, 2024
1e9a7ca
Merge pull request #4 from JxxIT/master
enzofrnt Nov 19, 2024
a93cfa0
Improve code structure and adding bottle-path for non crossover users
enzofrnt Nov 21, 2024
a27961e
Update src/Options.cpp
enzofrnt Nov 26, 2024
172f353
Update src/Network/Core.cpp
enzofrnt Nov 27, 2024
8356bec
Update src/Network/Core.cpp
enzofrnt Nov 27, 2024
78608c1
Update src/Network/Core.cpp
enzofrnt Nov 27, 2024
4b738e2
french -> english
enzofrnt Nov 27, 2024
2de0a8e
Update BeamNG.cpp
enzofrnt Nov 27, 2024
7f9e7df
Update BeamNG.cpp
enzofrnt Nov 27, 2024
b5d3c10
Update BeamNG.cpp
enzofrnt Nov 27, 2024
6583af5
Update Options.cpp
enzofrnt Nov 27, 2024
999c64d
Update Options.cpp
enzofrnt Nov 27, 2024
ec52f2c
option + find game filesystem
enzofrnt Nov 27, 2024
60795db
Update BeamNG.cpp
enzofrnt Nov 27, 2024
bd18630
Update src/Options.cpp
enzofrnt Nov 27, 2024
059eb7c
better drive name
enzofrnt Nov 27, 2024
102ae74
Merge branch 'master' of https://github.com/enzofrnt/BeamMP-Launcher
enzofrnt Nov 27, 2024
6b6d86c
string to char
enzofrnt Nov 27, 2024
84dd5f3
Update BeamNG.cpp
enzofrnt Nov 27, 2024
3a7dc06
comment done
enzofrnt Nov 27, 2024
95e9a6a
Update BeamNG.cpp
enzofrnt Nov 27, 2024
6ebe19a
Update BeamNG.cpp
enzofrnt Nov 27, 2024
40da2bb
Update src/Security/BeamNG.cpp
enzofrnt Dec 1, 2024
6f5d927
ToLower only on letter
enzofrnt Dec 1, 2024
cf7a193
Merge branch 'master' of https://github.com/enzofrnt/BeamMP-Launcher
enzofrnt Dec 1, 2024
43eabf1
fix
enzofrnt Dec 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/cmake-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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: 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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ bin/
compile_commands.json
key
out/
build/
.vscode/
vcpkg/
vcpkg_installed/
CMakeFiles/
cmake_install.cmake
CMakeCache.txt
Makefile
BeamMP-Launcher
.DS_Store
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if (WIN32)
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
elseif(APPLE)
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Build architectures for MacOS" FORCE)
endif(WIN32)

set(CMAKE_CXX_STANDARD 20)
Expand All @@ -32,6 +34,11 @@ elseif (LINUX)
find_package(OpenSSL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto CURL::libcurl)
elseif(APPLE)
find_package(ZLIB REQUIRED)
find_package(OpenSSL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto CURL::libcurl)
else(WIN32) #MINGW
add_definitions("-D_WIN32_WINNT=0x0600")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
Expand Down
4 changes: 4 additions & 0 deletions include/Network/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <sys/ucontext.h>
#endif

#ifdef __APPLE__
#include "linuxfixes.h"
#endif

void NetReset();
extern bool Dev;
extern int ping;
Expand Down
6 changes: 5 additions & 1 deletion include/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
struct Options {
#if defined(_WIN32)
std::string executable_name = "BeamMP-Launcher.exe";
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
std::string executable_name = "BeamMP-Launcher";
#endif
unsigned int port = 4444;
Expand All @@ -15,6 +15,10 @@ struct Options {
bool no_launch = false;
const char **game_arguments = nullptr;
int game_arguments_length = 0;
#if defined(__APPLE__)
std::string bottle;
std::string bottle_path;
#endif
const char** argv = nullptr;
int argc = 0;
};
Expand Down
4 changes: 4 additions & 0 deletions include/Security/Init.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ void PreGame(const std::string& GamePath);
std::string CheckVer(const std::string& path);
void InitGame(const std::string& Dir);
std::string GetGameDir();
#if defined(__APPLE__)
std::string GetBottlePath();
std::string GetBottleName();
#endif
void LegitimacyCheck();
void CheckLocalKey();
27 changes: 25 additions & 2 deletions include/Utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <vector>
#include <algorithm>

namespace Utils {
inline std::vector<std::string> Split(const std::string& String, const std::string& delimiter) {
Expand All @@ -16,5 +17,27 @@ namespace Utils {
if (!s.empty())
Val.push_back(s);
return Val;
};
};
}

inline std::string ToLower(const std::string& str) {
std::string lowerStr = str;
std::transform(str.begin(), str.end(), lowerStr.begin(), ::tolower);
return lowerStr;
}

#if defined(__APPLE__)
inline std::pair<std::string, int> runCommand(const char* cmd) {
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) {
throw std::runtime_error("failed to run popen()");
}
while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe.get()) != nullptr) {
result += buffer.data();
}
int returnCode = pclose(pipe.release());
return { result, returnCode };
}
#endif
}
80 changes: 79 additions & 1 deletion src/GameStart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#if defined(_WIN32)
#include <windows.h>
#include <shlobj.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
#include "vdf_parser.hpp"
#include <pwd.h>
#include <spawn.h>
Expand All @@ -24,6 +24,7 @@
#include <filesystem>
#include <thread>
#include "Options.h"
#include "Utils.h"

unsigned long GamePID = 0;
#if defined(_WIN32)
Expand Down Expand Up @@ -73,6 +74,15 @@ std::string GetGamePath() {
Path += Ver + "/";
return Path;
}
#elif defined(__APPLE__)
std::string GetGamePath() {
std::string BottlePath = GetBottlePath();
std::string Path = BottlePath + "/drive_c/users/crossover/AppData/Local/BeamNG.drive/";
std::string Ver = CheckVer(GetGameDir());
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
Path += Ver + "/";
return Path;
}
#endif

#if defined(_WIN32)
Expand Down Expand Up @@ -132,6 +142,74 @@ void StartGame(std::string Dir) {
std::this_thread::sleep_for(std::chrono::seconds(5));
exit(2);
}

#elif defined(__APPLE__)
void StartGame(std::string Dir) {
extern char **environ;
int status;

std::string executable = Dir + "/Bin64/BeamNG.drive.x64.exe";
if (!std::filesystem::exists(executable)) {
error("The executable BeamNG.drive.x64.exe doesn't exist in folder: " + Dir + "/Bin64/");
exit(1);
}
std::pair<std::string, int> sharedCmd = Utils::runCommand("mdfind kMDItemCFBundleIdentifier = 'com.codeweavers.CrossOver'");
std::string sharedPath = sharedCmd.first;
int statusCode = sharedCmd.second;
if (statusCode != 0) {
error("Failed to detect SharedSupport folder, please make sure CrossOver is installed.");
exit(1);
} else {
std::istringstream stream(sharedPath);
std::string line;
std::vector<std::string> paths;
while (std::getline(stream, line)) {
if (line.find("CrossOver.app") != std::string::npos) {
paths.push_back(line);
}
}
if (paths.empty()) {
error("No valid CrossOver.app found.");
exit(1);
} else if (paths.size() > 1) {
debug("Multiple CrossOver.app found, using the first one.");
}
sharedPath = paths[0];
sharedPath += "/";
}

std::string wineExecutable = sharedPath + "Contents/SharedSupport/CrossOver/bin/wine";
std::string bottlePath = GetBottlePath();
std::vector<const char*> argv;
argv.push_back(wineExecutable.c_str());
argv.push_back("--bottle");
argv.push_back(bottlePath.c_str());
argv.push_back(executable.c_str());
enzofrnt marked this conversation as resolved.
Show resolved Hide resolved

for (int i = 0; i < options.game_arguments_length; i++) {
argv.push_back(options.game_arguments[i]);
}
argv.push_back(nullptr);

pid_t pid;
posix_spawn_file_actions_t spawn_actions;
posix_spawn_file_actions_init(&spawn_actions);
posix_spawn_file_actions_addclose(&spawn_actions, STDOUT_FILENO);
posix_spawn_file_actions_addclose(&spawn_actions, STDERR_FILENO);

int result = posix_spawn(&pid, wineExecutable.c_str(), &spawn_actions, nullptr, const_cast<char**>(argv.data()), environ);

if (result != 0) {
error("Failed to Launch the game! launcher closing soon");
return;
} else {
waitpid(pid, &status, 0);
info("Game Closed! launcher closing soon");
}

std::this_thread::sleep_for(std::chrono::seconds(5));
exit(2);
}
#endif

void InitGame(const std::string& Dir) {
Expand Down
24 changes: 11 additions & 13 deletions src/Network/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#if defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
#include <cstring>
#include <errno.h>
#include <netdb.h>
Expand Down Expand Up @@ -372,21 +372,19 @@ int Handle(EXCEPTION_POINTERS* ep) {

[[noreturn]] void CoreNetwork() {
while (true) {
#if not defined(__MINGW32__)
#if defined(_WIN32)
__try {
#endif

CoreMain();

#if not defined(__MINGW32__) and not defined(__linux__)
} __except (Handle(GetExceptionInformation())) { }
#elif not defined(__MINGW32__) and defined(__linux__)
}
catch (...) {
except("(Core) Code : " + std::string(strerror(errno)));
}
#else
try {
CoreMain();
} catch (const std::exception& e) {
error("(Core) Exception: " + std::string(e.what()));
} catch (...) {
error("(Core) Unknown exception");
}
#endif

std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
}
2 changes: 1 addition & 1 deletion src/Network/DNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#if defined(_WIN32)
#include <winsock2.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
#include "linuxfixes.h"
#include <arpa/inet.h>
#include <netdb.h>
Expand Down
2 changes: 1 addition & 1 deletion src/Network/GlobalHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#if defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
#include "linuxfixes.h"
#include <arpa/inet.h>
#include <cstring>
Expand Down
3 changes: 1 addition & 2 deletions src/Network/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if defined(_WIN32)
#include <ws2tcpip.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
#include <arpa/inet.h>
#include <cstring>
#include <errno.h>
Expand All @@ -35,7 +35,6 @@
#include <filesystem>
#include <fstream>
#include <future>
#include <iostream>
#include <thread>

#include "hashpp.h"
Expand Down
4 changes: 2 additions & 2 deletions src/Network/VehicleData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#if defined(_WIN32)
#include <ws2tcpip.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
#include "linuxfixes.h"
#include <arpa/inet.h>
#include <cstring>
Expand Down Expand Up @@ -66,7 +66,7 @@ void UDPRcv() {
sockaddr_in FromServer {};
#if defined(_WIN32)
int clientLength = sizeof(FromServer);
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
socklen_t clientLength = sizeof(FromServer);
#endif
ZeroMemory(&FromServer, clientLength);
Expand Down
2 changes: 1 addition & 1 deletion src/Network/VehicleEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#if defined(_WIN32)
#include <ws2tcpip.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__APPLE__)
#include <arpa/inet.h>
#include <cstring>
#include <errno.h>
Expand Down
Loading