Any plugins to extract save files from web deployment

Is there a plugin or script I can refer to to extract a save file from an Rpg Maker MZ game from the Web.

I thought of deploying an RPG Maker MZ game and release on the web / html. I also want the players to download a copy of their save file after they save their files on the web. So if the players are playing the game on a different device they can upload their save file and continue their progress without starting over because they play on a different device.
Old thread might help a little: https://forums.rpgmakerweb.com/inde...ing-saves-from-desktop-to-web-version.125176/

I'm unaware of an existing plugin that does specifically what you're asking, but there should be one. You would need to program access options (some login like oauth) and configure a repository per user. I can think of pretty quick ways to do it in Google Play, Steam, or Windows Store, but for a web game I'm at a loss. I am unfamiliar with the Itch.io API, but this is the reference. Usually save files are in localstorage cache, so it would be a pretty large tangent for this small feature. For an RPG, it could be worth it.

This makes me think if I had users between multiple platforms, how would I manage the game save files regardless of device? Difficult question.
I did came across this thread, however it didnt say anything about extracting save files from the web. it sounds more like uploading save files to the web, moreover it is in RPG Maker MV. I need to find that is compatible with MZ
In terms of pure implementation...

Scripted download can be done with an <a> element:
I think scripted upload can be done with an <input type=file> element?
(Web saves are stored in the browser's local storage.)
yea, i take a look at this, the idea is Players can download their save file, so if they accidentally clean the history or change device, they can upload their save file and continue their progress.
There is the AltSaveLocation plugin. You could massage that a bit. It would work in many instances, but not all instances such as kids using library computers or kids using phones/tablets without sufficient permissions. Thinking about where browsers save files and then standardize it can be tricky. You could make the default the download folder. But then you would need to modify the plugin to load from the selected folder.
RMMZ seems to store save files in local storage of the browser.

1734933465719.png

So if you are lazy you can write a function to extract the whole local storage in a string.
var x = JSON.stringify(localStorage);
prompt('COPY ME!!!!!!!', x);


If you want the user to upload their save:
var x = prompt('PASTE YOUR SAVE HERE:');
localStorage.clear();
Object.assign(localStorage, JSON.parse(x));

However there should be more checks if you want to validate the string the user provides. And make sure to restart the game after that.
Thinking about where browsers save files and then standardize it can be tricky.
The plugin you linked states it only works for NWJS, because for security reasons browsers do not have standard access to the user's file system. Hence the download/upload idea.

So if you are lazy you can write a function to extract the whole local storage in a string.
I'm not sure that's a good idea. There's no guarantee the site's local storage would be dedicated to the game, so you risk deleting/overwriting unrelated values.

I would instead recommend using MZ's existing save/load methods, e.g.
JavaScript:
const id  = 1;                             // Save file ID.
const key = DataManager.makeSaveName(id);  // Storage key.
// Get save data (for export).
const data = StorageManager.loadZip(key);
// Write save data (for import).
StorageManager.saveZip(key, data);
(Copy+paste should work A-OK, assuming there's no practical character limit in place. Manually copying to/from a new .txt file is hardly any less convenient than automatically saving to file.)

I don't think restarting the game would correct missing or mismatched global info, though. So after importing the actual data, it may be necessary to follow up by calling DataManager.loadGame and .saveGame for each imported save file, since global info entries are generated from the game data at the time of saving.
RMMZ seems to store save files in local storage of the browser.

View attachment 326679
So if you are lazy you can write a function to extract the whole local storage in a string.
var x = JSON.stringify(localStorage);
prompt('COPY ME!!!!!!!', x);


If you want the user to upload their save:
var x = prompt('PASTE YOUR SAVE HERE:');
localStorage.clear();
Object.assign(localStorage, JSON.parse(x));

However there should be more checks if you want to validate the string the user provides. And make sure to restart the game after that.
its an option for people who are not familiar with rpg maker. So instead of looking for a tutorial, i thought of finding a code / plugin for them, else they get frustrated if they accidentally erase the local storage or if they play on another device

The plugin you linked states it only works for NWJS, because for security reasons browsers do not have standard access to the user's file system. Hence the download/upload idea.


I'm not sure that's a good idea. There's no guarantee the site's local storage would be dedicated to the game, so you risk deleting/overwriting unrelated values.

I would instead recommend using MZ's existing save/load methods, e.g.
JavaScript:
const id  = 1;                             // Save file ID.
const key = DataManager.makeSaveName(id);  // Storage key.
// Get save data (for export).
const data = StorageManager.loadZip(key);
// Write save data (for import).
StorageManager.saveZip(key, data);
(Copy+paste should work A-OK, assuming there's no practical character limit in place. Manually copying to/from a new .txt file is hardly any less convenient than automatically saving to file.)

I don't think restarting the game would correct missing or mismatched global info, though. So after importing the actual data, it may be necessary to follow up by calling DataManager.loadGame and .saveGame for each imported save file, since global info entries are generated from the game data at the time of saving.
refreshing the game does not erase the file, rather if you decide to clear cookies / windows clean up. To avoid losing their files, thats why i want an option they can save their game. Also a freedom to pass around the save file to someone else / transfer the save file to another computer. Little me plays a lot of flash game. Sometimes the same game but different servers, like armor games and kongregate. Its frustrating to start the game all over again so thats why i want to opt this solution
refreshing the game does not erase the file, rather if you decide to clear cookies / windows clean up.
Of course. Did you misunderstand me here?
I don't think restarting the game would correct missing or mismatched global info, though.
Spoiler: clarification
The global save info is what the engine uses to list save data in-game. It includes timestamps, playtime, relevant save menu graphics, etc. By default it is written on save, and also gets pruned of invalid entries on game boot. Like the config/options settings, it is saved in its own file.

If you manually add a new save file to the game's save folder, the game will not register the new file's presence; if you overwrite an existing save with a different save, the game will still use the old save's global info. Hence my comment about "missing or mismatched global info".

Here's a rough version of a functional plugin, using @utunnels copy+paste approach for simplicity:
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Adds Import Save & Export Save buttons to the title menu.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/174088/
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (() => {
"use strict";

  /** "Import Save" command display name. */
  const COM_IN = "Import Save";
  /** "Export Save" command display name. */
  const COM_EX = "Export Save";

  /** @returns {number} Height (px) to add to title command window. */
  const addHeight = function() {
    return 2 * Window_TitleCommand.prototype.itemHeight();
  };

  // Response functions, all bound to parent `Scene_Title` instance.
  const postAction    = function()   { this._commandWindow.activate(); };
  const importSuccess = function(id) { alert(`Save ${id} imported successfully!`); };
  const importFailure = function()   { alert("Import save failed."); };
  const exportSuccess = function()   { alert("Save data copied to clipboard!"); };
  const exportFailure = function()   { alert("Save export failed."); };

  /** Prompts user to paste save data, then imports it. */
  const importSave = function(
    id = DataManager.emptySavefileId(),
    json = prompt("Paste save data here:")
  ) {
    if (id < 0) {
      alert(`Cannot import to save slot ${id}.`);
      postAction.call(this);
    } else if (!json) {
      postAction.call(this);
    } else {
      console.log("importSave:", json);
      const key = DataManager.makeSavename(id);
      StorageManager.jsonToZip(json)
                    .then(zip => StorageManager.saveZip(key, zip))
                    .then(() => DataManager.loadGame(id))
                    .then(() => DataManager.saveGame(id))
                    .then(importSuccess.bind(this, id))
                    .catch(importFailure.bind(this))
                    .finally(postAction.bind(this));
    }
  };

  /** Exports save data from specified slot. */
  const exportSave = function(id = prompt("Enter save ID to export:")) {
    if (DataManager.savefileExists(id = parseInt(id, 10))) {
      const key = DataManager.makeSavename(id);
      StorageManager.loadZip(key)
                    .then(zip => StorageManager.zipToJson(zip))
                    .then(json => navigator.clipboard.writeText(json))
                    .then(exportSuccess.bind(this))
                    .catch(exportFailure.bind(this))
                    .finally(postAction.bind(this));
    } else {
      alert(`Save file ${id} not found. Export failed!`);
      postAction.call(this);
    }
  };

  // Patch - add new commands to title menu.
  void (alias => {
    Window_TitleCommand.prototype.makeCommandList = function() {
      alias.apply(this, arguments);
      this.addCommand(COM_IN, "saveImport");
      this.addCommand(COM_EX, "saveExport", DataManager.isAnySavefileExists());
    };
  })(Window_TitleCommand.prototype.makeCommandList);

  // Patch - bind handlers to new title commands.
  void (alias => {
    Scene_Title.prototype.createCommandWindow = function() {
      alias.apply(this, arguments);
      const w = this._commandWindow;
      w.setHandler("saveImport", importSave.bind(this));
      w.setHandler("saveExport", exportSave.bind(this));
    };
  })(Scene_Title.prototype.createCommandWindow);

  // Patch - increase title window height to accommodate new commands.
  void (alias => {
    Scene_Title.prototype.commandWindowRect = function() {
      const r = alias.apply(this, arguments);
      r.height += addHeight();
      return r;
    };
  })(Scene_Title.prototype.commandWindowRect);

})();
(I wasn't sure if it'd work reliably with zip directly, hence zipToJson & back.) Did a few quick tests and it seemed mostly OK, though the displayed playtime on imported saves seems a bit off for some reason. Probably because I'm not calling onBeforeSave/onAfterSave in there? Not sure. Y'all are free to do whatever with it~ 👋

As I implied earlier, I think the awkward/tedious part would be the interface. The save scene is a more logical place to add such commands, especially in terms of selecting a save slot. However, by default that scene doesn't have a secondary command window or the code to handle associated program flow changes.
Of course. Did you misunderstand me here?
I apologize, my brain does not brain.

Spoiler: clarification
The global save info is what the engine uses to list save data in-game. It includes timestamps, playtime, relevant save menu graphics, etc. By default it is written on save, and also gets pruned of invalid entries on game boot. Like the config/options settings, it is saved in its own file.

If you manually add a new save file to the game's save folder, the game will not register the new file's presence; if you overwrite an existing save with a different save, the game will still use the old save's global info. Hence my comment about "missing or mismatched global info".

Here's a rough version of a functional plugin, using @utunnels copy+paste approach for simplicity:
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Adds Import Save & Export Save buttons to the title menu.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/174088/
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (() => {
"use strict";

  /** "Import Save" command display name. */
  const COM_IN = "Import Save";
  /** "Export Save" command display name. */
  const COM_EX = "Export Save";

  /** @returns {number} Height (px) to add to title command window. */
  const addHeight = function() {
    return 2 * Window_TitleCommand.prototype.itemHeight();
  };

  // Response functions, all bound to parent `Scene_Title` instance.
  const postAction    = function()   { this._commandWindow.activate(); };
  const importSuccess = function(id) { alert(`Save ${id} imported successfully!`); };
  const importFailure = function()   { alert("Import save failed."); };
  const exportSuccess = function()   { alert("Save data copied to clipboard!"); };
  const exportFailure = function()   { alert("Save export failed."); };

  /** Prompts user to paste save data, then imports it. */
  const importSave = function(
    id = DataManager.emptySavefileId(),
    json = prompt("Paste save data here:")
  ) {
    if (id < 0) {
      alert(`Cannot import to save slot ${id}.`);
      postAction.call(this);
    } else if (!json) {
      postAction.call(this);
    } else {
      console.log("importSave:", json);
      const key = DataManager.makeSavename(id);
      StorageManager.jsonToZip(json)
                    .then(zip => StorageManager.saveZip(key, zip))
                    .then(() => DataManager.loadGame(id))
                    .then(() => DataManager.saveGame(id))
                    .then(importSuccess.bind(this, id))
                    .catch(importFailure.bind(this))
                    .finally(postAction.bind(this));
    }
  };

  /** Exports save data from specified slot. */
  const exportSave = function(id = prompt("Enter save ID to export:")) {
    if (DataManager.savefileExists(id = parseInt(id, 10))) {
      const key = DataManager.makeSavename(id);
      StorageManager.loadZip(key)
                    .then(zip => StorageManager.zipToJson(zip))
                    .then(json => navigator.clipboard.writeText(json))
                    .then(exportSuccess.bind(this))
                    .catch(exportFailure.bind(this))
                    .finally(postAction.bind(this));
    } else {
      alert(`Save file ${id} not found. Export failed!`);
      postAction.call(this);
    }
  };

  // Patch - add new commands to title menu.
  void (alias => {
    Window_TitleCommand.prototype.makeCommandList = function() {
      alias.apply(this, arguments);
      this.addCommand(COM_IN, "saveImport");
      this.addCommand(COM_EX, "saveExport", DataManager.isAnySavefileExists());
    };
  })(Window_TitleCommand.prototype.makeCommandList);

  // Patch - bind handlers to new title commands.
  void (alias => {
    Scene_Title.prototype.createCommandWindow = function() {
      alias.apply(this, arguments);
      const w = this._commandWindow;
      w.setHandler("saveImport", importSave.bind(this));
      w.setHandler("saveExport", exportSave.bind(this));
    };
  })(Scene_Title.prototype.createCommandWindow);

  // Patch - increase title window height to accommodate new commands.
  void (alias => {
    Scene_Title.prototype.commandWindowRect = function() {
      const r = alias.apply(this, arguments);
      r.height += addHeight();
      return r;
    };
  })(Scene_Title.prototype.commandWindowRect);

})();
(I wasn't sure if it'd work reliably with zip directly, hence zipToJson & back.) Did a few quick tests and it seemed mostly OK, though the displayed playtime on imported saves seems a bit off for some reason. Probably because I'm not calling onBeforeSave/onAfterSave in there? Not sure. Y'all are free to do whatever with it~ 👋

As I implied earlier, I think the awkward/tedious part would be the interface. The save scene is a more logical place to add such commands, especially in terms of selecting a save slot. However, by default that scene doesn't have a secondary command window or the code to handle associated program flow changes.
Gee, Thank you very much, i use this as a reference
I'm not sure that's a good idea. There's no guarantee the site's local storage would be dedicated to the game, so you risk deleting/overwriting unrelated values.
You are right. I didn't read the code before so I checked it again.
The screenshot I posted was from a MV game on itch.io. You can see all the save keys use the same pattern: RPG + filename.:LZSskeptic: So it will be a problem if you play other MV games on the same website.
MZ fixed the problem by providing a game id. So in theory you can check the game id string in those local storage keys.

Original thread: https://forums.rpgmakerweb.com/threads/any-plugins-to-extract-save-files-from-web-deployment.174088/