This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [QUESTION] Parsing ADTs..  (Read 2526 times)

Neglected

  • Registred Member
  • MS Paint Freak
  • *****
  • Posts: 3
    • View Profile
[QUESTION] Parsing ADTs..
« on: November 11, 2011, 07:34:39 pm »
Hey there guys :)

Right now I'm working on a small project where I parse ADTs and WDTs and then display them in an OpenGL window. Nothing too special, just to test mah skeeeelz as it were.

Anyway, I've run into a roadblock parsing ADT files. The issue being that, while I can read every chunk header absolutely fine, and all the data from a WDT file just fine, any data in the ADT seems to be out of whack. See below for more on what I mean..

Code: [Select]
MHDR: flags=0
MHDR: OffsetInfo=0
MHDR: OffsetTex=0
MHDR: OffsetModel=0
MHDR: OffsetModelId=0
MHDR: OffsetMapObj=0
MHDR: OffsetMapObjId=0
MHDR: OffsetDoodadDef=4251
MHDR: OffsetObjDef=4243
MHDR: pad1=4235
MHDR: pad2=4227
MHDR: unk1=4219
MHDR: unk2=4211
MHDR: unk3=4168
MHDR: unk4=64
MHDR: unk5=-1097516758
MCIN: entry0={flags=1740, aSyncId=450019, MCNK_Offset=0, size=0}
MCIN: entry1={flags=1740, aSyncId=448271, MCNK_Offset=0, size=0}
...
MCIN: entry251={flags=1740, aSyncId=11271, MCNK_Offset=0, size=0}
MCIN: entry252={flags=1740, aSyncId=9523, MCNK_Offset=0, size=0}
MCIN: entry253={flags=1740, aSyncId=7775, MCNK_Offset=0, size=0}
MCIN: entry254={flags=1740, aSyncId=6027, MCNK_Offset=0, size=0}
MCIN: entry255={flags=1740, aSyncId=4279, MCNK_Offset=0, size=0}
MTEX: texture_path_34=
MCNK: flags=0
MCNK: indexX=1296257861
MCNK: indexY=0
MCNK: nLayers=1296253260
MCNK: nDoodadRefs=0
MCNK: ofsHeightMap=0

The above is an excerpt from the log that I write to every time  I parse a file. I parse a file by creating a new instance of my Chunk class (which automatically reads the Chunk header in the current input stream and automatically reverses the data so it's in BIG_ENDIAN rather than LITTLE_ENDIAN. I'm following the Wiki TO THE LETTER on the info about ADT and it jut seems that the numbers are parsing incredibly wrong. Take MCNK.nLayres, which is 1296253260, for example. It just doesn't seem right.

Any ideas on where I am going wrong?

My thoughts are that the wiki lists the ADT format in Little Endian.

EDIT: And posted in the wrong forum. Sorry, I googled and found another support post in this forum and thought "OHAI I'LL POST HERE". :c
« Last Edit: November 12, 2011, 05:28:37 pm by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [QUESTION] Parsing ADTs..
« Reply #1 on: November 11, 2011, 07:58:56 pm »
You're having a pointer off. Your nLayers is the beginning of a zero-size MCAL. Seems like you're taking the wrong offset to start at.
Also: the wiki is on WotLK files!
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Neglected

  • Registred Member
  • MS Paint Freak
  • *****
  • Posts: 3
    • View Profile
Re: [QUESTION] Parsing ADTs..
« Reply #2 on: November 11, 2011, 09:00:56 pm »
Quote from: "schlumpf"
You're having a pointer off. Your nLayers is the beginning of a zero-size MCAL. Seems like you're taking the wrong offset to start at.
Also: the wiki is on WotLK files!
Ah awesome, thanks. :)
And I'm using the custommap1 blank map from these forums :P

What I was doing is using a FileInputStream in Java and reading chunks by finding the chunk header and then turning that into a ByteBuffer - reading procedurally. Gonna try and find this MCAL now. Thanks for your help Schlumpf. :)


EDIT: When you were talking about MCAL I assume you were talking about it at the end of my parse; I was more concerned with the start of the parse. I reversed the read direction (back to little endian) to get this:

