Major rewrite of the network

This commit is contained in:
Anonymous275
2020-05-10 23:37:29 +03:00
parent a132fd7b9f
commit 042671b146
31 changed files with 6314 additions and 6211 deletions

42
src/GameStart.cpp Normal file
View 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);
}