Fixed game crashing without launcher

This commit is contained in:
Anonymous275 2020-05-02 18:25:26 +03:00
parent 0782b71638
commit e14c35950b
3 changed files with 46 additions and 40 deletions

View File

@ -9,6 +9,6 @@ project(BeamMP-Launcher)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
add_executable(BeamMP-Launcher main.cpp VehicleNetwork.cpp proxy.cpp Security.cpp http.cpp Discord.cpp UpdateCheck.cpp CoreNetwork.cpp Resources.cpp Compressor.cpp VehicleNetwork.cpp) add_executable(BeamMP-Launcher main.cpp VehicleNetwork.cpp proxy.cpp Security.cpp http.cpp Discord.cpp UpdateCheck.cpp CoreNetwork.cpp Resources.cpp Compressor.cpp VehicleNetwork.cpp GameStart.cpp)
target_link_libraries(BeamMP-Launcher discord-rpc libcurl_a zlibstatic) target_link_libraries(BeamMP-Launcher discord-rpc libcurl_a zlibstatic)

42
GameStart.cpp Normal file
View File

@ -0,0 +1,42 @@
///
/// Created by Anonymous275 on 5/2/2020
///
#include <windows.h>
#include <iostream>
#include <thread>
#include <string>
std::string QueryKey(HKEY hKey,int ID);
void SystemExec(const std::string&cmd);
void Exit(const std::string& Msg);
std::string Write(const std::string&Path){
HKEY hKey;
LPCTSTR sk = TEXT("Software\\BeamNG\\BeamNG.drive");
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
if (openRes != ERROR_SUCCESS)Exit("Error! Please launch the game at least once");
std::string Query = QueryKey(hKey,4);
LONG setRes = RegSetValueEx(hKey, TEXT("userpath_override"), 0, REG_SZ, (LPBYTE)Path.c_str(), Path.size());
if(setRes != ERROR_SUCCESS)Exit("Error! Failed to launch the game code 1");
RegCloseKey(hKey);
return Query;
}
void DeleteKey(){
HKEY hKey;
LPCTSTR sk = TEXT("Software\\BeamNG\\BeamNG.drive");
RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
LPCTSTR value = TEXT("userpath_override");
RegDeleteValueA(hKey, value);
}
void RollBack(const std::string&Val){
std::this_thread::sleep_for(std::chrono::seconds(7));
if(!Val.empty())Write(Val);
else DeleteKey();
}
void StartGame(const std::string&ExeDir,const std::string&Current){
std::cout << "Game Launched!\n";
std::thread RB(RollBack,Write(Current));
RB.detach();
SystemExec(ExeDir + " -nocrashreport");
Exit("Game Closed!");
}

View File

@ -11,11 +11,10 @@
#include <thread> #include <thread>
#pragma comment(lib, "urlmon.lib") #pragma comment(lib, "urlmon.lib")
void StartGame(const std::string&ExeDir,const std::string&Current);
std::string HTTP_REQUEST(const std::string&url,int port); std::string HTTP_REQUEST(const std::string&url,int port);
void CheckForUpdates(const std::string& CV); void CheckForUpdates(const std::string& CV);
std::vector<std::string> GetDiscordInfo(); std::vector<std::string> GetDiscordInfo();
std::string QueryKey(HKEY hKey,int ID);
std::vector<std::string> GlobalInfo; std::vector<std::string> GlobalInfo;
std::vector<std::string> Check(); std::vector<std::string> Check();
std::string getHardwareID(); std::string getHardwareID();
@ -81,42 +80,8 @@ std::string CheckVer(const std::string &path){
} }
return temp; return temp;
} }
void SyncResources(const std::string&IP,int Port); int main(int argc, char* argv[]){
std::string Write(const std::string&Path){
HKEY hKey;
LPCTSTR sk = TEXT("Software\\BeamNG\\BeamNG.drive");
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
if (openRes != ERROR_SUCCESS) {
Exit("Error! Please launch the game at least once");
}
std::string Query = QueryKey(hKey,4);
LPCTSTR value = TEXT("userpath_override");
LONG setRes = RegSetValueEx(hKey, value, 0, REG_SZ, (LPBYTE)Path.c_str(), Path.size());
if (setRes != ERROR_SUCCESS) {
Exit("Error! Failed to launch the game code 1");
}
RegCloseKey(hKey);
return Query;
}
void RollBack(const std::string&Val){
std::this_thread::sleep_for(std::chrono::seconds(5));
if(!Val.empty())Write(Val);
else Write(" ");
}
void StartGame(const std::string&ExeDir,const std::string&Current){
std::cout << "Game Launched!\n";
std::thread RB(RollBack,Current);
RB.detach();
SystemExec(ExeDir + " -nocrashreport");
Exit("Game Closed!");
}
int main(int argc, char* argv[])
{
const unsigned long long NPos = std::string::npos; const unsigned long long NPos = std::string::npos;
struct stat info{}; struct stat info{};
@ -158,10 +123,9 @@ int main(int argc, char* argv[])
Download("https://beamng-mp.com/client-data",Settings); Download("https://beamng-mp.com/client-data",Settings);
std::cout << "Downloaded default config!" << std::endl; std::cout << "Downloaded default config!" << std::endl;
} }
Download("https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2),Path + R"(\mods\BeamMP.zip)"); Download("https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2),Path + R"(\mods\BeamMP.zip)");
if(!MPDEV){ if(!MPDEV){
std::thread Game(StartGame,ExeDir,Write(Path + "\\")); std::thread Game(StartGame,ExeDir,(Path + "\\"));
Game.detach(); Game.detach();
}else{ }else{
std::cout << "Name : " << GlobalInfo.at(0) << std::endl; std::cout << "Name : " << GlobalInfo.at(0) << std::endl;