Introduction to BHAV Files

A TS2 Tutorial by Carrigon

This tutorial will teach you how to add code lines, bypass code lines, call a private, call a private within a private, how to enter GUIDS in code lines, and how to make a summoner. This is a basic introduction to BHAV’s.

For this tutorial you will need:

The project file. If you haven’t already done so, please do the two other tutorials at the SimPe site because they will build your hacking skills for this tutorial.

 

Before we get started:

Backup your entire Documents/Sims2 folder or forever hold your piece. And do NOT try to PM me, email me, or otherwise bug me about this tutorial. If you have questions, post at MTS2 and someone will help you there.

Part One:

The first thing we’re going to do is to turn one of Oberkorn’s Krystals into a simple summoner. So, open the project file for Part One of the tutorial with SimPe. If you look in the left column, you’ll notice there are no Pie Menu Strings. We’re going to add the Pie string and one BHAV. Click Plugin View. Click Pie Menu Fuctions. Right click on the big white space under Pie Menu Functions and choose Add.

Open the folder with my code files for Part One. You only need the .xml Pie Menu String. Add that one. You won’t see it yet. Go to the left column and click the line above Audio Reference, then scroll down in the right column and you should see your new Pie Menu String file at the bottom. Click it and make sure you’re in plugin view.

Click on the last line "Summon the Mothership". We’re going to change that to Drop a Boat. In the Value area, change it to Drop a Boat. Click change in all, click commit, then go to the top and click file, save. Double check that your change stayed.

Now click on Pie Menu Functions and look at it in Plugin View. You can’t see anything, right? That’s because we need to change the instance to match the Pie Menu String. This is very important and you must always remember this: Pie Menu Functions and Pie Menu Strings must ALWAYS have the same instance or they will not work. So, click on the Packed File tab. Look at the instance. Change that from 83 to 80 so it will match your Pie String’s instance. Click commit, and file, save.

There is one more step to getting your Pie Menu to work. In addition to the Menu and Strings needing the same instance, there is a line in the Object Data that must also have the same instance number. So, click on Object Data and look at it in Plugin View.

You must change Interaction Table ID to 80. Do this on its LEFT column and you should see the right column’s value change to 128. Click commit and file save. Then come back to this Object Data file and look at it in Plugin View again. Make sure your change stuck. Now, we’re going to change the GUID.

Go to the top of SimPe and click Plugins. Click Hash Generator. Click GUID in the little box that pops up.

This will generate a GUID based on your filename. Go to your GUID, backspace to remove the one that’s in there and Copy the first eight digits of your new into it. REPEAT the Hash Generator and do this step for the Fallback GUID so you have a new Fallback GUID as well. Do NOT touch the Original GUID in the middle. When you are done, click commit and go to file save. Make sure you all your changes stuck.

Let’s change the Catalog Description now. Left column of SimPe, click Catalog Description. Look at it in Plugin View.

Click on where it says Red Violet by Oberkorn. In the Value, change that to Tutorial Boat Summoner. Click change in all, click commit, go up to the top and click file save. Double check that your changes stuck.

Now, we’re ready to import a BHAV. Click on Behavior Function, left column of SimPe. Then in the right, in the white space below the BHAV lines, right click and choose Add. I want you to add my BHAV code that I included with the tutorial for Part One. You only need to add the .xml file for it.

Once you’ve added the file, click on it and look at it in Plugin View. I want you to change the file name from "Summon the Mother Ship" to Drop a Boat. It should read Interaction - Drop a Boat. Now, click on line 2 (Create New Object Instance) and look to your right at the Operands. Top row of the Operands, first four columns. That’s a GUID. But, it must be entered a certain way. We are not going to do that just yet. I want to show you how to find the GUID and how to enter it for what you want to summon, then we’ll come back here and we’ll change it. Basically, you can summon almost anything in the game if you know how to enter the GUID properly here. Some things can’t be summoned and some have self deleting codes, so that if you try, they’ll just delete themselves or the object will turn into a pile of garbage and your sim will clean it up. So you really need to know what you are summoning. Today, for this tutorial, we’ll summon something alittle bit different. So, click on commit, and go to file, save to exit this area.

