Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Lab Assistant
#26 Old 2nd Sep 2014 at 8:04 PM
Yo. so i am trying some cool python IDES just to check them out.

What i have noticed by far:

-Most of the game content related to python can be tweaked via the DATA files in the simulation package. I Suspect we can add new traits, careers, moodlets, etc just via DATA files.
-Other global values (Such as timescale ) are inside pyc files. And my goal to make a Time Slower mod is most likely going to be a Python mod
-I searched for "time" and "clock" and "datetime" and all sorts of related words in all the game packages and os far i found nothing relevant.

-I Tried to HexEdit date_and_time.pyo but i dont know which bytes corresponds to the global value "TICKS_PER_REAL_WORLD_SECOND = 1000"

some questions are starting to rise:
-Is it possible to import functions directly from .pyc\pyo's ?
-If i wanted to show a costum notification in the wall (just for testing purposes) whenever the game is loaded, where do i know which event handler i must use?

i am so used to C# and c++, i am still a bit clueless regarding this aspects of python, but i think i will get there fast enough.
Advertisement
Eminence Grise
#27 Old 2nd Sep 2014 at 8:25 PM
Quote: Originally posted by IceM
I Suspect we can add new traits, careers, moodlets, etc just via DATA files.


That much was confirmed by SimGuruModSquad on the official forums.
Lab Assistant
#28 Old 2nd Sep 2014 at 8:27 PM
Once we figure out what mechanism is used to load script files from the mods folder how things is best implemented can be determined. Python is very different and more flexible then C# and most importantly not typed, so you have to think differently. Do not try to use a hex editor, that is not the way to go. If you are unsure of how to attack the problem it might be best to wait for the moment, just until someone actually have loaded a script successfully (I would try to do this myself, but I sadly do not have access to the game until Thursday).
Test Subject
#29 Old 2nd Sep 2014 at 8:34 PM
You can totally import functions from base pyo files. You can also overwrite functions or wrap them easily.

I have yet to get anything loaded and run though. A simple script which opens a file and writes some text works fine standalone but not here. Either they disabled IO like they did in Sims3 or the code is not just run. Perhaps an __init__.py routine is needed.
Lab Assistant
#30 Old 2nd Sep 2014 at 8:41 PM
Quote: Originally posted by Fogity
Once we figure out what mechanism is used to load script files from the mods folder how things is best implemented can be determined. Python is very different and more flexible then C# and most importantly not typed, so you have to think differently. Do not try to use a hex editor, that is not the way to go. If you are unsure of how to attack the problem it might be best to wait for the moment, just until someone actually have loaded a script successfully (I would try to do this myself, but I sadly do not have access to the game until Thursday).


U can use a VPN connection from korea. it worked for me... its not illegal
Test Subject
#31 Old 3rd Sep 2014 at 4:48 AM
Heads up. Looks like the unpyc3.py script does not handle Function Signature Objects properly and I've only discovered that those are actually used everywhere that is probably interesting to modders that want to add commands.
Code:
@sims4.commands.Command('traits.remove_trait', command_type=sims4.commands.CommandType.Automation)
def remove_trait(trait_type, opt_sim=OptionalTargetParam, _connection=('trait_type', 'opt_sim')):
    sim = get_optional_target(opt_sim, _connection)

Might compile but its totally wrong in python 3 syntax according to PEP 362 -- Function Signature Object and adding something similar will not work in the game. Of course I've yet to get anything acknowledge in game other than my zip file is indeed in the Mods folder. Unfortunately how this is supposed to work is currently beyond my skill. Looks like I'm not done with this script afterall.
Test Subject
#32 Old 3rd Sep 2014 at 5:02 AM
Quote: Originally posted by TheHologramMan
You can totally import functions from base pyo files. You can also overwrite functions or wrap them easily.

I have yet to get anything loaded and run though. A simple script which opens a file and writes some text works fine standalone but not here. Either they disabled IO like they did in Sims3 or the code is not just run. Perhaps an __init__.py routine is needed.



Like most things Python you need to include an __init__.py file.

Edit: I also believe like in TS3 when you modded, you have to include the compiled python module that you are referencing in your zip file, correct me again if I am wrong. But in TS3 for core mods you had to include the recompiled TS3 dll file.
Test Subject
#33 Old 3rd Sep 2014 at 5:11 AM
From what I've learned decompiling a Python 2 game, the Python 'decompilers' are never 100% accurate. You want to run through your decompiler to do most of the work, and then correct any files that don't generate identical bytecode... and from experience that's going to be a lot.
Test Subject
#34 Old 3rd Sep 2014 at 5:27 AM
Quote: Originally posted by Hawkheart
From what I've learned decompiling a Python 2 game, the Python 'decompilers' are never 100% accurate. You want to run through your decompiler to do most of the work, and then correct any files that don't generate identical bytecode... and from experience that's going to be a lot.


