Compare commits

..

124 Commits

Author SHA1 Message Date
Starystars67 7217cb1cab Update Startup.cpp 2023-12-16 03:01:28 +00:00
Anonymous275 c2f260a86c v2.0.84
- remove comment
2023-12-15 19:39:55 +00:00
Anonymous275 2781179b4b v2.0.84
- proxy tweaking
2023-12-15 19:38:47 +00:00
Anonymous275 3b479abf64 v2.0.84
- add hash check
- new routes for updates
- use C++ 20
2023-12-15 18:16:12 +00:00
Anonymous275 c731718f50 v2.0.84
- HTTP Proxy for backend.beammp.com
- Fix Attempt for mod loading, game detecting partial zip file
- Use nlohmann JSON
- Update vcpkg parameters and commit ID
- Add ability to open URL using default browser with filter
2023-12-15 17:38:47 +00:00
Anonymous-275 0fd0a9fe7e Merge remote-tracking branch 'origin/master' 2023-10-26 00:09:04 +01:00
Anonymous-275 302582bfe1 v2.0.83
- removed code that is no longer needed
2023-10-26 00:08:56 +01:00
Anonymous275 839bb48cd6 Merge pull request #58 from WhiteHusky/patch-1
Emit a useful message if cleaning the mods folder fails
2023-08-04 20:30:36 +01:00
Carlen White c4ebdda1a4 Emit a useful message if cleaning the mods folder fails
The launcher complains if it can not delete a file when it's trying to clean the mods folder out. However the message it emits is unhelpful and does not offer a suggestion to what is going on.

