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"]);
fseek($ADT_Handle,0x14+0x08+$OFFVALUE,SEEK_SET);

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)
{
    $string='';
    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

//===================================
//ADT MTEX INFO
//===================================
$OFFVALUE = "0x".EndianConverter($STRUCT_INFO["MTEX_Offset"]);
 
fseek($ADT_Handle,0x14+0x08+$OFFVALUE,SEEK_SET);
 
    $MTEX_Data = array("");
    unset($MTEX_Data["0"]);
    $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
                break;
            }
        fseek($ADT_Handle,-2,SEEK_CUR);
        $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 = "";
            }else{
                $Cadena_Actual .= hexToStr($Byte_Actual);
            }
    }

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

Array
(
    [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! https://github.com/karliky/php-wow

Leave a Reply

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