Quick Reply
Search this Thread
Lab Assistant
Original Poster
#1 Old 17th Apr 2012 at 6:44 PM
Scripting mod to replace original methods
Is it possible to make a scripting mod that would overwrite the original methods contained within the game? My case, in particular, is that I want to add supplemental tuning to something that doesn't have it.

It appears that I can only do this via a core mod, but I want a 2nd opinion.


Thanks.
Forum Resident
#2 Old 17th Apr 2012 at 7:31 PM
To my knowledge it's absolutely impossible to overwrite code with a script mod. You always have to trick the game into executing your code instead of the EA code somehow.
There are many ways to get your foot in the door but it really depends what you're trying to do.
A classic is adding/modifying the interaction menus, but you can also "jump in" and change the changes the game has just made (when the sim has aged up you age him back 30 seconds later... so to speak). Another trick is to "mute" EA code via XML mods or by modifying other variables at runtime. You then try to manage the muted functionality with your own code. (like.. erm... you use XML to set the pregnancy moodlet to 0 in all cases and then write your own code to simulate wild moodswings for all pregnant sims every 15 minutes)

I hope you like my crappy examples
Lab Assistant
Original Poster
#3 Old 17th Apr 2012 at 7:46 PM
I was thinking along the same lines, but I'm not sure how successfully I would be able to modify privately-scoped variables. Will need to investigate.

I was thinking of disecting CmarNYC's tattoo locations mod and its alternative, as modified by Twallan. I'm thinking that that will be as good a place to start as any.

If there are any other interesting examples that I should consider, please don't hesitate to send them my way.


Thanks again.
Forum Resident
#4 Old 17th Apr 2012 at 8:08 PM
I have not looked into Cmar nor Twallan's code but they are different concepts...
Cmar's tattoo mod is a core mod, not a script mod.
Twallans CAS and Stylist are only available ingame via his menus, so he can launch whatever code he likes.. most likely the code he modified to his liking, not the EA code.
Ms. Byte (Deceased)
#5 Old 17th Apr 2012 at 8:11 PM
My XCAS / tattoo locations mod is a core mod, which replaces the entire UI.dll with the usual core mod method of decompiling the EA UI.dll, making changes to the MSIL code, recompiling, and putting the new .dll into a mod package. I'm guessing that's not what you want to do. The place to look is at Twallan's mods - I'd suggest CAS Integration as a starting point since that replaces the EA CAS entirely without depending on custom interactions, or as you said his Tattoo Extension since I think that specifically replaces the CAS tattoo methods although I've never used it and don't know if that's only inside his custom CAS.
Lab Assistant
Original Poster
#6 Old 17th Apr 2012 at 8:21 PM
Quote: Originally posted by CmarNYC
The place to look is at Twallan's mods - I'd suggest CAS Integration as a starting point since that replaces the EA CAS entirely without depending on custom interactions, or as you said his Tattoo Extension since I think that specifically replaces the CAS tattoo methods although I've never used it and don't know if that's only inside his custom CAS.


That's a good point--I didn't consider that Twallan's version of the xCAS may only affect the CAS replacement.

Looks like this might be a bit of a learning curve, if I am to do this the 'right' way.


Thanks again.
Top Secret Researcher
#7 Old 17th Apr 2012 at 9:00 PM
Quote: Originally posted by CmarNYC
The place to look is at Twallan's mods - I'd suggest CAS Integration as a starting point since that replaces the EA CAS entirely without depending on custom interactions


My definition of "custom interactions" is slightly broader, since I consider [Integration] to be *all* about custom interactions.

I replace existing EA interactions that call CAS with new custom interactions that call my version of CAS instead. That is how that module works.

This method works well if the code you are attempting to alter is near the surface of the Core coding. If the code is embedded deeper into the Core, or called from a lot of different interactions, it can become so complicated that only a Core-Mod is feasible.


NRaas Industries: Sims 3 Mods for the Discerning Player, hosted by The Wikispaces.
Lab Assistant
Original Poster
#8 Old 17th Apr 2012 at 9:39 PM
So, I suppose what I want to do then, is to completely replace the interactions in question with a slightly modified variation. It will most likely break every time the game is updated, but such is life. A lot better than having a core mod break.


Thanks again for your help guys.
Ms. Byte (Deceased)
#9 Old 18th Apr 2012 at 12:16 AM
Quote: Originally posted by twallan
My definition of "custom interactions" is slightly broader, since I consider [Integration] to be *all* about custom interactions.

I replace existing EA interactions that call CAS with new custom interactions that call my version of CAS instead. That is how that module works.

