PDA

View Full Version : Python decompiler batch file


darkkitten30
3rd Sep 2014, 5:10 AM
Old Information:

I created a batch file using the modified version of TheHologramMan's unpyc3.py which you can get in this post (http://modthesims.info/showthread.php?t=532279)
Make sure you have Python 3.3.5 installed <Correct me if that's the wrong version, but it for the most part worked>
Make sure you click Add Python to Path and then copy unpyc3.py to your Python root folder

download the compressed file, use 7zip to decompress it and run Decompile.bat :) simple as that.



I've completely cleaned up the script, removed the unpyc3.py requirement, added a check for Python if you don't have the right python version installed the script will tell you and stop working.

You will need 7zip still and a copy of Python 3.6.1 (https://www.python.org/downloads/release/python-361/)
It will download everything else you need by itself once those are set up properly

Please download v7.3.

I've also removed the straight through the whole thing version, you will have to press enter between zip files.

v7.3 was delayed slightly due to some technical difficulties with uncompyle6 and my batch coding skills, thank the stars for coffee and google.

TODO:


Make it only decompile .pyo files instead of every file in the directory. Found how on google.
Fix why it wont copy achivements and aspirations folders into the zip and delete them from the temp folder. Spelling errors suck huh?
Add a Python download and install feature if it doesn't already exist.
Figure out how to make uncompyle6 uncompile all the files properly as it fails on a handful of pyo files.




HowTo:

Edit the bat file changing the Directories, Where your Sims4 is, your preferred Zip program, and where you want to save the Temp files
It's pretty straight forward. I recommend 7zip since the compression commands for the saved zip files were made using 7zip.
Example


@set SIMS4DIR="D:\Origin Games\The Sims 4"
@set TEMPDIR="C:\temp"
@set ZIPPROGRAM="C:\Program Files\7-Zip\7z.exe"



Changes:

Edit!
TheHologramMan's unpyc3.py is a work in progress be forewarned.

Edit
Bug fix, please download v2 and see attachement's description for what was fixed.

Edit
Bug fix, please download v3 and see attachement's decription for what was fixed. Sorry guys, Writing large Bat files you tend to forget things *Sighs*

Edit
Last bug fix, if it's broken *Sighs*
Please download v4 and see attachement's decription for what was fixed.

Edit
Please Download v5 and see attachement's decription for whats changed.

Edit
Please Download v6 and see attachment's description for what's changed.

Edit
v7.1 Fixes a small bug it seems in the compression of simulation-src.zip

Edit
v7.2 Fixes the fix in v7.1 becuase I broke it yet again lol never edit batch files at 4am.

Edit
v7.3 Fixed the broken stuff in v7.2 and readded removal of pyo files, I also cleaned the code up a bit more, added a couple folders I had forgotten, hopefully now I can get to my small todo list soon :)

weeruz
3rd Sep 2014, 12:25 PM
Just a heads up.
My Sims installation and my tempdir is located at D:
So I needed to add @D: before the fun stuff happened, just so my command prompt changed working drive. Works fine after I added that just after setdirs.
The problem was with the extraction process, and I guess later with decompiling as my cmd was still at c:
Don't know if all cmd prompts works like that, I'm on Windows 7.

Thanks for great work anyway!! :)

Edit: Removed the pauses to, felt a bit to much manual work with me pressing a key every now and then. :p

kikiwalu
5th Sep 2014, 3:09 PM
Awesome! :up: But I think ur bat missed decompile some files under the subfolders, like /interaction/social etc. :rolleyes:

darkkitten30
6th Sep 2014, 2:23 AM
Awesome! :up: But I think ur bat missed decompile some files under the subfolders, like /interaction/social etc. :rolleyes:

Oh I'll look into it sorry :)

SpaceTimeDream
11th Sep 2014, 9:04 PM
I followed the steps and I got the files but all of decompiled files are blanks 0kb in size. What am I doing wrong?

Toocanzs
11th Sep 2014, 11:24 PM
I followed the steps and I got the files but all of recompiled files are blanks 0kb in size. What am I doing wrong? Same thing here.

Risuun
12th Sep 2014, 3:51 AM
I got the 0kb as well, but ran the batch with pauses and it doesn't know where the unpyc3.py file is.

I know that the instructions say, "Make sure you click Add Python to Path and then copy unpyc3.py to your Python root folder" but HOW do we do that?

pcgeekri
12th Sep 2014, 2:39 PM
Hopefully this will help you, read the instructions here:
http://www.modthesims.info/showthread.php?t=533907

