From 58ff74bd200b3cee5390b027fb91f9530e8633fa Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Wed, 5 Jan 2022 01:28:13 -0800 Subject: [PATCH 01/66] build: add publishing profiles --- ...e_net6.0-windows_framework-dependent.pubxml | 17 +++++++++++++++++ .../Release_net6.0-windows_win-x64.pubxml | 18 ++++++++++++++++++ .../Release_net6.0-windows_win-x86.pubxml | 18 ++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/Properties/PublishProfiles/Release_net6.0-windows_framework-dependent.pubxml create mode 100644 src/Properties/PublishProfiles/Release_net6.0-windows_win-x64.pubxml create mode 100644 src/Properties/PublishProfiles/Release_net6.0-windows_win-x86.pubxml diff --git a/src/Properties/PublishProfiles/Release_net6.0-windows_framework-dependent.pubxml b/src/Properties/PublishProfiles/Release_net6.0-windows_framework-dependent.pubxml new file mode 100644 index 00000000..efa692e9 --- /dev/null +++ b/src/Properties/PublishProfiles/Release_net6.0-windows_framework-dependent.pubxml @@ -0,0 +1,17 @@ + + + + + Release + Any CPU + ..\bin\Release\net6.0-windows\publish\ + FileSystem + net6.0-windows + false + true + true + + + diff --git a/src/Properties/PublishProfiles/Release_net6.0-windows_win-x64.pubxml b/src/Properties/PublishProfiles/Release_net6.0-windows_win-x64.pubxml new file mode 100644 index 00000000..7dd060fb --- /dev/null +++ b/src/Properties/PublishProfiles/Release_net6.0-windows_win-x64.pubxml @@ -0,0 +1,18 @@ + + + + + Release + Any CPU + ..\bin\Release\net6.0-windows\win-x64\publish\ + FileSystem + net6.0-windows + true + true + true + win-x64 + False + + diff --git a/src/Properties/PublishProfiles/Release_net6.0-windows_win-x86.pubxml b/src/Properties/PublishProfiles/Release_net6.0-windows_win-x86.pubxml new file mode 100644 index 00000000..bf2b3263 --- /dev/null +++ b/src/Properties/PublishProfiles/Release_net6.0-windows_win-x86.pubxml @@ -0,0 +1,18 @@ + + + + + Release + Any CPU + ..\bin\Release\net6.0-windows\win-x64\publish\ + FileSystem + net6.0-windows + true + true + true + win-x86 + False + + From 6f9868c1b8c86e46bea7bb9a1348b94444be7a91 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:47:05 -0800 Subject: [PATCH 02/66] ci(release): change RID to a matrix variable for win-x86, win-x64 --- .github/workflows/release.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aaafcec2..0de50af8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,10 +18,13 @@ jobs: name: Build runs-on: windows-latest env: - RID: "win-x86" TFM: "net5.0-windows" ASSEMBLYNAME: "HXE" PROJPATH: "./src/HXE.csproj" + strategy: + fail-fast: false + matrix: + RID: [ "win-x86", "win-x64" ] steps: ################ @@ -53,7 +56,7 @@ jobs: # BUILD ################ - name: dotnet-publish - run: dotnet publish $env:CSPROJ_RELPATH -c Release --no-self-contained -p:ContinuousIntegrationBuild=true + run: dotnet publish $env:CSPROJ_RELPATH -c Release --no-self-contained -t ${{ env.TFM }} --RID ${{ matrix.RID }} -p:ContinuousIntegrationBuild=true # required variables: TargetFramework, RuntimeIdentifier, GitVersion_FullSemVer - name: Compress-PublishArtifacts @@ -77,7 +80,7 @@ jobs: uses: actions/upload-artifact@v2 with: name: publish-artifacts - path: bin/Release/${{ env.TFM }}/${{ env.RID }}/publish + path: bin/Release/${{ env.TFM }}/${{ matrix.RID }}/publish - name: Publish to GitHub Packages working-directory: bin/Release From ebbebb485c8e38a8e2395e67217d409f2fbd336f Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:48:59 -0800 Subject: [PATCH 03/66] ci:(release): de-ref CSPROJ_RELPATH via workflow syntax instead of Posh sytax --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0de50af8..9ef090b1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,7 +56,7 @@ jobs: # BUILD ################ - name: dotnet-publish - run: dotnet publish $env:CSPROJ_RELPATH -c Release --no-self-contained -t ${{ env.TFM }} --RID ${{ matrix.RID }} -p:ContinuousIntegrationBuild=true + run: dotnet publish ${{ env.CSPROJ_RELPATH }} -c Release -t ${{ env.TFM }} --RID ${{ matrix.RID }} -p:ContinuousIntegrationBuild=true # required variables: TargetFramework, RuntimeIdentifier, GitVersion_FullSemVer - name: Compress-PublishArtifacts From ee202e4dc5044a20929c44dc7ed87f92015b0697 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:49:45 -0800 Subject: [PATCH 04/66] ci(release): trim comments and empty lines for Dotnet block --- .github/workflows/release.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9ef090b1..d38ada73 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,15 +40,12 @@ jobs: - run: npm install # Dependents: Semantic Release - # Authenticates packages to push to GPR - uses: actions/setup-dotnet@v1 with: - dotnet-version: "6.0.x" # SDK Version to use. + dotnet-version: "6.0.x" include-prerelease: true - - name: Add GitHub Package Repository run: dotnet nuget add source https://nuget.pkg.github.com/HaloSPV3/index.json -n "github" -u USERNAME -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text - - name: Set NuGet.org Credentials run: dotnet nuget update source "nuget.org" -u USERNAME -p ${{ secrets.NUGET_TOKEN }} --store-password-in-clear-text From 909c4d80964c44b95fd23d041e4506684b2e664b Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:50:24 -0800 Subject: [PATCH 05/66] ci(release): set Target Framework to net6.0-windows --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d38ada73..fc100937 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: name: Build runs-on: windows-latest env: - TFM: "net5.0-windows" + TFM: "net6.0-windows" ASSEMBLYNAME: "HXE" PROJPATH: "./src/HXE.csproj" strategy: From ae54b9d67f5e79d806dcb5da73fe3ba84cf7debf Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:52:42 -0800 Subject: [PATCH 06/66] ci(release): change path of packaged Publish artifacts --- .github/workflows/release.yml | 4 ++-- .releaserc.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fc100937..7606e9e8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,7 +61,7 @@ jobs: $publishPath = Resolve-Path ".\bin\Release\$env:TFM\$env:RID\publish"; $archiveName = "$env:ASSEMBLYNAME.$env:TFM-$env:RID.$env:GitVersion_FullSemVer.zip"; Set-Location $publishPath; - Compress-Archive -Path $publishPath -DestinationPath $archiveName -CompressionLevel Optimal; + Compress-Archive -Path $publishPath -DestinationPath ${{ github.workspace }}\bin\Release\publish\$archiveName -CompressionLevel Optimal; ################ # RELEASE @@ -77,7 +77,7 @@ jobs: uses: actions/upload-artifact@v2 with: name: publish-artifacts - path: bin/Release/${{ env.TFM }}/${{ matrix.RID }}/publish + path: bin/Release/publish - name: Publish to GitHub Packages working-directory: bin/Release diff --git a/.releaserc.yaml b/.releaserc.yaml index 2217cbd9..ed0801b5 100644 --- a/.releaserc.yaml +++ b/.releaserc.yaml @@ -28,7 +28,7 @@ ['@semantic-release/github', { "assets": [ - {"path": "bin/release/win-x64/publish"} + {"path": "bin/release/publish"} ] } ] From 62fef9b2549b253af19182969e6e04cc51fc2b49 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:57:04 -0800 Subject: [PATCH 07/66] build: IncludeNativeLibrariesForSelfExtract The .NET runtime depependency sni.dll will now be embedded in our app. Why is it a default dependency of win-x64? and win-x86? Why is it copied to the Publish folder if it's a prerequisite of the .NET runtime? --- src/HXE.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/HXE.csproj b/src/HXE.csproj index c09650e2..81701542 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -37,8 +37,7 @@ true - win-x86 - + true {ACAA5D9F-B23D-43E1-B2DF-8C03230975A1} Properties From b81b70a46673d73f285dc307ac336e6d2b506bf7 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:57:39 -0800 Subject: [PATCH 08/66] build: EnableCompressionInSingleFile --- src/HXE.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HXE.csproj b/src/HXE.csproj index 81701542..ef15924d 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -37,6 +37,7 @@ true + true true {ACAA5D9F-B23D-43E1-B2DF-8C03230975A1} From b1ca4a00be7ad97b163f932a97653658681e4f0f Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:58:23 -0800 Subject: [PATCH 09/66] build: if undefined, set RuntimeIdentifier to win-x64 --- src/HXE.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HXE.csproj b/src/HXE.csproj index ef15924d..8c33b80e 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -36,6 +36,7 @@ + win-x64 true true true From 948d8f8cba97536ad67d0b10c006baf6eacc4cf0 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 01:59:29 -0800 Subject: [PATCH 10/66] build: explicitly enable SelfContained --- src/HXE.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HXE.csproj b/src/HXE.csproj index 8c33b80e..e812a282 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -36,6 +36,7 @@ + true win-x64 true true From 20ddf0cebeb9601627903476fac7aa5d280e88dd Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 02:00:00 -0800 Subject: [PATCH 11/66] build: enable isTrimmable --- src/HXE.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HXE.csproj b/src/HXE.csproj index e812a282..a468f4f6 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -34,7 +34,7 @@ https://github.com/HaloSPV3/HXE snupkg - + true true win-x64 From b31efb9514a01bcd727058d61d5afdaa436ba518 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 02:10:01 -0800 Subject: [PATCH 12/66] fix: replace WMI for filesystem compression with DotNet functionality I hope this works the way I think it does. I'm worried the attribute will be set without the file being compressed. --- src/HXE.csproj | 1 - src/Installer.cs | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/HXE.csproj b/src/HXE.csproj index a468f4f6..954a62c4 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -119,7 +119,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - diff --git a/src/Installer.cs b/src/Installer.cs index 52a1447c..651ed81d 100644 --- a/src/Installer.cs +++ b/src/Installer.cs @@ -22,7 +22,6 @@ using System; using System.IO; using System.IO.Compression; -using System.Management; using System.Threading; using System.Threading.Tasks; using HXE.Properties; @@ -70,18 +69,20 @@ public static void Install(string source, string target, IProgress progr if (!Directory.Exists(target)) Directory.CreateDirectory(target); - if (enableLZNT1) + if (enableLZNT1) /// TODO: refactor to new Method for use from other Classes. { - var dirInfo = new DirectoryInfo(target); - if ((dirInfo.Attributes & FileAttributes.Compressed) != FileAttributes.Compressed) + string[] directories = Directory.GetDirectories(target); + string[] files = Directory.GetFiles(target); + foreach (string directoryPath in directories) { - var objPath = $"Win32_Directory.Name='{target}'"; - using (var dir = new ManagementObject(objPath)) - { - var outParams = dir.InvokeMethod("Compress", null, null); - uint ret = (uint) outParams.Properties["ReturnValue"].Value; - } + new DirectoryInfo(directoryPath).Attributes |= FileAttributes.Compressed; } + foreach (string filePath in files) + { + new FileInfo(filePath).Attributes |= FileAttributes.Compressed; + } + + /// TODO: Introduce and display progress of changes using Events } Info("Gracefully created target directory"); From 929c51ea1a0d49e55bdcb95c808da522fc74ed06 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 02:27:04 -0800 Subject: [PATCH 13/66] chore(vscode): add markdown rules --- .vscode/settings.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2e4b7d93..5a3b6411 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,5 +15,11 @@ "conv-pr", // Conventional Pull Request config "commitizen", "pull-requests" // pull requests workflow - ] + ], + "markdownlint.config": { + "MD028": false, + "MD025": { + "front_matter_title": "" + } + } } From 0a8ab77c8daca0a351a38a31614c61441fa9d942 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 9 Jan 2022 02:29:13 -0800 Subject: [PATCH 14/66] docs(readme): add Requirements --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 911f3373..6cd2940e 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,30 @@ The USAGE document goes into detail on how to use HXE. In a nutshell: # configure the kernel .\hxe.exe -config + +# Requirements + +## Operating System + +| Minimum | Recommended +| ---------------------------------------- | ----------- +| Windows 7 SP1 32-bit (w/ addl. software) | Windows 10 64-bit + +## .NET 6.0 + +Because HXE is built on the relatively new .NET 6, you may need to download the [.NET 6.0 Desktop Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) for this app to work. Hopefully, this will be distributed via Windows Updates to Windows 10 and Windows 11 sooner rather than later. +For 64-bit PCs: [Dotnet Runtime (Desktop) 6.0.1 Windows x64 Installer](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-6.0.1-windows-x64-installer) +For 32-bit PCs: [Dotnet Runtime (Desktop) 6.0.1 Windows x86 Installer](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-6.0.1-windows-x86-installer) + +### Windows 7/8.1 + +Additional software dependencies to be installed for this .NET-based app to work on Windows 8.1 and Windows 7 +Read the [Microsoft docs](https://docs.microsoft.com/en-us/dotnet/core/install/windows?tabs=net60#additional-deps) to learn what you need and how to get it. + +## Note: Upgrading To Windows 10 + +Using the [Windows Installation Media Creation Tool](https://www.microsoft.com/en-us/software-download/windows10?36261b60-2f68-4336-abe2-4b00f210b6aa=True), you can still upgrade to Windows 10 with your Windows 7/8/8.1 license. +HOWEVER... + +- If your hardware distributor does not make Windows 10 drivers for your hardware, you may have a worse Windows 10 experience than expected. +- Some drivers made for earlier Windows releases may work on Windows 10; some won't. You won't know until you try. From 2c211501769af91502d08307c2a6b52338c65dcf Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Mon, 14 Feb 2022 02:57:05 -0800 Subject: [PATCH 15/66] feat: Add CLI alternative to Positions GUI --- src/CLI/Positions.cs | 157 +++++++++++++++++++++++++++++++++++++++++++ src/Program.cs | 3 + 2 files changed, 160 insertions(+) create mode 100644 src/CLI/Positions.cs diff --git a/src/CLI/Positions.cs b/src/CLI/Positions.cs new file mode 100644 index 00000000..00f9848c --- /dev/null +++ b/src/CLI/Positions.cs @@ -0,0 +1,157 @@ +/** + * Copyright (c) 2022 Noah Sherwin + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +using System; +using System.IO; + +namespace HXE.CLI +{ + public static class Positions + { + public static void Run(string source = null, string target = null) + { + Console.Info("Read the file \"OS_Settings.User.xml\" and write its weapons positions to a .bin file."); + FileInfo fiSource = null; + FileInfo fiTarget = null; + + while (fiSource == null) + { + try + { + fiSource = GetSource(); + } + catch (Exception e) + { + Console.Error(e.ToString()); + } + } + + while (fiTarget == null) + { + try + { + fiTarget = GetTarget(); + } + catch (Exception e) + { + Console.Error(e.ToString()); + } + } + + try + { + Save(fiSource, fiTarget); + } + catch (Exception e) + { + Console.Error(e.ToString()); + } + + + } + + private static FileInfo GetSource(string source = null) + { + FileInfo fileInfo = null; + + Console.Info("Full path of OS_Settings.User.xml:"); + + if (source == null) + { + string input = System.Console.In.ReadLine(); + + if (string.IsNullOrWhiteSpace(input)) + { + throw new NullReferenceException("The supplied path was null, empty, or whitespace."); + } + + fileInfo = new FileInfo(Path.GetFullPath(input)); + } + else + { + Console.Info(source); + fileInfo = new FileInfo(Path.GetFullPath(source)); + } + + if (!fileInfo.Exists) + { + throw new FileNotFoundException($"The file {fileInfo.Name} was not found."); + } + + if (fileInfo.Name != "OS_Settings.User.xml") + { + throw new ArgumentException("The provided file is not OS_Settings.User.xml."); + } + + return fileInfo; + } + + private static FileInfo GetTarget(string target = null) + { + FileInfo fileInfo; + + Console.Info("Full path of target/output .bin file:"); + + if (target == null) + { + string input = System.Console.In.ReadLine(); + + if (string.IsNullOrWhiteSpace(input)) + { + throw new NullReferenceException("The supplied path was null, empty, or whitespace."); + } + + fileInfo = new FileInfo(Path.GetFullPath(input)); + } + else + { + Console.Info(target); + fileInfo = new FileInfo(Path.GetFullPath(target)); + } + + if (!fileInfo.Exists) + { + throw new FileNotFoundException($"The file {fileInfo.Name} was not found."); + } + + if (!fileInfo.Extension.EndsWith("bin")) + { + throw new ArgumentException("The provided file lacks the .bin extension."); + } + + return fileInfo; + + } + + private static void Save(FileInfo source, FileInfo target) + { + Console.Info("Saving weapon positions..."); + + var openSauce = (OpenSauce) source.FullName; + + openSauce.Load(); + openSauce.Objects.Weapon.Save(target.FullName); + openSauce.Objects.Weapon.Load(target.FullName); + + foreach (var position in openSauce.Objects.Weapon.Positions) + Console.Debug($"Weapon: {position.Name} | I/J/K: {position.Position.I}/{position.Position.J}/{position.Position.K}"); + } + } +} diff --git a/src/Program.cs b/src/Program.cs index 7fa167ae..cbeef879 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -160,6 +160,9 @@ private static void InvokeProgram(string[] args) app = new Application(); _ = app.Run(test_positions); app.Shutdown(); + //string target = Path.Combine(CurrentDirectory, "positions.bin"); + //Positions.Run(source, target); + Logs("TODO: Positions test requires an OpenSauce.User.xml file."); Logs("Positions Test: Succeeded"); } catch (Exception e) From 0f7825bc4cc1456e62e576a0f2a2449ab0721607 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Mon, 14 Feb 2022 02:37:46 -0800 Subject: [PATCH 16/66] fix: support targeting NETFX 4.6.2, 4.8.0 Some faimilar features are not available in .NET Framework. NOT SUPPORTED IN NET4: - string.Split(char[] separator, StringSplitOptions options) - string.Split(string separator) - System.Net.Http.HttpResponseMessage.Content.ReadAsStream() --- src/HXE.csproj | 8 ++++++-- src/MCC/Halo1.cs | 2 +- src/Program.cs | 2 +- src/Steam/Libraries.cs | 2 +- src/Update.cs | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/HXE.csproj b/src/HXE.csproj index 954a62c4..7af6c0f2 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -6,8 +6,8 @@ AnyCPU false Exe - net5.0-windows - net5.0-windows;net6.0-windows + net462 + net462;net480;net5.0-windows;net6.0-windows HXE.Program HXE HXE @@ -120,6 +120,10 @@ all + + + + diff --git a/src/MCC/Halo1.cs b/src/MCC/Halo1.cs index 12dc24e3..9f7e264b 100644 --- a/src/MCC/Halo1.cs +++ b/src/MCC/Halo1.cs @@ -114,7 +114,7 @@ public static bool Halo1DLLIsCertified() try { var response = Client.GetAsync(uri).Result; - MemoryStream ms = (MemoryStream) response.Content.ReadAsStream(); + var ms = (MemoryStream) response.Content.ReadAsStreamAsync().Result; byte[] msArray = ms.ToArray(); remoteCert = new X509Certificate(msArray); } diff --git a/src/Program.cs b/src/Program.cs index cbeef879..00441e0e 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -372,7 +372,7 @@ internal static int GetLongestStringLength(string[] strings) { foreach (string line in s.Split('\n')) { - lines.AddRange(line.Split('\r', StringSplitOptions.RemoveEmptyEntries)); + lines.AddRange(line.Split('\r').Where(l => !string.IsNullOrWhiteSpace(l))); } } diff --git a/src/Steam/Libraries.cs b/src/Steam/Libraries.cs index c905b794..f4bb7f04 100644 --- a/src/Steam/Libraries.cs +++ b/src/Steam/Libraries.cs @@ -117,7 +117,7 @@ public static void ParseLibrary(File libraryFoldersVdf = null) { string text = libraryFoldersVdf.ReadAllText(); - List libs = text.Split("\n").ToList(); /// Start by adding each line to a list. + List libs = text.Split('\n').ToList(); /// Start by adding each line to a list. libs = libs.Where(line => line.Contains("\"path\"")).ToList(); /// Filter the list for entries containing `"path"`. foreach (string line in libs) diff --git a/src/Update.cs b/src/Update.cs index c703a5ea..293c7e2e 100644 --- a/src/Update.cs +++ b/src/Update.cs @@ -78,7 +78,7 @@ public async void Import(string uri) Info("Inferred web request manifest - " + uri); using (var rm = await Client.GetAsync(uri)) - using (var sr = new StreamReader(rm.Content.ReadAsStream() ?? throw new NullReferenceException("No response."))) + using (var sr = new StreamReader(await rm.Content.ReadAsStreamAsync() ?? throw new NullReferenceException("No response."))) { data = sr.ReadToEnd(); } From 0bd31251fbc23bded823302982552afc6b102f0f Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:21:21 -0800 Subject: [PATCH 17/66] fix: remove/replace WinForms references Use Microsoft.Win32 or WPF equivalents instead. --- src/HCE/Executable.cs | 18 +++++++++--------- src/HXE.csproj | 1 - src/Kernel.cs | 16 +++++++++------- src/Positions.xaml.cs | 21 +++++++++++---------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/HCE/Executable.cs b/src/HCE/Executable.cs index f897d812..a4958f74 100644 --- a/src/HCE/Executable.cs +++ b/src/HCE/Executable.cs @@ -66,16 +66,16 @@ public static Executable Detect() var log = (File) Paths.Exception; log.AppendAllText("The inferred executable path was probably malformed or incomplete.\n Error: " + e + "\n"); - using (System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog()) + var ofd = new Microsoft.Win32.OpenFileDialog { - ofd.InitialDirectory = GetFolderPath(SpecialFolder.Desktop); - ofd.Filter = "Halo Custom Edition (haloce.exe)|haloce.exe|Halo Retail/Trial (halo.exe)|halo.exe"; - ofd.FilterIndex = 1; - ofd.RestoreDirectory = true; - - if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) - fullName = GetFullPath(ofd.FileName); - } + InitialDirectory = GetFolderPath(SpecialFolder.Desktop), + Filter = "Halo Custom Edition (haloce.exe)|haloce.exe|Halo Retail/Trial (halo.exe)|halo.exe", + FilterIndex = 1, + RestoreDirectory = true + }; + + if (ofd.ShowDialog() == true) + fullName = GetFullPath(ofd.FileName); } if (System.IO.File.Exists(fullName)) diff --git a/src/HXE.csproj b/src/HXE.csproj index 7af6c0f2..ef06ff43 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -49,7 +49,6 @@ true hxe true - true x64 diff --git a/src/Kernel.cs b/src/Kernel.cs index d4b18744..08e1aebf 100644 --- a/src/Kernel.cs +++ b/src/Kernel.cs @@ -31,7 +31,6 @@ using static System.IO.Directory; using static System.IO.Path; using static System.Text.Encoding; -using static System.Windows.Forms.Screen; using static HXE.Console; using static HXE.HCE.Profile.ProfileAudio; using static HXE.HCE.Profile.ProfileVideo; @@ -436,19 +435,22 @@ void Video() { if (!configuration.Video.ResolutionEnabled) { + var w = System.Windows.SystemParameters.PrimaryScreenWidth; + var h = System.Windows.SystemParameters.PrimaryScreenHeight; + // infer from resolution if Native Resoluton preferred. if (executable.Video.Width == 0 || executable.Video.Height == 0) { - executable.Video.Width = (ushort) PrimaryScreen.Bounds.Width; - executable.Video.Height = (ushort) PrimaryScreen.Bounds.Height; + executable.Video.Width = (ushort) System.Windows.SystemParameters.PrimaryScreenWidth; + executable.Video.Height = (ushort) System.Windows.SystemParameters.PrimaryScreenHeight; Core("BLAM.VIDEO.RESOLUTION: No resolution provided. Applied native resolution to executable."); } - else if (executable.Video.Width > (ushort) PrimaryScreen.Bounds.Width || - executable.Video.Height > (ushort) PrimaryScreen.Bounds.Height) + else if (executable.Video.Width > (ushort) System.Windows.SystemParameters.PrimaryScreenWidth || + executable.Video.Height > (ushort) System.Windows.SystemParameters.PrimaryScreenHeight) { - executable.Video.Width = (ushort) PrimaryScreen.Bounds.Width; - executable.Video.Height = (ushort) PrimaryScreen.Bounds.Height; + executable.Video.Width = (ushort) System.Windows.SystemParameters.PrimaryScreenWidth; + executable.Video.Height = (ushort) System.Windows.SystemParameters.PrimaryScreenHeight; Core("BLAM.VIDEO.RESOLUTION: Resolution out of bounds. Applied native resolution to executable."); } diff --git a/src/Positions.xaml.cs b/src/Positions.xaml.cs index 47175737..d5a901f1 100644 --- a/src/Positions.xaml.cs +++ b/src/Positions.xaml.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2019 Emilian Roman * * This software is provided 'as-is', without any express or implied @@ -19,7 +19,7 @@ */ using System.Windows; -using System.Windows.Forms; +using Microsoft.Win32; using static HXE.Console; using MessageBox = System.Windows.MessageBox; @@ -28,7 +28,7 @@ namespace HXE /// /// Interaction logic for Positions.xaml /// - public partial class Positions + public partial class Positions : Window { private string _source; private string _target; @@ -67,16 +67,17 @@ private void Cancel(object sender, RoutedEventArgs e) private void BrowseSource(object sender, RoutedEventArgs e) { - using (var dialog = new OpenFileDialog()) - { - dialog.DefaultExt = ".xml"; - dialog.Filter = "XML files (*.xml)|*.xml"; + var dialog = new OpenFileDialog + { + DefaultExt = ".xml", + Filter = "XML files (*.xml)|*.xml" + }; - if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; + if (dialog.ShowDialog() != true) return; _source = dialog.FileName; SourceTextBox.Text = _source; - } + } private void BrowseTarget(object sender, RoutedEventArgs e) @@ -87,7 +88,7 @@ private void BrowseTarget(object sender, RoutedEventArgs e) Filter = "BIN files (*.bin)|*.bin" }; - if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; + if (dialog.ShowDialog() != true) return; _target = dialog.FileName; TargetTextBox.Text = _target; From 1ed397fe7071c05b54f9d77c055cb7c564cf4f05 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:25:52 -0800 Subject: [PATCH 18/66] build: simplify GitVersion prebuild script --- src/.msb.prebuild.ps1 | 53 ++++++++----------------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/src/.msb.prebuild.ps1 b/src/.msb.prebuild.ps1 index 0f9e5f06..88434e36 100644 --- a/src/.msb.prebuild.ps1 +++ b/src/.msb.prebuild.ps1 @@ -8,59 +8,26 @@ function prebuild { - $minVer_isShallow = [version]'2.15.0.0'; - $minVer_unshallow = [version]'2.1.4.0'; - $gitBinVer = ""; $isShallow = $true; - # 0. Announce - Write-Host "0. GitVersion cannot determine the next version in shallow reposistories.`n", - "`tWe will use Git to determine if the current repository needs to be un-shallowed.`n", - "Checking if Git is available..."; + # Announce + Write-Host "GitVersion requires unshallow repositories.`n", + "We will use Git to determine if the current repository needs to be un-shallowed."; - # 1. Ensure Git is available - try - { - Write-Host "1. Git was found.`n", - "It is $(git --version) at...`n", - (Get-Command -Name git).path - - $gitBinVer = [version]('{2}.{3}.{4}.{6}' -f (git --version).split(' ').split('.')) - } - catch - { - Write-Error "Git is not installed or it is not in PATH!"; - throw - } - - # 2. Check if the repository is shallow - Write-Host "2. Checking if repository is shallow..." - if ($gitBinVer -gt $minVer_isShallow) # GitVersion >= 2.15.0.0 - { - $isShallow = git rev-parse --is-shallow-repository - } - else - { - Write-Debug "Git Version less than 2.15.0.0" - $isShallow = Test-Path (Join-Path $GitStatus.GitDir shallow) - } + # Check if the repository is shallow + Write-Host "Checking if repository is shallow..." + $isShallow = git rev-parse --is-shallow-repository - # 3. If the repository is shallow, then unshallow + # If the repository is shallow, then unshallow if ($isShallow -eq $true) { - Write-Host "3. Repository is shallow. Fetching full history..." - if ($gitBinVer -lt $minVer_unshallow) # GitVersion < 2.1.4.0 (exact version unknown) - { - git fetch --depth=0; - } - else { - git fetch --unshallow - } + Write-Warning "Repository is shallow. Fetching full history..." + git fetch --unshallow Write-Host "Fetch Completed. Proceeding to Build...`n" } else { - Write-Host "3. Repository is complete. Proceeding to Build..." + Write-Host "Repository is complete. Proceeding to Build..." } } From 40fed6bd2c63cf496f5dfd5a7df74529dd1c78a4 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:29:07 -0800 Subject: [PATCH 19/66] style: add end-of-file newline style: set charset to UTF-8 BOM --- src/HCE/Executable.cs | 4 ++-- src/Kernel.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/HCE/Executable.cs b/src/HCE/Executable.cs index a4958f74..eb1902fa 100644 --- a/src/HCE/Executable.cs +++ b/src/HCE/Executable.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2019 Emilian Roman * Copyright (c) 2021 Noah Sherwin * @@ -238,4 +238,4 @@ public class MiscellaneousOptions public bool NoVideo { get; set; } } } -} \ No newline at end of file +} diff --git a/src/Kernel.cs b/src/Kernel.cs index 08e1aebf..d8b4ddc7 100644 --- a/src/Kernel.cs +++ b/src/Kernel.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2019 Emilian Roman * Copyright (c) 2021 Noah Sherwin * @@ -1078,7 +1078,7 @@ public class ConfigurationMain public class ConfigurationVideo { - public bool ResolutionEnabled { get; set; } = false; /* custom resolution */ + public bool ResolutionEnabled { get; set; } = false; /* auto resolution */ public bool Uncap { get; set; } = true; /* unlock framerate */ public bool Quality { get; set; } /* set to false by default for optimisation */ public bool GammaOn { get; set; } = false; /* enable hce gamma */ @@ -1109,4 +1109,4 @@ public class ConfigurationTweaks } } } -} \ No newline at end of file +} From ee1f6f5493782b1ea321069812256230f356d409 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:36:40 -0800 Subject: [PATCH 20/66] build: change CPU arch conditions from Equals to Contains --- src/HXE.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HXE.csproj b/src/HXE.csproj index ef06ff43..892bc3d7 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -50,11 +50,11 @@ hxe true - + x64 false - + x86 true From c6006aff81f494419a9b2925195e73638c0c1d18 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:38:53 -0800 Subject: [PATCH 21/66] build: set satellite resource langs to en-us --- src/HXE.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HXE.csproj b/src/HXE.csproj index 892bc3d7..b8396f0b 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -49,6 +49,7 @@ true hxe true + en-US x64 From 881e50f2282fdef448d689785a05c702a0d94ae7 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:39:24 -0800 Subject: [PATCH 22/66] build: enable InvariantGlobalization --- src/HXE.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HXE.csproj b/src/HXE.csproj index b8396f0b..d2c89a67 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -50,6 +50,7 @@ hxe true en-US + true x64 From 2302717a6f577011f0c1fbb427f84e0334f4c996 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:41:22 -0800 Subject: [PATCH 23/66] build: set custom var `Win7SF` if SDK version is 6.0.300 or greater The Windows 7 SingleFile host will be introduced in .NET 6.0.300. --- src/HXE.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HXE.csproj b/src/HXE.csproj index d2c89a67..664f5198 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -51,6 +51,7 @@ true en-US true + $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '6.0.300')) x64 From 35c25b6d8911e7e53c2dd656a80e1613d2e09032 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:44:21 -0800 Subject: [PATCH 24/66] build: only allow PublishSingleFile with Win7 if Win7SF is True --- src/HXE.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HXE.csproj b/src/HXE.csproj index 664f5198..125a7360 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -52,6 +52,7 @@ en-US true $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '6.0.300')) + $(Win7SF) x64 From 505c511175e8ab0a5781e3057d24ce2c408482ac Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:46:18 -0800 Subject: [PATCH 25/66] build: do not publish Release symbols --- src/HXE.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HXE.csproj b/src/HXE.csproj index 125a7360..02029c6d 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -66,6 +66,7 @@ DEBUG;TRACE + false TRACE From 757790c7ec795bceb42abc3bfc9d5b80c659169f Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 18:59:13 -0800 Subject: [PATCH 26/66] build: move publish-related props and conditions - if both PublishSingleFile and RuntimeIdentifier are unset, disable PublishSingleFile - if RuntimeIdentifier is unset and PublishSingleFile is enabled, set RuntimeIdentifier to 'win-x86' - if SelfContained is unset, but RuntimeIdentifier *is*, enable SelfContained - if PublishSingleFile is enabled.. ...enable SelfContained ...enable IncludeNativeLibrariesForSelfExtract ...enable EnableCompressionInSingleFile --- src/HXE.csproj | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/HXE.csproj b/src/HXE.csproj index 02029c6d..238ef01c 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -36,11 +36,9 @@ true - true - win-x64 - true - true - true + false + win-x86 + true {ACAA5D9F-B23D-43E1-B2DF-8C03230975A1} Properties @@ -69,6 +67,11 @@ false TRACE + + true + true + true + .root\%(Filename)%(Extension) From 0fddbba0d921c90e54da659731f2177d1f1bfeb2 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 19:01:04 -0800 Subject: [PATCH 27/66] style: fix indentation --- src/HXE.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HXE.csproj b/src/HXE.csproj index 238ef01c..029ae7bf 100644 --- a/src/HXE.csproj +++ b/src/HXE.csproj @@ -78,7 +78,7 @@ Never - .root\.github\%(RecursiveDir)%(Filename)%(Extension) + .root\.github\%(RecursiveDir)%(Filename)%(Extension) .docs\%(RecursiveDir)%(Filename)%(Extension) From 06a54908e6429c5b008cb62df7df77caa1e43267 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 19:07:01 -0800 Subject: [PATCH 28/66] style: set charset to UTF-8 BOM --- src/Positions.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Positions.xaml.cs b/src/Positions.xaml.cs index d5a901f1..fdb44202 100644 --- a/src/Positions.xaml.cs +++ b/src/Positions.xaml.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2019 Emilian Roman * * This software is provided 'as-is', without any express or implied From cacc0e2d2ecb913314b85eae8c32ed8a84c1f6ba Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 19:08:25 -0800 Subject: [PATCH 29/66] refactor: remove unnecessary using System.Reflection --- src/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Program.cs b/src/Program.cs index 00441e0e..81055d08 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Reflection; using System.Threading.Tasks; using System.Windows; using HXE.HCE; From fe6773b8b8108fada5c506034538d23ec7379fb2 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 19:47:09 -0800 Subject: [PATCH 30/66] fix: add using System.Linq --- src/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Program.cs b/src/Program.cs index 81055d08..df5d6503 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -30,6 +30,7 @@ using static HXE.Console; using static HXE.Exit; using static HXE.Properties.Resources; +using System.Linq; namespace HXE { From 3fffced1030487166bafb47a79b8c07f0290deba Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 19:57:03 -0800 Subject: [PATCH 31/66] feat: add --cli arg Opens CLI instead of GUI when available --- src/Program.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index df5d6503..276482da 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -60,6 +60,7 @@ public static void Main(string[] args) /// --test Start a dry run of HXE to self-test
/// --config Opens configuration GUI
/// --positions Opens first-person model positions GUI
+ /// --cli Opens CLI instead of GUI where available
/// --install=VALUE Installs HCE/SPV3 to destination
/// --compile=VALUE Compiles HCE/SPV3 to destination
/// --update=VALUE Updates directory with specified manifest
@@ -84,6 +85,7 @@ private static void InvokeProgram(string[] args) var test = false; /* Start a dry run of HXE to self-test */ var config = false; /* Opens configuration GUI */ var positions = false; /* Opens positions GUI */ + var cli = false; /* Opens CLI instead of GUI where available */ var install = string.Empty; /* Installs HCE/SPV3 to destination */ var compile = string.Empty; /* Compiles HCE/SPV3 to destination */ var update = string.Empty; /* Updates directory using manifest */ @@ -105,6 +107,7 @@ private static void InvokeProgram(string[] args) .Add("test", "Start a dry run of HXE to self-test", s => test =s != null) /* hxe command */ .Add("config", "Opens configuration GUI", s => config = s != null) /* hxe command */ .Add("positions", "Opens positions GUI", s => positions = s != null) /* hxe command */ + .Add("cli", "Enable CLI of Positions or Config", s => cli = s != null) /* hxe parameter */ .Add("install=", "Installs HCE/SPV3 to destination", s => install = s) /* hxe parameter */ .Add("compile=", "Compiles HCE/SPV3 to destination", s => compile = s) /* hxe parameter */ .Add("update=", "Updates directory using manifest", s => update = s) /* hxe parameter */ @@ -179,8 +182,15 @@ private static void InvokeProgram(string[] args) if (positions) { - _ = new Application().Run(new Positions()); - Exit(0); + if (cli) + { + CLI.Positions.Run(); + } + else + { + _ = new Application().Run(new Positions()); + } + WithCode(0); } if (infer) From 9c44fb0fbb81de4129207c808a0d45ecd4ab8801 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 19:58:19 -0800 Subject: [PATCH 32/66] refactor: move NewLine appendix in Exception output --- src/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 276482da..cb4b680b 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -266,9 +266,9 @@ private static void InvokeProgram(string[] args) " -- Looked in working directory, Program Files, and Registry." + NewLine + " -- The working directory is " + CurrentDirectory + NewLine + " -- Error: " + NewLine + - e.ToString() + NewLine; + e.ToString(); var log = (File) Paths.Exception; - log.AppendAllText(msg); + log.AppendAllText(msg + NewLine); Error(msg); } From 417b21749fa8f01966bfa1b402c9474e8393be8b Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 19:58:56 -0800 Subject: [PATCH 33/66] refactor: change input prompt for --infer --- src/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Program.cs b/src/Program.cs index cb4b680b..b963bc25 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -206,7 +206,7 @@ private static void InvokeProgram(string[] args) }; Info($"Inferred the following Halo process: {descriptions[Process.Infer()]}"); - Info("Press any key to exit."); + Info("Press Enter to exit"); _ = ReadLine(); Exit(0); } From 135921b2aa79848eab2082bcbac82a9918c850d6 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:07:41 -0800 Subject: [PATCH 34/66] refactor: use Exit.WithCode() instead of Exit() --- src/Program.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index b963bc25..6f433ac7 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -134,7 +134,7 @@ private static void InvokeProgram(string[] args) if (help) { options.WriteOptionDescriptions(Out); - Exit(0); + WithCode(Code.Success); } if (test) @@ -172,12 +172,13 @@ private static void InvokeProgram(string[] args) { Error("Positions window threw an exception!" + NewLine + e.ToString()); } + WithCode(Code.Success); } if (config) { _ = new Application().Run(new Settings()); - Exit(0); + WithCode(Code.Success); } if (positions) @@ -190,7 +191,7 @@ private static void InvokeProgram(string[] args) { _ = new Application().Run(new Positions()); } - WithCode(0); + WithCode(Code.Success); } if (infer) @@ -208,7 +209,7 @@ private static void InvokeProgram(string[] args) Info($"Inferred the following Halo process: {descriptions[Process.Infer()]}"); Info("Press Enter to exit"); _ = ReadLine(); - Exit(0); + WithCode(Code.Success); } if (!string.IsNullOrWhiteSpace(install)) From 4f54a0bab81e74dc45daf942f7af22f81c70a51e Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:13:26 -0800 Subject: [PATCH 35/66] fix: re-throw exceptions during --test --- src/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Program.cs b/src/Program.cs index 6f433ac7..0c9a36a1 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -154,6 +154,7 @@ private static void InvokeProgram(string[] args) catch (Exception e) { Error("Settings window threw an exception!" + NewLine + e.ToString()); + throw; } try @@ -171,6 +172,7 @@ private static void InvokeProgram(string[] args) catch (Exception e) { Error("Positions window threw an exception!" + NewLine + e.ToString()); + throw; } WithCode(Code.Success); } From 292d67f1a4646460126510b3607d157b787c4b4b Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:13:59 -0800 Subject: [PATCH 36/66] style: sort usings --- src/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Program.cs b/src/Program.cs index 0c9a36a1..82479784 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading.Tasks; using System.Windows; using HXE.HCE; @@ -30,7 +31,6 @@ using static HXE.Console; using static HXE.Exit; using static HXE.Properties.Resources; -using System.Linq; namespace HXE { From cee28c74b1f3e41b20e0e420b80c7c263aae461b Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:14:57 -0800 Subject: [PATCH 37/66] docs: add TODO regarding --silent --- src/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Program.cs b/src/Program.cs index 82479784..bb40a6ca 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -77,6 +77,7 @@ public static void Main(string[] args) /// --vidmode=VALUE Loads HCE with custom res. and Hz
/// --refresh=VALUE Loads HCE with custom refresh rate
/// + /// TODO: implement --silent to run CLI without user prompts; private static void InvokeProgram(string[] args) { Directory.CreateDirectory(Paths.Directory); From 251136efec60484e588b79e949e43d60d5c2c17a Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:16:23 -0800 Subject: [PATCH 38/66] refactor: add const string ExceptionHeader --- src/Process.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Process.cs b/src/Process.cs index fe911839..bfcea91a 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2021 Emilian Roman * * This software is provided 'as-is', without any express or implied @@ -27,6 +27,7 @@ namespace HXE { public class Process { + private const string ExceptionHeader = " -- Process Inference failed"; public enum Type { Unknown, From 73bee930e14edccbac04c963e6c9cd7145dffc38 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:16:52 -0800 Subject: [PATCH 39/66] style: fix indentation --- src/Process.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Process.cs b/src/Process.cs index bfcea91a..e740ea06 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -39,13 +39,13 @@ public enum Type } public static IEnumerable Candidates { get; } = new List - { - new Candidate { Type = Type.Retail, Name = "halo" }, - new Candidate { Type = Type.HCE, Name = "haloce" }, - new Candidate { Type = Type.Steam, Name = "MCC-Win64-Shipping" }, - new Candidate { Type = Type.StoreOld, Name = "MCC-Win64-Shipping-WinStore" }, - new Candidate { Type = Type.Store, Name = "MCCWinStore-Win64-Shipping" } - }; + { + new Candidate { Type = Type.Retail, Name = "halo" }, + new Candidate { Type = Type.HCE, Name = "haloce" }, + new Candidate { Type = Type.Steam, Name = "MCC-Win64-Shipping" }, + new Candidate { Type = Type.StoreOld, Name = "MCC-Win64-Shipping-WinStore" }, + new Candidate { Type = Type.Store, Name = "MCCWinStore-Win64-Shipping" } + }; /// /// Infers the running Halo executable, with support for HCE, HCE and MCC (Steam & Windows Store). From 6e68934519ddcf669c88fce7a7826d41a7cef021 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:25:32 -0800 Subject: [PATCH 40/66] refactor: add Results list for returning result type and message --- src/Process.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Process.cs b/src/Process.cs index e740ea06..3a17f642 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -47,6 +47,21 @@ public enum Type new Candidate { Type = Type.Store, Name = "MCCWinStore-Win64-Shipping" } }; + public static IEnumerable Results { get; } = new List + { + new Result { Success = true, Message = "Found Halo Retail/CD or Halo Custom Edition"}, + new Result { Success = true, Message = "Found MCC with CEA DLC"}, + new Result { Success = false, Message = "Found MCC, but CEA DLC is missing"}, + new Result { Success = false, Message = + "No running processes matched the following criteria:" + NewLine + + "halo.exe v1.0.10.621" + NewLine + + "haloce.exe v1.0.10.621" + NewLine + + "MCC-Win64-Shipping.exe with CEA DLC" + NewLine + + "MCC-Win64-Shipping-WinStore.exe with CEA DLC" + NewLine + + "MCCWinStore-Win64-Shipping.exe with CEA DLC"}, + new Result { Success = false, Message = "Unknown error occurred."} + }; + /// /// Infers the running Halo executable, with support for HCE, HCE and MCC (Steam & Windows Store). /// @@ -139,5 +154,11 @@ public class Candidate public Type Type { get; set; } public string Name { get; set; } } + + public class Result + { + public bool Success { get; set; } + public string Message { get; set; } + } } -} \ No newline at end of file +} From b33daa86920300a9c314f12bfd4207be5fb53438 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:29:48 -0800 Subject: [PATCH 41/66] refactor: consolidate Process' error output --- src/Process.cs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Process.cs b/src/Process.cs index 3a17f642..1af03406 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -77,11 +77,7 @@ public static Type Infer() } catch (System.Exception e) { - var msg = $" -- Process Inference failed{NewLine}Error: { e }{NewLine}"; - var log = (File) Paths.Exception; - log.AppendAllText(msg); - Console.Info(msg); - throw; + ErrorOutput(e, ""); } return processCandidate?.Type ?? Type.Unknown; @@ -128,10 +124,9 @@ private static bool DeeperCheck(System.Diagnostics.Process process, string candi } catch (System.Exception e) { - var msg2 = string.Empty; - msg2 += Is64BitProcess ? "Current process is 64-bit." : "Current process is not 32-bit."; - msg2 += NewLine; - msg2 += Is64BitOperatingSystem ? "Operating system is 64-bit." : "Operating system is NOT 64-bit."; + string msg2 = "MCC process found, but failed to inspect loaded modules for halo1.dll" + NewLine + + (Is64BitProcess ? "Current process is 64-bit." : "Current process is not 32-bit.") + NewLine + + (Is64BitOperatingSystem ? "Operating system is 64-bit." : "Operating system is NOT 64-bit."); ErrorOutput(e, msg2); return false; } @@ -140,13 +135,15 @@ private static bool DeeperCheck(System.Diagnostics.Process process, string candi default: return false; } - void ErrorOutput(System.Exception e, string msg2) - { - var msg = $" -- Process Inference failed{NewLine}{msg2}{NewLine}Error: { e }{NewLine}"; - var log = (File) Paths.Exception; - log.AppendAllText(msg); - Console.Error(msg); ; - } + } + + private static void ErrorOutput(System.Exception e, string msg2) + { + string msg = ExceptionHeader + NewLine + + msg2 + NewLine + + "Error: " + e.ToString(); + ((File)Paths.Exception).AppendAllText(msg + NewLine); + Console.Error(msg); } public class Candidate From b40915bd087b71075b06b52aee5755cba191d580 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:40:00 -0800 Subject: [PATCH 42/66] refactor: add class `ResultAndType` --- src/Process.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Process.cs b/src/Process.cs index 1af03406..30aaa464 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -157,5 +157,11 @@ public class Result public bool Success { get; set; } public string Message { get; set; } } + + public class ResultAndType + { + public Result Result { get; set; } + public Type Type { get; set; } + } } } From 89f00bf1b805ba4a82fd6812cd9a69c2d431b8e4 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:41:03 -0800 Subject: [PATCH 43/66] docs: update Infer()'s summary --- src/Process.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Process.cs b/src/Process.cs index 30aaa464..71f260a9 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -63,7 +63,7 @@ public enum Type }; /// - /// Infers the running Halo executable, with support for HCE, HCE and MCC (Steam & Windows Store). + /// Infers the running Halo executable, with support for Halo Retail, Halo Custom Edition, and MCC (Steam & Windows Store). /// /// Type of Platform public static Type Infer() From 5f5323e12ca68f6addfa60ea278c50ac23564384 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:43:27 -0800 Subject: [PATCH 44/66] refactor: move process matching from Infer() to DeeperCheck() --- src/Process.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Process.cs b/src/Process.cs index 71f260a9..a52411a7 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -68,12 +68,11 @@ public enum Type /// Type of Platform public static Type Infer() { - var processCandidate = new Candidate(); + Candidate processCandidate = null; + List processList = GetProcesses().ToList(); try { - processCandidate = Candidates - .FirstOrDefault(x => DeeperCheck(GetProcesses() - .FirstOrDefault(Processname => Processname.ProcessName == x.Name), x.Name)); + processCandidate = Candidates.First(x => DeeperCheck(x, processList)); } catch (System.Exception e) { @@ -83,16 +82,16 @@ public static Type Infer() return processCandidate?.Type ?? Type.Unknown; } - private static bool DeeperCheck(System.Diagnostics.Process process, string candidateName) + private static bool DeeperCheck(Candidate candidate, List processList) { - /** Check for NullReferenceException (no processes match current candidate) */ + System.Diagnostics.Process process; try { - bool check = process.ProcessName == candidateName; + process = processList.First(p => p.ProcessName == candidate.Name); } - catch (System.NullReferenceException) + catch (System.InvalidOperationException) { - return false; + return false; /// No processes match current candidate } switch (process.ProcessName) From e7c3076b1e4b20730a25ab949b31fd8772776aa5 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 20:46:04 -0800 Subject: [PATCH 45/66] refactor: set Process to static BREAKING CHANGE --- src/Process.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Process.cs b/src/Process.cs index a52411a7..fc9fe8ef 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -25,7 +25,7 @@ namespace HXE { - public class Process + public static class Process { private const string ExceptionHeader = " -- Process Inference failed"; public enum Type From 13fe9c41a3527a666f2d3c35cbdfe8ba3e852348 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 21:45:57 -0800 Subject: [PATCH 46/66] refactor: combine Result and ResultAndType --- src/Process.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Process.cs b/src/Process.cs index fc9fe8ef..7dcc65b9 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -154,13 +154,8 @@ public class Candidate public class Result { public bool Success { get; set; } - public string Message { get; set; } - } - - public class ResultAndType - { - public Result Result { get; set; } public Type Type { get; set; } + public string Message { get; set; } } } } From 76dfafbd3ff2a52f1a5bd94ddf2c34e466d02c89 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 19 Feb 2022 23:44:41 -0800 Subject: [PATCH 47/66] refactor: add LastResult for random access and returned values --- src/Process.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Process.cs b/src/Process.cs index 7dcc65b9..77125f81 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -62,6 +62,8 @@ public enum Type new Result { Success = false, Message = "Unknown error occurred."} }; + public static Result LastResult { get; internal set; } // TODO: Upon success/failure, update CurrentStatus with appropriate Status from Results + /// /// Infers the running Halo executable, with support for Halo Retail, Halo Custom Edition, and MCC (Steam & Windows Store). /// From 9f26d751c36714327e7a1d0af8748619518e8f6c Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 02:12:30 -0800 Subject: [PATCH 48/66] refactor: move Halo PC workload to InspectHPC() This allows halo and haloce cases to set LastResult members without one case falling through to the other. --- src/Process.cs | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Process.cs b/src/Process.cs index 77125f81..6679f554 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -99,18 +99,13 @@ private static bool DeeperCheck(Candidate candidate, List Date: Sun, 20 Feb 2022 02:30:38 -0800 Subject: [PATCH 49/66] refactor: move MCC workload to InspectMCC() --- src/Process.cs | 51 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/Process.cs b/src/Process.cs index 6679f554..0bdbbdc9 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -110,23 +110,13 @@ private static bool DeeperCheck(Candidate candidate, List() - .Any(module => module.ModuleName == Paths.MCC.H1dll); - } - catch (System.Exception e) - { - string msg2 = "MCC process found, but failed to inspect loaded modules for halo1.dll" + NewLine - + (Is64BitProcess ? "Current process is 64-bit." : "Current process is not 32-bit.") + NewLine - + (Is64BitOperatingSystem ? "Operating system is 64-bit." : "Operating system is NOT 64-bit."); - ErrorOutput(e, msg2); - return false; - } - } + LastResult.Success = InspectMCC(); + LastResult.Type = Type.Steam; + return LastResult.Success; default: return false; @@ -145,7 +135,34 @@ bool InspectHPC() catch (System.Exception e) { const string msg = "Failed to assess Halo/HaloCE process"; - LastResult.Success = false; + LastResult.Message = msg; + ErrorOutput(e, msg); + return false; + } + } + + bool InspectMCC() + { + try + { + bool isValid = process.Modules + .Cast() + .Any(module => module.ModuleName == Paths.MCC.H1dll); + LastResult.Message = "Found MCC process with halo1.dll loaded"; + return isValid; + } + catch (System.ComponentModel.Win32Exception e) + { + string msg = "MCC process found, but cannot inspect its modules because 32-bit processes cannot inspect 64-bit processes" + NewLine + + (Is64BitProcess ? "Current process is 64-bit." : "Current process NOT 64-bit.") + NewLine + + (Is64BitOperatingSystem ? "Operating system is 64-bit." : "Operating system is NOT 64-bit."); + LastResult.Message = msg; + ErrorOutput(e, msg); + return false; + } + catch (System.Exception e) + { + const string msg = "MCC process found, but failed to inspect loaded modules for halo1.dll for an unknown reason"; LastResult.Message = msg; ErrorOutput(e, msg); return false; From 4e76bcf0283dc63f430767fd7c28ad533f7b6dc5 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 02:33:50 -0800 Subject: [PATCH 50/66] refactor: set LastResult members in Infer() --- src/Process.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Process.cs b/src/Process.cs index 0bdbbdc9..3fbb4269 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -79,9 +79,29 @@ public static Type Infer() catch (System.Exception e) { ErrorOutput(e, ""); + LastResult.Success = false; + LastResult.Type = Type.Unknown; + LastResult.Message = "An unhandled exception occurred" + NewLine + e.ToString(); } - return processCandidate?.Type ?? Type.Unknown; + if (processCandidate?.Type == null) + { + LastResult.Success = false; + LastResult.Type = Type.Unknown; + LastResult.Message = + "No running processes matched the following criteria:" + NewLine + + "halo.exe v1.0.10.621" + NewLine + + "haloce.exe v1.0.10.621" + NewLine + + "MCC-Win64-Shipping.exe with CEA DLC" + NewLine + + "MCC-Win64-Shipping-WinStore.exe with CEA DLC" + NewLine + + "MCCWinStore-Win64-Shipping.exe with CEA DLC"; + return Type.Unknown; + } + else + { + /// LastResult has already been set by DeeperCheck() + return processCandidate.Type; + } } private static bool DeeperCheck(Candidate candidate, List processList) From a6258ad04565b15ed56207434dd0273ef0f371c9 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 02:39:05 -0800 Subject: [PATCH 51/66] refactor: remove unused Results list --- src/Process.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Process.cs b/src/Process.cs index 3fbb4269..7f6f0265 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -47,21 +47,6 @@ public enum Type new Candidate { Type = Type.Store, Name = "MCCWinStore-Win64-Shipping" } }; - public static IEnumerable Results { get; } = new List - { - new Result { Success = true, Message = "Found Halo Retail/CD or Halo Custom Edition"}, - new Result { Success = true, Message = "Found MCC with CEA DLC"}, - new Result { Success = false, Message = "Found MCC, but CEA DLC is missing"}, - new Result { Success = false, Message = - "No running processes matched the following criteria:" + NewLine + - "halo.exe v1.0.10.621" + NewLine + - "haloce.exe v1.0.10.621" + NewLine + - "MCC-Win64-Shipping.exe with CEA DLC" + NewLine + - "MCC-Win64-Shipping-WinStore.exe with CEA DLC" + NewLine + - "MCCWinStore-Win64-Shipping.exe with CEA DLC"}, - new Result { Success = false, Message = "Unknown error occurred."} - }; - public static Result LastResult { get; internal set; } // TODO: Upon success/failure, update CurrentStatus with appropriate Status from Results /// From aecf6e1a21e8f7b970be9291f9fce70de22738e2 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 02:40:25 -0800 Subject: [PATCH 52/66] docs: add summary of DeeperCheck's switch statement --- src/Process.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Process.cs b/src/Process.cs index 7f6f0265..49874981 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -101,6 +101,12 @@ private static bool DeeperCheck(Candidate candidate, List Date: Sun, 20 Feb 2022 02:43:34 -0800 Subject: [PATCH 53/66] feat: add InferResult() ...which makes use of recent Result additions. InferResult() is an informative alternative to Infer. Infer() is kept for compatibility. --- src/Process.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Process.cs b/src/Process.cs index 49874981..1eef8359 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -49,6 +49,12 @@ public enum Type public static Result LastResult { get; internal set; } // TODO: Upon success/failure, update CurrentStatus with appropriate Status from Results + public static Result InferResult() + { + _ = Infer(); + return LastResult; + } + /// /// Infers the running Halo executable, with support for Halo Retail, Halo Custom Edition, and MCC (Steam & Windows Store). /// From d835abedc1b587d6837ae56114cf9830d50046c3 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 03:05:54 -0800 Subject: [PATCH 54/66] docs: add summary and return docs to InferResult() --- src/Process.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Process.cs b/src/Process.cs index 1eef8359..8e29b56b 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -49,6 +49,11 @@ public enum Type public static Result LastResult { get; internal set; } // TODO: Upon success/failure, update CurrentStatus with appropriate Status from Results + /// + /// An informative alternative to Infer()
+ /// Infers the running Halo executable, with support for Halo Retail, Halo Custom Edition, and MCC (Steam & Windows Store) + ///
+ /// , a static instance of that was updated by Infer() and its called method(s) public static Result InferResult() { _ = Infer(); From 420a2952879890548d543bcb817f9f0eb2597d05 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 03:06:28 -0800 Subject: [PATCH 55/66] docs: remove old TODO note --- src/Process.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Process.cs b/src/Process.cs index 8e29b56b..2c9334d8 100644 --- a/src/Process.cs +++ b/src/Process.cs @@ -47,7 +47,7 @@ public enum Type new Candidate { Type = Type.Store, Name = "MCCWinStore-Win64-Shipping" } }; - public static Result LastResult { get; internal set; } // TODO: Upon success/failure, update CurrentStatus with appropriate Status from Results + public static Result LastResult { get; internal set; } /// /// An informative alternative to Infer()
From 4ba3e57c48f945345fddee3bafdb62c789b6462b Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 03:09:13 -0800 Subject: [PATCH 56/66] style: add end-of-file newline --- src/Common/ExtProcess.cs | 4 ++-- src/Settings.xaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Common/ExtProcess.cs b/src/Common/ExtProcess.cs index 017a785b..8a1a13b8 100644 --- a/src/Common/ExtProcess.cs +++ b/src/Common/ExtProcess.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2019 Emilian Roman * Copyright (c) 2021 Noah Sherwin * @@ -31,4 +31,4 @@ public static bool RunningAsAdmin() return Principle.IsInRole(WindowsBuiltInRole.Administrator); } } -} \ No newline at end of file +} diff --git a/src/Settings.xaml b/src/Settings.xaml index 04ee2f27..2bc84434 100644 --- a/src/Settings.xaml +++ b/src/Settings.xaml @@ -1,4 +1,4 @@ - + + + Release + Any CPU + false + ..\bin\Release\net462\publish\ + FileSystem + net462 + + diff --git a/src/Properties/PublishProfiles/Release_net6.0-windows_framework-dependent.pubxml b/src/Properties/PublishProfiles/Release_net6.0-windows_fdd.pubxml similarity index 64% rename from src/Properties/PublishProfiles/Release_net6.0-windows_framework-dependent.pubxml rename to src/Properties/PublishProfiles/Release_net6.0-windows_fdd.pubxml index efa692e9..2b1bae69 100644 --- a/src/Properties/PublishProfiles/Release_net6.0-windows_framework-dependent.pubxml +++ b/src/Properties/PublishProfiles/Release_net6.0-windows_fdd.pubxml @@ -10,8 +10,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. FileSystem net6.0-windows false - true - true - + true + true diff --git a/src/Properties/PublishProfiles/Release_net6.0-windows_win7-x86.pubxml b/src/Properties/PublishProfiles/Release_net6.0-windows_win7-x86.pubxml new file mode 100644 index 00000000..7d553ca3 --- /dev/null +++ b/src/Properties/PublishProfiles/Release_net6.0-windows_win7-x86.pubxml @@ -0,0 +1,17 @@ + + + + + Release + Any CPU + ..\bin\Release\net6.0-windows\win7-x86\publish\ + FileSystem + net6.0-windows + win7-x86 + true + false + $('$(Win7SF)' == 'true') + + From 6fac0c10d5258168344f8907db01c503cb702655 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 03:28:46 -0800 Subject: [PATCH 65/66] feat: add unfinished Settings CLI Hardly any commands are fully functional, but it's a start. --- src/CLI/Settings.cs | 173 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/CLI/Settings.cs diff --git a/src/CLI/Settings.cs b/src/CLI/Settings.cs new file mode 100644 index 00000000..8c8fb254 --- /dev/null +++ b/src/CLI/Settings.cs @@ -0,0 +1,173 @@ +using System; +using System.Linq; +using static HXE.Kernel.Configuration; +using static HXE.SettingsCore; + +namespace HXE.CLI +{ + public class Settings + { + public Settings(SettingsCore core) + { + Core = core ?? throw new ArgumentNullException(nameof(core)); + } + + private const string LockedMsg = "(LOCKED BY RULESET)"; + private bool ExitScheduled { get; set; } + public SettingsCore Core { get; } + private void InvokeMode(string input) + { + /** No Mode entered; print current and available values e.g. + * SELECT CONFIGURATION MODE + * Current: SPV33 + * Available: + * HCE + * SPV32 + * SPV33 + */ + if (string.IsNullOrEmpty(input)) + { + Console.Info("Current: " + Core.Configuration.Mode); + Console.Info("Available:"); + if (ModeUnlocked) + { + foreach (ConfigurationMode mode in Enum.GetValues(typeof(ConfigurationMode)).Cast().ToList()) + { + Console.Info(mode.ToString()); + } + } + else + { + Console.Warn(LockedMsg); + } + } + // Mode entered; set Mode or warn + // TODO: move Lock mechanism to Mode's Set accessor + else if (ModeUnlocked) + { + try + { + Core.Configuration.Mode = Enum.GetValues(typeof(ConfigurationMode)) + .Cast() + .ToList() + .Single(m => m.ToString() == input); + } + catch (InvalidOperationException) + { + Console.Info("The input " + input + " did not match any Modes"); + } + catch (Exception ex) + { + Console.Error("Failed to assign Mode"); + Console.Error(ex.ToString()); + } + } + else + { + Console.Warn(LockedMsg); + } + } + + private void InvokeMain(string input) + { + // TODO: MainReset, MainPatch, MainStart, MainResume, MainElevated + var subcommands = new CommandSet("Main") + { + { "Reset", "If True, kill existing haloce processes before starting a new one", s => invokeMainReset(s) }, + { "Patch", "If True, applying patches to haloce.exe before starting it", s => invokeMainPatch(s) }, + { "Resume", "If True, allow Continue button to work by writing last-played map and difficulty to init.txt/initc.txt", s => invokeMainResume(s) }, + { "Start", "If True, start the game after exiting Settings CLI", s => invokeMainStart(s) } + }; + + /** no value entered; print helper */ + if (string.IsNullOrWhiteSpace(input)) + { + Console.Info("TODO"); + } + + _ = subcommands.Run(input.Split(' ')); + + void notImplemented() + { + Console.Error("TODO"); + throw new NotImplementedException(); + } + + /// TODO + void invokeMainReset(string s) + { + notImplemented(); + } + + void invokeMainPatch(string s) + { + /** no value entered; print helper */ + if (string.IsNullOrWhiteSpace(s)) + { + Console.Info("Toggle haloce.exe patching"); + Console.Info("Current: " + Core.Configuration.Main.Patch.ToString()); + Console.Info("Available: " + true.ToString() + false.ToString()); + } + } + + /// TODO + void invokeMainResume(string s) + { + notImplemented(); + } + + /// TODO + void invokeMainStart(string s) + { + notImplemented(); + } + } + + private void InvokeTweaks(string s) => throw new NotImplementedException(); + + private void InvokeVideo(string s) => throw new NotImplementedException(); + + private void InvokeAudio(string s) => throw new NotImplementedException(); + + private void InvokeInput(string s) => throw new NotImplementedException(); + + + + /// + /// Prompt user for the setting to read or write + /// + public void Invoke() + { + var Commands = new CommandSet("Settings") + { + { "Exit", "Exit the program", s => ExitScheduled = s != null }, + { "Mode", "Select the appropriate Configuration Mode for Halo:CE or your standalone mod", s => InvokeMode(s) }, + { "Main", "Settings of the pre-launch sequence", s => InvokeMain(s) }, + { "Tweaks", "Miscellaneous settings that affect gameplay, user experience, or aesthetics", s => InvokeTweaks(s) }, + { "Video", "Halo:CE's built-in video settings and enhancements provided by HXE", s => InvokeVideo(s) }, + { "Audio", "Halo:CE's built-in audio settings and some misc settings provided by HXE", s => InvokeAudio(s) }, + { "Input", "Gameplay, menu, and auxilliary input settings", s => InvokeInput(s) } + }; + + Console.Info("A CLI tool to change HXE's settings"); + // TODO: allow user to pass Configuration object or path via startup args. See HXE.Program.InvokeProgram() + while (!ExitScheduled) + { + try + { + /// Read input for command name + string input = System.Console.In.ReadLine(); + if (!string.IsNullOrEmpty(input)) + { + Console.Wait("Processing command..."); + _ = Commands.Run(input.Split(' ')); + } + } + catch (Exception e) + { + Console.Error(e.ToString()); + } + } + } + } +} From 8d0db9fa33c85b56e7b7aa2aa0ced1432e62912c Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 20 Feb 2022 03:30:05 -0800 Subject: [PATCH 66/66] feat: allow Settings CLI to be invokable via `hxe.exe --config --cli` --- src/Program.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Program.cs b/src/Program.cs index bb40a6ca..faae83be 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -180,7 +180,15 @@ private static void InvokeProgram(string[] args) if (config) { - _ = new Application().Run(new Settings()); + var core = new SettingsCore(new Kernel.Configuration(Paths.Configuration)); + if (cli) + { + new CLI.Settings(core).Invoke(); + } + else + { + _ = new Application().Run(new Settings(core)); + } WithCode(Code.Success); }