#2
11th Dec 2018 at 8:32 PM
Posts: 2,671
Thanks: 62729 in 190 Posts
25 Achievements
Well, I'm not sure what fixes you have in mind, so I suppose ymmv, but you want to wait until after tuning mods are loaded in order to alter them (otherwise there is nothing there to actually alter). This is typically done by injecting a method to the load_data_into_class_instances() method of the InstanceManager. The new method calls the original function and follows that with any changes that need to be made to those tuning instances. A lot of mods use this method to simply add to the super affordances list for an object tuning.
A relatively simple example of this would be what I do in my Unlisted Phone Numbers mod -- look at the unlisted_phones.py script of that mod. The EXCH_load_data_into_class_instances() method calls the original, and then makes a choice depending on what tuning types were just loaded. If snippet tunings were loaded, then a new friendly exchange numbers interaction is added to the friendly tuning snippet's super affordances. If object tunings were just loaded, then two new interactions to exchange and revoke phone numbers are added to the object_sim tuning's relationship panel affordances.
There's also a way more complex modification done in that same file to drama nodes. This is done by actually modifying the method to resolve drama participants and is done in this manner to ensure that the filter term we want to add to a sim_filter tuning is ONLY done for actual drama nodes, and not any other XML tunings that may utilize that same sim_filter. The code sticks our new filter term into the sim_filter tuning, runs the original _resolve_drama_participant() method, and then removes that filter term from the sim_filter before anything else tries to use it. This demonstrates that tuning can be changed "on-the-fly" while the game runs, when necessary.