Copies a file or directory from the mod directory to the data directory. This is primarily used for including non-mergeable assets like sprites in your mod.
The path of the file or directory to copy, relative to the mod directory.
The path of the file or directory to copy to, relative to the data directory.
Optional
overwrite: booleanWhether to overwrite any conflicts.
While you can use this API to provide whole new versions of TSV/JSON game
files to the game, this is an anti-pattern and will dramatically reduce your
mod's compatibility with other mods. Don't do it. Use the read*
and write*
APIs instead.
// copy new sprites to the output directory
D2RMM.copyFile(
'hd', // <mod folder>\hd
'hd', // <diablo 2 folder>\mods\D2RMM\D2RMM.mpq\data\hd
true // overwrite any conflicts
);
Shows an error message to the user.
The message to show.
Use console.error()
or throw new Error()
instead.
D2RMM.error('Something went wrong!');
D2RMM.error(new Error('Something went wrong!'));
Internal
getReturns the configuration of the mod as a JSON string.
This is an internal API. You should reference the JSON parsed version of this value using the global config
object instead.
const config = D2RMM.getConfigJSON();
console.log('isFooEnabled = ' + JSON.parse(config).isFooEnabled);
The configuration of the mod.
Returns the full version of D2RMM composed of the major, minor, and patch versions as an array of integers.
Mods should not need to rely on the patch version.
const [major, minor, patch] = D2RMM.getFullVersion();
The version including the major, minor, and patch numbers.
Returns the list of mods being installed.
const modList = D2RMM.getModList();
modList.forEach(mod => {
console.log(
`mod ${mod.name} (${mod.id})`,
`v${mod.version}`,
`is ${mod.installed ? 'already installed' : 'not yet installed'}`,
`with config ${JSON.stringify(mod.config)}`,
);
});
The list of installed mods.
Produces the next valid string ID to use as an identifier in D2R's data files.
The ID is read from next_string_id.txt
, and then incremented within that file.
The next valid string ID.
Returns the version of D2RMM composed of the major and minor versions as a float.
You can use this API to check if the installed version of D2RMM is compatible with the APIs that your mod is using.
const version = D2RMM.getVersion(); // 1.5
The version including the major and the minor number.
Reads a JSON D2R file.
D2R's JSON files don't follow the standard JSON spec. This method will ignore any comments, whitespace, and various invalid properties (for example, duplicate keys), that D2R might use.
The file is either read from D2R game files as specified in D2RMM's config, or is the result of previously installed mods already operating on this file.
const profileHD = D2RMM.readJson('global\\ui\\layouts\\_profilehd.json');
profileHD.FontColorRed.r; // 252
The parsed JSON data.
Reads a save file from the saves directory as binary. The result is an array of bytes.
The path of the save file to read, relative to the saves directory.
const stashData = D2RMM.readSaveFile('SharedStashSoftCoreV2.d2i');
console.log('Save file size: ' + stashData.length);
The binary data of the save file.
Reads a TSV (tab separated values in a .txt) D2R file. This is a classic data format used by D2.
The last column in the file will probably have a \r
at the end of its name.
The file is either read from D2R game files as specified in D2RMM's config, or is the result of previously installed mods already operating on this file.
const treasureclassex = D2RMM.readTsv('global\\excel\\treasureclassex.txt');
console.log('There are ' + treasureclassex.rows.length + ' treasure classes!');
console.log('Each treasure class has ' + treasureclassex.headers.length + ' properties!');
The parsed TSV data.
Reads a plain text D2R file.
The path of the file to read, relative to the data directory.
The file is either read from D2R game files as specified in D2RMM's config, or is the result of previously installed mods already operating on this file.
const nextStringIDRaw = D2RMM.readJson('local\\next_string_id.txt');
let nextStringID = nextStringIDRaw.match(/[0-9]+/)[0]; // next valid string id
The raw text data.
Writes a JSON D2R file.
The path of the file to write, relative to the data directory.
The JSON data to write.
// change red colored text to bright green!
const profileHD = D2RMM.readJson('global\\ui\\layouts\\_profilehd.json');
profileHD.FontColorRed = {r: 0, b: 0, g: 255, a: 255};
D2RMM.writeJson('global\\ui\\layouts\\_profilehd.json', profileHD);
Writes a save file to the saves directory as binary.
The path of the save file to write, relative to the saves directory.
The binary data of the save file to write as an array of bytes.
It's highly recommended to write a backup of any save file you are modifying because save files can be corrupted if written incorrectly.
const stashData = D2RMM.readSaveFile('SharedStashSoftCoreV2.d2i');
D2RMM.writeSaveFile('SharedStashSoftCoreV2.d2i', stashData.concat(EXTRA_STASH_TAB));
Writes a TSV (tab separated values in a .txt) D2R file. This is a classic data format used by D2.
The path of the file to write, relative to the data directory.
The TSV data to write.
const treasureclassex = D2RMM.readTsv('global\\excel\\treasureclassex.txt');
treasureclassex.rows.forEach(row => {
// D2R TSV files sometimes have blank rows
if (row['Treasure Class'] !== '') {
row.NoDrop = 1;
}
});
D2RMM.writeTsv('global\\excel\\treasureclassex.txt', treasureclassex);
Writes a plain text D2R file.
The path of the file to write, relative to the data directory.
The raw text data to write.
const nextStringIDRaw = D2RMM.readTxt('local\\next_string_id.txt');
let nextStringID = nextStringIDRaw.match(/[0-9]+/)[0]; // next valid string id
nextStringID ++;
nextStringIDRaw.replace(/[0-9]+/, nextStringID);
D2RMM.writeTxt('local\\next_string_id.txt', nextStringIDRaw);
This is the interface of the global "D2RMM" variable provided to mods at runtime.
Example