mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-04 06:46:06 +00:00
Major rewrite of the network
This commit is contained in:
42
src/GameStart.cpp
Normal file
42
src/GameStart.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 5/2/2020
|
||||
///
|
||||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
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);
|
||||
RegDeleteValueA(hKey, TEXT("userpath_override"));
|
||||
}
|
||||
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");
|
||||
std::cout << "\nGame Closed! launcher closing in 5 secs\n";
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
exit(2);
|
||||
}
|
||||
Reference in New Issue
Block a user