Open the tutorial boat pizza package with SimPe that I’ve included with this tutorial. Click on Object Data and look at it Plugin View. Look at the GUID. Do NOT change anything in this file! We are just looking at it. You need to write the numbers down in the order I tell you and watch what I’m doing with it. GUIDs are entered into a BHAV code line reversed in groups of two. They are not just reversed, they must be done in groups of two the way I show you. Now, see how the GUID looks like this: 8BCFFA37. You must write the GUID down like this: 37FACF8B. Do you see what I’ve done here? You break it apart in groups of two and you do it reversed. This step is very important. You will always enter GUIDS in BHAVs this way. Exit this file without having done anything to it.

Open the Fire Krystal tutorial package file we were originally working with, your summoner. Click Behavior Function and click on Interaction - Drop a Boat. Click line two, create new object instance. Look at the operands on the right. Top column, first four boxes. Enter the boat pizza’s GUID as I just showed you. The numbers should look like this: 37FACF8B Click commit and go to file save. Double check that this change stuck.

Now I want you to click on Pie Menu Functions. We need to make sure it will drop this boat.

When we added the Pie Menu String, we changed line F to make it say Drop a Boat. Now, to link that to Pie Menu Functions, you need to click Add and then click in the Pie String ID box. Backspace over the last zero and type in F. You should see the column on your left change to Drop a Boat. That’s what you want. Look at the Flags area. Check off Immediately, Adults, Elders, Teens, Children, Demo Child. Then look under it at the Guardian and Action area. This code doesn’t need a Guardian, so you can leave that alone. For Action, click the little arrow next to it, wait for it to load. Click the private tab in the box that pops up, choose Interaction - Drop a Boat. Look at the Autonomy area, you can make this 64. And the Attenuation I usually make it a 3. That’s it. Click commit, and go to file, save. Come back here and make sure your changes stuck.

Before we go on with adding more things to this file, test it out in your game and make sure the summoner works. So, place BOTH the tutorial boat pizza package and the Fire Krystal project summoner package into your downloads folder. Play the game and find the Fire Krystal in decorative/all. Put it on an endtable. Have your sim click on it and see if it drops an edible boat your sim can eat.

Part Two:

If you were able to make the summoner and it worked, you’re now ready to go on to part two and make the summoner do more than just give you a boat. So, open the Fire Krystal summoner package with SimPe.

For this part of the tutorial, we’re going to use a little code off of Merola’s Multi Painting. We’re going to tell the file to drop the boat and make our sim’s aspiration platinum.

So, looking at the summoner in SimPe, click on Behavior Function and then in the white area right click and choose Add. This time, you are going to add files from the folder labeled code files part two. Add only the .xml files.

Now, click on Interaction - Drop a Boat. We’re going to be adding code lines. Look at it in Plugin View.

Click the last line, line 4, Fade Object In. Now look to your right. Click Add and it will dupe the line.

So, now you have a line 5. This next step is one of the most important ones you’ll learn. We are going to link the line. You can never just add a line without another line linking to it. All code must point somewhere and be linked somewhere.

Click the line above it, line 4. Look at where it says True: FFFD Look to your right at True Target. We are going to change this value so it will point to line 5. So change it to 0005. Then look at your line and you should see it says 5.

Okay, now we have a new linked line of code. We need to change the code so it will do what we want it to do. To do that, we’re going to use a technique called, "Calling a Private". So, click on line 5. Then look over on the right at OpCode and the little triangle next to it. Click the triangle and wait for the code box to pop up. Click the Private tab. Click Int. Aspiration Self Max. Click use. See how the OpCode is now changed to 1300 and your line 5 now says (Private) Int. Aspiration Self Max. Click commit and go to file save.

Now, come back to the Behavior Functions area and click on Int. Aspiration Self Max. I just want to show you what this file is actually doing. It is using a technique called, "Calling a Private Within a Private". See how it’s using a Sub file in the code line. It’s pointing to the set aspiration meter. So what we’re doing here is we told the summoner code to point to the self max line and then the self max line is told to go this sub line and use this. Don’t change anything with this code. Just exit out of it.