If you left click on the "unpyc3.py" your browser will open it and you see text so instead right click on it and "Save Target As" and leave the filename as "unpyc3.py".

Darkkitten30 *hugz* above mentioned her (I'm guessing a her, oops) installs were on the "D" drive. Fortunately so are mine.
Probably a good idea to install Python on the same drive as "The Sims 4". Python was installed in the D:\Python33 folder. During the installation just changed the "C" to a "D". This is the folder where the unpyc3.py file was placed, in that same D:\Python33 folder with the Python executable.

The Batch File must be placed in the root directory of where your game resides. Fortunately Both Python and Sims 4 are both installed on the "D" drive so the batch file was placed in the root directory of my "D" drive or in D:\ . And ran or double-clicked at that location.

Hopefully this helps you.

PcGeek

omg, that avatar is still on my account? Haven't seen that in years! lmao Member since 2005, my how time flies.

darkkitten30
13th Sep 2014, 7:03 AM
Hopefully this will help you, read the instructions here:
http://www.modthesims.info/showthread.php?t=533907

If you left click on the "unpyc3.py" your browser will open it and you see text so instead right click on it and "Save Target As" and leave the filename as "unpyc3.py".

Darkkitten30 *hugz* above mentioned her (I'm guessing a her, oops) installs were on the "D" drive. Fortunately so are mine.
Probably a good idea to install Python on the same drive as "The Sims 4". Python was installed in the D:\Python33 folder. During the installation just changed the "C" to a "D". This is the folder where the unpyc3.py file was placed, in that same D:\Python33 folder with the Python executable.

The Batch File must be placed in the root directory of where your game resides. Fortunately Both Python and Sims 4 are both installed on the "D" drive so the batch file was placed in the root directory of my "D" drive or in D:\ . And ran or double-clicked at that location.

Hopefully this helps you.

PcGeek

omg, that avatar is still on my account? Haven't seen that in years! lmao Member since 2005, my how time flies.

Yes her. Yeah, I do all my development work on my D: drive. it keeps things clean for me since my C: drive is a SSD and I use it mostly for windows only.
Thank you for helping :)

Morphar
13th Sep 2014, 9:49 AM
@rem Batch file created by Darkkitten on 9/2/2014 at 9pm PST

At line 26 I think you have a discrepancy. You have not created a lib directory yet

@echo Moving to %TEMPDIR%\lib
@cd %TEMPDIR%\lib

You have done a cd to %TEMPDIR% so you need to do this:

@mkdir lib
@echo Moving to %TEMPDIR%\lib
@cd %TEMPDIR%\lib


Edit:
Oh I see now. The lib directory is in the compressed file %SIMS4DIR%\Data\Simulation\Gameplay\base.zip and when you uncompress it lib will turn up..

Edit 2:

OK, now I got it right. I had problem with the pathes. Here is my settings for a "normal" installation of the game (in C:\).
@echo Setting Directories...
@set SIMS4DIR="C:\Program Files (x86)\Origin Games\The Sims 4"
@set TEMPDIR="C:\temp"
@set ZIPPROGRAM="C:\Program Files\7-Zip\7z.exe"

Emty .py files though.


Edit3

This does not work. It says unpyc3.py is not a command or program.
@for /f %%f in ('dir /b %TEMPDIR%\lib\collections\*.pyo') do unpyc3.py %%f > %%f.py

ashjack0
13th Sep 2014, 10:04 AM
All the python files are empty for me. Why is this and how can I fix it?

darkkitten30
13th Sep 2014, 6:26 PM
You need to grab unpyc3.py, I've left a link for it in the main post. Your best bet is to save the file in your python directory where the python.exe is.

jtravers88
16th Sep 2014, 4:07 PM
Make sure you use the same drive for extraction as the drive you execute the bat file from, otherwise a simple cd %tempdir% doesn't work and everything fails after that command.

For instance, I have the bat file on e and my tempdir on e but I rightclicked the bat file to run it rather than run from a command prompt. So I'm on c, not e, and change dir commands don't work unless a drive change is made first.

Morphar
20th Sep 2014, 8:12 AM
Problem solved:
For us deadly people that have The Sims 4 installed on our only disc C:\ the script is not working.

I guess it is Microsoft that likes to protect us from evil things. Here is what I did:

1. The script could net create this:
@set TEMPDIR="C:\temp"
@mkdir %TEMPDIR%
Something is protecting C:\.

I manually created a map called TS4 and changed that line to:
@set TEMPDIR="C:\TS4\pytemp".
OK. Now the script copied all files to the pytemp directory.

2. The unpyc3.py did not execute. Reported that it was not an internal or external command.....
I opened the command tool and run unpyc3.py. Same problem. Typed the command set and discovered that the path to python33 was missing. I set it manually with the command:
set path=%path%;C:\python33.
Now I could run unpyc3.py
Tried the script again but still the same problem. Got frustrated and put this in the script after the copy line.:

@echo Set ENV-variable for Python
@set path=%path%;C:\python33

It worked!!!!!

I have now the files here:
C:\TS4\MTS_darkkitten30_1456480_Decompilev6\Decompile.bat
C:\Python33\unpyc3.py
C:\TS4\pytemp (The resulting .zip files)

Learn Python:
https://docs.python.org/3/tutorial/index.html

Morphar
20th Sep 2014, 8:35 AM
Sorry, little too early to report that it worked. I checked only the size of the -py files and it was not 0 kB now but all was 1 kB and contains this informatic text:

USAGE: C:\python33\unpyc3.py <filename.pyc>

I give up on this script for now. Tried this pyDecompile instead with success:

http://modthesims.info/showthread.php?t=534660

Unzip it anyware and move the zip files from:
C:\Program Files (x86)\Origin Games\The Sims 4\Data\Simulation\Gameplay
to that folder and start pyDecompileVer1.5.5 - firstRelease.py.

Lots of .py files in different sizes.

loveme19
26th Jan 2015, 2:01 AM
@rem Batch file created by Darkkitten on 9/2/2014 at 9pm PST

At line 26 I think you have a discrepancy. You have not created a lib directory yet

@echo Moving to %TEMPDIR%\lib
@cd %TEMPDIR%\lib

You have done a cd to %TEMPDIR% so you need to do this:

@mkdir lib
@echo Moving to %TEMPDIR%\lib
@cd %TEMPDIR%\lib


Edit:
Oh I see now. The lib directory is in the compressed file %SIMS4DIR%\Data\Simulation\Gameplay\base.zip and when you uncompress it lib will turn up..

Edit 2:

OK, now I got it right. I had problem with the pathes. Here is my settings for a "normal" installation of the game (in C:\).
@echo Setting Directories...
@set SIMS4DIR="C:\Program Files (x86)\Origin Games\The Sims 4"
@set TEMPDIR="C:\temp"
@set ZIPPROGRAM="C:\Program Files\7-Zip\7z.exe"

Emty .py files though.


Edit3

This does not work. It says unpyc3.py is not a command or program.
@for /f %%f in ('dir /b %TEMPDIR%\lib\collections\*.pyo') do unpyc3.py %%f > %%f.py
I got this same error when i had me 7-zip dir set like yours. it should be C:\Program Files (x86)\7-Zip\7z.exe.

simsinmypocket
15th Apr 2015, 6:22 PM
Sorry, little too early to report that it worked. I checked only the size of the -py files and it was not 0 kB now but all was 1 kB and contains this informatic text:

USAGE: C:\python33\unpyc3.py <filename.pyc>

I give up on this script for now. Tried this pyDecompile instead with success:

http://modthesims.info/showthread.php?t=534660

Unzip it anyware and move the zip files from:
C:\Program Files (x86)\Origin Games\The Sims 4\Data\Simulation\Gameplay
to that folder and start pyDecompileVer1.5.5 - firstRelease.py.

Lots of .py files in different sizes.

Thanks! It helped in my case. :)

