Frogging-Family / wine-tkg-git

The wine-tkg build systems, to create custom Wine and Proton builds
863 stars 156 forks source link

Fix for recent 5.0.8 steamclient swap patch #62

Closed GloriousEggroll closed 4 years ago

GloriousEggroll commented 4 years ago

Managed to get this working after some help from aeikum and with Herbert over discord. There's two parts.

Part 1: change these two lines in the LAA patch:

    if ((ptr = strrchrW( name, '\\' ))) name = ptr + 1;
    if ((ptr = strrchrW( name, '/' ))) name = ptr + 1;

to:

    if ((ptr = wcsrchr( name, '\\' ))) name = ptr + 1;
    if ((ptr = wcsrchr( name, '/' ))) name = ptr + 1;

This should be done anyway as Herbert described: "the whole thing is about removing wine/unicode.h and libport usage from ntdll IIUC so strrchrW and such have to be replaced with standard msvcrt functions"

Part 2: here's the updated patch which uses RtlCompareUnicodeStrings as wine did when they made the switch from wine/unicode.h to msvcrt:

From cb95c72878a011d59e8d6f91f84cd0539d899661 Mon Sep 17 00:00:00 2001
From: Jan Sikorski <jsikorski@codeweavers.com>
Date: Mon, 20 Apr 2020 16:41:52 +0200
Subject: [PATCH] steam: ntdll: When swapping steamclient.dll, match basename
 exactly

---
 dlls/ntdll/loader.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 2979061a5e2..360b43dc382 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -1604,15 +1604,14 @@ static WCHAR builtin_steamclient_w[] = {'C',':','\\','w','i','n','d','o','w','s'
                                         's','t','e','a','m','c','l','i','e','n','t','6','4','.','d','l','l',0};
 static WCHAR native_steamclient_w[] = {'C',':','\\','P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\\','S','t','e','a','m','\\',
                                        's','t','e','a','m','c','l','i','e','n','t','6','4','.','d','l','l',0};
-static WCHAR steamclient_w[] = {'s','t','e','a','m','c','l','i','e','n','t','6','4',0};
+static WCHAR steamclient_w[] = {'s','t','e','a','m','c','l','i','e','n','t','6','4','.','d','l','l',0};
 #else
 static WCHAR builtin_steamclient_w[] = {'C',':','\\','w','i','n','d','o','w','s','\\','s','y','s','t','e','m','3','2','\\',
                                         's','t','e','a','m','c','l','i','e','n','t','.','d','l','l',0};
 static WCHAR native_steamclient_w[] = {'C',':','\\','P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\\','S','t','e','a','m','\\',
                                        's','t','e','a','m','c','l','i','e','n','t','.','d','l','l',0};
-static WCHAR steamclient_w[] = {'s','t','e','a','m','c','l','i','e','n','t',0};
+static WCHAR steamclient_w[] = {'s','t','e','a','m','c','l','i','e','n','t','.','d','l','l',0};
 #endif
-static WCHAR lsteamclient_w[] = {'l','s','t','e','a','m','c','l','i','e','n','t',0};

 static WCHAR *strstriW( const WCHAR *str, const WCHAR *sub )
 {
@@ -3254,10 +3264,13 @@ NTSTATUS WINAPI DECLSPEC_HOTPATCH LdrLoadDll(LPCWSTR path_name, DWORD flags,
 {
     WINE_MODREF *wm;
     NTSTATUS nts;
+    const WCHAR *basename;

     RtlEnterCriticalSection( &loader_section );

-    if (!(flags & LDR_STEAM_INTERNAL) && strstriW(libname->Buffer, steamclient_w) && !strstriW(libname->Buffer, lsteamclient_w))
+    if (!(flags & LDR_STEAM_INTERNAL) && (basename = get_basename(libname->Buffer)) &&
+        !RtlCompareUnicodeStrings(steamclient_w, wcslen(steamclient_w),
+                                  basename, wcslen(basename), TRUE))
     {
         *hModule = get_builtin_steamclient_mod(TRUE);
         swap_builtin_to_native_steamclient_hack(hModule);

Here's the reference from aeikum:

https://github.com/wine-mirror/wine/commit/4d93bafe961ed53488ff0fb4b44cb1ad085531fe

I tested this with TOXIKK (purchased copy, not free version), and it loaded properly with access to purchased parts.

rbernon commented 4 years ago

I forgot when writing the patch but strlenW could also be replaced with wcslen here and elsewhere in the patches. It should still work for now, but may be required in the future.

GloriousEggroll commented 4 years ago

thanks for the heads up, i just made a quick edit to it for consistency