View Single Post
Neobeo

JCF Member

Joined: Sep 2002

Posts: 409

Neobeo is an asset to this forumNeobeo is an asset to this forum

May 24, 2007, 12:44 AM
Neobeo is offline
Reply With Quote
Ok, I'd like to think I wasn't being a wet blanket, but many of the methods you have been discussing are stepping off the wrong path. So before we begin, I'd like to give a quick tutorial on how JCS.ini utilises bitfields.

Diagram 1.1
Code:
46=046|046||Param1:-8|Param2:-8|Param3:-8
                    ^         ^         ^
     bitfields -----|---------|---------|
Ok, so each event in JJ2/BC/JCS/BCCS is represented as a 32-bit structure. Of these 32 bits, the event ID already ranges from 0 to 255, which takes up 8 bits. Then the "generic event properties" such as the Difficulty and Illuminate Surroundings takes up another 4 bits. This leaves us with another 20 bits we can use for the parameters. So how do we inform JCS how many bits each parameter takes? By specifying the bitfield in JCS.ini as shown above in diagram 1.1.

In the example above, parameter 1 uses 8 bits, parameter 2 uses another 8 bits, and parameter 3 uses yet another 8 bits. That's a total of 24 bits, so in fact 4 bits are being discarded because there is no space to store them.

What about the negative sign, you ask? Ok, a bitfield of 8 means it takes up 8 bits, and is an unsigned value (i.e. 0 to 255). But if it is given a negative sign, -8, it also takes up 8 bits but is given a signed value (i.e. -128 to 127). Either way, the number of bits taken by the parameter is 8.

As an example, lets take event 192 (gem ring), which is given the parameters Length:5 | Speed:5. So if we gave it a length of 7 and a speed of 1, it would look like the following:

Diagram 1.2
Code:
1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<-------> <-------> <----------------->
 length    speed     unused extra space
This works perfectly fine. However, if were to read the same bitfield using a different parameter setting, of lets say, Length:-8 | Speed:-8 | Param3: -8, it would look something like the following:

Diagram 1.3
Code:
1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<-------------> <-------------> <------
  length = 39       speed = 0   overflow
As compared to diagram 1.2 before, this gives you a wrong reading for both length and speed. Not to mention that overflowing the 3rd parameter can have serious consequences. With that said, let's go through the problems and fix them one by one.

Quote:
Originally Posted by Jerrythabest View Post
-Replace event 46 of JCS.ini (you may want to back up the original event 46 by putting ';' in front of it; JCS will ignore that line in the file then) with this: 46=046|046||Unknown1XXX:30|Unknown2:10|Unknown3:10 |Unknown4:10
This does not happen only with event 46, but any event, as long as the bitfields are nonsensical like that. The first bitfield, 30, already pretty much overflows the buffer, so none of the 3 parameters would make any sense.

Quote:
Originally Posted by Jerrythabest View Post
EDIT: And I seem to have found a very weird 'BatteryCheck Rule': all events' parameter #3 has the event number as their value.
This rule is not valid. Maybe if you set the bitfields param1+param2 to equal to twenty, param3 would overflow back to the event number.

Quote:
Originally Posted by Jerrythabest View Post
Well, you are right: on that paramter some values happen to be below zero... though actually that number was not negative
No, it was not negative. The number that was given is correct, just that your bitfield was specified incorrectly.

Quote:
Originally Posted by Jerrythabest View Post
EDIT: and that rule I stated above is only true if you set all event parameter value ranges in jcs.ini to 10...
Ah ok, you corrected the above mistake. I didn't notice this earlier.

Quote:
Originally Posted by Jerrythabest View Post
I think the paramter values are only accurate for JCS.ini value ranges of -8 to 8 (which results in ranges from -128 - 127 to 0 - 255 in JCS) as I think these values are stored as a singe byte in the j2l file, and thus only support 256 different possibilities.
It is still wrong to assume all bitfields are of size 8. Some boolean values that do not need to be anything other than 0 or 1 can just have a bitfield of 1. Also, the bitfields need not be stored in a single byte. In fact they are usually spread out, eg, 3 bits in one byte and 5 bits in another byte.

Quote:
Originally Posted by Jerrythabest View Post
Stuff looks a lot more 'normal' right now, as I can't find any values above 100 very fast atm and there are no stupid rules ;p

EDIT2: actually there is a rule: parameters 1 + 5 and 2 + 6 are always identical, but I think that simply means BC (or 1.10o? don't feel like checking) uses only 4 parameters... I'll just leave 5 and 6 out.
Assuming all your bitfields here are of size 8, then param1+param2+param3+param4 will have a size of 32, which is the entire event. So param5 will overflow exactly one event length and end up back at param1. Same goes to param6. As long as the bitfields don't exceed 20, you can have as many parameters as you want.

Quote:
Originally Posted by Jerrythabest View Post
EDIT: Parameter 4 happened to be 'automatically set' too, so I removed that one from the ini file too.
Same as above. Param1 + param2 + param3 = bitfield > 20, so param4 overflows and is not safe to use. In fact param3 already overflows.

Quote:
Originally Posted by Jerrythabest View Post
Results of the investigation of Binnen.j2l after some nice hours of work:

-- code cut out --

High positive values are most probably all ID parameters. I'm surprised by the number of big ranges though: that means at least one event in the level had a value for that parameter lower than -64 or higher than 63...
Again, your ranges are restricted only by your choice of bitfields for each parameter. Not all parameters would need an entire 8 bits since they would only need to represent minimal data.

That said, that effort has not gone to waste at all! You have correctly stated that events 1, 17, 29, 50, 52, 53, 60, 62 and 63 have no parameters, thus can be kept "unparametered" in JCS.ini. Equally correct is that events 42, 51 and 55 have exactly 1 bool value, which means only one bit is used out of the twenty. Thus they can have a parameter like Param1:1.

Also, the results of your previous experiment, while not using the correct bitfields, need not be completely discarded. You could convert the parameters to binary fields and then use analysis to figure out the appropriate bitfields to use for each parameter.
__________________
<TABLE border=1><TR><TD>Facts:
Jazz Sprite Dynamite (JSD)
Tileset Extractor
Neobeo's Firetruck

</TD><TD>Myths:
Jazz Creation Station Plus (JCS+) - 10%
Coming soon - a dedicated server! - 25%
Jazz Sprite Dynamite v2 (JSDv2) - 2%
Another generic single-player level - 0%
</TD></TR></TABLE>