scumbumbo
20th Apr 2015, 9:09 AM
Has anyone been able to decompile the core\sims4\tuning\tunable.pyo script from the latest patches? I'm working on using a sim picker from a script and everything seems to be working well except for setting the maximum number of sims which can be selected on the picker. The parameters for that are stored in an ImmutableSlots class. There's a make_immutable_slots_class that I found, but the only place that seems to call it is tunable.pyo, so right now I'm kind of working in the dark trying to get that right.

If no one else can decompile it, I'll just have to keep plugging at it I guess - or I suppose worst case I can just ignore some sims if they pick more than the maximum, but that's hardly user friendly!

For what it's worth, here's the errors I get from unpyc3, not sure if anyone here is familiar with how it works internally or not...Proccessing tunable.pyo...
#ERROR: jaddr is None
Traceback (most recent call last):
File "pyDecompileVer1.5.6.py", line 33, in <module>
make_file.write(str(decompiled_data))
File "C:\Python33\unpyc3.py", line 1194, in __str__
self.display(istr)
File "C:\Python33\unpyc3.py", line 1200, in display
stmt.display(indent)
File "C:\Python33\unpyc3.py", line 1043, in display
self.display_undecorated(indent)
File "C:\Python33\unpyc3.py", line 1173, in display_undecorated
suite.display(indent + 1)
File "C:\Python33\unpyc3.py", line 1200, in display
stmt.display(indent)
File "C:\Python33\unpyc3.py", line 1043, in display
self.display_undecorated(indent)
File "C:\Python33\unpyc3.py", line 1067, in display_undecorated
self.code.get_suite().display(indent + 1)
File "C:\Python33\unpyc3.py", line 301, in get_suite
dec.run()
File "C:\Python33\unpyc3.py", line 1259, in run
new_addr = method(addr)
File "C:\Python33\unpyc3.py", line 1469, in POP_TOP
self.stack.pop().on_pop(self)
AttributeError: 'Unpack' object has no attribute 'on_pop'

