The Unwritten Rules of .mes Files

Last time I went over dialog, I detailed how to edit index entries.

Upon review, I’ve found that there are some additional “unwritten rules” on how .mes dialog files in A Wonderful Life are structured.

Index Entries Aligned as Hex “Words”

After looking at the index values in any given .mes file, I began to notice a pattern.

Note every dialog index ends in a 0, 4, 8, or c

Every single message starts at a position ending in a multiple of 4 in hex (i.e. 0, 4, 8, c).

At first I thought this was a weird coincidence. However, upon review I’ve determined that this is not on accident.

Different Types of Hex Grouping

There are different ways of grouping hex values.

Bytes: A pair of hex values
Words: 2 bytes
Double Words: 4 bytes

Message #1 in badog.mes, illustrated as bytes, words, and double words

What this means for MES files

It seems that .mes files are read in memory as “double words”. This means that a new message needs to start at a double word position (i.e. a hex position multiple of 4).

Every message needs at least one “00” end-of-message {EOM} byte to tell the system that it’s the end of that message. Additional EOM bytes are then added to pad out the message so that the next message in the file is pushed to start at the next double-word position.

This explains why some messages seem to have only 1 {EOM} byte, while some messages can have up to 4 {EOM} bytes.

File Endings

The Double Words pattern above still didn’t explain why the last messages in each dialog file seemed to have a random number of EOM bytes.

After reviewing the file endings, I found that the last byte position in any .mes file was at the “f” position on an odd line.
i.e. 1f, 3f, 5f, 7f, 9f, bf, df, ff

The last bytes for carter.mes, badog.mes, and bahn.mes are all at an odd _f position

This means that each file is padded out with EOM bytes until they reach a valid ending position.

Why bother with any of this?

These groupings are both seemingly due to how the game stores dialog in memory.

If dialog files weren’t configured properly with these rules, there is potential for dialog to overflow into other areas of memory (or other areas of memory to overflow into allocated “dialog space”) and wreak havoc.

This was evidenced during a recent Twitch stream, in which the dialog for Muffy (muumuu.mes) was improperly configured.

In this case, the game would experience numerous glitches following any interaction with Muffy (e.g. random words/phrases showing up where they shouldn’t, freezing, crashes, etc.).

To prevent any of these types of issues, dialog files must follow the above positioning rules.

Endian Differences between the Gamecube and PS2

Upon review, it seems that the Gamecube primarily stores data using big-endian (a type of data encoding), whereas the PS2 primarily stores data as little-endian.

This means that some game data (e.g. dialogue files) might appear to have their data “flipped” when comparing the GCN and PS2 versions.

As an example, a section of data might be “cdc3b0b0” for a file in the PS2 version, but “b0b0c3cd” in the GCN version.

This means that certain files were re-encoded when the game was ported to the PS2 to avoid them from being read as corrupt.

Shoutout to Dahni in the Discord chat for making this discovery.

It’s unclear at this time exactly which files were re-encoded. It seems that dialogue files were altered at the very least, but this could extend to other file types (textures, models, etc).

With that said, I’ll be focusing exclusively on the GCN versions of the game files to prevent any confusion of endian encoding going forward.

Tutorial: Dialogue Part II – Simple AWL Dialogue Editing

Once you’ve been able to read some dialogue files, it’s time to start editing any sections you want to change.

Locating Phrases

In this example, I’m going to alter the word “husband” in a phrase said by Griffin.

First things first.  You’re going to open up your .mes file in a hex editor of your choice.  I prefer Hex Editor Neo on Windows, but any hex editor should do.

Once open, you’ll want to locate the phrase in the file.  The easiest way to do this is to copy the hex code displayed in Harrison’s tool, then search for it in your file.

Replacing Words

For simplicity, it’s best to replace words with alternatives that have an equal or lesser amount of characters.

