Skip to content

Commit

Permalink
Merge pull request #14 from lonemeow/hook-version-check
Browse files Browse the repository at this point in the history
Check for outdated hook DLL version.
  • Loading branch information
lonemeow authored Feb 8, 2024
2 parents 454e31e + a7dbdb5 commit dd7bd83
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
submodules: 'true'
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Update DLL version
run: |
client-hooks/makever.ps1 ${{ inputs.app_version }} client-hooks/version.h
- name: Build app
run: |
msbuild /t:publish /restore /p:PublishProfile=FolderProfile /property:Configuration=Release
Expand Down
12 changes: 11 additions & 1 deletion client-gui/ACCHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public static bool IsHookInstalled(string accInstallPath) {
return File.Exists(InstallPathToDllPath(accInstallPath));
}

public static bool IsHookOutdated(string accInstallPath) {
if (IsHookInstalled(accInstallPath)) {
var myInfo = FileVersionInfo.GetVersionInfo(FindHookDLL());
var verInfo = FileVersionInfo.GetVersionInfo(InstallPathToDllPath(accInstallPath));
Trace.WriteLine($"Installed hook version: {verInfo.ProductVersion} my version {myInfo.ProductVersion}");
return myInfo.ProductVersion != verInfo.ProductVersion;
}
return false;
}

private static string InstallPathToDllPath(string accInstallPath) {
return Path.Join(accInstallPath, "AC2", "Binaries", "Win64", "hid.dll");
}
Expand All @@ -107,7 +117,7 @@ public static void RemoveHook(string accInstallPath) {

public static void InstallHook(string accInstallPath) {
var dllPath = InstallPathToDllPath(accInstallPath);
File.Copy(FindHookDLL(), dllPath);
File.Copy(FindHookDLL(), dllPath, true);
Trace.WriteLine($"Copied hook DLL to {dllPath}");
}
}
Expand Down
39 changes: 28 additions & 11 deletions client-gui/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using Win32;
Expand All @@ -20,6 +19,7 @@ protected override void OnLoad(EventArgs e) {
User32.SetWindowLongPtr(Handle, User32.GWLP_USERDATA, Constants.TAG);

base.OnLoad(e);
CheckHookVersion();
UpdateHookButton();
}

Expand Down Expand Up @@ -49,6 +49,31 @@ protected override void WndProc(ref Message m) {
}
}

private void CheckHookVersion() {
if (ACCHook.IsHookOutdated(settings.AccInstallPath)) {
var msg = """
Hook from a different version of ACC Connector seems to be installed.
Do you want to replace it with the hook from this version?
""";
if (MessageBox.Show(msg, "ACC Connector", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
InstallHook();
}
}
}

private void InstallHook() {
if (ACCHook.IsACCRunning()) {
var message = """
ACC seems to be running.
The hook may fail to install, and even if it succceeds it won't take effect until you restart the game.
""";
if (MessageBox.Show(message, "ACC Connector", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) {
return;
}
}
ACCHook.InstallHook(settings.AccInstallPath);
}

private void UpdateHookButton() {
if (ACCHook.IsHookInstalled(settings.AccInstallPath)) {
hookButton.Text = "Remove\nhook";
Expand All @@ -70,6 +95,7 @@ private void SettingsButton_Click(object sender, EventArgs e) {
if (settingsDialog.ShowDialog() == DialogResult.OK) {
settings = tempSettings;
Settings.Save(settings);
UpdateHookButton();
}
}

Expand All @@ -94,16 +120,7 @@ private void HookButton_Click(object sender, EventArgs e) {
if (ACCHook.IsHookInstalled(settings.AccInstallPath)) {
ACCHook.RemoveHook(settings.AccInstallPath);
} else {
if (ACCHook.IsACCRunning()) {
var message = """
ACC seems to be running.
The hook may fail to install, and even if it succceeds it won't take effect until you restart the game.
""";
if (MessageBox.Show(message, "ACC Connector", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) {
return;
}
}
ACCHook.InstallHook(settings.AccInstallPath);
InstallHook();
}
UpdateHookButton();
}
Expand Down
8 changes: 8 additions & 0 deletions client-hooks/makever.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
param($ver, $file)

$major, $minor = $ver -split "\."

@"
#define VERSION_BIN $major,$minor,0,0
#define VERSION_STR "$major.$minor.0.0"
"@ | Out-File -Encoding ASCII $file
Binary file modified client-hooks/proxy.rc
Binary file not shown.
2 changes: 2 additions & 0 deletions client-hooks/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define VERSION_BIN 0,0,0,0
#define VERSION_STR "0.0.0.0"

0 comments on commit dd7bd83

Please sign in to comment.