0 Members and 1 Guest are viewing this topic.
<?php// Textual PHP PMS Data Reader // Version 4// Fully written by: Mikhail D.// AKA: Doc// Date: May 12, 2007class mapInfo { // Constructor. function mapInfo($path) { $this->path = $path; $this->read($this->path); } // Reader. function read($path) { $file = fopen($path, "rb"); $bin = fread($file, filesize($path)); $hex = bin2hex($bin); fclose($file); $pos = 0; $pos += 4; // header $title_length = hexdec(bin2hex(substr($bin,$pos,1))); // title len $pos += 1; $this->title = $this->hexstr(bin2hex(substr($bin,$pos,$title_length))); // title $pos += 38; $texture_length = hexdec(bin2hex(substr($bin,$pos,1))); // texture len $pos += 1; $this->texture = $this->hexstr(bin2hex(substr($bin,$pos,$texture_length))); // texture $pos += 24; $this->color_top = "#".bin2hex(substr($bin,$pos,3)); // color top $pos += 4; $this->color_bottom = "#".bin2hex(substr($bin,$pos,3)); // color low $pos += 4; $this->jets = $this->num2jets($this->bin2long(substr($bin,$pos,4))); // jets $pos += 4; $this->grenades = hexdec(bin2hex(substr($bin,$pos,1))); // grenades $pos += 1; $this->medkits = hexdec(bin2hex(substr($bin,$pos,1))); // medics $pos += 1; $this->weather = $this->num2weather(hexdec(bin2hex(substr($bin,$pos,1)))); // weather $pos += 1; $this->steptype = $this->num2steptype(hexdec(bin2hex(substr($bin,$pos,1)))); // step type $pos += 1; $pos += 4; // ID $this->poly_count = $this->bin2long(substr($bin,$pos,4)); // poly count $pos += 4; $pos += 121 * $this->poly_count; // pass all polygons $pos += 4; // sector division $sector_count = $this->bin2long(substr($bin,$pos,4)); // sector count $sector_count = (($sector_count*2)+1)*(($sector_count*2)+1); $pos += 4; // sector len skip start $pos2 = $pos * 2; for ( $i = 1; $i <= $sector_count; $i += 1) { $dec2 = hexdec(substr($hex,$pos2,2)); if($dec2 > 0){ $pos2 += (4*$dec2); } $pos2 += 4; } $pos = $pos2 / 2; // sector len skip end $prop_count = $this->bin2long(substr($bin,$pos,4)); // prop count $pos += 4; $pos += $prop_count * 44; // passing prop data $this->scenery_count = $this->bin2long(substr($bin,$pos,4)); // scenery count $pos += 4; if($this->scenery_count > 0) // scenery list if any $this->sceneryList(substr($bin,$pos,55 * $this->scenery_count)); $pos += 55 * $this->scenery_count; // passing all scenery data $this->collider_count = $this->bin2long(substr($bin,$pos,4)); // collider count $pos += 4; $pos += 16 * $this->collider_count; // passing all collider data $this->spawnpoint_count = $this->bin2long(substr($bin,$pos,4)); // spawnpoint count $pos += 4; $pos += 16 * $this->spawnpoint_count; // passing all spawnpoint data $this->waypoint_count = $this->bin2long(substr($bin,$pos,4)); // waypoint count $pos += 4; } function sceneryList($scenery_bin) { $this->scenery_list = array(); $p = 0; for ( $i = 1; $i <= $this->scenery_count; $i++) { $scenery_hex = bin2hex(substr($scenery_bin,$p,55)); $scenery_length = hexdec(substr($scenery_hex,0,2)); $this->scenery_list[$i][0] = $this->hexstr(substr($scenery_hex,2,$scenery_length*2)); // name $this->scenery_list[$i][1] = substr($scenery_hex,102,4); // x $this->scenery_list[$i][2] = substr($scenery_hex,106,4); // y $p += 55; } } // Converters pass this point. function num2steptype($steptype) { if($steptype == "00") $steptype = "Hard Ground"; elseif($steptype == "01") $steptype = "Soft Ground"; elseif($steptype == "02") $steptype = "None"; else $steptype = "Error: Invalid step type in map."; return $steptype; } function num2weather($weather) { if($weather == "00") $weather = "Normal"; elseif($weather == "01") $weather = "Rain"; elseif($weather == "02") $weather = "Sand Storm"; elseif($weather == "03") $weather = "Snow"; else $weather = "Error: Invalid weather in map."; return $weather; } function num2jets($jets) { if($jets == 0) $jets = "None (".$jets.")"; elseif($jets == 12) $jets = "Minimal (".$jets.")"; elseif($jets == 45) $jets = "Very Low (".$jets.")"; elseif($jets == 95) $jets = "Low (".$jets.")"; elseif($jets == 190) $jets = "Normal (".$jets.")"; elseif($jets == 320) $jets = "Lots (".$jets.")"; elseif($jets == 800) $jets = "Maximum (".$jets.")"; else $jets = "Custom (".$jets.")"; return $jets; } function bin2long($bin) { if(strlen($bin) == 4) $long = unpack("l", $bin); else $long = array(1 => 0); return $long[1]; } function hexstr($hexstr) { $hexstr = str_replace(' ', '', $hexstr); $retstr = pack('H*', $hexstr); return $retstr; } }// how to use$map = new mapInfo("ctf_Ash.PMS");echo $map->title."<br>";echo $map->texture."<br>";echo $map->color_top."<br>";echo $map->color_bottom."<br>";echo $map->jets."<br>";echo $map->grenades."<br>";echo $map->medkits."<br>";echo $map->weather."<br>";echo $map->steptype."<br>";echo $map->poly_count."<br>";echo $map->scenery_count."<br>";for($i = 1; $i <= $map->scenery_count; $i++){ echo $map->scenery_list[$i][0]."<br>";}echo $map->collider_count."<br>";echo $map->spawnpoint_count."<br>";echo $map->waypoint_count."<br>";?>
Any questions or sugestion?
gj with flippin burgers
teh selfish