Aren
21st Apr 2015, 7:18 AM
Has anyone been able to decompile the core\sims4\tuning\tunable.pyo script from the latest patches? I'm working on using a sim picker from a script and everything seems to be working well except for setting the maximum number of sims which can be selected on the picker. The parameters for that are stored in an ImmutableSlots class. There's a make_immutable_slots_class that I found, but the only place that seems to call it is tunable.pyo, so right now I'm kind of working in the dark trying to get that right.

If no one else can decompile it, I'll just have to keep plugging at it I guess - or I suppose worst case I can just ignore some sims if they pick more than the maximum, but that's hardly user friendly!

For what it's worth, here's the errors I get from unpyc3, not sure if anyone here is familiar with how it works internally or not...Proccessing tunable.pyo...
#ERROR: jaddr is None
Traceback (most recent call last):
File "pyDecompileVer1.5.6.py", line 33, in <module>
make_file.write(str(decompiled_data))
File "C:\Python33\unpyc3.py", line 1194, in __str__
self.display(istr)
File "C:\Python33\unpyc3.py", line 1200, in display
stmt.display(indent)
File "C:\Python33\unpyc3.py", line 1043, in display
self.display_undecorated(indent)
File "C:\Python33\unpyc3.py", line 1173, in display_undecorated
suite.display(indent + 1)
File "C:\Python33\unpyc3.py", line 1200, in display
stmt.display(indent)
File "C:\Python33\unpyc3.py", line 1043, in display
self.display_undecorated(indent)
File "C:\Python33\unpyc3.py", line 1067, in display_undecorated
self.code.get_suite().display(indent + 1)
File "C:\Python33\unpyc3.py", line 301, in get_suite
dec.run()
File "C:\Python33\unpyc3.py", line 1259, in run
new_addr = method(addr)
File "C:\Python33\unpyc3.py", line 1469, in POP_TOP
self.stack.pop().on_pop(self)
AttributeError: 'Unpack' object has no attribute 'on_pop'

I think I was able to extract most of it, except for the contents of one method (it's at line 1832). I wrapped the code for unpyc3's dec.run method in a try/except block so it skips over anything it can't parse. Better than nothing anyway. :)

I've attached a zip with the tunable.py and the updated unpyc3.py script.

scumbumbo
22nd Apr 2015, 8:06 AM
Better than nothing anyway. :)
A far, far better thing than nothing in this case! Solved my problem with getting the simpicker working via pure scripting by putting some logging into the TunableTuple class's __init__ to figure out the ImmutableSlots issue. I'll add the info to my thread about doing dialogs from scripts and hopefully this will end up in the door locks code. One problem down, several hurdles to go I'm sure, but progress is progress! :turtle:

Karthas077
7th May 2015, 4:32 AM
First of all I wanted to thank darkkitten30 for his efforts thus far, however when I tried using this batch file I ran into ALL sorts of errors, especially considering it hasn't been updated to handle the content added by the new expansion.

So I made a new batch file that handles new subdirectories being added and a bunch of other things.

Plus it's only 31 lines long!

Use as follows:
Extract to any folder.
Change the GAMEDIR, and ZIP parameters on the first 2 lines to reflect your installation paths and desired output.
Run the .bat

base.zip, core.zip, and simulation.zip files are created in the directory the batch was run in
These zips will contain any every .py script that successfully decompiled as well as any .pyo script that did NOT decompile.

