ADT Editor chapter II

I wanted to share more thoughts about how to edit ADT files with php.

At the bottom of this articule you can download the PHP Script that i use, it’s not a Class oriented object but it works!
In the last article I talk about how to get the offsets for each chunk, now the idea it’s get the info about “M2,WMO,TEXTURES” and put them in array.

To seek each chunk I use this code:

$OFFVALUE = "0x".EndianConverter($STRUCT_INFO["MTEX_Offset"]);

This code will place the pointer of fopen at the MTEX info.

For read strings in hexadecimal i googled a little bit and i got this code:

function hexToStr($hex)
    for ($i=0; $i < strlen($hex)-1; $i+=2)
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    return $string;

And for example, if we want to know few textures are inside the ADT this code will read all and will keep each texture inside the array $MTEX_Data

$OFFVALUE = "0x".EndianConverter($STRUCT_INFO["MTEX_Offset"]);
    $MTEX_Data = array("");
    $Cadena_Actual = "";
    while (1 != 2) {
        $Byte_Actual = bin2hex(fread($ADT_Handle,2));
            if($Byte_Actual == "5844"){                             //(5844) = (XD)  == header of XDMM (MDDX) so we stop here beacuse there are not more tileset
        $Byte_Actual = bin2hex(fread($ADT_Handle,1));
            if($Byte_Actual == "00"){                               //  it's -0 terminated string and then we stop reading
                $MTEX_Data[] = $Cadena_Actual;
                $Cadena_Actual = "";
                $Cadena_Actual .= hexToStr($Byte_Actual);

And the content for $MTEX_Data[] will be something like this:

    [1] => Tileset\Elwynn\ElwynnRockBaseTest2.blp
    [2] => Tileset\Elwynn\ElwynnDirtBase2.blp
    [3] => Tileset\Elwynn\ElwynnGrassBase.blp
    [4] => Tileset\Elwynn\ElwynnFlowerBase.blp
    [5] => Tileset\Aerie Peaks\AeriePeaksScrubBrushBase.blp
    [6] => Tileset\Elwynn\ElwynnCobbleStoneBase.blp
    [7] => Tileset\Elwynn\ElwynnCrop92.blp

Download the code here!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.