Cosmo's Cosmic Adventure II: The Humanizer Thread

Anything related to Keen Modding.
User avatar
T-Squared
Posts: 143
Joined: Mon Dec 01, 2008 6:11 pm
Location: San Antonio, Texas
Contact:

Post by T-Squared »

levellass wrote:Do we have the level format anywhere?
Yes, on the Modding Wiki:

http://www.shikadi.net/moddingwiki/Cosmo_Level_Format

but the format breakdown is very rough and is hard to quantize. (e.g. For the music index of the iFlags value, what's the smallest value that each of those symbols refer to? Would one of those symbols refer to a bit [0 or 1] or an actual byte [0 to F] like it says on the page?)
User avatar
Malvineous
Posts: 113
Joined: Sat Mar 13, 2004 12:54 am
Location: Brisbane, Australia
Contact:

Post by Malvineous »

On the ModdingWiki page, if you look in the "File format" section you can see the iFlags data type is UINT16LE. This is a little-endian 16-bit number. Under level flags it tells you the structure of the *bits* in the iFlags value, so it's telling you how these 16 bits are arranged. You'll notice that it says "[ mmmmm | ppp | yxr | bbbbb ]" which contains 16 letters (you ignore the spaces and lines as they are just there as a visual aid) so this is the arrangement of the 16 bits in the iFlags value.

The bits are always written from most significant to least significant, so the first "m" will have a decimal value of 32768 and the last "b" will have a value of 1. If you are interested in rain, it is bit number 6, so it will have a value of 2^6 (two to the power of 6) or 64.

To set the value, you'll need to take the first two bytes in the map file. They are little endian, so the bytes are swapped. If the bytes (in hex) are 34 12 then they are the hex value 1234, or the decimal value 4660.

To figure out whether the rain flag (64) has been set, you need to use a logical AND. 4660 AND 64 is equal to 0, so the flag has not been set (it would be equal to 64 if it was set.)

To actually set the value, you need to use a logical OR. You can also cheat and just use normal addition, but addition will let you add the same value twice which will stuff things up, while you can perform a logical OR as many times as you like and it won't break anything. So 4660 OR 64 is equal to 4724 (again, 4660+64 is also equal to this) so this is the value to write back into the file.

Going backwards, 4724 is 1274 in hex, so swapping the bytes means you will write hex bytes 74 12 back to the start of the file (overwriting the original 34 12) to save this value.

Likewise you can replace the other values the same way. It's a little more complex for the music and palette animation values because they have multiple bits (so they have a wider range of values than just 0 or 1 like the rain flag) but you really need to know how to perform "bit shifts" (like "shift left" and "shift right" in order to manipulate these values easily.)
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Or someone could write a little utility for it, it wouldn't be hard.
User avatar
Malvineous
Posts: 113
Joined: Sat Mar 13, 2004 12:54 am
Location: Brisbane, Australia
Contact:

Post by Malvineous »

Very true, but that would involve relying on someone else! I figured if I explained how to do it manually then anyone can do it themselves.

But fair point - so I made the flags available as Camoto map attributes:

Image

Interestingly enough the palette animation flags don't seem to do anything. If I set it to enable lightning then I can hear the thunder sound effect, but there are no flashes. Even if I set it to background 0 (bdblank.mni) then there is no animation. (Incidentally, bdblank.mni seems to result in a mildly corrupted background instead of an entirely blank one - same as setting a non-existent file as the background.)

EDIT: Oh now I see, only dark magenta (EGA colour 5) is actually animated, so if that's not in the backdrop image then there won't be any visible animation. Now I understand why bdspooky.mni has so much magenta in it - that's what gets replaced with black and white for the lightning flashes.
Last edited by Malvineous on Thu Nov 14, 2013 9:47 pm, edited 1 time in total.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Heh, that's right, it's quite common (See Dave 2) in ID\Apogee games. Another case of if it ain't broke, don't fix it.
User avatar
T-Squared
Posts: 143
Joined: Mon Dec 01, 2008 6:11 pm
Location: San Antonio, Texas
Contact:

Post by T-Squared »

Malvineous wrote: To set the value, you'll need to take the first two bytes in the map file. They are little endian, so the bytes are swapped. If the bytes (in hex) are 34 12 then they are the hex value 1234, or the decimal value 4660.

To figure out whether the rain flag (64) has been set, you need to use a logical AND. 4660 AND 64 is equal to 0, so the flag has not been set (it would be equal to 64 if it was set.)

To actually set the value, you need to use a logical OR. You can also cheat and just use normal addition, but addition will let you add the same value twice which will stuff things up, while you can perform a logical OR as many times as you like and it won't break anything. So 4660 OR 64 is equal to 4724 (again, 4660+64 is also equal to this) so this is the value to write back into the file.

Going backwards, 4724 is 1274 in hex, so swapping the bytes means you will write hex bytes 74 12 back to the start of the file (overwriting the original 34 12) to save this value.

Likewise you can replace the other values the same way. It's a little more complex for the music and palette animation values because they have multiple bits (so they have a wider range of values than just 0 or 1 like the rain flag) but you really need to know how to perform "bit shifts" (like "shift left" and "shift right" in order to manipulate these values easily.)
Or we could try the lazy approach I just found today that is only available at the moment on Mac OS's Calculator. I'll try to start writing it up tomorrow.
User avatar
Fleexy
Site Admin
Posts: 490
Joined: Fri Dec 12, 2008 1:33 am
Location: Bloogton Tower

Post by Fleexy »

Windows Calculator in Programmer mode allows bit manipulation.
User avatar
T-Squared
Posts: 143
Joined: Mon Dec 01, 2008 6:11 pm
Location: San Antonio, Texas
Contact:

Post by T-Squared »

Fleexy wrote:Windows Calculator in Programmer mode allows bit manipulation.
You mean as in it can show individual bits like I found on Mac OS's calculator?
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Yes.

Image
Post Reply