$gumpfile = fopen("{$mulpath}gumpart.mul", "rb"); if ($gumpfile == FALSE) { fclose($hues); fclose($tiledata); die("Unable to open gumpart.mul - ERROR\nDATAEND!"); exit; } $gumpindex = fopen("{$mulpath}gumpidx.mul", "rb"); if ($gumpindex == FALSE) { fclose($hues); fclose($tiledata); fclose($gumpfile); die("Unable to open gumpidx.mul - ERROR\nDATAEND!"); exit; } InitializeGump($gumprawdata, $width, $height); for ($i = 0; $i < sizeof($indexA); $i++) { $index = intval($indexA[$i]); $female = intval($femaleA[$i]); $hue = intval($hueA[$i]); $isgump = intval($isgumpA[$i]); if ($female >= 1) { $female = 1; } else { $female = 0; } if ($hue < 1 || $hue > 65535) { $hue = 0; } if ($isgump > 0 || $index == 12 || $index == 13) { $isgump = 1;
function LoadRawGump($gumpindex, $gumpfile, $index, $hue, $hues, &$gumprawdata) { $send_data = ''; $color32 = array(); fseek($gumpindex, $index * 12, SEEK_SET); if (feof($gumpindex)) { return; } // Invalid gumpid, reached end of gumpindex. $lookup = read_big_to_little_endian($gumpindex, 4); if ($lookup == -1) { if ($index >= 60000) { $index -= 10000; } fseek($gumpindex, $index * 12, SEEK_SET); if (feof($gumpindex)) { // Invalid gumpid, reached end of gumpindex. return; } $lookup = read_big_to_little_endian($gumpindex, 4); if ($lookup == -1) { return; } // Gumpindex returned invalid lookup. } $gsize = read_big_to_little_endian($gumpindex, 4); $gextra = read_big_to_little_endian($gumpindex, 4); fseek($gumpindex, $index * 12, SEEK_SET); $gwidth = $gextra >> 16 & 0xffff; $gheight = $gextra & 0xffff; $send_data .= sprintf("Lookup: %d\n", $lookup); $send_data .= sprintf("Size: %d\n", $gsize); $send_data .= sprintf("Height: %d\n", $gheight); $send_data .= sprintf("Width: %d\n", $gwidth); /* echo "$gwidth, $gheight"; exit; */ InitializeGump($gumprawdata, $gwidth, $gheight); if ($gheight <= 0 || $gwidth <= 0) { return; } // Gump width or height was less than 0. fseek($gumpfile, $lookup, SEEK_SET); $heightTable = read_big_to_little_endian($gumpfile, $gheight * 4); if (feof($gumpfile)) { return; } // Invalid gumpid, reached end of gumpfile. $send_data .= sprintf("DATASTART:\n"); if ($hue <= 0) { for ($y = 1; $y < $gheight; $y++) { fseek($gumpfile, $heightTable[$y] * 4 + $lookup, SEEK_SET); // Start of row $x = 0; while ($x < $gwidth) { $rle = read_big_to_little_endian($gumpfile, 4); // Read the RLE data $length = $rle >> 16 & 0xffff; // First two bytes - how many pixels does this color cover $color = $rle & 0xffff; // Second two bytes - what color do we apply // Begin RGB value decoding $r = ($color >> 10) * 8; $g = ($color >> 5 & 0x1f) * 8; $b = ($color & 0x1f) * 8; if ($r > 0 || $g > 0 || $b > 0) { $send_data .= sprintf("%d:%d:%d:%d:%d:%d***", $x, $y, $r, $g, $b, $length); } $x = $x + $length; } } } else { // We are using the hues.mul $hue = $hue - 1; $orighue = $hue; if ($hue > 0x8000) { $hue = $hue - 0x8000; } if ($hue > 3001) { // Bad hue will cause a crash $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_big_to_little_endian($hues, 2); $color32[$i] |= 0x8000; } for ($y = 1; $y < $gheight; $y++) { fseek($gumpfile, $heightTable[$y] * 4 + $lookup, SEEK_SET); // Start of row $x = 0; while ($x < $gwidth) { $rle = read_big_to_little_endian($gumpfile, 4); // Read the RLE data $length = $rle >> 16 & 0xffff; // First two bytes - how many pixels does this color cover $color = $rle & 0xffff; // Second two bytes - what color do we apply // Begin RGB value decoding $r = $color >> 10; $g = $color >> 5 & 0x1f; $b = $color & 0x1f; // Check if we're applying a special hue (skin hues), if so, apply only to grays if ($orighue > 0x8000 && ($r == $g && $r == $b)) { $newr = ($color32[$r] >> 10) * 8; $newg = ($color32[$r] >> 5 & 0x1f) * 8; $newb = ($color32[$r] & 0x1f) * 8; } else { if ($orighue > 0x8000) { $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 ($r * 8 > 0 || $g * 8 > 0 || $b * 8 > 0) { $send_data .= sprintf("%d:%d:%d:%d:%d:%d***", $x, $y, $newr, $newg, $newb, $length); } $x += $length; } } } $send_data .= sprintf("DATAEND!"); add_gump($send_data, $gumprawdata); }