Skip to content

armgit / soju

Public Imported from GitHub
0

Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.

patches: atomic key files, damaged keys count as absent, deletions stay deletions

mikey9212d654592d91
diff --git a/docs/DIAGNOSIS.md b/docs/DIAGNOSIS.md
index 75503b5cb4c..a618c706687 100644
--- a/docs/DIAGNOSIS.md
+++ b/docs/DIAGNOSIS.md
@@ -209,6 +209,11 @@ override가 적용되는 것은 regsvr32로 확인했다. `SOJU_EPIC_OVERLAY=1`
입력 소스는 게임 전에 영어(ABC)로 두고 게임 중에는 바꾸지 않는다. 입력 소스 전환 자체가
포커스 이탈 트리거다.
+리뷰에서 나온 패치 자체의 빈틈 두 가지. (1) 앞쪽 Wine 창이 없으면 비트맵만 지우고 이벤트를
+안 보냈는데, 그러면 나중에 진짜 key up이 와도 "안 눌린 키"라며 버린다. 창이 없으면 비트맵을 그대로
+두도록 고쳤다. (2) 릴리스를 `frontWineWindow`로 보내는데 그것이 키를 누른 창이 아닐 수 있다
+(오버레이 창이 맨 앞인 경우). 키마다 누른 창을 기억해야 제대로 고쳐지며, 아직 안 했다.
+
## 켜둔 런처가 먹통이 되는 이유: wineserver를 잃은 고아 프로세스 (2026-08-31)
### 증상
diff --git a/patches/chromium-flags-append.patch b/patches/chromium-flags-append.patch
index 2f01239cb02..aee871ca644 100644
--- a/patches/chromium-flags-append.patch
+++ b/patches/chromium-flags-append.patch
@@ -1,6 +1,6 @@
--- a/dlls/kernelbase/process.c
-+++ b/dlls/kernelbase/process.c 2026-08-30 01:16:39
-@@ -1815,10 +1815,33 @@
++++ b/dlls/kernelbase/process.c
+@@ -1719,10 +1719,33 @@
/***********************************************************************
* SetEnvironmentVariableW (kernelbase.@)
*/
@@ -15,7 +15,7 @@
+ DWORD len, vlen;
+ WCHAR *ret;
+
-+ if (!name || wcsicmp( name, L"QTWEBENGINE_CHROMIUM_FLAGS" )) return NULL;
++ if (!name || !value || wcsicmp( name, L"QTWEBENGINE_CHROMIUM_FLAGS" )) return NULL; /* NULL value = delete */
+ len = GetEnvironmentVariableW( L"SOJU_CHROMIUM_FLAGS", extra, ARRAY_SIZE(extra) );
+ if (!len || len >= ARRAY_SIZE(extra)) return NULL;
+ if (value && wcsstr( value, extra )) return NULL;
@@ -34,9 +34,9 @@
TRACE( "(%s %s)\n", debugstr_w(name), debugstr_w(value) );
-@@ -1834,6 +1857,12 @@
- if (!wcscmp( name, L"VK_ICD_FILENAMES" ) && value && is_ubisoft())
- write_ubisoft_vulkan_json( value );
+@@ -1732,6 +1755,12 @@
+ return FALSE;
+ }
+ if ((soju_value = soju_append_chromium_flags( name, value )))
+ {
@@ -47,7 +47,7 @@
RtlInitUnicodeString( &us_name, name );
if (value)
{
-@@ -1842,6 +1871,7 @@
+@@ -1740,6 +1769,7 @@
}
else status = RtlSetEnvironmentVariable( NULL, &us_name, NULL );
@@ -57,7 +57,7 @@
--- a/dlls/msvcrt/environ.c
+++ b/dlls/msvcrt/environ.c
-@@ -144,11 +144,41 @@
+@@ -144,11 +144,42 @@
return i;
}
@@ -76,6 +76,7 @@
+ size_t wl, al;
+
+ if (wcsnicmp(*wenv, prefix, ARRAY_SIZE(prefix) - 1)) return;
++ if (!(*wenv)[ARRAY_SIZE(prefix) - 1]) return; /* "NAME=" removes the variable: leave it removed */
+ len = GetEnvironmentVariableW(L"SOJU_CHROMIUM_FLAGS", extra, ARRAY_SIZE(extra));
+ if (!len || len >= ARRAY_SIZE(extra)) return;
+ if (wcsstr(*wenv, extra)) return;
diff --git a/patches/ncrypt-persisted-keys.patch b/patches/ncrypt-persisted-keys.patch
index 3ee4511a58b..667be16cfde 100644
--- a/patches/ncrypt-persisted-keys.patch
+++ b/patches/ncrypt-persisted-keys.patch
@@ -54,12 +54,10 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
struct storage_provider
--- a/dlls/ncrypt/main.c
+++ b/dlls/ncrypt/main.c
-@@ -124,6 +124,190 @@
- memcpy(property->value, value, value_size);
-
+@@ -126,6 +126,213 @@
return ERROR_SUCCESS;
-+}
-+
+ }
+
+/* Persistent key storage.
+ *
+ * Windows keeps a user's CNG keys under %APPDATA%\Microsoft\Crypto\Keys, so a
@@ -153,13 +151,19 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
+ const WCHAR *blob_type;
+ SECURITY_STATUS ret = NTE_INTERNAL_ERROR;
+ BYTE *blob = NULL;
-+ WCHAR *path;
++ WCHAR *path, *tmp = NULL;
+ DWORD blob_len = 0, written;
+ NTSTATUS status;
+ HANDLE file;
+
+ if (!(blob_type = blob_type_for_algid(algid))) return NTE_NOT_SUPPORTED;
+ if (!(path = key_store_path(name))) return NTE_INTERNAL_ERROR;
++ /* Write next to the final name and rename over it, so a crash or a full
++ * disk mid-write cannot leave a truncated key behind: that would fail to
++ * open (NTE_BAD_KEYSET) yet count as existing (NTE_EXISTS) forever. */
++ if (!(tmp = malloc((lstrlenW(path) + 5) * sizeof(WCHAR)))) { ret = NTE_NO_MEMORY; goto done; }
++ lstrcpyW(tmp, path);
++ lstrcatW(tmp, L".tmp");
+
+ status = BCryptExportKey(bcrypt_key, NULL, blob_type, NULL, 0, &blob_len, 0);
+ if (status != STATUS_SUCCESS) goto done;
@@ -167,33 +171,50 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
+ status = BCryptExportKey(bcrypt_key, NULL, blob_type, blob, blob_len, &blob_len, 0);
+ if (status != STATUS_SUCCESS) goto done;
+
-+ file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
++ file = CreateFileW(tmp, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (file == INVALID_HANDLE_VALUE) goto done;
+
+ header.magic = KEY_STORE_MAGIC;
+ header.algid = algid;
+ header.blob_len = blob_len;
+ if (WriteFile(file, &header, sizeof(header), &written, NULL) && written == sizeof(header) &&
-+ WriteFile(file, blob, blob_len, &written, NULL) && written == blob_len)
++ WriteFile(file, blob, blob_len, &written, NULL) && written == blob_len &&
++ FlushFileBuffers(file))
+ ret = ERROR_SUCCESS;
+ CloseHandle(file);
-+ if (ret != ERROR_SUCCESS) DeleteFileW(path);
++ if (ret == ERROR_SUCCESS && !MoveFileExW(tmp, path, MOVEFILE_REPLACE_EXISTING)) ret = NTE_INTERNAL_ERROR;
++ if (ret != ERROR_SUCCESS) DeleteFileW(tmp);
+
+done:
+ free(blob);
++ free(tmp);
+ free(path);
+ return ret;
+}
+
++/* A stored key counts as existing only if it can be read back. A damaged
++ * file must look absent: otherwise the caller's open fails with
++ * NTE_BAD_KEYSET, its create then fails with NTE_EXISTS, and nothing short of
++ * deleting the file by hand gets it out of that loop. */
+static BOOL key_store_exists(const WCHAR *name)
+{
++ struct key_store_header header;
+ WCHAR *path;
-+ DWORD attr;
++ HANDLE file;
++ DWORD read, size;
++ BOOL ok = FALSE;
+
+ if (!(path = key_store_path(name))) return FALSE;
-+ attr = GetFileAttributesW(path);
++ file = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ free(path);
-+ return attr != INVALID_FILE_ATTRIBUTES;
++ if (file == INVALID_HANDLE_VALUE) return FALSE;
++ size = GetFileSize(file, NULL);
++ if (ReadFile(file, &header, sizeof(header), &read, NULL) && read == sizeof(header) &&
++ header.magic == KEY_STORE_MAGIC && header.blob_len && header.blob_len <= 0x10000 &&
++ size == sizeof(header) + header.blob_len)
++ ok = TRUE;
++ CloseHandle(file);
++ return ok;
+}
+
+static SECURITY_STATUS read_key_store(const WCHAR *name, enum algid *algid, BCRYPT_KEY_HANDLE *bcrypt_key,
@@ -242,10 +263,12 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
+ free(blob);
+ CloseHandle(file);
+ return ret;
- }
-
++}
++
static struct object *create_key_object(enum algid algid, NCRYPT_PROV_HANDLE provider)
-@@ -150,6 +334,26 @@
+ {
+ NCRYPT_SUPPORTED_LENGTHS supported_lengths = {512, 16384, 8, 1024};
+@@ -150,6 +357,26 @@
set_object_property(object, BCRYPT_SIGNATURE_LENGTH, (BYTE *)&dw_value, sizeof(dw_value));
break;
@@ -272,7 +295,7 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
default:
ERR("Invalid algid %#x\n", algid);
return NULL;
-@@ -175,7 +379,7 @@
+@@ -175,7 +402,7 @@
if (!provider) return NTE_INVALID_HANDLE;
if (!algid) return HRESULT_FROM_WIN32(RPC_X_NULL_REF_POINTER);
@@ -281,7 +304,7 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
if (!lstrcmpiW(algid, BCRYPT_RSA_ALGORITHM))
{
-@@ -199,12 +403,39 @@
+@@ -199,12 +426,39 @@
set_object_property(object, NCRYPT_LENGTH_PROPERTY, (BYTE *)&default_bitlen, sizeof(default_bitlen));
set_object_property(object, BCRYPT_PUBLIC_KEY_LENGTH, (BYTE *)&default_bitlen, sizeof(default_bitlen));
}
@@ -321,7 +344,7 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
*key = (NCRYPT_KEY_HANDLE)object;
return ERROR_SUCCESS;
}
-@@ -219,8 +450,19 @@
+@@ -219,8 +473,19 @@
SECURITY_STATUS WINAPI NCryptDeleteKey(NCRYPT_KEY_HANDLE key, DWORD flags)
{
@@ -343,7 +366,7 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
}
SECURITY_STATUS WINAPI NCryptEncrypt(NCRYPT_KEY_HANDLE key, BYTE *input, DWORD insize, void *padding,
-@@ -277,11 +519,16 @@
+@@ -277,11 +542,16 @@
if (!(prop = get_object_property(object, NCRYPT_LENGTH_PROPERTY))) return NTE_INVALID_HANDLE;
key_length = *(DWORD *)prop->value;
@@ -364,10 +387,12 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
}
status = BCryptFinalizeKeyPair(object->key.bcrypt_key, 0);
-@@ -291,6 +538,19 @@
+@@ -289,6 +559,19 @@
+ {
+ ERR("Error finalizing key pair\n");
return map_ntstatus(status);
- }
-
++ }
++
+ if (object->key.name)
+ {
+ /* Report a storage failure rather than hiding it: a caller told its
@@ -379,12 +404,10 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
+ WARN("could not store key %s\n", wine_dbgstr_w(object->key.name));
+ return ret;
+ }
-+ }
-+
- return ERROR_SUCCESS;
- }
+ }
-@@ -302,6 +562,8 @@
+ return ERROR_SUCCESS;
+@@ -302,6 +585,8 @@
static SECURITY_STATUS free_key_object(struct key *key)
{
@@ -393,7 +416,7 @@ taken from its blob so a 2048 bit RSA key does not come back claiming 1024.
return map_ntstatus( BCryptDestroyKey(key->bcrypt_key) );
}
-@@ -512,8 +774,42 @@
+@@ -512,8 +797,42 @@
SECURITY_STATUS WINAPI NCryptOpenKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_HANDLE *key,
const WCHAR *name, DWORD keyspec, DWORD flags)
{
diff --git a/patches/winemac-release-keys-on-focus-loss.patch b/patches/winemac-release-keys-on-focus-loss.patch
index 4db526a8309..7774a0a50a6 100644
--- a/patches/winemac-release-keys-on-focus-loss.patch
+++ b/patches/winemac-release-keys-on-focus-loss.patch
@@ -18,7 +18,7 @@ and fall back to the front window for a key up that arrives without one.
--- a/dlls/winemac.drv/cocoa_app.h
+++ b/dlls/winemac.drv/cocoa_app.h
-@@ -122,6 +122,7 @@
+@@ -110,6 +110,7 @@
- (void) computeEventTimeAdjustmentFromTicks:(unsigned long long)tickcount uptime:(uint64_t)uptime_ns;
- (double) ticksForEventTime:(NSTimeInterval)eventTime;
@@ -28,7 +28,7 @@ and fall back to the front window for a key up that arrives without one.
--- a/dlls/winemac.drv/cocoa_app.m
+++ b/dlls/winemac.drv/cocoa_app.m
-@@ -1402,6 +1402,39 @@
+@@ -1257,6 +1257,43 @@
int index = keyCode / bits;
uint32_t mask = 1 << (keyCode % bits);
return (pressedKeyCodes[index] & mask) != 0;
@@ -48,6 +48,11 @@ and fall back to the front window for a key up that arrives without one.
+ int bits = sizeof(pressedKeyCodes[0]) * 8;
+ unsigned int i;
+
++ /* Nowhere to deliver a release: keep our record of the held keys, so
++ * the real key up, when it does arrive, is still recognised and
++ * forwarded rather than dropped as a release of an unpressed key. */
++ if (!window) return;
++
+ for (i = 0; i < sizeof(pressedKeyCodes) / sizeof(pressedKeyCodes[0]) * bits; i++)
+ {
+ macdrv_event* event;
@@ -56,7 +61,6 @@ and fall back to the front window for a key up that arrives without one.
+ if (![self isKeyPressed:i]) continue;
+
+ [self noteKey:i pressed:FALSE];
-+ if (!window) continue;
+
+ event = macdrv_create_event(KEY_RELEASE, window);
+ event->key.keycode = i;
@@ -68,7 +72,7 @@ and fall back to the front window for a key up that arrives without one.
}
- (void) noteKey:(uint16_t)keyCode pressed:(BOOL)pressed
-@@ -1965,7 +1998,13 @@
+@@ -1820,7 +1857,13 @@
{
WineWindow* window = (WineWindow*)[anEvent window];
[self noteKey:keyCode pressed:FALSE];
@@ -83,11 +87,11 @@ and fall back to the front window for a key up that arrives without one.
[window postKeyEvent:anEvent];
}
}
-@@ -2513,6 +2552,7 @@
+@@ -2209,6 +2252,7 @@
WineEventQueue* queue;
[self invalidateGotFocusEvents];
+ [self releasePressedKeys];
- if (!temporarilyIgnoreResignEventsForDialog)
- {
+ event = macdrv_create_event(APP_DEACTIVATED, nil);
+