Page 1 of 1

Meta Access Information

Posted: Mon Mar 26, 2007 11:27 pm
by jlddodger
I am working on an application. I need to access meta data. I have successfully calculated the secondary magic. And I understand that the data location is the following:
start of the meta + meta offset + value offset

However, I have found conflicting reports of how to calculate the meta start. One involved subtracting the secondary magic from the meta offset. This makes no sense to me.

I have also been told that one simply adds the secondary magic to the meta offset; however, the secondary magic is greater than the file size. On the other hand, the output of the secondary magic matches the output of DotHalo.

So, what gives?

Posted: Mon Mar 26, 2007 11:47 pm
by Prey
Ok, first of all there are some values you need to take frm the Header:

Code: Select all

            br.BaseStream.Position = 16;

            //the offset of the index
            indexOffset = br.ReadInt32();

            //the total length in bytes of the index
            indexSize = br.ReadInt32();

            //the start of the meta (straight after the index)
            metaStart = indexOffset + indexSize;

            //the total length in bytes of the meta
            metaSize = br.ReadInt32();

            //MetaSize + index Size + BSP Size
            nonRawSize = br.ReadInt32();
Then you goto the index and this is where you get the secondaryMagic:

Code: Select all

            //start of tags + 8 (skips matg tags tagtype and ident)
            br.BaseStream.Position = offsetOfObjectIndex + 8;

            //constant is raw meta offset of matg tag
            secondaryMagicConstant = br.ReadInt32();
            secondaryMagic = secondaryMagicConstant - map.header.metaStart;
Then you read all the tagInfo from the index and subtract the secondaryMagic frm the raw offset each time:

Code: Select all

            for (int x = 0; x < map.index.objectCount; x++)
            {
                //this is the tagtype, they are backward in map so we reverse
                string tt = map.Reverse(new string(br.ReadChars(4)));

                //if its not in the list add it
                if (!tagTypes.Contains(tt)) tagTypes.Add(tt);

                //and this is the rest of the info
                tagsList[x].Type = tt;
                tagsList[x].Ident = br.ReadInt32();
                tagsList[x].MetaOffset = br.ReadInt32() - map.index.secondaryMagic;
                tagsList[x].MetaSize = br.ReadInt32();
            }
Now w/e you need to access the meta of a tag you just need to go to its stored offset - 'br.BaseStream.Position = tagsList[45].MetaOffset;'

Posted: Tue Mar 27, 2007 7:18 am
by jlddodger
Thank you!