In the Behavior Function area, click Interaction - Drop a Boat. We’re going back to our summoner code lines. I’m going to show you how to make it drop another boat after it maxes the aspiration.

Click line 2, then go to the right and click add so it dupes the line. Do this for line 3 and line 4 as well.

So now we have three new code lines, but they are all pointing to the wrong place. We need to change the True Targets so they point to the right places.

Click line 5, change the true target to 6 by typing in 0006 in the box. Click line 6 make it point to 7 and make 7 point to 8. So you are just repeating these steps. When you get to 8, make that true target FFFD. Click commit, and go to file, save.

Before we go any further with this tutorial you should now test this file and make sure it is now dropping two boats and making your sim platinum. So put this file and your boat pizza file into downloads, make sure you have both files in there. Then go play and test it out.

The summoner should have dropped you two boats and your sim should have gone Platinum. If it worked, you are ready for the last part of the tutorial.

Part Three

Open your Krystal summoner file in SimPe. We’re going to add one more code. Click on Behavior Function. Right click on the white part and choose Add. Add the three .xml files from my folder marked codes part three. Only add the .xml files, that’s all you need.

In Behavior Function, click Interaction - Drop a Boat. We are going to add a code line and I’m going to show you how to bypass a code line.

Click line 5 and click add. We are duping line 5. You’ll see it has now added it and made it line 9. Click line 9.

Now on the right, click on the OpCode triangle and wait for the box to popup. Click the Private tab. Choose Int. Personality Drain Fitness. Click Use.

Click line 8 changed the True Target to 0009, so the line points to line 9. Then click line 9 and change the true target to FFFD. Click commit and go to file save. Make sure your changes stuck. So now you have the new line and the code is pointing to it.

Go back to Behavior Function and click Interaction - Drop a Boat. I’m going to teach you how to bypass a code line.

Click line 4, Fade In. See how the True is pointing to line 5? We’re going to bypass that and tell it to just plain skip over to line 6. So look at the True Target Box and change the 5 to 6.

Click line 5 and change the True Target to FFFE. That’s so if it does somehow try to read the line, even though we bypassed it, it should just skip it anyway. You now have no lines pointing to five. It is an unlinked code line. What we just did was tell this file we want two boats, but we don’t want to be platinum, we want to be fat instead.

Click commit and go to file save.

Come back to Behavior Function and click Interaction - Drop a Boat. Click line 6, create new object instance. We’re going to tell it to give us something other than an extra boat. Minimize the SimPe program and open up the OBJD.txt file I’ve included with this tutorial. Search for Teddy Bear. Find this line: Object Data (OBJD, 0×4F424A44); 0×00000000; 0×7F2FFF93; 0×000041A7; 0xC239A78B; 0×0004; Normal; Durably Plush Teddy Bear; Stuffed Animal - Teddy Bear;

This is the Teddy Bear GUID: C239A78B

Remember how we have to enter the GUID in the Operands boxes? It must be entered like this: 8B A7 39 C2

So, go back into SimPe and change the GUID numbers in the Operand box for line six. Click commit and go to file save. Make sure your changes stuck.

Your file should now drop one boat, one teddy bear, and it should make your sim fat. Exit SimPe. Make sure you have this package and the boat pizza package in your downloads folder. Go play the game and test it out.

And that concludes this introduction to BHAV’s. This tutorial in no way encompasses all the things you need to learn with BHAV’s, but it should get you started with some simple hacking. You cannot just import any BHAV into a file. Most BHAV’s reference other things. They reference Privates, BCONs, Call Trees, Text Files. You need to know what that BHAV is referencing before you can import it anywhere and then you have to import every single thing it is referencing or your code won’t work. Experiment. The more you experiment, the more you will learn to hack. Many fun things can be changed in the Text files. You can change a sound, an animation, or the look of something by changing its name in the Text files. That is how I made the pizza slice look like a boat. Look at different files, look at their names in the Text files and experiment.

Credits:

Thanks and Hugs to Quaxi and Merola.