DO NOT Run this file as an administrator for the following reasons:

You should generally not run potentially system modifying files like this as an administrator as a less honorable person than myself might be up to ALL kinds of nonsense.
Running a batch file as administrator changes the 'current directory' of execution to C:\Windows\System32\, which means that's where your files are going to end up.

No part of this copying, unzipping, decompiling, zipping, process should require administrator privileges anyways.

As usual, you may use whatever unpyc3.py you wish as long as it is in the system path and can be found and executed from the command line.
In theory, leaving the unpyc3.py file in the directory with the .bat will also work if you're having trouble.

If you run into strange problems because your directories are all full of SPACES, Put the directory near the root of a drive and run it there.

Vinathi
12th Jun 2015, 4:42 AM
This didn't work for me for the most recent patch, even after I followed the instructions. The python decompiler tool extracts the .py files into folders, but when I open the .py files they're totally empty.

Would anyone be willing to upload a .zip of the game's .py files or help me figure out what I'm doing wrong?

scumbumbo
12th Jun 2015, 6:47 AM
This didn't work for me for the most recent patch, even after I followed the instructions. The python decompiler tool extracts the .py files into folders, but when I open the .py files they're totally empty.
I don't use the batch file as I don't have 7-zip and didn't feel like rewriting it for winrar, but also as I prefer to do just one folder at a time so I can see any issues that happen -- but, afaik this one should work. Do you have the unpyc3.py script installed? There's a good copy Aren uploaded just a few posts up.

Vinathi
13th Jun 2015, 7:36 PM
I don't use the batch file as I don't have 7-zip and didn't feel like rewriting it for winrar, but also as I prefer to do just one folder at a time so I can see any issues that happen -- but, afaik this one should work. Do you have the unpyc3.py script installed? There's a good copy Aren uploaded just a few posts up.

Using Aren's unpyc3 in the same folder as Kartha's Decompile batch file worked flawlessly. Thank you.

