From 5d54014ce3df6720bf508562c0e6f3b76da17f53 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Sat, 14 Dec 2024 14:05:53 -0600 Subject: [PATCH] Read state from memory instead of saving to disk --- data/src/GameManager.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/data/src/GameManager.js b/data/src/GameManager.js index 8ca4fd3..02328b5 100644 --- a/data/src/GameManager.js +++ b/data/src/GameManager.js @@ -5,7 +5,7 @@ class EJS_GameManager { this.FS = this.Module.FS; this.functions = { restart: this.Module.cwrap('system_restart', '', []), - saveStateInfo: this.Module.cwrap('save_state_info', 'null', []), + saveStateInfo: this.Module.cwrap('save_state_info', 'string', []), loadState: this.Module.cwrap('load_state', 'number', ['string', 'number']), screenshot: this.Module.cwrap('cmd_take_screenshot', '', []), simulateInput: this.Module.cwrap('simulate_input', 'null', ['number', 'number', 'number']), @@ -172,8 +172,15 @@ class EJS_GameManager { this.functions.restart(); } getState() { - this.functions.saveStateInfo(); - return this.FS.readFile("/current.state"); + const state = this.functions.saveStateInfo().split("|"); + if (state[2] !== "1") { + console.error(state[0]); + return state[0]; + } + const size = parseInt(state[0]); + const dataStart = parseInt(state[1]); + const data = this.Module.HEAPU8.subarray(dataStart, dataStart + size); + return new Uint8Array(data); } loadState(state) { try {