From 54cd2f6e9a60f265f7b7159d533ab499a7166083 Mon Sep 17 00:00:00 2001 From: 888be1df7c6f962725a28a172a5394eec3e228e7 <888be1df7c6f962725a28a172a5394eec3e228e7@redacted> Date: Wed, 18 Dec 2019 21:30:35 +0100 Subject: [PATCH] hooklib/path.c: add slash-insensitive path comparison API --- hooklib/path.c | 29 +++++++++++++++++++++++++++++ hooklib/path.h | 1 + platform/vfs.c | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/hooklib/path.c b/hooklib/path.c index 887a9e9..864d2e2 100644 --- a/hooklib/path.c +++ b/hooklib/path.c @@ -388,6 +388,35 @@ end: return ok; } +int path_compare_w(const wchar_t *string1, const wchar_t *string2, size_t count) +{ + size_t i; + wchar_t c1, c2; + + assert(string1 != NULL); + assert(string2 != NULL); + + for (i = 0; i < count && string1[i] && string2[i]; i++) { + c1 = towlower(string1[i]); + + if (c1 == '/') { + c1 = '\\'; + } + + c2 = towlower(string2[i]); + + if (c2 == '/') { + c2 = '\\'; + } + + if (c1 != c2) { + break; + } + } + + return i == count ? 0 : string2[i] - string1[i]; +} + /* Dumping ground for kernel32 file system ops whose path parameters we have to hook into and translate. This list will grow over time as we go back and fix up older games that don't pay attention to the mount point registry. */ diff --git a/hooklib/path.h b/hooklib/path.h index 9e7b408..779e013 100644 --- a/hooklib/path.h +++ b/hooklib/path.h @@ -10,3 +10,4 @@ typedef HRESULT (*path_hook_t)( size_t *count); HRESULT path_hook_push(path_hook_t hook); +int path_compare_w(const wchar_t *string1, const wchar_t *string2, size_t count); diff --git a/platform/vfs.c b/platform/vfs.c index 689cd44..d78e6b5 100644 --- a/platform/vfs.c +++ b/platform/vfs.c @@ -273,7 +273,7 @@ static HRESULT vfs_path_hook_nthome( /* Case-insensitive check to see if src starts with vfs_nthome */ - if (_wcsnicmp(src, vfs_nthome, vfs_nthome_len) != 0) { + if (path_compare_w(src, vfs_nthome, vfs_nthome_len) != 0) { return S_FALSE; }