# How do we convert a pex file to a psc file?

How do we convert a pex file to a psc file?

There used to be a file here that allegedly converted pex files to psc files, but it's no longer available, so I was wondering if there was a alternative GUI program that allows you to do this. I am trying to modify a pex file in a Skyrim mod.

You can use PapyrusAssembler.exe to decompile the .pex (which is a compiled Papyrus script) into something more human-readable:

PapyrusAssembler.exe <name of .pex without extension> -D


However the documentation notes that this output isn't the .psc file itself. You can also look for a .pex decompiler (or write one yourself). The Creation Kit documentation doesn't seem to detail the format of the .pex file, so unless you want to spend a lot of time reverse-engineering it you're probably better off finding a pre-written tool.

Searching the web for "Skyrim pex decompiler" yields a few results, including a link to this tool. These sorts of tools are usually never able to recover the original source code (since often, most of that information -- such as comments -- is lost when compiling). Poking around a little, it looks like they're useful for producing human-readable stuff but that stuff isn't necessarily human friendly and may not immediately be re-compilable as a new .pex without editing.

This one claims to be able to produce something that is round-trip capable, even if it isn't the original file.

If you're doing this to recover source code to scripts you've written, and subsequently lost, it won't get you all the way there (and next time, you may want to consider a backup solution).

If you're doing this to try to figure out how scripts you didn't write function, you may have better results trying to contact the author of the script and see if they can't just explain it to you. If they're not willing to do that, they may also not be okay with your decompiling their scripts.

• It creates a pexd file and not a psc file. Jun 1 '19 at 14:37
• Right; "pexd" and "psc" are just text files; as I noted it's usually quite hard to produce original source code for something compiled, because information is lost. While doing some follow-up research I found a second tool (now linked in the answer) that claims to produce output that is round-trip capable, you might try that one.
– user1430
Jun 1 '19 at 14:58