That decompiler also doesn't touch some of the files as well, it errors on them, like in simulation.zip objects\ theres a pools.pyo that it refuses to decompile.
Test Subject
#35 Old 3rd Sep 2014 at 6:58 AM
I've uploaded a new version which fixes Tuples and function signatures that I had problems with previously so the example above works now and looks like:
Code:
@sims4.commands.Command('traits.remove_trait', command_type=sims4.commands.CommandType.Automation)
def remove_trait(trait_type, opt_sim:OptionalTargetParam=None, _connection=None):
    sim = get_optional_target(opt_sim, _connection)


I'm still seeing some errors in while loop generation like in simulation/distributor/system.py but its looking much better with every edit. I've tried the __init__.py file and still dont get much action. How is anyone testing code changes at the moment? By overriding or adding new functionality? Is there a way to turn on logging?

I also cannot find a pools.pyo in my zip file. Did you get it from somewhere else?
Test Subject
#36 Old 3rd Sep 2014 at 6:59 AM
Quote: Originally posted by TheHologramMan
I've uploaded a new version which fixes Tuples and function signatures that I had problems with previously so the example above works now and looks like:
Code:
@sims4.commands.Command('traits.remove_trait', command_type=sims4.commands.CommandType.Automation)
def remove_trait(trait_type, opt_sim:OptionalTargetParam=None, _connection=None):
    sim = get_optional_target(opt_sim, _connection)


I'm still seeing some errors in while loop generation like in simulation/distributor/system.py but its looking much better with every edit. I've tried the __init__.py file and still dont get much action. How is anyone testing code changes at the moment? By overriding or adding new functionality? Is there a way to turn on logging?


No Idea, I've just spent the last 5 hours making a front end batch file for your decompiler Edit: I hate windows Batch files now thank you.
Test Subject
#37 Old 3rd Sep 2014 at 7:03 AM
Quote: Originally posted by darkkitten30
No Idea, I've just spent the last 5 hours making a front end batch file for your decompiler

If I may ask. Why? I just use a bat file that looks like:
Quote: Originally posted by rebuild.bat
@echo off
for /f "usebackq delims=|" %%i in (`dir /b /s *.pyo`) do call unpyc3.bat "%%~dpni.pyo" > "%%~dpni.py" 2> "%%~dpni.err"
for /f "usebackq delims=|" %%i in (`dir /b /s *.err`) do if %%~zi == 0 del /q "%%i"

Where unpyc3.bat is:
Code:
@c:\Python33\python.exe D:\Development\Projects\unpyc3\unpyc3.py %*

Creates all of the files including stderr and then removes all of the empty err files. Of course paths may be changed to match each persons environment.
Test Subject
#38 Old 3rd Sep 2014 at 7:06 AM
Quote:
Originally Posted by darkkitten30
No Idea, I've just spent the last 5 hours making a front end batch file for your decompiler

If I may ask. Why? I just use a bat file that looks like:
Quote:
Originally Posted by rebuild.bat
@echo off
for /f "usebackq delims=|" %%i in (`dir /b /s *.pyo`) do call unpyc3.bat "%%~dpni.pyo" > "%%~dpni.py" 2> "%%~dpni.err"
for /f "usebackq delims=|" %%i in (`dir /b /s *.err`) do if %%~zi == 0 del /q "%%i"


Creates all of the files including stderr and then removes all of the empty err files.


Because every time I tried to use it before, it just output to the console, and then I Was like ugh, and whatever and just started writing it.
Edit: Note that I'm also a woman and I reserve the right to do things the hard way :P
Edit Edit: However I wanted to say Thank you for modding this thing to work
Test Subject
#39 Old 4th Sep 2014 at 2:17 AM
Script doesn't work on Python 3.3.5:

File "C:\Python33\Tools\Scripts\unpyc3.py", line 1654
func, name, *parents = posargs
^
SyntaxError: invalid syntax
Test Subject
#40 Old 4th Sep 2014 at 3:11 AM
It works on this version is about all I can say:
Code:
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
That happens to be the version I have on my machine. Pretty sure that is code I never touched in any case. I'm surprised python broken in point release though.
Test Subject
#41 Old 4th Sep 2014 at 9:36 AM
Quote: Originally posted by nonono1989
Script doesn't work on Python 3.3.5:

File "C:\Python33\Tools\Scripts\unpyc3.py", line 1654
func, name, *parents = posargs
^
SyntaxError: invalid syntax


I have 3.3.5 and it works fine for me.
Test Subject
#42 Old 4th Sep 2014 at 10:48 AM
Can you upload your script file? maybe mine is broken.



