static function freadstring($file, $max, $trim = true)
 {
     $chars = file_helpers::freadchars($file, $max);
     $string = "";
     foreach ($chars as $c) {
         if ($c == 0) {
             break;
         }
         $string .= chr($c);
     }
     return $trim ? file_helpers::_oem2ansi(trim($string)) : $string;
 }
Пример #2
0
 private function _load()
 {
     $wld = fopen($this->file, "rb");
     if (!$wld) {
         return $this->_error("invalid file");
     }
     if (!file_helpers::freadid($wld)) {
         // WORLD_V1.0
         return $this->_error("no S2-Map");
     }
     $this->header['name'] = file_helpers::freadstring($wld, 20);
     // "foo"
     $this->header['width'] = file_helpers::freadshort($wld);
     // w
     $this->header['height'] = file_helpers::freadshort($wld);
     // h
     $this->header['type'] = file_helpers::freadchar($wld);
     // green-/waste-/winterland
     $this->header['players'] = file_helpers::freadchar($wld);
     // number of players
     $this->header['author'] = file_helpers::freadstring($wld, 20);
     // "bar"
     // jump to first subheader
     fseek($wld, 2342, SEEK_SET);
     if (!file_helpers::freadshid($wld, 0x11)) {
         // 11 27 0 0 0 0
         return $this->_error("invalid S2-Map");
     }
     $this->header['width'] = file_helpers::freadshort($wld);
     // w (again)
     $this->header['height'] = file_helpers::freadshort($wld);
     // h (again)
     $keys = array_keys($this->blocks);
     // read the blocks
     for ($i = 0; $i < 14; $i++) {
         if (!file_helpers::freadshid($wld, 0x10)) {
             // 10 27 0 0 0 0
             return $this->_error("invalid S2-Subheader");
         }
         $width = file_helpers::freadshort($wld);
         // sub w
         $height = file_helpers::freadshort($wld);
         // sub h
         if (file_helpers::freadshort($wld) != 1) {
             // 01 00
             return $this->_error("invalid S2-Sub-Id");
         }
         $length = file_helpers::freadint($wld);
         // length of block (w*h)
         $this->blocks[$keys[$i]] = file_helpers::freadchars($wld, $length);
     }
     fclose($wld);
     return true;
 }