PDA

View Full Version : How to change the simulation clock speed by changing maxis scripts


jcgurango
7th Sep 2014, 3:24 PM
Hello everybody! This is going to be a quick tutorial on how to change the clock speed of the simulation by changing the built-in maxis scripts.

You will need...

Python v3.3.3 (https://www.python.org/download/releases/3.3.3/)
The Sims 4
A text editor (I use Notepad++ (http://notepad-plus-plus.org/), but you can use notepad or anything)
This (https://github.com/figment/unpyc3/raw/master/unpyc3.py) python script
A little bit of magic, and a drop of imagination


Installing & Configuring Python
Once you've downloaded the python release, the first step is to install it. For the purposes of this tutorial, I'm going to assume you've installed it to C:\Python33\. When it's completely installed, you should add an entry to your system's path variable. To do this, follow the steps below.

Open the start menu and search for the word "environment"
Click on "Edit environment variables for your account"
Under "System Variables," look for the entry named "Path"
Click it, then click on "Edit..."
It should look something like this: "C:\folder1\;C:\otherfolder\;C:\blabla;"
Just add another entry pointing to your installation directory. Once you've done that it should look something like "C:\folder1\;C:\otherfolder\;C:\blabla;C:\Python33\"
Click OK, then OK.

Now that your python environment is configured, we can begin with the decompiling.

Decompiling the Scripts
For this tutorial, I'm gonna create a folder called "TS4 modding". Copy the .zip files in the game's "Data\Simulation\Gameplay\" folder into your TS4 modding folder, and extract each of them into their own folders. You should now have three sub folders, one called "base," "core," and "simulation".

Next, you should place the unpyc3.py file into this TS4 modding folder. Create a .bat file too with the following contents:

@echo off
for /r %%i in (*) do unpyc3.py "%%i" > %%i.py


Now, run the .bat file. You'll see some errors, but that's okay. It may take a while depending on the speed of your computer, but it should proceed to decompile all of the .pyo files so that you can edit them later on. Once it's finished, you can move on to the next step.

Editing the Scripts
So, we want to change the simulation's clock speed. The script that controls this is called "clock.pyo". It's in the "simulation" folder. Open the newly created "clock.pyo.py" file in your text editor and move to line 265, where you'll find this code.

def _clock_speed_to_scale(self, clock_speed):
if clock_speed == ClockSpeedMode.PAUSED:
return self.PAUSED_SPEED_MULTIPLIER
if clock_speed == ClockSpeedMode.NORMAL:
return self.NORMAL_SPEED_MULTIPLIER
if clock_speed == ClockSpeedMode.SPEED2:
return speed_two_multiplier(self.clock_speed_multiplier_type)
if clock_speed == ClockSpeedMode.SPEED3:
if services.get_super_speed_three_service().super_speed_three_active:
return ClockSpeedMultipliers.super_speed_three_multiplier(self.clock_speed_multiplier_type)
return ClockSpeedMultipliers.speed_three_multiplier(self.clock_speed_multiplier_type)
if clock_speed == ClockSpeedMode.INTERACTION_STARTUP_SPEED:
return ClockSpeedMultipliers.get_interaction_startup_speed_multiplier()

I'm not going to go into detail as to what this does or what it changes, as it's pretty self evident. We want to change this so that it looks like this

def _clock_speed_to_scale(self, clock_speed):
if clock_speed == ClockSpeedMode.PAUSED:
return self.PAUSED_SPEED_MULTIPLIER
if clock_speed == ClockSpeedMode.NORMAL:
return self.NORMAL_SPEED_MULTIPLIER
if clock_speed == ClockSpeedMode.SPEED2:
return 5
if clock_speed == ClockSpeedMode.SPEED3:
return 10
if clock_speed == ClockSpeedMode.INTERACTION_STARTUP_SPEED:
return 20

Once you've done that, save the file. Now, we have to compile it and deploy it into the game.

Recompiling and Deploying the edit
Open up your command line (Windows Key + R and type in "cmd", or search for "cmd"), and type in
cd (path to your TS4 Modding directory)
This will change the directory before the > character to your TS4 modding directory. Now type in
cd simulation
and then
python -m py_compile "clock.pyo.py"
This will compile the script and place a sub-folder called "__pycache__" inside of the \simulation\ folder. Inside this folder is where you'll find the compiled script, named "clock.cpython-33.pyc". To actually deploy this into the game, open the game's simulation.zip file and delete the already existing "clock.pyo" file inside of it. Then, rename "clock.cpython-33.pyc" to just "clock.pyc", and copy this into the simulation.zip file. Now when you run the game, the 2 and 3 speeds will be much faster.

It should be easy enough to figure out where everything else is hiding in the scripts and edit them. You can also create entirely new scripts and put the compiled file into one of the .zip files. The game will still run them.

Happy scripting!

Kodek
7th Sep 2014, 5:15 PM
Hey jcgurango, thanks for tutorial, it will help a lot of people to understand how to decompile and compile python files.
If someone have empty files after decompilation, make sure you are using Python 3.3.3, newer versions may haves issues.

BTW, I recommend to use Shift+RMB in directory and open console instead of use 'cd' commands in console, it's a little bit quicker. :)

revistabr
7th Sep 2014, 6:10 PM
There is a problem on the speed change ...

There's something related with the clock-speed and the simulation speed sincronism..

If u're not using the default speeds ... then this sincronism keep getting far and far away.... and at some point .... the game goes crazy because of that ... which means that u get stucked on super-speed events (like work or sleeping)

If you don't change it by tunning (how it is supposed to be done) the math of the rates simulation/clock gets wrong resulting in this bug at some point....

I'm pretty sure its because of the sincronism... because when i've used the speed of 60... the bug happend REALLY fast... (the simulation on speed 60, after turning back to regular speed(1), caused the clock to go back half or or soo)...

Same thing happend to lower speeds ... but it took a few game days....

I'm looking for a way to avoid this bug ... but ... i'm not finding any...

Nemesis.
8th Sep 2014, 5:51 AM
I'm getting a "no such file or directory" error when I'm trying to recompile. What am I doing wrong?

decemberfriend
9th Sep 2014, 6:24 AM
I'm using python 3.3.3 and the decompiled files come up with "USAGE: C:\Users\bilba_000\Desktop\TS4 modding\unpyc3.py <filename.pyc>" in Word. Am I doing something wrong? I followed the instructions as much as I could. I've done this 10 times already...

Simser der Deutschen
9th Sep 2014, 2:30 PM
I've done and installed all like you've described it, but I got the error in the cmd "Access denied" and the created *.pyo.py files are empty. Nothing more happens.

Is it possible, that you upload the decompiled Python files? (Or is this not allowed because of copyright, I don't know?)

[Update 1]
I got it work, I don't know why. It creates .py files and the cmd prints no errors. But now, the content of every .py file is the same as for decemberfriend:
USAGE: C:\TS4 Modding\unpyc3.py <filename.pyc>
[Update 2]
Now I got all work! @ decemberfriend
I thought, that maybe another program cause complications. So I tried the same way in an clean install virtual Windows 8.1 and it worked. So all of you, who got some errors: Try to execute the de-/compilation on another pc or a virtual pc. (I use Hyper-V)

Simser der Deutschen
9th Sep 2014, 5:49 PM
Uihhh :rofl:
I found a cool folder in the decompiled python scripts:
http://thumbs2.modthesims2.com/img/8/1/0/9/3/1/5/MTS_SimserderDeutschen-1457631-Unbenannt.JPG
But it's an empty folder :/

Simsupermom
12th Sep 2014, 7:01 AM
followed up until I tried to click edit, it was gray, like it is refusing to allow?? Here is a screen shot.
.

UPDATE: So I had to go in another way, I had to
My Computer ‣ Properties ‣ Advanced ‣ Environment Variables
Then add the entry point! Not sure why but in case someone else is a newbie that was the issue. The other way just grays out the edit button. Back on track!
Hope I can do this! :)

Simser der Deutschen
12th Sep 2014, 7:34 AM
followed up until I tried to click edit, it was gray, like it is refusing to allow?? Here is a screen shot.

I think I know why it's grayed. It's because there are two environment variables menus:
The first can be edited without administrator rights, it's named "User Environment Variables" and it seems to be the same as your screenshot.
To open this one, you need to go to the Control Panel, "Useraccounts" and "Change own environment variables" (I'm from germany, the text may vary in english):
http://thumbs2.modthesims2.com/img/8/1/0/9/3/1/5/MTS_SimserderDeutschen-1458897-UserVariables.jpg

The second one is the "System Environment Variables" and needs administrator rights. They can be edited while going to the Control Panel, "System", "Advanced System Settings", "Environment Variables".
Now the "Edit" button is available.
http://thumbs2.modthesims2.com/img/8/1/0/9/3/1/5/MTS_SimserderDeutschen-1458896-SystemVariables.jpg

botaurus
20th Sep 2014, 9:16 PM
[Update 2]
Now I got all work! @ decemberfriend
I thought, that maybe another program cause complications. So I tried the same way in an clean install virtual Windows 8.1 and it worked. So all of you, who got some errors: Try to execute the de-/compilation on another pc or a virtual pc. (I use Hyper-V)

just add 'python' to the bat file to fix this. The bat file will now look like this:

@echo off
for /r %%i in (*) do python unpyc3.py "%%i" > %%i.py

Also, I was getting a syntax error for *parent on line 1654. Besides setting up your Path environment variable, make sure windows is associating the right python.exe with .py extensions (Mine was pointing to python 2.7)

AliXmAn
12th Apr 2015, 1:37 AM
I don't know why but the .pyo files compile to an empty .py file. What's wrong? I followed every step.

Thanks in advance.

Edit: I found the solution (http://modthesims.info/showthread.php?p=4511236#post4511236) .

simmythesim
17th Apr 2015, 4:51 AM
Putting the mod file into my game didn't work, if i loaded a lot it just bounced back to the world select.

splishs
18th May 2015, 2:27 AM
Putting the mod file into my game didn't work, if i loaded a lot it just bounced back to the world select. same thing happened to me. Hope to fix it somehow

scumbumbo
20th May 2015, 7:28 AM
This is not the best way to be doing this - far better to inject or override just the method you are changing and put it in the mods folder than to recompile the entire script with changes and put it into the game's zip files. It will just get deleted everytime the game is updated or repaired.

Also, @simmythesim - I thought you had these changes working for you with the XML tuning? That should be the safest and most EA-update-proof method of doing this?

simmythesim
20th May 2015, 8:56 AM
This is not the best way to be doing this - far better to inject or override just the method you are changing and put it in the mods folder than to recompile the entire script with changes and put it into the game's zip files. It will just get deleted everytime the game is updated or repaired.

Also, @simmythesim - I thought you had these changes working for you with the XML tuning? That should be the safest and most EA-update-proof method of doing this?
That was a LONG time ago a while before I made the other thread, unfortunately speeding up the time multipliers causes headaches for the game, and will cause time to desynchronise and move backward when you speed up.

scumbumbo
20th May 2015, 5:42 PM
That was a LONG time ago a while before I made the other thread, unfortunately speeding up the time multipliers causes headaches for the game, and will cause time to desynchronise and move backward when you speed up.
Interesting. I've never tried either method and assumed the XML change would work fine. There must be a calculation somewhere in the Python script that is assuming the time multipliers don't change from the defaults. Does it drift continuously, or just "jump" backwards when the speed change takes place?

simmythesim
20th May 2015, 9:16 PM
Interesting. I've never tried either method and assumed the XML change would work fine. There must be a calculation somewhere in the Python script that is assuming the time multipliers don't change from the defaults. Does it drift continuously, or just "jump" backwards when the speed change takes place?
What happens is that time works fine, fast even, but the sims, they also move fine, until they stop, they start talking then they stop, and do it repeatedly, and then when time finally goes back to normal speed the clock goes backward. It seems to be unfixable unfortunately, as it seems to happen with no mods on lots with lots of objects or sims.

EDIT: Now with video to demonstrate time travel!

scumbumbo
21st May 2015, 8:00 AM
Thanks for the video -- that really makes it clear what's happening. Interesting problem. Any reason I could offer for why that's happening would be just a guess, but it seems most likely that the server/ui thread is getting out of sync with the client thread (the native object-code server is able to run faster than the Python scripting can keep up). Have you tried smaller speed increments to see if there's a threshold for your system that starts causing the issues?

You also may want to bounce it off the gurus on the EA technical forum and see if they have an informed reason.

simmythesim
21st May 2015, 9:42 AM
Thanks for the video -- that really makes it clear what's happening. Interesting problem. Any reason I could offer for why that's happening would be just a guess, but it seems most likely that the server/ui thread is getting out of sync with the client thread (the native object-code server is able to run faster than the Python scripting can keep up). Have you tried smaller speed increments to see if there's a threshold for your system that starts causing the issues?

You also may want to bounce it off the gurus on the EA technical forum and see if they have an informed reason.
There is no threshold where time starts rolling back as time worked fine even with the speed mod on one sim and a small lot. However even without the mod lots with lots of sims, (player controlled or npcs, doesn't matter) time rolls back even without changing the speed,

I think a better way Maxis could handle speed is by changing the speed by the amount of sims on the lot. So, with 1 sim only, speed 3 runs faster than TS2 speed 3, but with 20 sims it would run slower than default to process those sims properly. Perhaps another mod for me to try working on I guess.
EDIT: Yes! progress on the mod is going smoothly, we'll have faster speeds that don't break the game within the next weeks or so.