MZ and RMMV - Advanced Change SaveLocation

Download: GitHub
Version: 0.4 (Test)

Terms of use:
It is allowed to modify
Can be used in commercial and non-commercial games
It is not necessary to credit me, but I am happy if you do.

About:
This Plugin works on games made with RMMV and RMMZ
But only those exported to Windows and using the NW.js platform

Instructions:
After downloading the file or copying the code, move or create the JS file named Advanced_ChangeSaveLocation.js in your project's Plugins folder.

When activating in the Rpg Maker Plugins manager you will have two options:
  1. One to define the path of the folder where the savefiles will be
  2. And another to define the folder name


Setting the path:
To better understand, I made a caption:
{Game} is where files are located, like Game.exe
{SO} is the drive where the operating system is installed, like C
{User} is the connected user's folder

The options are:
  1. {Game}\save\ (Core Default)
  2. {Game}\ (Where is Game.exe located)
  3. {SO}:\ProgramData
  4. {SO}:\Users\{User}\Appdata\Local
  5. {SO}:\Users\{User}\Appdata\Roaming
  6. {SO}:\Users\Public\Documents
  7. {SO}:\Users\{User}
  8. {SO}:\Users\{User}\Documents\
If you try to enter manually it will be set to Default automatically

Setting the folder name:
Here you define the name of the folder that will store the savefiles, this option does not work with {Game}\save or {Game}\.

The options are:
  1. GameTitle -> The folder will be named the same as the title in the game bar
  2. GameTitle (without space) -> Spaces that exist in the game title will not be included in the folder name
    My Rpg Game is converted to MyRpgGame
  3. GameTitle (underline replaces spaces) -> It is, as already shown, to replace the spaces with underlines
    My Rpg Game is converted to My_Rpg_Game
  4. Developer defined -> Here the developer defines a custom name, which just switch to text mode.
Warning: Symbols, accented letters and non-English characters will be removed automatically, except "+", "-" and "_"
This is very useful. Thank you so much!
Thank you for this. * _ *
Hello! first of all, I found your plugin awesome, thanks for creating it 😀

I have a small doubt: You comment that it only works on Windows, if I want to make so that it can also be used on Mac and Linux routes how could it be done? Because I understand that the routes are different, right?

Greetings!
Thanks for commenting, I believe it's possible, I just need to be able to open the console using the version compiled for Linux to be able to read the "process.env" object and analyze the options. That's why it's in version 0.4.
I only complete systems that really spark users' interest, which is why this Plugin has not received any more updates.

Edit:
One note: I didn't give the developer the option to manually enter the path, as any mistakes could cause problems for players or even the developer.

I assume that MacOS and Linux have paths allowed only by root access, so the ideal would be to understand the most common paths so that the dev does not receive complaints from players in the future.
Ah I see, I understand. Anyway I'll keep an eye out, in case you make any updates in the future. Thanks for your answer 🙂
Ah I see, I understand. Anyway I'll keep an eye out, in case you make any updates in the future. Thanks for your answer 🙂
I know this thread is like 9 months old now, but if you or any future reader wants the simple fix: just wanted to let you know that the dev gave you a bullshit answer. It took me like 5 seconds to make this work on linux without all of the convoluted spaghetti code above. You don't need a path object for the save path, just pass in a normal string.

JavaScript:
      (() => {
          const save_path = "/PATH/TO/SAVEFILES";
         
          /* RMMV */
          if(StorageManager.localFileDirectoryPath){
              StorageManager.localFileDirectoryPath = function() {
                  return save_path;
              }
          }

          /* RMMZ */
          if(StorageManager.fileDirectoryPath){
              StorageManager.fileDirectoryPath = function() {
                  return save_path;
              }
          }

      })();

If you need environment variables (for example, to store game data in $HOME/.local/share/GAMENAME), you could do something like process.env.HOME + "/.local/share/GAMENAME/". Don't forget the trailing slash.
I know this thread is like 9 months old now, but if you or any future reader wants the simple fix: just wanted to let you know that the dev gave you a bullshit answer. It took me like 5 seconds to make this work on linux without all of the convoluted spaghetti code above. You don't need a path object for the save path, just pass in a normal string.

