1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Hi There! And help!, Confused!

Discussion in 'Tools programming' started by Slopey, 15/5/07.

  1. Slopey

    Slopey

    Joined:
    15/5/07
    Messages:
    26
    Greetings All!

    Possibly a simple one for you - I'm trying to write a little program to parse FSX bgl airport information for a little mission builder program I'm having a go at.

    I've got the FSX file structure pdf and looked at the various code posted to do with extracting ICAO codes which has been an enormous help - I can now extract the relevant info from a specfic position in the bgl file.

    However, if I look at the BGL file header and more specifically the section pointers which come after the header, I'm not able to get the section starting positions to match with whats in the header.

    For example, in my FSX folder in scenery\0000\scenery\APX03070.bgl - if I open that file with a hex editor, I can see the section pointers - I know there are 5 from the main file header at offset 4, and I can see the data therein.

    If I look at the section pointers for that file, theres an airport which starts at offset &9c (156), additional airport info, waypoints and a name list. But the problem is that the airport section actually starts at 284 - SDE and the Hexeditor confirm this.

    Further more, there's only one airport section listed in the pointer section of the file, but there are 2 airports in that file as confirmed by SDE which seems to open the file without any issues.

    I can't parse the entire file for the airport identifier (&003c) as this occurs naturally as data in other places.

    Is the file spec pdf out of date or incorrect? Or am I missing something fundamental? The pointer location is 128 out which is always incredibly suspicious - but although I can find the other airport in the hex file manually, there doesn't seem to be a pointer to it in the header of the BGL??

    Any illumination would be gratefully receieved!

    Kind Regards,
    Slopey
  2. scruffyduck

    scruffyduck Administrator Staff Member FSDevConf team Resource contributor

    Joined:
    17/9/05
    Messages:
    24,482
    Country:
    wales
    I'm not sure I understand. SDE and BglAnalyzeX both use the basic description of Bgl headers. It has not changed since FS9 (although information in some of the records have). What language are you writing your code in?
  3. Slopey

    Slopey

    Joined:
    15/5/07
    Messages:
    26
    Hi,

    It's in VB.Net, but that's an aside - if Im looking at the bgl file with a hex editor, and the section pointer for the first airport in the file has 9c 00 00 00 as the offset from the start of the file to the section, I would expect that section to start at the 156th byte wouldn't I?

    Cheers,
    S.
  4. scruffyduck

    scruffyduck Administrator Staff Member FSDevConf team Resource contributor

    Joined:
    17/9/05
    Messages:
    24,482
    Country:
    wales
    If you are using SDE then you can see the offset information by using the rawdata view. This will also show the hex values relating to the object

    Are you saying that your code is not getting the right data at the offset you mention? or are you having a problem seeing things in the hex editor

    Looking at the file with SDE I see that there are two airport records and they start at 284dec. The first is PAPO starting at 284 and is 5892 bytes long; the second is PALU starting at 6176dec and is 2240 bytes long
  5. Slopey

    Slopey

    Joined:
    15/5/07
    Messages:
    26
    I'm having a problem in that the section doesn't start at the position given in the section pointer.

    When I look at the bgl with a hex editor, according to the section pointer it says the airport section should start at position 156, when in fact it starts at 284 as SDE shows.

    How does SDE find the various sections, does it parse the section pointers in the header area? And if so, how do you get the offset to be 284 from the given 9c?

    If I scroll down the bgl file in the hex editor, I've no problem finding the appropriate section and my code extracts the correct info if I give it the correct offset to start at, it's finding that initial offset which is causing me problems as it's not where the section pointer says it should be. Unless I'm missing something.
  6. scruffyduck

    scruffyduck Administrator Staff Member FSDevConf team Resource contributor

    Joined:
    17/9/05
    Messages:
    24,482
    Country:
    wales
    There are 56 bytes in the main header (0x38) and then each section pointer record is 20 bytes. Winfried makes a mistake in his documentation describing 0x38 as 54 bytes when in fact it is 56 bytes - are you OK with that?
  7. Slopey

    Slopey

    Joined:
    15/5/07
    Messages:
    26
    Yes - I figured that out earlier.

    Here's the first 80 bytes of APX03070.bgl:

    Code:
    01 02 92 19 38 00 00 00 70 d1 22 cd b1 bd c6 01 
    03 18 05 08 05 00 00 00 fc 02 08 00 f9 02 08 00 
    fb 02 08 00 fc 02 08 00 fe 02 08 00 00 00 00 00 
    00 00 00 00 00 00 00 00 03 00 00 00 01 00 00 00 
    01 00 00 00 9c 00 00 00 10 00 00 00 2c 00 00 00 
    Now, according to the pdf (taking the 56 header bytes into account), the section pointer starts on line 4 and runs for 20 bytes, which if I break down, should give:

    Code:
    03 00 00 00 <- Offset 0x00, Airport
    01 00 00 00 <- Offset 0x04, Unknown
    01 00 00 00 <- Offset 0x08, Num subsections
    9c 00 00 00 <- Offset 0x0c, Offset from file start to section header
    10 00 00 00 <- Offset 0x10, Size of section header
    
    So according to me, the section identified by this section pointer inside the BGL file should start at offset 0x9c, or Byte position 156? No?
  8. scruffyduck

    scruffyduck Administrator Staff Member FSDevConf team Resource contributor

    Joined:
    17/9/05
    Messages:
    24,482
    Country:
    wales
    No - you are missing a step. There are 56 Bytes that make up the Bgl Header. Following that are Section Pointers each of 20 Bytes. They do not identify the start of a record (e.g Airport Record) but the location of the Section Header and that points to the actual records. In the case of this Bgl there are 5 Section Pointers of 20 Bytes (100 in total) so the location of the first Bgl Section Header is going to be 156. This happens to be a section header for the airports. So you now need to look at the Section Header staring at 156. These are described in the documentation and each one is 16 Bytes. The DWORD starting at byte 0x08 is the pointer to the first real record - in this case it should be te first airport. This is at 0xA4 and that points at 0x11c. I see at 284 (0x11C) a value of 3C that is the start of Point Hope where SDE finds it.
  9. Slopey

    Slopey

    Joined:
    15/5/07
    Messages:
    26
    Ahh haaa! I knew I was missing something!

    Right so the section pointer points to the section header which then contains the offset to the subjection I'm interested in.

    Got it :)

    Many thanks - I was going round and round with that one - too many sections/headers/pointers, I think I was getting myself in knots with the nomenclature!

    Again, many thanks - I'll go give it a whirl! :)

    Cheers,
    S.
  10. Slopey

    Slopey

    Joined:
    15/5/07
    Messages:
    26
    Right - got it now. I can correctly find and pick up the first airport in the bgl file, PAPO, not quite got to the bottom of where the second one (PALU) is yet, but I think that's referenced on a section header subrecord and I just need to track back to find it :) (hopefully)

    ** scratch that - it's in the airport subsection block, immeadiately after the first airport. I can work that back from the section size, minus the current airport size :)
    Last edited: 17/5/07

Share This Page