-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from xparadoxical/master
Fix a NRE and add pvz installation path detection
- Loading branch information
Showing
8 changed files
with
414 additions
and
374 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
#nullable enable | ||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.Win32; | ||
using IntelOrca.MemPatch; | ||
using System.IO; | ||
|
||
namespace IntelOrca.PvZTools | ||
{ | ||
class PvZProcess : AppProcess | ||
{ | ||
public override string StartupPath | ||
{ | ||
get { return @"C:\Program Files (x86)\PopCap Games\Plants vs. Zombies"; } | ||
} | ||
internal PvZProcess() | ||
{ | ||
(string? path, bool goty) = GetInstallLocation(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall", wow6432node: true); | ||
if (path is null) | ||
{ | ||
(path, goty) = GetInstallLocation(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", wow6432node: false); | ||
if (path is null) throw new NullReferenceException("Could not find a Plants vs. Zombies installation."); | ||
} | ||
|
||
public override string ExecutablePath | ||
{ | ||
get { return @"C:\Program Files (x86)\PopCap Games\Plants vs. Zombies\PlantsVsZombies.exe"; } | ||
GOTY = goty; | ||
StartupPath = path; | ||
} | ||
|
||
public override string ProcessName | ||
{ | ||
get { return @"popcapgame1"; } | ||
} | ||
readonly string[] displayNames = new string[] { "Plants vs. Zombies", "Plants vs. Zombies SDR" }; | ||
readonly string gotyName = "Plants vs. Zombies: Game of the Year"; | ||
|
||
private (string? path, bool goty) GetInstallLocation(string regkey, bool wow6432node) | ||
{ | ||
using RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, wow6432node ? RegistryView.Registry32 : RegistryView.Registry64); | ||
using RegistryKey installed = hklm.OpenSubKey(regkey); | ||
foreach (string id in installed.GetSubKeyNames()) | ||
{ | ||
using RegistryKey program = installed.OpenSubKey(id); | ||
string displayName = (string)program.GetValue("DisplayName"); | ||
|
||
if (displayNames.Contains(displayName)) | ||
return ((string)program.GetValue("InstallLocation") ?? Path.GetDirectoryName((string)program.GetValue("DisplayIcon")), false); | ||
else if (gotyName == (string)program.GetValue("DisplayName")) | ||
return ((string)program.GetValue("InstallLocation") ?? Path.GetDirectoryName((string)program.GetValue("DisplayIcon")), true); | ||
} | ||
|
||
return (null, false); | ||
} | ||
|
||
public override string StartupPath { get; } | ||
|
||
public override string ExecutablePath => StartupPath + '\\' + ProcessName; | ||
|
||
public override string ProcessName => GOTY ? "popcapgame1" : "PlantsVsZombies"; | ||
|
||
public bool GOTY { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30114.105 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PvZTools", "PvZTools.csproj", "{5E62F60C-F31E-44D3-82BF-8256F0297011}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelOrca.MemPatch", "..\IntelOrca.MemPatch\IntelOrca.MemPatch.csproj", "{28741DD2-F467-446E-A363-6814DAEA23F6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|Mixed Platforms = Debug|Mixed Platforms | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|Mixed Platforms = Release|Mixed Platforms | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Debug|Any CPU.ActiveCfg = Debug|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Debug|Mixed Platforms.Build.0 = Debug|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Debug|x86.ActiveCfg = Debug|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Debug|x86.Build.0 = Debug|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Release|Any CPU.ActiveCfg = Release|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Release|Mixed Platforms.ActiveCfg = Release|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Release|Mixed Platforms.Build.0 = Release|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Release|x86.ActiveCfg = Release|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Release|x86.Build.0 = Release|x86 | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5E62F60C-F31E-44D3-82BF-8256F0297011}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Release|Mixed Platforms.Build.0 = Release|Any CPU | ||
{28741DD2-F467-446E-A363-6814DAEA23F6}.Release|x86.ActiveCfg = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A546983C-15DA-41C6-BB8F-6B179E44471D} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration> |