Sign in to follow this  
Guest tdragger

Anyone know how MS code ICAO in the BGL files?

Recommended Posts

After the recently release of the BGLCOMP SDK I started my 'GA AI Traffic generator' project. Part of this project is to examine every airport BGL file (Stock and usermade) and count the numbers/types of GA parking places. The programm should be able to manipulate the GA traffic at airport level up to global world settings. For showing airport data I tried to read the ICAO (called identifier in the SDK) of the airport BGL. But there is a problem, MS used 4 Bytes to store the 5 charcters you could use for the identifier. I found that they use only capatials and numbers, so they could use a 7 Bit code. But if I loock with a hexeditor I couldn't identify the coding MS did. I know the place where the 4 Bytes are stored, I tried several alphanumerical identifiers, but I didn't find the algorithm :-(It loock like they use 3 Bit fileds for coding, but I didn't see the formular.So is anyone know how to get the ICAO string back out of the BGL file?Please help

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

It's definitely an interesting data scheme. It took quite a few sample BGLs and some time in Excel to figure this out. Basically, each letter is a digit in a base 38 number scheme.There are 38 possible values for each position. 0 seems to signify an empty space, I'm not sure what 1 means, 2-11 are "0"-"9", and 12 is the first letter ("A").Start by shifting the 32 bit value right by 5. Only the top 3 bits of the lowest byte are used. After that each character can be pulled off by dividing and mod'ing the 27-bit value with 38.So for a 27-bit value X, char n = ( X / 38^(n - 1) ) mod 38As an example, here's KPDX (0x0260c721): 0x0260c721 >> 5 = 0x130639 = 1246777 ( 1246777 / 1 ) mod 38 = 35 ("X") ( 1246777 / 38 ) mod 38 = 15 ("D") ( 1246777 / 1444 ) mod 38 = 27 ("P") ( 1246777 / 54872 ) mod 38 = 22 ("K") ( 1246777 / 2085136 ) mod 38 = 0 ("")So, I have a question for you as well. I can't figure out how to find the location of the ICAO, airport name, etc. within the BGL. I assume that there is an offset of some sort in the BGL header that points to it. Do you know what that would be and how to find it?Thanks,Eliot

Share this post


Link to post
Share on other sites

Hi Eliot,thanks for youre help. Meanwhile I figured out the scheme too.So you loock for the Offset where the data is stored?I'm not totally finished with my analyze of the new FS2004 BGL's but, as far as I know there is no a fixed offset.The new BGL have a header which is 0x37 Bytes long. This header contains the filetime at offset 0x08. A BGL with airport(s) structure in has at 0x38 a data structure of at least 10 Bytes. The last 4 Bytes are a offset to the next structures. The following values I didn't fully understand, but it loock that they are 16 Bytes long structs. The number of structs is the part I didn't found out. Sometimes there are two 16 Byte structs for every airport and sometimes not. After those structs there is a structure starting with 0x00000002 next 4 Bytes are the number of airports and the next 4 Bytes are the offset to the name table. This table is easy to read:0x00000027 struct value2 Bytes unknown2 Bytes number of countrys2 Bytes number of region2 Bytes number of city2 Bytes number of Airport name2 Bytes number of ICAO4 Bytes relative offset to country table4 Bytes relative offset to region table4 Bytes relative offset to city table4 Bytes relative offset to Airport name table4 Bytes relative offset to ICAO tableIf I found out what the 10 Bytes struct means which I don't know I will inform you, maybe you could contact me by e-mail (in_04@web.de) if you found something intresting out.

Share this post


Link to post
Share on other sites

Thanks Markus. Thats good information to have.I actually found a shortcut for getting the ICAO in AFD-only BGLs. The 32-bit value can be found a second (or 3rd in some cases) time 12 bytes from the end of the file. This seems to be consistant for BGLs generated by both AFCAD and bglcomp. I haven't tried this on a bglcomp-created BGL that contains scenery in addition to AFD data, but I'm assuming this trick won't work. The SDK as well as your information above seems to imply that a BGL can contain multiple AFD entries.Eliot

Share this post


Link to post
Share on other sites

Hi Eliot,yes the BGL's could contain multiple AFD entries, but I managed to read them too. I use MS Visual C++ Version 6.0. So if you wish I can send you the code for reading.

Share this post


Link to post
Share on other sites

Many thanks for this, I've been masking and shifting for hours and got nowhere.I think there's a few of us on the same track here, trying to extract facility data from the new BGL. I'm going the long way around using BGLCOMP to generate BGL's and doing a lot of diff comparisons.RegardsEd.

Share this post


Link to post
Share on other sites

I'd just be very careful how and where I used the data, if I were you. The license agreement for both FS and the SDK explicitly prohbit decompilation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this