Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.98 KB | None | 0 0
  1. <?php
  2. header('Cache-control: max-age='.(60*60*24*365));
  3. header('Expires: '.gmdate(DATE_RFC1123,time()+60*60*24*365));
  4. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', 1337) . ' GMT');
  5. if(isset($SERVER['HTTP_IF_MODIFIED_SINCE']))
  6. {
  7. header('HTTP/1.0 304 Not Modified');
  8. /* PHP/webserver by default can return 'no-cache', so we must modify it */
  9. header('Cache-Control: public');
  10. header('Pragma: cache');
  11. exit;
  12. }
  13. /*
  14. $overloadList = array('cantebia.pl', 'aurera-global.com', 'marlboro-war.servegame.com', 'wu-uka.com', 'powerot.com.br', 'luminera-war.com');
  15. if(in_array(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST), $overloadList) || in_array(substr(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST), 4), $overloadList))
  16. {
  17. header('Content-Type: image/gif');
  18. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', 1337) . ' GMT');
  19. readfile('x.gif');
  20. }
  21. */
  22. /**
  23. *
  24. * @author Kamil Karkus <kaker@wp.eu>
  25. * @copyright Copyright (c) 2012, Kamil Karkus
  26. * @version 1
  27. */
  28.  
  29. class Outfitter {
  30.  
  31. protected static $instance = null;
  32. protected static $_outfit_lookup_table = array(
  33. 0xFFFFFF, 0xFFD4BF, 0xFFE9BF, 0xFFFFBF, 0xE9FFBF, 0xD4FFBF,
  34. 0xBFFFBF, 0xBFFFD4, 0xBFFFE9, 0xBFFFFF, 0xBFE9FF, 0xBFD4FF,
  35. 0xBFBFFF, 0xD4BFFF, 0xE9BFFF, 0xFFBFFF, 0xFFBFE9, 0xFFBFD4,
  36. 0xFFBFBF, 0xDADADA, 0xBF9F8F, 0xBFAF8F, 0xBFBF8F, 0xAFBF8F,
  37. 0x9FBF8F, 0x8FBF8F, 0x8FBF9F, 0x8FBFAF, 0x8FBFBF, 0x8FAFBF,
  38. 0x8F9FBF, 0x8F8FBF, 0x9F8FBF, 0xAF8FBF, 0xBF8FBF, 0xBF8FAF,
  39. 0xBF8F9F, 0xBF8F8F, 0xB6B6B6, 0xBF7F5F, 0xBFAF8F, 0xBFBF5F,
  40. 0x9FBF5F, 0x7FBF5F, 0x5FBF5F, 0x5FBF7F, 0x5FBF9F, 0x5FBFBF,
  41. 0x5F9FBF, 0x5F7FBF, 0x5F5FBF, 0x7F5FBF, 0x9F5FBF, 0xBF5FBF,
  42. 0xBF5F9F, 0xBF5F7F, 0xBF5F5F, 0x919191, 0xBF6A3F, 0xBF943F,
  43. 0xBFBF3F, 0x94BF3F, 0x6ABF3F, 0x3FBF3F, 0x3FBF6A, 0x3FBF94,
  44. 0x3FBFBF, 0x3F94BF, 0x3F6ABF, 0x3F3FBF, 0x6A3FBF, 0x943FBF,
  45. 0xBF3FBF, 0xBF3F94, 0xBF3F6A, 0xBF3F3F, 0x6D6D6D, 0xFF5500,
  46. 0xFFAA00, 0xFFFF00, 0xAAFF00, 0x54FF00, 0x00FF00, 0x00FF54,
  47. 0x00FFAA, 0x00FFFF, 0x00A9FF, 0x0055FF, 0x0000FF, 0x5500FF,
  48. 0xA900FF, 0xFE00FF, 0xFF00AA, 0xFF0055, 0xFF0000, 0x484848,
  49. 0xBF3F00, 0xBF7F00, 0xBFBF00, 0x7FBF00, 0x3FBF00, 0x00BF00,
  50. 0x00BF3F, 0x00BF7F, 0x00BFBF, 0x007FBF, 0x003FBF, 0x0000BF,
  51. 0x3F00BF, 0x7F00BF, 0xBF00BF, 0xBF007F, 0xBF003F, 0xBF0000,
  52. 0x242424, 0x7F2A00, 0x7F5500, 0x7F7F00, 0x557F00, 0x2A7F00,
  53. 0x007F00, 0x007F2A, 0x007F55, 0x007F7F, 0x00547F, 0x002A7F,
  54. 0x00007F, 0x2A007F, 0x54007F, 0x7F007F, 0x7F0055, 0x7F002A,
  55. 0x7F0000,
  56. );
  57.  
  58. public static function instance() {
  59. if (!isset(self::$instance))
  60. self::$instance = new self();
  61. return self::$instance;
  62. }
  63.  
  64. protected function outfit($outfit, $addons, $head, $body, $legs, $feet, $mount, $direction = 3, $animation = 1) {
  65. $outfitPath = "outfitsIdle1092/";
  66.  
  67. $mount_id = ($mount & 0xFFFF);
  68. $mountState = (($mount & 0xFFFF0000) != 0) ? 2 : 1;
  69. $creature = false;
  70.  
  71. /*
  72. // CODE TO BLOCK RENDERING OF CHARACTER SITTING ON NOT EXISTING MOUNT
  73. // CAN BLOCK ADDONS FOR OUTFITS THAT ADDONS DON'T HAVE 'template' (color) FILE
  74. $max = ($addons != 0) ? 3 : 1;
  75. for ($i = 1; $i <= $max; $i++) {
  76. //a_b_c_d
  77. //a animationFrame
  78. //b mountState
  79. //c addons
  80. //d direction
  81.  
  82. if (!file_exists($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_' . $i . '_'.$direction.'.png') || !file_exists($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_' . $i . '_'.$direction.'_template.png')) {
  83. if ($mountState == 2) {
  84. $mountState = 1;
  85. $i = 1;
  86. } else {
  87. $creature = true;
  88. break;
  89. }
  90. }
  91.  
  92. }
  93. */
  94.  
  95. if ($creature) {
  96. $tmpOutfit = null;
  97. if (file_exists($outfitPath . $outfit . '/'.$animation.'_1_1_'.$direction.'.png'))
  98. $tmpOutfit = imagecreatefrompng($outfitPath . $outfit . '/'.$animation.'_1_1_'.$direction.'.png');
  99. elseif (file_exists($outfitPath . $outfit . '/1_1_1_3.png'))
  100. $tmpOutfit = imagecreatefrompng($outfitPath . $outfit . '/1_1_1_3.png');
  101. if ($tmpOutfit == null)
  102. return;
  103. imagealphablending($tmpOutfit, false);
  104. imagesavealpha($tmpOutfit, true);
  105. return $tmpOutfit;
  106. }
  107.  
  108. $image_outfit = imagecreatefrompng($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_1_'.$direction.'.png');
  109. $image_template = imagecreatefrompng($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_1_'.$direction.'_template.png');
  110.  
  111. if ($addons == 1 || $addons == 3) {
  112. $image_first = imagecreatefrompng($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_2_'.$direction.'.png');
  113. $this->alphaOverlay($image_outfit, $image_first, 64, 64);
  114. if(file_exists($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_2_'.$direction.'_template.png'))
  115. {
  116. $image_first_template = imagecreatefrompng($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_2_'.$direction.'_template.png');
  117. $this->alphaOverlay($image_template, $image_first_template, 64, 64);
  118. }
  119. }
  120. if ($addons == 2 || $addons == 3) {
  121. $image_second = imagecreatefrompng($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_3_'.$direction.'.png');
  122. $this->alphaOverlay($image_outfit, $image_second, 64, 64);
  123. if(file_exists($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_3_'.$direction.'_template.png'))
  124. {
  125. $image_second_template = imagecreatefrompng($outfitPath . $outfit . '/'.$animation.'_' . $mountState . '_3_'.$direction.'_template.png');
  126. $this->alphaOverlay($image_template, $image_second_template, 64, 64);
  127. }
  128. }
  129.  
  130. $this->colorize($image_template, $image_outfit, $head, $body, $legs, $feet);
  131. if ($mountState == 2 && file_exists($outfitPath . $mount_id . '/'.$animation.'_1_1_'.$direction.'.png')) {
  132. $mount = imagecreatefrompng($outfitPath . $mount_id . '/'.$animation.'_1_1_'.$direction.'.png');
  133. $this->alphaOverlay($mount, $image_outfit, 64, 64);
  134. $image_outfit = $mount;
  135. }
  136.  
  137. imagealphablending($image_outfit, false);
  138. imagesavealpha($image_outfit, true);
  139. imagedestroy($image_template);
  140. if(imagesx($image_outfit) == 32)
  141. {
  142. $img = imagecreatetruecolor(64, 64);
  143. imagesavealpha($img, true);
  144. $color = imagecolorallocatealpha($img, 0, 0, 0, 127);
  145. imagefill($img, 0, 0, $color);
  146. imagecopy($img, $image_outfit, 32, 32, 0, 0, 32, 32);
  147. imagedestroy($image_outfit);
  148. $image_outfit = $img;
  149. }
  150. return $image_outfit;
  151. }
  152.  
  153. /**
  154. * every parameter need to be passed from table players, excluding animation
  155. * for example u can use POT/OTS_PLayer::getLookType to pass outfit, etc...
  156. */
  157. public function renderOutfit($outfit, $addons, $head, $body, $legs, $feet, $mount, $directon = 3, $animation = 1) {
  158. return imagepng($this->outfit($outfit, $addons, $head, $body, $legs, $feet, $mount, $directon, $animation));
  159. }
  160.  
  161. protected function colorizePixel($_color, &$_r, &$_g, &$_b) {
  162. if ($_color < count(self::$_outfit_lookup_table))
  163. $value = self::$_outfit_lookup_table[$_color];
  164. else
  165. $value = 0;
  166. $ro = ($value & 0xFF0000) >> 16; // rgb outfit
  167. $go = ($value & 0xFF00) >> 8;
  168. $bo = ($value & 0xFF);
  169. $_r = (int) ($_r * ($ro / 255));
  170. $_g = (int) ($_g * ($go / 255));
  171. $_b = (int) ($_b * ($bo / 255));
  172. }
  173.  
  174. protected function colorize(&$_image_template, &$_image_outfit, $_head, $_body, $_legs, $_feet) {
  175. for ($i = 0; $i < imagesy($_image_template); $i++) {
  176. for ($j = 0; $j < imagesx($_image_template); $j++) {
  177. $templatepixel = imagecolorat($_image_template, $j, $i);
  178. $outfit = imagecolorat($_image_outfit, $j, $i);
  179.  
  180. if ($templatepixel == $outfit)
  181. continue;
  182.  
  183. $rt = ($templatepixel >> 16) & 0xFF;
  184. $gt = ($templatepixel >> 8) & 0xFF;
  185. $bt = $templatepixel & 0xFF;
  186. $ro = ($outfit >> 16) & 0xFF;
  187. $go = ($outfit >> 8) & 0xFF;
  188. $bo = $outfit & 0xFF;
  189.  
  190. if ($rt && $gt && !$bt) { // yellow == head
  191. $this->colorizePixel($_head, $ro, $go, $bo);
  192. } else if ($rt && !$gt && !$bt) { // red == body
  193. $this->colorizePixel($_body, $ro, $go, $bo);
  194. } else if (!$rt && $gt && !$bt) { // green == legs
  195. $this->colorizePixel($_legs, $ro, $go, $bo);
  196. } else if (!$rt && !$gt && $bt) { // blue == feet
  197. $this->colorizePixel($_feet, $ro, $go, $bo);
  198. } else {
  199. continue; // if nothing changed, skip the change of pixel
  200. }
  201.  
  202. imagesetpixel($_image_outfit, $j, $i, imagecolorallocate($_image_outfit, $ro, $go, $bo));
  203. }
  204. }
  205. }
  206.  
  207. protected function alphaOverlay(&$destImg, &$overlayImg, $imgW, $imgH) {
  208. for ($y = 0; $y < $imgH; $y++) {
  209. for ($x = 0; $x < $imgW; $x++) {
  210. $ovrARGB = imagecolorat($overlayImg, $x, $y);
  211. $ovrA = ($ovrARGB >> 24) << 1;
  212. $ovrR = $ovrARGB >> 16 & 0xFF;
  213. $ovrG = $ovrARGB >> 8 & 0xFF;
  214. $ovrB = $ovrARGB & 0xFF;
  215.  
  216. $change = false;
  217. if ($ovrA == 0) {
  218. $dstR = $ovrR;
  219. $dstG = $ovrG;
  220. $dstB = $ovrB;
  221. $change = true;
  222. } elseif ($ovrA < 254) {
  223. $dstARGB = imagecolorat($destImg, $x, $y);
  224. $dstR = $dstARGB >> 16 & 0xFF;
  225. $dstG = $dstARGB >> 8 & 0xFF;
  226. $dstB = $dstARGB & 0xFF;
  227.  
  228. $dstR = (($ovrR * (0xFF - $ovrA)) >> 8) + (($dstR * $ovrA) >> 8);
  229. $dstG = (($ovrG * (0xFF - $ovrA)) >> 8) + (($dstG * $ovrA) >> 8);
  230. $dstB = (($ovrB * (0xFF - $ovrA)) >> 8) + (($dstB * $ovrA) >> 8);
  231. $change = true;
  232. }
  233. if ($change) {
  234. $dstRGB = imagecolorallocatealpha($destImg, $dstR, $dstG, $dstB, 0);
  235. imagesetpixel($destImg, $x, $y, $dstRGB);
  236. }
  237. }
  238. }
  239. return $destImg;
  240. }
  241. }
  242. header('Content-Type: image/png');
  243. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', 1337) . ' GMT');
  244. $mount = 0;
  245. if(isset($_GET['mount']))
  246. {
  247. $mount = $_GET['mount'];
  248. }
  249. $direction = 3;
  250. if(isset($_GET['direction']))
  251. {
  252. $direction = $_GET['direction'];
  253. }
  254. // animations removed
  255. $animation = 1;
  256. Outfitter::instance()->renderOutfit($_GET['id'], $_GET['addons'], $_GET['head'], $_GET['body'], $_GET['legs'], $_GET['feet'], $mount, $direction, $animation);
  257.  
  258. //example
  259. //outfitter.php?a=514&b=2&c=45&d=13&e=65&f=1&g=66083&&h=2&i=3
  260. //a = outfit id
  261. //b = addons
  262. //c = head
  263. //d = body
  264. //e = legs
  265. //f = feet
  266. //g = mount
  267. //h = direction
  268. //i = animation
  269. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement