# LOOT Metadata Syntax

## Contents

1. Introduction
2. Metadata File Contents
3. Data Structures
   1. Tag Data Structure
   2. File Data Structure
   3. Message Data Structure
   4. Location Data Structure
   5. Dirty Info Data Structure
   6. Plugin Data Structure
4. Condition Strings
   1. Functions
   2. The Negator & Junctors
   3. Order Of Evaluation
5. Language Codes
6. Version History
7. License

## Introduction

The metadata syntax is what LOOT's masterlists and userlists are written in. If you know YAML, good news: the syntax is essentially just YAML 1.2. If you don't know YAML, then its Wikipedia page is a good introduction. All you really need to know is:

- How lists and associative arrays (key-value maps) are written.
- That whitespace is important, and that only normal spaces (ie. no non-breaking spaces or tabs) count as such.
- That data entries that are siblings must be indented by the same amount, and child data nodes must be indented further than their parents (see the example later in this document if you don't understand).
- That YAML files must be written in a Unicode encoding.
- That each key in a key-value map must only appear once per map object.

An important point that is more specific to how LOOT uses YAML:

- Strings are case-sensitive, apart from file paths, regular expressions and checksums.

Some properties of file paths as used by LOOT:

- They are evaluated as paths relative to the game's Data folder.
- They cannot reference a path outside of the game's folder structure, ie. they cannot contain the substring `../../`.
- Regular expression file paths must be written in the EMCAScript syntax.
- Only the filename of a regex file path may contain non-literal regex syntax, ie. if the filename part of the regex file path is removed, the remainder must be an exact folder path (though with the regex syntax special characters escaped). For example, given the regex file path `Meshes\\Resources(1|2)\\(upperclass)?table.nif`, LOOT will look for a file named `table.nif` or `upperclasstable.nif` in the `Meshes\Resources(1|2)` folder, rather than looking in the `Meshes\Resources1` and `Meshes\Resources2` folders.

In this document, where a value's type is given as `X list`, this is equivalent to a YAML sequence of values which are of the data type X. Where a value's type is given as `X set`, this is equivalent to a YAML sequence of unique values which are of the data type X. Uniqueness is determined using the equality criteria for that data type. All the non-standard data types that LOOT's metadata syntax uses have their equality criteria defined later in this document.

## Metadata File Contents

The root of a metadata file is a key-value map. LOOT will recognise the following keys, none of which are required:

Key Name | Value Type | Notes
--- | --- | ---
`globals` | message list | A list of message data structures for messages that are displayed independently of any plugin.
`plugins` | plugin list and plugin set | The plugin data structures that hold all the plugin metadata within the file. It is a mixture of a list and a set because no non-regex plugin value may be equal to any other non-regex plugin value, but there may be any number of equal regex plugin values, and non-regex plugin values may be equal to regex plugin values. If multiple plugin values match a single plugin, their metadata is merged in the order the values are listed, and as defined later in this document.

Other keys may also be present, but are not processed by LOOT. The message and plugin data structures are detailed in the next section.

An example metadata file:

    globals:
      - type: say
        content: 'You are using the latest version of LOOT.'
        condition: 'version("LOOT", "0.5.0.0", ==)'
    plugins:
      - name: 'Armamentarium.esm'
        tag:
          - Relev
      - name: 'ArmamentariumFran.esm'
        tag:
          - Relev
      - name: 'Beautiful People 2ch-Ed.esm'
        tag:
          - Eyes
          - Graphics
          - Hair
          - R.Relations

## Data Structures

LOOT expects metadata to be laid out using a certain set of data structures, described in this section.

### Tag Data Structure

LOOT metadata files can contain suggestions for the addition or removal of Bash Tags, and this is the structure used for them. It has two forms: a key-value map and a scalar string.

#### Map Form

All values in the map are strings.

Key Name | Required | Notes
--- | --- | ---
`name` | ✓ | A Bash Tag, preceded by a minus sign if it is suggested for removal.
`condition` | ✗ | A condition string that is evaluated to determine whether this Bash Tag should be suggested: if it evaluates to true, the Tag is suggested, otherwise it is ignored. See Condition Strings for details.

#### Scalar Form

    tag

where `tag` is equivalent to the value of the `name` key in the map form.

#### Equality

Two tag data structures are equal if the lowercased values of their `name` keys are identical.

#### Examples

    Relations

    name: -Relations
    condition: 'file("Mart''s Monster Mod for OOO.esm") or file("FCOM_Convergence.esm")'

### File Data Structure

Not to be confused with the structure of the metadata file itself, this structure can be used to hold file paths. It has two forms: a key-value map and a scalar string.

#### Map Form

All values in the map are strings.

Key Name | Required | Notes
--- | --- | ---
`name` | ✓ | An exact (ie. not regex) file path or name.
`display` | ✗ | A substitute string to be displayed instead of the file path in any generated messages, eg. the name of the mod the file belongs to.
`condition` | ✗ | A condition string that is evaluated to determine whether this file data should be used: if it evaluates to true, the data is used, otherwise it is ignored. See Condition Strings for details.

#### Scalar Form

    filepath

where `filepath` is equivalent to the value of the `name` key in the map form.

#### Equality

Two file data structures are equal if the lowercased values of their `name` keys are identical.

#### Examples

    '../obse_loader.exe'

    name: '../obse_loader.exe'
    condition: 'version("../obse_loader.exe", "0.0.18.0", >=)'
    display: 'OBSE v18+'

### Message Data Structure

Messages are given as key-value maps.

Key Name | Value Type | Required | Notes
--- | --- | --- | ---
`type` | string | ✓ | The type string can be one of three keywords, see the table below for their semantics.
`content` | string or localised content list | ✓ | Either simply a string, or a list of localised content data structures. If the latter, one of the structures must be for English.
`condition` | string | ✗ | A condition string that is evaluated to determine whether the message should be displayed: if it evaluates to true, the message is displayed, otherwise it is not. See Condition Strings for details.
`subs` | string list | ✗ | A list of strings to be substituted into the message content string. The content string must use numbered specifiers (`%1%`, `%2%`, etc.), where the numbers correspond to the position of the substitution string in this list to use, to denote where these strings are to be substituted.

LOOT supports formatting of messages using GitHub Flavored Markdown. Support is provided by the Marked library (v0.3). Strings that get substituted into messages, such as file display names and dirty info utility strings, also support the same formatting options.

LOOT handles messages and languages as follows:

1. If a message's `content` value is a string, the message will use the string as its content if displayed.
2. If a message's `content` value is a list of localised content structures, then the first structure with a language that matches LOOT's current language will be used as the message's content if displayed. If there are no matches, then the first structure in English will be used.

#### Message Types

Keyword | Description
--- | ---
`say` | A generic message, useful for miscellaneous notes.
`warn` | A warning message, describing a non-critical issue with the user's mods (eg. dirty mods).
`error` | An error message, decribing a critical installation issue (eg. missing masters, corrupt plugins).

#### Localised Content Data Structure

The localised content data structure is a key-value map, with all values being strings:

Key Name | Required | Notes
--- | --- | ---
`str` | ✓ | The actual message content string.
`lang` | ✓ | The language that `str` is written in, given as a POSIX language code. The languages LOOT supports are given in Language Codes.

#### Equality

The equality of two message data structures is determined by comparing the values of their `content` keys. As the values of the keys can be different types, a comparison value is selected for each message using the following logic:

- If a value's type is a localised content list, then the English content string in that list is selected as the comparison value.
- If a value's type is a string, then that string is selected as the comparison value.

The two message data structures are then equal if their lowercased comparison values are identical.

#### Examples
(translations by Google)

    type: say
    condition: 'file("foo.esp")'
    content:
      - lang: en
        str: 'An example link: <http://www.example.com>'
      - lang: ru
        str: 'Это пример ссылки: <http://www.example.com>'

would be displayed as

> отмечать: Это пример ссылки: http://www.example.com

if the current language was Russian and `foo.esp` was installed, while

    type: say
    content: 'An alternative [example link](http://www.example.com), with no translations.'

would be displayed as

> отмечать: An alternative example link, with no translations.

In English,

    type: say
    content: 'A newer version of %1% [is available](%2%).
    subs:
      - 'this plugin'
      - 'http://www.example.com'

would be displayed as

> Note: A newer version of this plugin is available.

### Location Data Structure

This data structure is used to hold information on where a plugin is hosted online. It has two forms: a key-value map and a scalar string.

#### Map Form

All values in the map are strings.

Key Name | Required | Notes
--- | --- | ---
`link` | ✓ | A URL at which the plugin is found.
`name` | ✗ | A descriptive name for the URL, which may be used as hyperlink text.

#### Scalar Form

    URL

where `URL` is equivalent to the value of the `link` key in the map form.

#### Equality

Two location data structures are equal if the lowercased values of their `link` keys are identical.

#### Examples

    'http://skyrim.nexusmods.com/mods/19/'

    link: 'https://steamcommunity.com/sharedfiles/filedetails/?id=419668499'
    name: 'Unofficial Skyrim Patch on Steam Workshop'

### Dirty Info Data Structure

This structure holds information on which versions of a plugin are dirty, and how many identical-to-master records, deleted records and deleted navmeshes (if applicable) it contains. Dirty info is given as a key-value map.

Key Name | Value Type | Required | Notes
--- | --- | --- | ---
`crc` | hexadecimal integer | ✓ | The CRC checksum of the dirty plugin, before cleaning. LOOT displays the CRCs of installed plugins in its report. The 8-character CRC should be preceded by `0x` so that it is correctly interpreted.
`util` | string | ✓ | The utility that should be used to clean the plugin.
`itm` | integer | ✗ | The number of identical-to-master records reported for the dirty plugin. If the number is unknown, this field should not be supplied. If the number is known and zero, this field should be supplied.
`udr` | integer | ✗ | The number of undeleted records reported for the dirty plugin. If the number is unknown, this field should not be supplied. If the number is known and zero, this field should be supplied.
`nav` | integer | ✗ | The number of deleted navmeshes reported for the dirty plugin. If the number is unknown, this field should not be supplied. If the number is known and zero, this field should be supplied.

#### Equality

Two location data structures are equal if the values of their `crc` keys are identical.

#### Examples

    crc: 0x3DF62ABC
    util: '[TES5Edit](http://www.creationkit.com/TES5Edit_Cleaning_Guide_-_TES5Edit)'
    itm: 4
    udr: 160
    nav: 0

### Plugin Data Structure

This is the structure that brings all the others together, and forms the main component of a metadata file. It is a key-value map.

Key Name | Value Type | Required | Notes
--- | --- | --- | ---
`name` | string | ✓ | Can be an exact plugin filename or a regular expression plugin filename. If the filename contains any of the characters `:\*?|`, the string will be treated as a regular expression, otherwise it will be treated as an exact filename. For example, `Example\.esm` will be treated as a regular expression, as it contains a `\` character.
`enabled` | boolean | ✗ | Enables or disables use of the plugin object. Used for user rules, but no reason to use it in the masterlist. If unspecified, defaults to `true`.
`priority` | integer | ✗ | Modifies plugin position relative to others that change one or more of the same records, but which are otherwise unrelated (ie. neither plugin lists the other as a master, requirement, or in its `after` list). Plugins that don't change any of the same records are not compared, unless: One of the plugins is an empty plugin, containing only a header record. One of the plugins has a priority greater than or equal to 1,000,000. In this case, only the modulo (ie. remainder when divided) with 1,000,000 is used when comparing plugin priority values – the rest is only used to signify that the plugin should be compared against all others. For example, `priority: 153000352` and `priority: 352` have equal values when compared, but a plugin with the first priority will be compared against all others, while a (non-empty) plugin with the second priority will be compared against only those it conflicts with. A plugin with a higher priority value will load after a plugin with a lower priority value. The value can be anything in the range `-2000000000` to `2000000000`, and if unspecified defaults to `0`.
`after` | file set | ✗ | An unordered set of plugins that this plugin must load after, but which are not dependencies. Used for resolving specific compatibility issues and by user rules for specifying custom plugin positions.
`req` | file set | ✗ | An unordered set of files that this plugin requires to be present. This plugin will load after any plugins listed. If any of these files are missing, an error message will be displayed. Intended for use specifying implicit dependencies, as LOOT will detect a plugin's explicit masters itself.
`inc` | file set | ✗ | An unordered set of files that this plugin is incompatible with. If any of these files are present, an error message will be displayed.
`msg` | message list | ✗ | The messages attached to this plugin. The messages will be displayed in the order that they are listed.
`tag` | tag set | ✗ | An unordered set of Bash Tags suggested for this plugin. If a Bash Tag is suggested for both addition and removal, the latter will override the former when the list is evaluated.
`url` | location set | ✗ | An unordered set of locations for this plugin. If the same version can be found at multiple locations, only one location should be recorded. This metadata is not currently used by LOOT.
`dirty` | dirty info set | ✗ | An unordered set of dirty info structures for this plugin. Plugin entries with regular expression filenames must not contain dirty info.

#### Equality

The equality of two plugin data structures is determined by comparing the values of their `name` keys.

- If neither or both values are regular expressions, then the plugin data structures are equal if the lowercased values are identical.
- If one value is a regular expression, then the plugin data structures are equal if the other value is an exact match for it.

#### Merging Behaviour

Key Name | Merge Behaviour (merging B into A)
--- | ---
`name` | Not merged.
`enabled` | Replaced by B's value.
`priority` | Replaced by B's value, unless that value is `0` and it was not explicitly set.
`after` | Merged. If B's file set contains an item that is equal to one already present in A's file set, B's item is discarded.
`req` | Merged. If B's file set contains an item that is equal to one already present in A's file set, B's item is discarded.
`inc` | Merged. If B's file set contains an item that is equal to one already present in A's file set, B's item is discarded.
`msg` | Merged. If B's message list contains an item that is equal to one already present in A's message list, B's item is discarded.
`tag` | Merged.If B's tag set contains an item that is equal to one already present in A's tag set, B's item is discarded.
`url` | Merged. If B's location set contains an item that is equal to one already present in A's location set, B's item is discarded.
`dirty` | Merged.If B's dirty info set contains an item that is equal to one already present in A's dirty info set, B's item is discarded.

#### Examples

    name: 'Oscuro''s_Oblivion_Overhaul.esm'
    req:
      - 'Oblivion.esm'  # Don't do this, Oblivion.esm is a master of Oscuro's_Oblivion_Overhaul.esm, so LOOT already knows it's required.
      - name: 'example.esp'
        display: '[Example Mod](http://www.example.com)'
        condition: 'version("Oscuro''s_Oblivion_Overhaul.esm", "15.0", ==)'
    tag:
      - Actors.Spells
      - Graphics
      - Invent
      - Relations
      - Scripts
      - Stats
      - name: -Relations
        condition: 'file("Mart''s Monster Mod for OOO.esm") or file("FCOM_Convergence.esm")'
    msg:
      - type: say
        content: 'Do not clean. "Dirty" edits are intentional and required for the mod to function.'

## Condition Strings

Condition strings can be used to ensure that data is only acted on by LOOT under certain circumstances. They are very similar to boolean conditional expressions in programming languages such as Python, though more limited. Their EBNF grammar is:

    [ negator ], function, { junctor, [ negator ], function } ;

The `[ negator ], function` grammar is referred to as a condition, and two conditions joined by an operator, ie. `condition, operator, condition` is referred to as a compound condition.

LOOT caches the results of condition evaluations, so performance is not really an issue. A regular expression check will still take longer than a file check though, so use the former only when appropriate to do so.

### Functions

There are several conditions that can be tested for using the functions detailed in the table below.

Function | Syntax | Description
--- | --- | ---
File | `file("filepath")` | Returns true if filepath is installed, false otherwise.
File | `regex("regex")` | Returns true if a file matching regex is found, false otherwise.
Many | `many("regex")` | Returns true if more than one file matching regex is found, and false otherwise.
Checksum | `checksum("filepath", checksum)` | Returns true if the calculated checksum of filepath matches checksum, false otherwise. If filepath does not exist, returns false.
Version | `version("filepath", "version", comparator)` | Returns true if the boolean expression `(actual version of filepath) comparator version` holds true, false otherwise. If filepath does not exist and comparator is `==`, `>` or `>=`, returns false. If filepath does not exist and comparator is `!=`, `<` or `<=`, returns true. The comparison is not a straightforward per-character comparison, but instead uses the precedence rules defined by Semantic Versioning, extended to allow leading zeroes, an arbitrary number of release version numbers, case-insensitivity and a wider range of separator characters.
Plugin Active Status | `active("filepath")` | Returns true if filepath is a `.esp` or `.esm` file that is both installed and active, false otherwise.

The different types of variable used in the above functions are described in more detail below.

Variable Type | Description
--- | ---
`filepath` | A Windows file path, or `LOOT`, which references the LOOT executable being run.
`regex` | A regular expression string to match file paths to.
`checksum` | A string of hexadecimal digits representing an unsigned integer that is the data checksum of a file. LOOT displays the checksums of plugins in its user interface after running.
`version` | A string of characters representing the version of a plugin or executable. LOOT displays the versions of plugins in its user interface after running.
`comparator` | A comparison operator, ie. one of `==`, `!=`, `<`, `>`, `<=` or `>=`, meaning "is equal to", "is not equal to", "is less than", "is greater than", "is less than or equal to" and "is greater than or equal to" respectively.

### The Negator & Junctors

The negator, or logical negation operator, inverts the value of the function that follows it. Its inclusion is optional, and its syntax is simply:

    not

Below is a truth table for the negator.

Value of `function` | Value of `not function`
--- | ---
false | true
true | false

There are two supported junctors, the logical conjunction (logical and operator) and the logical disjunction (logical or operator), that operate on the expressions to their left and right.

Junctor | Syntax | Description
--- | --- | ---
Logical Conjunction | `and` | Both conditions must evaluate to true for the compound condition to evaluate to true. If not, the compound condition evaluates to false.
Logical Disjunction | `or` | One condition or both conditions must evaluate to true for the compound condition to evaluate to true. If neither condition is true, then the compound condition evaluates to false.

The following is a truth table for the junctors:

Value of `condition1` | Value of `condition2` | Value of `condition1 and condition2` | Value of `condition1 or condition2`
--- | --- | --- | ---
true | true | true | true
true | false | false | true
false | true | false | true
false | false | false | false

### Order Of Evaluation

When a condition string is evaluated, its constituent parts are evaluated according to the standard precedence rules of operator logic, ie.

1. Function
2. Negator
3. Logical and
4. Logical or

Below is a table that lists some combinations of conditions, showing for each the order of evaluation by explicit bracketing. To make it easier to read, the `negator function` pair is shortened to `C` after the first example.

String Structure | Evaluated As
--- | ---
`negator function` | `( negator ( function ) )`
`C and C` | `( C and C )`
`C or C` | `( C or C )`
`C and C and C` | `( ( C and C ) and C )`
`C or C or C` | `( ( C or C ) or C )`
`C and C or C` | `( ( C and C ) or C )`
`C or C and C` | `( C or ( C and C ) )`
`C and C and C and C` | `( ( ( C and C ) and C ) and C )`
`C and C and C or C` | `( ( ( C and C ) and C ) or C )`
`C and C or C and C` | `( ( C and C ) or ( C and C ) )`
`C and C or C or C` | `( ( ( C and C ) or C ) or C)`
`C or C or C or C` | `( ( ( C or C ) or C ) or C )`
`C or C or C and C` | `( ( C or C ) or ( C and C ) )`
`C or C and C or C` | `( ( C or ( C and C ) ) or C )`
`C or C and C and C` | `( C or ( ( C and C ) and C ) )`

You can also explicitly enclose any condition in brackets to override the evaluation order, eg. `C and ( C or C )` is evaluated as `C and ( C or C )`, in contrast to the unbracketed string above.

## Language Codes

LOOT supports the following languages and language codes:

Language | POSIX Code
--- | ---
Brazilian Portuguese | pt_BR
Chinese | zh_CN
Danish | da
English | en
Finnish | fi
French | fr
German | de
Korean | ko
Polish | pl
Russian | ru
Spanish | es

## Version History

Each version of LOOT has a corresponding version of the metadata format, and its version history is given below.

### 0.8

- Removed support for the `ver` key in location data structures.
- Added support for the `name` key in location data structures.
- Added support for the `many("regex")` condition function.
- Changed detection of regular expression plugin entries. Previously, a plugin entry was treated as having a regular expression filename if the filename ended with `\.esp` or `\.esp`. Now, a plugin entry is treated as having a regular expression filename if the filename contains one or more of `:\*?|`.
- The plugin data structure definition in this document was fixed so that it correctly gives the values of the `after`, `req`, `inc`, `tag`, `url` and `dirty` keys as sets, not lists.
- This document now defines the equality criteria for all of the metadata syntax's non-standard data structures.
- The algorithm used for version comparison has been changed to give better results for a wider variety of version strings.

### 0.7

- Changed support for Markdown formatting in messages. Previously, only URL hyperlinking was supported, and only for `file:`, `http:` and `https:` URLs using the `[label](url)` or `<url>` syntaxes. Now, the Marked library (v0.3) is used to provide support for most of GitHub Flavored Markdown, minus the GitHub-specific features (like @mentions, issue/repo linking and emoji).
- Added support for message string substitution keys, i.e. `sub`, in message data structures.
- Added support for YAML merge keys, i.e. `<<`.

### 0.6

No changes.

### 0.5

Initial release.

## License

This document is part of the LOOT documentation.
Copyright (C) 2012—2015 WrinklyNinja
See the file LOOT ReadMe.html for copying conditions.