This commit addresses this issue by telling the user what the launcher is trying to do and suggests checking if something is currently open in that directory. I figure not having to go into detail in *where* the folder is not necessary and (primarily) only happens if the user is inspecting the folder themselves and already knows where the folder is.
2023-07-02 23:02:14 -04:00
Anonymous275 d6b494c6c4 - release v2.0.82 2022-12-18 14:30:21 +00:00
Anonymous275 a80d4f5147 - quick fix for launcher crash 2022-12-18 14:29:38 +00:00
Anonymous275 811b04485c - try fix for github workflow 2022-12-18 13:20:20 +00:00
Simon Abed El Sater a64fead653 update 2.0.81 2022-12-18 14:39:54 +02:00
Simon Abed El Sater 399461d1b1 remove version check 2022-12-18 14:39:28 +02:00
Anonymous275 ec5e8ed5b3 v2.0.80 2022-09-25 20:39:27 +03:00
Anonymous275 5655164e60 bump 2.0.80 2022-09-25 20:37:46 +03:00
Simon Abed El Sater 3d9b7c2d67 Merge pull request #49 from snepsnepsnep/master
Fix kick message for server 3.0+
2022-09-25 20:32:50 +03:00
snepsnepsnep 764e3ab5c1 Fix kick message for server 3.0+ 2022-09-25 19:26:46 +02:00
Simon Abed El Sater 3314362faf Merge pull request #48 from Mack29446/master
Decided by vote: Update BeamNG Version and remove Mod Delete warning & Delay
2022-09-25 01:18:58 +03:00
Mackenzie e483f520db Bump launcher version
2.0.78 -> 2.0.79
2022-09-24 22:49:10 +01:00
Mackenzie c92e32c0e1 Remove mod wipe warn and delay 2022-09-24 22:48:17 +01:00
Mackenzie cb872f8a41 Update BeamNG Version 2022-09-24 22:46:38 +01:00
Anonymous275 0aae245054 release 2.0.78 2022-09-24 00:37:29 +03:00
Anonymous275 480a7d038f follow redirects if present 2022-09-24 00:37:04 +03:00
Anonymous275 f62f44d4c0 version 2.0.77 2022-09-20 22:27:26 +03:00
Anonymous275 e316b89fb1 bump 0.26 2022-09-20 22:26:51 +03:00
Anonymous275 3b2dbcac1b release 2.0.76 2022-09-05 03:23:15 +03:00
Anonymous275 d881c9faf6 release 2.0.75 2022-09-05 02:59:05 +03:00
Anonymous275 11d9375f36 fix invalid Key being used 2022-09-05 02:58:22 +03:00
Simon Abed El Sater 4207d7adcf Merge pull request #44 from snepsnepsnep/master
remove key if auth is unsuccessful
2022-09-05 02:40:50 +03:00
snepsnepsnep 832b1d66a0 remove key if auth is unsuccessful 2022-09-04 20:24:27 +02:00
Anonymous275 cd829f9f22 Update Startup.cpp
version 2.0.74
2022-08-12 12:14:31 +03:00
Anonymous275 f7c70eb6df Merge pull request #36 from Mack29446/master
Change serverlist request URL and Protocol
2022-08-12 12:11:22 +03:00
Mackenzie 01960f6470 Change serverlist request URL and Protocol 2022-08-11 20:27:26 +01:00
Anonymous275 f6065a1c00 Merge pull request #21 from Mack29446/master
Update version
2022-06-24 19:46:26 +03:00
Mackenzie ba3b7f0ed0 Update version 2022-06-23 16:53:06 +01:00
Anonymous275 056eadbef2 Merge pull request #20 from Mack29446/master
Update version
2022-06-21 18:12:49 +03:00
Mackenzie 2bb2dc9040 Update version 2022-06-21 14:28:10 +01:00
Anonymous275 17553fd412 bump launcher version 2022-06-19 02:28:26 +03:00
Anonymous275 08c1c0f682 Merge pull request #19 from Mack29446/master
Update Version Number
2022-06-18 02:02:36 +03:00
Mackenzie 84959ae9c9 Update Version Number 2022-06-17 21:35:00 +01:00
Anonymous275 c90c102097 trying to fix github actions 2022-06-15 21:38:45 +03:00
Anonymous275 5b004426ce vcpkgGitCommitId update 2022-06-15 21:35:12 +03:00
Anonymous275 69c9060dd2 Update release-build.yml 2022-06-15 21:13:02 +03:00
Anonymous275 49870639ff Update cmake-windows.yml 2022-06-15 21:12:41 +03:00
Anonymous275 0843862af9 update for game version 0.25 2022-06-15 21:02:43 +03:00
Anonymous275 71a9a567bc 2.0.63 2021-12-03 18:45:36 +02:00
Anonymous275 a6e3d0fad9 Update cmake-windows.yml 2021-12-03 18:28:03 +02:00
Anonymous275 411d0786a5 0.24.0.1 game version bump 2021-12-03 18:18:57 +02:00
Anonymous-275 acb6b11e24 bump minor version to 62 2021-10-01 00:17:55 +03:00
Anonymous-275 1739393a73 launcher no longer extracts zip file 2021-10-01 00:11:46 +03:00
Anonymous-275 298ef33ab7 V2.0.61 2021-07-03 17:11:56 +03:00
Anonymous-275 d2433cceca V2.0.7 2021-07-03 17:10:55 +03:00
Anonymous-275 705e0ab9c4 Updated version to 0.23.1 2021-07-03 17:09:29 +03:00
Anonymous-275 53c40a2bc3 Removed debug prints 2021-07-01 18:54:36 +03:00
Anonymous-275 96c60ef05a 0.23.0.0 support 2021-07-01 18:54:06 +03:00
Anonymous-275 61759b8531 0.23.0.0 support 2021-07-01 18:53:50 +03:00
Anonymous-275 691be8cd08 Mod validity check 2021-06-02 00:02:50 +03:00
Anonymous-275 082445c295 updated gitignore 2021-05-23 20:04:34 +03:00
Anonymous-275 f4bda81be0 Added 'N' packet flag 2021-05-23 19:22:44 +03:00
Anonymous-275 1ad8e0b8e5 Minor edit 2021-05-11 22:32:46 +03:00
Anonymous-275 6c673e78e5 Fixed invalid string position, Bumped game version 2021-05-11 22:19:42 +03:00
Anonymous-275 09abe75fbb Fixed false detection of proton 2021-04-15 21:05:30 +03:00
Anonymous-275 b45e4b40f2 Auto proton patch, fix for 0.22.2.0 2021-04-15 18:22:54 +03:00
Anonymous-275 15d1539a92 v2.0.2 2021-04-04 23:42:29 +03:00
Anonymous-275 14a5f47549 Merge branch 'master' of ssh://github.com/BeamMP/BeamMP-Launcher 2021-04-04 23:41:23 +03:00
Anonymous-275 584998277d v2.0.2 2021-04-04 23:40:57 +03:00
Anonymous275 fb59b6997c Create release-build.yml 2021-04-04 23:37:32 +03:00
Anonymous275 a1f5ec9ba5 Update cmake-windows.yml 2021-04-04 23:23:11 +03:00
Anonymous-275 989ac981be Merge branch 'master' of ssh://github.com/BeamMP/BeamMP-Launcher 2021-04-04 23:22:02 +03:00
Anonymous-275 d425b8035a Update CMakeLists.txt 2021-04-04 23:22:00 +03:00
Anonymous275 f0540c2df5 Update cmake-windows.yml 2021-04-04 23:08:07 +03:00
Anonymous275 9df08025ad Create cmake-windows.yml 2021-04-04 23:02:40 +03:00
Anonymous-275 bb732f102f v2.0.2 2021-04-04 22:49:52 +03:00
Anonymous-275 ec3bcffe7c New header only http library 2021-04-04 19:20:25 +03:00
Anonymous-275 e70cf0f877 Fixed launcher crash in wine! 2021-04-02 03:52:31 +03:00
Anonymous-275 b40ab5e36a V2.0.1 2021-03-31 23:18:09 +03:00
Anonymous-275 54a27f5c4c Bump to 0.22.1.0 2021-03-31 22:57:05 +03:00
Anonymous-275 37cfec9fdc Added chat to reliable 2021-03-30 23:31:11 +03:00
Anonymous-275 16f0769f87 fixed new custom profile directory 2021-03-30 03:07:49 +03:00
Starystars67 9f1e58bb70 Launcher v2 updated strings 2021-03-29 22:15:50 +01:00
Anonymous-275 83b43d782d Small tweak 2021-03-30 00:03:43 +03:00
Anonymous-275 3a0b96da52 Client mod download system update 2021-03-30 00:01:20 +03:00
Anonymous-275 aa2b07b359 Updated Supported version 2021-03-29 23:34:49 +03:00
Anonymous-275 289402a9ba Switched to new default userdata 2021-03-29 23:29:03 +03:00
Anonymous-275 1afa81e420 updated submodule 2021-03-29 21:45:32 +03:00
Starystars67 ae6725ece3 Possible fix for new backend linix ~Anonymous275 2021-03-29 19:00:23 +01:00
Anonymous-275 fff747afca Replaced cURL with evpp 2021-03-29 16:43:17 +03:00
Anonymous-275 5c1b7b1dbf updated submodule 2021-03-29 16:13:00 +03:00
Anonymous-275 e290910312 updated submodule 2021-03-29 12:44:48 +03:00
Anonymous-275 fb7831d629 Added evpp with git link 2021-03-29 11:57:58 +03:00
Anonymous-275 5b4b930701 Removed broken module link 2021-03-29 11:52:03 +03:00
Anonymous-275 fe59083257 Added evpp 2021-03-29 11:47:49 +03:00
Anonymous-275 fbc5e28d25 Mingw Compatible 2021-03-29 11:43:24 +03:00
Anonymous275 d96f968dde Cleanup 2021-02-22 23:00:54 +02:00
Anonymous275 ba5ba4b8b4 Partial fix for directory startup location 2021-02-22 20:09:36 +02:00
Anonymous275 263b6c9c0d Potential auth fix 2021-01-07 15:28:51 +02:00
Anonymous275 78875c2c9c Fixed single player, fixed duplicated multiplayer mods 2021-01-02 20:58:23 +02:00
Anonymous275 8e55edaa29 1.80.92, fixed some startup crashes 2021-01-02 02:02:50 +02:00
Anonymous275 c77f8742b4 Update BeamNG.cpp 2021-01-01 16:40:37 +02:00
Anonymous275 0a58001b09 Update BeamNG.cpp 2021-01-01 16:39:31 +02:00
Anonymous275 075d4a8c4d 1.80.91 2021-01-01 16:36:44 +02:00
Anonymous275 00313e32f9 Merge pull request #3 from finicu212/patch-1
Close #2: Alert user of what malicious file has been found
2021-01-01 16:34:45 +02:00
Anonymous275 16ea84b4cf Merge branch 'master' into patch-1 2021-01-01 16:34:27 +02:00
Anonymous275 6b124e89a8 Update BeamNG.cpp 2020-12-28 18:07:04 +02:00
Anonymous275 543183b852 launcher is now more linux friendly 2020-12-28 18:05:32 +02:00
Anonymous275 fda7567044 fixed crash -report 2020-12-28 16:34:24 +02:00
Anonymous275 6b4211d9cf bump to 1.80.8 2020-12-27 23:34:19 +02:00
Anonymous275 3572a188d1 added try catch 2020-12-27 23:21:41 +02:00
Anonymous275 775e44a68f fixed crash when starting up 2020-12-27 23:19:24 +02:00
Anonymous275 eaa8796c02 final hotfix 2020-12-27 06:34:11 +02:00
Anonymous275 2a03448b3f Fix for custom document location 2020-12-27 06:31:03 +02:00
Anonymous275 9734a7f3d5 Hotfix 2020-12-27 05:50:51 +02:00
Anonymous275 e207f2febd Potential default dir fix 2020-12-27 05:14:02 +02:00
Anonymous275 9f821a01f0 Mod downloading hotfix 2020-12-27 00:23:58 +02:00
Anonymous275 9a04665c34 Unicode path support 2020-12-26 23:35:43 +02:00
Anonymous275 ab2a58bf42 switched to normal filesystem + crash fixes 2020-12-26 22:52:01 +02:00
finicu 32bcbac979 Alert user of what malicious file has been found 2020-12-26 13:34:09 +02:00
Anonymous275 757ac6303b Update README.md 2020-12-23 21:03:05 +02:00
Anonymous275 20ba2b9e0a Update README.md 2020-12-23 20:47:23 +02:00
Anonymous275 99006627a4 Update README.md 2020-12-23 20:46:17 +02:00
Anonymous275 7cd25fbb22 fixed mod downloading stuck at 50% 2020-12-22 19:38:01 +02:00
Anonymous275 76a1b05056 Update Login.cpp 2020-12-22 17:19:02 +02:00
Anonymous275 b7ffa153b1 Added more error returns on auth fail 2020-12-22 17:12:38 +02:00
73 changed files with 11641 additions and 853 deletions
+43
View File
@@ -0,0 +1,43 @@
name: CMake Windows Build
on: [push, pull_request]
env:
BUILD_TYPE: Release
jobs:
windows-build:
runs-on: windows-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: 'discord-rpc zlib nlohmann-json openssl cpp-httplib[openssl]'
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
vcpkgGitCommitId: '16ee2ecb31788c336ace8bb14c21801efb6836e4'
vcpkgTriplet: 'x64-windows-static'
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build-windows
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build-windows
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake' -DVCPKG_TARGET_TRIPLET=x64-windows-static
- name: Build
working-directory: ${{github.workspace}}/build-windows
shell: bash
run: cmake --build . --config $BUILD_TYPE
- name: Archive artifacts
uses: actions/upload-artifact@v2
with:
name: BeamMP-Launcher.exe
path: ${{github.workspace}}/build-windows/Release/BeamMP-Launcher.exe
+72
View File
@@ -0,0 +1,72 @@
name: Release Create & Build
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
env:
BUILD_TYPE: Release
jobs:
create-release:
runs-on: ubuntu-latest
name: Create Release
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
body: |
Files included in this release:
- `BeamMP-Launcher.exe` windows build
upload-release-files-windows:
name: Upload Windows Release Files
runs-on: windows-latest
needs: create-release
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Restore artifacts, or run vcpkg, build and cache artifacts
uses: lukka/run-vcpkg@main
id: runvcpkg
with:
vcpkgArguments: 'discord-rpc zlib nlohmann-json openssl cpp-httplib[openssl]'
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
vcpkgGitCommitId: '16ee2ecb31788c336ace8bb14c21801efb6836e4'
vcpkgTriplet: 'x64-windows-static'
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build-windows
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build-windows
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake' -DVCPKG_TARGET_TRIPLET=x64-windows-static
- name: Build
working-directory: ${{github.workspace}}/build-windows
shell: bash
run: cmake --build . --config $BUILD_TYPE
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ${{github.workspace}}/build-windows/Release/BeamMP-Launcher.exe
asset_name: BeamMP-Launcher.exe
asset_content_type: application/vnd.microsoft.portable-executable
+5 -11
View File
@@ -1,13 +1,7 @@
cmake-build-debug/CMakeFiles/
cmake-build-release/CMakeFiles/
cmake-build-debug/BeamNG/
cmake-build-release/BeamNG/
cmake-build-debug/Resources/
cmake-build-release/Resources/
cmake-build-debug/*.*
cmake-build-release/*.*
cmake-build-debug/Makefile
cmake-build-release/Makefile
cmake-build-debug
cmake-build-release
/.idea/
*.log
cmake-build-release/key
/*.sh
/*.obj
/*.exe
+3
View File
@@ -0,0 +1,3 @@
[submodule "evpp"]
path = evpp
url = https://github.com/BeamMP/evpp.git
+34 -4
View File
@@ -1,12 +1,42 @@
cmake_minimum_required(VERSION 3.10)
project(Launcher)
set(CMAKE_CXX_STANDARD 17)
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})
endif(WIN32)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h")
find_package(httplib CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
add_executable(${PROJECT_NAME} ${source_files})
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "BeamMP-Launcher")
if (WIN32)
find_package(ZLIB REQUIRED)
find_package(CURL CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32 rstrtmgr discord-rpc CURL::libcurl ZLIB::ZLIB)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
find_package(OpenSSL REQUIRED)
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
include_directories(${VcpkgRoot}/include)
link_directories(${VcpkgRoot}/lib)
target_link_libraries(${PROJECT_NAME} PRIVATE
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32 httplib::httplib nlohmann_json::nlohmann_json)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/lib/discord-rpc.lib)
else ()
target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/debug/lib/discord-rpc.lib)
endif()
else(WIN32) #MINGW
add_definitions("-D_WIN32_WINNT=0x0600")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
target_link_libraries(${PROJECT_NAME} discord-rpc ssl crypto ws2_32 ssp crypt32 z)
endif(WIN32)
target_include_directories(${PROJECT_NAME} PRIVATE "include")
Regular → Executable
+9
View File
@@ -1 +1,10 @@
# BeamMP-Launcher
The launcher is the way we communitcate to outside the game, it does a few automated actions such as but not limited to: downloading the mod, launching the game, and create a connection to a server.
Copyright (c) 2019-present Anonymous275.
BeamMP Launcher code is not in the public domain and is not free software.
One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries,
the only permission that has been granted is to use the software in its compiled form as distributed from the BeamMP.com website.
Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
Submodule
+1
Submodule evpp added at 44e10774e2
Regular → Executable
View File
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once
#include <stdint.h>
#include <cstdint>
// clang-format off
+10 -3
View File
@@ -7,6 +7,13 @@
///
#pragma once
#include <string>
int Download(const std::string& URL,const std::string& Path,bool close);
std::string PostHTTP(const std::string& IP, const std::string& Fields);
std::string HTTP_REQUEST(const std::string& IP,int port);
#include "Logger.h"
class HTTP {
public:
static bool Download(const std::string &IP, const std::string &Path);
static std::string Post(const std::string& IP, const std::string& Fields);
static std::string Get(const std::string &IP);
static bool ProgressBar(size_t c, size_t t);
public:
static bool isDownload;
};
-12
View File
@@ -1,12 +0,0 @@
// Copyright (c) 2019-present Anonymous275.
// BeamMP Launcher code is not in the public domain and is not free software.
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
///
/// Created by Anonymous275 on 11/27/2020
///
#pragma once
#include "rapidjson/stringbuffer.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
namespace json = rapidjson;
Regular → Executable
View File
Regular → Executable
+7 -1
View File
@@ -5,12 +5,16 @@
///
/// Created by Anonymous275 on 7/18/2020
///
#pragma once
#include <string>
void NetReset();
extern bool Dev;
extern int ping;
void CoreNetwork();
[[noreturn]] void CoreNetwork();
extern int ProxyPort;
extern int ClientID;
extern int LastPort;
extern bool ModLoaded;
@@ -18,11 +22,13 @@ extern bool Terminate;
extern int DEFAULT_PORT;
extern uint64_t UDPSock;
extern uint64_t TCPSock;
extern std::string Branch;
extern bool TCPTerminate;
extern std::string LastIP;
extern std::string MStatus;
extern std::string UlStatus;
extern std::string PublicKey;
extern std::string PrivateKey;
extern std::string ListOfMods;
int KillSocket(uint64_t Dead);
void UUl(const std::string& R);
Regular → Executable
View File
Regular → Executable
+1 -1
View File
@@ -7,7 +7,7 @@
///
#pragma once
#include <string>
void PreGame(int argc, char* argv[],const std::string& GamePath);
void PreGame(const std::string& GamePath);
std::string CheckVer(const std::string &path);
void InitGame(const std::string& Dir);
std::string GetGameDir();
Regular → Executable
+14 -1
View File
@@ -7,9 +7,22 @@
///
#pragma once
#include <string>
#include <compare>
#include <vector>
void InitLauncher(int argc, char* argv[]);
void CheckDir(int argc,char* args[]);
std::string GetEP(char*P = nullptr);
std::string GetGamePath();
std::string GetVer();
std::string GetEN();
void StartProxy();
void ConfigInit();
extern bool Dev;
struct VersionParser {
explicit VersionParser(const std::string& from_string);
std::strong_ordering operator<=>(VersionParser const& rhs) const noexcept;
bool operator==(VersionParser const& rhs) const noexcept;
std::vector<std::string> split;
std::vector<size_t> data;
};
Regular → Executable
View File
+4642
View File
File diff suppressed because it is too large Load Diff
Regular → Executable
View File
View File
Regular → Executable
View File
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
View File
View File
Regular → Executable
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
Regular → Executable
View File
Regular → Executable
View File
View File
View File
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
+24
View File
@@ -0,0 +1,24 @@
#pragma once
namespace {
struct OnApp {
OnApp() {
#ifdef WIN32
// Initialize Winsock 2.2
WSADATA wsaData;
int err = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (err) {
std::cout << "WSAStartup() failed with error: %d" << err;
}
#endif
}
~OnApp() {
#ifdef WIN32
WSACleanup();
#endif
}
} __s_onexit_pause;
}
+5710
View File
File diff suppressed because it is too large Load Diff
Regular → Executable
View File
Executable
+58
View File
@@ -0,0 +1,58 @@
///
/// Created by Anonymous275 on 2/23/2021
///
#include <nlohmann/json.hpp>
#include "Network/network.h"
#include <filesystem>
#include "Logger.h"
#include <fstream>
#include <cstdint>
namespace fs = std::filesystem;
std::string Branch;
void ParseConfig(const nlohmann::json& d){
if(d["Port"].is_number()){
DEFAULT_PORT = d["Port"].get<int>();
}
//Default -1
//Release 1
//EA 2
//Dev 3
//Custom 3
if(d["Build"].is_string()){
Branch = d["Build"].get<std::string>();
for(char& c : Branch)c = char(tolower(c));
}
}
void ConfigInit(){
if(fs::exists("Launcher.cfg")){
std::ifstream cfg("Launcher.cfg");
if(cfg.is_open()){
auto Size = fs::file_size("Launcher.cfg");
std::string Buffer(Size, 0);
cfg.read(&Buffer[0], Size);
cfg.close();
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
if(d.is_discarded()){
fatal("Config failed to parse make sure it's valid JSON!");
}
ParseConfig(d);
}else fatal("Failed to open Launcher.cfg!");
}else{
std::ofstream cfg("Launcher.cfg");
if(cfg.is_open()){
cfg <<
R"({
"Port": 4444,
"Build": "Default"
})";
cfg.close();
}else{
fatal("Failed to write config on disk!");
}
}
}
Regular → Executable
+3 -3
View File
@@ -7,7 +7,7 @@
///
#include "Discord/discord_rpc.h"
#include "Logger.h"
#include <iostream>
#include <cstring>
#include <thread>
#include <ctime>
@@ -99,8 +99,8 @@ void ErrorAboard(){
exit(6);
}
void Discord_Main(){
std::thread t1(DMain);
t1.detach();
/*std::thread t1(DMain);
t1.detach();*/
/*info("Connecting to discord client...");
int C = 0;
while(DiscordInfo == nullptr && C < 80){
Regular → Executable
+13 -12
View File
@@ -6,11 +6,10 @@
/// Created by Anonymous275 on 7/19/2020
///
#include <Windows.h>
#include <Security/Init.h>
#include <windows.h>
#include "Startup.h"
#include <ShlObj.h>
#include "Logger.h"
#include <iostream>
#include <thread>
unsigned long GamePID = 0;
@@ -23,21 +22,22 @@ std::string GetGamePath(){
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
if (openRes != ERROR_SUCCESS){
fatal("Please launch the game at least once");
fatal("Please launch the game at least once!");
}
Path = QueryKey(hKey,4);
if(Path.empty()){
CoInitialize(nullptr);
wchar_t * path = nullptr;
SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, (PWSTR *)(&path));
CoTaskMemFree(path);
std::wstring ws(path);
std::string s(ws.begin(), ws.end());
Path = s;
sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)";
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
if (openRes != ERROR_SUCCESS){
fatal("Cannot get Local Appdata directory!");
}
Path = QueryKey(hKey,5);
Path += "\\BeamNG.drive\\";
}
std::string Ver = CheckVer(GetGameDir());
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
Path += Ver + "\\";
return Path;
}
@@ -61,6 +61,7 @@ void StartGame(std::string Dir){
std::this_thread::sleep_for(std::chrono::seconds(5));
exit(2);
}
void InitGame(const std::string& Dir){
if(!Dev){
std::thread Game(StartGame, Dir);
Regular → Executable
+4 -12
View File
@@ -14,16 +14,8 @@
#include <thread>
std::string getDate() {
typedef std::chrono::duration<int, std::ratio_multiply<std::chrono::hours::period, std::ratio<24>>::type> days;
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
std::chrono::system_clock::duration tp = now.time_since_epoch();
days d = std::chrono::duration_cast<days>(tp);tp -= d;
auto h = std::chrono::duration_cast<std::chrono::hours>(tp);tp -= h;
auto m = std::chrono::duration_cast<std::chrono::minutes>(tp);tp -= m;
auto s = std::chrono::duration_cast<std::chrono::seconds>(tp);tp -= s;
time_t tt = std::chrono::system_clock::to_time_t(now);
tm local_tm{};
localtime_s(&local_tm,&tt);
time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
tm local_tm = *localtime(&tt);
std::stringstream date;
int S = local_tm.tm_sec;
int M = local_tm.tm_min;
@@ -44,14 +36,14 @@ std::string getDate() {
}
void InitLog(){
std::ofstream LFS;
LFS.open ("Launcher.log");
LFS.open(GetEP() + "Launcher.log");
if(!LFS.is_open()){
error("logger file init failed!");
}else LFS.close();
}
void addToLog(const std::string& Line){
std::ofstream LFS;
LFS.open("Launcher.log", std::ios_base::app);
LFS.open(GetEP() + "Launcher.log", std::ios_base::app);
LFS << Line.c_str();
LFS.close();
}
Regular → Executable
+29 -7
View File
@@ -5,12 +5,13 @@
///
/// Created by Anonymous275 on 7/20/2020
///
#include "Network/network.h"
#include "Security/Init.h"
#include "Curl/http.h"
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <regex>
#include "Http.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include "Startup.h"
#include "Logger.h"
#include <charconv>
@@ -47,6 +48,13 @@ void StartSync(const std::string &Data){
GS.detach();
info("Connecting to server");
}
bool IsAllowedLink(const std::string& Link) {
std::regex link_pattern(R"(https:\/\/(?:\w+)?(?:\.)?(?:beammp\.com|discord\.gg))");
std::smatch link_match;
return std::regex_search(Link,link_match, link_pattern) && link_match.position() == 0;
}
void Parse(std::string Data,SOCKET CSocket){
char Code = Data.at(0), SubCode = 0;
if(Data.length() > 1)SubCode = Data.at(1);
@@ -58,7 +66,7 @@ void Parse(std::string Data,SOCKET CSocket){
NetReset();
Terminate = true;
TCPTerminate = true;
Data = Code + HTTP_REQUEST("https://beammp.com/servers-info",443);
Data = Code + HTTP::Get("https://backend.beammp.com/servers-info");
break;
case 'C':
ListOfMods.clear();
@@ -69,6 +77,16 @@ void Parse(std::string Data,SOCKET CSocket){
if(ListOfMods == "-")Data = "L";
else Data = "L"+ListOfMods;
break;
case 'O': //open default browser with URL
if(IsAllowedLink(Data.substr(1))) {
ShellExecuteA(nullptr, "open", Data.substr(1).c_str(), nullptr, nullptr,SW_SHOW); ///TODO: Look at when working on linux port
info("Opening Link \"" + Data.substr(1) + "\"");
}
Data.clear();
break;
case 'P':
Data = Code + std::to_string(ProxyPort);
break;
case 'U':
if(SubCode == 'l')Data = UlStatus;
if(SubCode == 'p'){
@@ -240,11 +258,15 @@ int Handle(EXCEPTION_POINTERS *ep){
}
void CoreNetwork(){
while(TraceBack >= 4){
[[noreturn]] void CoreNetwork(){
while(true) {
#ifndef __MINGW32__
__try{
#endif
CoreMain();
#ifndef __MINGW32__
}__except(Handle(GetExceptionInformation())){}
#endif
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
Regular → Executable
+1 -1
View File
@@ -7,7 +7,7 @@
///
#include <string>
#include <winsock.h>
#include <winsock2.h>
#include "Logger.h"
std::string GetAddr(const std::string&IP){
Regular → Executable
+4 -6
View File
@@ -6,17 +6,15 @@
/// Created by Anonymous275 on 7/25/2020
///
#include "Network/network.h"
#include "Security/Init.h"
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include "Logger.h"
#include <charconv>
#include <string>
#include <thread>
#include <mutex>
std::chrono::time_point<std::chrono::steady_clock> PingStart,PingEnd;
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart,PingEnd;
bool GConnected = false;
bool CServer = true;
SOCKET CSocket = -1;
@@ -77,7 +75,7 @@ void ServerSend(std::string Data, bool Rel){
int DLen = int(Data.length());
if(DLen > 3)C = Data.at(0);
if (C == 'O' || C == 'T')Ack = true;
if(C == 'W' || C == 'Y' || C == 'V' || C == 'E')Rel = true;
if(C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')Rel = true;
if(Ack || Rel){
if(Ack || DLen > 1000)SendLarge(Data);
else TCPSend(Data,TCPSock);
Regular → Executable
+97 -90
View File
@@ -5,111 +5,118 @@
///
/// Created by Anonymous275 on 7/18/2020
///
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "Security/Game.h"
#include <curl/curl.h>
#include <iostream>
#include <Logger.h>
#include <fstream>
#include "Http.h"
#include <mutex>
#include <cmath>
#include <httplib.h>
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
std::string HTTP_REQUEST(const std::string& IP,int port){
bool HTTP::isDownload = false;
std::string HTTP::Get(const std::string &IP) {
static std::mutex Lock;
Lock.lock();
CURL *curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_PORT, port);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(res != CURLE_OK)return "-1";
std::scoped_lock Guard(Lock);
auto pos = IP.find('/',10);
httplib::Client cli(IP.substr(0, pos).c_str());
cli.set_connection_timeout(std::chrono::seconds(10));
cli.set_follow_location(true);
auto res = cli.Get(IP.substr(pos).c_str(), ProgressBar);
std::string Ret;
if(res){
if(res->status == 200){
Ret = res->body;
}else error(res->reason);
}else{
if(isDownload) {
std::cout << "\n";
}
Lock.unlock();
return readBuffer;
error("HTTP Get failed on " + to_string(res.error()));
}
int nb_bar;
double last_progress, progress_bar_adv;
int progress_bar (void *bar, double t, double d){
if(last_progress != round(d/t*100)){
nb_bar = 25;
progress_bar_adv = round(d/t*nb_bar);
return Ret;
}
std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
static std::mutex Lock;
std::scoped_lock Guard(Lock);
auto pos = IP.find('/',10);
httplib::Client cli(IP.substr(0, pos).c_str());
cli.set_connection_timeout(std::chrono::seconds(10));
std::string Ret;
if(!Fields.empty()) {
httplib::Result res = cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
if(res) {
if (res->status != 200) {
error(res->reason);
}
Ret = res->body;
}else{
error("HTTP Post failed on " + to_string(res.error()));
}
}else{
httplib::Result res = cli.Post(IP.substr(pos).c_str());
if(res) {
if (res->status != 200) {
error(res->reason);
}
Ret = res->body;
}else{
error("HTTP Post failed on " + to_string(res.error()));
}
}
if(Ret.empty())return "-1";
else return Ret;
}
bool HTTP::ProgressBar(size_t c, size_t t){
if(isDownload) {
static double last_progress, progress_bar_adv;
progress_bar_adv = round(c / double(t) * 25);
std::cout << "\r";
std::cout << "Progress : [ ";
if(t!=0)std::cout<<round(d/t*100);else std::cout<<0;
std::cout << round(c / double(t) * 100);
std::cout << "% ] [";
int i;
for (i = 0; i <= progress_bar_adv; i++)std::cout << "#";
for(i = 0; i < nb_bar - progress_bar_adv; i++)std::cout<<".";
for (i = 0; i < 25 - progress_bar_adv; i++)std::cout << ".";
std::cout << "]";
last_progress = round(d/t*100);
last_progress = round(c / double(t) * 100);
}
return 0;
return true;
}
struct File {
const char *filename;
FILE *stream;
};
static size_t my_fwrite(void *buffer,size_t size,size_t nmemb,void *stream){
auto *out = (struct File*)stream;
if(!out->stream) {
fopen_s(&out->stream,out->filename,"wb");
if(!out->stream)return -1;
bool HTTP::Download(const std::string &IP, const std::string &Path) {
static std::mutex Lock;
std::scoped_lock Guard(Lock);
isDownload = true;
std::string Ret = Get(IP);
isDownload = false;
if(Ret.empty())return false;
std::ofstream File(Path, std::ios::binary);
if(File.is_open()) {
File << Ret;
File.close();
std::cout << "\n";
info("Download Complete!");
}else{
error("Failed to open file directory: " + Path);
return false;
}
return fwrite(buffer, size, nmemb, out->stream);
}
int Download(const std::string& URL,const std::string& Path,bool close){
CURL *curl;
CURLcode res;
struct File file = {Path.c_str(),nullptr};
curl = curl_easy_init();
if(curl){
curl_easy_setopt(curl, CURLOPT_URL,URL.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &file);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_bar);
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(res != CURLE_OK)return res;
}
if(file.stream)fclose(file.stream);
std::cout << std::endl;
return -1;
}
std::string PostHTTP(const std::string& IP, const std::string& Fields) {
static auto *header = new curl_slist{(char*)"Content-Type: application/json"};
CURL* curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, Fields.size());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Fields.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK)
return "-1";
}
return readBuffer;
return true;
}
Regular → Executable
+30 -20
View File
@@ -7,8 +7,7 @@
///
#include "Network/network.h"
#include <WS2tcpip.h>
#include <ws2tcpip.h>
#include <filesystem>
#include "Startup.h"
#include "Logger.h"
@@ -20,8 +19,9 @@
#include <atomic>
#include <vector>
#include <future>
#include <cmath>
namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem;
std::string ListOfMods;
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
std::vector<std::string> Val;
@@ -37,8 +37,7 @@ std::vector<std::string> Split(const std::string& String,const std::string& deli
}
void CheckForDir(){
struct stat info{};
if(stat( "Resources", &info) != 0){
if(!fs::exists("Resources")){
_wmkdir(L"Resources");
}
}
@@ -61,7 +60,7 @@ std::string Auth(SOCKET Sock){
auto Res = TCPRcv(Sock);
if(Res.empty() || Res[0] == 'E'){
if(Res.empty() || Res[0] == 'E' || Res[0] == 'K'){
Abord();
return "";
}
@@ -88,7 +87,7 @@ std::string Auth(SOCKET Sock){
Res = TCPRcv(Sock);
if(Res[0] == 'E'){
if(Res[0] == 'E' || Res[0] == 'K'){
Abord();
return "";
}
@@ -110,11 +109,10 @@ void UpdateUl(bool D,const std::string&msg){
void AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name){
do {
double pr = Rcv / double(Size) * 100;
double pr = double(Rcv) / double(Size) * 100;
std::string Per = std::to_string(trunc(pr * 10) / 10);
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}while(!Terminate && Rcv < Size);
}
@@ -126,11 +124,10 @@ char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){
}
char* File = new char[Size];
uint64_t Rcv = 0;
int32_t Temp;
do{
int Len = int(Size-Rcv);
if(Len > 1000000)Len = 1000000;
Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
if(Temp < 1){
info(std::to_string(Temp));
UUl("Socket Closed Code 1");
@@ -153,6 +150,7 @@ SOCKET InitDSock(){
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN ServerAddr;
if(DSock < 1){
KillSocket(DSock);
Terminate = true;
return 0;
}
@@ -178,7 +176,6 @@ std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::s
uint64_t GRcv = 0, MSize = Size/2, DSize = Size - MSize;
std::thread Au(AsyncUpdate,std::ref(GRcv), Size, Name);
Au.detach();
std::packaged_task<char*()> task([&] { return TCPRcvRaw(MSock,GRcv,MSize); });
std::future<char*> f1 = task.get_future();
@@ -199,6 +196,7 @@ std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::s
MultiKill(MSock,DSock);
return "";
}
if(Au.joinable())Au.join();
@@ -213,6 +211,11 @@ std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::s
return Ret;
}
void InvalidResource(const std::string& File){
UUl("Invalid mod \"" + File + "\"");
warn("The server tried to sync \"" + File + "\" that is not a .zip file!");
Terminate = true;
}
void SyncResources(SOCKET Sock){
std::string Ret = Auth(Sock);
@@ -239,10 +242,16 @@ void SyncResources(SOCKET Sock){
t.clear();
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
auto pos = FN->find_last_of('/');
auto ZIP = FN->find(".zip");
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
InvalidResource(*FN);
return;
}
if (pos == std::string::npos)continue;
Amount++;
}
if(!FNames.empty())info("Syncing...");
SOCKET DSock = InitDSock();
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
auto pos = FN->find_last_of('/');
if (pos != std::string::npos) {
@@ -251,15 +260,17 @@ void SyncResources(SOCKET Sock){
Pos++;
if (fs::exists(a)) {
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
if (fs::file_size(a) == std::stoi(*FS)){
if (fs::file_size(a) == std::stoull(*FS)){
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
try {
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
fs::create_directory(GetGamePath() + "mods/multiplayer");
fs::create_directories(GetGamePath() + "mods/multiplayer");
}
fs::copy_file(a, GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/')),
fs::copy_options::overwrite_existing);
auto name = GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/'));
auto tmp_name = name + ".tmp";
fs::copy_file(a,tmp_name,fs::copy_options::overwrite_existing);
fs::rename(tmp_name, name);
} catch (std::exception& e) {
error("Failed copy to the mods folder! " + std::string(e.what()));
Terminate = true;
@@ -271,7 +282,6 @@ void SyncResources(SOCKET Sock){
}
CheckForDir();
std::string FName = a.substr(a.find_last_of('/'));
SOCKET DSock = InitDSock();
do {
TCPSend("f" + *FN,Sock);
@@ -295,16 +305,16 @@ void SyncResources(SOCKET Sock){
LFS.close();
}
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
KillSocket(DSock);
}while(fs::file_size(a) != std::stoull(*FS) && !Terminate);
if(!Terminate){
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
fs::create_directory(GetGamePath() + "mods/multiplayer");
fs::create_directories(GetGamePath() + "mods/multiplayer");
}
fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing);
}
WaitForConfirm();
}
KillSocket(DSock);
if(!Terminate){
TCPSend("Done",Sock);
info("Done!");
Regular → Executable
+1 -1
View File
@@ -8,7 +8,7 @@
#include "Zlib/Compressor.h"
#include "Network/network.h"
#include <WS2tcpip.h>
#include <ws2tcpip.h>
#include "Logger.h"
#include <string>
#include <set>
Regular → Executable
+5 -4
View File
@@ -10,7 +10,7 @@
#include <vector>
#include "Logger.h"
#include <iostream>
#include <WS2tcpip.h>
#include <ws2tcpip.h>
#include <Zlib/Compressor.h>
#include "Network/network.h"
@@ -109,7 +109,7 @@ std::string TCPRcv(SOCKET Sock){
#ifdef DEBUG
//debug("Parsing from server -> " + std::to_string(Ret.size()));
#endif
if(Ret[0] == 'E')UUl(Ret.substr(1));
if(Ret[0] == 'E' || Ret[0] == 'K')UUl(Ret.substr(1));
return Ret;
}
@@ -133,13 +133,14 @@ void TCPClientMain(const std::string& IP,int Port){
RetCode = connect(TCPSock, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
if(RetCode != 0){
UlStatus = "UlConnection Failed!";
std::cout << "Client: connect failed! Error code: " << WSAGetLastError() << std::endl;
error("Client: connect failed! Error code: " + std::to_string(WSAGetLastError()));
KillSocket(TCPSock);
WSACleanup();
Terminate = true;
return;
}
getsockname(TCPSock, (SOCKADDR *)&ServerAddr, (int *)sizeof(ServerAddr));
info("Connected!");
char Code = 'C';
send(TCPSock, &Code, 1, 0);
SyncResources(TCPSock);
Regular → Executable
+56 -30
View File
@@ -7,7 +7,7 @@
///
#include <filesystem>
#include <Windows.h>
#include <windows.h>
#include "Logger.h"
#include <fstream>
#include <sstream>
@@ -28,7 +28,7 @@ void lowExit(int code){
std::this_thread::sleep_for(std::chrono::seconds(10));
exit(2);
}
void Exit(int code){
/*void Exit(int code){
TraceBack = 0;
std::string msg =
"Sorry. We do not support cracked copies report this if you believe this is a mistake code ";
@@ -43,9 +43,9 @@ void SteamExit(int code){
error(msg+std::to_string(code));
std::this_thread::sleep_for(std::chrono::seconds(10));
exit(4);
}
}*/
std::string GetGameDir(){
if(TraceBack != 4)Exit(0);
//if(TraceBack != 4)Exit(0);
return GameDir.substr(0,GameDir.find_last_of('\\'));
}
LONG OpenKey(HKEY root,const char* path,PHKEY hKey){
@@ -106,16 +106,21 @@ std::string QueryKey(HKEY hKey,int ID){
DWORD lpData = cbMaxValueData;
buffer[0] = '\0';
LONG dwRes = RegQueryValueEx(hKey, achValue, nullptr, nullptr, buffer, &lpData);
std::string data = reinterpret_cast<const char *const>(buffer);
std::string data = (char *)(buffer);
std::string key = achValue;
switch (ID){
case 1: if(key == "SteamExe"){
auto p = data.find_last_of('/');
if(p != std::string::npos)return data.substr(0,p);
}break;
auto p = data.find_last_of("/\\");
if(p != std::string::npos){
return data.substr(0,p);
}
}
break;
case 2: if(key == "Name" && data == "BeamNG.drive")return data;break;
case 3: if(key == "rootpath")return data;break;
case 4: if(key == "userpath_override")return data;
case 5: if(key == "Local AppData")return data;
default: break;
}
}
@@ -124,18 +129,30 @@ std::string QueryKey(HKEY hKey,int ID){
delete [] buffer;
return "";
}
namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem;
bool NameValid(const std::string& N){
if(N == "config" || N == "librarycache"){
return true;
}
if(N.find_first_not_of("0123456789") == std::string::npos){
return true;
}
return false;
}
void FileList(std::vector<std::string>&a,const std::string& Path){
for (const auto &entry : fs::directory_iterator(Path)) {
auto pos = entry.path().filename().string().find('.');
if (pos != std::string::npos) {
a.emplace_back(entry.path().string());
}else FileList(a,entry.path().string());
const auto& DPath = entry.path();
if (!entry.is_directory()) {
a.emplace_back(DPath.string());
}else if(NameValid(DPath.filename().string())){
FileList(a, DPath.string());
}
}
}
bool Find(const std::string& FName,const std::string& Path){
std::vector<std::string> FS;
FileList(FS,Path+"/userdata");
FileList(FS,Path+"\\userdata");
for(std::string&a : FS){
if(a.find(FName) != std::string::npos){
FS.clear();
@@ -151,7 +168,10 @@ bool FindHack(const std::string& Path){
std::string Name = entry.path().filename().string();
for(char&c : Name)c = char(tolower(c));
if(Name == "steam.exe")s = false;
if(Name.find("greenluma") != -1)return true;
if(Name.find("greenluma") != -1){
error("Found malicious file/folder \"" + Name+"\"");
return true;
}
Name.clear();
}
return s;
@@ -224,35 +244,38 @@ std::string GetManifest(const std::string& Man){
bool IDCheck(std::string Man, std::string steam){
bool a = false,b = true;
int pos = int(Man.rfind("steamapps"));
if(pos == -1)Exit(5);
Man = Man.substr(0,pos+9) + "/appmanifest_284160.acf";
steam += "/config/loginusers.vdf";
// if(pos == -1)Exit(5);
Man = Man.substr(0,pos+9) + "\\appmanifest_284160.acf";
steam += "\\config\\loginusers.vdf";
if(fs::exists(Man) && fs::exists(steam)){
for(const std::string&ID : GetID(steam)){
if(ID == GetManifest(Man))b = false;
}
if(b)Exit(6);
//if(b)Exit(6);
}else a = true;
return a;
}
void LegitimacyCheck(){
std::string Result,T;
std::string K1 = R"(Software\Valve\Steam)";
std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
HKEY hKey;
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
//std::string K1 = R"(Software\Valve\Steam)";
//std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
/*LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 1);
if(Result.empty())Exit(1);
if(fs::exists(Result)){
if(!Find("284160.json",Result))Exit(2);
if(FindHack(Result))SteamExit(1);
}else Exit(3);
T = Result;
Result.clear();
TraceBack++;
}else Exit(4);
K1.clear();
RegCloseKey(hKey);
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);
@@ -262,19 +285,22 @@ void LegitimacyCheck(){
TraceBack++;
}else lowExit(2);
K2.clear();
RegCloseKey(hKey);
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
RegCloseKey(hKey);*/
std::string 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())lowExit(3);
if(IDCheck(Result,T))lowExit(5);
//if(IDCheck(Result,T))lowExit(5);
GameDir = Result;
TraceBack++;
//TraceBack++;
}else lowExit(4);
K3.clear();
Result.clear();
RegCloseKey(hKey);
if(TraceBack < 3)exit(-1);
//if(TraceBack < 3)exit(-1);
}
std::string CheckVer(const std::string &dir){
std::string temp,Path = dir + "\\integrity.json";
Regular → Executable
+63 -34
View File
@@ -6,24 +6,28 @@
/// Created by Anonymous275 on 11/26/2020
///
#include "Curl/http.h"
#include <nlohmann/json.hpp>
#include "Http.h"
#include <filesystem>
#include "Logger.h"
#include <fstream>
#include "Json.h"
using namespace std::filesystem;
namespace fs = std::filesystem;
std::string PublicKey;
std::string PrivateKey;
extern bool LoginAuth;
std::string Role;
void UpdateKey(const char* newKey){
if(newKey){
if(newKey && std::isalnum(newKey[0])){
PrivateKey = newKey;
std::ofstream Key("key");
if(Key.is_open()){
Key << newKey;
Key.close();
}else fatal("Cannot write to disk!");
}else if(exists("key")){
}else if(fs::exists("key")){
remove("key");
}
}
@@ -32,56 +36,81 @@ void UpdateKey(const char* newKey){
/// "Guest":"Name"
/// "pk":"private_key"
std::string GetFail(const std::string& R){
std::string DRet = R"({"success":false,"message":)";
DRet += "\""+R+"\"}";
error(R);
return DRet;
}
std::string Login(const std::string& fields){
if(fields == "LO"){
LoginAuth = false;
UpdateKey(nullptr);
return "";
}
info("Attempting to authenticate...");
std::string Buffer = PostHTTP("https://auth.beammp.com/userlogin", fields);
json::Document d;
d.Parse(Buffer.c_str());
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
if(Buffer == "-1"){
fatal("Failed to communicate with the auth system!");
return GetFail("Failed to communicate with the auth system!");
}
if (Buffer.find('{') == -1 || d.HasParseError()) {
fatal("Invalid answer from authentication servers, please try again later!");
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
if (Buffer.at(0) != '{' || d.is_discarded()) {
error(Buffer);
return GetFail("Invalid answer from authentication servers, please try again later!");
}
if(!d["success"].IsNull() && d["success"].GetBool()){
if(d.contains("success") && d["success"].get<bool>()){
LoginAuth = true;
if(!d["private_key"].IsNull()){
UpdateKey(d["private_key"].GetString());
if(!d.contains("private_key")) {
UpdateKey(d["private_key"].get<std::string>().c_str());
}
if(!d["public_key"].IsNull()){
PublicKey = d["public_key"].GetString();
if(!d.contains("public_key")){
PublicKey = d["public_key"].get<std::string>();
}
info("Authentication successful!");
}else info("Authentication failed!");
if(!d["message"].IsNull()){
d.RemoveMember("private_key");
d.RemoveMember("public_key");
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
d.Accept(writer);
return buffer.GetString();
if(!d.contains("message")){
d.erase("private_key");
d.erase("public_key");
return d.dump();
}
return "{\"success\":false}";
return GetFail("Invalid message parsing!");
}
void CheckLocalKey(){
if(exists("key") && file_size("key") < 100){
if(fs::exists("key") && fs::file_size("key") < 100){
std::ifstream Key("key");
if(Key.is_open()) {
auto Size = file_size("key");
auto Size = fs::file_size("key");
std::string Buffer(Size, 0);
Key.read(&Buffer[0], Size);
Key.close();
Buffer = PostHTTP("https://auth.beammp.com/userlogin", R"({"pk":")"+Buffer+"\"}");
json::Document d;
d.Parse(Buffer.c_str());
if (Buffer == "-1" || Buffer.find('{') == -1 || d.HasParseError()) {
fatal("Invalid answer from authentication servers, please try again later!");
for (char& c : Buffer) {
if (!std::isalnum(c) && c != '-') {
UpdateKey(nullptr);
return;
}
if(d["success"].GetBool()){
}
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
if (Buffer == "-1" || Buffer.at(0) != '{' || d.is_discarded()) {
error(Buffer);
info("Invalid answer from authentication servers.");
UpdateKey(nullptr);
}
if(d["success"].get<bool>()){
LoginAuth = true;
UpdateKey(d["private_key"].GetString());
PublicKey = d["public_key"].GetString();
UpdateKey(d["private_key"].get<std::string>().c_str());
PublicKey = d["public_key"].get<std::string>();
Role = d["role"].get<std::string>();
//info(Role);
}else{
info("Auto-Authentication unsuccessful please re-login!");
UpdateKey(nullptr);
Regular → Executable
+239 -149
View File
@@ -5,29 +5,72 @@
///
/// Created by Anonymous275 on 7/16/2020
///
#include <nlohmann/json.hpp>
#include <httplib.h>
#include "zip_file.h"
#include <windows.h>
#include "Discord/discord_info.h"
#include "Network/network.h"
#include "Security/Init.h"
#include "Curl/http.h"
#include <curl/curl.h>
#include <filesystem>
#include "Startup.h"
#include <iostream>
#include "hashpp.h"
#include "Logger.h"
#include <fstream>
#include <thread>
#include "Http.h"
extern int TraceBack;
bool Dev = false;
namespace fs = std::experimental::filesystem;
int ProxyPort = 0;
namespace fs = std::filesystem;
VersionParser::VersionParser(const std::string& from_string) {
std::string token;
std::istringstream tokenStream(from_string);
while (std::getline(tokenStream, token, '.')) {
data.emplace_back(std::stol(token));
split.emplace_back(token);
}
}
std::strong_ordering VersionParser::operator<=>(
const VersionParser& rhs) const noexcept {
size_t const fields = std::min(data.size(), rhs.data.size());
for (size_t i = 0; i != fields; ++i) {
if (data[i] == rhs.data[i]) continue;
else if (data[i] < rhs.data[i]) return std::strong_ordering::less;
else return std::strong_ordering::greater;
}
if (data.size() == rhs.data.size()) return std::strong_ordering::equal;
else if (data.size() > rhs.data.size()) return std::strong_ordering::greater;
else return std::strong_ordering::less;
}
bool VersionParser::operator==(const VersionParser& rhs) const noexcept {
return std::is_eq(*this <=> rhs);
}
std::string GetEN(){
return "BeamMP-Launcher.exe";
}
std::string GetVer(){
return "1.80";
return "2.0";
}
std::string GetPatch(){
return "";
return ".84";
}
std::string GetEP(char*P){
static std::string Ret = [&](){
std::string path(P);
return path.substr(0, path.find_last_of("\\/") + 1);
} ();
return Ret;
}
void ReLaunch(int argc,char*args[]){
std::string Arg;
@@ -36,7 +79,7 @@ void ReLaunch(int argc,char*args[]){
Arg += args[c-1];
}
system("cls");
ShellExecute(nullptr,"runas",GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
ShellExecute(nullptr,"runas",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
ShowWindow(GetConsoleWindow(),0);
std::this_thread::sleep_for(std::chrono::seconds(1));
exit(1);
@@ -47,121 +90,46 @@ void URelaunch(int argc,char* args[]){
Arg += " ";
Arg += args[c-1];
}
ShellExecute(nullptr,"open",GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
ShellExecute(nullptr,"open",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
ShowWindow(GetConsoleWindow(),0);
std::this_thread::sleep_for(std::chrono::seconds(1));
exit(1);
}
void CheckName(int argc,char* args[]){
struct stat info{};
std::string DN = GetEN(),CDir = args[0],FN = CDir.substr(CDir.find_last_of('\\')+1);
if(FN != DN){
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
if(stat(DN.c_str(),&info)==0)ReLaunch(argc,args);
if(fs::exists(DN))remove(DN.c_str());
if(fs::exists(DN))ReLaunch(argc,args);
std::rename(FN.c_str(), DN.c_str());
URelaunch(argc,args);
}
}
/// Deprecated
void RequestRole(){
auto NPos = std::string::npos;
std::string HTTP_Result = HTTP_REQUEST("https://beammp.com/entitlement?did="+GetDID()+"&t=l",443);
if(HTTP_Result == "-1"){
HTTP_Result = HTTP_REQUEST("https://backup1.beammp.com/entitlement?did="+GetDID()+"&t=l",443);
if(HTTP_Result == "-1") {
fatal("Sorry Backend System Outage! Don't worry it will back on soon!");
}
}
if(HTTP_Result.find("\"MDEV\"") != NPos || HTTP_Result.find("\"CON\"") != NPos){
Dev = true;
}
if(HTTP_Result.find("Error") != NPos){
fatal("Sorry You need to be in the official BeamMP Discord to proceed! https://discord.gg/beammp");
}
info("Client Connected!");
}
void CheckForUpdates(int argc, char* args[], const std::string& CV) {
std::string link = "https://beammp.com/builds/launcher?version=true";
std::string HTTP = HTTP_REQUEST(link,443);
bool fallback = false;
if(HTTP.find_first_of("0123456789") == std::string::npos){
link = "https://backup1.beammp.com/builds/launcher?version=true";
HTTP = HTTP_REQUEST(link,443);
fallback = true;
if(HTTP.find_first_of("0123456789") == std::string::npos) {
fatal("Primary Servers Offline! sorry for the inconvenience!");
}
}
if(fallback){
link = "https://backup1.beammp.com/builds/launcher?download=true";
}else link = "https://beammp.com/builds/launcher?download=true";
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);
struct stat buffer{};
std::string Back = "BeamMP-Launcher.back";
if(stat(Back.c_str(), &buffer) == 0)remove(Back.c_str());
if(HTTP > CV){
system("cls");
info("Update found!");
info("Updating...");
if(std::rename(GetEN().c_str(), Back.c_str()))error("failed creating a backup!");
int i = Download(link, GetEN(),true);
if(i != -1){
error("Launcher Update failed! trying again... code : " + std::to_string(i));
std::this_thread::sleep_for(std::chrono::seconds(2));
int i2 = Download(link, GetEN(),true);
if(i2 != -1){
error("Launcher Update failed! code : " + std::to_string(i2));
std::this_thread::sleep_for(std::chrono::seconds(5));
ReLaunch(argc,args);
}
}
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, EP);
if (FileHash != LatestHash && VersionParser(LatestVersion) > VersionParser(GetVer()+GetPatch())) {
info("Launcher update found!");
fs::remove(Back);
fs::rename(EP, Back);
info("Downloading Launcher update " + LatestHash);
HTTP::Download(
"https://backend.beammp.com/builds/launcher?download=true"
"&pk=" +
PublicKey + "&branch=" + Branch,
EP);
URelaunch(argc, args);
}else{
info("Version is up to date");
}
} else info("Launcher version is up to date");
TraceBack++;
}
void CheckDir(int argc,char*args[]){
std::string CDir = args[0];
std::string MDir = "BeamNG\\mods";
if(!fs::is_directory("BeamNG")){
if(!fs::create_directory("BeamNG")){
error("Cannot Create BeamNG Directory! Retrying...");
std::this_thread::sleep_for(std::chrono::seconds(3));
ReLaunch(argc,args);
}
}
if(fs::is_directory(MDir) && !Dev){
int c = 0;
for (auto& p : fs::directory_iterator(MDir))c++;
if(c > 2) {
warn(std::to_string(c-1) + " local launcher mods will be wiped! Close this window if you don't want that!");
std::this_thread::sleep_for(std::chrono::seconds(15));
}
try{
fs::remove_all(MDir);
} catch (...) {
error("Please close the game and try again");
std::this_thread::sleep_for(std::chrono::seconds(5));
exit(1);
}
}
if(fs::is_directory(MDir) && !Dev)ReLaunch(argc,args);
if(!fs::create_directory(MDir) && !Dev){
error("Cannot Create Mods Directory! Retrying...");
std::this_thread::sleep_for(std::chrono::seconds(3));
ReLaunch(argc,args);
}
if(!fs::is_directory("BeamNG\\settings")){
if(!fs::create_directory("BeamNG\\settings")){
error("Cannot Create Settings Directory! Retrying...");
std::this_thread::sleep_for(std::chrono::seconds(3));
ReLaunch(argc,args);
}
}
}
void CustomPort(int argc, char* argv[]){
if(argc > 1){
std::string Port = argv[1];
@@ -171,66 +139,188 @@ void CustomPort(int argc, char* argv[]){
warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
}
}
if(argc > 2)Dev = false;
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);
info("Patched!");
}
void InitLauncher(int argc, char* argv[]) {
system("cls");
curl_global_init(CURL_GLOBAL_DEFAULT);
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
InitLog();
CheckName(argc, argv);
CheckLocalKey(); //will replace RequestRole
Discord_Main();
//RequestRole();
LinuxPatch();
CheckLocalKey();
ConfigInit();
CustomPort(argc, argv);
Discord_Main();
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
}
void PreGame(int argc, char* argv[],const std::string& GamePath){
info("Game Version : " + CheckVer(GamePath));
std::string DUI = R"(BeamNG\settings\uiapps-layouts.json)";
std::string GS = R"(BeamNG\settings\game-settings.ini)";
std::string link = "https://beammp.com/client-ui-data";
bool fallback = false;
int i;
if(!fs::exists(DUI)){
info("Downloading default ui data...");
i = Download(link,DUI,true);
if(i != -1){
fallback = true;
remove(DUI.c_str());
link = "https://backup1.beammp.com/client-ui-data";
i = Download(link,DUI,true);
if(i != -1) {
error("Failed to download code : " + std::to_string(i));
std::this_thread::sleep_for(std::chrono::seconds(3));
ReLaunch(argc, argv);
size_t DirCount(const std::filesystem::path& path){
return (size_t)std::distance(std::filesystem::directory_iterator{path}, std::filesystem::directory_iterator{});
}
void CheckMP(const std::string& Path) {
if (!fs::exists(Path))return;
size_t c = DirCount(fs::path(Path));
try {
for (auto& p : fs::directory_iterator(Path)){
if(p.exists() && !p.is_directory()){
std::string Name = p.path().filename().string();
for(char&Ch : Name)Ch = char(tolower(Ch));
if(Name != "beammp.zip")fs::remove(p.path());
}
}
info("Download Complete!");
} catch (...) {
fatal("We were unable to clean the multiplayer mods folder! Is the game still running or do you have something open in that folder?");
}
if(!fs::exists(GS)) {
info("Downloading default game settings...");
if(fallback)link = "https://backup1.beammp.com/client-settings-data";
else link = "https://beammp.com/client-settings-data";
Download(link, GS,true);
info("Download Complete!");
}
void EnableMP(){
std::string File(GetGamePath() + "mods/db.json");
if(!fs::exists(File))return;
auto Size = fs::file_size(File);
if(Size < 2)return;
std::ifstream db(File);
if(db.is_open()) {
std::string Data(Size, 0);
db.read(&Data[0], Size);
db.close();
nlohmann::json d = nlohmann::json::parse(Data, nullptr, false);
if(Data.at(0) != '{' || d.is_discarded()) {
//error("Failed to parse " + File); //TODO illegal formatting
return;
}
if(d.contains("mods") && d["mods"].contains("multiplayerbeammp")){
d["mods"]["multiplayerbeammp"]["active"] = true;
std::ofstream ofs(File);
if(ofs.is_open()){
ofs << d.dump();
ofs.close();
}else{
error("Failed to write " + File);
}
}
}
}
void PreGame(const std::string& GamePath){
std::string GameVer = CheckVer(GamePath);
info("Game Version : " + GameVer);
CheckMP(GetGamePath() + "mods/multiplayer");
if(!Dev) {
info("Downloading mod...");
if(fallback)link = "https://backup1.beammp.com/builds/client";
else link ="https://beammp.com/builds/client";
if(!fs::exists(GetGamePath() + "mods")){
fs::create_directory(GetGamePath() + "mods");
}
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());
try {
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
fs::create_directory(GetGamePath() + "mods/multiplayer");
fs::create_directories(GetGamePath() + "mods/multiplayer");
}
Download(link, GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true);
info("Download Complete!");
EnableMP();
}catch(std::exception&e){
fatal(e.what());
}
/*debug("Name : " + GetDName());
debug("Discriminator : " + GetDTag());
debug("Unique ID : " + GetDID());*/
std::string ZipPath(GetGamePath() + R"(mods\multiplayer\BeamMP.zip)");
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, ZipPath);
if (FileHash != LatestHash) {
info("Downloading BeamMP Update " + LatestHash);
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
"&pk=" + PublicKey + "&branch=" + Branch, ZipPath);
}
std::string Target(GetGamePath() + "mods/unpacked/beammp");
if(fs::is_directory(Target)) {
fs::remove_all(Target);
}
}
}
void set_headers(httplib::Response& res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Headers", "X-API-Version");
res.set_header("Access-Control-Allow-Method", "GET,POST,OPTIONS");
}
void StartProxy() {
std::thread proxy([&](){
httplib::Server HTTPProxy;
httplib::Headers headers = {
{"User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch()},
{"Accept", "*/*"}
};
std::string pattern = "/:any1";
for (int i = 2; i <= 4; i++) {
HTTPProxy.Get(pattern, [&](const httplib::Request &req, httplib::Response &res) {
httplib::Client cli("https://backend.beammp.com");
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"));
}
if (auto cli_res = cli.Get(req.path, headers); 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.Post(pattern, [&](const httplib::Request &req, httplib::Response &res) {
httplib::Client cli("https://backend.beammp.com");
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"));
}
if (auto cli_res = cli.Post(req.path, headers, req.body,
req.get_header_value("Content-Type")); 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");
}
});
pattern += "/:any" + std::to_string(i);
}
ProxyPort = HTTPProxy.bind_to_any_port("0.0.0.0");
HTTPProxy.listen_after_bind();
});
proxy.detach();
}
Regular → Executable
+16 -4
View File
@@ -8,13 +8,15 @@
#include "Network/network.h"
#include "Security/Init.h"
#include "Startup.h"
#include <thread>
#include <iostream>
#include "Logger.h"
#include <thread>
#include "Http.h"
[[noreturn]] void flush(){
while(true){
std::cout.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
@@ -23,10 +25,20 @@ int main(int argc, char* argv[]) {
std::thread th(flush);
th.detach();
#endif
GetEP(argv[0]);
InitLauncher(argc, argv);
CheckDir(argc,argv);
try {
LegitimacyCheck();
PreGame(argc,argv,GetGameDir());
} catch (std::exception &e) {
fatal("Main 1 : " + std::string(e.what()));
}
StartProxy();
PreGame(GetGameDir());
InitGame(GetGameDir());
CoreNetwork();
///TODO: make sure to use argv[0] for everything that should be in the same dir (mod down ect...)
}