PDA

View Full Version : How to decompile PYOs from mods and Sims 4 core content


mgomez
16th Sep 2014, 4:44 PM
I've had a few people ask me for the source code of my mods, and I figured it's time to write a little tutorial:

What you'll need:

- Python 3.3.5 (https://www.python.org/download/releases/3.3.5/)
- TheHologramMan's decompiler (https://raw.githubusercontent.com/figment/unpyc3/master/unpyc3.py)
- The source file (of course!)

How to decompile

- Once you've installed Python 3.3.5, put TheHologramMan's decompiler (unpyc3) into the main directory (C:\Python33 by default)
- Place the source file you'd like to decompile into your Python directory (it's easier that way)
- Open python.exe
- Type "from unpyc3 import decompile"
- Let's make a file now: f = open('blabla.py', 'w')
- Let's make a string with the decompiled source (replace "source.pyo" with the actual source file): output = str(decompile('source.pyo'))
- Now, let's write the string to the file: f.write(output)
- And now, let's close the file: f.close()

You should find the decompiled contents in your "blabla.py" file. I don't know about other mods, but this will definitely decompile any of my mods, and you're free to do this!

jtravers88
18th Sep 2014, 12:47 AM
I believe the source.py file you mention in your directions would be the source.pyo file.

Some (most) modders so far providing python mods include the py and pyo file in their zip file. If you want everyone to run through the decompile process if they want to see your changes, so be it.

Morphar
20th Sep 2014, 5:11 AM
You must tell that the file is to be open for writing like this:
- Let's make a file now: f = open('blabla.py', 'w')

mgomez
20th Sep 2014, 11:22 AM
You must tell that the file is to be open for writing like this:
- Let's make a file now: f = open('blabla.py', 'w')

Yeah, I was extremely sleepy when writing this. Thanks! Also, I've made it a policy to release mods from now on with the decompiled source code alongside the compiled PYOs. That makes things less complicated.

pcgeekri
22nd Sep 2014, 4:16 PM
Hey,

Tried following your instructions and all I ended up with is a folder called _pycache_ with a file unpyc3.cpython-33.pyc inside it. That file was created immediately after - Type "from unpyc3 import decompile". Doing the f= open('blabla.py', 'W') command gave an error that the "source file name I entered.py" file is undefined meaning Python can't find the file.

Doing the f.write(output) and f.close() gave an 'f" is not defined error.

What am I doing wrong?

Thanks.
Pcggeek

mgomez
27th Sep 2014, 12:21 AM
Hey,

Tried following your instructions and all I ended up with is a folder called _pycache_ with a file unpyc3.cpython-33.pyc inside it. That file was created immediately after - Type "from unpyc3 import decompile". Doing the f= open('blabla.py', 'W') command gave an error that the "source file name I entered.py" file is undefined meaning Python can't find the file.

Doing the f.write(output) and f.close() gave an 'f" is not defined error.

What am I doing wrong?

Thanks.
Pcggeek

Are you putting the source file in the Python33 folder? It needs to be in the same folder as Python.exe. (well, it doesn't have to be that way, but it's a lot less complicated like that)

Gh0st_wires
27th Sep 2014, 8:21 AM
So I wrote a script to compile all the pyo files in the same directory as my script but its not working. Don't know if anyone here is a programmer like me but heres my script if anyone want to take a look tell me what i doing wrong. http://pastebin.com/EEfRgDzX

Morphar
27th Sep 2014, 9:12 AM
So I wrote a script to compile all the pyo files in the same directory as my script but its not working. Don't know if anyone here is a programmer like me but heres my script if anyone want to take a look tell me what i doing wrong. http://pastebin.com/EEfRgDzX


Already invented in the latest version of this:
http://modthesims.info/showthread.php?t=534660

It can booth decompile and compile.

Gh0st_wires
27th Sep 2014, 8:15 PM
Already invented in the latest version of this:
http://modthesims.info/showthread.php?t=534660

It can booth decompile and compile.

sweet saves me the trouble of writing my own.