Replies: 8 (Who?), Viewed: 7476 times.
Lab Assistant
Original Poster
#1 Old 16th Sep 2014 at 3:44 PM Last edited by justJones : 6th May 2018 at 11:24 PM.
Default How to decompile PYOs from mods and Sims 4 core content
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
- TheHologramMan's decompiler
- 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!
1 users say thanks for this. (Who?)
Advertisement
Lab Assistant
#2 Old 17th Sep 2014 at 11:47 PM
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.
Scholar
#3 Old 20th Sep 2014 at 4: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')
Lab Assistant
Original Poster
#4 Old 20th Sep 2014 at 10:22 AM
Quote:
Originally Posted by Morphar
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.
Test Subject
#5 Old 22nd Sep 2014 at 3: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
Lab Assistant
Original Poster
#6 Old 26th Sep 2014 at 11:21 PM
Quote:
Originally Posted by pcgeekri
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)
Test Subject
#7 Old 27th Sep 2014 at 7: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
Scholar
#8 Old 27th Sep 2014 at 8:12 AM
Quote:
Originally Posted by Gh0st_wires
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.
Test Subject
#9 Old 27th Sep 2014 at 7:15 PM
Quote:
Originally Posted by Morphar
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.
Back to top