private static void Main() { _handler += Handler; var p = (int)Environment.OSVersion.Platform; if (p == 4 || p == 6 || p == 128) { setupHandlers(); } else { SetConsoleCtrlHandler(_handler, true); } var settings = ServerSettings.ReadSettings(Location + "settings.xml"); _log = settings.LogToFile; if (_log) { File.AppendAllText("server.log", "-> SERVER STARTED AT " + DateTime.Now); } var serverVersion = ParseableVersion.FromAssembly(Assembly.GetExecutingAssembly()); Console.WriteLine("======================================================================="); Console.WriteLine("= APPI MULTIPLAYER v{0}", serverVersion); Console.WriteLine("======================================================================="); Console.WriteLine("= Server Name: " + settings.Name); Console.WriteLine("= Server Port: " + settings.Port); Console.WriteLine("= Server FQDN: " + settings.fqdn); Console.WriteLine("="); Console.WriteLine("= Player Limit: " + settings.MaxPlayers); Console.WriteLine("= Log Level: " + settings.LogLevel + " (1: ERROR, 2: DEBUG, 3: VERBOSE)"); Console.WriteLine("======================================================================="); if (settings.Port != 4499) { Output("WARN: Port is not the default one, players on your local network won't be able to automatically detect you!"); } Output("Starting..."); //AppDomain.CurrentDomain.SetShadowCopyFiles(); if (!Directory.Exists("resources")) { Output("ERROR: Necessary \"resources\" folder does not exist!"); Console.Read(); return; } ServerInstance = new GameServer(settings) { AllowDisplayNames = true }; ServerInstance.Start(settings.Resources.Select(r => r.Path).ToArray()); Output("Started! Waiting for connections."); while (!CloseProgram) { ServerInstance.Tick(); Thread.Sleep(1000 / 60); } }
public void Start() { /* * WE START HERE: * * 1. Check for new update * 2. Start GTAVLauncher.exe * 3. Spin until GTAVLauncher.exe process is kill * 4. Is there a GTA5.exe process? No -> terminate self. Yes -> continue * 5. Move all mods/whatever to temporary folder. * 6. Move our mod into the game directory. * 7. Spin until GTA5.exe terminates * 8. Delete our mod files. * 9. Move the temporary mod files back * 10. Terminate * */ var settings = ReadSettings("settings.xml"); if (settings == null) { MessageBox.Show("No settings were found."); return; } // Create splash screen var splashScreen = new SplashScreenThread(); ParseableVersion fileVersion = new ParseableVersion(0, 0, 0, 0); if (File.Exists("bin\\scripts\\MultiV.dll")) { fileVersion = ParseableVersion.Parse(FileVersionInfo.GetVersionInfo(Path.GetFullPath("bin\\scripts\\MultiV.dll")).FileVersion); } splashScreen.SetPercent(10); // Check for new version using (var wc = new ImpatientWebClient()) { try { var lastVersion = ParseableVersion.Parse(wc.DownloadString(settings.MasterServerAddress.Trim('/') + "/version")); if (lastVersion > fileVersion) { var updateResult = MessageBox.Show( "New GTA Network version is available! Download now?\n\nInternet Version: " + lastVersion + "\nOur Version: " + fileVersion, "Update Available", MessageBoxButtons.YesNo); if (updateResult == DialogResult.Yes) { // Download latest version. if (!Directory.Exists("tempstorage")) { Directory.CreateDirectory("tempstorage"); } wc.DownloadFile(settings.MasterServerAddress.Trim('/') + "/files", "tempstorage\\files.zip"); using (var zipfile = ZipFile.Read("tempstorage\\files.zip")) { foreach (var entry in zipfile) { entry.Extract("bin", ExtractExistingFileAction.OverwriteSilently); } } File.Delete("tempstorage\\files.zip"); } } } catch (WebException) { MessageBox.Show( "The master server is unavailable at this time. Unable to check for latest version.", "Warning"); } } splashScreen.SetPercent(40); if (Process.GetProcessesByName("GTA5").Any()) { MessageBox.Show("GTA V is already running. Please shut down the game before starting GTA Network."); return; } var dictPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Rockstar Games\Grand Theft Auto V"; var steamDictPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Rockstar Games\GTAV"; var steamKeyName = "InstallFolderSteam"; var keyName = "InstallFolder"; InstallFolder = (string)Registry.GetValue(dictPath, keyName, null); if (string.IsNullOrEmpty(InstallFolder)) { InstallFolder = (string)Registry.GetValue(steamDictPath, steamKeyName, null); settings.SteamPowered = true; try { SaveSettings("settings.xml", settings); } catch (UnauthorizedAccessException) { MessageBox.Show("We require administrative privileges to continue. Please restart as administrator.", "Unauthorized access"); return; } if (string.IsNullOrEmpty(InstallFolder)) { var diag = new OpenFileDialog(); diag.Filter = "GTA5 Executable|GTA5.exe"; diag.RestoreDirectory = true; diag.CheckFileExists = true; diag.CheckPathExists = true; if (diag.ShowDialog() == DialogResult.OK) { InstallFolder = Path.GetDirectoryName(diag.FileName); try { Registry.SetValue(dictPath, keyName, InstallFolder); } catch (UnauthorizedAccessException) { } } else { return; } } } splashScreen.SetPercent(50); if ((string)Registry.GetValue(dictPath, "MultiVInstallDir", null) != AppDomain.CurrentDomain.BaseDirectory) { try { Registry.SetValue(dictPath, "MultiVInstallDir", AppDomain.CurrentDomain.BaseDirectory); } catch (UnauthorizedAccessException ex) { MessageBox.Show("We have no access to the registry. Please start the program as Administrator.", "UNAUTHORIZED ACCESS"); return; } } splashScreen.SetPercent(60); var mySettings = GameSettings.LoadGameSettings(); if (mySettings.Video != null && mySettings.Video.PauseOnFocusLoss != null) { mySettings.Video.PauseOnFocusLoss.Value = 0; } else { mySettings.Video = new GameSettings.Video(); mySettings.Video.PauseOnFocusLoss = new GameSettings.PauseOnFocusLoss(); mySettings.Video.PauseOnFocusLoss.Value = 0; } splashScreen.SetPercent(65); MoveStuffIn(); if (!settings.SteamPowered) { Process.Start(InstallFolder + "\\GTAVLauncher.exe"); } else { Process.Start("steam://run/271590"); } splashScreen.SetPercent(80); Process gta5Process; var counter = 0; while ((gta5Process = Process.GetProcessesByName("GTA5").FirstOrDefault(p => p != null)) == null) { Thread.Sleep(100); if (Process.GetProcessesByName("GTAVLauncher").FirstOrDefault(p => p != null) == null) { counter++; if (counter > 50) { MoveStuffOut(); return; } } } splashScreen.SetPercent(100); // Close the splashscreen here. Thread.Sleep(1000); splashScreen.Stop(); // Wait for GTA5 to exit while (!gta5Process.HasExited) { Thread.Sleep(1000); } Thread.Sleep(5000); // Move everything back MoveStuffOut(); }
public void Start(params string[] args) { /* * WE START HERE: * * 1. Check for new update * 2. Start GTAVLauncher.exe * 3. Spin until GTAVLauncher.exe process is kill * 4. Is there a GTA5.exe process? No -> terminate self. Yes -> continue * 5. Move all mods/whatever to temporary folder. * 6. Move our mod into the game directory. * 7. Spin until GTA5.exe terminates * 8. Delete our mod files. * 9. Move the temporary mod files back * 10. Terminate * * REWORK: * * 1. Check for new update * 2. Check Game directory * 3. Check Game version * 4. Start GTAVLauncher.exe * 5. Start the game * 6. Inject ourselves into GTA5.exe * 7. Restore old settings on GTA5.exe termination. * 8. Terminate */ var playerSetings = new PlayerSettings(); #region Create settings.xml if it does not exist //MessageBox.Show(Directory.GetParent(Directory.GetCurrentDirectory()).FullName); //shows a path error but returns the correct listing if (!File.Exists(GTANFolder + "settings.xml") || string.IsNullOrWhiteSpace(File.ReadAllText(GTANFolder + "settings.xml"))) { var ser = new XmlSerializer(typeof(PlayerSettings)); using (var stream = File.OpenWrite(GTANFolder + "settings.xml")) { ser.Serialize(stream, playerSetings); } } #endregion #region Create splash screen SplashScreenThread splashScreen = new SplashScreenThread(); #endregion #region Read settings.xml PlayerSettings settings = null; splashScreen.SetPercent(10); settings = ReadSettings(GTANFolder + "settings.xml"); #endregion splashScreen.SetPercent(15); #region Check if GTA5 or GTAVLauncher is running if (Process.GetProcessesByName("GTA5").Any() || Process.GetProcessesByName("GTAVLauncher").Any()) { MessageBox.Show(splashScreen.SplashScreen, "GTA5 or the GTAVLauncher is already running. Please close them before starting GTA Network."); return; } #endregion #region Check for dependencies if (!Environment.Is64BitOperatingSystem) { MessageBox.Show(splashScreen.SplashScreen, "GTA Network does not work on 32bit machines.", "Incompatible"); return; } var NetPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"; if ((int)Registry.GetValue(NetPath, "Release", null) < 379893) //379893 == .NET Framework v4.5.2 { MessageBox.Show(splashScreen.SplashScreen, "Missing or outdated .NET Framework, required version: 4.5.2 or newer.", "Missing Dependency"); return; } var Redist2013x86 = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\12.0\VC\Runtimes\x86"; if (string.IsNullOrEmpty((string)Registry.GetValue(Redist2013x86, "Version", null))) { MessageBox.Show(splashScreen.SplashScreen, "Microsoft Visual C++ 2013 Redistributable (x86) is missing.", "Missing Dependency"); return; } var Redist2013x64 = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\12.0\VC\Runtimes\x64"; if (string.IsNullOrEmpty((string)Registry.GetValue(Redist2013x64, "Version", null))) { MessageBox.Show(splashScreen.SplashScreen, "Microsoft Visual C++ 2013 Redistributable (x64) is missing.", "Missing Dependency"); return; } var Redist2015x86 = @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86"; if (string.IsNullOrEmpty((string)Registry.GetValue(Redist2015x86, "Version", null))) { MessageBox.Show(splashScreen.SplashScreen, "Microsoft Visual C++ 2015 Redistributable (x86) is missing.", "Missing Dependency"); return; } var Redist2015x64 = @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"; if (string.IsNullOrEmpty((string)Registry.GetValue(Redist2015x64, "Version", null))) { MessageBox.Show(splashScreen.SplashScreen, "Microsoft Visual C++ 2015 Redistributable (x64) is missing.", "Missing Dependency"); return; } #endregion #region Check CEF version if (!Directory.Exists(GTANFolder + "cef") || !File.Exists(GTANFolder + "cef\\libcef.dll")) { MessageBox.Show(splashScreen.SplashScreen, "CEF directory or one of the core CEF components is missing from the directory, please reinstall."); return; } //FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(GTANFolder + "cef\\libcef.dll"); //splashScreen.SetPercent(20); //using (var wc = new ImpatientWebClient()) //{ // try // { // string lastCefVersion = wc.DownloadString(settings.MasterServerAddress.Trim('/') + $"/update/{settings.UpdateChannel}/cef/version"); // if (lastCefVersion != myFileVersionInfo.ProductVersion) // { // var updateResult = // MessageBox.Show(splashScreen.SplashScreen, // "New CEF Update is available! Requires a client re-install!\n " + // "\nUpdate Version: " + lastCefVersion + "\nInstalled Version: " + myFileVersionInfo.ProductVersion + // "\n\nYou must download the client installer from the website, Download now?", // "CEF Update Available",MessageBoxButtons.YesNo); // if (updateResult == DialogResult.Yes) // { // Process.Start("https://download.gtanet.work/client/GTANSetup.zip"); // return; // } // else // { // return; // } // } // } // catch (WebException ex) // { // MessageBox.Show(splashScreen.SplashScreen, "Unable to contact master server, Please check your internet connection and try again.", "Warning"); // if (!Directory.Exists(GTANFolder + "logs")) Directory.CreateDirectory(GTANFolder + "logs"); // File.AppendAllText(GTANFolder + "logs" + "\\" + "launcher.log", "MASTER SERVER LOOKUP EXCEPTION AT " + DateTime.Now + "\n\n" + ex); // } //} #endregion #region Check for Client Dependencies var shvVersion = new ParseableVersion(0, 0, 0, 0); if (File.Exists(GTANFolder + "bin" + "\\" + "depsver.txt")) { shvVersion = ParseableVersion.Parse(File.ReadAllText(GTANFolder + "bin" + "\\" + "depsver.txt")); } splashScreen.SetPercent(30); using (var wc = new ImpatientWebClient()) { try { var lastVersion = ParseableVersion.Parse(wc.DownloadString(settings.MasterServerAddress.Trim('/') + $"/update/{settings.UpdateChannel}/deps/version")); if (lastVersion > shvVersion) { var updateResult = MessageBox.Show(splashScreen.SplashScreen, "New GTA Network Dependency Update is available! Download now?\n\nUpdate Version: " + lastVersion + "\nInstalled Version: " + shvVersion, "Update Available", MessageBoxButtons.YesNo); if (updateResult == DialogResult.Yes) { // Download latest version. if (!Directory.Exists(GTANFolder + "tempstorage")) { Directory.CreateDirectory(GTANFolder + "tempstorage"); } wc.Timeout = int.MaxValue; wc.DownloadFile(settings.MasterServerAddress.Trim('/') + $"/update/{settings.UpdateChannel}/deps/files", GTANFolder + "tempstorage" + "\\" + "deps.zip"); using (var zipfile = ZipFile.Read(GTANFolder + "tempstorage" + "\\" + "deps.zip")) { zipfile.ParallelDeflateThreshold = -1; // http://stackoverflow.com/questions/15337186/dotnetzip-badreadexception-on-extract foreach (var entry in zipfile) { entry.Extract(GTANFolder + "bin", ExtractExistingFileAction.OverwriteSilently); } } File.Delete(GTANFolder + "tempstorage" + "\\" + "deps.zip"); } } } catch (WebException ex) { MessageBox.Show(splashScreen.SplashScreen, "Unable to contact master server, Please check your internet connection and try again.", "Warning"); if (!Directory.Exists(GTANFolder + "logs")) { Directory.CreateDirectory(GTANFolder + "logs"); } File.AppendAllText(GTANFolder + "logs" + "\\" + "launcher.log", "MASTER SERVER LOOKUP EXCEPTION AT " + DateTime.Now + "\n\n" + ex); } } #endregion #region Check for new client version ParseableVersion fileVersion = new ParseableVersion(0, 0, 0, 0); if (File.Exists(GTANFolder + "bin" + "\\" + "scripts" + "\\" + "GTANetwork.dll")) { fileVersion = ParseableVersion.Parse(FileVersionInfo.GetVersionInfo(GTANFolder + "bin" + "\\" + "scripts" + "\\" + "GTANetwork.dll").FileVersion); } splashScreen.SetPercent(30); using (var wc = new ImpatientWebClient()) { try { var lastVersion = ParseableVersion.Parse(wc.DownloadString(settings.MasterServerAddress.Trim('/') + $"/update/{settings.UpdateChannel}/version")); if (lastVersion > fileVersion) { var updateResult = MessageBox.Show(splashScreen.SplashScreen, "New GTA Network Client Update is available! Download now?\n\nUpdate Version: " + lastVersion + "\nInstalled Version: " + fileVersion, "Update Available", MessageBoxButtons.YesNo); if (updateResult == DialogResult.Yes) { // Download latest version. if (!Directory.Exists(GTANFolder + "tempstorage")) { Directory.CreateDirectory(GTANFolder + "tempstorage"); } wc.Timeout = Int32.MaxValue; wc.DownloadFile(settings.MasterServerAddress.Trim('/') + $"/update/{settings.UpdateChannel}/files", GTANFolder + "tempstorage" + "\\" + "files.zip"); using (var zipfile = ZipFile.Read(GTANFolder + "tempstorage" + "\\" + "files.zip")) { zipfile.ParallelDeflateThreshold = -1; // http://stackoverflow.com/questions/15337186/dotnetzip-badreadexception-on-extract foreach (var entry in zipfile) { entry.Extract(GTANFolder + "bin", ExtractExistingFileAction.OverwriteSilently); } } File.Delete(GTANFolder + "tempstorage" + "\\" + "files.zip"); } } } catch (WebException ex) { MessageBox.Show(splashScreen.SplashScreen, "Unable to contact master server, Please check your internet connection and try again.", "Warning"); if (!Directory.Exists(GTANFolder + "logs")) { Directory.CreateDirectory(GTANFolder + "logs"); } File.AppendAllText(GTANFolder + "logs" + "\\" + "launcher.log", "MASTER SERVER LOOKUP EXCEPTION AT " + DateTime.Now + "\n\n" + ex); } } #endregion splashScreen.SetPercent(35); #region Check GamePath directory if (string.IsNullOrWhiteSpace(settings.GamePath) || !File.Exists(settings.GamePath + "\\" + "GTA5.exe")) { var diag = new OpenFileDialog(); diag.Filter = "GTA5 Executable|GTA5.exe"; diag.FileName = "GTA5.exe"; diag.DefaultExt = ".exe"; diag.RestoreDirectory = true; diag.CheckFileExists = true; diag.CheckPathExists = true; diag.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); if (diag.ShowDialog() == DialogResult.OK) { settings.GamePath = Path.GetDirectoryName(diag.FileName); try { SaveSettings(GTANFolder + "settings.xml", settings); } catch (UnauthorizedAccessException) { MessageBox.Show(splashScreen.SplashScreen, "Insufficient permissions, Please run as Admin to avoid permission issues. (2)", "Unauthorized access"); return; } } else { return; } } #endregion #region Check GTA5 version FileVersionInfo myGTAVersionInfo = FileVersionInfo.GetVersionInfo(settings.GamePath + "\\" + "GTA5.exe"); splashScreen.SetPercent(40); using (var wc = new ImpatientWebClient()) { try { string lastVersion = wc.DownloadString(settings.MasterServerAddress.Trim('/') + $"/update/version"); if (ParseableVersion.Parse(lastVersion) > ParseableVersion.Parse(myGTAVersionInfo.ProductVersion)) { var updateResult = MessageBox.Show(splashScreen.SplashScreen, "You are running an outdated Grand Theft Auto V Game version\n " + "\nLatest Version: " + lastVersion + "\nInstalled Version: " + myGTAVersionInfo.ProductVersion + "\n\nPlease update either via Steam or RGSC launcher, Continue with the installed version?", "Outdated Game version", MessageBoxButtons.YesNo); if (updateResult == DialogResult.No) { return; } } } catch (WebException ex) { MessageBox.Show(splashScreen.SplashScreen, "Unable to contact master server, Please check your internet connection and try again.", "Warning"); if (!Directory.Exists(GTANFolder + "logs")) { Directory.CreateDirectory(GTANFolder + "logs"); } File.AppendAllText(GTANFolder + "logs" + "\\" + "launcher.log", "MASTER SERVER LOOKUP EXCEPTION AT " + DateTime.Now + "\n\n" + ex); } } #endregion #region Registry checking (Obsolete) //splashScreen.SetPercent(35); //#region Check GTAN Folder Registry entry //var dictPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Rockstar Games\Grand Theft Auto V"; //var GTANFolder = (string)Registry.GetValue(dictPath, "GTANetworkInstallDir", null); //if (GTANFolder != AppDomain.CurrentDomain.BaseDirectory) //{ // try // { // Registry.SetValue(dictPath, "GTANetworkInstallDir", AppDomain.CurrentDomain.BaseDirectory); // } // catch (UnauthorizedAccessException) // { // MessageBox.Show(splashScreen.SplashScreen, "Insufficient permissions, Please run as Admin to avoid permission issues.(6)", "Unauthorized access"); // return; // } //} //#endregion #endregion splashScreen.SetPercent(45); #region Check required folders and clean up string Profiles = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Rockstar Games" + "\\GTA V" + "\\Profiles"; if (!Directory.Exists(Profiles)) { MessageBox.Show(splashScreen.SplashScreen, "Missing Path: " + Profiles + ", Make sure to have run the game atleast once.", "Missing files"); return; } if (!Directory.GetFiles(Profiles, "pc_settings.bin", SearchOption.AllDirectories).Any()) { MessageBox.Show(splashScreen.SplashScreen, "Missing Profile, Make sure to have run the game atleast once.", "Missing files"); return; } try { //if (Directory.Exists(settings.GamePath + "\\" + "scripts")) //{ // if (!Directory.Exists(settings.GamePath + "\\" + "Disabled")) Directory.CreateDirectory(settings.GamePath + "\\" + "Disabled"); // if (Directory.Exists(settings.GamePath + "\\" + "Disabled" + "\\" + "scripts")) DeleteDirectory(settings.GamePath + "\\" + "Disabled" + "\\" + "scripts"); // MoveDirectory(settings.GamePath + "\\" + "scripts", settings.GamePath + "\\" + "Disabled" + "\\" + "scripts"); //} foreach (var file in Directory.GetFiles(settings.GamePath, "*.asi", SearchOption.TopDirectoryOnly)) { if (!Directory.Exists(settings.GamePath + "\\" + "Disabled")) { Directory.CreateDirectory(settings.GamePath + "\\" + "Disabled"); } if (File.Exists(settings.GamePath + "\\" + "Disabled" + "\\" + Path.GetFileName(file))) { File.Delete(settings.GamePath + "\\" + "Disabled" + "\\" + Path.GetFileName(file)); } MoveFile(file, settings.GamePath + "\\" + "Disabled" + "\\" + Path.GetFileName(file)); } string[] Files = { "ClearScript.dll", "ClearScriptV8-32.dll", "ClearScriptV8-64.dll", "EasyHook64.dll", "scripthookv.dll", "ScriptHookVDotNet.dll", "v8-ia32.dll", "dinput8.dll" }; foreach (var file in Files) { if (!File.Exists(settings.GamePath + "\\" + file)) { continue; } if (!Directory.Exists(settings.GamePath + "\\" + "Disabled")) { Directory.CreateDirectory(settings.GamePath + "\\" + "Disabled"); } if (!File.Exists(settings.GamePath + "\\" + "Disabled" + "\\" + file)) { File.Delete(settings.GamePath + "\\" + "Disabled" + "\\" + file); } if (File.Exists(settings.GamePath + "\\" + "Disabled" + "\\" + file)) { File.Delete(settings.GamePath + "\\" + "Disabled" + "\\" + file); } MoveFile(settings.GamePath + "\\" + file, settings.GamePath + "\\" + "Disabled" + "\\" + file); } foreach (var file in Directory.GetFiles(Profiles, "pc_settings.bin", SearchOption.AllDirectories)) { if (!File.Exists((Path.GetDirectoryName(file) + "\\" + "SGTA50000.bak"))) { continue; } if (File.Exists(Path.GetDirectoryName(file) + "\\" + "SGTA50000")) { File.Delete(Path.GetDirectoryName(file) + "\\" + "SGTA50000"); } MoveFile(Path.GetDirectoryName(file) + "\\" + "SGTA50000.bak", Path.GetDirectoryName(file) + "\\" + "SGTA50000"); } //if (File.Exists(GTANFolder + "bin\\dinput8.dll")) //{ // File.Copy(GTANFolder + "bin\\dinput8.dll", settings.GamePath + "\\dinput8.dll"); //} //if (File.Exists(GTANFolder + "bin\\xmloader.asi")) //{ // File.Copy(GTANFolder + "bin\\xmloader.asi", settings.GamePath + "\\xmloader.asi"); //} //if (File.Exists(GTANFolder + "bin\\OpenIV.asi")) //{ // File.Copy(GTANFolder + "bin\\OpenIV.asi", settings.GamePath + "\\OpenIV.asi"); //} } catch (Exception e) { //MessageBox.Show(splashScreen.SplashScreen, "Insufficient permissions, Please run as Admin to avoid permission issues. (1)", "Unauthorized access"); MessageBox.Show(splashScreen.SplashScreen, e.ToString(), "Unauthorized access"); //MessageBox.Show(e.ToString()); return; } #endregion splashScreen.SetPercent(60); #region Patching Game Settings var mySettings = GameSettings.LoadGameSettings(); if (mySettings.Video != null) { if (mySettings.Video.PauseOnFocusLoss != null) { mySettings.Video.PauseOnFocusLoss.Value = 0; mySettings.Graphics.DX_Version.Value = 2; } } else { mySettings.Video = new GameSettings.Video(); mySettings.Video.PauseOnFocusLoss = new GameSettings.PauseOnFocusLoss(); mySettings.Video.PauseOnFocusLoss.Value = 0; mySettings.Graphics.DX_Version = new GameSettings.DX_Version(); mySettings.Graphics.DX_Version.Value = 2; mySettings.Video.Windowed = new GameSettings.Windowed(); mySettings.Video.Windowed.Value = 2; } try { GameSettings.SaveSettings(mySettings); } catch { MessageBox.Show(splashScreen.SplashScreen, "Insufficient permissions, Please run as Admin to avoid permission issues.(8)", "Unauthorized access"); return; } #endregion splashScreen.SetPercent(70); #region Patch Startup Settings //string filePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.Create) + "\\" + "Rockstar Games" + "\\" + "GTA V" + "\\" + "Profiles"; //if (!Directory.Exists(filePath)) //{ // MessageBox.Show(splashScreen.SplashScreen, "Missing GTA V Profile folder, Make sure to have run the game atleast once.", "Missing files"); // return; //} //foreach (var dir in Directory.GetDirectories(filePath)) //{ // var Path = dir + "\\" + "pc_settings.bin"; // if (!File.Exists(Path)) continue; // using (Stream stream = new FileStream(Path, FileMode.Open)) // { // stream.Seek(0xE4, SeekOrigin.Begin); // Startup Flow // _startupFlow = (byte)stream.ReadByte(); // stream.Seek(0xEC, SeekOrigin.Begin); // Landing Page // _landingPage = (byte)stream.ReadByte(); // } //} PatchStartup(); #endregion splashScreen.SetPercent(80); #region Copy over the savegame foreach (var file in Directory.GetFiles(Profiles, "pc_settings.bin", SearchOption.AllDirectories)) { try { if (File.Exists((Path.GetDirectoryName(file) + "\\" + "SGTA50000"))) { MoveFile(Path.GetDirectoryName(file) + "\\" + "SGTA50000", Path.GetDirectoryName(file) + "\\" + "SGTA50000.bak"); } if (File.Exists(GTANFolder + "savegame" + "\\" + "SGTA50000")) { File.Copy(GTANFolder + "savegame" + "\\" + "SGTA50000", Path.GetDirectoryName(file) + "\\" + "SGTA50000"); } } catch (Exception e) { //MessageBox.Show(splashScreen.SplashScreen, "Insufficient permissions, Please run as Admin to avoid permission issues. (4)", "Unauthorized access"); MessageBox.Show(splashScreen.SplashScreen, e.ToString(), "Unauthorized access"); return; } } #endregion #region Create commandline try { //if (settings.OfflineMode) //{ if (File.Exists(settings.GamePath + "\\commandline.txt")) { string text = File.ReadAllText(settings.GamePath + "\\commandline.txt"); if (!text.Contains("-scOfflineOnly")) { File.AppendAllText(settings.GamePath + "\\commandline.txt", "-scOfflineOnly"); } } else { File.AppendAllText(settings.GamePath + "\\commandline.txt", "-scOfflineOnly"); } //} //else //{ // if (File.Exists(settings.GamePath + "\\commandline.txt")) // { // string text = File.ReadAllText(settings.GamePath + "\\commandline.txt"); // text = text.Replace("-scOfflineOnly", ""); // File.WriteAllText(settings.GamePath + "\\commandline.txt", text); // } //} } catch (Exception) { MessageBox.Show(splashScreen.SplashScreen, "Insufficient permissions, Please run as Admin to avoid permission issues. (10)", "Unauthorized access"); } #endregion splashScreen.SetPercent(85); #region Launch the Game if (Directory.GetFiles(settings.GamePath, "*.wow").Length == 0) { BinaryReader br = new BinaryReader(new MemoryStream(File.ReadAllBytes(settings.GamePath + "\\" + "GTA5.exe"))); br.BaseStream.Position = 0x01500000; byte[] array = br.ReadBytes(0x35F757); string value = BitConverter.ToString(array).Replace("-", string.Empty); if (value.Contains("737465616D")) { Process.Start("steam://run/271590"); } else { Process.Start(settings.GamePath + "\\" + "GTAVLauncher.exe"); } } else { Process.Start(settings.GamePath + "\\" + "GTAVLauncher.exe"); } #endregion splashScreen.SetPercent(90); #region Wait for the Game to launch Process gta5Process; while ((gta5Process = Process.GetProcessesByName("GTA5").FirstOrDefault(p => p != null)) == null) { Thread.Sleep(100); } #endregion splashScreen.SetPercent(100); splashScreen.Stop(); #region Inject into GTAV Thread.Sleep(15000); InjectOurselves(gta5Process); #endregion //IntPtr addr = (IntPtr)0x22E139A62E1; //var sharp = new MemorySharp(gta5Process); //var toFind = new byte[] //{ // 0x4c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x47, 0x54, 0x41, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b //}; //SigScan.Classes.SigScan scanner = new SigScan.Classes.SigScan //{ // Process = gta5Process, // Address = gta5Process.MainModule.BaseAddress, // Size = 5000000 //}; //IntPtr ptr = scanner.FindPattern(toFind, "xxxxxxxxxxxxxxxxxx", 18); //var pattern = new Pattern("4c 6f 61 64 69 6e 67 20 47 54 41 4e 65 74 77 6f 72 6b", 0, false); //var result = sharp[""].FindPattern(pattern); //// if bool param above is true the result is rebased before being returned. //var offset = result.Offset; //SigScan.Classes.SigScan scanner = new SigScan.Classes.SigScan(gta5Process, new IntPtr(0x22E139A62E1), 0x1000); //IntPtr ptr = scanner.FindPattern(, "xxxxxxxxxxxxxxxxxx", 0x06); //sharp.Write(offset, 0x75); #region Terminate duplicate GTA5 processes var t = new Thread((ThreadStart) delegate { Thread.Sleep(10000); while (true) { foreach (var process in Process.GetProcesses().Where(x => x.ProcessName.ToString().ToLower().Contains("gta5") && x.Id != gta5Process.Id).ToList()) { process.Kill(); Thread.CurrentThread.Abort(); } Thread.Sleep(1000); } }); t.Start(); #endregion #region Wait for GTA5 to exit var launcherProcess = Process.GetProcessesByName("GTAVLauncher").FirstOrDefault(p => p != null); while (!gta5Process.HasExited || (launcherProcess != null && !launcherProcess.HasExited)) { Thread.Sleep(1000); } Thread.Sleep(1000); t.Abort(); #endregion #region Cleanup try { //if (File.Exists(settings.GamePath + "\\dinput8.dll")) //{ // File.Delete(settings.GamePath + "\\dinput8.dll"); //} //if (File.Exists(settings.GamePath + "\\xmloader.asi")) //{ // File.Delete(settings.GamePath + "\\xmloader.asi"); //} //if (File.Exists(settings.GamePath + "\\OpenIV.asi")) //{ // File.Delete(settings.GamePath + "\\OpenIV.asi"); //} if (File.Exists(settings.GamePath + "\\commandline.txt")) { string text = File.ReadAllText(settings.GamePath + "\\commandline.txt"); text = text.Replace("-scOfflineOnly", ""); File.WriteAllText(settings.GamePath + "\\commandline.txt", text); } } catch (Exception e) { //MessageBox.Show(splashScreen.SplashScreen, "Insufficient permissions, Please run as Admin to avoid permission issues. (11)", "Unauthorized access"); MessageBox.Show(splashScreen.SplashScreen, e.ToString(), "Unauthorized access"); } #endregion #region Restore save game foreach (var file in Directory.GetFiles(Profiles, "pc_settings.bin", SearchOption.AllDirectories)) { try { if (File.Exists((Path.GetDirectoryName(file) + "\\" + "SGTA50000"))) { File.Delete(Path.GetDirectoryName(file) + "\\" + "SGTA50000"); } if (File.Exists((Path.GetDirectoryName(file) + "\\" + "SGTA50000.bak"))) { MoveFile(Path.GetDirectoryName(file) + "\\" + "SGTA50000.bak", Path.GetDirectoryName(file) + "\\" + "SGTA50000"); } } catch (Exception) { MessageBox.Show(splashScreen.SplashScreen, "Insufficient permissions, Please run as Admin to avoid permission issues. (5)", "Unauthorized access"); return; } } #endregion }
static void Main() { ParseableVersion subprocessVersion = new ParseableVersion(0, 0, 0, 0); if (File.Exists("MultiV.dll")) { var versiontext = System.Diagnostics.FileVersionInfo.GetVersionInfo("MultiV.dll").FileVersion.ToString(); subprocessVersion = ParseableVersion.Parse(versiontext); } var playerSetings = new PlayerSettings(); if (File.Exists("settings.xml")) { var ser = new XmlSerializer(typeof(PlayerSettings)); using (var stream = File.OpenRead("settings.xml")) { playerSetings = (PlayerSettings)ser.Deserialize(stream); } } else { var ser = new XmlSerializer(typeof(PlayerSettings)); using (var stream = File.OpenWrite("settings.xml")) { ser.Serialize(stream, playerSetings); } } try { using (var wc = new ImpatientWebClient()) { var internetTextVersion = wc.DownloadString(playerSetings.MasterServerAddress.Trim('/') + "/launcherversion"); var internetVersion = ParseableVersion.Parse(internetTextVersion); if (internetVersion > subprocessVersion) { wc.DownloadFile(playerSetings.MasterServerAddress.Trim('/') + "/launcher", "MultiV.dll"); } } } catch (WebException) { } IEnumerable <Type> validTypes; try { var ourAssembly = Assembly.LoadFrom("MultiV.dll"); var types = ourAssembly.GetExportedTypes(); validTypes = types.Where(t => !t.IsInterface && !t.IsAbstract) .Where(t => typeof(ISubprocessBehaviour).IsAssignableFrom(t)); } catch (Exception e) { MessageBox.Show("ERROR: " + e.Message, "CRITICAL ERROR"); goto end; } if (!validTypes.Any()) { MessageBox.Show("Failed to load assembly \"MultiV.dll\": no assignable classes found.", "CRITICAL ERROR"); goto end; } ISubprocessBehaviour mainBehaviour = null; foreach (var type in validTypes) { mainBehaviour = Activator.CreateInstance(type) as ISubprocessBehaviour; if (mainBehaviour != null) { break; } } if (mainBehaviour == null) { MessageBox.Show("Failed to load assembly \"MultiV.dll\": assignable class is null.", "CRITICAL ERROR"); goto end; } mainBehaviour.Start(); end: { } }