function createart($id, $hue, $show) { if (file_exists("images/art/art_" . $id . "_" . $hue . ".png")) { if ($show == 1) { Header("Content-type: image/png"); Header("Content-disposition: inline; filename=art_" . $id . "_" . $hue . ".png"); $img = imagecreatefrompng("images/art/art_" . $id . "_" . $hue . ".png"); $black = imagecolorallocate($img, 0, 0, 0); imagecolortransparent($img, $black); imagepng($img); return; } //return; } $oldhue = $hue; $mulpath = "./uofiles/"; $hue = hex($hue); $id = hex($id); $id += 0x4000; $hues = FALSE; $tiledata = FALSE; $gumpindex = FALSE; $gumpfile = FALSE; //open files for reading //********************** if ($hue < 1 || $hue > 65535) { //If invalid or missing hue, unset hue and don't read hues.mul and tiledata.mul $hue = 0; } else { //If valid hue, read hues.mul and tiledata.mul $hues = fopen("{$mulpath}hues.mul", "rb"); if ($hues == FALSE) { $hue = 0; } $tiledata = fopen("{$mulpath}tiledata.mul", "rb"); if ($tiledata == FALSE) { $hue = 0; } else { $index = $id - 0x4000; $group = intval($index / 32); $groupidx = $index % 32; fseek($tiledata, 512 * 836 + 1188 * $group + 4 + $groupidx * 37, SEEK_SET); $tileflag = read_byte($tiledata, 4); if ($tileflag & 0x40000) { $partialhue = 1; } else { $partialhue = 0; } fclose($tiledata); } } //Read artidx.mul $gumpindex = fopen("{$mulpath}artidx.mul", "rb"); if ($gumpindex == FALSE) { unavailable_pic(); exit; } else { fseek($gumpindex, $id * 12, SEEK_SET); $lookup = read_byte($gumpindex, 4); $size = read_byte($gumpindex, 4); fclose($gumpindex); } //Read art.mul $gumpfile = fopen("{$mulpath}art.mul", "rb"); if ($gumpfile == FALSE) { unavailable_pic(); exit; } else { fseek($gumpfile, $lookup, SEEK_SET); $flag = read_byte($gumpfile, 4); $width = read_byte($gumpfile, 2); $height = read_byte($gumpfile, 2); //create base image //********************** $im = imagecreatetruecolor($width, $height); $almostblack = imagecolorallocate($im, 0, 0, 0); imagefill($im, 0, 0, $almostblack); $black = imagecolorallocate($im, 0, 0, 0); imagecolortransparent($im, $black); imagealphablending($im, true); imageSaveAlpha($im, true); //Read pixels //********************** for ($i = 0; $i < $height; $i++) { $offset[$i] = read_byte($gumpfile, 2); } $datastart = ftell($gumpfile); $x = 0; $y = 0; //Display without hues //********************** if ($hue <= 0) { while ($y < $height) { $xOffset = read_byte($gumpfile, 2); $xRun = read_byte($gumpfile, 2); if ($xRun + $xOffset > 2048) { break; } else { if ($xRun + $xOffset != 0) { $x += $xOffset; for ($Run = 0; $Run < $xRun; $Run++) { $color[$Run] = read_byte($gumpfile, 2); $r = ($color[$Run] >> 10) * 8; $g = ($color[$Run] >> 5 & 0x1f) * 8; $b = ($color[$Run] & 0x1f) * 8; if (imagecolorexact($im, $r, $g, $b) == -1) { $col = imageColorAllocate($im, $r, $g, $b); imagesetpixel($im, $x, $y, $col); } else { $found = imagecolorexact($im, $r, $g, $b); imagesetpixel($im, $x, $y, $found); } $x++; } } else { $x = 0; $y++; if (isset($offset[$y])) { fseek($gumpfile, $offset[$y] * 2 + $datastart, SEEK_SET); } } } } } else { $hue = $hue - 1; $orighue = $hue; if ($hue > 0x8000) { $hue = $hue - 0x8000; } if ($hue > 3001) { $hue = 1; } $colors = intval($hue / 8) * 4; $colors = 4 + $hue * 88 + $colors; fseek($hues, $colors, SEEK_SET); for ($i = 0; $i < 32; $i++) { $color32[$i] = read_byte($hues, 2); $color32[$i] |= 0x8000; } while ($y < $height) { $xOffset = read_byte($gumpfile, 2); $xRun = read_byte($gumpfile, 2); if ($xRun + $xOffset > 2048) { break; } else { if ($xRun + $xOffset != 0) { $x += $xOffset; for ($Run = 0; $Run < $xRun; $Run++) { $color[$Run] = read_byte($gumpfile, 2); $r = $color[$Run] >> 10; $g = $color[$Run] >> 5 & 0x1f; $b = $color[$Run] & 0x1f; if ($partialhue == 1 && ($r == $g && $r == $b)) { $newr = ($color32[$r] >> 10) * 8; $newg = ($color32[$r] >> 5 & 0x1f) * 8; $newb = ($color32[$r] & 0x1f) * 8; } else { if ($partialhue == 1) { $newr = $r * 8; $newg = $g * 8; $newb = $b * 8; } else { $newr = ($color32[$r] >> 10) * 8; $newg = ($color32[$r] >> 5 & 0x1f) * 8; $newb = ($color32[$r] & 0x1f) * 8; } } if (imagecolorexact($im, $newr, $newg, $newb) == -1) { $col = imageColorAllocate($im, $newr, $newg, $newb); imagesetpixel($im, $x, $y, $col); } else { $found = imagecolorexact($im, $newr, $newg, $newb); imagesetpixel($im, $x, $y, $found); } $x++; } } else { $x = 0; $y++; if (isset($offset[$y])) { fseek($gumpfile, $offset[$y] * 2 + $datastart, SEEK_SET); } } } } fclose($hues); } } fclose($gumpfile); $index = $id - 0x4000; if (hexdec($oldhue) > 0) { $hue = $hue + 1; } imagepng($im, "images/art/art_" . $index . "_" . $hue . ".png", 0, NULL); imagedestroy($im); if ($show == 1) { Header("Content-type: image/png"); Header("Content-disposition: inline; filename=art_" . $id . "_" . $hue . ".png"); $img = imagecreatefrompng("images/art/art_" . $index . "_" . $hue . ".png"); $black = imagecolorallocate($img, 0, 0, 0); imagecolortransparent($img, $black); imagepng($img); imagedestroy($img); } return; }
function image_getdimension($file) { $size = @getimagesize($file); if ($size[0] != 0 || $size[1] != 0) { return $size; } // Try to get the Dimension manually, depending on the mimetype $fp = @fopen($file, 'rb'); if (!$fp) { return $size; } $error = FALSE; // // BMP - IMAGE // $tmp_str = fread($fp, 2); if ($tmp_str == 'BM') { $length = read_longint($fp); if ($length <= 6) { $error = TRUE; } if (!$error) { $i = read_longint($fp); if ($i != 0) { $error = TRUE; } } if (!$error) { $i = read_longint($fp); if ($i != 0x3e && $i != 0x76 && $i != 0x436 && $i != 0x36) { $error = TRUE; } } if (!$error) { $tmp_str = fread($fp, 4); $width = read_longint($fp); $height = read_longint($fp); if ($width > 3000 || $height > 3000) { $error = TRUE; } } } else { $error = TRUE; } if (!$error) { fclose($fp); return array($width, $height, '6'); } $error = FALSE; fclose($fp); // // GIF - IMAGE // $fp = @fopen($file, 'rb'); $tmp_str = fread($fp, 3); if ($tmp_str == 'GIF') { $tmp_str = fread($fp, 3); $width = read_word($fp); $height = read_word($fp); $info_byte = fread($fp, 1); $info_byte = ord($info_byte); if (($info_byte & 0x80) != 0x80 && ($info_byte & 0x80) != 0) { $error = TRUE; } if (!$error) { if (($info_byte & 8) != 0) { $error = TRUE; } } } else { $error = TRUE; } if (!$error) { fclose($fp); return array($width, $height, '1'); } $error = FALSE; fclose($fp); // // JPG - IMAGE // $fp = @fopen($file, 'rb'); $tmp_str = fread($fp, 4); $w1 = read_word($fp); if (intval($w1) < 16) { $error = TRUE; } if (!$error) { $tmp_str = fread($fp, 4); if ($tmp_str == 'JFIF') { $o_byte = fread($fp, 1); if (intval($o_byte) != 0) { $error = TRUE; } if (!$error) { $str = fread($fp, 2); $b = read_byte($fp); if ($b != 0 && $b != 1 && $b != 2) { $error = TRUE; } } if (!$error) { $width = read_word($fp); $height = read_word($fp); if ($width <= 0 || $height <= 0) { $error = TRUE; } } } } else { $error = TRUE; } if (!$error) { fclose($fp); return array($width, $height, '2'); } $error = FALSE; fclose($fp); // // PCX - IMAGE // $fp = @fopen($file, 'rb'); $tmp_str = fread($fp, 3); if (ord($tmp_str[0]) == 10 && (ord($tmp_str[1]) == 0 || ord($tmp_str[1]) == 2 || ord($tmp_str[1]) == 3 || ord($tmp_str[1]) == 4 || ord($tmp_str[1]) == 5) && ord($tmp_str[2]) == 1) { $b = fread($fp, 1); if (ord($b) != 1 && ord($b) != 2 && ord($b) != 4 && ord($b) != 8 && ord($b) != 24) { $error = TRUE; } if (!$error) { $xmin = read_word($fp); $ymin = read_word($fp); $xmax = read_word($fp); $ymax = read_word($fp); $tmp_str = fread($fp, 52); $b = fread($fp, 1); if ($b != 0) { $error = TRUE; } } if (!$error) { $width = $xmax - $xmin + 1; $height = $ymax - $ymin + 1; } } else { $error = TRUE; } if (!$error) { fclose($fp); return array($width, $height, '7'); } fclose($fp); return $size; }
function old_chunk_get_block($x, $y, $z) { global $chunks; $x = intval($x); $y = intval($y); $z = intval($z); $X = intval($x / 16); $Z = intval($z / 16); $x %= 16; $y %= 128; $z %= 16; if (!isset($chunks[$X . "|" . $Z])) { return 0x0; //AIR } $index = $y + $z * 128 + $x * 128 * 16; return read_byte($chunks[$X . "|" . $Z][$index], false); }