diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index b42ddc0..a8ffc09 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -23,7 +23,7 @@ jobs: working-directory: ./bin/Release run: | Copy-Item "..\..\launcher.json" -Destination "." - Compress-Archive -Path .\CardboardLauncher.exe, .\launcher.json, .\Newtonsoft.Json.dll -DestinationPath CardboardLauncher.zip + Compress-Archive -Path .\CardboardLauncher.exe, .\launcher.json, .\Newtonsoft.Json.dll, .\Facepunch.Steamworks.Win64.dll, .\Microsoft.Web.WebView2.Core.dll, .\Microsoft.Web.WebView2.WinForms.dll, .\runtimes -DestinationPath CardboardLauncher.zip - name: Create Release id: create_release uses: actions/create-release@v1 diff --git a/CardboardLauncher.csproj b/CardboardLauncher.csproj index 03d8a46..92fbd9c 100644 --- a/CardboardLauncher.csproj +++ b/CardboardLauncher.csproj @@ -27,6 +27,8 @@ false false true + + AnyCPU @@ -62,6 +64,12 @@ packages\Facepunch.Steamworks.2.3.3\lib\net46\Facepunch.Steamworks.Win64.dll + + packages\Microsoft.Web.WebView2.1.0.1823.32\lib\net45\Microsoft.Web.WebView2.Core.dll + + + packages\Microsoft.Web.WebView2.1.0.1823.32\lib\net45\Microsoft.Web.WebView2.WinForms.dll + packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -138,4 +146,11 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 36c2ff0..8874375 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -1,4 +1,6 @@ -namespace CardboardLauncher +using Microsoft.Web.WebView2.Core; + +namespace CardboardLauncher { partial class mainForm { @@ -33,15 +35,15 @@ private void InitializeComponent() this.archRadio64 = new System.Windows.Forms.RadioButton(); this.archRadio32 = new System.Windows.Forms.RadioButton(); this.playButton = new System.Windows.Forms.Button(); - this.webLauncher = new System.Windows.Forms.WebBrowser(); + this.webLauncher = new Microsoft.Web.WebView2.WinForms.WebView2(); this.homeDirBrowser = new System.Windows.Forms.FolderBrowserDialog(); this.homeDirGroup = new System.Windows.Forms.GroupBox(); this.homeDirBtn = new System.Windows.Forms.Button(); this.homeDirBox = new System.Windows.Forms.TextBox(); this.versionLabel = new System.Windows.Forms.Label(); this.webWarn = new System.Windows.Forms.Panel(); - this.label2 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); + this.technicalBody = new System.Windows.Forms.Label(); + this.technicalTitle = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.userAuthLabel = new System.Windows.Forms.Label(); this.gameTokenBtn = new System.Windows.Forms.Button(); @@ -57,6 +59,7 @@ private void InitializeComponent() this.playOfflineChkBox = new System.Windows.Forms.CheckBox(); this.panel1 = new System.Windows.Forms.Panel(); this.archGroup.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.webLauncher)).BeginInit(); this.homeDirGroup.SuspendLayout(); this.webWarn.SuspendLayout(); this.groupBox1.SuspendLayout(); @@ -122,18 +125,17 @@ private void InitializeComponent() // // webLauncher // - this.webLauncher.AllowWebBrowserDrop = false; + this.webLauncher.AllowExternalDrop = false; + this.webLauncher.CreationProperties = null; + this.webLauncher.DefaultBackgroundColor = this.BackColor; this.webLauncher.Location = new System.Drawing.Point(533, 326); this.webLauncher.MinimumSize = new System.Drawing.Size(20, 20); this.webLauncher.Name = "webLauncher"; - this.webLauncher.ScrollBarsEnabled = false; this.webLauncher.Size = new System.Drawing.Size(590, 410); this.webLauncher.TabIndex = 2; - this.webLauncher.Url = new System.Uri("", System.UriKind.Relative); - this.webLauncher.Visible = false; - this.webLauncher.WebBrowserShortcutsEnabled = false; - this.webLauncher.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webLauncher_Loaded); - this.webLauncher.Navigating += new System.Windows.Forms.WebBrowserNavigatingEventHandler(this.webLauncher_Navigating); + this.webLauncher.ZoomFactor = 1D; + this.webLauncher.NavigationStarting += new System.EventHandler(this.webLauncher_Navigating); + this.webLauncher.NavigationCompleted += new System.EventHandler(this.webLauncher_Loaded); // // homeDirBrowser // @@ -191,38 +193,40 @@ private void InitializeComponent() // webWarn // this.webWarn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(18))))); - this.webWarn.Controls.Add(this.label2); - this.webWarn.Controls.Add(this.label1); + this.webWarn.Controls.Add(this.technicalBody); + this.webWarn.Controls.Add(this.technicalTitle); this.webWarn.Controls.Add(this.webLauncher); this.webWarn.Location = new System.Drawing.Point(206, 34); this.webWarn.Name = "webWarn"; this.webWarn.Size = new System.Drawing.Size(596, 416); this.webWarn.TabIndex = 4; // - // label2 + // technicalBody // - this.label2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label2.ForeColor = System.Drawing.SystemColors.Control; - this.label2.Location = new System.Drawing.Point(8, 166); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(580, 84); - this.label2.TabIndex = 4; - this.label2.Text = "Looks like our servers are having some issues!\r\nDon\'t worry, you can still play i" + + this.technicalBody.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.technicalBody.ForeColor = System.Drawing.SystemColors.Control; + this.technicalBody.Location = new System.Drawing.Point(8, 166); + this.technicalBody.Name = "technicalBody"; + this.technicalBody.Size = new System.Drawing.Size(580, 84); + this.technicalBody.TabIndex = 4; + this.technicalBody.Text = "Looks like our servers are having some issues!\r\nDon\'t worry, you can still play i" + "n offline mode until the issues are resolved!\r\n\r\nSorry about that, we\'ll get eve" + "rything working as soon as we can!"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Segoe UI", 48F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(36)))), ((int)(((byte)(0))))); - this.label1.Location = new System.Drawing.Point(191, 40); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(214, 86); - this.label1.TabIndex = 3; - this.label1.Text = "Oops!"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.technicalBody.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.technicalBody.Visible = false; + // + // technicalTitle + // + this.technicalTitle.AutoSize = true; + this.technicalTitle.Font = new System.Drawing.Font("Segoe UI", 48F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.technicalTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(36)))), ((int)(((byte)(0))))); + this.technicalTitle.Location = new System.Drawing.Point(191, 40); + this.technicalTitle.Name = "technicalTitle"; + this.technicalTitle.Size = new System.Drawing.Size(214, 86); + this.technicalTitle.TabIndex = 3; + this.technicalTitle.Text = "Oops!"; + this.technicalTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.technicalTitle.Visible = false; // // groupBox1 // @@ -429,6 +433,7 @@ private void InitializeComponent() this.Load += new System.EventHandler(this.mainForm_Load); this.archGroup.ResumeLayout(false); this.archGroup.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.webLauncher)).EndInit(); this.homeDirGroup.ResumeLayout(false); this.homeDirGroup.PerformLayout(); this.webWarn.ResumeLayout(false); @@ -452,7 +457,7 @@ private void InitializeComponent() private System.Windows.Forms.RadioButton archRadio32; private System.Windows.Forms.RadioButton archRadio64; private System.Windows.Forms.Button playButton; - private System.Windows.Forms.WebBrowser webLauncher; + private Microsoft.Web.WebView2.WinForms.WebView2 webLauncher; private System.Windows.Forms.FolderBrowserDialog homeDirBrowser; private System.Windows.Forms.GroupBox homeDirGroup; private System.Windows.Forms.TextBox homeDirBox; @@ -473,8 +478,8 @@ private void InitializeComponent() private System.Windows.Forms.Panel advSettings; private System.Windows.Forms.CheckBox playOfflineChkBox; private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label technicalBody; + private System.Windows.Forms.Label technicalTitle; } } diff --git a/MainForm.cs b/MainForm.cs index 706d67e..93f8d42 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -5,6 +5,8 @@ using System.Net; using System.Security.Permissions; using System.Windows.Forms; +using Microsoft.Web.WebView2.Core; +using Microsoft.Web.WebView2.WinForms; using Newtonsoft.Json; using Steamworks; @@ -26,6 +28,7 @@ public partial class mainForm : Form private Config config; + private string trusted_url = @"https://harpnetstudios.com"; private string api_url = @"https://harpnetstudios.com/hnid/api/"; private string migratePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Project Crimson Alpha"); @@ -123,10 +126,10 @@ private void CheckVersion() DisplayMessage(string.Format("Looks like your launcher is out of date!\n\nNew version available: {0}\nYour version: {1}", content, ver.ToString()), "Launcher Update", MessageBoxButtons.OK, MessageBoxIcon.Information); } } - catch(WebException e) + catch(WebException) { - technicalIssues = true; - webLauncher.Visible = false; + technicalIssues = technicalBody.Visible = technicalTitle.Visible = true; + //webLauncher.Visible = false; playOfflineChkBox.Checked = true; } } @@ -212,17 +215,13 @@ public mainForm() webLauncher.Location = new Point(3, 3); webLauncher.BringToFront(); - - webLauncher.Document.BackColor = this.BackColor; - #if DEBUG - webLauncher.ScriptErrorsSuppressed = false; - #else - webLauncher.ScriptErrorsSuppressed = true; - #endif + + webLauncher.DefaultBackgroundColor = this.BackColor; LoadConfig(); CheckVersion(); + if (args.Length > 1 && args[1] == "--steam") ValidateSteam(); GrabInfo(config.gameToken); if(config.homeDir == "") config.homeDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Carmine Impact Alpha"); @@ -236,8 +235,6 @@ public mainForm() pageSelectCombo.SelectedIndex = 0; // HNID - webLauncher.ObjectForScripting = this; - webLauncher.Url = new Uri(config.webUrl); this.Text = launcherTitle.Text = LauncherInfo.gameName + " Launcher"; playButton.Text = "&Play " + LauncherInfo.gameName; versionLabel.Text = "Launcher Version " + typeof(Program).Assembly.GetName().Version; @@ -282,11 +279,6 @@ public void displayMessage(String message) { DisplayMessage(message, "Webpage"); } - - public void setScroll(bool scroll) - { - this.webLauncher.ScrollBarsEnabled = scroll; - } public void setGameToken(string token, bool quiet=true) { @@ -386,40 +378,67 @@ private void versionLabel_DoubleClick(object sender, EventArgs e) DisplayMessage("Created by Yellowberry.\n\nSpecial thanks to the rest of the HarpNet crew!"); } - private void mainForm_Load(object sender, EventArgs e) + private async void mainForm_Load(object sender, EventArgs e) { - webLauncher.ObjectForScripting = this; + webLauncher.DefaultBackgroundColor = this.BackColor; + + await webLauncher.EnsureCoreWebView2Async(); + + webLauncher.CoreWebView2.AddWebResourceRequestedFilter($"*", CoreWebView2WebResourceContext.All); + + webLauncher.CoreWebView2.WebResourceRequested += webLauncher_AddLauncherHeader; + webLauncher.CoreWebView2.NewWindowRequested += webLauncher_ExternalLink; + + webLauncher.CoreWebView2.Settings.IsSwipeNavigationEnabled = false; + webLauncher.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false; + webLauncher.CoreWebView2.Settings.IsGeneralAutofillEnabled = false; + webLauncher.CoreWebView2.Settings.IsPasswordAutosaveEnabled = false; + webLauncher.CoreWebView2.Settings.AreHostObjectsAllowed = true; + webLauncher.CoreWebView2.Settings.IsBuiltInErrorPageEnabled = false; + webLauncher.CoreWebView2.Settings.IsPinchZoomEnabled = false; + webLauncher.CoreWebView2.Settings.IsReputationCheckingRequired = false; + webLauncher.CoreWebView2.Settings.IsZoomControlEnabled = false; + webLauncher.CoreWebView2.Settings.IsStatusBarEnabled = false; + + #if DEBUG + webLauncher.CoreWebView2.Settings.AreDevToolsEnabled = true; + webLauncher.CoreWebView2.Settings.AreDefaultContextMenusEnabled = true; + #else + webLauncher.CoreWebView2.Settings.AreDevToolsEnabled = false; + webLauncher.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; + #endif + + webLauncher.CoreWebView2.AddHostObjectToScript("form", this); + + webLauncher.CoreWebView2.Settings.UserAgent += $" CardboardLauncher/{typeof(Program).Assembly.GetName().Version}"; + + webLauncher.Source = new Uri(config.webUrl); } - private void webLauncher_Navigating(object sender, WebBrowserNavigatingEventArgs e) + private void webLauncher_Navigating(object sender, CoreWebView2NavigationStartingEventArgs e) { - webLauncher.Document.BackColor = this.BackColor; - this.webLauncher.ScrollBarsEnabled = false; - if(e.Url.ToString() == "about:blank") { return; } - - string extForce = "#_force"; - string safeSite = "https://harpnetstudios.com/"; + //this.webLauncher.ScrollBarsEnabled = false; + if(e.Uri.ToString() == "about:blank") { return; } - Console.WriteLine(e.Url.ToString()); - if(!e.Url.ToString().StartsWith(safeSite)&&e.Url.ToString()!="about:blank") + Console.WriteLine(e.Uri.ToString()); + if(!e.Uri.ToString().StartsWith(trusted_url)&&e.Uri.ToString()!="about:blank") { webWarn.BackColor = Color.Red; + technicalTitle.ForeColor = this.BackColor; } else { webWarn.BackColor = this.BackColor; - - if (e.Url.ToString().EndsWith(extForce)) - { - //cancel the current event - e.Cancel = true; - - //this opens the URL in the user's default browser - Process.Start(e.Url.ToString().Remove(e.Url.ToString().Length - extForce.Length)); - } + technicalTitle.ForeColor = Color.FromArgb(255,36,0); } } + private void webLauncher_ExternalLink(object sender, CoreWebView2NewWindowRequestedEventArgs e) + { + e.Handled = true; + Process.Start(e.Uri.ToString()); + } + private void gameTokenBtn_Click(object sender, EventArgs e) { GametokenDialog gtDialog = new GametokenDialog(); @@ -523,9 +542,21 @@ private void playOfflineChkBox_CheckedChanged(object sender, EventArgs e) } } - private void webLauncher_Loaded(object sender, WebBrowserDocumentCompletedEventArgs e) + private void webLauncher_Loaded(object sender, CoreWebView2NavigationCompletedEventArgs e) + { + if (e.IsSuccess) + { + //((WebView2)sender).ExecuteScriptAsync("document.querySelector('body').style.overflow='hidden'"); + } + } + + private void webLauncher_AddLauncherHeader(object sender, CoreWebView2WebResourceRequestedEventArgs e) { - if (!webLauncher.Visible && !technicalIssues) webLauncher.Visible = true; + e.Request.Headers.SetHeader("X-Launcher-Version", typeof(Program).Assembly.GetName().Version.ToString()); + if(!string.IsNullOrEmpty(config.gameToken)) + { + e.Request.Headers.SetHeader("X-Game-Token", config.gameToken); + } } } } diff --git a/MainForm.resx b/MainForm.resx index d025509..1c5b847 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - 49 @@ -1723,4 +1720,7 @@ YQAAAABJRU5ErkJggg== + + 17, 17 + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 5196dce..5338293 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace CardboardLauncher.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/packages.config b/packages.config index 8778563..a6542d8 100644 --- a/packages.config +++ b/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file