public void RunGame(String s) { //MessageBox.Show(message, "executed RunGame"); string myparams = "?from_standalone=1"; if (File.Exists("data\\Plazma Burst 2.auth")) { String login = File.ReadAllText("data\\Plazma Burst 2.auth").Split('\n', 2)[0]; Aes aes = new Aes(); String plaintextPass = aes.getPlaintextPassword(); //Retrieved password, set object to null for garbage collection. aes = null; //File.WriteAllText("_debug.txt", "Password: "******"?l=" + login + "&p=" + plaintextPass + "&from_standalone=1"; } ProcessStartInfo startInfo = new ProcessStartInfo("data\\flashplayer11_7r700_224_win_sa.exe"); startInfo.WindowStyle = ProcessWindowStyle.Normal; if (s == "") { startInfo.Arguments = "\"data\\pb2_re34_alt.swf" + myparams + "\""; } else { startInfo.Arguments = "\"data\\" + s + "\""; } Process p = Process.Start(startInfo); p.WaitForInputIdle(); int xx = this.Size.Width - this.ClientSize.Width; int yy = this.Size.Height - this.ClientSize.Height; if (s == "") { SetWindowText(p.MainWindowHandle, "Plazma Burst 2"); } else if (s == "plazma_burst_fttp.swf") { SetWindowText(p.MainWindowHandle, "Plazma Burst: Forward to the Past"); } WindowsReStyle(p); IntPtr m_pIcon; // Load the empty icon (from a file in this example) //string strIconFilePath = @"C:\_HomeData\PC\projects fl\PB2\publish exe 2\Plazma Burst 2\data\favicon.ico"; // Replace with a valid path on your system! string strIconFilePath = Directory.GetCurrentDirectory() + "\\data\\favicon.ico"; const int IMAGE_ICON = 1; const int LR_LOADFROMFILE = 0x10; // edit: IntPtr pIcon = LoadImage(IntPtr.Zero, strIconFilePath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); m_pIcon = LoadImage(IntPtr.Zero, strIconFilePath, (IntPtr)IMAGE_ICON, (IntPtr)0, (IntPtr)0, (IntPtr)LR_LOADFROMFILE); SendMessage(p.MainWindowHandle, 0x80, IntPtr.Zero, m_pIcon); SetWindowPos( p.MainWindowHandle, 0, this.Left + this.Size.Width / 2 - 800 / 2 - xx / 2, this.Top, 800 + xx, 400 + yy, 0x0000 //0x0001 // SWP_NOSIZE ); if (this.WindowState == FormWindowState.Maximized) { ShowWindow(p.MainWindowHandle, SW_MAXIMIZE); } // Task.Delay( 1000 ); this.Close(); /* * this.WindowState = FormWindowState.Minimized; * * p.WaitForExit(); * * * this.WindowState = FormWindowState.Normal; * //this.BringToFront(); * this.Activate(); * * * //if (!IsOnline) * { * this.Close(); * }*/ }
public Form1() { InitializeComponent(); if (!Directory.Exists("data")) { MessageBox.Show("Try to unpack contents of this .zip archieve before executing it (application was not able to find 'data' folder near .exe file, usually it only happens when launcher is being executed in .zip archieve and not extracted).", "Unable to continue", MessageBoxButtons.OK, MessageBoxIcon.None); //this.Close(); //return; //System.Windows.Forms.Application.Exit(); System.Environment.Exit(0); return; } /*Gecko.Xpcom.Initialize(@"C:\_HomeData\PC\Projects C#\PB2Launcher\xulrunner"); * * //Xpcom.Initialize("Firefox"); * webBrowser1 = new GeckoWebBrowser { Dock = DockStyle.Fill }; * //Form f = new Form(); * //f.Controls.Add(geckoWebBrowser); * webBrowser1.Navigate("www.google.com"); * // Application.Run(f); */ webBrowser1 = new WebBrowser(); webBrowser1.Size = new Size(this.ClientSize.Width, this.ClientSize.Height); webBrowser1.AllowWebBrowserDrop = false; //webBrowser1.IsWebBrowserContextMenuEnabled = false; //webBrowser1.WebBrowserShortcutsEnabled = false; webBrowser1.ObjectForScripting = this; this.Controls.Add(webBrowser1); try { webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(OnDocumentCompleted); webBrowser1.Navigate("https://www.plazmaburst2.com/launcher/index.php"); //webBrowser1.Navigate("about:blank"); /*WebClient myWebClient_html_page = new WebClient(); * byte[] myDataBuffer_html_page = myWebClient_html_page.DownloadData("https://www.plazmaburst2.com/launcher/index.php"); * webBrowser1.Document.Write(String.Empty); * webBrowser1.DocumentText = System.Text.Encoding.UTF8.GetString( myDataBuffer_html_page );*/ } catch (System.UriFormatException) { File.WriteAllTextAsync("_error2.v", "URI format exception - could not navigate"); /*try * { * webBrowser1.Navigate("https://www.plazmaburst2.com/launcher/index.php"); * } * catch(System.UriFormatException) * { * File.WriteAllTextAsync("_error3.v", "URI format exception - could not navigate. But was able to proceed with regular string"); * }*/ return; } /* * Flow of this part of the code: * 1. Attempt to decrypt and retrieve password through getPlaintextPassword() * * If successful: * 2. Check if 3 days has passed, generate a new key if so * * Failing to decrypt it. (Invalid key: Possible sceanrios include: First time launching / PB2Launcher folder was shared..) * - Generate a new key (at CryptographicException exception block) */ //--------------------------------------------------------------------------------------------------------- Aes aes = new Aes(); try { //Step 1. //If missing .auth file, returns N/A. //If missing key file or invalid key, CryptographicException will be thrown. String plaintextPass = aes.getPlaintextPassword(); //If missing .auth file, regenerate key and ask for login (jump into CryptographicException exception block). if (plaintextPass.Equals("N/A")) { Console.WriteLine("\nMissing .auth file, throwing exception to regenerate key.."); throw new CryptographicException(); } //Reaching here, decryption is successful. Plaintext of password is obtained. Console.WriteLine("Successful decryption."); //Step 2. Verify if key is not older than MAX_KEY_LIFE days. //If key is older, key will be regenerated without needing to reprompt login. aes.verifyAge(GetLogin(), plaintextPass); } //Only catch if it's an exception related to decryption. //Key is invalid, don't skip authentication and regenerate key. catch (CryptographicException) { Console.WriteLine("-----\nDecryption failed"); //File.WriteAllTextAsync("_error5.v", "Exception during decryption; this indicates invalid key. Re-generating another key..\n" + ex.ToString()); //By deleting both of these files before WindowsForm loads, user will have to reprompt credentials. File.Delete("data\\skip_auth.v"); File.Delete("data\\Plazma Burst 2.auth"); //Setting ForceRegenerate to 1, generating key even with key file. aes.setKey(1); } //This block of code should never happen. catch (Exception ex) { File.WriteAllTextAsync("errorFatal.txt", "Fatal error, " + ex.ToString()); Application.Exit(); } //--------------------------------------------------------------------------------------------------------- }