Skip to content

Commit f6b72d2

Browse files
committed
Support macOS port
The official macOS port does not use a /www subfolder and the game's root directory (where latest.log is placed) is the same directory the index.html and JavaScript files are in.
1 parent 2ef6b31 commit f6b72d2

1 file changed

Lines changed: 35 additions & 78 deletions

File tree

www/modloader/vfs_web.js

Lines changed: 35 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,30 @@ function _modLoader_install_debugger_vfs(shadowfs, nativefs) {
44
$modLoader.$vfsTrace("WEB REQUEST " + JSON.stringify(data));
55
let url = new URL(data.request.url);
66

7-
if ($modLoader.isInTestMode) {
8-
if (url.origin === window.location.origin) {
9-
let vfsPath = url.pathname;
10-
try {
11-
let rdata = await _vfs_resolve_file(vfsPath);
12-
let hS = "";
13-
for (let header in data.responseHeaders) {
14-
hS = `${hS}${header}: ${data.responseHeaders[header]}\n`;
15-
}
16-
17-
let responseBody = `HTTP/1.1 200 OK\n${hS}\n`;
18-
responseBody = Buffer.concat([Buffer.from(responseBody), rdata]).toString("base64");
19-
return {
20-
interceptionId: data.interceptionId,
21-
rawResponse: responseBody
22-
};
23-
} catch(e) {
24-
window._logLine("Error occured when building response body: " + e.stack);
25-
return {
26-
interceptionId: data.interceptionId
27-
}
7+
if (url.origin === window.location.origin) {
8+
let vfsPath = url.pathname.replace(/^[\/\\]*www[\/\\]*/, "");
9+
try {
10+
let rdata = await _vfs_resolve_file(vfsPath);
11+
let hS = "";
12+
for (let header in data.responseHeaders) {
13+
hS = `${hS}${header}: ${data.responseHeaders[header]}\n`;
2814
}
29-
} else {
15+
16+
let responseBody = `HTTP/1.1 200 OK\n${hS}\n`;
17+
responseBody = Buffer.concat([Buffer.from(responseBody), rdata]).toString("base64");
18+
return {
19+
interceptionId: data.interceptionId,
20+
rawResponse: responseBody
21+
};
22+
} catch(e) {
23+
window._logLine("Error occured when building response body: " + e.stack);
3024
return {
3125
interceptionId: data.interceptionId
3226
}
3327
}
3428
} else {
35-
if (url.origin === window.location.origin && url.pathname.startsWith("/www/")) {
36-
let vfsPath = url.pathname.replace(/^[\/\\]*www[\/\\]*/, "");
37-
try {
38-
let rdata = await _vfs_resolve_file(vfsPath);
39-
let hS = "";
40-
for (let header in data.responseHeaders) {
41-
hS = `${hS}${header}: ${data.responseHeaders[header]}\n`;
42-
}
43-
44-
let responseBody = `HTTP/1.1 200 OK\n${hS}\n`;
45-
responseBody = Buffer.concat([Buffer.from(responseBody), rdata]).toString("base64");
46-
return {
47-
interceptionId: data.interceptionId,
48-
rawResponse: responseBody
49-
};
50-
} catch(e) {
51-
window._logLine("Error occured when building response body: " + e.stack);
52-
return {
53-
interceptionId: data.interceptionId
54-
}
55-
}
56-
} else {
57-
return {
58-
interceptionId: data.interceptionId
59-
}
29+
return {
30+
interceptionId: data.interceptionId
6031
}
6132
}
6233
}
@@ -82,35 +53,19 @@ function _modLoader_install_debugger_vfs(shadowfs, nativefs) {
8253
chrome.debugger.sendCommand(debugee, "Network.continueInterceptedRequest", await buildResponseBody(data));
8354
}
8455
});
85-
if (!$modLoader.isInTestMode) {
86-
chrome.debugger.sendCommand(
87-
debugee,
88-
"Network.setRequestInterception",
89-
{
90-
enabled: true,
91-
patterns: [
92-
{
93-
urlPattern: window.location.origin + "/www/*",
94-
interceptionStage: "HeadersReceived"
95-
}
96-
]
97-
}
98-
);
99-
} else {
100-
chrome.debugger.sendCommand(
101-
debugee,
102-
"Network.setRequestInterception",
103-
{
104-
enabled: true,
105-
patterns: [
106-
{
107-
urlPattern: window.location.origin + "/*",
108-
interceptionStage: "HeadersReceived"
109-
}
110-
]
111-
}
112-
);
113-
}
56+
chrome.debugger.sendCommand(
57+
debugee,
58+
"Network.setRequestInterception",
59+
{
60+
enabled: true,
61+
patterns: [
62+
{
63+
urlPattern: window.location.origin + "/*",
64+
interceptionStage: "HeadersReceived"
65+
}
66+
]
67+
}
68+
);
11469

11570
setTimeout(resolve, 100);
11671
});
@@ -243,19 +198,21 @@ function _modLoader_install_debugger_vfs(shadowfs, nativefs) {
243198
$modLoader.$log(`[VFS_WEB] Proxy server listening on Port 127.0.0.1:${port}`);
244199

245200
function beforeRequestInterceptor(details) {
201+
$modLoader.$vfsTrace("VFS_WEB REQUEST " + JSON.stringify(details));
246202
let u = new URL(details.url);
247203
if (u.pathname === "/www/modloader/one_loader_sw.js") return null;
248204
return {redirectUrl: `http://127.0.0.1:${port}/${SERVER_KEY}${u.pathname}`}
249205
}
250206

251207
chrome.webRequest.onBeforeRequest.addListener(beforeRequestInterceptor, {
252208
urls: [
253-
window.location.origin + "/www/*",
254-
window.location.origin + "/" + TEST_KEY
209+
window.location.origin + "/*"
255210
]
256211
}, ["blocking"])
212+
$modLoader.$log(`[VFS_WEB] Registered request listener ${window.location.origin}`);
257213

258214
window.addEventListener("beforeunload", function(e) {
215+
$modLoader.$log(`[VFS_WEB] Unregistering request listener ${window.location.origin}`);
259216
chrome.webRequest.onBeforeRequest.removeListener(beforeRequestInterceptor);
260217
server.close();
261218
});

0 commit comments

Comments
 (0)