Created
March 8, 2024 12:35
-
-
Save UserUnknownFactor/9320ca8dc463cf442fac2b2b8d61e2d9 to your computer and use it in GitHub Desktop.
Plugin to set custom save directory instead of www/save for RPG Maker MV/MZ games
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
powershell.exe -ExecutionPolicy Bypass -Command "$_=((Get-Content \"%~f0\") -join \"`n\");iex $_.Substring($_.IndexOf(\"goto :\"+\"EOF\")+9)" | |
del add_plugin.cmd | |
@goto :EOF | |
$pliginsName = ".\www\js\plugins.js" | |
$pluginsStr =(Get-Content $pliginsName) | |
if($pluginsStr -like '*RoamingSavePath*') { | |
Write-Host "Already patched!" | |
} else { | |
$pluginsStr.Replace("];",",{`"name`":`"RoamingSavePath`",`"status`":true,`"description`":`"Save directory to user specified instead of www/save`",`"parameters`":{}}`n];") | Set-Content $pliginsName | |
Write-Host "Patch successful." | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* | |
============================================================================================== | |
RoamingSavePath.js | |
License: WTFPL | |
Usage: add this line to your plugins.js: | |
{"name":"RoamingSavePath","status":true,"description":"Sets custom save directory instead of www/save","parameters":{"Save Directory": null}} | |
============================================================================================== | |
*/ | |
(function () { | |
if (!StorageManager.isLocalMode() || typeof process === 'undefined' || !process.env || !process.platform) return; | |
const fs = require('fs'); | |
const path = require('path'); | |
var globalSavePath = null; | |
const initPlugin = function () { | |
const defaultDir = (process.env.APPDATA ? "%USERPROFILE%" : | |
(process.platform == "darwin" ? "%HOME%/Library/Preferences" : "%HOME%/.local/share") | |
) + "/Saved Games/%GAMETITLE%/save/"; | |
const params = PluginManager.parameters("RoamingSavePath"); | |
var savePath = ( | |
(params["Save Directory"] || defaultDir) | |
.trim() | |
.replace(/^[/\\\.]+|[/\\\.]+$/g, '') + path.sep) | |
.replace("%GAMETITLE%", $dataSystem.gameTitle || "UnknownTitle") | |
.replace(/[/\\]/g, path.sep); | |
for (var e in process.env) | |
savePath = savePath.replace('%' + e + '%', process.env[e]); | |
globalSavePath = savePath; | |
} | |
const validateDirTree = function (targetDir) { | |
if (fs.existsSync(targetDir)) return true; | |
const parts = targetDir.split(path.sep); | |
var currentPath = parts[0]; | |
for (var i = 1; i < parts.length; i++) { | |
if (!parts[i]) continue; | |
currentPath += path.sep + parts[i]; | |
if (!fs.existsSync(currentPath)) { | |
try { | |
fs.mkdirSync(currentPath); | |
} catch (e) { | |
return false; | |
} | |
} | |
} | |
return true; | |
} | |
const oldDMOL = DataManager.onLoad; | |
DataManager.onLoad = function(object) { | |
oldDMOL.apply(this, arguments); | |
if (object === $dataSystem) | |
initPlugin(); | |
} | |
StorageManager.localFileDirectoryPath = function() { | |
return globalSavePath; | |
}; | |
const oldSTLF = StorageManager.saveToLocalFile; | |
StorageManager.saveToLocalFile = function() { | |
//if (!fs.existsSync(globalSavePath)) | |
//fs.mkdirSync(globalSavePath, { recursive: true }); // needs newer nwjs sometimes | |
if (validateDirTree(globalSavePath)) | |
oldSTLF.apply(this, arguments); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment