Game patch/parent url

This commit is contained in:
Ethan O'Brien 2023-07-11 11:30:27 -05:00
parent a36b3eba9d
commit c3b88f4f5a
2 changed files with 259 additions and 146 deletions

View file

@ -546,8 +546,9 @@ class EmulatorJS {
this.msgElem.innerText = message; this.msgElem.innerText = message;
} }
downloadStartState() { downloadStartState() {
return new Promise((resolve, reject) => {
if (typeof this.config.loadState !== "string") { if (typeof this.config.loadState !== "string") {
this.startGame(); resolve();
return; return;
} }
this.textElem.innerText = this.localization("Download Game State"); this.textElem.innerText = this.localization("Download Game State");
@ -563,14 +564,112 @@ class EmulatorJS {
this.gameManager.loadState(new Uint8Array(res.data)); this.gameManager.loadState(new Uint8Array(res.data));
}, 10); }, 10);
}) })
this.startGame(); resolve();
}, (progress) => { }, (progress) => {
this.textElem.innerText = this.localization("Download Game State") + progress; this.textElem.innerText = this.localization("Download Game State") + progress;
}, true, {responseType: "arraybuffer", method: "GET"}); }, true, {responseType: "arraybuffer", method: "GET"});
})
}
downloadGamePatch() {
return new Promise((resolve, reject) => {
if (typeof this.config.gamePatchUrl !== "string" || !this.config.gamePatchUrl.trim()) {
resolve();
return;
}
this.textElem.innerText = this.localization("Download Game Patch");
const gotData = (data) => {
this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Patch")).then((data) => {
for (const k in data) {
if (k === "!!notCompressedData") {
FS.writeFile(this.config.gamePatchUrl.split('/').pop().split("#")[0].split("?")[0], data[k]);
break;
}
if (k.endsWith('/')) continue;
FS.writeFile("/" + k.split('/').pop(), data[k]);
}
resolve();
})
}
this.downloadFile(this.config.gamePatchUrl, (res) => {
this.storage.rom.get(this.config.gamePatchUrl.split("/").pop()).then((result) => {
if (result && result['content-length'] === res.headers['content-length'] && !this.debug) {
gotData(result.data);
return;
}
this.downloadFile(this.config.gamePatchUrl, (res) => {
if (res === -1) {
this.textElem.innerText = "Error";
this.textElem.style.color = "red";
return;
}
gotData(res.data);
const limit = (typeof this.config.cacheLimit === "number") ? this.config.cacheLimit : 1073741824;
if (parseFloat(res.headers['content-length']) < limit && this.saveInBrowserSupported()) {
this.storage.rom.put(this.config.gamePatchUrl.split("/").pop(), {
"content-length": res.headers['content-length'],
data: res.data
})
}
}, (progress) => {
this.textElem.innerText = this.localization("Download Game Patch") + progress;
}, true, {responseType: "arraybuffer", method: "GET"});
})
}, null, true, {method: "HEAD"})
})
}
downloadGameParent() {
return new Promise((resolve, reject) => {
if (typeof this.config.gameParentUrl !== "string" || !this.config.gameParentUrl.trim()) {
resolve();
return;
}
this.textElem.innerText = this.localization("Download Game Parent");
const gotData = (data) => {
this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Parent")).then((data) => {
for (const k in data) {
if (k === "!!notCompressedData") {
FS.writeFile(this.config.gameParentUrl.split('/').pop().split("#")[0].split("?")[0], data[k]);
break;
}
if (k.endsWith('/')) continue;
FS.writeFile("/" + k.split('/').pop(), data[k]);
}
resolve();
})
}
this.downloadFile(this.config.gameParentUrl, (res) => {
this.storage.rom.get(this.config.gameParentUrl.split("/").pop()).then((result) => {
if (result && result['content-length'] === res.headers['content-length'] && !this.debug) {
gotData(result.data);
return;
}
this.downloadFile(this.config.gameParentUrl, (res) => {
if (res === -1) {
this.textElem.innerText = "Error";
this.textElem.style.color = "red";
return;
}
gotData(res.data);
const limit = (typeof this.config.cacheLimit === "number") ? this.config.cacheLimit : 1073741824;
if (parseFloat(res.headers['content-length']) < limit && this.saveInBrowserSupported()) {
this.storage.rom.put(this.config.gameParentUrl.split("/").pop(), {
"content-length": res.headers['content-length'],
data: res.data
})
}
}, (progress) => {
this.textElem.innerText = this.localization("Download Game Parent") + progress;
}, true, {responseType: "arraybuffer", method: "GET"});
})
}, null, true, {method: "HEAD"})
})
} }
downloadBios() { downloadBios() {
return new Promise((resolve, reject) => {
if (typeof this.config.biosUrl !== "string" || !this.config.biosUrl.trim()) { if (typeof this.config.biosUrl !== "string" || !this.config.biosUrl.trim()) {
this.downloadStartState(); resolve();
return; return;
} }
this.textElem.innerText = this.localization("Download Game BIOS"); this.textElem.innerText = this.localization("Download Game BIOS");
@ -582,10 +681,9 @@ class EmulatorJS {
break; break;
} }
if (k.endsWith('/')) continue; if (k.endsWith('/')) continue;
let folder = this.fileName.substring(0, this.fileName.length - this.fileName.split("/").pop().length); FS.writeFile("/" + k.split('/').pop(), data[k]);
FS.writeFile(folder + k.split('/').pop(), data[k]);
} }
this.downloadStartState(); resolve();
}) })
} }
@ -613,8 +711,10 @@ class EmulatorJS {
}, true, {responseType: "arraybuffer", method: "GET"}); }, true, {responseType: "arraybuffer", method: "GET"});
}) })
}, null, true, {method: "HEAD"}) }, null, true, {method: "HEAD"})
})
} }
downloadRom() { downloadRom() {
return new Promise((resolve, reject) => {
this.gameManager = new window.EJS_GameManager(this.Module, this); this.gameManager = new window.EJS_GameManager(this.Module, this);
this.textElem.innerText = this.localization("Download Game Data"); this.textElem.innerText = this.localization("Download Game Data");
@ -622,7 +722,7 @@ class EmulatorJS {
if (['arcade', 'mame2003'].includes(this.getCore(true))) { if (['arcade', 'mame2003'].includes(this.getCore(true))) {
this.fileName = this.config.gameUrl.split('/').pop().split("#")[0].split("?")[0]; this.fileName = this.config.gameUrl.split('/').pop().split("#")[0].split("?")[0];
FS.writeFile(this.fileName, new Uint8Array(data)); FS.writeFile(this.fileName, new Uint8Array(data));
this.downloadBios(); resolve();
return; return;
} }
this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Data")).then((data) => { this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Data")).then((data) => {
@ -674,7 +774,7 @@ class EmulatorJS {
if (this.getCore(true) === "psx" && execFile !== null) { if (this.getCore(true) === "psx" && execFile !== null) {
this.fileName = execFile; this.fileName = execFile;
} }
this.downloadBios(); resolve();
}); });
} }
this.downloadFile(this.config.gameUrl, (res) => { this.downloadFile(this.config.gameUrl, (res) => {
@ -702,12 +802,23 @@ class EmulatorJS {
}, true, {responseType: "arraybuffer", method: "GET"}); }, true, {responseType: "arraybuffer", method: "GET"});
}) })
}, null, true, {method: "HEAD"}) }, null, true, {method: "HEAD"})
})
}
downloadFiles() {
(async () => {
await this.downloadRom();
await this.downloadBios();
await this.downloadStartState();
await this.downloadGameParent();
await this.downloadGamePatch();
this.startGame();
})();
} }
initModule(wasmData) { initModule(wasmData) {
window.Module = { window.Module = {
'TOTAL_MEMORY': 0x10000000, 'TOTAL_MEMORY': 0x10000000,
'noInitialRun': true, 'noInitialRun': true,
'onRuntimeInitialized': this.downloadRom.bind(this), 'onRuntimeInitialized': this.downloadFiles.bind(this),
'arguments': [], 'arguments': [],
'preRun': [], 'preRun': [],
'postRun': [], 'postRun': [],

View file

@ -61,6 +61,8 @@
config.cacheLimit = window.EJS_CacheLimit; config.cacheLimit = window.EJS_CacheLimit;
config.cheats = window.EJS_cheats; config.cheats = window.EJS_cheats;
config.defaultOptions = window.EJS_defaultOptions; config.defaultOptions = window.EJS_defaultOptions;
config.gamePatchUrl = window.EJS_gamePatchUrl;
config.gameParentUrl = window.EJS_gameParentUrl;
if (typeof window.EJS_language === "string" && window.EJS_language !== "en-US") { if (typeof window.EJS_language === "string" && window.EJS_language !== "en-US") {
try { try {