EDIT: same on python 3.3. I downloaded your script from https://raw.githubusercontent.com/f...aster/unpyc3.py
Lab Assistant
#43 Old 4th Sep 2014 at 11:35 AM
Quote: Originally posted by nonono1989
Can you upload your script file? maybe mine is broken.



EDIT: same on python 3.3. I downloaded your script from https://raw.githubusercontent.com/f...aster/unpyc3.py


Is this your first time using python? I'm just wondering if you have it all configured correctly. path variables set and so on. This page has more details:

https://docs.python.org/3.3/using/windows.html
Test Subject
#44 Old 4th Sep 2014 at 3:26 PM
Yeah, everything is set up correctly.
Test Subject
#45 Old 4th Sep 2014 at 4:56 PM
I'm getting the same error as nonono1989. I've tried it on both the latest version, 3.4.1, and rolled back to 3.3.3, but still got the error. PATH variables are setup properly
Test Subject
#46 Old 4th Sep 2014 at 5:38 PM
For the awesome people attempting to convert the .pyo files to .py files. I have maybe a suggestion or maybe just and idea. in the core .zip folder it has a section in it for Google\proto.
So i did some looking and the folder structure in the core.zip folder looks just like the proto compiler or protoc setup folder. It also has a decoder and encoder .pyo files as well as a discripter.pyo.
it also seems to give us an api as well in looking at it. just wondering if maybe it's a hidden tool that we may have to compiler to use.

I'm not good with code or i'd attempt it myself put maybe you could check it out and see what you think. I might attempt it myself but it will take a long time.
Test Subject
#47 Old 4th Sep 2014 at 7:56 PM Last edited by tycox94 : 4th Sep 2014 at 8:15 PM.
Why is it not possible to paste unpyc3.py into "C:\Python33\Lib" and it run the script?

This is the error I'm receiving:
Code:
C:\temp\lib>unpyc3.py __phello__.foo.pyo  1>__phello__.foo.pyo.py
'unpyc3.py' is not recognized as an internal or external command,
operable program or batch file.


Btw: never used python before.

EDIT: Doesn't look like it is even casheing the file either so how do I implement this script?

EDIT 2: Okay so I set a path to the python file under %pythonLib%. Then I tried running it like this but I'm sure it is the wrong way of doing this.
Code:
@for /f %%f  in ('dir /b %TEMPDIR%\lib\*.pyo') do %PythonPath%\unpyc3.py %%f > %%f.py


EDIT 3: Now I see what the code is doing. Sorry guys.
Test Subject
#48 Old 4th Sep 2014 at 8:15 PM
Quote: Originally posted by gizmozow
I'm getting the same error as nonono1989. I've tried it on both the latest version, 3.4.1, and rolled back to 3.3.3, but still got the error. PATH variables are setup properly


I found that python 2.7 was running instead, so I moved the executable for 2.7 and tried again. At that point, I realized that it was now defaulting to 3.4, even when the path value was pointing to 3.3. So I moved the executables for 3.4, ran the script again, and everything worked.
Test Subject
#49 Old 4th Sep 2014 at 8:58 PM
Quote: Originally posted by Wolfman2020
For the awesome people attempting to convert the .pyo files to .py files. I have maybe a suggestion or maybe just and idea. in the core .zip folder it has a section in it for Google\proto.
So i did some looking and the folder structure in the core.zip folder looks just like the proto compiler or protoc setup folder. It also has a decoder and encoder .pyo files as well as a discripter.pyo.
it also seems to give us an api as well in looking at it. just wondering if maybe it's a hidden tool that we may have to compiler to use.

I'm not good with code or i'd attempt it myself put maybe you could check it out and see what you think. I might attempt it myself but it will take a long time.


Don't bother with the content of those directories, it's simply google's protocol buffers python library: https://developers.google.com/protocol-buffers/

The fact that they use that is good news though, because it means that probably a lot (maybe all, if we're lucky) binary data format used by the game can be easily reverse engineered.

The interesting part is what's in Game/Bin/Python/generated.zip. It contains the generated python protocol buffer classes that sims 4 uses. It is probably possible to reconstruct .proto files from that, which would then allow to serialize/deserialize any data that sims 4 stores using protocol buffers into something easy to manipulate. From what I've seen, it' seems to be used at least for game saves. But maybe it's also used for various binary data format in package files.
Test Subject
#50 Old 4th Sep 2014 at 9:41 PM Last edited by gizmozow : 6th Sep 2014 at 7:05 PM. Reason: renamed scripts
I ended up running unpyc3.py from my Ubuntu VM, and everything decompiled properly.

I've attached the decompiled files for anybody else having trouble.

Here's a MEGA backup as well

EDIT: I've renamed the files, so they do not contain the extra ".pyo"
Attached files:
File Type: zip  DecompiledTS4Scripts.zip (2.65 MB, 1834 downloads) - View custom content
Page 2 of 3
Back to top