JavaScript:
      (() => {
          const save_path = "/PATH/TO/SAVEFILES";
        
          /* RMMV */
          if(StorageManager.localFileDirectoryPath){
              StorageManager.localFileDirectoryPath = function() {
                  return save_path;
              }
          }

          /* RMMZ */
          if(StorageManager.fileDirectoryPath){
              StorageManager.fileDirectoryPath = function() {
                  return save_path;
              }
          }

      })();

If you need environment variables (for example, to store game data in $HOME/.local/share/GAMENAME), you could do something like process.env.HOME + "/.local/share/GAMENAME/". Don't forget the trailing slash.


Hello, thank you for providing your code, sorry I hadn't seen your message. The truth is I don't know much about programming so I do what I can, but I made a fix on this issue, editing the code of ‘Dev_With_Coffee’, I don't know if it's ok, if it could be better or if I've done it wrong, I just know it works, although I think it took me more time to write the code hehe. I don't know if it looks a bit like what you have passed.

I share the code here in case it is of interest:

Code:
(function() {
    if (process.env.OS == "Windows_NT" && Utils.isNwjs()) {
        var path = require('path');
        var base = path.dirname(process.mainModule.filename);
        var new_path = "";
        
        var parameters = PluginManager.parameters('Advanced_ChangeSaveLocation');
        
        switch (parameters['location']) {
            case "Default":
                new_path = path.join(base, 'save/');
                break;
            case "Current Folder":
                new_path = path.join(base, '/');
                break;
            case "ProgramData":
                new_path = process.env.ProgramData || process.env.ALLUSERSPROFILE;
                break;
            case "Appdata-Local":
                new_path = process.env.LOCALAPPDATA || process.env.LOCAL_APPDATA;
                break;
            case "Appdata-Roaming":
                new_path = process.env.APPDATA;
                break;
            case "Public Documents":
                new_path = process.env.PUBLIC+"/Documents";
                break;
            case "Current User":
                new_path = process.env.USERPROFILE;
                break;
            case "Documents of Current User":
                new_path = process.env.USERPROFILE+"/Documents";
                break;
            default:
                parameters['location'] = "Default";
                new_path = path.join(base, 'save/');
        }
        
        if (parameters['location'] != "Default" && parameters['location'] != "Current Folder"){
            var mkdirsaves = true;
            var convtitle = document.title;
            convtitle = convtitle.replace(/[^a-zA-Z0-9\_\-\+\s]/g,"");
            switch (parameters['dir_save_name']) {
                case "GameTitle":
                    new_path = new_path+"/"+convtitle+"/";
                    break;
                case "TitleNoSpace":
                    convtitle = convtitle.replace(/\s/g,"");
                    new_path = new_path+"/"+convtitle+"/";
                    break;
                case "TitleWithUnderline":
                    convtitle = convtitle.replace(/\s/g,"_");
                    new_path = new_path+"/"+convtitle+"/";
                    break;
                default:
                    var dev_defined = parameters['dir_save_name'];
                    dev_defined = dev_defined.replace(/[^a-zA-Z0-9\s\_\-]/g,"");
                    new_path = new_path+"/"+dev_defined+"/";
            }
            if(new_path.slice(-2) == "//"){
                new_path = path.join(base, 'save/');
            }
            var fs = require('fs');
            if(!fs.existsSync(new_path)){
                fs.mkdirSync(new_path);
            }
        }
        /* RMMV */
        if(StorageManager.localFileDirectoryPath){
            StorageManager.localFileDirectoryPath = function() {
                return new_path;
            };
        }
        
        /* RMMZ */
        if(StorageManager.fileDirectoryPath){
            StorageManager.fileDirectoryPath = function() {
                return new_path;
            }
        }
    }
})();
I modified this plugin to work on Mac and Linux (Linux is untested, but I think it should be fine; it would fail on some more obscure systems though.).

I also made two other changes that align with my personal preferences:

  • Always use default save location when testing.
  • Add a "company name" folder into the path.
Thanks for sharing, this will really be useful for the community 😉

Original thread: https://forums.rpgmakerweb.com/threads/and-rmmv-advanced-change-savelocation.138516/