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!
Quick Reply
Search this Thread
Test Subject
Original Poster
#1 Old 7th Sep 2014 at 4:14 AM Last edited by TheHologramMan : 14th Sep 2014 at 7:35 PM.
Default Another Scripting Example (with Remote Debugging)
Before they announced the custom content, I managed to create a working example using a dll injection technique to force code to be loaded. Now I expect they will fix the code soon so this will not have a long lifespan but I like this better than trying to hack files in the core zip files. In the meantime I figured other advanced modders can use this to test script examples and get something going. I don't know how much will work when the game is fixed but I expect this will still be of some value when its done.

Rather than reproduce the whole text I will just link to my github repository where you can download a zip of the source and read the README file: https://github.com/figment/sims4exmod

I was able to get a version of hot reloading working. In this example, using the command 'ex.reload' will reload all of the scripts in the source folder. The other example included was a 'ex.hello' command just to show off how to do logging.

By the way, the winmm.dll and scripts.ini file in the example can be used to load the example from SimGuruModSquad. Just rename the file simsmodsquad-maslow.zip file to maslow.zip and put it in the Mods folder and it should work. Type maslow in the cheats console in game to have it work.

If the game is updated I expect the winmm.dll workaround to stop working and might crash the game so delete it if that starts happening.

Edit: I updated the example to show how to include the ability to remote debug the python code. I'll note that the Remote Debugging I got working is with the paid edition of IntelliJ IDEA Professional and should work with the PyCharm Professional version but both have a sizable cost for most users. I was able to get Eclipse to connect but I have no idea how to use it but looks like it maybe possible. I've tried Visual Studio 2013 with Python Tools for Visual Studio but could not get that to work properly either. PyCharm has a 30-day trial on the Professional version. (Also if any one uses IntelliJ IDEA with Python plugin then you need to still download PyCharm to get the remote debugging egg files)

Anyway, you can just copy over the pycharm-debug-py3k.egg to the Mods folder and rename .egg to .zip to get it to work with PyCharm. After attaching you can set breakpoints in any code in the source folder and if you use the Console | "Show Python Prompt" can interactively inspect the global state to debug code. I had trouble getting source code to map using the Path mappings to the reverse engineered code in theory that should work. Also I set the port to 2345 but of course this can be changed as long as both sides agree.

Edit 2: I've updated the example to remove the need for winmm.dll as the game works properly with the Mods\<mod>\scripts\<mod>.py format.
Advertisement
Test Subject
#2 Old 7th Sep 2014 at 6:24 AM
Well if you're just trying scripts out, isn't it less effort to just py_compile and stick the pyc file into one of the games script zips?
Test Subject
Original Poster
#3 Old 7th Sep 2014 at 1:43 PM
Not really. As I said I already wrote this before the announcement of it being broke. Now my setup is easy to use and no need to modify game assets. Makes it faster to test changes as well since I got reloading working as well.
Field Researcher
#4 Old 7th Sep 2014 at 10:37 PM
Quote: Originally posted by TheHologramMan
Not really. As I said I already wrote this before the announcement of it being broke. Now my setup is easy to use and no need to modify game assets. Makes it faster to test changes as well since I got reloading working as well.


So I got it working but let me understand this...

The modified DLL makes it so that the ex mod is called, but nothing else in the mods folder will be called, correct?

I should place and scripts in the source folder and call them through ex for now instead?
Test Subject
Original Poster
#5 Old 8th Sep 2014 at 12:55 AM
The dll makes it so that any zip mods are imported with the name of the zip. So in this case it tries to "import ex" effectively because the zip is named ex.zip. If you had a zip called "asdf.zip" it would "import asdf" as well. If the contents of the zip do not have mod.py (or mod\__init__.py) it will do nothing effectively (where mod is name of the zip).

The source file will be imported as "mod.source" so any files are scoped to this directly. This is in contrast to the "scripts" folder which imports into global scope. Not sure this is a good idea but it works for now.

