Skip to content
radj307 edited this page Aug 20, 2022 · 1 revision

Bethesda Engine Unit Converter Wiki

This information is current as of 5.0.0

Why this exists

While making Another Archery Tweak I noticed the lack of any utilities to convert between real-life units & the game engine's "Units", and decided to do something about it.

After a lot of searching due to Bethesda's questionable choice of calling their length measurement units "Units", I stumbled upon this helpful table on the creation kit wiki.

Detailed Usage Guide for Less-Experienced Terminal Users

To understand what is and isn't allowed on the commandline, you need to know how the program handles arguments.
Most of this information is transferable to any other CLI program, with some exceptions, such as terminology.

Terminology

  • Argument

    Strings of characters that appear after the executable name and are passed directly to the program.
    They are separated with spaces, and either single or double quotation marks can be used to pass multiple words as one argument.
    An argument may have one of 3 types, denoted by the number of prefix dashes.

  • Parameter

    Any Argument that does not have any dashes as a prefix.

  • Option

    This is a type of Argument that has a special meaning to the program, and is usually used to specify optional features or modes.
    Certain specific options may capture additional input in the form of the following Parameter, or by appending an equals sign.
    Example: ckconv --precision=8, and ckconv --precision 8 mean the same thing.
    Note: Appending input with =… does not work if the input contains a space, use ="…" instead.

  • Long-Form Option

    These are multiple-character Options that use 2 dashes as a prefix.
    Example: ckconv --no-color

  • Short-Form Option, or Flag

    These are single-character Options that use 1 dash as a prefix, and are usually used as an alias for a long-form option.
    Flags are unique in that they can be chained together using a single dash.
    Only the flag at the end of the chain may capture additional input.
    Example: ckconv -nq is the same as ckconv --no-color --quiet
    Note: The argument parser is smart enough to differentiate between negative numbers and flags.

Program Execution Order

  1. Argument Parsing
  2. Config Parsing & Handling
  3. Option Handling
  4. Unit Conversion from Parameters
  5. Unit Conversion from STDIN

Step 1: Argument Parsing

Arguments are parsed in-order before they are used in the program.
The steps below are repeated for each argument.

  1. Check the number of prefixed dashes - & assign the argument a type.
  2. If an equals sign appears in the argument, move the characters that appear after it (Excluding quotation marks) into the next argument's "position" in the list.
    Note: This is just a layman's explanation of how captures are handled, the input array is not actually reordered.
  3. Check if the argument appears on the hardcoded "capture whitelist"; If it does, capture the next argument in the list if any of the following are true: - The next argument was appended to this option with an = sign. - The next argument is a Parameter

Step 2: Config Parsing & Handling

Next, the program checks if the INI config was found. The INI must have the same filename as the executable, with a .ini extension, and must be located in the same directory as the executable.
Example: ckconv.exe looks for ckconv.ini in the same directory.

Step 3: Option Handling

Next, the argument list is checked for the following options:

  • -h | --help
  • -v | --version
    If one of the above options is detected, either the inline help display and/or the current version number will be displayed, then the program will exit. Otherwise, the program checks for other recognized options, such as --standard, --precision, etc.
    The order in which these options are handled is not listed here, as it may change between versions.
    Finally, the program checks for the --reset-ini (or --ini-reset) option, and if found, the current settings are written to the INI config file.

Step 4: Unit Conversion from Parameters

Exactly 3 arguments are required for each conversion operation, which allows multiple operations to be processed using context.
Each operation requires an input number & unit, and a target unit to convert to. Arguments can appear in one of 2 orders:

  • <INPUT_UNIT> <INPUT_VALUE> <OUTPUT_UNIT>
  • <INPUT_VALUE> <INPUT_UNIT> <OUTPUT_UNIT>

Step 5: Unit Conversion from STDIN

This only occurs when there is piped input available in the STDIN stream, and the syntax is identical to Step 4, newlines are ignored.
This includes using the vertical bar operator | with something like cat.
Example: cat myFile | ckconv