TUTORIAL: Core Modding! (For complete and total nincompoops, like me!)
So I've always had this dream of one day, having my own cooking show. The tagline would be: "I have no idea how to cook, so if I can do it, you can too!"
That's basicly the idea behind this tutorial. I do not possess l33t skills like Pescado or Lemmy101 or Delphy. In fact, until yesterday, I had no idea how to core mod. But I bugged the hell out of the right people until they held my hand and walked me through it, and now, that's what I'm going to do for you, as a public service to those great modders, so that you won't have to bug them like I did. At least, maybe you'll bug them with slightly less stupid questions than mine. But enough introductions, let's get started. Oh, one more quick thing before that. This tutorial was not written by me. Well, it was, but not really. Really it was written a little bit by Delphy (whom I pestered in the chatrooms) and for the most part by Lemmy101. They showed me exactly what to do, I took notes, and now I'm passing it on to you. I'm just the middleman.
I. What is core modding?
A lot of you are probably familiar with XML tuning, a tutorial about which can be found right here on this very forum. A lot of you, also, probably know that XML tuning's fatal flaw is its ridiculous limitations! If you want to make some very minor adjustments to the way the game works, XML
may be able to do it, and you should definitely check there first, but most everything else about the game is deeper coded in 3 main DLL files. It turns out that even some very minor changes can only be made in these DLL's, but the plus side of that, is that the limitations are almost non-existant here. If you wanted to turn the Sims 3 into a first-person shooter set in a giant themepark with zombie clowns on the loose, well you might not be able to do that, but frankly I wouldn't be surprised. Editing these DLL's, however, is a kick in the head, but it's worth it if you want to mod the game, and even though it's a labor-intensive process, it actually ISN'T something far beyond the abilities of the average Joe Shmoe on this forum, thanks to the geniuses who figured it all out for us. Believe me, if I can do it, say it with me, you can too.
II. Ok, first of all, let's go over the laundry-list of programs you will need.
A. First, and foremost, you will need S3PE, which is in the early stages of becoming what
SimPE was to TS2, if you don't already have it, get it here:
S3PE (S3PI Demo Package Editor)
AA. Also, I hope this goes without saying, but you need the modding framework and Resource.cfg for your Sims 3 directory, in order to run any mod, and you MUST have the included d3dx9_31.dll file, in the correct directory, to run any core mod. If you don't already have 'em, get them here:
Framework. (Note: if your game freezes during the initial loading screen with any core mod installed, it's because you don't have d3dx9_31.dll, or you don't have it in the right directory)
B. You will also need the latest .NET framework to be able to use the aforementioned program. If you already have it, move on to bullet C, if not, go here:
.NET Framework AND you'll need the .NET sdk 2.0 for other stuff, so if you don't already have it, get it here:
.NET SDK 2.0. And finally, (thanks to TigerM and Lemmy for pointing this out) you're definitely going to need the
Windows SDK as well, if you don't already have it.
C. The .NET Reflector is a program that will give you a free peep-show of the DLL's you'll be modifying in a straight-forward intelligible format that I'm confident some species of monkeys would have little trouble deciphering, but will not let you edit them (at least, not in the correct way, and not without wreaking havoc on your game). Why is this necessary, you ask? Because the DLL's are not made to be edited in their present state, after we convert them to a format we CAN edit, they will be much, much harder to read. Seriously, those monkeys from before, they will cry. Just trust me and get the program.
.NET Reflector
D. Notepad can only handle so much abuse, and unfortunately it is ill-equipped to open the vast filesizes we need it to open. You'll need
Notepad++ .
E. ILASM and ILDASM: After you have installed all of the above, you will need to make use of two programs that should probably ALREADY be on your computer. The trouble is finding them, as they can be in a number of places. The first place to look, however, would be any of the many folders occupied by Microsoft's .NET in your system folders, i.e. Program Files and Windows. You will need to COPY (do not take them out, COPY them!) the exe files for these programs, and any dll's or other files they may need in order to run, to a new folder, anywhere on your computer, which is going to be your new modding workstation. Just make a folder in My Documents if you want and call it "MyStupidMod." Whatever floats your boat. My guess is that you'll need the same files I needed, which are:
ilasm.exe,
ilasm.exe.config,
fusion.dll ildasm.exe and
ildasm.exe.config .
Here's where I found mine, but yours may be somewhere different. If all else fails, try running a search of your entire computer to find the files. I found ilasm.exe, ilasm.exe.config, and fusion.dll in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727, and I found ildasm.exe and ildasm.exe.config in C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin .
Again, I can't stress enough, COPY them instead of moving them.
F. Last though certainly not least, a statement riddled with irony that you will only come to contemptuously appreciate once you actually begin to download and install this last program, is
Visual C# 2008 Express Edition . But don't go and download it just yet! Listen, this is a very handy and free program that will allow you to create C# code, but it may not be entirely necessary for you. It is definitely necessary if you are looking to create a more in-depth, larger scale mod, like the Indie Stone mod. For my mod, however, I only needed to change a single value, and I didn't open this program once in the process. Basicly, if you want to create new DLL's, you're going to need this program (or you can choose to do a pretty advanced workaround described by Rick and TigerM below). If you just want to modify the existing DLL's, skip this step, for sanity's sake, and move on. The only real reason for the hesitation here, is that this program takes a LONG ASS TIME to install. If you do end up installing it, make sure you have a good book. Or the firefox Stumble! add-on. Basicly, you're gonna have some time to kill.
That's it! Once you've gone through all of these steps, you are finally set up to core-mod. Now we can get started. (Didn't I tell you this was labor-intensive?)
III. Preparing the files for editing
A. First things first, open S3PE, and you'll need to open the right package and extract the right file. For your specific case, I don't know what you want to do here. You might want to make a fresh, new mod for the Sims 3 base game, or you might want to add some small detail to an existing mod that you can't live without. (note that if you want to keep your Indie Stone or Awesome Mod, you must make your changes to THESE mods, due to the highlander rule, there can only be one. This wouldn't be true of XML tuning, but we're in Core Modding country now, and things aren't quite as simple (yet)) There are 3 main DLL's that control nearly every aspect of the game. These are: Sims3GameplaySystems.dll (likely the one you're going to want to edit), Sims3GameplayObjects.dll, and UI.dll . Both Awesome Mod and Indie Stone modify all three, (which is why the are incompatible, and would be even if they only modified one in common).
So, if you want to edit the basegame, open ProgramFiles\Electronic Arts\Sims 3\Game\Bin\Gameplay.package (NOT GameplayData.package, that was for XML). If you want to edit an existing mod, open that mod's package. Either way, you will see a short list of files (anywhere between 1 and 4 of them), and you need to pick the correct one to edit. To do so, select each, one at a time, and press "Value". In the window that pops up, you should see a line that says "ManifestModule:" and after this will be the original filename (it should have .dll at the end). When you've found the one you want to have a go at, make sure it's still selected, and click "Grid", then Import/Export, Export, and navigate to the directory we set up earlier as your workstation. Now, save it as the filename you saw earlier, when you checked the Value. For instance, if you're exporting Sims3GameplaySystems.dll, you'll want to save it as that. And don't forget the .dll!
B. Now, open the .NET Reflector program, and use it to open the dll you just exported. (NOTE: If you have trouble opening the file, it is likely because you don't have it in the same folder as ILASM and ILDASM. If you do, then something is wrong with these programs, or your file. Go back and make sure you followed these steps correctly.) You'll have to click some plus signs in the left window once you open it, to see what's inside, but what you'll find is a very handy display of the entire contents of the file. Take this opportunity to do some detective work. Once you find an item that looks like what you probably want to edit, double-click it, and you'll see its contents in the right window. My goal was to make a "No Privacy" mod, so I went to Sims3GameplaySystems > Sims3.Gameplay.Situations > GenericPrivacySituation > OtherSimCanIgnorePrivacy(Sim) : Boolean, and found the following:
Code:
public override bool OtherSimCanIgnorePrivacy(Sim sim)
{
return sim.SimDescription.ToddlerOrBelow;
}
Now, the syntax might be scary, but hopefully a 5-year-old wouldn't have too much trouble ascertaining what's going on here. The condition, OtherSimCanIgnorePrivacy, is checking two factors, 1: is the invading Sim a spouse? and 2: Is the invading Sim a toddler or baby? If either of these factors is true, the condition returns true (and the sim is allowed to ignore privacy in the situation) but otherwise, it returns false (and the sim pitches a fit, gets embarrassed, and no one ends up using that bathroom). Well, I wanted to skip these two checks entirely, and simply return "true."
If we could edit this RIGHT NOW, in a mostly legible fashion, the world would truly be filled with sunshine and puppy dogs, but sadly it's a cruel, cruel place, and we can only view the code here. On to C.
C. We must convert our little DLL into a behemoth of a file of another type, called IL. The code will all be converted, so that we can edit it, into a much less user-friendly (if not a downright user-asshole) format, the filesize will be somewhere around 50mb. To do this, we need ILDASM, one of those strangely named programs we put in our workstation folder earlier. (REMEMBER: IL
DASM is for IL Disassembling, and ILASM is for IL Assembling. Basicly, ILDASM = DLL>IL, ILASM = IL>DLL) Don't go and double-click it, that won't work. Here's what you do:
Go to start > run, and type "cmd". This will bring up a DOS console, and you'll need to navigate to the directory we're working in. To do this in DOS, type "cd directoryname" where directoryname is the name of the folder you're navigating to, in My Documents. If you need to go up a folder, type "cd.." . If you're having trouble with this, go
here. Once you've gotten to your workstation directory, type the following (NOTE: syntax can be tricky):
Code:
ildasm filename.dll /output=filename.il
I'm hoping you already figured out what you're supposed to type in place of "filename." If all goes well, a window should appear and a progress bar should begin traversing a small window on your screen, and when it finishes you will have an IL file in your workstation directory.
IV. Making your Edit! (FINALLY!)
Now you'll want to use Notepad++ to open the IL file you just created. Take a moment to recover from the shock of how lengthy this file actually is. Go ahead, I'll wait for you. Ok, traversing the breadth of this file is going to be a headache, so you'll want to use the Search option a lot. (NOTE: The search box has an up/down toggle. Just so ya know.) Start by searching for some of the terms you found when you did your detective work in the .NET Reflector earlier. If you don't remember them, you can re-open it and check, the dll is still there. These terms will likely occur multiple times in the document, but if you pick something really specific to search for, you won't have to do quite as much hunting. I searched for "CanIgnorePrivacy" and found a few dead-ends, but finally came across this (the definition of the method I was looking for):
Code:
.method public hidebysig virtual instance bool
OtherSimCanIgnorePrivacy(class Sims3.Gameplay.Actors.Sim sim) cil managed
{
// Code size 12 (0xc)
.maxstack 8
IL_0000: ldarg.1
IL_0001: callvirt instance class Sims3.Gameplay.CAS.SimDescription Sims3.Gameplay.Actors.Sim::get_SimDescription()
IL_0006: callvirt instance bool Sims3.Gameplay.CAS.SimDescription::get_ToddlerOrBelow()
IL_000b: ret
} // end of method GenericPrivacySituation::OtherSimCanIgnorePrivacy
This is MSIL code, and if you don't know how to edit it, well, neither do I. You can read up on it, on the internet, I'm told, and you can check out
this helpful topic by Lemmy101, {UPDATE: Also check out
Lemmy's New IL / DLL Tutorial} but really, this is where the real difficulty, and creativity comes into play.
I can tell you, however that those strange bits like "IL_0001" are the line numbers inside the {curly brackets}, and that there cannot be two with the same name inside the same set of brackets.
Now, I probably would have had to play around with this file and think really hard for days until I figured out how to make the simple change of defining this condition as simply "true," but Lemmy101 geniusly pointed out that we could just copy and paste from the method ABOVE this one, which happened to be the following:
Code:
.method public hidebysig virtual instance bool
OtherSimCanJoinSituation(class Sims3.Gameplay.Actors.Sim otherSim) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldc.i4.0
IL_0001: ret
} // end of method GenericPrivacySituation::OtherSimCanJoinSituation
The condition OtherSimCanJoinSituation for GenericPrivacySituation is simply returning "false." We want to the CanIgnorePrivacy method to return "true." So, we copy and paste, with one little change. Apparently, the item that's really doing the work here is the unassuming "ldc.i4.0". I have no idea what the hell this means, but lemmy told me to change it to a .1 (for true) instead of a .0 (for false). Here's what our new code looked like:
Code:
.method public hidebysig virtual instance bool
OtherSimCanIgnorePrivacy(class Sims3.Gameplay.Actors.Sim sim) cil managed
{
// Code size 12 (0xc)
.maxstack 8
IL_0000: ldc.i4.1
IL_0001: ret
} // end of method GenericPrivacySituation::OtherSimCanIgnorePrivacy
Then save, and that's that. On to V.
V. Un-preparing the file and sticking it in your game.
A. First things first, we need to get our edited IL file back into DLL form. Before you do, though, consider that you might not want to replace your original DLL you exported way back in an earlier step that I'm too lazy to look up the name of. If you don't want to replace it, rename it something silly, and it'll be left alone. If you just don't care, the let it be. Now go back to that cmd DOS window. In your workstation directory, enter the following, using ILASM this time, and again remember that the syntax is tricky:
Code:
ilasm filename.il /dll
You should see a vortex of text come careening down the window at you. It will do this for a good 30 seconds though, so you can take this opportunity to pretend you're Neo from the matrix.
If all goes well, (and this is the part you have to cross your fingers for) it will finish up and say "Operation Completed Successfully" and you'll have a newly modded .dll file in your directory. Whatever the name of this dll is, make sure to change it (if need be) to that original filename we saw in
S3PE > Value at the start of this whole mess.
...If it FAILS, then either you didn't type it in the DOS window correctly (and you're hoping for that possibility, trust me) or your mod code doesn't make sense, and it couldn't compile it. In which case, you'll have to figure out what you did wrong back in Notepad++ and try again. (and again and again and again)
B. Once you've got your DLL file finished ILASM'ing, go ahead and open it with Reflector. Check the part or parts you modified, and see if you managed to do what you were trying to. Did it work?
C. If so, open S3PE, and depending on whether you're editing an existing mod, or creating your own new base-game mod, either open the mod package, or simply create a new one.
If you're going with door number one, then all you'll have to do is find that original file you exported before in the mod package (making sure it's the same one by clicking "Value") and simply select it, then Grid > Import and choose the DLL that's still warm from the ILASM. When it asks you if you want to commit the change, say yes, and then save the package and put it in your ProgramFiles\ElectronicArts\Sims3\mods directory (making sure there's no other core mod packages already in there, as they will almost certainly conflict).
If you're more of a number two person, then you'll need to re-open the original gameplay.package (in a new window of S3PE, for your convenience) and find the file you exported before. Now, in the other
S3PE window, your new package window (DO NOT ADD ANYTHING TO THE ORIGINAL GAMEPLAY.PACKAGE FILE! Your sims will all die horrible deaths and so will your computer.) go to Resource > Add Resource, and copy in the Type and Instance from the file in gameplay.package EXACTLY. The group should simply be "0x00000000" (that's zero x and 8 zeros). After you've added the resource, select it, and Grid > Import, choose the ILASM'ed DLL and commit, then save, put the package in your mods directory, making sure there's no other core mods present (as they will almost certainly conflict) and you're done!
// End of Tutorial *whew*
Anyway, I wish you all the best of luck with your modding, and I can't wait to see what you create. Note that during the majority of the steps in this tutorial I had no idea what the hell I was doing, and if your results turn out different than mine in any area, I will try my best to offer help, but it's more than possible that I'll be of no more use to you at that point.
Also, if anyone thinks they can improve or expand this tutorial, I have only this to say. OH SO YOU THINK YOU CAN DO IT BETTER, HUH? No, really, that would be awesome. Any flaws you can point out on my part, or any extra guidance you can offer in the MSIL editing part (which deserves a whole other tutorial) would be welcome.
That's it, thanks again to Lemmy101, and good luck to you all!
References:
Lemmy's IL and DLL Tutorial
Sims Wiki: Sims 3: 0x073FAA07
Sims 3 Tools Forum: Export / Import assemblies
Sims 3 Tools Forum: Assembly Errors. What am I doing wrong?
Sims 3 Tools Forum: On making a tutorial for Making a core mod