This method works well if the code you are attempting to alter is near the surface of the Core coding. If the code is embedded deeper into the Core, or called from a lot of different interactions, it can become so complicated that only a Core-Mod is feasible.



So you replace the "Create a Family" option in the Edit Town screen? You're right, I wasn't thinking of that as an interaction but of course it is.
Top Secret Researcher
#10 Old 18th Apr 2012 at 8:16 PM
Yes, the "Create A Family" button calls a "Click" delegate function when you press it. [Integration] replaces that delegate with a custom version that calls my CAS.


NRaas Industries: Sims 3 Mods for the Discerning Player, hosted by The Wikispaces.
Lab Assistant
Original Poster
#11 Old 18th Apr 2012 at 10:14 PM Last edited by dim4sim : 19th Apr 2012 at 5:38 AM.
Would I be able to replace an interaction on a Sim in a similar way? Delegate a click on an interaction that is already present in the vanilla game?

@twallan:
I tried to follow by example, and decided to dissect the Integration Module of Master Controller in an attempt to figure out how to override game actions. I've been a long-time fan of your work, but I did not expect to see such an abundance of code, all of which, incredibly modularized. Anyway, I dug deep to find the first interaction with a Sims3 library reference, and I stumbled upon the NRaas.CommonSpace.Options.IInteractionOptionItem<T> interface definition, used as a base for an abstract class, which inherits from Sims3.Gameplay.Interfaces.IGameObject.

I am assuming that this is the root level of integration. Would this be where I would have to work from, in order to override an interaction between 2 Sims?


Thanks again guys.

*edit: @twallan: I removed the code snippet, in case you did not want others to reveal trade secrets. Not sure if this is an issue, but I decided to err on the safe side.
1978 gallons of pancake batter
#12 Old 19th Apr 2012 at 9:09 AM
dim4sim, you might be better off looking at mods that utilize a less complex (and less powerful, I give you that) framework.

A simple example of a mod that replaces an actual interaction (completely without framework) would be my Excavation Site Hotfix mod. Look at the OnPreWorld() method. The first line is the actual replacement. The rest is to apply the tuning.

An example of a mod that replace an alarm callback is my Aging Manager mod. TwoBTech.AgingMan.AgingController.Manager.InjectCallback() would be the spot to look at. Directly replacing event delegates is a bit different, but not that much.

If gotcha is all you’ve got, then you’ve got nothing. - Paul Krugman
Lab Assistant
Original Poster
#13 Old 19th Apr 2012 at 1:44 PM
Thanks Buzzler, I'll check it out. I forgot that your mod was a replacement. I use it, too.
Top Secret Researcher
#14 Old 19th Apr 2012 at 4:01 PM
Quote: Originally posted by dim4sim
*edit: @twallan: I removed the code snippet, in case you did not want others to reveal trade secrets. Not sure if this is an issue, but I decided to err on the safe side.


No such thing as trade secrets, in a system where anyone can read your code-base.

If you wish to use my code, feel free. Ask over at my hosting site, and I will provide the original VS project files if you wish, so you don't need to decompile it.

However as Buzzler noted, my framework is an added complexity over the EA system (enforcing a standardization I use over my mod suite), and may not necessarily be something you want to use.


NRaas Industries: Sims 3 Mods for the Discerning Player, hosted by The Wikispaces.
Lab Assistant
Original Poster
#15 Old 19th Apr 2012 at 4:41 PM Last edited by dim4sim : 20th Apr 2012 at 5:29 AM.
Thanks for the reply, twallan. I appreciate the gesture. I will look into Buzzler's code first, and see if I can use that as a foundation for what I need right now. I will eventually try to make some more complicated mods, with time, so I may take you up on your offer.


Thanks again for your help guys.


Edit*
@Buzzler: I looked over the code in the place that you told me, and I think that the interaction gets overwritten in OnPreLoad()
I was trying to figure out what you were referring to in OnWorldLoaded(), but I think that the only thing that happens there, is the attachment of a new interaction, to terrains.

If all of that is correct, I think all the pieces are finally starting to fall into place.
1978 gallons of pancake batter
#16 Old 20th Apr 2012 at 7:53 AM
Quote: Originally posted by dim4sim
@Buzzler: I looked over the code in the place that you told me, and I think that the interaction gets overwritten in OnPreLoad()
Gah, stupid typos... Yes, OnPreLoad() is what I meant. OnWorldLoaded() isn't interesting in that case.

If gotcha is all you’ve got, then you’ve got nothing. - Paul Krugman
Lab Assistant
Original Poster
#17 Old 22nd Apr 2012 at 10:49 PM
I'm getting issues with class protection errors now, when I tried to implement the OnPreLoad method. I got an error message as follow:

