> For the complete documentation index, see [llms.txt](https://docs.shrinefox.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shrinefox.com/flowscript/atlusscriptcompiler/run-via-commandline/compile.md).

# Compile

As previously mentioned, [**AtlusScriptCompiler**](/flowscript/atlusscriptcompiler.md) can [**compile**](/flowscript/atlusscriptcompiler/run-via-commandline/compile.md) `.FLOW` and `.MSG` into `.BF` and `.BMD` respectively. Read the previous sections for more information.

## 1. Specifying the Input File

First, you must tell the program what file we're working with. \
For [compiling](/flowscript/atlusscriptcompiler/run-via-commandline/compile.md), this must be a `.FLOW` or `.MSG` file.

```
C:\Users\Username>"C:\Path\To\AtlusScriptCompiler.exe" "C:\Path\To\field.bf.flow"
```

{% hint style="info" %}
You can simply **drag** `AtlusScriptCompiler.exe` and then `field.bf.flow` **onto the command prompt window**. \
This will automatically wrap each paths in quotes, which keeps arguments separate in case your paths contain spaces.
{% endhint %}

## 2. Specify that you are Compiling

Now, let's tell the program what to do with that file. \
Add `-Compile`, separated by a space.

```
C:\Users\Username>"C:\Path\To\AtlusScriptCompiler.exe" "C:\Path\To\field.bf.flow" -Compile
```

## 2. Specifying the Library

A **Flowscript Library** instructs the compiler on function names and parameters.\
In order to work with the input file, you have to tell the compiler which Library to use with `-Library`.

```
C:\Users\Username>"C:\Path\To\AtlusScriptCompiler.exe" "C:\Path\To\field.bf.flow" -Compile -Library P5
```

### Included Libraries

|         Library Name | Usage                 |
| -------------------: | --------------------- |
| **DigitalDevilSaga** | `-Library`**`DDS`**   |
|         **Nocturne** | `-Library`**`SMT3`**  |
|         **Persona3** | `-Library`**`P3`**    |
|      **Persona3FES** | `-Library`**`P3FES`** |
| **Persona3Portable** | `-Library`**`P3P`**   |
|         **Persona4** | `-Library`**`P4`**    |
|   **Persona4Golden** | `-Library`**`P4G`**   |
|         **Persona5** | `-Library`**`P5`**    |
|    **Persona5Royal** | `-Library`**`P5R`**   |
|        **PersonaQ2** | `-Library`**`PQ2`**   |

{% hint style="warning" %}
&#x20;**Not all games** have libraries available. Knowledge of reverse engineering game executables is required to generate a library, as you'll have to find the offsets of function signatures yourself. A sample script for P3/P4 (PS2) can be seen [here](https://github.com/TGEnigma/Atlus-Script-Tools/blob/master/Scripts/ScriptInterpreterCOMMTableToJson_P3P4.py).
{% endhint %}

## 3. Specifying Output Format

You should also choose an **Output Type** with `-OutFormat`. \
This determine the version and endianness of the generated `BF` or `BMD`.

```
C:\Users\Username>"C:\Path\To\AtlusScriptCompiler.exe" "C:\Path\To\field.bf.flow" -Compile -Library P5 -OutFormat V3BE
```

### Output Types

|                                                              Output Type | Usage                  |
| -----------------------------------------------------------------------: | ---------------------- |
|                                 <p> Persona 5<br><strong>BF</strong></p> | `-OutFormat`**`V3BE`** |
|                           <p>Persona 5 (PS3)<br><strong>BMD</strong></p> | `-OutFormat`**`V1BE`** |
| <p>Persona 5 (PS4) &<br>Persona 3/4 (PS2)<br><strong>BF/BMD</strong></p> | `-OutFormat`**`V1`**   |

## 4. Specifying Encoding

An **Encoding** can be specified using `-Encoding`.\
It lets the compiler know what set of characters to use.

```
C:\Users\Username>"C:\Path\To\AtlusScriptCompiler.exe" "C:\Path\To\field.bf.flow" -Compile -Library P5 -OutFormat V3BE -Encoding P5
```

### Encodings

|                                                                     Game Name | Usage               |
| ----------------------------------------------------------------------------: | ------------------- |
|                                                                 **Persona 5** | `-Encoding`**`P5`** |
|                                                                 **Persona 4** | `-Encoding`**`P4`** |
|                                                           **Persona 3 (FES)** | `-Encoding`**`P3`** |
| <p><strong>PersonaQ(2)</strong> <br>or any game using <br>Shift-JIS/CP932</p> | `-Encoding`**`SJ`** |

## 5. Specifying the Output File

Finally, you can name the **Output File** using `-Out`.

```
C:\Users\Username>"C:\Path\To\AtlusScriptCompiler.exe" "C:\Path\To\field.bf.flow" -Compile -Library P5 -OutFormat V3BE -Encoding P5 -Out "C:\Path\To\field.bf"
```

{% hint style="info" %}
If `-Out` is **not specified,** it will default to the input filename and folder, but with the output filetype appended. In this case, that would be `C:\Path\To\field.bf.flow.bf`.
{% endhint %}

At this point, you can press **`Enter`**&#x74;o begin compiling. \
But, there are a few optional commands which might be useful to you.

## 6. Hooking

**Hooking** can be handy when you're compiling a `.FLOW` and only want to replace specific [**procedures**](/flowscript/flowscript/procedures.md) in an [**imported**](/flowscript/flowscript/importing.md) `.BF`.

{% hint style="info" %}
**AtlusScriptCompiler is not perfect**, so it doesn't hurt to be proactive.\
With hooks, we can avoid potential compiler issues when recompiling an entire `.BF` script.
{% endhint %}

Enable Hooking by adding the`-Hook` argument.

When [compiling](/flowscript/atlusscriptcompiler/run-via-commandline/compile.md) your `.FLOW` into `.BF`, this redirects existing [procedures](/flowscript/flowscript/procedures.md) in an [imported](/flowscript/flowscript/importing.md) `.BF` file to replacement [procedures](/flowscript/flowscript/procedures.md) with a matching names that end in **`_hook_()`**.&#x20;

{% hint style="success" %}
The original [procedure](/flowscript/flowscript/procedures.md) still exists and can be called by name in your `.FLOW` script,  since the original data is not overwritten when hooking a function.\
References to the original [procedure](/flowscript/flowscript/procedures.md) in the original `.BF` are simply redirected to your replacement.
{% endhint %}

```
C:\Users\Username>"C:\Path\To\AtlusScriptCompiler.exe" "C:\Path\To\field.bf.flow" -Compile -Library P5 -OutFormat V3BE -Encoding P5 -Out "C:\Path\To\field.bf" -Hook
```

### Setup

1. [**Decompile**](/flowscript/atlusscriptcompiler/run-via-commandline/decompile.md) the `.BF` that you're referencing in the `.FLOW` you're compiling.
2. **Open** the `.FLOW` and copy the procedure you want to edit.
3. **Paste** it into your `.FLOW` that references the `.BF`, and add **`_hook`** to the procedure name.
4. **Edit** the procedure however you'd like.
5. [Import](/flowscript/flowscript/importing.md) the original `.BF` file.
6. **Compile** your new `.FLOW`with the`-Hook` argument.

## Conclusion

Now that you know how to (de)compile with [AtlusScriptCompiler](/flowscript/atlusscriptcompiler.md), you're ready to read, edit, and create scripts. If you haven't already, read on to see how to use the [**GUI**](/flowscript/atlusscriptcompiler/run-via-gui.md) to make (de)compiling even easier:

{% content-ref url="/pages/-Mgwk7Vz9xhMzV3rmXc9" %}
[Run via GUI](/flowscript/atlusscriptcompiler/run-via-gui.md)
{% endcontent-ref %}
