Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

Fix default compatibility tool picker

NotProtonNota63f6f6575e0
diff --git a/dylib/feats/compat.c b/dylib/feats/compat.c
index 7b6f25c..a26d2a7 100644
--- a/dylib/feats/compat.c
+++ b/dylib/feats/compat.c
@@ -812,6 +812,11 @@ void np_compat_register_crossover(void *compat_mgr) {
}
}
+const char *np_compat_fallback_tool_name(void) {
+ load_tool_list_once();
+ return g_tool_count > 0 ? g_tools[0].name : TOOL_DIR_NAME;
+}
+
void *np_compat_registered_tool(void *compat_mgr) {
if (!compat_mgr)
return NULL;
diff --git a/dylib/feats/compat.h b/dylib/feats/compat.h
index 0dbb5b9..8468070 100644
--- a/dylib/feats/compat.h
+++ b/dylib/feats/compat.h
@@ -117,6 +117,9 @@ void *np_compat_manager(void);
// Manager-owned. Callers read fields without taking ownership.
void *np_compat_registered_tool(void *compat_mgr);
+// Name of the first tool in the app's list, which unmapped Windows games run under.
+const char *np_compat_fallback_tool_name(void);
+
uint32_t np_compat_manager_tools_max(void);
// Absolute path to the directory of the first tool in the app's list, or NULL.
diff --git a/dylib/feats/webpatch.c b/dylib/feats/webpatch.c
index 1a1e786..a9dc607 100644
--- a/dylib/feats/webpatch.c
+++ b/dylib/feats/webpatch.c
@@ -15,6 +15,11 @@
#define NP_C8 "\010"
#define NP_CAP_MAX 8
+// Stands for the name set by np_webpatch_set_fallback_tool.
+#define NP_FALLBACK_TOOL "\021"
+
+static char g_fallback_tool[128];
+
typedef struct {
const char *find;
const char *replace;
@@ -32,12 +37,29 @@ static int cap_index(unsigned char c) {
return (c >= 1 && c <= NP_CAP_MAX) ? c - 1 : -1;
}
+void np_webpatch_set_fallback_tool(const char *name) {
+ g_fallback_tool[0] = '\0';
+ if (!name) return;
+ size_t n = strlen(name);
+ if (n >= sizeof(g_fallback_tool)) return;
+ for (size_t i = 0; i < n; i++)
+ if (!is_ident_char((unsigned char)name[i]) && name[i] != '.' && name[i] != '-')
+ return;
+ memcpy(g_fallback_tool, name, n + 1);
+}
+
static size_t match_at(const char *src, size_t len, size_t pos,
const char *find, np_cap_t *caps) {
for (int i = 0; i < NP_CAP_MAX; i++) { caps[i].at = NULL; caps[i].len = 0; }
size_t s = pos;
for (const char *f = find; *f; f++) {
+ if (*f == NP_FALLBACK_TOOL[0]) {
+ size_t n = strlen(g_fallback_tool);
+ if (s + n > len || memcmp(src + s, g_fallback_tool, n) != 0) return 0;
+ s += n;
+ continue;
+ }
int ci = cap_index((unsigned char)*f);
if (ci < 0) {
if (s >= len || src[s] != *f) return 0;
@@ -93,6 +115,10 @@ static int out_put(np_out_t *o, const char *p, size_t n) {
static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {
for (const char *r = replace; *r; r++) {
+ if (*r == NP_FALLBACK_TOOL[0]) {
+ if (!out_put(o, g_fallback_tool, strlen(g_fallback_tool))) return 0;
+ continue;
+ }
int ci = cap_index((unsigned char)*r);
if (ci < 0) {
if (!out_put(o, r, 1)) return 0;
@@ -328,6 +354,15 @@ static const np_gate_t g_fixes[] = {
"(t.unAppID,r),o=r&&!!t.strCompatToolName&&t.nCompatToolPriority==h.JN,"
"l=a.length?(a.find(e=>e.strToolName===u.rV.settings.strCompatTool)||a[0]).strToolName:\"\"",
1 },
+ // Shows the default tool picker before a default has been saved
+ { "return " NP_C1 "?(0," NP_C2 ".jsx)(" NP_C3 ".B,{feature:" NP_C4 ".OK,label:(0," NP_C5 ".we)"
+ "(\"#Settings_SteamPlay_DefaultTool\"),rgOptions:" NP_C6 ",disabled:0==" NP_C6 ".length,"
+ "selectedOption:" NP_C1 ",",
+ "return(" NP_C1 "||" NP_C6 ".some(e=>e.data===\"" NP_FALLBACK_TOOL "\"))?(0," NP_C2 ".jsx)("
+ NP_C3 ".B,{feature:" NP_C4 ".OK,label:(0," NP_C5 ".we)"
+ "(\"#Settings_SteamPlay_DefaultTool\"),rgOptions:" NP_C6 ",disabled:0==" NP_C6 ".length,"
+ "selectedOption:" NP_C1 "||\"" NP_FALLBACK_TOOL "\",",
+ 1 },
{ "this.m_bServicesInitialized=!0,SteamClient.UI.NotifyAppInitialized()",
"this.m_bServicesInitialized=!0," NP_LAUNCH_MIGRATION ",SteamClient.UI.NotifyAppInitialized()", 1 },
};
diff --git a/dylib/feats/webpatch.h b/dylib/feats/webpatch.h
index b97f9f4..3d83f99 100644
--- a/dylib/feats/webpatch.h
+++ b/dylib/feats/webpatch.h
@@ -7,6 +7,10 @@
int np_webpatch_should_patch(const char *path);
+// The tool the default tool picker shows before a default has been saved. Names with
+// characters outside letters, digits, '_', '$', '.' and '-' are dropped.
+void np_webpatch_set_fallback_tool(const char *name);
+
// The compat UIs, named so a caller can compare against the table rather than a literal
// of its own that a rename would leave behind. forcetool calls SpecifyCompatTool straight
// out; selecttool reads its list from the CompatManager routes.
diff --git a/dylib/hooks/hook_webpatch.c b/dylib/hooks/hook_webpatch.c
index d80e5c8..36bc867 100644
--- a/dylib/hooks/hook_webpatch.c
+++ b/dylib/hooks/hook_webpatch.c
@@ -3,6 +3,7 @@
// not modified, to keep the Steam bootstrap happy.
#include "../feats/webpatch.h"
+#include "../feats/compat.h"
#include "../feats/compatsvc.h"
#include "../util/file.h"
#include "../util/log.h"
@@ -119,6 +120,7 @@ static int open_patched(const char *path) {
}
close(in);
+ np_webpatch_set_fallback_tool(np_compat_fallback_tool_name());
size_t patched_len = 0;
const char *shape = NULL;
char *patched = np_webpatch_transform((const uint8_t *)raw, raw_len, &patched_len,
diff --git a/dylib/tests/gatecheck.c b/dylib/tests/gatecheck.c
index ac31c9b..5f67321 100644
--- a/dylib/tests/gatecheck.c
+++ b/dylib/tests/gatecheck.c
@@ -215,6 +215,8 @@ int main(int argc, char **argv) {
if (argc < 2) { selfcheck(); return g_wrong; }
+ np_webpatch_set_fallback_tool("notproton-fex");
+
for (int i = 1; i < argc; i++) {
size_t len = 0;
uint8_t *buf = slurp(argv[i], &len);
diff --git a/dylib/tests/webpatch-fixtures/gates.forcetool.js b/dylib/tests/webpatch-fixtures/gates.forcetool.js
index 46dff1b..84f1be3 100644
--- a/dylib/tests/webpatch-fixtures/gates.forcetool.js
+++ b/dylib/tests/webpatch-fixtures/gates.forcetool.js
@@ -8,3 +8,4 @@ r_client_data.active_beta}get is_available_on_current_platform(){return this.loc
ie().HidePlayBar,bInPage:!0,details:a,overview:s,stickyheader:p,onGameInfoToggle:o,onSeek:t.SeekToSection,bShowInfoExpanded:h,bShowingLaunchDetails:_},s.appid),s.is_invalid_os_type&&(0,n.jsx)(U,{}),r.has("info")&&(0,n.jsx)(x.b,{concise:i,overview:s,details:a,expand:h,suppressTransition:C}),(0,n.jsx)(k.Qd,{overview:s,details:a,workshopVisible:f,marketPrese
,{})}),(0,h.we)("#GameList_Entry_Invalid_OSType")]}),(0,n.jsx)("div",{className:z().WarningText,children:(0,n.jsxs)("div",{className:z().WarningText2,children:[(0,h.we)("#GameList_Entry_Invalid_OSType2"),(0,n.jsx)("a",{href:"https://help.steampowered.com/faqs/view/5E0D-522A-4E62-B6EF",className:z().WarningText3,children:(0,h.we)("#GameList_Entry_Invalid_OSType3
,i.jsx)(St,{details:t,rgLaunchOptionsForApp:r}),(0,i.jsx)(vt,{details:t,bAndroidArm64Native:n,bLinuxArm64Native:s})]})}const It=(0,a.PA)(e=>{const{details:t}=e,r=(0,s.q3)(()=>u.rV.settings.bCompatEnabled),a=function(e,t){const[r,i]=n.useState([]);return n.useEffect(()=>{SteamClient.Apps.GetAvailableCompatTools(e).then(i)},[e,t]),r}(t.unAppID,r),o=r&&!!t.strCompatToolName&&t.nCompatToolPriority==h.JN,l=a.length?a[0].strToolName:"",d=a.map(e=>({data:e.strToolName,label:e.strDisplayName})),[m,p]=n.useState(!1),g=o||m,C=n.useCallback(e=>{p(e),e?SteamClient.Apps.SpecifyCompatTool(t.unAppID,o
+estartLater"),fnOnOK:()=>{},ownerWindow:e.ownerWindow})},[e])]}(),A=r?.map(e=>({label:e.strDisplayName,data:e.strToolName}))??[],g=n.useCallback(e=>{s(e)},[s]);return t?(0,i.jsx)(m.B,{feature:p.OK,label:(0,l.we)("#Settings_SteamPlay_DefaultTool"),rgOptions:A,disabled:0==A.length,selectedOption:t,onChange:e=>g(e.data),strDropDownButtonClassName:a().EnableSteamPlayForOthersDropdownButton,bMatchWidth:!1,bottomSeparator:e.bottomSeparator}):null}function h(e