arkeus17
5th Jul 2015, 6:52 AM
I used Aren 's unpyc3 along with Kartha 's Decompile batch file , and it did not work , the files are empty :(

LimpBiscuit
9th Feb 2016, 12:12 AM
Thanks A Lot!

DarkWalker
13th Feb 2016, 3:41 PM
I've build a Python script that does what the batch file does, but by finding the folders inside the game files instead of using a fixed list of them, so it should be future-proof. You need Python 3.3 for it to work, but since that is the same requirement as for unpyc3.py, I don't see any issues here. Just put Decompile_nodeps.py in the same folder as unpyc3.py, edit it to reflect where you have the game installed and where you want the extracted scripts to go, and run it.

I don't think I will be providing much support for it, but for what matters I'm releasing this script into public domain, so do whatever you want with it.

Edit: just found out that my batch errors out with the stock unpyc3.py; sorry for that. I am using Aren's tweaked unpyc3 (http://modthesims.info/showthread.php?p=4740694#post4740694), which is able to decompile a few files the stock one doesn't (including tunable.pyo). I recommend using that one, but in any case I've updated my batch so it can work with the stock unpyc3.py.

kk21
2nd Mar 2016, 8:52 PM
I'm trying to come up with a version of this for mac os, but I'm running into problems with the results of unpyc3. The gist of the process is 1. Copy base.zip core.zip simulation.zip into a temporary directory. 2. Navigate into that directory and unpack them. 3. Run the following:

for x in `find . | grep .pyo`; do python3 unpyc3.py $x > ${x/.pyo/.py}; rm $x; done

The problem is that, regardless of whether it was able to extract any code, every single file starts with *** Warning: file has wrong magic number *** . I'm not sure whether it's an indication that the process was unsuccessful, or an error I can simply remove.

Has this come up for Windows users as well?

EDIT:

If it really is safe just to comment this line out, the script to do it is:

for x in `find . | grep .pyo`; do python3 unpyc3.py $x | sed 's/\*\*\*/\#\*\*\*/' > ${x/.pyo/.py}; rm $x; done

All that does is changes the first instance of "***" to "#***", so that that line gets commented out. (It does this per line, so in my case there are exactly 14 instances where it matched on an additional line. All of them were print() statements, enclosed within strings, so at least for now, I'm not worrying about tweaking the regex to address this) That one line replaces the previous example, as the substitution happens before it writes the .py

kk21
3rd Mar 2016, 10:56 AM
I think, also, it's not succeeding in extracting code that it looks like other people have been able to get. In fact, I think only a small fraction of the .pyo files had any success. The error that seems to occur on most of the .pyo files is AttributeError: 'SuiteDecompiler' object has no attribute 'GET_YIELD_FROM_ITER'

Any thoughts would be most appreciated. If I can get this working, I'd be most happy to provide a shell script companion to this .bat file.

EDIT: I grabbed the aforementioned Aren's tweaked unpyc3 (http://modthesims.info/showthread.php?p=4740694#post4740694), linked to in the post above mine. *Significantly* better results, although the warning about the magic number is still there.

kk21
3rd Mar 2016, 1:40 PM
I've build a Python script that does what the batch file does, but by finding the folders inside the game files instead of using a fixed list of them, so it should be future-proof. You need Python 3.3 for it to work, but since that is the same requirement as for unpyc3.py, I don't see any issues here. Just put Decompile_nodeps.py in the same folder as unpyc3.py, edit it to reflect where you have the game installed and where you want the extracted scripts to go, and run it.

I don't think I will be providing much support for it, but for what matters I'm releasing this script into public domain, so do whatever you want with it.

Edit: just found out that my batch errors out with the stock unpyc3.py; sorry for that. I am using Aren's tweaked unpyc3 (http://modthesims.info/showthread.php?p=4740694#post4740694), which is able to decompile a few files the stock one doesn't (including tunable.pyo). I recommend using that one, but in any case I've updated my batch so it can work with the stock unpyc3.py.

Very nice! I made a couple changes to the file to make it os-independent, and provide examples for both Mac and Windows. Thanks tons!

"""

Look through the following options, and uncomment (remove the # at the start of the line) one option each for folderGame and folderScripts.

If you are running Windows, and are happy with the options 'D:\\Origin\\Games\\The Sims 4' (folderGame) and 'x:\\Scripts\\' (folderScripts), you don't have to do anything else!

This script was provided by DarkWalker on ModTheSims http://modthesims.info/showpost.php?p=4971513&postcount=27

The only modifications I've made are the addition of Mac/os-independent examples, and changing foldersGameplay to be os-independent

Big thanks to DarkWalker for this script!

"""



#########

"""
folderGame -- Where The Sims 4 is installed on your system
"""

# Windows Defaults
folderGame = 'D:\\Origin\\Games\\The Sims 4'

# Mac Defaults -- Mac users: comment out the line above this (under Windows Defaults), and uncomment the line below
#folderGame = "/Applications/The Sims 4.app/Contents"


"""
folderScripts -- Where you want the decompiled scripts to reside
"""

# Windows Example
folderScripts = 'x:\\Scripts\\'

# Uncomment the following lines to have the extractor place the scripts in a folder "Scripts" beneath your home directory
#import os
#folderScripts = os.path.join(os.path.expanduser("~"),"Scripts")


# Uncomment the following lines to have the extractor place the scripts in a folder "Scripts" beneath your current directory
#import os
#folderScripts= os.path.join(os.getcwd(),"Scripts")


"""
Make sure you have only one line uncommented for each option (folderGame, folderScripts)
If you are using an option that uses os, such as os.path or os.getcwd(), make sure to uncomment `import os` *BEFORE* the line in question
You should not need to modify any of the lines following
"""

#########




import os, subprocess, zipfile, codecs, unpyc3

foldersGameplay = os.path.join(folderGame, 'Data','Simulation','Gameplay')

for i in ['base.zip', 'core.zip', 'simulation.zip']:
file = zipfile.ZipFile(os.path.join(foldersGameplay, i))
file.extractall(os.path.join(folderScripts, os.path.splitext(i)[0]))
# Walk down all script folders and decompile all script files
for root, subFolders, files in os.walk(folderScripts):
for file in [f for f in files if os.path.splitext(f)[1].lower() == '.pyo']:
pyoFile = os.path.join(root,file)
pyFile = os.path.splitext(pyoFile)[0]+'.py'
try:
with codecs.open(pyFile, 'w', encoding='UTF-8') as o:
o.write(str(unpyc3.decompile(pyoFile)))
os.remove(pyoFile)
except:
os.remove(pyFile)
print("Failed to decompile {}".format(pyoFile))

DarkWalker
4th Mar 2016, 12:52 AM
The problem is that, regardless of whether it was able to extract any code, every single file starts with *** Warning: file has wrong magic number *** . I'm not sure whether it's an indication that the process was unsuccessful, or an error I can simply remove.

Has this come up for Windows users as well?
The error you mentioned should happen if you use any version of python other than 3.3 to run unpyc3. And, if you didn't change to the correct python version, you should still be getting that error even when using something based on my script, only the error should be going to the console instead of the decompiled files.

Also, given the way unpyc3 works, running it under any other version of python is bound to cause issues. Which might explain why you were getting half-decompiled files.

kk21
4th Mar 2016, 3:52 PM
The error you mentioned should happen if you use any version of python other than 3.3 to run unpyc3. And, if you didn't change to the correct python version, you should still be getting that error even when using something based on my script, only the error should be going to the console instead of the decompiled files.

Also, given the way unpyc3 works, running it under any other version of python is bound to cause issues. Which might explain why you were getting half-decompiled files.

Well, I *thought* I had 3.3, but I had some difficulties w/homebrew and had to reinstall, and it looks like I only had 3.5

I managed to install 3.3 (homebrew no longer had the formula), and it was a serious pain, but success! However, now I'm on to a new hurdle: if I eg, try to import (as in the Absolute Beginners (http://modthesims.info/showthread.php?t=536436) tutorial) sims4.commands, I get the error, ImportError: No module named '_trace'

Has this come up for you?

(Thanks so much for the help!)

EDIT: I tried using placeholder files for the missing modules, to see what happened if it could get past that step, and it seems it then moves on to complaining about a syntax error in graph_algos.py, where it uses `break` outside of a loop

File "./graph_algos.py", line 50
break
^
SyntaxError: 'break' outside loop

Do you think the file incorrectly decompiled, or some other issue?

import collections
__all__ = ['strongly_connected_components', 'topological_sort']

def topological_sort(node_gen, parents_gen_fn):
sccs = strongly_connected_components(node_gen, parents_gen_fn)
result = []
for scc in sccs:
if len(scc) != 1:
raise ValueError('Graph has a strongly connected cycle ({})'.format(','.join([str(item) for item in scc])))
result.append(scc[0])
return result

def strongly_connected_components(node_gen, parents_gen_fn):
index = 0
indices = {}
lowlinks = {}
stack = []
stack_members = set()
nodes = set(node_gen)
sccs = []
for node in nodes:
while node not in indices:
index = _strongconnect(node, sccs, nodes, parents_gen_fn, indices, lowlinks, stack, stack_members, index)
return sccs

def _strongconnect(node, sccs, nodes, parents_gen_fn, indices, lowlinks, stack, stack_members, index):
indices[node] = index
lowlinks[node] = index
index += 1
stack.append(node)
stack_members.add(node)
parents = parents_gen_fn(node)
if parents is not None:
for parent in parents:
if parent not in nodes:
pass
if parent not in indices:
index = _strongconnect(parent, sccs, nodes, parents_gen_fn, indices, lowlinks, stack, stack_members, index)
lowlinks[node] = min(lowlinks[node], lowlinks[parent])
else:
while parent in stack_members:
lowlinks[node] = min(lowlinks[node], indices[parent])
if lowlinks[node] == indices[node]:
scc = []
sccs.append(scc)
v = stack.pop()
stack_members.remove(v)
scc.append(v)
if v is node:
break
continue
return index

DarkWalker
4th Mar 2016, 5:51 PM
Well, I *thought* I had 3.3, but I had some difficulties w/homebrew and had to reinstall, and it looks like I only had 3.5

I managed to install 3.3 (homebrew no longer had the formula), and it was a serious pain, but success!
Not completely sure about Mac, but on both Windows and Linux you can have multiple versions of Python installed, you just need to call the right version to use the decompiler (and to compile files for use in Sims 4).

However, now I'm on to a new hurdle: if I eg, try to import (as in the Absolute Beginners (http://modthesims.info/showthread.php?t=536436) tutorial) sims4.commands, I get the error, ImportError: No module named '_trace'

Has this come up for you?
What are you attempting to do, compile a file for use in Sims 4? It will give an error, but the compiled file (if using Python 3.3 to compile) should be perfectly usable. Something like "python -O -m <filename>.py" should generate the compiled .pyo files you need inside a __pycache__ folder, just remove the extraneous ".cpython-33" added to the filename and use them.

BTW, the decompiled files will likely have many errors. Nothing we can do about it, apart from being on the lookout for things like while loops used in place of if conditionals and other such issues.

kk21
4th Mar 2016, 8:01 PM
Not completely sure about Mac, but on both Windows and Linux you can have multiple versions of Python installed, you just need to call the right version to use the decompiler (and to compile files for use in Sims 4).

Yes, that's correct. The current Mac OS ships w I think 2.6 and 2.7. The package on the official python site for 3.3 is incompatible with OSX El Capitan (the current OS). Homebrew (http://brew.sh) offers a package manager, intended to mirror the functionality of apt-get on Ubuntu/Debian. Unfortunately, the only version available there was 3.5. With homebrew, you can also use your own 'formula', and I was able to find one for 3.3. (here) (https://gist.github.com/dnozay/231a037d53e14052ccd6) Someone repeating these steps may have problems if they had a different version of python3 which they'd then removed. One solution is to create a symbolic link to the version you have installed.



What are you attempting to do, compile a file for use in Sims 4? It will give an error, but the compiled file (if using Python 3.3 to compile) should be perfectly usable. Something like "python -O -m <filename>.py" should generate the compiled .pyo files you need inside a __pycache__ folder, just remove the extraneous ".cpython-33" added to the filename and use them.

BTW, the decompiled files will likely have many errors. Nothing we can do about it, apart from being on the lookout for things like while loops used in place of if conditionals and other such issues

I was trying to use IPython to interactively test and develop. As it is, it can't import the module, which makes it tricky to use it interactively :D In these situations, do you guys then just modify the source code of the modules you're using to make it work in its uncompiled form?

Thanks again!

DarkWalker
5th Mar 2016, 1:24 AM
I can't tell about others, but I use external tools to just guarantee that there is no syntax error and test things in game. Being able to reload scripts without restarting the game helps, of course (http://modthesims.info/showthread.php?t=534451).

darkkitten30
6th Jun 2017, 4:58 PM
Nobody has posted in awhile, I asked a mod about the rules on that, not got a reply yet, if I get yelled at *Shrugs*, Okay I accidentally posted a broken version of v7.3, for all of you who downloaded it, please re download it, as I re posted the fixed version. As always check the spoiler Changelog at the very bottom is the latest information on whats new, etc

VictorialaRidge
19th Jun 2017, 6:18 PM
Hopefully this will help you, read the instructions here:
http://www.modthesims.info/showthread.php?t=533907

If you left click on the "unpyc3.py" your browser will open it and you see text so instead right click on it and "Save Target As" and leave the filename as "unpyc3.py".

Darkkitten30 *hugz* above mentioned her (I'm guessing a her, oops) installs were on the "D" drive. Fortunately so are mine.
Probably a good idea to install Python on the same drive as "The Sims 4". Python was installed in the D:\Python33 folder. During the installation just changed the "C" to a "D". This is the folder where the unpyc3.py file was placed, in that same D:\Python33 folder with the Python executable.

The Batch File must be placed in the root directory of where your game resides. Fortunately Both Python and Sims 4 are both installed on the "D" drive so the batch file was placed in the root directory of my "D" drive or in D:\ . And ran or double-clicked at that location.

Hopefully this helps you.

PcGeek

omg, that avatar is still on my account? Haven't seen that in years! lmao Member since 2005, my how time flies.

I realize i sound dumb but at least i'm making an effort to learn.
"Batch file placed in root directory of where the game resides" Would that be under origingames/sims4/game/bin ect or origingames/sims4/data/simulation ect?
I know how to recolor and download mods, i'm really trying to learn how everything works so i can start modding. Baby steps love, so windows 10, origin game, how do i find the root directory you speak of? Teach me great master

oraclelunafaye
1st Sep 2018, 5:53 PM
Hi,

I know this thread is rather old, but I kept getting a python error "can't open file pip". So I updated the following lines, it works fine now. (Windows)
@echo you have the correct version of python. Checking if Uncompyle6 is installed..
@python -m pip install uncompyle6
@echo Check results ... press any key to continue
@pause

It's the -m that's important.
I hope this helps someone.

Luna

ZYZ1216
19th Oct 2018, 3:55 AM
Hi,

I know this thread is rather old, but I kept getting a python error "can't open file pip". So I updated the following lines, it works fine now. (Windows)
@echo you have the correct version of python. Checking if Uncompyle6 is installed..
@python -m pip install uncompyle6
@echo Check results ... press any key to continue
@pause

It's the -m that's important.
I hope this helps someone.

Luna

Hi I have struggled with the error for two days. I just tried your code and it is kind of working now, but as it showing in the image, the first one and last one are empty. ..