Mods are plaintext inside zip files, you're welcome to go take a look at how I did it. I like to think I organised and commented it sensibly.
It's probably a bit complex for a comment (and I actually can't remember the algorithm names), but the basic concept is a simple big maze of complex little mazes.