PHP код:
<?
/********************************************************************/
/* */
/* Lineage2 DLE Module, Copyright © 2007-2009, hellEVIL TEAM */
/* http://www.hellevil.net */
/* */
/********************************************************************/
if(!defined('DATALIFEENGINE')) {
die("Hacking attempt!");
}
/*
* Функции
*/
function empty_image()
{
@header("Content-type: image/gif");
@header("Cache-Control: max-age=3600");
$img=imagecreatetruecolor(1,1);
imagecolortransparent($img, 0);
imagegif($img);
imagedestroy($img);
exit();
}
function readInt($file)
{
$b4 = ord(fgetc($file));
$b3 = ord(fgetc($file));
$b2 = ord(fgetc($file));
$b1 = ord(fgetc($file));
return ($b1<<24)|($b2<<16)|($b3<<8)|$b4;
}
function readShort($file)
{
$b2 = ord(fgetc($file));
$b1 = ord(fgetc($file));
return ($b1<<8)|$b2;
}
/*
* Переменные
*/
if ($id == 0) empty_image();
$type = isset($_REQUEST["type"]) ? $_REQUEST["type"] : "clan" ;
/*
* Тип запроса
*/
switch($type)
{
case "clan":
$query = $dbg[$_serv]->sql_query_jdb("getCrest", array('clan_id' => $id));
$prefix = "Crest_";
break;
case "ally":
$query = $dbg[$_serv]->sql_query_jdb("getCrest", array('clan_id' => $id));
$prefix = "AllyCrest_";
break;
default:
empty_image();
break;
}
if ($dbg[$_serv]->sql_numrows() == 1) $clan_crest = $dbg[$_serv]->sql_fetchfield(0, 0, $query);
else empty_image();
$filename = "{$la2config["gameserver"][$_serv]["menu"]["crests"]}/{$prefix}_{$id}.bmp";
if (file_exists($filename) == false)
@file_put_contents($filename, $clan_crest);
$file = @fopen($filename,'rb');
if($file)
$dds = fread($file,4);
else
$dds = false;
if ($dds!=='DDS ') die("Error: изображение DDS не найдено");
//DDS header
$hdrSize = readInt($file);
$hdrFlags = readInt($file);
$imgHeight = readInt($file)-4;
$imgWidth = readInt($file);
$imgPitch = readShort($file);
//DXT1 header
fseek($file, 84);
$dxt1 = fread($file,4);
if ($dxt1!=='DXT1') die("Error: не найден формат DX1");
//here we go
fseek($file, 128);
@header ("Content-type: image/png");
@header("Cache-Control: max-age=3600");
$img=imagecreatetruecolor($imgWidth,$imgHeight);
for ($y=-1; $y<$imgHeight/4; $y++)
{
for ($x=0; $x<$imgWidth/4; $x++)
{
$color0_16 = readShort($file);
$color1_16 = readShort($file);
$r0 = ($color0_16 >> 11) << 3;
$g0 = (($color0_16 >> 5) & 63) << 2;
$b0 = ($color0_16 & 31) << 3;
$r1 = ($color1_16 >> 11) << 3;
$g1 = (($color1_16 >> 5) & 63) << 2;
$b1 = ($color1_16 & 31) << 3;
$color0_32 = imagecolorallocate($img,$r0,$g0,$b0);
$color1_32 = imagecolorallocate($img,$r1,$g1,$b1);
$color01_32 = imagecolorallocate($img,$r0/2+$r1/2,$g0/2+$g1/2,$b0/2+$b1/2);
$black = imagecolorallocate($img,0,0,0);
$data = readInt($file);
for ($yy=0;$yy<4;$yy++)
{
for ($xx=0;$xx<4;$xx++)
{
$bb = $data & 3;
$data = $data >> 2;
switch ($bb)
{
case 0: $c = $color0_32; break;
case 1: $c = $color1_32; break;
case 2: $c = $color01_32; break;
default: $c = $black; break;
}
imagesetpixel($img,$x*4+$xx,$y*4+$yy,$c);
}
}
}
}
imagepng($img);
exit;
?>
Выдерните логику отсюда.