Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Slippery When Wet
Original Poster
#1 Old 2nd Jan 2006 at 7:16 PM Last edited by tunaisafish : 14th Jan 2006 at 1:41 PM. Reason: Update of BHAVs with more than 8 param
Default BHAV to BHAV Parameters
In the process of writing my first mod, I found that both DisaSim and the PJSE plugin were not intepreting what parameters were being passed correctly in some cases.

This is the result of my research that followed.
It's pure reverse engineering of what actually happens now with various data thrown at a BHAV. So you probably won't find all examples in Maxis code, but in your own code it may help track down some unexpected behaviour. 1 mis-typed bit could make all the difference.

Thanks to Dizzy2 and P.Jones for their source files that got me started.

I used a private function to pop-up a dialog to compile these parameters.
Not tested whether global or semi BHAVs are different, but assume (hope) they are. I experimented with formats 8007 and 8009, and with the flags = 6, but no differences were seen.

Below is obviously not PHP, but I couldn't find the pre tags, and code looked too spaced.
[PHP] Passing Parameters from BHAV to BHAV
(Applicable to TS2 + EP1 + EP2)

P_in = How many params declared in this BHAV
P_out = How many params declared in called BHAV

NV = Node Version (0 or 1)
b[n] = Operand bytes (0 to 15)
Kill = true when b[0..7] == 0xffffffffffffffff

X = b[12]
X0 = bit0
X1 = bit1
X72 = true when (X & 0xFC) == 0xFC


Truth Table for P_out > 0

NV X72 X1 X0 Kill P_out Method
0 ? ? 1 0 <9 4OI
0 ? ? 1 0 >8 NAR
0 ? ? 1 1 ? NAR
0 ? ? 0 0 ? 8C0
0 ? ? 0 1 ? UNK
1 1 1 1 0 ? 8C1
1 1 1 1 1 ? UNK
1 0 1 1 0 <9 4OI
1 0 1 1 0 >8 NAR
1 0 1 1 1 ? NAR
1 ? 0 1 0 <9 4OI
1 ? 0 1 0 >8 NAR
1 ? 0 1 1 ? NAR
1 ? 1 0 0 <9 PAR
1 ? 1 0 0 >8 NAR
1 ? 1 0 1 ? NAR
1 ? 0 0 0 ? 8C1
1 ? 0 0 1 ? UNK
>1 ? ? ? ? ? not tested

Method Key
NAR - no args
PRM - Use Parameters
8C0 - 8 Constants 0
8C1 - 8 Constants 1
4OI - 4 Owner Indices
UNK - Unknown

What Is Passed

Up to 8 shorts can be passed by all methods.
If P_out > 8, then pad the params over the 8th with unknown shorts.

NAR - no args
passes up to 8 shorts of 0x0

PRM - Use Parameters
Up to 8 shorts as currently defined in Params[0 .. (P_in - 1)]
Pad remaining up to 8th with 0x0

8C0 - 8 Constants 0
Set b[12] to 0
Up to 8 shorts read in LE order from b[0..15]

8C1 - 8 Constants 1
Up to 8 shorts read in LE order from b[0..15]

4OV - 4 Owner Indices
Up to 4 shorts defined in b[0..11] (owner1,low1,high1,...)
followed by 4 shorts of 0x0.

UNK - Unknown
Up to 8 (seemingly random but repeatable) shorts.[/PHP]

Related notes:

Parameters are passed by value.
ie. The called BHAV can change the params without changing the callee params.
If you want to pass by reference, use Temps.

I've only seen one BHAV, an entry point, that declares more that 8 params.
I've not searched for others.
# Group = 0x7FD0DEBA, Instance = 0x2009
# Title = Function - Portal - Test - SG
# Format = 8009, Params = 10, Locals = 0
This BHAV is also called from a Myne door BHAV with no args!

Edit: I've now searched for others.
BHAVs with more than 8 params from EP2 objects.package

Group/Instance/Params/Title
7F0C60C8 2002 9 Portal
7F117CD9 2005 9 Function - Portal
7F429113 1001 9 Function - Portal
7F429113 1002 9 Function - Portal - TEST
7F585FFD 1006 9 Function - Portal
7F585FFD 1007 9 Function - Portal - TEST
7F5BA5F7 1005 9 Function - Portal - TEST
7F5BA5F7 1006 9 Function - Portal
7FD0DEBA 1009 10 Function - Portal - Test - SG
7F739728 100F 13 CT - Handle Grow Up Feedback
7F739728 1142 14 CT - Handle Feedback - Verify All
7F739728 1003 15 CT - Handle Feedback
7F739728 11A7 15 CT - Handle Feedback - Lifetime Want
Advertisement
Don't ask me, I just code
#2 Old 7th Jan 2006 at 6:27 PM Last edited by pljones : 7th Jan 2006 at 7:23 PM.
Restating that truth table in a slightly different order:[PHP]NV X72 X1 X0 Kill P_out Method
0 ? ? 0 0 ? 8C0
1 ? 0 0 0 ? 8C1
1 ? 1 0 0 <9 PRM
1 ? 1 0 0 >8 ZER

0 ? ? 0 1 ? UNK
1 ? 0 0 1 ? UNK
1 ? 1 0 1 ? ZER


0 ? ? 1 0 <9 4OI
1 ? 0 1 0 <9 4OI
1 0 1 1 0 <9 4OI

0 ? ? 1 0 >8 ZER
1 ? 0 1 0 >8 ZER
1 0 1 1 0 >8 ZER
0 ? ? 1 1 ? ZER
1 ? 0 1 1 ? ZER
1 0 1 1 1 ? ZER


1 1 1 1 0 ? 8C1
1 1 1 1 1 ? UNK[/PHP]
I then derive the following:
[PHP]if (!x0) {
if (!kill) {
if (nv == 0 || !x1) do8Cx();
else {
if (P_out < 9) doPRM();
else doZER();
}
} else {
if (nv == 0 || !x1) doUNK();
else doZER();
}
} else { // x0 set
if (nv == 0 || x != 0xFF) {
if (!kill && P_out < 9) do4OI();
else doZER();
} else {
if (!kill) do8C1();
else doUNK();
}
}[/PHP]
Hopefully that makes sense...
Slippery When Wet
Original Poster
#3 Old 7th Jan 2006 at 8:22 PM Last edited by tunaisafish : 7th Jan 2006 at 8:26 PM. Reason: typos
Thanks for that Peter,

Looks like the correct logic to me.
V. nice. It made my brain hurt just following it.

I am going to write a script sometime to analyse the three object.package's (disaSim dump) to count the frequency of each variation used in Maxis code. That should give a better idea of what Edith spits out.
The alg. for that will be horrid.

BTW, Have only seen NV>1 for primitive 0x6D "Change Material".
None in base game. Seen 2 in EP1. Seen 2 & 3 in EP2.
One horse disagreer of the Apocalypse
#4 Old 7th Jan 2006 at 9:17 PM
I hope you're gonna test this for us, because I don't think I'd know if it was right or wrong! Are you in the SimPE QA group?

"You can do refraction by raymarching through the depth buffer" (c. Reddeyfish 2017)
Slippery When Wet
Original Poster
#5 Old 8th Jan 2006 at 1:56 AM
Course I'll test it

I've just applied for the QA group. If you want me to test it before I get admitted either mail it to me or put a test plugin up on your site.
One horse disagreer of the Apocalypse
#6 Old 8th Jan 2006 at 8:50 AM
I put up two compilations, one of which is useable in SimPE 052. I put them in their own thread on Simlogical forums.

"You can do refraction by raymarching through the depth buffer" (c. Reddeyfish 2017)
Don't ask me, I just code
#7 Old 14th Jan 2006 at 9:44 AM
Quote:
Up to 8 shorts can be passed by all methods.
If P_out > 8, then pad the params over the 8th with unknown shorts.

Don't know how much investigation you did around this...

I'm wondering if these are from previous calls:

BHAV 0x1000 (don't care on ArgC)
0x0000: [private 0x1001] Call to Bhav (no args)
(nv = 0, 0101 0202 0303 0404 0505 0606 0700 0808)

BHAV 0x1001 (ArgC 0)
0x0000: [private 0x1002] Another BHAV (10 args)
(nv = 0, 1111 2222 3333 4444 5555 6666 7700 8888)

Then display the results of what BHAV 0x1002 receives. I'm expecting it to get the eight shorts from 0x1001 plus two from the call to 0x1001 (because 0x1001 declares that it doesn't use them). Just a theory, anyway... (This is why I used to label these "unknowns" as "caller's params". I've not tested it either...)
Slippery When Wet
Original Poster
#8 Old 14th Jan 2006 at 1:42 PM Last edited by tunaisafish : 14th Jan 2006 at 1:44 PM. Reason: grr... stupid formatting
Peter, I just tried that, but we still don't know what they are.

I used 2 different sims (+ 1 in another lot) and called...

'show 10 args' through 'has no args' (as you suggested)
'show 10 args' through 'has 8 args'
'show 10 args' directly.

In all 9 cases the unknown params (8,9) held values (1,0).

I did the initial experiments over a long weekend, and I'm sure I thought along the same lines during that time. ie. I got to thinking that there was a param stack that pushed and popped 8 shorts as it passes in and out of subs, and that the game passes a larger stack to the initial EP. I tried loads of things but could never pass more than 8 param from a BHAV.
Even cloning a portal bhav where there are 10 valid args loses the last 2 if you try to pass them all along to another with 10.
The other 'UNK' function had reapeatable values being passed too, but they did not relate to the initial parameters either, nor to any values in the logs dumped for that lot.

I've updated the first post with the full list of BHAVs that declare more than 8 parameters. It's the same list I showed you earlier Peter, but if others are working in those areas and find those being called somewhere, please let us know.
Don't ask me, I just code
#9 Old 21st Jan 2006 at 6:57 PM Last edited by pljones : 21st Jan 2006 at 6:58 PM. Reason: Forgot to mention reason for posting...
(oops, thought I was subbed to this thread.)

/me stomps around. "I don't like 'unknown'..."

There are too many variables for my liking, too. ArgC and Kill are going to interact somehow.

Thanks for looking, anyway!
Back to top