BHAV Finder

The Simantics Resource Finder in SimPE (Tools -> PJSE -> Simantics Resource Finder...) is very good at what it does, but doesn't quite measure up if you want to dig into the Maxis game code, for example, when searching for code snippets that use primitives in a certain way, or link to specific strings (eg animations).

BHAV Finder is my attempt to make spelunking in the game code more productive. Recently, I have wanted to be able to answer questions such as

Which BHAVs ...

  • ... use the old version of the relationship primitive
  • ... use TNS Style 0x05 (see here)
  • ... create the "Token - Poison Ivy" object
  • ... access the Lot Inventory
  • ... call "Want Satisfy - Kiss" in the SofaSocialGlobals
  • ... use the firefly jar animations
  • ... in any of my mods use the Money Globals

BHAV Finder was written to provide the answers.


Before using BHAV Finder it is necessary to tell it where to find the objects.pacakge file for the latest expansion you have installed. From the "File" menu, select "Configuration..." and either enter or browse to the install location (where the CSBin, TSBin and TSData sub-directories are located) - for UC this will end "Fun with Pets\SP9"


How to answer ...

All of the sample answers search the game's objects.package file, so firstly we need to open it. From the File menu, select "Select Package..." (or type "Ctrl+O" or click the "Select Package" button) and browse to find the objects.package file. If this file has been opened recently, it can quickly be re-opened from the "File", "Recent Packages..." sub-menu.


Which BHAVs use the old version of the relationship primitive

From the "OpCode:" drop-down, select the "0x1A Relationship" entry, and from the "Version:" drop-down, select the "0x00" entry. Now click the "FIND BHAVs" button (or press the "F5" key or type "Ctrl+R")

(As you can see, there are some issues with non-standard charters in BHAV names!)

Check "Show Group/Object Names" (or type "Alt+N") to change the group numbers into more meaningful names


Which BHAVs use the old version of the relationship primitive in the Globals BHAVs

To filter the results from our first question to just include global BHAVs select "0x7FD46CD0 Globals" from the "In Group:" drop-down and click the "FIND BHAVs" button


Which BHAVs use TNS Style 0x05

Firstly, we need to remove any previous settings so, click the "Clear OpCode" button (or type "Alt+O") and then the "Clear Groups" button (or type "Alt+G"), alternatively type "Alt+X" to reset the finder completely.

Now select "0x0024 Dialogue" from the "OpCode:" drop-down. The TNS style is determined by operand 12 (see here), so enter "5" into the twelth operand box and then click the "FIND BHAVs" button

Click on the "Object / Semi Global" column header to sort by object

(You can also sort by Instance and Name by clicking on the associated column headers)


Which BHAVs create the "Token - Poison Ivy" object

For this we need to know that the GUID of the "Token - Poison Ivy" object is 0x33069756 - this can be found with SimPE. As neither SimPE nor BHAV Finder lock the package they are working on, the same package can be open in both applications at the same time.

Change the "OpCode:" drop-down to "0x2A Create New Object Instance", either delete the value "5" from the twelth operand box or click the "Clear Operands" button. Copy the GUID from somewhere, right click on operand 0 and select "Paste GUID", this will enter 56 into operand 0, 97 into operand 1, 6 into operand 2 and 33 into operand 3; finally click the "FIND BHAVs" button.

Ummm, nothing. Probably not surprising as this is a token object and those are hidden items in a Sim's inventory and hence manipulated with the "Manage Inventory" primitive. Change the "OpCode:" drop-down to "0x33 Manage Inventory", clear operands 0 thru 3, set operand 4 to 0 (see below) and right click operand 5 to paste the GUID; then click the "FIND BHAVs" button.

In case you're wondering, the meaning of the operands for a primitive can either be found on the SimsWiki or by deduction from the SimPE instruction wizard

Operand 4 controls the sub-function of the primitive and 0 corresponds to "Add token of GUID"


Which BHAVs access the Lot Inventory

Type "Alt-C" to clear the operands. By using the SimPE instruction wizard for "Manage Inventory" we can deduce that bits 1 and 2 of operand 0 determine if the global, lot, family or personal inventory is being acted upon. The other bits in operand 0 determine what type of object/token (hidden, memory, etc) is being acted upon.

The lot inventory is 1, so set operand 0 to "1". However, we need to mask out the other bits, so set mask 0 to 3 - if you hover the mouse cursor over this value it will display a balloon with "Binary: 0000 0011" which shows that we're only interested in bits 1 and 2

Click the "FIND BHAVs" button, there are 111 matching BHAVs (in UC/M&G)

To restrict the list to just one object, uncheck "Show Object/Group Names", click to highlight the cell with the object value of interest and copy/paste it into the "In Group:" text area

Recheck "Show Object/Group Names" and press the "F5" key to refresh the list


Which BHAVs call "Want Satisfy - Kiss" in the SofaSocialGlobals

Type "Alt+X" to reset the application and enter "200B" into the "OpCode:" text area (this is the instance id of the ""Want Satisfy - Kiss" BHAV). As this is a semi-global BHAV, a new filter appears; from the "OpCode In:" drop-down, select "0x7F8B4A08 Sofa Social" and click the "FIND BHAVs" button


Which BHAVs use the firefly jar animations

To answer this we need to decide which animation primitive we're interested in, and discover how its operands are used. I'm interested in the "Reach/Put" primitive (0x0074) and this page describes the operands

Type "Alt-X" to reset the application, select "0x74 Reach/Put" in the "OpCode:" drop-down, select "11" from the "Using Operand:" drop-down, select "0x0086 Object Anims" from the "As Index Into STR#:" drop-down, and type "o2a-(jarF|f)irefly-" into the "Matches:" area. Finally, click the "FIND BHAVs" button.


Which mods use the Money Globals?

To answer this we need to specify a directory instead of a specific package to search and a range of OpCodes to look for

Type "Alt-X" to reset the application, select any package in the directory to search and then delete the package name, leaving just the directory part and in the OpCode enter the range as two hex numbers seperated by a colon. Finally, click the "FIND BHAVs" button.


Shortcut Keys

  • Alt+B - Find bhavs
  • Alt+C - Clear operands
  • Alt+F - File menu
  • Alt+G - Clear groups
  • Alt+H - Help menu
  • Alt+M - Clear matching
  • Alt+N - Show group/object names
  • Alt+O - Clear opcode
  • Alt+R - Reset masks
  • Alt+S - Select package
  • Alt+X - Clear all entries (same as Alt+O then Alt+C then Alt+R then Alt+G then Alt+M)
  • Alt+F4 - Exit

  • Ctrl+O - Open file (select package)
  • Ctrl+R - Refresh (find bhavs)

  • F1 - Help (about)
  • F5 - Refresh (find bhavs)

Source Code

Source code can be downloaded from GitHub


Change Log

Version 2.3

  • Added drag-and-drop of a .package file onto the package path area.
  • Remembers last .package file (or folder) used.
  • Added Ignore Case option for "using" matches.
  • Option to save/restore last used filter settings.

Version 2.2

  • Fixed issue with right-click "SimPE Extract" with BHAVs from multiple .package files.

Version 2.1

  • Added "File -> Select Package Folder..." to select a folder instead of a package
  • Shift-click "Select Package..." button opens the "Select Folder" dialog instead of the "Select Package" dialog

Version 2.0

  • Recompiled to fix compression and SimPe issues - see here

Version 1.8

  • Selection mode for the Found BHAVs grid changed from cell to full row.
  • Right-click context menu added to Found BHAVs grid to extract selected BHAVs in SimPE package.xml format

Version 1.7

  • Added "Save Results As..." and "Save Results To Clipboard" options from the file menu. Saves the found BHAVs in CSV format.

Version 1.6

  • "Using op as index into" works for multiple packages in a directory.
  • "Using op as index into" knows about 1-based index primitives 0x001C RTBN and 0x0024 Dialog.

Version 1.5

  • Package Path can be a directory, in which case all .package files within it and any sub-directories will be searched
  • OpCode can specify a range, eg 0x0CA0:0x0CA4

Version 1.4

  • Improved error handling
  • Improved resource usage

Version 1.3

  • GUIDS are always pasted as two hex digits per operand
  • Fixed another bug with selecting the Sims 2 Path (configuration dialog)
  • Added a proper Sims 2 icon
  • Relocated to the Sims2Tools project

Version 1.2

  • Added context menu to first 12 operands with Paste GUID option

Version 1.1

  • Fixed a bug with selecting the Sims 2 Path (configuration dialog)

Version 1.0

  • Initial release


Files