You should copy the ex folder as is to the Mods folder. The loose .py files in the ex folder itself will not do anything.

I've been thinking that there is probably a better way of doing this but I'll wait for patch before continuing since this gets custom code loaded currently.
Field Researcher
#6 Old 9th Sep 2014 at 6:52 PM
Quote: Originally posted by TheHologramMan
The dll makes it so that any zip mods are imported with the name of the zip. So in this case it tries to "import ex" effectively because the zip is named ex.zip. If you had a zip called "asdf.zip" it would "import asdf" as well. If the contents of the zip do not have mod.py (or mod\__init__.py) it will do nothing effectively (where mod is name of the zip).

The source file will be imported as "mod.source" so any files are scoped to this directly. This is in contrast to the "scripts" folder which imports into global scope. Not sure this is a good idea but it works for now.

You should copy the ex folder as is to the Mods folder. The loose .py files in the ex folder itself will not do anything.

I've been thinking that there is probably a better way of doing this but I'll wait for patch before continuing since this gets custom code loaded currently.


Can you easily repatch that .dll? Sims 4 just got patched and broke it. I much prefer this way of testing.
Test Subject
Original Poster
#7 Old 10th Sep 2014 at 3:40 AM
I've uploaded new version winmm.dll and scripts.ini. The winmm.dll shouldn't have been required but I used strlen when I meant sizeof so it didn't do what I expected. In the future only scripts.ini need to be patched. It is required to be updated this time else the old address will be used with new dll.
Field Researcher
#8 Old 10th Sep 2014 at 6:20 AM
Quote: Originally posted by TheHologramMan
I've uploaded new version winmm.dll and scripts.ini. The winmm.dll shouldn't have been required but I used strlen when I meant sizeof so it didn't do what I expected. In the future only scripts.ini need to be patched. It is required to be updated this time else the old address will be used with new dll.


Thank you
Test Subject
#9 Old 14th Sep 2014 at 12:04 AM
Should we be compiling these files to pyo? I've placed the items into my mods folder as you said, then I went into the game, typed "ex.hello" and no results. Am I missing?
Test Subject
#10 Old 14th Sep 2014 at 12:20 AM
I've even put the DLL file in the main dir even though you said they wouldn't be needed.
Test Subject
Original Poster
#11 Old 14th Sep 2014 at 4:11 AM Last edited by TheHologramMan : 14th Sep 2014 at 4:36 AM.
winmm.dll has to go in the same folder as TS4.exe or it will never be used. That is the Origin\The Sims 4\Game\Bin directory. In theory, if the game is patched then my expectation is this isn't needed. I've never seen confirmation that this will work as I expect but if the maslow.py file works then it should I think. You need to put scripts.ini in the Mods folder. Then just copy the whole ex folder in to the Mods folder. (script reload from the source may not work, it seemed to stop working for me after latest updates but thats an advanced feature not need for the basic script loading).

You do not need to compile the PYO or PYC files to make this work, at least I do not. If the game has been patched again then I need to update the offsets in scripts.ini. Its not an arms race I want to play so I hope that they are properly importing the py files from the zip in the future or we will need a better way of doing this in a standard way. I've tried other techniques but they have all failed. I'll check if the game has been updated and make another patch.

Edit: Checked and my game is up-to-date so expecting this to work.

Edit 2: Apologies to all. Apparently, I may have forgotten to actually publish correctly to github so master did not have the latest dll. I've download the code from github and reinstalled on my machine from scratch with new mods folder to confirm it works.
Test Subject
#12 Old 14th Sep 2014 at 4:44 AM
It works ! Thank you so much for all this !
Test Subject
Original Poster
#13 Old 14th Sep 2014 at 7:30 PM
Sure. I've update the code again as I tried the Mods\<mod>\scripts\<mod>.py format and it works properly for me so I removed the need for the winmm.dll hack.
Back to top