mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Game patch/parent url
This commit is contained in:
parent
a36b3eba9d
commit
c3b88f4f5a
2 changed files with 259 additions and 146 deletions
129
data/emulator.js
129
data/emulator.js
|
@ -546,8 +546,9 @@ class EmulatorJS {
|
|||
this.msgElem.innerText = message;
|
||||
}
|
||||
downloadStartState() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof this.config.loadState !== "string") {
|
||||
this.startGame();
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
this.textElem.innerText = this.localization("Download Game State");
|
||||
|
@ -563,14 +564,112 @@ class EmulatorJS {
|
|||
this.gameManager.loadState(new Uint8Array(res.data));
|
||||
}, 10);
|
||||
})
|
||||
this.startGame();
|
||||
resolve();
|
||||
}, (progress) => {
|
||||
this.textElem.innerText = this.localization("Download Game State") + progress;
|
||||
}, 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() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof this.config.biosUrl !== "string" || !this.config.biosUrl.trim()) {
|
||||
this.downloadStartState();
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
this.textElem.innerText = this.localization("Download Game BIOS");
|
||||
|
@ -582,10 +681,9 @@ class EmulatorJS {
|
|||
break;
|
||||
}
|
||||
if (k.endsWith('/')) continue;
|
||||
let folder = this.fileName.substring(0, this.fileName.length - this.fileName.split("/").pop().length);
|
||||
FS.writeFile(folder + k.split('/').pop(), data[k]);
|
||||
FS.writeFile("/" + k.split('/').pop(), data[k]);
|
||||
}
|
||||
this.downloadStartState();
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -613,8 +711,10 @@ class EmulatorJS {
|
|||
}, true, {responseType: "arraybuffer", method: "GET"});
|
||||
})
|
||||
}, null, true, {method: "HEAD"})
|
||||
})
|
||||
}
|
||||
downloadRom() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.gameManager = new window.EJS_GameManager(this.Module, this);
|
||||
|
||||
this.textElem.innerText = this.localization("Download Game Data");
|
||||
|
@ -622,7 +722,7 @@ class EmulatorJS {
|
|||
if (['arcade', 'mame2003'].includes(this.getCore(true))) {
|
||||
this.fileName = this.config.gameUrl.split('/').pop().split("#")[0].split("?")[0];
|
||||
FS.writeFile(this.fileName, new Uint8Array(data));
|
||||
this.downloadBios();
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
this.fileName = execFile;
|
||||
}
|
||||
this.downloadBios();
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
this.downloadFile(this.config.gameUrl, (res) => {
|
||||
|
@ -702,12 +802,23 @@ class EmulatorJS {
|
|||
}, true, {responseType: "arraybuffer", method: "GET"});
|
||||
})
|
||||
}, 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) {
|
||||
window.Module = {
|
||||
'TOTAL_MEMORY': 0x10000000,
|
||||
'noInitialRun': true,
|
||||
'onRuntimeInitialized': this.downloadRom.bind(this),
|
||||
'onRuntimeInitialized': this.downloadFiles.bind(this),
|
||||
'arguments': [],
|
||||
'preRun': [],
|
||||
'postRun': [],
|
||||
|
|
|
@ -61,6 +61,8 @@
|
|||
config.cacheLimit = window.EJS_CacheLimit;
|
||||
config.cheats = window.EJS_cheats;
|
||||
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") {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue