### Example D2RMM mod.js Source: https://olegbl.github.io/d2rmm/index.html This example demonstrates checking the D2RMM version, writing JSON files, and conditionally logging messages based on configuration. Ensure the D2RMM version meets the mod's requirements. ```javascript if (D2RMM.getVersion() < 1.5) { throw new Error('This mod requires D2RMM version 1.5 or newer!'); } D2RMM.writeJson('local\lng\strings\foo.json', {foo: 'foo!'}); if (config.isBarEnabled) { console.log('Feature bar is enabled!'); D2RMM.writeJson('local\lng\strings\bar.json', {bar: 'bar!'}); } ``` -------------------------------- ### Example Binding Configuration Source: https://olegbl.github.io/d2rmm/types/Bindings.Binding.html This example shows how a binding can be used to conditionally control the visibility of a configuration field based on its value. This is common for UI elements like checkboxes. ```json { "id": "MyConfigField", "type": "checkbox" }, { "visible": ["value", "MyConfigField"] } ``` -------------------------------- ### Get List of Installed Mods Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Retrieves a list of all mods being installed, including their configuration, ID, installation status, name, and version. Useful for mod management and compatibility checks. ```javascript 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)}`, ); }); ``` -------------------------------- ### getModList Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Returns the list of mods being installed. ```APIDOC ## getModList getModList ### Description Returns the list of mods being installed. ### Method getModList ### Returns { config: Readonly<{ [key: string]: ModConfigSingleValue; }>; id: string; installed: boolean; name: string; version: undefined | string; }[] ### Example ```javascript 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)}`, ); }); ``` ### Returns The list of installed mods. ### Since D2RMM v1.7.0 ``` -------------------------------- ### BindingOr Example Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingOr.html This example demonstrates how to use the BindingOr type to make a configuration field visible if either 'MyConfigField1' or 'MyConfigField2' is true. The 'visible' property accepts an array where the first element is the operator ('or') and subsequent elements are the bindings to check. ```json { "id": "MyConfigField1", "type": "checkbox" }, { "id": "MyConfigField2", "type": "checkbox" }, { // ... "visible": ["or", ["value", "MyConfigField1"], ["value", "MyConfigField2"]] } ``` -------------------------------- ### BindingIncludes Example: Checking for String Inclusion Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingIncludes.html This example demonstrates how to use BindingIncludes with the 'in' operator to check if the string 'foo' is present in the array associated with 'MyConfigField'. This is useful for conditional visibility based on configuration values. ```json { "id": "MyConfigField", "type": "text", }, { // ... "visible": ["in", "foo", ["value", "MyConfigField"]], } ``` -------------------------------- ### Using BindingNotEquals for Visibility Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingNotEquals.html This example demonstrates how to use BindingNotEquals to control the visibility of a configuration field. The field 'MyConfigField' will be visible only when its value is not equal to 123. ```json { "id": "MyConfigField", "type": "number" }, { // ... "visible": ["neq", ["value", "MyConfigField"], 123] } ``` -------------------------------- ### Using BindingAnd for Visibility Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingAnd.html This example demonstrates how to use the 'and' operator with 'value' bindings to control the visibility of an element. It ensures that an element is only visible if both 'MyConfigField1' and 'MyConfigField2' are true. ```json { "id": "MyConfigField1", "type": "checkbox" }, { "id": "MyConfigField2", "type": "checkbox" }, { // ... "visible": ["and", ["value", "MyConfigField1"], ["value", "MyConfigField2"]] } ``` -------------------------------- ### Example D2RMM mod.json Configuration Source: https://olegbl.github.io/d2rmm/index.html This JSON file defines the metadata for your D2RMM mod, including its name, description, author, and version. The '$schema' field can be used for IDE validation. ```json { "$schema": "../config-schema.json", "name": "My New Mod", "description": "Best mod ever. Does great things! This is a terrible description.", "author": "myname", "website": "https://www.nexusmods.com/diablo2resurrected/mods/123456789", "version": "1.0" } ``` -------------------------------- ### BindingLiteralValue Example Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingLiteralValue.html This example shows a JSON object that could be a BindingLiteralValue. It includes a 'visible' property set to true. ```json { // ... "visible": true, } ``` -------------------------------- ### Using BindingEquals for Visibility Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingEquals.html Demonstrates how to use the 'eq' operator with BindingEquals to conditionally set the visibility of a field. This example checks if the value of 'MyConfigField' is equal to 123. ```json { "id": "MyConfigField", "type": "number" }, { // ... "visible": ["eq", ["value", "MyConfigField"], 123] } ``` -------------------------------- ### Using BindingLessThan for Visibility Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingLessThan.html This example demonstrates how to use the BindingLessThan operator to control the visibility of a configuration field. The 'visible' property is set to an array where the first element is 'lt', followed by the binding to check and the value to compare against. ```json { "id": "MyConfigField", "type": "number" }, { // ... "visible": ["lt", ["value", "MyConfigField"], 123] } ``` -------------------------------- ### Accessing Configuration Field Value with BindingConfigValue Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingConfigValue.html This example shows how to define a configuration field and then use BindingConfigValue to reference its value in the 'visible' property. This is useful for conditionally displaying configuration options. ```json { "id": "MyConfigField", "type": "checkbox", }, { // ... "visible": ["value", "MyConfigField"], } ``` -------------------------------- ### Get D2RMM Version Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Retrieves the current version of D2RMM. This is a simple example of calling a ModAPI function. ```javascript const version = D2RMM.getVersion(); ``` -------------------------------- ### Using BindingLessThanOrEqual for Visibility Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingLessThanOrEqual.html This example demonstrates how to use the 'lte' operator with BindingLessThanOrEqual to control the visibility of a field based on a numeric comparison. The 'visible' property is set to an array where the first element is the operator 'lte', followed by the binding to compare (e.g., ['value', 'MyConfigField']), and the threshold value. ```json { "id": "MyConfigField", "type": "number" }, { // ... "visible": ["lte", ["value", "MyConfigField"], 123] } ``` -------------------------------- ### Get Mod Configuration as JSON Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Retrieves the mod's configuration as a JSON string. This is an internal API; use the global `config` object for parsed data. ```javascript const config = D2RMM.getConfigJSON(); console.log('isFooEnabled = ' + JSON.parse(config).isFooEnabled); ``` -------------------------------- ### Using BindingNot for Conditional Visibility Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingNot.html This example demonstrates how to use the 'not' operator with a binding to control the visibility of a UI element. It checks if the value of 'MyConfigField' is false. ```json { "id": "MyConfigField", "type": "checkbox" }, { // ... "visible": ["not", ["value", "MyConfigField"]] } ``` -------------------------------- ### Using BindingGreaterThan for Visibility Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingGreaterThan.html This example demonstrates how to use the 'gt' operator with BindingGreaterThan to control the visibility of a field based on a numerical comparison. It checks if the value of 'MyConfigField' is greater than 123. ```json { "id": "MyConfigField", "type": "number" }, { // ... "visible": ["gt", ["value", "MyConfigField"], 123] } ``` -------------------------------- ### Get Full D2RMM Version Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Retrieves the full version of D2RMM as an array of integers [major, minor, patch]. The patch version is generally not needed by mods. ```javascript const [major, minor, patch] = D2RMM.getFullVersion(); ``` -------------------------------- ### Get D2RMM Version Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Retrieves the current version of D2RMM. Useful for ensuring API compatibility with your mod. ```javascript const version = D2RMM.getVersion(); // 1.5 ``` -------------------------------- ### Copy File or Directory Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Copies a file or directory from the mod directory to the data directory. Use this for non-mergeable assets. Overwriting is optional. ```javascript D2RMM.copyFile( 'hd', // \hd 'hd', // \mods\D2RMM\D2RMM.mpq\data\hd true // overwrite any conflicts ); ``` -------------------------------- ### writeSaveFile Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes a save file to the saves directory as binary data. It's recommended to back up save files before modification. ```APIDOC ## writeSaveFile ### Description Writes a save file to the saves directory as binary. ### Method `writeSaveFile(filePath: string, data: number[]): void` ### Parameters * **filePath** (string) - The path of the save file to write, relative to the saves directory. * **data** (number[]) - The binary data of the save file to write as an array of bytes. ### Returns void ### Note It's highly recommended to write a backup of any save file you are modifying because save files can be corrupted if written incorrectly. ### Example ```javascript const stashData = D2RMM.readSaveFile('SharedStashSoftCoreV2.d2d'); D2RMM.writeSaveFile('SharedStashSoftCoreV2.d2d', stashData.concat(EXTRA_STASH_TAB)); ``` ``` -------------------------------- ### writeTxt Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes data to a text file in the mod directory. ```APIDOC ## writeTxt writeTxt ### Description Writes data to a text file in the mod directory. ### Method writeTxt ### Parameters #### Path Parameters * **filePath** (string) - Required - The path to the text file, relative to the mod directory. * **data** (string) - Required - The data to write to the text file. ### Returns void ``` -------------------------------- ### readTxt Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a text file from the mod directory. ```APIDOC ## readTxt readTxt ### Description Reads a text file from the mod directory. ### Method readTxt ### Parameters #### Path Parameters * **filePath** (string) - Required - The path to the text file, relative to the mod directory. ### Returns string ``` -------------------------------- ### writeTxt Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes a plain text D2R file. ```APIDOC ## writeTxt ### Description Writes a plain text D2R file. ### Method `writeTxt(filePath: string, data: string): void` ### Parameters * **filePath** (string) - The path of the file to write, relative to the data directory. * **data** (string) - The raw text data to write. ### Returns void ### Example ```javascript 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); ``` ``` -------------------------------- ### Info message logging Source: https://olegbl.github.io/d2rmm/interfaces/ConsoleAPI.ConsoleAPI.html Outputs a message to the console with the log level 'info'. This is the standard method for general information. ```typescript log: ((...args) => void) ``` -------------------------------- ### copyFile Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html 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. ```APIDOC ## copyFile copyFile ### Description 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. ### Method copyFile ### Parameters #### Path Parameters * **src** (string) - Required - The path of the file or directory to copy, relative to the mod directory. * **dst** (string) - Required - The path of the file or directory to copy to, relative to the data directory. * **overwrite** (boolean) - Optional - Whether to overwrite any conflicts. ### Returns void ### Note 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. ### Example ```javascript // copy new sprites to the output directory D2RMM.copyFile( 'hd', // \hd 'hd', // \mods\D2RMM\D2RMM.mpq\data\hd true // overwrite any conflicts ); ``` ### Since D2RMM v1.0.0 ``` -------------------------------- ### Write Binary Save File Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes binary data to a save file. It is highly recommended to back up save files before modification to prevent corruption. ```javascript const stashData = D2RMM.readSaveFile('SharedStashSoftCoreV2.d2i'); D2RMM.writeSaveFile('SharedStashSoftCoreV2.d2i', stashData.concat(EXTRA_STASH_TAB)); ``` -------------------------------- ### ConsoleAPI Methods Source: https://olegbl.github.io/d2rmm/interfaces/ConsoleAPI.ConsoleAPI.html The ConsoleAPI provides methods for logging messages with different severity levels. These messages are directed to the D2RMM logs tab. ```APIDOC ## ConsoleAPI A console interface similar to that provided by the DOM or Node. It will print to D2RMM's logs tab. ### Methods #### debug Outputs a message to the console with the log level 'debug'. ##### Parameters - `...args` (ConsoleArg[]) - The data to log. ##### Returns - void #### error Outputs a message to the console with the log level 'error'. ##### Parameters - `...args` (ConsoleArg[]) - The data to log. ##### Returns - void #### log Outputs a message to the console with the log level 'info'. ##### Parameters - `...args` (ConsoleArg[]) - The data to log. ##### Returns - void #### warn Outputs a message to the console with the log level 'warn'. ##### Parameters - `...args` (ConsoleArg[]) - The data to log. ##### Returns - void ``` -------------------------------- ### getVersion Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Returns the major version of D2RMM. ```APIDOC ## getVersion getVersion ### Description Returns the major version of D2RMM. ### Method getVersion ### Returns number ``` -------------------------------- ### ModConfigSection Interface Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigSection.html Defines the structure of a configuration section, including its properties, children, and visibility controls. ```APIDOC ## Interface ModConfigSection A section in the configuration UI that can contain other fields or sections. #### Since D2RMM v1.6.0 interface ModConfigSection { allowToggleAll?: Binding; children?: readonly ModConfigFieldOrSection[]; defaultExpanded?: boolean; defaultValue?: Binding; description?: string; id: string; name: string; overrideValue?: Binding; type: "section"; visible?: Binding; } #### Hierarchy * ModConfigBase * ModConfigSection ## Properties ### `Optional` allowToggleAll allowToggleAll?: Binding Whether the "toggle all" button can appear in this section. Note that this button will only appear if all the children of this section are checkboxes. #### Since D2RMM v1.8.0 ### `Optional` children children?: readonly ModConfigFieldOrSection[] The fields or sections that are contained within this section. #### Since D2RMM v1.6.0 ### `Optional` defaultExpanded defaultExpanded?: boolean Whether the section should be expanded by default. #### Since D2RMM v1.6.0 ### `Optional` defaultValue defaultValue?: Binding If this value is anything other than `null`, the section will have a checkbox on the left hand side that will set this section's `value` the same way as it would work for a checkbox field. When used as a Binding, it is evaluated **once at load time** against the saved config — it does NOT re-evaluate reactively at runtime. For reactive value forcing, use `overrideValue` instead. #### Since D2RMM v1.9.0 as a Binding<> #### Since D2RMM v1.8.0 ### `Optional` description description?: string The description for the section that appears in a help tooltip. #### Since D2RMM v1.8.0 ### id id: string The unique identifier of the configuration element. ### name name: string The name of the section. #### Since D2RMM v1.6.0 ### `Optional` overrideValue overrideValue?: Binding The override value of the section field. If this value is anything other than `null`, it will override the current value. If the value is overridden, it will also be read only. This needs to be used in unison with `defaultValue`. #### Since D2RMM v1.8.0 ### type type: "section" The type of the configuration element. #### Since D2RMM v1.6.0 ### `Optional` visible visible?: Binding Determines if the section is visible or not. #### Since D2RMM v1.8.0 ``` -------------------------------- ### Log a message using ConsoleAPI Source: https://olegbl.github.io/d2rmm/interfaces/ConsoleAPI.ConsoleAPI.html Use the `log` method to output informational messages to the D2RMM logs tab. This is equivalent to `console.log` in browser or Node.js environments. ```typescript console.log('Hello, world!'); ``` -------------------------------- ### readTxt Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a plain text D2R file. The file can be read from game files or previously modified files. ```APIDOC ## readTxt ### Description Reads a plain text D2R file. 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. ### Method (filePath: string) => string ### Parameters #### Path Parameters - **filePath** (string) - Required - The path of the file to read, relative to the data directory. ### Returns string - The raw text data. ### Example ```javascript const nextStringIDRaw = D2RMM.readJson('local\next_string_id.txt'); let nextStringID = nextStringIDRaw.match(/[0-9]+/)[0]; // next valid string id ``` ### Since D2RMM v1.4.0 ``` -------------------------------- ### Modify and Write Plain Text File Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a plain text file, extracts and increments a numerical value, and then updates the file with the new value. Assumes the text file contains a number that can be matched. ```javascript 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); ``` -------------------------------- ### readJson Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a JSON file from the mod directory. ```APIDOC ## readJson readJson ### Description Reads a JSON file from the mod directory. ### Method readJson ### Parameters #### Path Parameters * **filePath** (string) - Required - The path to the JSON file, relative to the mod directory. ### Returns JSONData ``` -------------------------------- ### writeJson Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes data to a JSON file in the mod directory. ```APIDOC ## writeJson writeJson ### Description Writes data to a JSON file in the mod directory. ### Method writeJson ### Parameters #### Path Parameters * **filePath** (string) - Required - The path to the JSON file, relative to the mod directory. * **data** (JSONData) - Required - The data to write to the JSON file. ### Returns void ``` -------------------------------- ### writeSaveFile Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes data to a save file in the save directory. ```APIDOC ## writeSaveFile writeSaveFile ### Description Writes data to a save file in the save directory. ### Method writeSaveFile ### Parameters #### Path Parameters * **filePath** (string) - Required - The path to the save file, relative to the save directory. * **data** (number[]) - Required - The data to write to the save file. ### Returns void ``` -------------------------------- ### Warning message logging Source: https://olegbl.github.io/d2rmm/interfaces/ConsoleAPI.ConsoleAPI.html Outputs a message to the console with the log level 'warn'. Use this for potential issues or non-critical problems. ```typescript warn: ((...args) => void) ``` -------------------------------- ### ModConfigSection Interface Definition Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigSection.html Defines the structure of a configuration section, including properties like ID, name, description, and child elements. Supports optional toggles, default states, and visibility bindings. ```typescript interface ModConfigSection { allowToggleAll?: Binding; children?: readonly ModConfigFieldOrSection[]; defaultExpanded?: boolean; defaultValue?: Binding; description?: string; id: string; name: string; overrideValue?: Binding; type: "section"; visible?: Binding; } ``` -------------------------------- ### getNextStringID Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Returns the next available string ID. ```APIDOC ## getNextStringID getNextStringID ### Description Returns the next available string ID. ### Method getNextStringID ### Returns number ``` -------------------------------- ### getFullVersion Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Returns the full version of D2RMM composed of the major, minor, and patch versions as an array of integers. ```APIDOC ## getFullVersion getFullVersion ### Description Returns the full version of D2RMM composed of the major, minor, and patch versions as an array of integers. ### Method getFullVersion ### Returns [number, number, number] ### Note Mods should not need to rely on the patch version. ### Example ```javascript const [major, minor, patch] = D2RMM.getFullVersion(); ``` ### Returns The version including the major, minor, and patch numbers. ### Since D2RMM v1.7.0 ``` -------------------------------- ### readJson Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a JSON D2R file, ignoring comments, whitespace, and invalid properties. The file can be read from game files or previously modified files. ```APIDOC ## readJson ### Description 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. ### Method (filePath: string) => JSONData ### Parameters #### Path Parameters - **filePath** (string) - Required - The path of the file to read, relative to the data directory. ### Returns JSONData - The parsed JSON data. ### Example ```javascript const profileHD = D2RMM.readJson('global\ui\layouts\_profilehd.json'); profileHD.FontColorRed.r; // 252 ``` ### Since D2RMM v1.0.0 ``` -------------------------------- ### writeTsv Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes data to a TSV file in the mod directory. ```APIDOC ## writeTsv writeTsv ### Description Writes data to a TSV file in the mod directory. ### Method writeTsv ### Parameters #### Path Parameters * **filePath** (string) - Required - The path to the TSV file, relative to the mod directory. * **data** (TSVData) - Required - The data to write to the TSV file. * **options** (object) - Optional - Options for writing the TSV file. ### Returns void ``` -------------------------------- ### ModConfigFieldColor Interface Definition Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigFieldColor.html This snippet shows the structure of the ModConfigFieldColor interface, which is used to define a color picker element in the configuration UI. ```APIDOC ## Interface ModConfigFieldColor Represents a color configuration field that will be represented as a color picker element in the configuration UI. #### Since D2RMM v1.6.0 interface ModConfigFieldColor { defaultValue: NumberArrayBinding; description?: string; id: string; isAlphaHidden?: boolean; name: string; overrideValue?: Binding; type: "color"; visible?: Binding; } #### Hierarchy * ModConfigFieldBase * ModConfigFieldColor ``` -------------------------------- ### readSaveFile Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a save file from the saves directory as binary data, returning an array of bytes. This is useful for accessing save game information. ```APIDOC ## readSaveFile ### Description Reads a save file from the saves directory as binary. The result is an array of bytes. ### Method (filePath: string) => null | number[] ### Parameters #### Path Parameters - **filePath** (string) - Required - The path of the save file to read, relative to the saves directory. ### Returns null | number[] - The binary data of the save file. ### Example ```javascript const stashData = D2RMM.readSaveFile('SharedStashSoftCoreV2.d2i'); console.log('Save file size: ' + stashData.length); ``` ### Since D2RMM v1.7.0 ``` -------------------------------- ### Read D2R Save File Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a save file from the D2R saves directory as raw binary data. Returns an array of bytes. ```javascript const stashData = D2RMM.readSaveFile('SharedStashSoftCoreV2.d2i'); console.log('Save file size: ' + stashData.length); ``` -------------------------------- ### ModConfigFieldText Interface Definition Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigFieldText.html This snippet shows the structure of the ModConfigFieldText interface, which is used to define text-based configuration fields. ```APIDOC interface ModConfigFieldText { defaultValue: StringBinding; description?: string; id: string; name: string; overrideValue?: Binding; type: "text"; visible?: Binding; } ``` -------------------------------- ### getVersion Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Returns the version of D2RMM composed of the major and minor versions as a float. This API can be used to check for compatibility. ```APIDOC ## getVersion ### Description 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. ### Method (() => number) ### Returns number - The version including the major and the minor number. ### Example ```javascript const version = D2RMM.getVersion(); // 1.5 ``` ### Since D2RMM v1.4.0 ``` -------------------------------- ### writeJson Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes a JSON D2R file to the specified path relative to the data directory. ```APIDOC ## writeJson ### Description Writes a JSON D2R file. ### Method (filePath: string, data: JSONData) => void ### Parameters #### Path Parameters - **filePath** (string) - Required - The path of the file to write, relative to the data directory. - **data** (JSONData) - Required - The JSON data to write. ### Returns void ### Since D2RMM v1.0.0 ``` -------------------------------- ### Read D2R Plain Text File Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a plain text file from the D2R data directory. Useful for files like `next_string_id.txt`. ```javascript const nextStringIDRaw = D2RMM.readJson('local\next_string_id.txt'); let nextStringID = nextStringIDRaw.match(/[0-9]+/)[0]; // next valid string id ``` -------------------------------- ### readTsv Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a TSV file from the mod directory. ```APIDOC ## readTsv readTsv ### Description Reads a TSV file from the mod directory. ### Method readTsv ### Parameters #### Path Parameters * **filePath** (string) - Required - The path to the TSV file, relative to the mod directory. * **options** (object) - Optional - Options for reading the TSV file. ### Returns TSVData ``` -------------------------------- ### ModConfigFieldColor Properties Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigFieldColor.html Details on the properties available for the ModConfigFieldColor interface. ```APIDOC ## Properties ### defaultValue defaultValue: NumberArrayBinding The default value of the color in RGBA format (`[0, 255]`, `[0, 255]`, `[0, 255]`, `[0.0, 1.0]`). Used when the user has no saved value for this field. When used as a Binding, it is evaluated **once at load time** against the saved config — it does NOT re-evaluate reactively at runtime. For reactive value forcing, use `overrideValue` instead. #### Since D2RMM v1.9.0 as a Binding<> #### Since D2RMM v1.6.0 ### `Optional` description description?: string The description for the field that appears in a help tooltip. #### Since D2RMM v1.0.0 ### id id: string The unique identifier of the configuration element. ### `Optional` isAlphaHidden isAlphaHidden?: boolean Whether the alpha channel should be hidden in the color picker. #### Since D2RMM v1.6.0 ### name name: string The name of the field. #### Since D2RMM v1.0.0 ### `Optional` overrideValue overrideValue?: Binding The override value of the color field. If this value is anything other than `null`, it will override the current value. If the value is overridden, it will also be read only. #### Since D2RMM v1.8.0 ### type type: "color" The type of the configuration element. #### Since D2RMM v1.6.0 ### `Optional` visible visible?: Binding Determines if the field is visible or not. #### Since D2RMM v1.8.0 ``` -------------------------------- ### ModConfigFieldText Properties Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigFieldText.html Details on the properties available for the ModConfigFieldText interface. ```APIDOC ## Properties ### defaultValue defaultValue: StringBinding The default value of the text field. Used when the user has no saved value for this field. When used as a Binding, it is evaluated **once at load time** against the saved config — it does NOT re-evaluate reactively at runtime. For reactive value forcing, use `overrideValue` instead. #### Since D2RMM v1.9.0 as a Binding<> #### Since D2RMM v1.4.0 ### `Optional` description description?: string The description for the field that appears in a help tooltip. #### Since D2RMM v1.0.0 ### id id: string The unique identifier of the configuration element. ### name name: string The name of the field. #### Since D2RMM v1.0.0 ### `Optional` overrideValue overrideValue?: Binding The override value of the text field. If this value is anything other than `null`, it will override the current value. If the value is overridden, it will also be read only. #### Since D2RMM v1.8.0 ### type type: "text" The type of the configuration element. #### Since D2RMM v1.4.0 ### `Optional` visible visible?: Binding Determines if the field is visible or not. #### Since D2RMM v1.8.0 ``` -------------------------------- ### Check if a Configuration Section is Expanded Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingSectionExpanded.html Use this binding to check if a configuration section with a given ID is currently expanded. This is useful for conditional rendering or logic based on the UI state of sections. ```json { "id": "MyConfigSection", "type": "section", }, { // ... "visible": ["expanded", "MyConfigSection"], } ``` -------------------------------- ### readSaveFile Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a save file from the save directory. ```APIDOC ## readSaveFile readSaveFile ### Description Reads a save file from the save directory. ### Method readSaveFile ### Parameters #### Path Parameters * **filePath** (string) - Required - The path to the save file, relative to the save directory. ### Returns null | number[] ``` -------------------------------- ### D2RMM Mod Runtime Globals Source: https://olegbl.github.io/d2rmm/index.html These global variables are available within your mod's JavaScript or TypeScript file during runtime. They provide access to D2RMM's API, configuration, and logging. ```javascript const D2RMM: ModAPI; const config: ModConfigValue; const console: ConsoleAPI; ``` -------------------------------- ### Modify JSON File Properties Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a JSON file, modifies a specific property (e.g., font color), and writes the changes back to the file. Ensure the JSON structure is as expected. ```javascript // 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); ``` -------------------------------- ### ModConfigFieldSelect Interface Definition Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigFieldSelect.html This snippet details the properties of the ModConfigFieldSelect interface, which represents a select configuration field. ```APIDOC ## Interface ModConfigFieldSelect Represents a select configuration field that will be represented as a dropdown select element in the configuration UI. ### Properties - **defaultValue** (Binding): The default value of the select field. Used when the user has no saved value for this field. When used as a Binding, it is evaluated once at load time against the saved config — it does NOT re-evaluate reactively at runtime. For reactive value forcing, use `overrideValue` instead. - **description**? (string): The description for the field that appears in a help tooltip. - **id** (string): The unique identifier of the configuration element. - **name** (string): The name of the field. - **options** ({ description?: string; label: string; value: ModConfigSingleValue; }[]): The options that the user can select from. Each option includes an optional description, a required label, and a required value. - **overrideValue**? (Binding): The override value of the select field. If this value is anything other than `null`, it will override the current value. If the value is overridden, it will also be read only. - **type** ("select"): The type of the configuration element, fixed to "select". - **visible**? (Binding): Determines if the field is visible or not. ``` -------------------------------- ### Write D2R JSON File Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes data to a JSON file in the D2R data directory. The data is expected to be in a format compatible with D2R's JSON structure. ```javascript D2RMM.writeJson('path\to\your\file.json', { key: 'value' }); ``` -------------------------------- ### ModConfigFieldCheckbox Interface Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigFieldCheckbox.html Represents a boolean (true/false) configuration field that will be represented as a checkbox or toggle element in the configuration UI. ```APIDOC ## Interface ModConfigFieldCheckbox Represents a boolean (true/false) configuration field that will be represented as a checkbox or toggle element in the configuration UI. #### Since D2RMM v1.0.0 interface ModConfigFieldCheckbox { defaultValue: Binding; description?: string; id: string; name: string; overrideValue?: Binding; type: "checkbox"; visible?: Binding; } #### Hierarchy * ModConfigFieldBase * ModConfigFieldCheckbox ### Properties defaultValue description? id name overrideValue? type visible? ## Properties ### defaultValue defaultValue: Binding The default value of the checkbox field. Used when the user has no saved value for this field. When used as a Binding, it is evaluated **once at load time** against the saved config — it does NOT re-evaluate reactively at runtime. For reactive value forcing, use `overrideValue` instead. #### Since D2RMM v1.9.0 as a Binding<> #### Since D2RMM v1.0.0 ### `Optional` description description?: string The description for the field that appears in a help tooltip. #### Since D2RMM v1.0.0 ### id id: string The unique identifier of the configuration element. ### name name: string The name of the field. #### Since D2RMM v1.0.0 ### `Optional` overrideValue overrideValue?: Binding The override value of the checkbox field. If this value is anything other than `null`, it will override the current value. If the value is overridden, it will also be read only. #### Since D2RMM v1.8.0 ### type type: "checkbox" The type of the configuration element. #### Since D2RMM v1.0.0 ### `Optional` visible visible?: Binding Determines if the field is visible or not. #### Since D2RMM v1.8.0 ``` -------------------------------- ### error Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Shows an error message to the user. Deprecated in favor of console.error() or throw new Error(). ```APIDOC ## error error ### Description Shows an error message to the user. ### Method error ### Parameters #### Path Parameters * **message** (string | Error) - Required - The message to show. ### Returns void ### Deprecated Use `console.error()` or `throw new Error()` instead. ### Example ```javascript D2RMM.error('Something went wrong!'); D2RMM.error(new Error('Something went wrong!')); ``` ### Since D2RMM v1.0.0 ``` -------------------------------- ### writeTsv Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Writes a TSV (tab separated values) D2R file. This function is used for classic data formats in Diablo 2. ```APIDOC ## writeTsv ### Description Writes a TSV (tab separated values in a .txt) D2R file. This is a classic data format used by D2. ### Method `writeTsv(filePath: string, data: TSVData, options?: { addCarriageReturns?: boolean }): void` ### Parameters * **filePath** (string) - The path of the file to write, relative to the data directory. * **data** (TSVData) - The TSV data to write. * **options** (Optional) - Optional settings. * **addCarriageReturns** (Optional, boolean) - When true, writes the file with CRLF (`\r\n`) line endings so the last column retains its trailing `\r` as D2R expects. Use this when you passed `removeCarriageReturns: true` to the corresponding `readTsv` call. ### Returns void ### Example ```javascript 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); ``` ``` -------------------------------- ### getNextStringID Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html 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. ```APIDOC ## getNextStringID ### Description 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. ### Method (() => number) ### Returns number - The next valid string ID. ### Since D2RMM v1.4.0 ``` -------------------------------- ### ModConfigFieldNumber Interface Definition Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigFieldNumber.html Defines the structure of a number configuration field within D2RMM. ```APIDOC ## Interface ModConfigFieldNumber Represents a number configuration field that will be represented as a number input in the configuration UI. #### Since D2RMM v1.0.0 interface ModConfigFieldNumber { defaultValue: NumberBinding; description?: string; id: string; maxValue?: number; minValue?: number; name: string; overrideValue?: Binding; type: "number"; visible?: Binding; } #### Hierarchy * ModConfigFieldBase * ModConfigFieldNumber ``` -------------------------------- ### BindingGreaterThanOrEqual Source: https://olegbl.github.io/d2rmm/types/Bindings.BindingGreaterThanOrEqual.html Defines a binding that checks if the first numeric value is greater than or equal to the second numeric value. ```APIDOC ## BindingGreaterThanOrEqual ### Description Checks if the first parameter (number) is greater than or equal to the second parameter (number). ### Type Alias `BindingGreaterThanOrEqual: [operator: "gte", binding1: Binding, binding2: Binding]` ### Example ```json { "id": "MyConfigField", "type": "number" } ``` ```json { "visible": ["gte", ["value", "MyConfigField"], 123] } ``` ### Since D2RMM v1.6.0 ``` -------------------------------- ### ModConfigFieldNumber Properties Source: https://olegbl.github.io/d2rmm/interfaces/ModConfig.ModConfigFieldNumber.html Details of the properties available for the ModConfigFieldNumber interface. ```APIDOC ## Properties ### defaultValue defaultValue: NumberBinding The default value of the number field. Used when the user has no saved value for this field. When used as a Binding, it is evaluated **once at load time** against the saved config — it does NOT re-evaluate reactively at runtime. For reactive value forcing, use `overrideValue` instead. #### Since D2RMM v1.9.0 as a Binding<> #### Since D2RMM v1.0.0 ### `Optional` description description?: string The description for the field that appears in a help tooltip. #### Since D2RMM v1.0.0 ### id id: string The unique identifier of the configuration element. ### `Optional` maxValue maxValue?: number The maximum value that the user can input. #### Since D2RMM v1.0.0 ### `Optional` minValue minValue?: number The minimum value that the user can input. #### Since D2RMM v1.0.0 ### name name: string The name of the field. #### Since D2RMM v1.0.0 ### `Optional` overrideValue overrideValue?: Binding The override value of the number field. If this value is anything other than `null`, it will override the current value. If the value is overridden, it will also be read only. #### Since D2RMM v1.8.0 ### type type: "number" The type of the configuration element. #### Since D2RMM v1.0.0 ### `Optional` visible visible?: Binding Determines if the field is visible or not. #### Since D2RMM v1.8.0 ``` -------------------------------- ### Modify and Write TSV File Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Reads a TSV file, modifies its rows (e.g., setting 'NoDrop' for non-blank rows), and writes the updated data back. Handles potential blank rows in the TSV. ```javascript 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); ``` -------------------------------- ### Display Error Message Source: https://olegbl.github.io/d2rmm/interfaces/ModAPI.ModAPI.html Shows an error message to the user. Deprecated in favor of console.error() or throw new Error(). ```javascript D2RMM.error('Something went wrong!'); D2RMM.error(new Error('Something went wrong!')); ```