In this case, we’ll replace “husband” (7 letters) with “wife” (4 letters, 3 letters less than the original).  In this case we’ll need to add a few spaces onto the end of the line.  Spaces are encoded as “02″ in hex.  Since they only take up 1 hex slot as opposed to 2 (which most letters do), we’ll need to double the amount of needed spaces to 6 to make up for 3 missing letters.  So we’ll replace “a great husband for” with  “a great wife for      ”.  In the end, your replacement phrase should be just as long in hex as your original.  This keeps us from needing to modify the list of indexes at the start of the file and possibly creating any bugs.

While we might need to modify the file at times where the new text is longer than the original, we won’t worry about it right now.

APL/AWL Dialogue Offsets

I’m almost done adjusting the message offsets for all of the edited AWL files.  I just have a couple I need to run another pass or two on.

I should be able to finish those off tonight and will begin working on the AnWL files tomorrow.

I’ve been using the github repo as a way to easily mass-compare all of the files from their source contents to the edited versions.  This has helped me to easily identify which files need offset fixes and which can be ignored.

Now that I’m more aware of how editing text affects the offsets, I should be able to adjust the offsets at the same time as I make any further changes in the future to avoid having to go through this again.

AWL Dialogue Edited

I’ve finally finished my edits to the AWL dialogue files.  Because the chapters are longer, there’s a significantly greater amount of text to go through.

My next step will be to fix offsets in the dialogue files.

As I had mentioned in earlier posts, replacing dialogue with other words of different lengths can cause the text to change since the offsets no longer match.

I’ve decided to create a [github repo] for tracking changes to the dialogue files so I can help pinpoint any areas that need offset adjustments.

This would also be easier than dumping the text files and uploading the contents individually to the blog.

Once I’ve fixed the offsets, I’ll make updated patches for each game and will upload them within the next week or two.

Updating MES Files

Now that I’ve found a bunch of dialogue that needs changing, I’ve started hex editing the MES files in question to adjust the specific messages.

So far, I’ve edited the following for AnWL:

  • [garfun.mes]
  • [godey.mes]
  • [gustafa.mes]
  • [gustafa_husband.mes]
  • [mash_husband.mes]
  • [muumuu.mes]
  • [other.mes]
  • [phrase.mes]
  • [rock.mes]
  • [rock_husband.mes]
  • [sepilia.mes]
  • [son.mes]
  • [son_baby.mes]
  • [son_diary.mes]
  • [son_other.mes]
  • [son_talk.mes]

I’ll be going through the AWL files (as well as some more AnWL edits) tomorrow,.

I’ve created a [directory] from which I will be linking to all of my dialogue file dumps.

I will upload new alpha patches shortly thereafter with just the dialogue edits (no texture/model replacement) so that users can test them and see if there are any lingering misgendered messages.

One main issue I’ve noticed with some of the dialogue, is that when I replace some text with text of different length (e.g. “she” [3 letters] with he [2 letters]), it seems to change the offset of any messages afterwards.  This is especially apparent with the rock_husband dialogue as some of the later messages are missing the first word or half-word.

AWL Dialogue Dumped, AnWL Dialogue Cipher Broken

The MES Editor is now at v0.2 [link] and now includes export features.

With this, I’ve been able to fully dump all of the dialogue from AWL. [link]

The dialogue files can be viewed for anyone interested. [link].

The only things that aren’t dumped from AWL are some kanji characters that haven’t been added to the tool yet. But this is being worked on.  I’ve been progressing through each of the characters from the font texture.

The red characters are those that I haven’t been able to identify.  If anyone knows what they are, please let me know so we can add them to the program.

I’ve just broken the AnWL hex cipher, so I should hopefully be able to coordinate with Harrison to create an alternate version of the Editor for AnWL MES files.

If you notice any dialogue lines in-game that need to be changed, please let me know so I can find and edit them.

I’ll start by looking for individual gender identifiers (he/she, husband/wife, boy/girl. mom/dad, etc) and will go from there.  But it will likely be a little slow without full context of the conversations.