Code:
Error	1	A static readonly field cannot be assigned to (except in a static constructor or a variable initializer) // the line where I was trying to replace Singleton



Then, I figured, "why not try to compile the Digsite Fixer". So, I kept trying to compile it until I ran into THIS error:

Code:
Error	1	Inconsistent accessibility: base class 'Sims3.Gameplay.Objects.DigSite.Excavate' is less accessible than class 'dim4sim.Sims3Game.Test.DigSiteFixer.Excavate'




Now I'm stuck. How do you get around the protection/exposure errors?


Thanks
Forum Resident
#18 Old 23rd Apr 2012 at 12:27 AM
read this http://www.modthesims.info/showthread.php?t=467578

pljones has turned twallans skript into a handy exe. You might want to give that a shot
Lab Assistant
Original Poster
#19 Old 23rd Apr 2012 at 6:17 AM
Gah. That is a great util. I had to recompile it using VS2010 (which I had to download and install, on top of VS2008) because it couldn't find the path to the decopiler. Regardless, it still did the trick. The problem, however, is that when I try to add those unprotected libraries to the solution, they come up as "Warning 1 The referenced component 'ScriptCore' could not be found."

I'll assume this has to do with the libraries being recompiled using a different compiler than it expects. Other than that, I can't think of anything besides screaming at VS2008, "but the file is right THERE!". That won't help much though--I've tried.

Also, on a side note: why does mscorlib.dll create complaints with Tunable and wreak all sorts of havoc? (I was trying to re-create my project in VS2010, which was throwing System.Object undefined errors, resolvable by referencing mscorlib.dll).

Odd.


Thanks for the help again.
Lab Assistant
#20 Old 23rd Apr 2012 at 6:54 AM
I don't have any guesses what could cause the ScriptCore error, but I have stumbled to the mscorlib problem.

VS2010 does not allow changing the mscorlib.dll like VS2008 did. You'll have to compile against Microsoft's mscorlib.dll. But that should not be a problem since EA mscorlib is a subset of Microsoft's. For example, EA has implemented their own timer system and thus removed timer-related classes from their mscorlib.

You'll do fine with VS2010 following the project setup tutorial, but skipping replacing/importing the mscorlib.dll and leaving the original mscorlib there.
Forum Resident
#21 Old 23rd Apr 2012 at 7:21 AM
In order to reference the EA mscorlib.dll you have to edit the .csproj file and... in simple terms: make the entry for mscorlib look like the other entries. This will make vs2010 eat that lib and ignore the MS version. This was explained in this forum somewhere... maybe google can help.

There should be no complaints about the tunables if you follow the project setup tutorial correctly. Check the assemblyinfo.cs if all using: parameters are set.
Lab Assistant
Original Poster
#22 Old 23rd Apr 2012 at 3:04 PM
Thanks for the info. I'll try to set up a VS10 project later. First I have to figure out why VS doesn't like the unprotected libs. Does anyone have an idea of what could have gone wrong?

Thanks.
Forum Resident
#23 Old 23rd Apr 2012 at 5:27 PM
That accessibility error pops up when you inherit from a sims3 class and declare a different accessibility level http://msdn.microsoft.com/en-us/lib...2(v=vs.71).aspx than the base class. Just use the same level as your protected/unprotected dll and it should work, Or switch from protected to unprotected for the dll in question.
I usually have everything protected except gameplaysystems.dll, not sure if buzzler used any deprotected .dlls or maybe a mixed set for that particular mod.
Lab Assistant
Original Poster
#24 Old 23rd Apr 2012 at 6:24 PM Last edited by dim4sim : 24th Apr 2012 at 5:13 AM.
I unprotected all of them, and none of them seem to be referencing properly. It's saying that the DLLs that I am including, cannot be found. The wording doesn't make sense, since I am including the references. Perhaps a screenshot may be in order. I'll get one when I get home.


Thanks.


*Edit: I think I got it. In VS2010, it wants an internal reference to mscorlib.dll, as was pointed out, and it doesn't like the [assembly: Tuning] line in AssemblyInfo.cs
Lab Assistant
Original Poster
#25 Old 25th Apr 2012 at 5:49 AM
I have all of the libraries unprotected, but for some unknown reason, I can't seem to get past the following error
Code:
Error	3	'Sims3.SimIFace.LoadSaveManager' does not contain a definition for 'ObjectGroupsPreLoad'

I even tried to recompile Buzzler's code, which uses that exact line. Same error.

I also would like to add that, perhaps related, Reflector shows this:
Code:
private static  event ObjectGroupsPreLoadHandler ObjectGroupsPreLoad

Any insight would be appreciated.
Page 1 of 2
Back to top