Code: [Select]
MHDR: unused4=0
MHDR: unused3=0
MHDR: unused2=0
MHDR: unused1=0
MHDR: offsetMTFX=0
MHDR: offsetMH2O=0
MHDR: offsetMFBO=0
MHDR: offsetMODF=4251
MHDR: offsetMDDF=4243
MHDR: offsetMWID=4235
MHDR: offsetMWMO=4227
MHDR: offsetMMID=4219
MHDR: offsetMMDX=4211
MHDR: offsetMTEX=4168
MHDR: offsetMCIN=64
MHDR: flags=-1097516758

Which makes more sense - but those flags.. wtf is up with that? Is that intended or is it a red herring?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Steff

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 4551
    • View Profile
Re: [QUESTION] Parsing ADTs..
« Reply #3 on: November 11, 2011, 09:46:50 pm »
You should use original blizz files for such a test. The custommap files are created with taliis. So it can be that they are not 100% ok.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »
Please mark as solved if solved.
Don't ask if you could ask a question... JUST ask the Question.
You can send me also offline messages. I will answer if I get online.
Skype: project.modcraft
Discord: steff#6954

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [QUESTION] Parsing ADTs..
« Reply #4 on: November 11, 2011, 10:02:08 pm »
Add 0x14 to all offsets.

You may always want to start reading a chunk by comparing the identifier. At 0x0 in the file you should get 'MVER'.

This is not the case with your reading. It is not the file being wrong, but as said, you reading starting at the wrong position.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Neglected

  • Registred Member
  • MS Paint Freak
  • *****
  • Posts: 3
    • View Profile
Re: [QUESTION] Parsing ADTs..
« Reply #5 on: November 11, 2011, 10:31:23 pm »
Quote from: "schlumpf"
Add 0x14 to all offsets.

You may always want to start reading a chunk by comparing the identifier. At 0x0 in the file you should get 'MVER'.

This is not the case with your reading. It is not the file being wrong, but as said, you reading starting at the wrong position.
Just started using official Blizz files and the reading is going fine so far, but the MCNK part still seems to be out of it.

I'm not actually reading by offsets, btw, I'm reading the file as a whole, so the need for offsets is largely negligble. That is, I'm doing something like this..

Code: [Select]
 Read MVER
  // now we've read the MVER from the file, the FileInputStream increments it's position, so the next chunk will be MHDR
  Read MHDR
  Read MCIN
  Read MCNK // This is where I am having trouble.

I am always comparing the Chunk header, and whenever I compare it, the header is correct - even the MCNK one, which I'm having problems with. :l By reading the whole file and checking the header I don't need to check if we're on the right chunk because I'm guarenteed we are :P

Edit: http://pastebin.com/qcjPGF8r
Above is the MCNK parse code. As you can see, the Subchunks are not included, and that is for the reason that because the class reads like this:
Code: [Select]
 read 4 bytes -> name
  read 4 bytes -> size
  create array[size]
It means we get heap allocation errors because we read integers that are 1296256081 big. xD

Edit 2: http://pastebin.com/JvXk59E4
Corrosponding value dump.

Edit 3: I'm indecisive. Anyway, I DO check for MH2O before loading the MCNK, so that's not the issue in case you're wondering :P

Edit 4: SOLVED! I forgot I had set the Endianness of the buffer to LITTLE_ENDIAN and was then attempting to reverse all the data, effectively negating it. Thanks for your help :)

Edit 5: Removing the solved status as I still have an issue parsing the ADTs.
Right now I'm attempting to simply draw the plane on which the ADT lies - that is, a point by point representation of the ADT. I'm having trouble working out how to use MCVT to generate a height map - how would I go about doing this?
(Also, how could I tesselate the chunks in an ADT so that they are next to each other? Using OpenGL at the moment)
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

glararan

  • Registred Member
  • Wiki Incarnate
  • *****
  • Posts: 162
    • View Profile
    • http://glararan.eu
Re: [QUESTION] Parsing ADTs..
« Reply #6 on: November 14, 2011, 09:11:37 pm »
If you want i can help you with this program.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »