A RuneTek3 client (377) that is deobfuscated, converted to Kotlin, and includes QoL improvements.
0

Configure Feed

Select the types of activity you want to include in your feed.

Migrate 11 client files to Kotlin, rename obfuscated fields, fix wilderness text

Java→Kotlin: Skins, TiledUtils, Animation, Actor, Npc, Player,
ProducingGraphicsBuffer, GameFrame, BufferTests, Rasterizer, GameShell.
78 Kotlin / 3 Java remaining (Game, MapRegion, CollisionMap).

Renamed obfuscated fields using rs-deob usage analysis:
- Animation: anInt431→delay, aBooleanArray438→noAlpha
- Actor: anInt1596→healthRatio, anInt1597→healthScale
- Player: anInt1743→objectX, anInt1745→objectY,
anInt1768-1771→objectMinTileX/Y, objectMaxTileX/Y

Fixed TypeFace.getDisplayedWidth @xxx@ color code skip — the for-in
loop made idx immutable so the shadowed variable hack never advanced
the loop counter, overcounting width and clipping centered text (e.g.
wilderness "Level: 1" rendered as "evel: 1").

+1742 -2079
+20 -19
src/main/java/com/jagex/runescape/Game.java
··· 1106 1106 } 1107 1107 } 1108 1108 1109 - void mouseWheelDragged(int i, int j) { 1109 + @Override 1110 + public void mouseWheelDragged(int i, int j) { 1110 1111 if (!mouseWheelDown) 1111 1112 return; 1112 1113 this.cameraVelocityHorizontal += i * 3; ··· 4652 4653 int j2 = buffer.getUnsignedPostNegativeOffsetByte(); 4653 4654 npc.updateHits(j2, j1, pulseCycle); 4654 4655 npc.endCycle = pulseCycle + 300; 4655 - npc.anInt1596 = buffer.getUnsignedByte(); 4656 - npc.anInt1597 = buffer.getUnsignedPreNegativeOffsetByte(); 4656 + npc.healthRatio = buffer.getUnsignedByte(); 4657 + npc.healthScale = buffer.getUnsignedPreNegativeOffsetByte(); 4657 4658 } 4658 4659 if ((i1 & 4) != 0) { 4659 4660 npc.graphic = buffer.getUnsignedShortBE(); ··· 4706 4707 int l2 = buffer.getUnsignedPreNegativeOffsetByte(); 4707 4708 npc.updateHits(l2, i2, pulseCycle); 4708 4709 npc.endCycle = pulseCycle + 300; 4709 - npc.anInt1596 = buffer.getUnsignedByte(); 4710 - npc.anInt1597 = buffer.getUnsignedInvertedByte(); 4710 + npc.healthRatio = buffer.getUnsignedByte(); 4711 + npc.healthScale = buffer.getUnsignedInvertedByte(); 4711 4712 } 4712 4713 } 4713 4714 ··· 4826 4827 player.updateHits(type, damage, pulseCycle); 4827 4828 4828 4829 player.endCycle = pulseCycle + 300; 4829 - player.anInt1596 = buffer.getUnsignedInvertedByte(); 4830 - player.anInt1597 = buffer.getUnsignedByte(); 4830 + player.healthRatio = buffer.getUnsignedInvertedByte(); 4831 + player.healthScale = buffer.getUnsignedByte(); 4831 4832 } 4832 4833 4833 4834 if ((mask & 0x40) != 0) { ··· 4886 4887 player.updateHits(type, damage, pulseCycle); 4887 4888 4888 4889 player.endCycle = pulseCycle + 300; 4889 - player.anInt1596 = buffer.getUnsignedPreNegativeOffsetByte(); 4890 - player.anInt1597 = buffer.getUnsignedByte(); 4890 + player.healthRatio = buffer.getUnsignedPreNegativeOffsetByte(); 4891 + player.healthScale = buffer.getUnsignedByte(); 4891 4892 } 4892 4893 } 4893 4894 ··· 9044 9045 player.drawHeight2 = getFloorDrawHeight( 9045 9046 plane, player.worldX, player.worldY 9046 9047 ); 9047 - currentScene.addEntity(player.anInt1768, player.anInt1769, plane, player.worldX, player.worldY, player.drawHeight2, 9048 - player.currentRotation, player.anInt1771, player.anInt1770, player, 9048 + currentScene.addEntity(player.objectMinTileX, player.objectMinTileY, plane, player.worldX, player.worldY, player.drawHeight2, 9049 + player.currentRotation, player.objectMaxTileY, player.objectMaxTileX, player, 9049 9050 hash); 9050 9051 continue; 9051 9052 } ··· 9961 9962 if (((Actor) (obj)).endCycle > pulseCycle) { 9962 9963 setDrawXY(((Actor) (obj)), ((Actor) (obj)).modelHeight + 15); 9963 9964 if (drawX > -1) { 9964 - int l = (((Actor) (obj)).anInt1596 * 30) / ((Actor) (obj)).anInt1597; 9965 + int l = (((Actor) (obj)).healthRatio * 30) / ((Actor) (obj)).healthScale; 9965 9966 if (l > 30) 9966 9967 l = 30; 9967 9968 Rasterizer.drawFilledRectangle(drawX - 15, drawY - 3, l, 5, 65280); ··· 10630 10631 i23 = object.sizeY; 10631 10632 j23 = object.sizeX; 10632 10633 } 10633 - player.anInt1743 = x * 128 + i23 * 64; 10634 - player.anInt1745 = y * 128 + j23 * 64; 10635 - player.drawHeight = getFloorDrawHeight(plane, player.anInt1743, player.anInt1745 10634 + player.objectX = x * 128 + i23 * 64; 10635 + player.objectY = y * 128 + j23 * 64; 10636 + player.drawHeight = getFloorDrawHeight(plane, player.objectX, player.objectY 10636 10637 ); 10637 10638 if (byte1 > byte0) { 10638 10639 byte byte4 = byte1; ··· 10644 10645 byte3 = byte2; 10645 10646 byte2 = byte5; 10646 10647 } 10647 - player.anInt1768 = x + byte1; 10648 - player.anInt1770 = x + byte0; 10649 - player.anInt1769 = y + byte3; 10650 - player.anInt1771 = y + byte2; 10648 + player.objectMinTileX = x + byte1; 10649 + player.objectMaxTileX = x + byte0; 10650 + player.objectMinTileY = y + byte3; 10651 + player.objectMaxTileY = y + byte2; 10651 10652 } 10652 10653 } 10653 10654 }
-41
src/main/java/com/jagex/runescape/GameFrame.java
··· 1 - package com.jagex.runescape; 2 - 3 - import javax.swing.*; 4 - import java.awt.*; 5 - 6 - @SuppressWarnings("serial") 7 - public class GameFrame extends JFrame { 8 - private final GameShell gameStub; 9 - 10 - public GameFrame(GameShell gameStub, int width, int height) { 11 - this.gameStub = gameStub; 12 - pack(); 13 - setTitle("Jagex"); 14 - setResizable(false); 15 - gameStub.extraWidth = getInsets().left; 16 - gameStub.extraHeight = getInsets().top; 17 - setSize(width + gameStub.extraWidth + getInsets().right, height + gameStub.extraHeight + getInsets().bottom); 18 - setVisible(true); 19 - toFront(); 20 - 21 - 22 - } 23 - 24 - @Override 25 - public Graphics getGraphics() { 26 - Graphics graphics = super.getGraphics(); 27 - graphics.translate(gameStub.extraWidth, gameStub.extraHeight); 28 - return graphics; 29 - } 30 - 31 - @Override 32 - public void update(Graphics graphics) { 33 - gameStub.update(); 34 - } 35 - 36 - @Override 37 - public void paint(Graphics graphics) { 38 - gameStub.paint(); 39 - } 40 - 41 - }
+32
src/main/java/com/jagex/runescape/GameFrame.kt
··· 1 + package com.jagex.runescape 2 + 3 + import java.awt.Graphics 4 + import javax.swing.JFrame 5 + 6 + class GameFrame(private val gameStub: GameShell, width: Int, height: Int) : JFrame() { 7 + 8 + init { 9 + pack() 10 + title = "Jagex" 11 + isResizable = false 12 + gameStub.extraWidth = insets.left 13 + gameStub.extraHeight = insets.top 14 + setSize(width + gameStub.extraWidth + insets.right, height + gameStub.extraHeight + insets.bottom) 15 + isVisible = true 16 + toFront() 17 + } 18 + 19 + override fun getGraphics(): Graphics { 20 + val graphics = super.getGraphics() 21 + graphics.translate(gameStub.extraWidth, gameStub.extraHeight) 22 + return graphics 23 + } 24 + 25 + override fun update(graphics: Graphics) { 26 + gameStub.update() 27 + } 28 + 29 + override fun paint(graphics: Graphics) { 30 + gameStub.paint() 31 + } 32 + }
-581
src/main/java/com/jagex/runescape/GameShell.java
··· 1 - package com.jagex.runescape; 2 - 3 - import com.jagex.runescape.cache.media.ImageRGB; 4 - import com.jagex.runescape.cache.media.Widget; 5 - import com.jagex.runescape.media.ProducingGraphicsBuffer; 6 - 7 - import java.awt.*; 8 - import java.awt.event.*; 9 - 10 - @SuppressWarnings("serial") 11 - public class GameShell extends Canvas implements Runnable, MouseListener, MouseMotionListener, KeyListener, 12 - MouseWheelListener, FocusListener, WindowListener { 13 - 14 - 15 - private int gameState; 16 - private int deltime = 20; 17 - public int mindel = 1; 18 - private long optims[] = new long[10]; 19 - public int fps; 20 - public int cameraZoom = 600; 21 - public boolean dumpRequested = false; 22 - public int width; 23 - public int height; 24 - public int extraWidth = 0; 25 - public int extraHeight = 22; 26 - public Graphics gameGraphics; 27 - public ProducingGraphicsBuffer imageProducer; 28 - public ImageRGB aClass50_Sub1_Sub1_Sub1Array16[] = new ImageRGB[6]; 29 - public GameFrame gameFrame; 30 - public boolean clearScreen = true; 31 - public boolean awtFocus = true; 32 - public int idleTime; 33 - public int mouseButtonPressed; 34 - public int mouseX; 35 - public int mouseY; 36 - public int eventMouseButtonPressed; 37 - public int eventClickX; 38 - public int eventClickY; 39 - public long lastClick; 40 - public int clickType; 41 - public int clickX; 42 - public int clickY; 43 - public long clickTime; 44 - public int keyStatus[] = new int[128]; 45 - private int inputBuffer[] = new int[128]; 46 - private int readIndex; 47 - private int writeIndex; 48 - public boolean mouseWheelDown; 49 - public int mouseWheelX; 50 - public int mouseWheelY; 51 - 52 - 53 - public final void initializeApplication(int _width, int _height) { 54 - width = _width; 55 - height = _height; 56 - gameFrame = new GameFrame(this, width, height); 57 - gameGraphics = gameFrame.getGraphics(); 58 - // this.height = this.height + this.extraHeight; 59 - // gameGraphics.translate(extraWidth, extraHeight); 60 - imageProducer = new ProducingGraphicsBuffer(width, height, gameFrame); 61 - // this.setPreferredSize(new Dimension(width, height)); 62 - // this.setMaximumSize(new Dimension(width, height)); 63 - // this.setMinimumSize(new Dimension(width, height)); 64 - // gameFrame.add(this); 65 - // gameFrame.pack(); 66 - 67 - startRunnable(this, 1); 68 - } 69 - 70 - public final void initializeApplet(int width, int height) { 71 - this.width = width; 72 - this.height = height; 73 - gameGraphics = gameFrame.getGraphics(); 74 - imageProducer = new ProducingGraphicsBuffer(this.width, this.height, getParentComponent()); 75 - startRunnable(this, 1); 76 - } 77 - 78 - public void run() { 79 - gameFrame.addMouseListener(this); 80 - gameFrame.addMouseMotionListener(this); 81 - gameFrame.addMouseWheelListener(this); 82 - gameFrame.addKeyListener(this); 83 - gameFrame.addFocusListener(this); 84 - if (gameFrame != null) { 85 - // Handle SIGTERM and exit 86 - gameFrame.addWindowListener(new WindowAdapter() { 87 - @Override 88 - public void windowClosing(WindowEvent event) { 89 - System.out.println("Closing Client..."); 90 - System.exit(0); 91 - } 92 - }); 93 - } 94 - 95 - drawLoadingText(0, "Loading..."); 96 - startup(); 97 - int opos = 0; 98 - int ratio = 256; 99 - int del = 1; 100 - int count = 0; 101 - int intex = 0; 102 - for (int optim = 0; optim < 10; optim++) 103 - optims[optim] = System.currentTimeMillis(); 104 - 105 - while (gameState >= 0) { 106 - if (gameState > 0) { 107 - gameState--; 108 - if (gameState == 0) { 109 - exit(); 110 - return; 111 - } 112 - } 113 - ratio = 300; 114 - del = 1; 115 - long currentTime = System.currentTimeMillis(); 116 - if (currentTime > optims[opos]) 117 - ratio = (int) ((2560 * deltime) / (currentTime - optims[opos])); 118 - if (ratio < 25) 119 - ratio = 25; 120 - if (ratio > 256) { 121 - ratio = 256; 122 - del = (int) (deltime - (currentTime - optims[opos]) / 10L); 123 - } 124 - if (del > deltime) 125 - del = deltime; 126 - optims[opos] = currentTime; 127 - opos = (opos + 1) % 10; 128 - if (del > 1) { 129 - for (int optim = 0; optim < 10; optim++) 130 - if (optims[optim] != 0L) 131 - optims[optim] += del; 132 - 133 - } 134 - if (del < mindel) 135 - del = mindel; 136 - try { 137 - Thread.sleep(del); 138 - } catch (InterruptedException _ex) { 139 - intex++; 140 - } 141 - for (; count < 256; count += ratio) { 142 - clickType = eventMouseButtonPressed; 143 - clickX = eventClickX; 144 - clickY = eventClickY; 145 - clickTime = lastClick; 146 - eventMouseButtonPressed = 0; 147 - processGameLoop(); 148 - readIndex = writeIndex; 149 - } 150 - 151 - count &= 0xff; 152 - if (deltime > 0) 153 - fps = (1000 * ratio) / (deltime * 256); 154 - repaintGame(); 155 - if (dumpRequested) { 156 - System.out.println("ntime:" + currentTime); 157 - for (int i = 0; i < 10; i++) { 158 - int optim = ((opos - i - 1) + 20) % 10; 159 - System.out.println("otim" + optim + ":" + optims[optim]); 160 - } 161 - 162 - System.out.println("fps:" + fps + " ratio:" + ratio + " count:" + count); 163 - System.out.println("del:" + del + " deltime:" + deltime + " mindel:" + mindel); 164 - System.out.println("intex:" + intex + " opos:" + opos); 165 - dumpRequested = false; 166 - intex = 0; 167 - } 168 - } 169 - if (gameState == -1) 170 - exit(); 171 - } 172 - 173 - public void exit() { 174 - gameState = -2; 175 - shutdown(); 176 - if (gameFrame != null) { 177 - try { 178 - Thread.sleep(1000L); 179 - } catch (Exception _ex) { 180 - } 181 - System.exit(0); 182 - } 183 - } 184 - 185 - public void setFrameRate(int i) { 186 - deltime = 1000 / i; 187 - } 188 - 189 - public void start() { 190 - if (gameState >= 0) 191 - gameState = 0; 192 - } 193 - 194 - public void stop() { 195 - if (gameState >= 0) 196 - gameState = 4000 / deltime; 197 - } 198 - 199 - public void destroy() { 200 - gameState = -1; 201 - try { 202 - Thread.sleep(10000L); 203 - } catch (Exception _ex) { 204 - } 205 - if (gameState == -1) 206 - exit(); 207 - } 208 - 209 - public void update() { 210 - clearScreen = true; 211 - redraw(); 212 - } 213 - 214 - public void paint() { 215 - clearScreen = true; 216 - redraw(); 217 - } 218 - 219 - public void mousePressed(MouseEvent mouseevent) { 220 - int mouseX = mouseevent.getX(); 221 - int mouseY = mouseevent.getY(); 222 - if (gameFrame != null) { 223 - mouseX -= extraWidth; 224 - mouseY -= 2 + extraHeight; 225 - } 226 - idleTime = 0; 227 - eventClickX = mouseX; 228 - eventClickY = mouseY; 229 - lastClick = System.currentTimeMillis(); 230 - if (mouseevent.getButton() == MouseEvent.BUTTON2) { 231 - mouseWheelDown = true; 232 - mouseWheelX = mouseX; 233 - mouseWheelY = mouseY; 234 - return; 235 - } 236 - if (mouseevent.isMetaDown() || mouseevent.getButton() == MouseEvent.BUTTON3) { 237 - eventMouseButtonPressed = 2; 238 - mouseButtonPressed = 2; 239 - } else { 240 - eventMouseButtonPressed = 1; 241 - mouseButtonPressed = 1; 242 - } 243 - } 244 - 245 - public void mouseReleased(MouseEvent mouseevent) { 246 - idleTime = 0; 247 - mouseButtonPressed = 0; 248 - mouseWheelDown = false; 249 - } 250 - 251 - public void mouseClicked(MouseEvent mouseevent) { 252 - } 253 - 254 - public void mouseEntered(MouseEvent mouseevent) { 255 - } 256 - 257 - public void mouseExited(MouseEvent mouseevent) { 258 - idleTime = 0; 259 - mouseX = -1; 260 - mouseY = -1; 261 - } 262 - 263 - public void mouseDragged(MouseEvent mouseevent) { 264 - int mouseX = mouseevent.getX(); 265 - int mouseY = mouseevent.getY(); 266 - if (gameFrame != null) { 267 - mouseX -= extraWidth; 268 - mouseY -= 2 + extraHeight; 269 - } 270 - if (mouseWheelDown) { 271 - mouseY = mouseWheelX - mouseevent.getX(); 272 - int k = mouseWheelY - mouseevent.getY(); 273 - mouseWheelDragged(mouseY, -k); 274 - mouseWheelX = mouseevent.getX(); 275 - mouseWheelY = mouseevent.getY(); 276 - return; 277 - } 278 - idleTime = 0; 279 - this.mouseX = mouseX; 280 - this.mouseY = mouseY; 281 - } 282 - 283 - void mouseWheelDragged(int param1, int param2) { 284 - 285 - } 286 - 287 - public void mouseMoved(MouseEvent mouseevent) { 288 - int mouseX = mouseevent.getX(); 289 - int mouseY = mouseevent.getY(); 290 - if (gameFrame != null) { 291 - mouseX -= extraWidth; 292 - mouseY -= 2 + extraHeight; 293 - } 294 - idleTime = 0; 295 - this.mouseX = mouseX; 296 - this.mouseY = mouseY; 297 - } 298 - 299 - public void keyPressed(KeyEvent keyevent) { 300 - idleTime = 0; 301 - int keyCode = keyevent.getKeyCode(); 302 - int keyChar = keyevent.getKeyChar(); 303 - if (keyChar < 30) 304 - keyChar = 0; 305 - if (keyCode == 37) 306 - keyChar = 1; 307 - if (keyCode == 39) 308 - keyChar = 2; 309 - if (keyCode == 38) 310 - keyChar = 3; 311 - if (keyCode == 40) 312 - keyChar = 4; 313 - if (keyCode == 17) 314 - keyChar = 5; 315 - if (keyCode == 16) 316 - keyChar = 6; 317 - if (keyCode == 8) 318 - keyChar = 8; 319 - if (keyCode == 127) 320 - keyChar = 8; 321 - if (keyCode == 9) 322 - keyChar = 9; 323 - if (keyCode == 10) 324 - keyChar = 10; 325 - if (keyCode >= 112 && keyCode <= 123) 326 - keyChar = (1008 + keyCode) - 112; 327 - if (keyCode == 36) 328 - keyChar = 1000; 329 - if (keyCode == 35) 330 - keyChar = 1001; 331 - if (keyCode == 33) 332 - keyChar = 1002; 333 - if (keyCode == 34) 334 - keyChar = 1003; 335 - if (keyChar > 0 && keyChar < 128) 336 - keyStatus[keyChar] = 1; 337 - if (keyChar > 4) { 338 - inputBuffer[writeIndex] = keyChar; 339 - writeIndex = writeIndex + 1 & 0x7f; 340 - } 341 - } 342 - 343 - public void keyReleased(KeyEvent keyevent) { 344 - idleTime = 0; 345 - int keyCode = keyevent.getKeyCode(); 346 - char keyChar = keyevent.getKeyChar(); 347 - if (keyChar < '\036') 348 - keyChar = '\0'; 349 - if (keyCode == 37) 350 - keyChar = '\001'; 351 - if (keyCode == 39) 352 - keyChar = '\002'; 353 - if (keyCode == 38) 354 - keyChar = '\003'; 355 - if (keyCode == 40) 356 - keyChar = '\004'; 357 - if (keyCode == 17) 358 - keyChar = '\005'; 359 - if (keyCode == 16) 360 - keyChar = '\006'; 361 - if (keyCode == 8) 362 - keyChar = '\b'; 363 - if (keyCode == 127) 364 - keyChar = '\b'; 365 - if (keyCode == 9) 366 - keyChar = '\t'; 367 - if (keyCode == 10) 368 - keyChar = '\n'; 369 - if (keyChar > 0 && keyChar < '\200') 370 - keyStatus[keyChar] = 0; 371 - } 372 - 373 - public void keyTyped(KeyEvent keyevent) { 374 - } 375 - 376 - public int readCharacter() { 377 - int character = -1; 378 - if (writeIndex != readIndex) { 379 - character = inputBuffer[readIndex]; 380 - readIndex = readIndex + 1 & 0x7f; 381 - } 382 - return character; 383 - } 384 - 385 - public void focusGained(FocusEvent focusevent) { 386 - awtFocus = true; 387 - clearScreen = true; 388 - redraw(); 389 - } 390 - 391 - public void focusLost(FocusEvent focusevent) { 392 - awtFocus = false; 393 - for (int key = 0; key < 128; key++) 394 - keyStatus[key] = 0; 395 - 396 - } 397 - 398 - public void windowActivated(WindowEvent windowevent) { 399 - } 400 - 401 - public void windowClosed(WindowEvent windowevent) { 402 - } 403 - 404 - public void windowClosing(WindowEvent windowevent) { 405 - destroy(); 406 - } 407 - 408 - public void windowDeactivated(WindowEvent windowevent) { 409 - } 410 - 411 - public void windowDeiconified(WindowEvent windowevent) { 412 - } 413 - 414 - public void windowIconified(WindowEvent windowevent) { 415 - } 416 - 417 - public void windowOpened(WindowEvent windowevent) { 418 - } 419 - 420 - public void startup() { 421 - } 422 - 423 - public void processGameLoop() { 424 - } 425 - 426 - public void shutdown() { 427 - } 428 - 429 - public void repaintGame() { 430 - } 431 - 432 - public void redraw() { 433 - } 434 - 435 - public Component getParentComponent() { 436 - if (gameFrame != null) 437 - return gameFrame; 438 - else 439 - return this; 440 - } 441 - 442 - public void startRunnable(Runnable runnable, int priority) { 443 - Thread thread = new Thread(runnable); 444 - thread.start(); 445 - thread.setPriority(priority); 446 - } 447 - 448 - public void mouseWheelMoved(MouseWheelEvent event) { 449 - int rotation = event.getWheelRotation(); 450 - if (this instanceof Game) { 451 - if (!handleInterfaceScrolling(event, (Game) this)) { 452 - if ((cameraZoom <= 300 && rotation <= 0) 453 - || (cameraZoom >= 1200 && rotation >= 0)) { 454 - return; 455 - } 456 - int diff = rotation * 8; 457 - cameraZoom = cameraZoom + diff; 458 - } 459 - } 460 - } 461 - 462 - public boolean handleInterfaceScrolling(MouseWheelEvent event, Game client) { 463 - int rotation = event.getWheelRotation(); 464 - if (mouseX > 0 && mouseY > 346 && mouseX < 516 && mouseY < 505 && client.openChatboxWidgetId == -1) { 465 - if (rotation < 0) { 466 - if (client.chatboxInterface.scrollPosition >= 1) { 467 - 468 - if (client.inputType == 3) { 469 - client.itemSearchScroll = client.itemSearchScroll - 30; 470 - client.redrawChatbox = true; 471 - } else { 472 - client.chatboxScroll = client.chatboxScroll + 30; 473 - client.redrawChatbox = true; 474 - } 475 - } 476 - } else { 477 - if (client.inputType == 3) { 478 - client.itemSearchScroll = client.itemSearchScroll + 30; 479 - client.redrawChatbox = true; 480 - } else if (client.chatboxScroll < 1) { 481 - client.chatboxScroll = 0; 482 - client.redrawChatbox = true; 483 - } else { 484 - client.chatboxScroll = client.chatboxScroll - 30; 485 - client.redrawChatbox = true; 486 - } 487 - } 488 - return true; 489 - } else { 490 - int positionX = 0; 491 - int positionY = 0; 492 - int width = 0; 493 - int height = 0; 494 - int offsetX = 0; 495 - int offsetY = 0; 496 - int childID = 0; 497 - /* Tab interface scrolling */ 498 - int tabInterfaceID = client.tabWidgetIds[client.currentTabId]; 499 - if (tabInterfaceID != -1) { 500 - Widget tab = Widget.interfaces[tabInterfaceID]; 501 - offsetX = 765 - 218; 502 - offsetY = 503 - 298; 503 - for (int index = 0; index < tab.children.length; index++) { 504 - if (Widget.interfaces[tab.children[index]].scrollLimit > 0) { 505 - childID = index; 506 - positionX = tab.childrenX[index]; 507 - positionY = tab.childrenY[index]; 508 - width = Widget.interfaces[tab.children[index]].width; 509 - height = Widget.interfaces[tab.children[index]].height; 510 - break; 511 - } 512 - } 513 - if (mouseX > offsetX + positionX && mouseY > offsetY + positionY && mouseX < offsetX + positionX + width && mouseY < offsetY + positionY + height) { 514 - Widget.interfaces[tab.children[childID]].scrollPosition += rotation * 30; 515 - // client.tabAreaAltered = true; 516 - client.redrawTabArea = true; 517 - return true; 518 - } 519 - } 520 - /* Main interface scrolling */ 521 - if (client.openScreenWidgetId != -1) { 522 - Widget widget = Widget.interfaces[client.openScreenWidgetId]; 523 - offsetX = 4; 524 - offsetY = 4; 525 - for (int index = 0; index < widget.children.length; index++) { 526 - if (Widget.interfaces[widget.children[index]].scrollLimit > 0) { 527 - childID = index; 528 - positionX = widget.childrenX[index]; 529 - positionY = widget.childrenY[index]; 530 - width = Widget.interfaces[widget.children[index]].width; 531 - height = Widget.interfaces[widget.children[index]].height; 532 - break; 533 - } 534 - } 535 - if (mouseX > offsetX + positionX && mouseY > offsetY + positionY && mouseX < offsetX + positionX + width && mouseY < offsetY + positionY + height) { 536 - Widget.interfaces[widget.children[childID]].scrollPosition += rotation * 30; 537 - return true; 538 - } 539 - 540 - } 541 - } 542 - return false; 543 - 544 - 545 - } 546 - 547 - public void drawLoadingText(int percent, String desc) { 548 - while (gameGraphics == null) { 549 - gameGraphics = gameFrame.getGraphics(); 550 - try { 551 - gameFrame.repaint(); 552 - } catch (Exception _ex) { 553 - } 554 - try { 555 - Thread.sleep(1000L); 556 - } catch (Exception _ex) { 557 - } 558 - } 559 - Font helveticaBold = new Font("Helvetica", 1, 13); 560 - FontMetrics fontmetrics = getParentComponent().getFontMetrics(helveticaBold); 561 - Font helvetica = new Font("Helvetica", 0, 13); 562 - getParentComponent().getFontMetrics(helvetica); 563 - if (clearScreen) { 564 - gameGraphics.setColor(Color.black); 565 - gameGraphics.fillRect(0, 0, width, height); 566 - clearScreen = false; 567 - } 568 - Color color = new Color(140, 17, 17); 569 - int centerHeight = height / 2 - 18; 570 - gameGraphics.setColor(color); 571 - gameGraphics.drawRect(width / 2 - 152, centerHeight, 304, 34); 572 - gameGraphics.fillRect(width / 2 - 150, centerHeight + 2, percent * 3, 30); 573 - gameGraphics.setColor(Color.black); 574 - gameGraphics.fillRect((width / 2 - 150) + percent * 3, centerHeight + 2, 300 - percent * 3, 30); 575 - gameGraphics.setFont(helveticaBold); 576 - gameGraphics.setColor(Color.white); 577 - gameGraphics.drawString(desc, (width - fontmetrics.stringWidth(desc)) / 2, centerHeight + 22); 578 - } 579 - 580 - 581 - }
+469
src/main/java/com/jagex/runescape/GameShell.kt
··· 1 + package com.jagex.runescape 2 + 3 + import com.jagex.runescape.cache.media.ImageRGB 4 + import com.jagex.runescape.cache.media.Widget 5 + import com.jagex.runescape.media.ProducingGraphicsBuffer 6 + import java.awt.* 7 + import java.awt.event.* 8 + 9 + open class GameShell : Canvas(), Runnable, MouseListener, MouseMotionListener, KeyListener, 10 + MouseWheelListener, FocusListener, WindowListener { 11 + 12 + private var gameState: Int = 0 13 + private var deltime: Int = 20 14 + @JvmField var mindel: Int = 1 15 + private val optims: LongArray = LongArray(10) 16 + @JvmField var fps: Int = 0 17 + @JvmField var cameraZoom: Int = 600 18 + @JvmField var dumpRequested: Boolean = false 19 + @JvmField var width: Int = 0 20 + @JvmField var height: Int = 0 21 + @JvmField var extraWidth: Int = 0 22 + @JvmField var extraHeight: Int = 22 23 + @JvmField var gameGraphics: Graphics? = null 24 + @JvmField var imageProducer: ProducingGraphicsBuffer? = null 25 + @JvmField var aClass50_Sub1_Sub1_Sub1Array16: Array<ImageRGB?> = arrayOfNulls(6) 26 + @JvmField var gameFrame: GameFrame? = null 27 + @JvmField var clearScreen: Boolean = true 28 + @JvmField var awtFocus: Boolean = true 29 + @JvmField var idleTime: Int = 0 30 + @JvmField var mouseButtonPressed: Int = 0 31 + @JvmField var mouseX: Int = 0 32 + @JvmField var mouseY: Int = 0 33 + @JvmField var eventMouseButtonPressed: Int = 0 34 + @JvmField var eventClickX: Int = 0 35 + @JvmField var eventClickY: Int = 0 36 + @JvmField var lastClick: Long = 0L 37 + @JvmField var clickType: Int = 0 38 + @JvmField var clickX: Int = 0 39 + @JvmField var clickY: Int = 0 40 + @JvmField var clickTime: Long = 0L 41 + @JvmField var keyStatus: IntArray = IntArray(128) 42 + private val inputBuffer: IntArray = IntArray(128) 43 + private var readIndex: Int = 0 44 + private var writeIndex: Int = 0 45 + @JvmField var mouseWheelDown: Boolean = false 46 + @JvmField var mouseWheelX: Int = 0 47 + @JvmField var mouseWheelY: Int = 0 48 + 49 + fun initializeApplication(width: Int, height: Int) { 50 + this.width = width 51 + this.height = height 52 + gameFrame = GameFrame(this, width, height) 53 + gameGraphics = gameFrame!!.graphics 54 + imageProducer = ProducingGraphicsBuffer(width, height, gameFrame!!) 55 + startRunnable(this, 1) 56 + } 57 + 58 + fun initializeApplet(width: Int, height: Int) { 59 + this.width = width 60 + this.height = height 61 + gameGraphics = gameFrame!!.graphics 62 + imageProducer = ProducingGraphicsBuffer(this.width, this.height, getParentComponent()) 63 + startRunnable(this, 1) 64 + } 65 + 66 + override fun run() { 67 + gameFrame!!.addMouseListener(this) 68 + gameFrame!!.addMouseMotionListener(this) 69 + gameFrame!!.addMouseWheelListener(this) 70 + gameFrame!!.addKeyListener(this) 71 + gameFrame!!.addFocusListener(this) 72 + gameFrame!!.addWindowListener(object : WindowAdapter() { 73 + override fun windowClosing(event: WindowEvent) { 74 + println("Closing Client...") 75 + System.exit(0) 76 + } 77 + }) 78 + 79 + drawLoadingText(0, "Loading...") 80 + startup() 81 + var opos = 0 82 + var ratio = 256 83 + var del = 1 84 + var count = 0 85 + var intex = 0 86 + for (optim in 0 until 10) 87 + optims[optim] = System.currentTimeMillis() 88 + 89 + while (gameState >= 0) { 90 + if (gameState > 0) { 91 + gameState-- 92 + if (gameState == 0) { 93 + exit() 94 + return 95 + } 96 + } 97 + ratio = 300 98 + del = 1 99 + val currentTime = System.currentTimeMillis() 100 + if (currentTime > optims[opos]) 101 + ratio = ((2560 * deltime) / (currentTime - optims[opos])).toInt() 102 + if (ratio < 25) ratio = 25 103 + if (ratio > 256) { 104 + ratio = 256 105 + del = (deltime - (currentTime - optims[opos]) / 10L).toInt() 106 + } 107 + if (del > deltime) del = deltime 108 + optims[opos] = currentTime 109 + opos = (opos + 1) % 10 110 + if (del > 1) { 111 + for (optim in 0 until 10) 112 + if (optims[optim] != 0L) 113 + optims[optim] += del.toLong() 114 + } 115 + if (del < mindel) del = mindel 116 + try { 117 + Thread.sleep(del.toLong()) 118 + } catch (_: InterruptedException) { 119 + intex++ 120 + } 121 + while (count < 256) { 122 + clickType = eventMouseButtonPressed 123 + clickX = eventClickX 124 + clickY = eventClickY 125 + clickTime = lastClick 126 + eventMouseButtonPressed = 0 127 + processGameLoop() 128 + readIndex = writeIndex 129 + count += ratio 130 + } 131 + count = count and 0xff 132 + if (deltime > 0) 133 + fps = (1000 * ratio) / (deltime * 256) 134 + repaintGame() 135 + if (dumpRequested) { 136 + println("ntime:$currentTime") 137 + for (i in 0 until 10) { 138 + val optim = ((opos - i - 1) + 20) % 10 139 + println("otim$optim:${optims[optim]}") 140 + } 141 + println("fps:$fps ratio:$ratio count:$count") 142 + println("del:$del deltime:$deltime mindel:$mindel") 143 + println("intex:$intex opos:$opos") 144 + dumpRequested = false 145 + intex = 0 146 + } 147 + } 148 + if (gameState == -1) exit() 149 + } 150 + 151 + open fun exit() { 152 + gameState = -2 153 + shutdown() 154 + if (gameFrame != null) { 155 + try { Thread.sleep(1000L) } catch (_: Exception) {} 156 + System.exit(0) 157 + } 158 + } 159 + 160 + fun setFrameRate(i: Int) { 161 + deltime = 1000 / i 162 + } 163 + 164 + fun start() { 165 + if (gameState >= 0) gameState = 0 166 + } 167 + 168 + fun stop() { 169 + if (gameState >= 0) gameState = 4000 / deltime 170 + } 171 + 172 + fun destroy() { 173 + gameState = -1 174 + try { Thread.sleep(10000L) } catch (_: Exception) {} 175 + if (gameState == -1) exit() 176 + } 177 + 178 + fun update() { 179 + clearScreen = true 180 + redraw() 181 + } 182 + 183 + fun paint() { 184 + clearScreen = true 185 + redraw() 186 + } 187 + 188 + override fun mousePressed(mouseevent: MouseEvent) { 189 + var mx = mouseevent.x 190 + var my = mouseevent.y 191 + if (gameFrame != null) { 192 + mx -= extraWidth 193 + my -= 2 + extraHeight 194 + } 195 + idleTime = 0 196 + eventClickX = mx 197 + eventClickY = my 198 + lastClick = System.currentTimeMillis() 199 + if (mouseevent.button == MouseEvent.BUTTON2) { 200 + mouseWheelDown = true 201 + mouseWheelX = mx 202 + mouseWheelY = my 203 + return 204 + } 205 + if (mouseevent.isMetaDown || mouseevent.button == MouseEvent.BUTTON3) { 206 + eventMouseButtonPressed = 2 207 + mouseButtonPressed = 2 208 + } else { 209 + eventMouseButtonPressed = 1 210 + mouseButtonPressed = 1 211 + } 212 + } 213 + 214 + override fun mouseReleased(mouseevent: MouseEvent) { 215 + idleTime = 0 216 + mouseButtonPressed = 0 217 + mouseWheelDown = false 218 + } 219 + 220 + override fun mouseClicked(mouseevent: MouseEvent) {} 221 + override fun mouseEntered(mouseevent: MouseEvent) {} 222 + 223 + override fun mouseExited(mouseevent: MouseEvent) { 224 + idleTime = 0 225 + mouseX = -1 226 + mouseY = -1 227 + } 228 + 229 + override fun mouseDragged(mouseevent: MouseEvent) { 230 + var mx = mouseevent.x 231 + var my = mouseevent.y 232 + if (gameFrame != null) { 233 + mx -= extraWidth 234 + my -= 2 + extraHeight 235 + } 236 + if (mouseWheelDown) { 237 + val dy = mouseWheelX - mouseevent.x 238 + val k = mouseWheelY - mouseevent.y 239 + mouseWheelDragged(dy, -k) 240 + mouseWheelX = mouseevent.x 241 + mouseWheelY = mouseevent.y 242 + return 243 + } 244 + idleTime = 0 245 + mouseX = mx 246 + mouseY = my 247 + } 248 + 249 + open fun mouseWheelDragged(param1: Int, param2: Int) {} 250 + 251 + 252 + 253 + override fun mouseMoved(mouseevent: MouseEvent) { 254 + var mx = mouseevent.x 255 + var my = mouseevent.y 256 + if (gameFrame != null) { 257 + mx -= extraWidth 258 + my -= 2 + extraHeight 259 + } 260 + idleTime = 0 261 + mouseX = mx 262 + mouseY = my 263 + } 264 + 265 + override fun keyPressed(keyevent: KeyEvent) { 266 + idleTime = 0 267 + val keyCode = keyevent.keyCode 268 + var keyChar = keyevent.keyChar.code 269 + if (keyChar < 30) keyChar = 0 270 + if (keyCode == 37) keyChar = 1 271 + if (keyCode == 39) keyChar = 2 272 + if (keyCode == 38) keyChar = 3 273 + if (keyCode == 40) keyChar = 4 274 + if (keyCode == 17) keyChar = 5 275 + if (keyCode == 16) keyChar = 6 276 + if (keyCode == 8) keyChar = 8 277 + if (keyCode == 127) keyChar = 8 278 + if (keyCode == 9) keyChar = 9 279 + if (keyCode == 10) keyChar = 10 280 + if (keyCode in 112..123) keyChar = (1008 + keyCode) - 112 281 + if (keyCode == 36) keyChar = 1000 282 + if (keyCode == 35) keyChar = 1001 283 + if (keyCode == 33) keyChar = 1002 284 + if (keyCode == 34) keyChar = 1003 285 + if (keyChar in 1..127) keyStatus[keyChar] = 1 286 + if (keyChar > 4) { 287 + inputBuffer[writeIndex] = keyChar 288 + writeIndex = writeIndex + 1 and 0x7f 289 + } 290 + } 291 + 292 + override fun keyReleased(keyevent: KeyEvent) { 293 + idleTime = 0 294 + val keyCode = keyevent.keyCode 295 + var keyChar = keyevent.keyChar.code 296 + if (keyChar < 30) keyChar = 0 297 + if (keyCode == 37) keyChar = 1 298 + if (keyCode == 39) keyChar = 2 299 + if (keyCode == 38) keyChar = 3 300 + if (keyCode == 40) keyChar = 4 301 + if (keyCode == 17) keyChar = 5 302 + if (keyCode == 16) keyChar = 6 303 + if (keyCode == 8) keyChar = 8 304 + if (keyCode == 127) keyChar = 8 305 + if (keyCode == 9) keyChar = 9 306 + if (keyCode == 10) keyChar = 10 307 + if (keyChar in 1..127) keyStatus[keyChar] = 0 308 + } 309 + 310 + override fun keyTyped(keyevent: KeyEvent) {} 311 + 312 + fun readCharacter(): Int { 313 + var character = -1 314 + if (writeIndex != readIndex) { 315 + character = inputBuffer[readIndex] 316 + readIndex = readIndex + 1 and 0x7f 317 + } 318 + return character 319 + } 320 + 321 + override fun focusGained(focusevent: FocusEvent) { 322 + awtFocus = true 323 + clearScreen = true 324 + redraw() 325 + } 326 + 327 + override fun focusLost(focusevent: FocusEvent) { 328 + awtFocus = false 329 + for (key in 0 until 128) keyStatus[key] = 0 330 + } 331 + 332 + override fun windowActivated(windowevent: WindowEvent) {} 333 + override fun windowClosed(windowevent: WindowEvent) {} 334 + override fun windowClosing(windowevent: WindowEvent) { destroy() } 335 + override fun windowDeactivated(windowevent: WindowEvent) {} 336 + override fun windowDeiconified(windowevent: WindowEvent) {} 337 + override fun windowIconified(windowevent: WindowEvent) {} 338 + override fun windowOpened(windowevent: WindowEvent) {} 339 + 340 + open fun startup() {} 341 + open fun processGameLoop() {} 342 + open fun shutdown() {} 343 + open fun repaintGame() {} 344 + open fun redraw() {} 345 + 346 + open fun getParentComponent(): Component = gameFrame ?: this 347 + 348 + open fun startRunnable(runnable: Runnable, priority: Int) { 349 + val thread = Thread(runnable) 350 + thread.start() 351 + thread.priority = priority 352 + } 353 + 354 + override fun mouseWheelMoved(event: MouseWheelEvent) { 355 + val rotation = event.wheelRotation 356 + if (this is Game) { 357 + if (!handleInterfaceScrolling(event, this)) { 358 + if ((cameraZoom <= 300 && rotation <= 0) || (cameraZoom >= 1200 && rotation >= 0)) 359 + return 360 + cameraZoom += rotation * 8 361 + } 362 + } 363 + } 364 + 365 + fun handleInterfaceScrolling(event: MouseWheelEvent, client: Game): Boolean { 366 + val rotation = event.wheelRotation 367 + if (mouseX > 0 && mouseY > 346 && mouseX < 516 && mouseY < 505 && client.openChatboxWidgetId == -1) { 368 + if (rotation < 0) { 369 + if (client.chatboxInterface.scrollPosition >= 1) { 370 + if (client.inputType == 3) { 371 + client.itemSearchScroll -= 30 372 + client.redrawChatbox = true 373 + } else { 374 + client.chatboxScroll += 30 375 + client.redrawChatbox = true 376 + } 377 + } 378 + } else { 379 + if (client.inputType == 3) { 380 + client.itemSearchScroll += 30 381 + client.redrawChatbox = true 382 + } else if (client.chatboxScroll < 1) { 383 + client.chatboxScroll = 0 384 + client.redrawChatbox = true 385 + } else { 386 + client.chatboxScroll -= 30 387 + client.redrawChatbox = true 388 + } 389 + } 390 + return true 391 + } else { 392 + var positionX = 0 393 + var positionY = 0 394 + var w = 0 395 + var h = 0 396 + var childID = 0 397 + val tabInterfaceID = client.tabWidgetIds[client.currentTabId] 398 + if (tabInterfaceID != -1) { 399 + val tab = Widget.interfaces!![tabInterfaceID]!! 400 + val offsetX = 765 - 218 401 + val offsetY = 503 - 298 402 + for (index in tab.children!!.indices) { 403 + if (Widget.interfaces!![tab.children!![index]]!!.scrollLimit > 0) { 404 + childID = index 405 + positionX = tab.childrenX!![index] 406 + positionY = tab.childrenY!![index] 407 + w = Widget.interfaces!![tab.children!![index]]!!.width 408 + h = Widget.interfaces!![tab.children!![index]]!!.height 409 + break 410 + } 411 + } 412 + if (mouseX > offsetX + positionX && mouseY > offsetY + positionY && 413 + mouseX < offsetX + positionX + w && mouseY < offsetY + positionY + h) { 414 + Widget.interfaces!![tab.children!![childID]]!!.scrollPosition += rotation * 30 415 + client.redrawTabArea = true 416 + return true 417 + } 418 + } 419 + if (client.openScreenWidgetId != -1) { 420 + val widget = Widget.interfaces!![client.openScreenWidgetId]!! 421 + val offsetX = 4 422 + val offsetY = 4 423 + for (index in widget.children!!.indices) { 424 + if (Widget.interfaces!![widget.children!![index]]!!.scrollLimit > 0) { 425 + childID = index 426 + positionX = widget.childrenX!![index] 427 + positionY = widget.childrenY!![index] 428 + w = Widget.interfaces!![widget.children!![index]]!!.width 429 + h = Widget.interfaces!![widget.children!![index]]!!.height 430 + break 431 + } 432 + } 433 + if (mouseX > offsetX + positionX && mouseY > offsetY + positionY && 434 + mouseX < offsetX + positionX + w && mouseY < offsetY + positionY + h) { 435 + Widget.interfaces!![widget.children!![childID]]!!.scrollPosition += rotation * 30 436 + return true 437 + } 438 + } 439 + } 440 + return false 441 + } 442 + 443 + open fun drawLoadingText(percent: Int, desc: String) { 444 + while (gameGraphics == null) { 445 + gameGraphics = gameFrame!!.graphics 446 + try { gameFrame!!.repaint() } catch (_: Exception) {} 447 + try { Thread.sleep(1000L) } catch (_: Exception) {} 448 + } 449 + val helveticaBold = Font("Helvetica", 1, 13) 450 + val fontmetrics = getParentComponent().getFontMetrics(helveticaBold) 451 + Font("Helvetica", 0, 13) 452 + getParentComponent().getFontMetrics(Font("Helvetica", 0, 13)) 453 + if (clearScreen) { 454 + gameGraphics!!.color = Color.black 455 + gameGraphics!!.fillRect(0, 0, width, height) 456 + clearScreen = false 457 + } 458 + val color = Color(140, 17, 17) 459 + val centerHeight = height / 2 - 18 460 + gameGraphics!!.color = color 461 + gameGraphics!!.drawRect(width / 2 - 152, centerHeight, 304, 34) 462 + gameGraphics!!.fillRect(width / 2 - 150, centerHeight + 2, percent * 3, 30) 463 + gameGraphics!!.color = Color.black 464 + gameGraphics!!.fillRect(width / 2 - 150 + percent * 3, centerHeight + 2, 300 - percent * 3, 30) 465 + gameGraphics!!.font = helveticaBold 466 + gameGraphics!!.color = Color.white 467 + gameGraphics!!.drawString(desc, (width - fontmetrics.stringWidth(desc)) / 2, centerHeight + 22) 468 + } 469 + }
+1 -1
src/main/java/com/jagex/runescape/cache/media/AnimationSequence.kt
··· 26 26 if (frameLength == 0) { 27 27 val animation = Animation.getAnimation(getPrimaryFrame!![animationId]) 28 28 if (animation != null) 29 - frameLength = animation.anInt431 29 + frameLength = animation.delay 30 30 frameLenghts!![animationId] = frameLength 31 31 } 32 32 if (frameLength == 0)
+6 -5
src/main/java/com/jagex/runescape/cache/media/TypeFace.kt
··· 90 90 var index = -1 91 91 var width = 0 92 92 val length = string.length 93 - for (idx in 0 until length) { 93 + var idx = 0 94 + while (idx < length) { 94 95 var character = string[idx].code 95 96 if (character == 60) { 96 97 index = idx ··· 114 115 } catch (_: Exception) { 115 116 } 116 117 } 118 + idx++ 117 119 continue 118 120 } 119 121 character = 174 120 122 } 121 123 } 122 - if (character == '@'.code && idx + 4 < string.length && string[idx + 4] == '@') { 123 - @Suppress("NAME_SHADOWING") 124 - var idx = idx 125 - idx += 4 124 + if (character == '@'.code && idx + 4 < length && string[idx + 4] == '@') { 125 + idx += 5 126 126 continue 127 127 } 128 128 if (index == -1) { 129 129 width += characterScreenWidths[character] 130 130 } 131 131 } 132 + idx++ 132 133 } 133 134 return width 134 135 }
-135
src/main/java/com/jagex/runescape/media/Animation.java
··· 1 - package com.jagex.runescape.media; 2 - 3 - import com.jagex.runescape.net.Buffer; 4 - 5 - public class Animation { 6 - public static Animation[] cache; 7 - public int anInt431; 8 - public Skins animationSkins; 9 - public int transformCount; 10 - public int opcodeTable[]; 11 - public int modifier1[]; 12 - public int modifier2[]; 13 - public int modifier3[]; 14 - public static boolean aBooleanArray438[]; 15 - 16 - public static void method235(int i) { 17 - cache = new Animation[i + 1]; 18 - aBooleanArray438 = new boolean[i + 1]; 19 - for (int j = 0; j < i + 1; j++) 20 - aBooleanArray438[j] = true; 21 - 22 - } 23 - 24 - public static void method236(byte[] bs) { 25 - Buffer buffer = new Buffer(bs); 26 - buffer.currentPosition = bs.length - 8; 27 - int i = buffer.getUnsignedShortBE(); 28 - int j = buffer.getUnsignedShortBE(); 29 - int k = buffer.getUnsignedShortBE(); 30 - int l = buffer.getUnsignedShortBE(); 31 - int i1 = 0; 32 - Buffer buffer_5_ = new Buffer(bs); 33 - buffer_5_.currentPosition = i1; 34 - i1 += i + 2; 35 - Buffer class50_sub1_sub2_2 = new Buffer(bs); 36 - class50_sub1_sub2_2.currentPosition = i1; 37 - i1 += j; 38 - Buffer class50_sub1_sub2_3 = new Buffer(bs); 39 - class50_sub1_sub2_3.currentPosition = i1; 40 - i1 += k; 41 - Buffer class50_sub1_sub2_4 = new Buffer(bs); 42 - class50_sub1_sub2_4.currentPosition = i1; 43 - i1 += l; 44 - Buffer buffer_9_ = new Buffer(bs); 45 - buffer_9_.currentPosition = i1; 46 - Skins skins = new Skins(buffer_9_); 47 - int animationAmount = buffer_5_.getUnsignedShortBE(); 48 - int ai[] = new int[500]; 49 - int ai1[] = new int[500]; 50 - int ai2[] = new int[500]; 51 - int ai3[] = new int[500]; 52 - for (int k1 = 0; k1 < animationAmount; k1++) { 53 - int l1 = buffer_5_.getUnsignedShortBE(); 54 - Animation animation = cache[l1] = new Animation(); 55 - animation.anInt431 = class50_sub1_sub2_4.getUnsignedByte(); 56 - animation.animationSkins = skins; 57 - int i2 = buffer_5_.getUnsignedByte(); 58 - int j2 = -1; 59 - int k2 = 0; 60 - for (int l2 = 0; l2 < i2; l2++) { 61 - int i3 = class50_sub1_sub2_2.getUnsignedByte(); 62 - if (i3 > 0) { 63 - if (skins.opcodes[l2] != 0) { 64 - for (int k3 = l2 - 1; k3 > j2; k3--) { 65 - if (skins.opcodes[k3] != 0) 66 - continue; 67 - ai[k2] = k3; 68 - ai1[k2] = 0; 69 - ai2[k2] = 0; 70 - ai3[k2] = 0; 71 - k2++; 72 - break; 73 - } 74 - 75 - } 76 - ai[k2] = l2; 77 - char c = '\0'; 78 - if (skins.opcodes[l2] == 3) 79 - c = '\200'; 80 - if ((i3 & 1) != 0) 81 - ai1[k2] = class50_sub1_sub2_3.getSignedSmart(); 82 - else 83 - ai1[k2] = c; 84 - if ((i3 & 2) != 0) 85 - ai2[k2] = class50_sub1_sub2_3.getSignedSmart(); 86 - else 87 - ai2[k2] = c; 88 - if ((i3 & 4) != 0) 89 - ai3[k2] = class50_sub1_sub2_3.getSignedSmart(); 90 - else 91 - ai3[k2] = c; 92 - j2 = l2; 93 - k2++; 94 - if (skins.opcodes[l2] == 5) 95 - aBooleanArray438[l1] = false; 96 - } 97 - } 98 - 99 - animation.transformCount = k2; 100 - animation.opcodeTable = new int[k2]; 101 - animation.modifier1 = new int[k2]; 102 - animation.modifier2 = new int[k2]; 103 - animation.modifier3 = new int[k2]; 104 - for (int j3 = 0; j3 < k2; j3++) { 105 - animation.opcodeTable[j3] = ai[j3]; 106 - animation.modifier1[j3] = ai1[j3]; 107 - animation.modifier2[j3] = ai2[j3]; 108 - animation.modifier3[j3] = ai3[j3]; 109 - } 110 - 111 - } 112 - 113 - } 114 - 115 - public static void reset() { 116 - cache = null; 117 - } 118 - 119 - public static Animation getAnimation(int animationId) { 120 - if (cache == null) 121 - return null; 122 - else 123 - return cache[animationId]; 124 - } 125 - 126 - public static boolean exists(int i) { 127 - return i == -1; 128 - } 129 - 130 - public Animation() { 131 - } 132 - 133 - 134 - 135 - }
+127
src/main/java/com/jagex/runescape/media/Animation.kt
··· 1 + package com.jagex.runescape.media 2 + 3 + import com.jagex.runescape.net.Buffer 4 + 5 + class Animation { 6 + 7 + @JvmField var delay: Int = 0 8 + @JvmField var animationSkins: Skins? = null 9 + @JvmField var transformCount: Int = 0 10 + @JvmField var opcodeTable: IntArray = IntArray(0) 11 + @JvmField var modifier1: IntArray = IntArray(0) 12 + @JvmField var modifier2: IntArray = IntArray(0) 13 + @JvmField var modifier3: IntArray = IntArray(0) 14 + 15 + companion object { 16 + @JvmField var cache: Array<Animation?>? = null 17 + @JvmField var noAlpha: BooleanArray? = null 18 + 19 + @JvmStatic 20 + fun method235(i: Int) { 21 + cache = arrayOfNulls(i + 1) 22 + noAlpha = BooleanArray(i + 1) { true } 23 + } 24 + 25 + @JvmStatic 26 + fun method236(bs: ByteArray) { 27 + val buffer = Buffer(bs) 28 + buffer.currentPosition = bs.size - 8 29 + val i = buffer.getUnsignedShortBE() 30 + val j = buffer.getUnsignedShortBE() 31 + val k = buffer.getUnsignedShortBE() 32 + val l = buffer.getUnsignedShortBE() 33 + var i1 = 0 34 + val buffer5 = Buffer(bs) 35 + buffer5.currentPosition = i1 36 + i1 += i + 2 37 + val buffer2 = Buffer(bs) 38 + buffer2.currentPosition = i1 39 + i1 += j 40 + val buffer3 = Buffer(bs) 41 + buffer3.currentPosition = i1 42 + i1 += k 43 + val buffer4 = Buffer(bs) 44 + buffer4.currentPosition = i1 45 + i1 += l 46 + val buffer9 = Buffer(bs) 47 + buffer9.currentPosition = i1 48 + val skins = Skins(buffer9) 49 + val animationAmount = buffer5.getUnsignedShortBE() 50 + val ai = IntArray(500) 51 + val ai1 = IntArray(500) 52 + val ai2 = IntArray(500) 53 + val ai3 = IntArray(500) 54 + for (k1 in 0 until animationAmount) { 55 + val l1 = buffer5.getUnsignedShortBE() 56 + val animation = Animation() 57 + cache!![l1] = animation 58 + animation.delay = buffer4.getUnsignedByte() 59 + animation.animationSkins = skins 60 + val i2 = buffer5.getUnsignedByte() 61 + var j2 = -1 62 + var k2 = 0 63 + for (l2 in 0 until i2) { 64 + val i3 = buffer2.getUnsignedByte() 65 + if (i3 > 0) { 66 + if (skins.opcodes[l2] != 0) { 67 + for (k3 in l2 - 1 downTo j2 + 1) { 68 + if (skins.opcodes[k3] != 0) continue 69 + ai[k2] = k3 70 + ai1[k2] = 0 71 + ai2[k2] = 0 72 + ai3[k2] = 0 73 + k2++ 74 + break 75 + } 76 + } 77 + ai[k2] = l2 78 + var c = '\u0000' 79 + if (skins.opcodes[l2] == 3) c = '\u0080' 80 + if (i3 and 1 != 0) 81 + ai1[k2] = buffer3.getSignedSmart() 82 + else 83 + ai1[k2] = c.code 84 + if (i3 and 2 != 0) 85 + ai2[k2] = buffer3.getSignedSmart() 86 + else 87 + ai2[k2] = c.code 88 + if (i3 and 4 != 0) 89 + ai3[k2] = buffer3.getSignedSmart() 90 + else 91 + ai3[k2] = c.code 92 + j2 = l2 93 + k2++ 94 + if (skins.opcodes[l2] == 5) 95 + noAlpha!![l1] = false 96 + } 97 + } 98 + animation.transformCount = k2 99 + animation.opcodeTable = IntArray(k2) 100 + animation.modifier1 = IntArray(k2) 101 + animation.modifier2 = IntArray(k2) 102 + animation.modifier3 = IntArray(k2) 103 + for (j3 in 0 until k2) { 104 + animation.opcodeTable[j3] = ai[j3] 105 + animation.modifier1[j3] = ai1[j3] 106 + animation.modifier2[j3] = ai2[j3] 107 + animation.modifier3[j3] = ai3[j3] 108 + } 109 + } 110 + } 111 + 112 + @JvmStatic 113 + fun reset() { 114 + cache = null 115 + } 116 + 117 + @JvmStatic 118 + fun getAnimation(animationId: Int): Animation? { 119 + return cache?.get(animationId) 120 + } 121 + 122 + @JvmStatic 123 + fun exists(i: Int): Boolean { 124 + return i == -1 125 + } 126 + } 127 + }
-85
src/main/java/com/jagex/runescape/media/ProducingGraphicsBuffer.java
··· 1 - package com.jagex.runescape.media; 2 - 3 - import java.awt.Component; 4 - import java.awt.Graphics; 5 - import java.awt.Image; 6 - import java.awt.image.ColorModel; 7 - import java.awt.image.DirectColorModel; 8 - import java.awt.image.ImageConsumer; 9 - import java.awt.image.ImageObserver; 10 - import java.awt.image.ImageProducer; 11 - 12 - public class ProducingGraphicsBuffer implements ImageProducer, ImageObserver { 13 - 14 - public int pixels[]; 15 - public int width; 16 - public int height; 17 - public ColorModel colorModel; 18 - public ImageConsumer imageConsumer; 19 - public Image image; 20 - 21 - public ProducingGraphicsBuffer(int width, int height, Component component) { 22 - this.width = width; 23 - this.height = height; 24 - pixels = new int[width * height]; 25 - colorModel = new DirectColorModel(32, 0xff0000, 65280, 255); 26 - image = component.createImage(this); 27 - drawPixels(); 28 - component.prepareImage(image, this); 29 - drawPixels(); 30 - component.prepareImage(image, this); 31 - drawPixels(); 32 - component.prepareImage(image, this); 33 - createRasterizer(); 34 - } 35 - 36 - public void createRasterizer() { 37 - Rasterizer.createRasterizer(pixels, width, height); 38 - } 39 - 40 - public void drawGraphics(int x, int y, Graphics graphics) { 41 - drawPixels(); 42 - graphics.drawImage(image, x, y, this); 43 - } 44 - 45 - public synchronized void addConsumer(ImageConsumer imageConsumer) { 46 - this.imageConsumer = imageConsumer; 47 - imageConsumer.setDimensions(width, height); 48 - imageConsumer.setProperties(null); 49 - imageConsumer.setColorModel(colorModel); 50 - imageConsumer.setHints(14); 51 - } 52 - 53 - public synchronized boolean isConsumer(ImageConsumer imageConsumer) { 54 - return this.imageConsumer == imageConsumer; 55 - } 56 - 57 - public synchronized void removeConsumer(ImageConsumer imageConsumer) { 58 - if (this.imageConsumer == imageConsumer) 59 - this.imageConsumer = null; 60 - } 61 - 62 - public void startProduction(ImageConsumer imageConsumer) { 63 - addConsumer(imageConsumer); 64 - } 65 - 66 - public void requestTopDownLeftRightResend(ImageConsumer imageConsumer) { 67 - System.out.println("TDLR"); 68 - } 69 - 70 - public synchronized void drawPixels() { 71 - if (imageConsumer == null) { 72 - return; 73 - } else { 74 - imageConsumer.setPixels(0, 0, width, height, colorModel, pixels, 0, width); 75 - imageConsumer.imageComplete(2); 76 - return; 77 - } 78 - } 79 - 80 - public boolean imageUpdate(Image image, int i, int j, int k, int l, int i1) { 81 - return true; 82 - } 83 - 84 - 85 - }
+77
src/main/java/com/jagex/runescape/media/ProducingGraphicsBuffer.kt
··· 1 + package com.jagex.runescape.media 2 + 3 + import java.awt.Component 4 + import java.awt.Graphics 5 + import java.awt.Image 6 + import java.awt.image.ColorModel 7 + import java.awt.image.DirectColorModel 8 + import java.awt.image.ImageConsumer 9 + import java.awt.image.ImageObserver 10 + import java.awt.image.ImageProducer 11 + 12 + class ProducingGraphicsBuffer(width: Int, height: Int, component: Component) : ImageProducer, ImageObserver { 13 + 14 + @JvmField var pixels: IntArray = IntArray(width * height) 15 + @JvmField var width: Int = width 16 + @JvmField var height: Int = height 17 + @JvmField var colorModel: ColorModel = DirectColorModel(32, 0xff0000, 65280, 255) 18 + @JvmField var imageConsumer: ImageConsumer? = null 19 + @JvmField var image: Image 20 + 21 + init { 22 + image = component.createImage(this) 23 + drawPixels() 24 + component.prepareImage(image, this) 25 + drawPixels() 26 + component.prepareImage(image, this) 27 + drawPixels() 28 + component.prepareImage(image, this) 29 + createRasterizer() 30 + } 31 + 32 + fun createRasterizer() { 33 + Rasterizer.createRasterizer(pixels, width, height) 34 + } 35 + 36 + fun drawGraphics(x: Int, y: Int, graphics: Graphics) { 37 + drawPixels() 38 + graphics.drawImage(image, x, y, this) 39 + } 40 + 41 + @Synchronized 42 + override fun addConsumer(imageConsumer: ImageConsumer) { 43 + this.imageConsumer = imageConsumer 44 + imageConsumer.setDimensions(width, height) 45 + imageConsumer.setProperties(null) 46 + imageConsumer.setColorModel(colorModel) 47 + imageConsumer.setHints(14) 48 + } 49 + 50 + @Synchronized 51 + override fun isConsumer(imageConsumer: ImageConsumer): Boolean { 52 + return this.imageConsumer === imageConsumer 53 + } 54 + 55 + @Synchronized 56 + override fun removeConsumer(imageConsumer: ImageConsumer) { 57 + if (this.imageConsumer === imageConsumer) 58 + this.imageConsumer = null 59 + } 60 + 61 + override fun startProduction(imageConsumer: ImageConsumer) { 62 + addConsumer(imageConsumer) 63 + } 64 + 65 + override fun requestTopDownLeftRightResend(imageConsumer: ImageConsumer) { 66 + println("TDLR") 67 + } 68 + 69 + @Synchronized 70 + fun drawPixels() { 71 + val consumer = imageConsumer ?: return 72 + consumer.setPixels(0, 0, width, height, colorModel, pixels, 0, width) 73 + consumer.imageComplete(2) 74 + } 75 + 76 + override fun imageUpdate(image: Image, i: Int, j: Int, k: Int, l: Int, i1: Int): Boolean = true 77 + }
-501
src/main/java/com/jagex/runescape/media/Rasterizer.java
··· 1 - package com.jagex.runescape.media; 2 - 3 - import com.jagex.runescape.collection.CacheableNode; 4 - 5 - public class Rasterizer extends CacheableNode { 6 - 7 - public static int[] pixels; 8 - public static int width; 9 - public static int height; 10 - public static int topY; 11 - public static int bottomY; 12 - public static int topX; 13 - public static int bottomX; 14 - public static int viewportRx; 15 - public static int centerX; 16 - public static int centerY; 17 - 18 - 19 - public static void createRasterizer(int[] pixels, int width, int height) { 20 - Rasterizer.pixels = pixels; 21 - Rasterizer.width = width; 22 - Rasterizer.height = height; 23 - setCoordinates(0, 0, height, width); 24 - } 25 - 26 - public static void resetCoordinates() { 27 - topX = 0; 28 - topY = 0; 29 - bottomX = width; 30 - bottomY = height; 31 - viewportRx = bottomX - 1; 32 - centerX = bottomX / 2; 33 - } 34 - 35 - public static void resize(int topX, int topY, int bottomX, int bottomY) { 36 - if (Rasterizer.topX < topX) { 37 - Rasterizer.topX = topX; 38 - } 39 - if (Rasterizer.topY < topY) { 40 - Rasterizer.topY = topY; 41 - } 42 - if (Rasterizer.bottomX > bottomX) { 43 - Rasterizer.bottomX = bottomX; 44 - } 45 - if (Rasterizer.bottomY > bottomY) { 46 - Rasterizer.bottomY = bottomY; 47 - } 48 - } 49 - 50 - 51 - public static void setCoordinates(int y, int x, int height, int width) { 52 - if (x < 0) 53 - x = 0; 54 - if (y < 0) 55 - y = 0; 56 - if (width > Rasterizer.width) 57 - width = Rasterizer.width; 58 - if (height > Rasterizer.height) 59 - height = Rasterizer.height; 60 - topX = x; 61 - topY = y; 62 - bottomX = width; 63 - bottomY = height; 64 - viewportRx = bottomX - 1; 65 - centerX = bottomX / 2; 66 - centerY = bottomY / 2; 67 - 68 - } 69 - 70 - public static void resetPixels() { 71 - int pixelCount = width * height; 72 - for (int pixel = 0; pixel < pixelCount; pixel++) 73 - pixels[pixel] = 0; 74 - 75 - } 76 - 77 - public static void drawFilledRectangleAlpha(int x, int y, int width, int height, int colour, int alpha) { 78 - if (x < topX) { 79 - width -= topX - x; 80 - x = topX; 81 - } 82 - if (y < topY) { 83 - height -= topY - y; 84 - y = topY; 85 - } 86 - if (x + width > bottomX) 87 - width = bottomX - x; 88 - if (y + height > bottomY) 89 - height = bottomY - y; 90 - int a = 256 - alpha; 91 - int r = (colour >> 16 & 0xff) * alpha; 92 - int g = (colour >> 8 & 0xff) * alpha; 93 - int b = (colour & 0xff) * alpha; 94 - int widthOffset = Rasterizer.width - width; 95 - int pixel = x + y * Rasterizer.width; 96 - for (int heightCounter = 0; heightCounter < height; heightCounter++) { 97 - for (int widthCounter = -width; widthCounter < 0; widthCounter++) { 98 - int red = (pixels[pixel] >> 16 & 0xff) * a; 99 - int green = (pixels[pixel] >> 8 & 0xff) * a; 100 - int blue = (pixels[pixel] & 0xff) * a; 101 - int rgba = ((r + red >> 8) << 16) + ((g + green >> 8) << 8) + (b + blue >> 8); 102 - pixels[pixel++] = rgba; 103 - } 104 - 105 - pixel += widthOffset; 106 - } 107 - 108 - } 109 - 110 - public static void drawFilledRectangle(int x, int y, int width, int height, int colour) { 111 - if (x < topX) { 112 - width -= topX - x; 113 - x = topX; 114 - } 115 - if (y < topY) { 116 - height -= topY - y; 117 - y = topY; 118 - } 119 - if (x + width > bottomX) 120 - width = bottomX - x; 121 - if (y + height > bottomY) 122 - height = bottomY - y; 123 - int pixelOffset = Rasterizer.width - width; 124 - int pixel = x + y * Rasterizer.width; 125 - for (int heightCounter = -height; heightCounter < 0; heightCounter++) { 126 - for (int widthCounter = -width; widthCounter < 0; widthCounter++) 127 - pixels[pixel++] = colour; 128 - 129 - pixel += pixelOffset; 130 - } 131 - } 132 - 133 - public static void drawUnfilledRectangle(int x, int y, int width, int height, int color) { 134 - drawHorizontalLine(x, y, width, color); 135 - drawHorizontalLine(x, (y + height) - 1, width, color); 136 - drawVerticalLine(x, y, height, color); 137 - drawVerticalLine((x + width) - 1, y, height, color); 138 - } 139 - 140 - public static void drawUnfilledRectangleAlpha(int x, int y, int width, int height, int colour, int alpha) { 141 - drawHorizontalLineAlpha(x, y, width, colour, alpha); 142 - drawHorizontalLineAlpha(x, (y + height) - 1, width, colour, alpha); 143 - if (height >= 3) { 144 - drawVerticalLineAlpha(x, y + 1, height - 2, colour, alpha); 145 - drawVerticalLineAlpha((x + width) - 1, y + 1, height - 2, colour, alpha); 146 - } 147 - } 148 - 149 - public static void drawHorizontalLine(int x, int y, int lenght, int colour) { 150 - if (y < topY || y >= bottomY) 151 - return; 152 - if (x < topX) { 153 - lenght -= topX - x; 154 - x = topX; 155 - } 156 - if (x + lenght > bottomX) 157 - lenght = bottomX - x; 158 - int pixelOffset = x + y * width; 159 - for (int pixel = 0; pixel < lenght; pixel++) 160 - pixels[pixelOffset + pixel] = colour; 161 - 162 - } 163 - 164 - public static void drawHorizontalLineAlpha(int x, int y, int length, int colour, int alpha) { 165 - if (y < topY || y >= bottomY) 166 - return; 167 - if (x < topX) { 168 - length -= topX - x; 169 - x = topX; 170 - } 171 - if (x + length > bottomX) 172 - length = bottomX - x; 173 - int a = 256 - alpha; 174 - int r = (colour >> 16 & 0xff) * alpha; 175 - int g = (colour >> 8 & 0xff) * alpha; 176 - int b = (colour & 0xff) * alpha; 177 - int pixelOffset = x + y * width; 178 - for (int lengthCounter = 0; lengthCounter < length; lengthCounter++) { 179 - int red = (pixels[pixelOffset] >> 16 & 0xff) * a; 180 - int green = (pixels[pixelOffset] >> 8 & 0xff) * a; 181 - int blue = (pixels[pixelOffset] & 0xff) * a; 182 - int rgba = ((r + red >> 8) << 16) + ((g + green >> 8) << 8) + (b + blue >> 8); 183 - pixels[pixelOffset++] = rgba; 184 - } 185 - } 186 - 187 - public static void drawVerticalLine(int x, int y, int lenght, int colour) { 188 - if (x < topX || x >= bottomX) 189 - return; 190 - if (y < topY) { 191 - lenght -= topY - y; 192 - y = topY; 193 - } 194 - if (y + lenght > bottomY) 195 - lenght = bottomY - y; 196 - int pixelOffset = x + y * width; 197 - for (int pixel = 0; pixel < lenght; pixel++) 198 - pixels[pixelOffset + pixel * width] = colour; 199 - 200 - } 201 - 202 - public static void drawVerticalLineAlpha(int x, int y, int lenght, int colour, int alpha) { 203 - if (x < topX || x >= bottomX) 204 - return; 205 - if (y < topY) { 206 - lenght -= topY - y; 207 - y = topY; 208 - } 209 - if (y + lenght > bottomY) 210 - lenght = bottomY - y; 211 - int a = 256 - alpha; 212 - int r = (colour >> 16 & 0xff) * alpha; 213 - int g = (colour >> 8 & 0xff) * alpha; 214 - int b = (colour & 0xff) * alpha; 215 - int pixel = x + y * width; 216 - for (int lengthCounter = 0; lengthCounter < lenght; lengthCounter++) { 217 - int red = (pixels[pixel] >> 16 & 0xff) * a; 218 - int blue = (pixels[pixel] >> 8 & 0xff) * a; 219 - int green = (pixels[pixel] & 0xff) * a; 220 - int rgba = ((r + red >> 8) << 16) + ((g + blue >> 8) << 8) + (b + green >> 8); 221 - pixels[pixel] = rgba; 222 - pixel += width; 223 - } 224 - 225 - } 226 - 227 - 228 - static final void drawDiagonalLine(int x, int y, int DestX, int destY, int linecolor) { 229 - DestX -= x; 230 - destY -= y; 231 - if (destY == 0) { 232 - if (DestX >= 0) { 233 - drawHorizontalLine(x, y, DestX + 1, linecolor); 234 - } else { 235 - drawHorizontalLine(x + DestX, y, -DestX + 1, linecolor); 236 - } 237 - } else if (DestX == 0) { 238 - if (destY >= 0) { 239 - drawVerticalLine(x, y, destY + 1, linecolor); 240 - } else { 241 - drawVerticalLine(x, y + destY, -destY + 1, linecolor); 242 - } 243 - } else { 244 - if (DestX + destY < 0) { 245 - x += DestX; 246 - DestX = -DestX; 247 - y += destY; 248 - destY = -destY; 249 - } 250 - int var5; 251 - int var6; 252 - if (DestX > destY) { 253 - y <<= 16; 254 - y += '\u8000'; 255 - destY <<= 16; 256 - var5 = (int) Math.floor((double) destY / (double) DestX + 0.5D); 257 - DestX += x; 258 - if (x < topX) { 259 - y += var5 * (topX - x); 260 - x = topX; 261 - } 262 - if (DestX >= bottomX) { 263 - DestX = bottomX - 1; 264 - } 265 - while (x <= DestX) { 266 - var6 = y >> 16; 267 - if (var6 >= topY && var6 < bottomY) { 268 - pixels[x + var6 * width] = linecolor; 269 - } 270 - y += var5; 271 - ++x; 272 - } 273 - } else { 274 - x <<= 16; 275 - x += '\u8000'; 276 - DestX <<= 16; 277 - var5 = (int) Math.floor((double) DestX / (double) destY + 0.5D); 278 - destY += y; 279 - if (y < topY) { 280 - x += var5 * (topY - y); 281 - y = topY; 282 - } 283 - if (destY >= bottomY) { 284 - destY = bottomY - 1; 285 - } 286 - while (y <= destY) { 287 - var6 = x >> 16; 288 - if (var6 >= topX && var6 < bottomX) { 289 - pixels[var6 + y * width] = linecolor; 290 - } 291 - x += var5; 292 - ++y; 293 - } 294 - } 295 - } 296 - } 297 - 298 - 299 - public static void drawCircle(int x, int y, int radius, int color) { 300 - if (radius == 0) { 301 - drawPixel(x, y, color); 302 - } else { 303 - if (radius < 0) { 304 - radius = -radius; 305 - } 306 - int var4 = y - radius; 307 - if (var4 < topY) { 308 - var4 = topY; 309 - } 310 - int var5 = y + radius + 1; 311 - if (var5 > bottomY) { 312 - var5 = bottomY; 313 - } 314 - int var6 = var4; 315 - int var7 = radius * radius; 316 - int var8 = 0; 317 - int var9 = y - var4; 318 - int var10 = var9 * var9; 319 - int var11 = var10 - var9; 320 - if (y > var5) { 321 - y = var5; 322 - } 323 - int var12; 324 - int var13; 325 - int var14; 326 - int var15; 327 - while (var6 < y) { 328 - while (var11 <= var7 || var10 <= var7) { 329 - var10 += var8 + var8; 330 - var11 += var8++ + var8; 331 - } 332 - var12 = x - var8 + 1; 333 - if (var12 < topX) { 334 - var12 = topX; 335 - } 336 - var13 = x + var8; 337 - if (var13 > bottomX) { 338 - var13 = bottomX; 339 - } 340 - var14 = var12 + var6 * width; 341 - for (var15 = var12; var15 < var13; ++var15) { 342 - pixels[var14++] = color; 343 - } 344 - ++var6; 345 - var10 -= var9-- + var9; 346 - var11 -= var9 + var9; 347 - } 348 - var8 = radius; 349 - var9 = var6 - y; 350 - var11 = var9 * var9 + var7; 351 - var10 = var11 - radius; 352 - for (var11 -= var9; var6 < var5; var10 += var9++ + var9) { 353 - while (var11 > var7 && var10 > var7) { 354 - var11 -= var8-- + var8; 355 - var10 -= var8 + var8; 356 - } 357 - var12 = x - var8; 358 - if (var12 < topX) { 359 - var12 = topX; 360 - } 361 - var13 = x + var8; 362 - if (var13 > bottomX - 1) { 363 - var13 = bottomX - 1; 364 - } 365 - var14 = var12 + var6 * width; 366 - for (var15 = var12; var15 <= var13; ++var15) { 367 - pixels[var14++] = color; 368 - } 369 - ++var6; 370 - var11 += var9 + var9; 371 - } 372 - } 373 - } 374 - 375 - public static void drawCircleAlpha(int x, int y, int radius, int color, int alpha) { 376 - if (alpha != 0) { 377 - if (alpha == 256) { 378 - drawCircle(x, y, radius, color); 379 - } else { 380 - if (radius < 0) { 381 - radius = -radius; 382 - } 383 - int a = 256 - alpha; 384 - int r = (color >> 16 & 255) * alpha; 385 - int g = (color >> 8 & 255) * alpha; 386 - int b = (color & 255) * alpha; 387 - int topY = y - radius; 388 - if (topY < Rasterizer.topY) { 389 - topY = Rasterizer.topY; 390 - } 391 - int bottomY = y + radius + 1; 392 - if (bottomY > Rasterizer.bottomY) { 393 - bottomY = Rasterizer.bottomY; 394 - } 395 - int var14 = topY; 396 - int var15 = radius * radius; 397 - int var16 = 0; 398 - int var17 = y - topY; 399 - int var18 = var17 * var17; 400 - int var19 = var18 - var17; 401 - if (y > bottomY) { 402 - y = bottomY; 403 - } 404 - int var9; 405 - int var10; 406 - int var11; 407 - int var21; 408 - int var20; 409 - int var23; 410 - int var22; 411 - int var24; 412 - while (var14 < y) { 413 - while (var19 <= var15 || var18 <= var15) { 414 - var18 += var16 + var16; 415 - var19 += var16++ + var16; 416 - } 417 - var20 = x - var16 + 1; 418 - if (var20 < topX) { 419 - var20 = topX; 420 - } 421 - var21 = x + var16; 422 - if (var21 > bottomX) { 423 - var21 = bottomX; 424 - } 425 - var22 = var20 + var14 * width; 426 - for (var23 = var20; var23 < var21; ++var23) { 427 - var9 = (pixels[var22] >> 16 & 255) * a; 428 - var10 = (pixels[var22] >> 8 & 255) * a; 429 - var11 = (pixels[var22] & 255) * a; 430 - var24 = (r + var9 >> 8 << 16) + (g + var10 >> 8 << 8) + (b + var11 >> 8); 431 - pixels[var22++] = var24; 432 - } 433 - ++var14; 434 - var18 -= var17-- + var17; 435 - var19 -= var17 + var17; 436 - } 437 - var16 = radius; 438 - var17 = -var17; 439 - var19 = var17 * var17 + var15; 440 - var18 = var19 - radius; 441 - for (var19 -= var17; var14 < bottomY; var18 += var17++ + var17) { 442 - while (var19 > var15 && var18 > var15) { 443 - var19 -= var16-- + var16; 444 - var18 -= var16 + var16; 445 - } 446 - var20 = x - var16; 447 - if (var20 < topX) { 448 - var20 = topX; 449 - } 450 - var21 = x + var16; 451 - if (var21 > bottomX - 1) { 452 - var21 = bottomX - 1; 453 - } 454 - var22 = var20 + var14 * width; 455 - for (var23 = var20; var23 <= var21; ++var23) { 456 - var9 = (pixels[var22] >> 16 & 255) * a; 457 - var10 = (pixels[var22] >> 8 & 255) * a; 458 - var11 = (pixels[var22] & 255) * a; 459 - var24 = (r + var9 >> 8 << 16) + (g + var10 >> 8 << 8) + (b + var11 >> 8); 460 - pixels[var22++] = var24; 461 - } 462 - ++var14; 463 - var19 += var17 + var17; 464 - } 465 - } 466 - } 467 - } 468 - 469 - 470 - private static void drawPixel(int x, int y, int color) { 471 - if (x >= topX && y >= topY && x < bottomX && y < bottomY) { 472 - pixels[x + y * width] = color; 473 - } 474 - } 475 - 476 - public static void clearPixels() { 477 - int i = 0; 478 - int pixeltoclear; 479 - for (pixeltoclear = width * height - 7; i < pixeltoclear; pixels[i++] = 0) { 480 - pixels[i++] = 0; 481 - pixels[i++] = 0; 482 - pixels[i++] = 0; 483 - pixels[i++] = 0; 484 - pixels[i++] = 0; 485 - pixels[i++] = 0; 486 - pixels[i++] = 0; 487 - } 488 - for (pixeltoclear += 7; i < pixeltoclear; pixels[i++] = 0) { 489 - } 490 - } 491 - 492 - public static void destroy() { 493 - pixels = null; 494 - } 495 - 496 - 497 - public Rasterizer() { 498 - } 499 - 500 - 501 - }
+404
src/main/java/com/jagex/runescape/media/Rasterizer.kt
··· 1 + package com.jagex.runescape.media 2 + 3 + import com.jagex.runescape.collection.CacheableNode 4 + import kotlin.math.floor 5 + 6 + open class Rasterizer : CacheableNode() { 7 + 8 + companion object { 9 + @JvmStatic lateinit var pixels: IntArray 10 + @JvmField var width: Int = 0 11 + @JvmField var height: Int = 0 12 + @JvmField var topY: Int = 0 13 + @JvmField var bottomY: Int = 0 14 + @JvmField var topX: Int = 0 15 + @JvmField var bottomX: Int = 0 16 + @JvmField var viewportRx: Int = 0 17 + @JvmField var centerX: Int = 0 18 + @JvmField var centerY: Int = 0 19 + 20 + @JvmStatic 21 + fun createRasterizer(pixels: IntArray, width: Int, height: Int) { 22 + Companion.pixels = pixels 23 + Companion.width = width 24 + Companion.height = height 25 + setCoordinates(0, 0, height, width) 26 + } 27 + 28 + @JvmStatic 29 + fun resetCoordinates() { 30 + topX = 0 31 + topY = 0 32 + bottomX = width 33 + bottomY = height 34 + viewportRx = bottomX - 1 35 + centerX = bottomX / 2 36 + } 37 + 38 + @JvmStatic 39 + fun resize(topX: Int, topY: Int, bottomX: Int, bottomY: Int) { 40 + if (Companion.topX < topX) Companion.topX = topX 41 + if (Companion.topY < topY) Companion.topY = topY 42 + if (Companion.bottomX > bottomX) Companion.bottomX = bottomX 43 + if (Companion.bottomY > bottomY) Companion.bottomY = bottomY 44 + } 45 + 46 + @JvmStatic 47 + fun setCoordinates(y: Int, x: Int, height: Int, width: Int) { 48 + var cx = x 49 + var cy = y 50 + var cw = width 51 + var ch = height 52 + if (cx < 0) cx = 0 53 + if (cy < 0) cy = 0 54 + if (cw > Companion.width) cw = Companion.width 55 + if (ch > Companion.height) ch = Companion.height 56 + topX = cx 57 + topY = cy 58 + bottomX = cw 59 + bottomY = ch 60 + viewportRx = bottomX - 1 61 + centerX = bottomX / 2 62 + centerY = bottomY / 2 63 + } 64 + 65 + @JvmStatic 66 + fun resetPixels() { 67 + val pixelCount = width * height 68 + for (pixel in 0 until pixelCount) 69 + pixels[pixel] = 0 70 + } 71 + 72 + @JvmStatic 73 + fun drawFilledRectangleAlpha(x: Int, y: Int, width: Int, height: Int, colour: Int, alpha: Int) { 74 + var dx = x 75 + var dy = y 76 + var dw = width 77 + var dh = height 78 + if (dx < topX) { dw -= topX - dx; dx = topX } 79 + if (dy < topY) { dh -= topY - dy; dy = topY } 80 + if (dx + dw > bottomX) dw = bottomX - dx 81 + if (dy + dh > bottomY) dh = bottomY - dy 82 + val a = 256 - alpha 83 + val r = (colour shr 16 and 0xff) * alpha 84 + val g = (colour shr 8 and 0xff) * alpha 85 + val b = (colour and 0xff) * alpha 86 + val widthOffset = Companion.width - dw 87 + var pixel = dx + dy * Companion.width 88 + for (heightCounter in 0 until dh) { 89 + for (widthCounter in -dw until 0) { 90 + val red = (pixels[pixel] shr 16 and 0xff) * a 91 + val green = (pixels[pixel] shr 8 and 0xff) * a 92 + val blue = (pixels[pixel] and 0xff) * a 93 + val rgba = ((r + red shr 8) shl 16) + ((g + green shr 8) shl 8) + (b + blue shr 8) 94 + pixels[pixel++] = rgba 95 + } 96 + pixel += widthOffset 97 + } 98 + } 99 + 100 + @JvmStatic 101 + fun drawFilledRectangle(x: Int, y: Int, width: Int, height: Int, colour: Int) { 102 + var dx = x 103 + var dy = y 104 + var dw = width 105 + var dh = height 106 + if (dx < topX) { dw -= topX - dx; dx = topX } 107 + if (dy < topY) { dh -= topY - dy; dy = topY } 108 + if (dx + dw > bottomX) dw = bottomX - dx 109 + if (dy + dh > bottomY) dh = bottomY - dy 110 + val pixelOffset = Companion.width - dw 111 + var pixel = dx + dy * Companion.width 112 + for (heightCounter in -dh until 0) { 113 + for (widthCounter in -dw until 0) 114 + pixels[pixel++] = colour 115 + pixel += pixelOffset 116 + } 117 + } 118 + 119 + @JvmStatic 120 + fun drawUnfilledRectangle(x: Int, y: Int, width: Int, height: Int, color: Int) { 121 + drawHorizontalLine(x, y, width, color) 122 + drawHorizontalLine(x, y + height - 1, width, color) 123 + drawVerticalLine(x, y, height, color) 124 + drawVerticalLine(x + width - 1, y, height, color) 125 + } 126 + 127 + @JvmStatic 128 + fun drawUnfilledRectangleAlpha(x: Int, y: Int, width: Int, height: Int, colour: Int, alpha: Int) { 129 + drawHorizontalLineAlpha(x, y, width, colour, alpha) 130 + drawHorizontalLineAlpha(x, y + height - 1, width, colour, alpha) 131 + if (height >= 3) { 132 + drawVerticalLineAlpha(x, y + 1, height - 2, colour, alpha) 133 + drawVerticalLineAlpha(x + width - 1, y + 1, height - 2, colour, alpha) 134 + } 135 + } 136 + 137 + @JvmStatic 138 + fun drawHorizontalLine(x: Int, y: Int, length: Int, colour: Int) { 139 + var dx = x 140 + var dl = length 141 + if (y < topY || y >= bottomY) return 142 + if (dx < topX) { dl -= topX - dx; dx = topX } 143 + if (dx + dl > bottomX) dl = bottomX - dx 144 + val pixelOffset = dx + y * width 145 + for (pixel in 0 until dl) 146 + pixels[pixelOffset + pixel] = colour 147 + } 148 + 149 + @JvmStatic 150 + fun drawHorizontalLineAlpha(x: Int, y: Int, length: Int, colour: Int, alpha: Int) { 151 + var dx = x 152 + var dl = length 153 + if (y < topY || y >= bottomY) return 154 + if (dx < topX) { dl -= topX - dx; dx = topX } 155 + if (dx + dl > bottomX) dl = bottomX - dx 156 + val a = 256 - alpha 157 + val r = (colour shr 16 and 0xff) * alpha 158 + val g = (colour shr 8 and 0xff) * alpha 159 + val b = (colour and 0xff) * alpha 160 + var pixelOffset = dx + y * width 161 + for (lengthCounter in 0 until dl) { 162 + val red = (pixels[pixelOffset] shr 16 and 0xff) * a 163 + val green = (pixels[pixelOffset] shr 8 and 0xff) * a 164 + val blue = (pixels[pixelOffset] and 0xff) * a 165 + val rgba = ((r + red shr 8) shl 16) + ((g + green shr 8) shl 8) + (b + blue shr 8) 166 + pixels[pixelOffset++] = rgba 167 + } 168 + } 169 + 170 + @JvmStatic 171 + fun drawVerticalLine(x: Int, y: Int, length: Int, colour: Int) { 172 + var dy = y 173 + var dl = length 174 + if (x < topX || x >= bottomX) return 175 + if (dy < topY) { dl -= topY - dy; dy = topY } 176 + if (dy + dl > bottomY) dl = bottomY - dy 177 + val pixelOffset = x + dy * width 178 + for (pixel in 0 until dl) 179 + pixels[pixelOffset + pixel * width] = colour 180 + } 181 + 182 + @JvmStatic 183 + fun drawVerticalLineAlpha(x: Int, y: Int, length: Int, colour: Int, alpha: Int) { 184 + var dy = y 185 + var dl = length 186 + if (x < topX || x >= bottomX) return 187 + if (dy < topY) { dl -= topY - dy; dy = topY } 188 + if (dy + dl > bottomY) dl = bottomY - dy 189 + val a = 256 - alpha 190 + val r = (colour shr 16 and 0xff) * alpha 191 + val g = (colour shr 8 and 0xff) * alpha 192 + val b = (colour and 0xff) * alpha 193 + var pixel = x + dy * width 194 + for (lengthCounter in 0 until dl) { 195 + val red = (pixels[pixel] shr 16 and 0xff) * a 196 + val blue = (pixels[pixel] shr 8 and 0xff) * a 197 + val green = (pixels[pixel] and 0xff) * a 198 + val rgba = ((r + red shr 8) shl 16) + ((g + blue shr 8) shl 8) + (b + green shr 8) 199 + pixels[pixel] = rgba 200 + pixel += width 201 + } 202 + } 203 + 204 + @JvmStatic 205 + fun drawDiagonalLine(x: Int, y: Int, destX: Int, destY: Int, linecolor: Int) { 206 + var cx = x 207 + var cy = y 208 + var dx = destX - cx 209 + var dy = destY - cy 210 + if (dy == 0) { 211 + if (dx >= 0) drawHorizontalLine(cx, cy, dx + 1, linecolor) 212 + else drawHorizontalLine(cx + dx, cy, -dx + 1, linecolor) 213 + } else if (dx == 0) { 214 + if (dy >= 0) drawVerticalLine(cx, cy, dy + 1, linecolor) 215 + else drawVerticalLine(cx, cy + dy, -dy + 1, linecolor) 216 + } else { 217 + if (dx + dy < 0) { 218 + cx += dx; dx = -dx 219 + cy += dy; dy = -dy 220 + } 221 + if (dx > dy) { 222 + cy = (cy shl 16) + 0x8000 223 + dy = dy shl 16 224 + val step = floor(dy.toDouble() / dx.toDouble() + 0.5).toInt() 225 + dx += cx 226 + if (cx < topX) { cy += step * (topX - cx); cx = topX } 227 + if (dx >= bottomX) dx = bottomX - 1 228 + while (cx <= dx) { 229 + val py = cy shr 16 230 + if (py in topY until bottomY) 231 + pixels[cx + py * width] = linecolor 232 + cy += step 233 + ++cx 234 + } 235 + } else { 236 + cx = (cx shl 16) + 0x8000 237 + dx = dx shl 16 238 + val step = floor(dx.toDouble() / dy.toDouble() + 0.5).toInt() 239 + dy += cy 240 + if (cy < topY) { cx += step * (topY - cy); cy = topY } 241 + if (dy >= bottomY) dy = bottomY - 1 242 + while (cy <= dy) { 243 + val px = cx shr 16 244 + if (px in topX until bottomX) 245 + pixels[px + cy * width] = linecolor 246 + cx += step 247 + ++cy 248 + } 249 + } 250 + } 251 + } 252 + 253 + @JvmStatic 254 + fun drawCircle(x: Int, y: Int, radius: Int, color: Int) { 255 + var r = radius 256 + var cy = y 257 + if (r == 0) { 258 + drawPixel(x, cy, color) 259 + return 260 + } 261 + if (r < 0) r = -r 262 + var varTop = cy - r 263 + if (varTop < topY) varTop = topY 264 + var varBottom = cy + r + 1 265 + if (varBottom > bottomY) varBottom = bottomY 266 + var scanY = varTop 267 + val r2 = r * r 268 + var dx = 0 269 + var distY = cy - varTop 270 + var d1 = distY * distY 271 + var d2 = d1 - distY 272 + if (cy > varBottom) cy = varBottom 273 + while (scanY < cy) { 274 + while (d2 <= r2 || d1 <= r2) { 275 + d1 += dx + dx 276 + d2 += dx++ + dx 277 + } 278 + var left = x - dx + 1 279 + if (left < topX) left = topX 280 + var right = x + dx 281 + if (right > bottomX) right = bottomX 282 + var pi = left + scanY * width 283 + for (px in left until right) 284 + pixels[pi++] = color 285 + ++scanY 286 + d1 -= distY-- + distY 287 + d2 -= distY + distY 288 + } 289 + dx = r 290 + distY = scanY - cy 291 + d2 = distY * distY + r2 292 + d1 = d2 - r 293 + d2 -= distY 294 + while (scanY < varBottom) { 295 + while (d2 > r2 && d1 > r2) { 296 + d2 -= dx-- + dx 297 + d1 -= dx + dx 298 + } 299 + var left = x - dx 300 + if (left < topX) left = topX 301 + var right = x + dx 302 + if (right > bottomX - 1) right = bottomX - 1 303 + var pi = left + scanY * width 304 + for (px in left..right) 305 + pixels[pi++] = color 306 + ++scanY 307 + d2 += distY + distY 308 + d1 += distY++ + distY 309 + } 310 + } 311 + 312 + @JvmStatic 313 + fun drawCircleAlpha(x: Int, y: Int, radius: Int, color: Int, alpha: Int) { 314 + if (alpha == 0) return 315 + if (alpha == 256) { drawCircle(x, y, radius, color); return } 316 + var r = radius 317 + var cy = y 318 + if (r < 0) r = -r 319 + val a = 256 - alpha 320 + val cr = (color shr 16 and 255) * alpha 321 + val cg = (color shr 8 and 255) * alpha 322 + val cb = (color and 255) * alpha 323 + var varTop = cy - r 324 + if (varTop < topY) varTop = topY 325 + var varBottom = cy + r + 1 326 + if (varBottom > bottomY) varBottom = bottomY 327 + var scanY = varTop 328 + val r2 = r * r 329 + var dx = 0 330 + var distY = cy - varTop 331 + var d1 = distY * distY 332 + var d2 = d1 - distY 333 + if (cy > varBottom) cy = varBottom 334 + while (scanY < cy) { 335 + while (d2 <= r2 || d1 <= r2) { 336 + d1 += dx + dx 337 + d2 += dx++ + dx 338 + } 339 + var left = x - dx + 1 340 + if (left < topX) left = topX 341 + var right = x + dx 342 + if (right > bottomX) right = bottomX 343 + var pi = left + scanY * width 344 + for (px in left until right) { 345 + val pr = (pixels[pi] shr 16 and 255) * a 346 + val pg = (pixels[pi] shr 8 and 255) * a 347 + val pb = (pixels[pi] and 255) * a 348 + pixels[pi++] = (cr + pr shr 8 shl 16) + (cg + pg shr 8 shl 8) + (cb + pb shr 8) 349 + } 350 + ++scanY 351 + d1 -= distY-- + distY 352 + d2 -= distY + distY 353 + } 354 + dx = r 355 + distY = -distY 356 + d2 = distY * distY + r2 357 + d1 = d2 - r 358 + d2 -= distY 359 + while (scanY < varBottom) { 360 + while (d2 > r2 && d1 > r2) { 361 + d2 -= dx-- + dx 362 + d1 -= dx + dx 363 + } 364 + var left = x - dx 365 + if (left < topX) left = topX 366 + var right = x + dx 367 + if (right > bottomX - 1) right = bottomX - 1 368 + var pi = left + scanY * width 369 + for (px in left..right) { 370 + val pr = (pixels[pi] shr 16 and 255) * a 371 + val pg = (pixels[pi] shr 8 and 255) * a 372 + val pb = (pixels[pi] and 255) * a 373 + pixels[pi++] = (cr + pr shr 8 shl 16) + (cg + pg shr 8 shl 8) + (cb + pb shr 8) 374 + } 375 + ++scanY 376 + d2 += distY + distY 377 + d1 += distY++ + distY 378 + } 379 + } 380 + 381 + private fun drawPixel(x: Int, y: Int, color: Int) { 382 + if (x in topX until bottomX && y in topY until bottomY) 383 + pixels[x + y * width] = color 384 + } 385 + 386 + @JvmStatic 387 + fun clearPixels() { 388 + var i = 0 389 + val pixelToClear = width * height - 7 390 + while (i < pixelToClear) { 391 + pixels[i++] = 0; pixels[i++] = 0; pixels[i++] = 0; pixels[i++] = 0 392 + pixels[i++] = 0; pixels[i++] = 0; pixels[i++] = 0; pixels[i++] = 0 393 + } 394 + val remaining = pixelToClear + 7 395 + while (i < remaining) 396 + pixels[i++] = 0 397 + } 398 + 399 + @JvmStatic 400 + fun destroy() { 401 + pixels = IntArray(0) 402 + } 403 + } 404 + }
-29
src/main/java/com/jagex/runescape/media/Skins.java
··· 1 - package com.jagex.runescape.media; 2 - 3 - import com.jagex.runescape.net.Buffer; 4 - 5 - public class Skins { 6 - 7 - public int count; 8 - public int[] opcodes; 9 - public int[][] skinList; 10 - 11 - public Skins(Buffer buffer) { 12 - count = buffer.getUnsignedByte(); 13 - opcodes = new int[count]; 14 - skinList = new int[count][]; 15 - for (int opcode = 0; opcode < count; opcode++) 16 - opcodes[opcode] = buffer.getUnsignedByte(); 17 - 18 - for (int skin = 0; skin < count; skin++) { 19 - int subSkinAmount = buffer.getUnsignedByte(); 20 - skinList[skin] = new int[subSkinAmount]; 21 - for (int subSkin = 0; subSkin < subSkinAmount; subSkin++) 22 - skinList[skin][subSkin] = buffer.getUnsignedByte(); 23 - 24 - } 25 - 26 - } 27 - 28 - 29 - }
+25
src/main/java/com/jagex/runescape/media/Skins.kt
··· 1 + package com.jagex.runescape.media 2 + 3 + import com.jagex.runescape.net.Buffer 4 + 5 + class Skins(buffer: Buffer) { 6 + 7 + @JvmField val count: Int 8 + @JvmField val opcodes: IntArray 9 + @JvmField val skinList: Array<IntArray> 10 + 11 + init { 12 + count = buffer.getUnsignedByte() 13 + opcodes = IntArray(count) 14 + skinList = Array(count) { IntArray(0) } 15 + for (opcode in 0 until count) 16 + opcodes[opcode] = buffer.getUnsignedByte() 17 + 18 + for (skin in 0 until count) { 19 + val subSkinAmount = buffer.getUnsignedByte() 20 + skinList[skin] = IntArray(subSkinAmount) 21 + for (subSkin in 0 until subSkinAmount) 22 + skinList[skin][subSkin] = buffer.getUnsignedByte() 23 + } 24 + } 25 + }
+2 -2
src/main/java/com/jagex/runescape/media/renderable/Model.kt
··· 822 822 return 823 823 } 824 824 val animation = Animation.getAnimation(frameId) ?: return 825 - val skins = animation.animationSkins 825 + val skins = animation.animationSkins ?: return 826 826 vertexXModifier = 0 827 827 vertexYModifier = 0 828 828 vertexZModifier = 0 ··· 849 849 applyTransform(k) 850 850 return 851 851 } 852 - val skins = animation.animationSkins 852 + val skins = animation.animationSkins ?: return 853 853 vertexXModifier = 0 854 854 vertexYModifier = 0 855 855 vertexZModifier = 0
-154
src/main/java/com/jagex/runescape/media/renderable/actor/Actor.java
··· 1 - package com.jagex.runescape.media.renderable.actor; 2 - 3 - import com.jagex.runescape.cache.media.AnimationSequence; 4 - import com.jagex.runescape.media.renderable.Renderable; 5 - 6 - public abstract class Actor extends Renderable { 7 - public String forcedChat; 8 - public int textCycle = 100; 9 - public int textColour; 10 - public int nextStepOrientation; 11 - public int pulseCycle; 12 - public int[] pathX = new int[10]; 13 - public int[] pathY = new int[10]; 14 - public int movementAnimation = -1; 15 - public int displayedMovementFrames; 16 - public int movementCycle; 17 - public boolean[] runningQueue = new boolean[10]; 18 - public boolean dynamic = false; 19 - public int textEffect; 20 - public int modelHeight = 200; 21 - public int endCycle = -1000; 22 - public int anInt1596; 23 - public int anInt1597; 24 - public int faceX; 25 - public int faceY; 26 - public int turnSpeed = 32; 27 - public int boundaryDimension = 1; 28 - public int movementStartX; 29 - public int movementEndX; 30 - public int movementStartY; 31 - public int movementEndY; 32 - public int moveCycleEnd; 33 - public int moveCycleStart; 34 - public int moveDirection; 35 - public int faceActor = -1; 36 - public int worldX; 37 - public int worldY; 38 - public int currentRotation; 39 - public int stillPathPosition; 40 - public int graphic = -1; 41 - public int currentAnimation; 42 - public int animationCycle; 43 - public int spotGraphicDelay; 44 - public int spotGraphicHeight; 45 - public int walkAnimationId = -1; 46 - public int turnAroundAnimationId = -1; 47 - public int turnRightAnimationId = -1; 48 - public int turnLeftAnimationId = -1; 49 - public int resyncWalkCycle; 50 - public int emoteAnimation = -1; 51 - public int displayedEmoteFrames; 52 - public int animationSequence; 53 - public int animationDelay; 54 - public int animationResetCycle; 55 - public int runAnimationId = -1; 56 - public int[] hitDamages = new int[4]; 57 - public int[] hitTypes = new int[4]; 58 - public int[] hitCycles = new int[4]; 59 - public int pathLength; 60 - public int idleAnimation = -1; 61 - public int standTurnAnimationId = -1; 62 - 63 - public void resetPath() { 64 - pathLength = 0; 65 - stillPathPosition = 0; 66 - } 67 - 68 - public boolean isVisible() { 69 - return false; 70 - } 71 - 72 - public void move(int direction, boolean running) { 73 - int x = pathX[0]; 74 - int y = pathY[0]; 75 - if (direction == 0) { 76 - x--; 77 - y++; 78 - } 79 - if (direction == 1) 80 - y++; 81 - if (direction == 2) { 82 - x++; 83 - y++; 84 - } 85 - if (direction == 3) 86 - x--; 87 - if (direction == 4) 88 - x++; 89 - if (direction == 5) { 90 - x--; 91 - y--; 92 - } 93 - if (direction == 6) 94 - y--; 95 - if (direction == 7) { 96 - x++; 97 - y--; 98 - } 99 - if (emoteAnimation != -1 && AnimationSequence.animations[emoteAnimation].priority == 1) 100 - emoteAnimation = -1; 101 - if (pathLength < 9) 102 - pathLength++; 103 - for (int pos = pathLength; pos > 0; pos--) { 104 - pathX[pos] = pathX[pos - 1]; 105 - pathY[pos] = pathY[pos - 1]; 106 - runningQueue[pos] = runningQueue[pos - 1]; 107 - } 108 - 109 - pathX[0] = x; 110 - pathY[0] = y; 111 - runningQueue[0] = running; 112 - } 113 - 114 - public void updateHits(int hitType, int hitDamage, int hitCycle) { 115 - for (int hit = 0; hit < 4; hit++) 116 - if (hitCycles[hit] <= hitCycle) { 117 - hitDamages[hit] = hitDamage; 118 - hitTypes[hit] = hitType; 119 - hitCycles[hit] = hitCycle + 70; 120 - return; 121 - } 122 - 123 - } 124 - 125 - public void setPosition(int x, int y, boolean discard) { 126 - if (emoteAnimation != -1 && AnimationSequence.animations[emoteAnimation].priority == 1) 127 - emoteAnimation = -1; 128 - if (!discard) { 129 - int k = x - pathX[0]; 130 - int i1 = y - pathY[0]; 131 - if (k >= -8 && k <= 8 && i1 >= -8 && i1 <= 8) { 132 - if (pathLength < 9) 133 - pathLength++; 134 - for (int j1 = pathLength; j1 > 0; j1--) { 135 - pathX[j1] = pathX[j1 - 1]; 136 - pathY[j1] = pathY[j1 - 1]; 137 - runningQueue[j1] = runningQueue[j1 - 1]; 138 - } 139 - 140 - pathX[0] = x; 141 - pathY[0] = y; 142 - runningQueue[0] = false; 143 - return; 144 - } 145 - } 146 - pathLength = 0; 147 - stillPathPosition = 0; 148 - resyncWalkCycle = 0; 149 - pathX[0] = x; 150 - pathY[0] = y; 151 - worldX = pathX[0] * 128 + boundaryDimension * 64; 152 - worldY = pathY[0] * 128 + boundaryDimension * 64; 153 - } 154 - }
+131
src/main/java/com/jagex/runescape/media/renderable/actor/Actor.kt
··· 1 + package com.jagex.runescape.media.renderable.actor 2 + 3 + import com.jagex.runescape.cache.media.AnimationSequence 4 + import com.jagex.runescape.media.renderable.Renderable 5 + 6 + abstract class Actor : Renderable() { 7 + @JvmField var forcedChat: String? = null 8 + @JvmField var textCycle: Int = 100 9 + @JvmField var textColour: Int = 0 10 + @JvmField var nextStepOrientation: Int = 0 11 + @JvmField var pulseCycle: Int = 0 12 + @JvmField var pathX: IntArray = IntArray(10) 13 + @JvmField var pathY: IntArray = IntArray(10) 14 + @JvmField var movementAnimation: Int = -1 15 + @JvmField var displayedMovementFrames: Int = 0 16 + @JvmField var movementCycle: Int = 0 17 + @JvmField var runningQueue: BooleanArray = BooleanArray(10) 18 + @JvmField var dynamic: Boolean = false 19 + @JvmField var textEffect: Int = 0 20 + init { modelHeight = 200 } 21 + @JvmField var endCycle: Int = -1000 22 + @JvmField var healthRatio: Int = 0 23 + @JvmField var healthScale: Int = 0 24 + @JvmField var faceX: Int = 0 25 + @JvmField var faceY: Int = 0 26 + @JvmField var turnSpeed: Int = 32 27 + @JvmField var boundaryDimension: Int = 1 28 + @JvmField var movementStartX: Int = 0 29 + @JvmField var movementEndX: Int = 0 30 + @JvmField var movementStartY: Int = 0 31 + @JvmField var movementEndY: Int = 0 32 + @JvmField var moveCycleEnd: Int = 0 33 + @JvmField var moveCycleStart: Int = 0 34 + @JvmField var moveDirection: Int = 0 35 + @JvmField var faceActor: Int = -1 36 + @JvmField var worldX: Int = 0 37 + @JvmField var worldY: Int = 0 38 + @JvmField var currentRotation: Int = 0 39 + @JvmField var stillPathPosition: Int = 0 40 + @JvmField var graphic: Int = -1 41 + @JvmField var currentAnimation: Int = 0 42 + @JvmField var animationCycle: Int = 0 43 + @JvmField var spotGraphicDelay: Int = 0 44 + @JvmField var spotGraphicHeight: Int = 0 45 + @JvmField var walkAnimationId: Int = -1 46 + @JvmField var turnAroundAnimationId: Int = -1 47 + @JvmField var turnRightAnimationId: Int = -1 48 + @JvmField var turnLeftAnimationId: Int = -1 49 + @JvmField var resyncWalkCycle: Int = 0 50 + @JvmField var emoteAnimation: Int = -1 51 + @JvmField var displayedEmoteFrames: Int = 0 52 + @JvmField var animationSequence: Int = 0 53 + @JvmField var animationDelay: Int = 0 54 + @JvmField var animationResetCycle: Int = 0 55 + @JvmField var runAnimationId: Int = -1 56 + @JvmField var hitDamages: IntArray = IntArray(4) 57 + @JvmField var hitTypes: IntArray = IntArray(4) 58 + @JvmField var hitCycles: IntArray = IntArray(4) 59 + @JvmField var pathLength: Int = 0 60 + @JvmField var idleAnimation: Int = -1 61 + @JvmField var standTurnAnimationId: Int = -1 62 + 63 + fun resetPath() { 64 + pathLength = 0 65 + stillPathPosition = 0 66 + } 67 + 68 + open fun isVisible(): Boolean = false 69 + 70 + fun move(direction: Int, running: Boolean) { 71 + var x = pathX[0] 72 + var y = pathY[0] 73 + if (direction == 0) { x--; y++ } 74 + if (direction == 1) y++ 75 + if (direction == 2) { x++; y++ } 76 + if (direction == 3) x-- 77 + if (direction == 4) x++ 78 + if (direction == 5) { x--; y-- } 79 + if (direction == 6) y-- 80 + if (direction == 7) { x++; y-- } 81 + if (emoteAnimation != -1 && AnimationSequence.animations!![emoteAnimation]!!.priority == 1) 82 + emoteAnimation = -1 83 + if (pathLength < 9) pathLength++ 84 + for (pos in pathLength downTo 1) { 85 + pathX[pos] = pathX[pos - 1] 86 + pathY[pos] = pathY[pos - 1] 87 + runningQueue[pos] = runningQueue[pos - 1] 88 + } 89 + pathX[0] = x 90 + pathY[0] = y 91 + runningQueue[0] = running 92 + } 93 + 94 + fun updateHits(hitType: Int, hitDamage: Int, hitCycle: Int) { 95 + for (hit in 0 until 4) 96 + if (hitCycles[hit] <= hitCycle) { 97 + hitDamages[hit] = hitDamage 98 + hitTypes[hit] = hitType 99 + hitCycles[hit] = hitCycle + 70 100 + return 101 + } 102 + } 103 + 104 + fun setPosition(x: Int, y: Int, discard: Boolean) { 105 + if (emoteAnimation != -1 && AnimationSequence.animations!![emoteAnimation]!!.priority == 1) 106 + emoteAnimation = -1 107 + if (!discard) { 108 + val k = x - pathX[0] 109 + val i1 = y - pathY[0] 110 + if (k >= -8 && k <= 8 && i1 >= -8 && i1 <= 8) { 111 + if (pathLength < 9) pathLength++ 112 + for (j1 in pathLength downTo 1) { 113 + pathX[j1] = pathX[j1 - 1] 114 + pathY[j1] = pathY[j1 - 1] 115 + runningQueue[j1] = runningQueue[j1 - 1] 116 + } 117 + pathX[0] = x 118 + pathY[0] = y 119 + runningQueue[0] = false 120 + return 121 + } 122 + } 123 + pathLength = 0 124 + stillPathPosition = 0 125 + resyncWalkCycle = 0 126 + pathX[0] = x 127 + pathY[0] = y 128 + worldX = pathX[0] * 128 + boundaryDimension * 64 129 + worldY = pathY[0] * 128 + boundaryDimension * 64 130 + } 131 + }
-62
src/main/java/com/jagex/runescape/media/renderable/actor/Npc.java
··· 1 - package com.jagex.runescape.media.renderable.actor; 2 - 3 - import com.jagex.runescape.cache.def.ActorDefinition; 4 - import com.jagex.runescape.cache.media.AnimationSequence; 5 - import com.jagex.runescape.cache.media.SpotAnimation; 6 - import com.jagex.runescape.media.Animation; 7 - import com.jagex.runescape.media.renderable.Model; 8 - 9 - public class Npc extends Actor { 10 - public ActorDefinition npcDefinition; 11 - 12 - public Model getChildModel() { 13 - if (super.emoteAnimation >= 0 && super.animationDelay == 0) { 14 - int frameId = AnimationSequence.animations[super.emoteAnimation].getPrimaryFrame[super.displayedEmoteFrames]; 15 - int frameId2 = -1; 16 - if (super.movementAnimation >= 0 && super.movementAnimation != super.idleAnimation) 17 - frameId2 = AnimationSequence.animations[super.movementAnimation].getPrimaryFrame[super.displayedMovementFrames]; 18 - return npcDefinition.getChildModel(frameId, frameId2, AnimationSequence.animations[super.emoteAnimation].flowControl); 19 - } 20 - int j = -1; 21 - if (super.movementAnimation >= 0) 22 - j = AnimationSequence.animations[super.movementAnimation].getPrimaryFrame[super.displayedMovementFrames]; 23 - return npcDefinition.getChildModel(j, -1, null); 24 - } 25 - 26 - @Override 27 - public Model getRotatedModel() { 28 - if (npcDefinition == null) 29 - return null; 30 - Model model = getChildModel(); 31 - if (model == null) 32 - return null; 33 - super.modelHeight = model.modelHeight; 34 - if (super.graphic != -1 && super.currentAnimation != -1) { 35 - SpotAnimation spotanimation = SpotAnimation.cache[super.graphic]; 36 - Model model_4_ = spotanimation.getModel(); 37 - if (model_4_ != null) { 38 - int animationId = spotanimation.sequences.getPrimaryFrame[super.currentAnimation]; 39 - Model animationModel = new Model(true, 40 - model_4_, Animation.exists(animationId)); 41 - animationModel.translate(0, 0, -super.spotGraphicHeight); 42 - animationModel.createBones(); 43 - animationModel.applyTransform(animationId); 44 - animationModel.triangleSkin = null; 45 - animationModel.vectorSkin = null; 46 - if (spotanimation.resizeXY != 128 || spotanimation.resizeZ != 128) 47 - animationModel.scaleT(spotanimation.resizeZ, spotanimation.resizeXY, 9, spotanimation.resizeXY); 48 - animationModel.applyLighting(64 + spotanimation.modelLightFalloff, 850 + spotanimation.modelLightAmbient, -30, -50, -30, true); 49 - Model[] models = { model, animationModel }; 50 - model = new Model(models); 51 - } 52 - } 53 - if (npcDefinition.boundaryDimension == 1) 54 - model.singleTile = true; 55 - return model; 56 - } 57 - 58 - @Override 59 - public boolean isVisible() { 60 - return npcDefinition != null; 61 - } 62 - }
+53
src/main/java/com/jagex/runescape/media/renderable/actor/Npc.kt
··· 1 + package com.jagex.runescape.media.renderable.actor 2 + 3 + import com.jagex.runescape.cache.def.ActorDefinition 4 + import com.jagex.runescape.cache.media.AnimationSequence 5 + import com.jagex.runescape.cache.media.SpotAnimation 6 + import com.jagex.runescape.media.Animation 7 + import com.jagex.runescape.media.renderable.Model 8 + 9 + class Npc : Actor() { 10 + @JvmField var npcDefinition: ActorDefinition? = null 11 + 12 + fun getChildModel(): Model? { 13 + if (emoteAnimation >= 0 && animationDelay == 0) { 14 + val frameId = AnimationSequence.animations!![emoteAnimation]!!.getPrimaryFrame!![displayedEmoteFrames] 15 + var frameId2 = -1 16 + if (movementAnimation >= 0 && movementAnimation != idleAnimation) 17 + frameId2 = AnimationSequence.animations!![movementAnimation]!!.getPrimaryFrame!![displayedMovementFrames] 18 + return npcDefinition!!.getChildModel(frameId, frameId2, AnimationSequence.animations!![emoteAnimation]!!.flowControl) 19 + } 20 + var j = -1 21 + if (movementAnimation >= 0) 22 + j = AnimationSequence.animations!![movementAnimation]!!.getPrimaryFrame!![displayedMovementFrames] 23 + return npcDefinition!!.getChildModel(j, -1, null) 24 + } 25 + 26 + override fun getRotatedModel(): Model? { 27 + if (npcDefinition == null) return null 28 + var model = getChildModel() ?: return null 29 + modelHeight = model.modelHeight 30 + if (graphic != -1 && currentAnimation != -1) { 31 + val spotAnimation = SpotAnimation.cache!![graphic]!! 32 + val spotModel = spotAnimation.getModel() 33 + if (spotModel != null) { 34 + val animationId = spotAnimation.sequences!!.getPrimaryFrame!![currentAnimation] 35 + val animationModel = Model(true, spotModel, Animation.exists(animationId)) 36 + animationModel.translate(0, 0, -spotGraphicHeight) 37 + animationModel.createBones() 38 + animationModel.applyTransform(animationId) 39 + animationModel.triangleSkin = null 40 + animationModel.vectorSkin = null 41 + if (spotAnimation.resizeXY != 128 || spotAnimation.resizeZ != 128) 42 + animationModel.scaleT(spotAnimation.resizeZ, spotAnimation.resizeXY, 9, spotAnimation.resizeXY) 43 + animationModel.applyLighting(64 + spotAnimation.modelLightFalloff, 850 + spotAnimation.modelLightAmbient, -30, -50, -30, true) 44 + model = Model(arrayOf(model, animationModel)) 45 + } 46 + } 47 + if (npcDefinition!!.boundaryDimension.toInt() == 1) 48 + model.singleTile = true 49 + return model 50 + } 51 + 52 + override fun isVisible(): Boolean = npcDefinition != null 53 + }
-348
src/main/java/com/jagex/runescape/media/renderable/actor/Player.java
··· 1 - package com.jagex.runescape.media.renderable.actor; 2 - 3 - import com.jagex.runescape.Game; 4 - import com.jagex.runescape.cache.def.ActorDefinition; 5 - import com.jagex.runescape.cache.def.ItemDefinition; 6 - import com.jagex.runescape.cache.media.AnimationSequence; 7 - import com.jagex.runescape.cache.media.IdentityKit; 8 - import com.jagex.runescape.cache.media.SpotAnimation; 9 - import com.jagex.runescape.collection.Cache; 10 - import com.jagex.runescape.media.Animation; 11 - import com.jagex.runescape.media.renderable.Model; 12 - import com.jagex.runescape.net.Buffer; 13 - import com.jagex.runescape.util.TextUtils; 14 - 15 - public class Player extends Actor { 16 - 17 - public int anInt1743; 18 - public int drawHeight; 19 - public int anInt1745; 20 - public Model playerModel; 21 - public int headIcon = -1; 22 - private long cachedModel = -1L; 23 - public int drawHeight2; 24 - public String playerName; 25 - public int[] appearance = new int[12]; 26 - public int combatLevel; 27 - private long appearanceHash; 28 - private int gender; 29 - public int isSkulled = -1; 30 - public ActorDefinition npcDefinition; 31 - public boolean visible = false; 32 - public int skillLevel; 33 - public int[] appearanceColors = new int[5]; 34 - public static Cache modelCache = new Cache(260); 35 - public boolean preventRotation = false; 36 - public int objectAppearanceStartTick; 37 - public int objectAppearanceEndTick; 38 - public int teamId; 39 - public int anInt1768; 40 - public int anInt1769; 41 - public int anInt1770; 42 - public int anInt1771; 43 - 44 - 45 - public Model getHeadModel() { 46 - if(!visible) 47 - return null; 48 - if(npcDefinition != null) 49 - return npcDefinition.getHeadModel(); 50 - boolean cached = false; 51 - for(int index = 0; index < 12; index++) { 52 - int appearanceId = appearance[index]; 53 - if(appearanceId >= 256 && appearanceId < 512 && !IdentityKit.cache[appearanceId - 256].isHeadModelCached()) 54 - cached = true; 55 - if(appearanceId >= 512 && !ItemDefinition.lookup(appearanceId - 512).headPieceReady(gender)) 56 - cached = true; 57 - } 58 - 59 - if(cached) 60 - return null; 61 - Model[] headModels = new Model[12]; 62 - int headModelsOffset = 0; 63 - for(int modelIndex = 0; modelIndex < 12; modelIndex++) { 64 - int appearanceId = appearance[modelIndex]; 65 - if(appearanceId >= 256 && appearanceId < 512) { 66 - Model subModel = IdentityKit.cache[appearanceId - 256].getHeadModel(); 67 - if(subModel != null) 68 - headModels[headModelsOffset++] = subModel; 69 - } 70 - if(appearanceId >= 512) { 71 - Model subModel = ItemDefinition.lookup(appearanceId - 512).asHeadPiece(gender); 72 - if(subModel != null) 73 - headModels[headModelsOffset++] = subModel; 74 - } 75 - } 76 - 77 - Model headModel = new Model(headModelsOffset, headModels); 78 - for(int index = 0; index < 5; index++) 79 - if(appearanceColors[index] != 0) { 80 - headModel.replaceColor(Game.playerColours[index][0], Game.playerColours[index][appearanceColors[index]]); 81 - if(index == 1) 82 - headModel.replaceColor(Game.SKIN_COLOURS[0], Game.SKIN_COLOURS[appearanceColors[index]]); 83 - } 84 - 85 - return headModel; 86 - } 87 - 88 - public Model getAnimatedModel() { 89 - if(npcDefinition != null) { 90 - int frame = -1; 91 - if(super.emoteAnimation >= 0 && super.animationDelay == 0) 92 - frame = AnimationSequence.animations[super.emoteAnimation].getPrimaryFrame[super.displayedEmoteFrames]; 93 - else if(super.movementAnimation >= 0) 94 - frame = AnimationSequence.animations[super.movementAnimation].getPrimaryFrame[super.displayedMovementFrames]; 95 - Model model = npcDefinition.getChildModel(frame, -1, null); 96 - return model; 97 - } 98 - long hash = appearanceHash; 99 - int primaryFrame = -1; 100 - int secondaryFrame = -1; 101 - int shieldModel = -1; 102 - int weaponModel = -1; 103 - if(super.emoteAnimation >= 0 && super.animationDelay == 0) { 104 - AnimationSequence emote = AnimationSequence.animations[super.emoteAnimation]; 105 - primaryFrame = emote.getPrimaryFrame[super.displayedEmoteFrames]; 106 - if(super.movementAnimation >= 0 && super.movementAnimation != super.idleAnimation) 107 - secondaryFrame = AnimationSequence.animations[super.movementAnimation].getPrimaryFrame[super.displayedMovementFrames]; 108 - if(emote.getPlayerShieldDelta >= 0) { 109 - shieldModel = emote.getPlayerShieldDelta; 110 - hash += shieldModel - appearance[5] << 8; 111 - } 112 - if(emote.getPlayerWeaponDelta >= 0) { 113 - weaponModel = emote.getPlayerWeaponDelta; 114 - hash += weaponModel - appearance[3] << 16; 115 - } 116 - } else if(super.movementAnimation >= 0) 117 - primaryFrame = AnimationSequence.animations[super.movementAnimation].getPrimaryFrame[super.displayedMovementFrames]; 118 - Model model = (Model) modelCache.get(hash); 119 - if(model == null) { 120 - boolean invalid = false; 121 - for(int bodyPart = 0; bodyPart < 12; bodyPart++) { 122 - int appearanceModel = appearance[bodyPart]; 123 - if(weaponModel >= 0 && bodyPart == 3) 124 - appearanceModel = weaponModel; 125 - if(shieldModel >= 0 && bodyPart == 5) 126 - appearanceModel = shieldModel; 127 - if(appearanceModel >= 256 && appearanceModel < 512 && !IdentityKit.cache[appearanceModel - 256].isBodyModelCached()) 128 - invalid = true; 129 - if(appearanceModel >= 512 && !ItemDefinition.lookup(appearanceModel - 512).equipmentReady(gender)) 130 - invalid = true; 131 - } 132 - 133 - if(invalid) { 134 - if(cachedModel != -1L) 135 - model = (Model) modelCache.get(cachedModel); 136 - if(model == null) 137 - return null; 138 - } 139 - } 140 - if(model == null) { 141 - Model models[] = new Model[12]; 142 - int count = 0; 143 - for(int index = 0; index < 12; index++) { 144 - int part = appearance[index]; 145 - if(weaponModel >= 0 && index == 3) 146 - part = weaponModel; 147 - if(shieldModel >= 0 && index == 5) 148 - part = shieldModel; 149 - if(part >= 256 && part < 512) { 150 - Model bodyModel = IdentityKit.cache[part - 256].getBodyModel(); 151 - if(bodyModel != null) 152 - models[count++] = bodyModel; 153 - } 154 - if(part >= 512) { 155 - Model equipment = ItemDefinition.lookup(part - 512).asEquipment(gender); 156 - if(equipment != null) 157 - models[count++] = equipment; 158 - } 159 - } 160 - 161 - model = new Model(count, models); 162 - for(int part = 0; part < 5; part++) 163 - if(appearanceColors[part] != 0) { 164 - model.replaceColor(Game.playerColours[part][0], Game.playerColours[part][appearanceColors[part]]); 165 - if(part == 1) 166 - model.replaceColor(Game.SKIN_COLOURS[0], Game.SKIN_COLOURS[appearanceColors[part]]); 167 - } 168 - 169 - model.createBones(); 170 - model.applyLighting(64, 850, -30, -50, -30, true); 171 - modelCache.put(model, hash); 172 - cachedModel = hash; 173 - } 174 - if(preventRotation) 175 - return model; 176 - Model empty = Model.EMPTY_MODEL; 177 - empty.replaceWithModel(model, Animation.exists(primaryFrame) & Animation.exists(secondaryFrame)); 178 - if(primaryFrame != -1 && secondaryFrame != -1) 179 - empty.mixAnimationFrames(secondaryFrame, 0, primaryFrame, AnimationSequence.animations[super.emoteAnimation].flowControl); 180 - else if(primaryFrame != -1) 181 - empty.applyTransform(primaryFrame); 182 - empty.calculateDiagonals(); 183 - empty.triangleSkin = null; 184 - empty.vectorSkin = null; 185 - return empty; 186 - } 187 - 188 - @Override 189 - public boolean isVisible() { 190 - return visible; 191 - } 192 - 193 - @Override 194 - public Model getRotatedModel() { 195 - if(!visible) 196 - return null; 197 - Model appearanceModel = getAnimatedModel(); 198 - if(appearanceModel == null) 199 - return null; 200 - modelHeight = appearanceModel.modelHeight; 201 - appearanceModel.singleTile = true; 202 - if(preventRotation) 203 - return appearanceModel; 204 - if(super.graphic != -1 && super.currentAnimation != -1) { 205 - SpotAnimation spotAnimation = SpotAnimation.cache[super.graphic]; 206 - Model spotAnimationModel = spotAnimation.getModel(); 207 - if(spotAnimationModel != null) { 208 - Model spotAnimationModel2 = new Model(true, spotAnimationModel, Animation.exists(super.currentAnimation)); 209 - spotAnimationModel2.translate(0, 0, -super.spotGraphicHeight); 210 - spotAnimationModel2.createBones(); 211 - spotAnimationModel2.applyTransform(spotAnimation.sequences.getPrimaryFrame[super.currentAnimation]); 212 - spotAnimationModel2.triangleSkin = null; 213 - spotAnimationModel2.vectorSkin = null; 214 - if(spotAnimation.resizeXY != 128 || spotAnimation.resizeZ != 128) 215 - spotAnimationModel2.scaleT(spotAnimation.resizeZ, spotAnimation.resizeXY, 9, spotAnimation.resizeXY); 216 - spotAnimationModel2.applyLighting(64 + spotAnimation.modelLightFalloff, 850 + spotAnimation.modelLightAmbient, -30, -50, -30, true); 217 - Model[] models = {appearanceModel, spotAnimationModel2}; 218 - appearanceModel = new Model(models); 219 - } 220 - } 221 - if(playerModel != null) { 222 - if(Game.pulseCycle >= objectAppearanceEndTick) 223 - playerModel = null; 224 - if(Game.pulseCycle >= objectAppearanceStartTick && Game.pulseCycle < objectAppearanceEndTick) { 225 - Model model = playerModel; 226 - model.translate(anInt1743 - super.worldX, anInt1745 - super.worldY, drawHeight - drawHeight2); 227 - if(super.nextStepOrientation == 512) { 228 - model.rotate90Degrees(); 229 - model.rotate90Degrees(); 230 - model.rotate90Degrees(); 231 - } else if(super.nextStepOrientation == 1024) { 232 - model.rotate90Degrees(); 233 - model.rotate90Degrees(); 234 - } else if(super.nextStepOrientation == 1536) 235 - model.rotate90Degrees(); 236 - Model[] models = {appearanceModel, model}; 237 - appearanceModel = new Model(models); 238 - if(super.nextStepOrientation == 512) 239 - model.rotate90Degrees(); 240 - else if(super.nextStepOrientation == 1024) { 241 - model.rotate90Degrees(); 242 - model.rotate90Degrees(); 243 - } else if(super.nextStepOrientation == 1536) { 244 - model.rotate90Degrees(); 245 - model.rotate90Degrees(); 246 - model.rotate90Degrees(); 247 - } 248 - model.translate(super.worldX - anInt1743, super.worldY - anInt1745, drawHeight2 - drawHeight); 249 - } 250 - } 251 - appearanceModel.singleTile = true; 252 - return appearanceModel; 253 - } 254 - 255 - public void updateAppearance(Buffer buffer) { 256 - buffer.currentPosition = 0; 257 - gender = buffer.getUnsignedByte(); 258 - System.out.println("Got Gender: " + gender); 259 - isSkulled = buffer.getByte(); 260 - 261 - System.out.println("Got Skulled: " + isSkulled); 262 - headIcon = buffer.getByte(); 263 - 264 - System.out.println("HeadIcon: " + headIcon); 265 - npcDefinition = null; 266 - teamId = 0; 267 - for(int index = 0; index < 12; index++) { 268 - int upperByte = buffer.getUnsignedByte(); 269 - if(upperByte == 0) { 270 - appearance[index] = 0; 271 - continue; 272 - } 273 - int lowerByte = buffer.getUnsignedByte(); 274 - appearance[index] = (upperByte << 8) + lowerByte; 275 - if(index == 0 && appearance[0] == 65535) { 276 - npcDefinition = ActorDefinition.getDefinition(buffer.getUnsignedShortBE()); 277 - break; 278 - } 279 - if(appearance[index] >= 512 && appearance[index] - 512 < ItemDefinition.count) { 280 - int itemTeam = ItemDefinition.lookup(appearance[index] - 512).team; 281 - if(itemTeam != 0) 282 - teamId = itemTeam; 283 - } 284 - } 285 - 286 - for(int l = 0; l < 5; l++) { 287 - int j1 = buffer.getUnsignedByte(); 288 - if(j1 < 0 || j1 >= Game.playerColours[l].length) 289 - j1 = 0; 290 - appearanceColors[l] = j1; 291 - } 292 - 293 - super.idleAnimation = buffer.getUnsignedShortBE(); 294 - if(super.idleAnimation == 65535) 295 - super.idleAnimation = -1; 296 - super.standTurnAnimationId = buffer.getUnsignedShortBE(); 297 - if(super.standTurnAnimationId == 65535) 298 - super.standTurnAnimationId = -1; 299 - super.walkAnimationId = buffer.getUnsignedShortBE(); 300 - if(super.walkAnimationId == 65535) 301 - super.walkAnimationId = -1; 302 - super.turnAroundAnimationId = buffer.getUnsignedShortBE(); 303 - if(super.turnAroundAnimationId == 65535) 304 - super.turnAroundAnimationId = -1; 305 - super.turnRightAnimationId = buffer.getUnsignedShortBE(); 306 - if(super.turnRightAnimationId == 65535) 307 - super.turnRightAnimationId = -1; 308 - super.turnLeftAnimationId = buffer.getUnsignedShortBE(); 309 - if(super.turnLeftAnimationId == 65535) 310 - super.turnLeftAnimationId = -1; 311 - super.runAnimationId = buffer.getUnsignedShortBE(); 312 - if(super.runAnimationId == 65535) 313 - super.runAnimationId = -1; 314 - playerName = TextUtils.formatName(TextUtils.longToName(buffer.getLongBE())); 315 - System.out.println("Name: " + playerName); 316 - combatLevel = buffer.getUnsignedByte(); 317 - System.out.println("Combat Level: " + combatLevel); 318 - skillLevel = buffer.getUnsignedShortBE(); 319 - System.out.println("SkillLevel: " + skillLevel); 320 - visible = true; 321 - appearanceHash = 0L; 322 - int k1 = appearance[5]; 323 - int i2 = appearance[9]; 324 - appearance[5] = i2; 325 - appearance[9] = k1; 326 - for(int j2 = 0; j2 < 12; j2++) { 327 - appearanceHash <<= 4; 328 - if(appearance[j2] >= 256) 329 - appearanceHash += appearance[j2] - 256; 330 - } 331 - 332 - if(appearance[0] >= 256) 333 - appearanceHash += appearance[0] - 256 >> 4; 334 - if(appearance[1] >= 256) 335 - appearanceHash += appearance[1] - 256 >> 8; 336 - appearance[5] = k1; 337 - appearance[9] = i2; 338 - for(int k2 = 0; k2 < 5; k2++) { 339 - appearanceHash <<= 3; 340 - appearanceHash += appearanceColors[k2]; 341 - } 342 - 343 - appearanceHash <<= 1; 344 - appearanceHash += gender; 345 - } 346 - 347 - 348 - }
+299
src/main/java/com/jagex/runescape/media/renderable/actor/Player.kt
··· 1 + package com.jagex.runescape.media.renderable.actor 2 + 3 + import com.jagex.runescape.Game 4 + import com.jagex.runescape.cache.def.ActorDefinition 5 + import com.jagex.runescape.cache.def.ItemDefinition 6 + import com.jagex.runescape.cache.media.AnimationSequence 7 + import com.jagex.runescape.cache.media.IdentityKit 8 + import com.jagex.runescape.cache.media.SpotAnimation 9 + import com.jagex.runescape.collection.Cache 10 + import com.jagex.runescape.media.Animation 11 + import com.jagex.runescape.media.renderable.Model 12 + import com.jagex.runescape.net.Buffer 13 + import com.jagex.runescape.util.TextUtils 14 + 15 + class Player : Actor() { 16 + 17 + @JvmField var objectX: Int = 0 18 + @JvmField var drawHeight: Int = 0 19 + @JvmField var objectY: Int = 0 20 + @JvmField var playerModel: Model? = null 21 + @JvmField var headIcon: Int = -1 22 + private var cachedModel: Long = -1L 23 + @JvmField var drawHeight2: Int = 0 24 + @JvmField var playerName: String? = null 25 + @JvmField var appearance: IntArray = IntArray(12) 26 + @JvmField var combatLevel: Int = 0 27 + private var appearanceHash: Long = 0L 28 + private var gender: Int = 0 29 + @JvmField var isSkulled: Int = -1 30 + @JvmField var npcDefinition: ActorDefinition? = null 31 + @JvmField var visible: Boolean = false 32 + @JvmField var skillLevel: Int = 0 33 + @JvmField var appearanceColors: IntArray = IntArray(5) 34 + @JvmField var preventRotation: Boolean = false 35 + @JvmField var objectAppearanceStartTick: Int = 0 36 + @JvmField var objectAppearanceEndTick: Int = 0 37 + @JvmField var teamId: Int = 0 38 + @JvmField var objectMinTileX: Int = 0 39 + @JvmField var objectMinTileY: Int = 0 40 + @JvmField var objectMaxTileX: Int = 0 41 + @JvmField var objectMaxTileY: Int = 0 42 + 43 + fun getHeadModel(): Model? { 44 + if (!visible) return null 45 + if (npcDefinition != null) return npcDefinition!!.getHeadModel() 46 + var cached = false 47 + for (index in 0 until 12) { 48 + val appearanceId = appearance[index] 49 + if (appearanceId in 256 until 512 && !IdentityKit.cache!![appearanceId - 256]!!.isHeadModelCached()) 50 + cached = true 51 + if (appearanceId >= 512 && !ItemDefinition.lookup(appearanceId - 512).headPieceReady(gender)) 52 + cached = true 53 + } 54 + if (cached) return null 55 + val headModels = arrayOfNulls<Model>(12) 56 + var headModelsOffset = 0 57 + for (modelIndex in 0 until 12) { 58 + val appearanceId = appearance[modelIndex] 59 + if (appearanceId in 256 until 512) { 60 + val subModel = IdentityKit.cache!![appearanceId - 256]!!.getHeadModel() 61 + if (subModel != null) 62 + headModels[headModelsOffset++] = subModel 63 + } 64 + if (appearanceId >= 512) { 65 + val subModel = ItemDefinition.lookup(appearanceId - 512).asHeadPiece(gender) 66 + if (subModel != null) 67 + headModels[headModelsOffset++] = subModel 68 + } 69 + } 70 + val headModel = Model(headModelsOffset, headModels) 71 + for (index in 0 until 5) 72 + if (appearanceColors[index] != 0) { 73 + headModel.replaceColor(Game.playerColours[index][0], Game.playerColours[index][appearanceColors[index]]) 74 + if (index == 1) 75 + headModel.replaceColor(Game.SKIN_COLOURS[0], Game.SKIN_COLOURS[appearanceColors[index]]) 76 + } 77 + return headModel 78 + } 79 + 80 + fun getAnimatedModel(): Model? { 81 + if (npcDefinition != null) { 82 + var frame = -1 83 + if (emoteAnimation >= 0 && animationDelay == 0) 84 + frame = AnimationSequence.animations!![emoteAnimation]!!.getPrimaryFrame!![displayedEmoteFrames] 85 + else if (movementAnimation >= 0) 86 + frame = AnimationSequence.animations!![movementAnimation]!!.getPrimaryFrame!![displayedMovementFrames] 87 + return npcDefinition!!.getChildModel(frame, -1, null) 88 + } 89 + var hash = appearanceHash 90 + var primaryFrame = -1 91 + var secondaryFrame = -1 92 + var shieldModel = -1 93 + var weaponModel = -1 94 + if (emoteAnimation >= 0 && animationDelay == 0) { 95 + val emote = AnimationSequence.animations!![emoteAnimation]!! 96 + primaryFrame = emote.getPrimaryFrame!![displayedEmoteFrames] 97 + if (movementAnimation >= 0 && movementAnimation != idleAnimation) 98 + secondaryFrame = AnimationSequence.animations!![movementAnimation]!!.getPrimaryFrame!![displayedMovementFrames] 99 + if (emote.getPlayerShieldDelta >= 0) { 100 + shieldModel = emote.getPlayerShieldDelta 101 + hash += (shieldModel - appearance[5]).toLong() shl 8 102 + } 103 + if (emote.getPlayerWeaponDelta >= 0) { 104 + weaponModel = emote.getPlayerWeaponDelta 105 + hash += (weaponModel - appearance[3]).toLong() shl 16 106 + } 107 + } else if (movementAnimation >= 0) 108 + primaryFrame = AnimationSequence.animations!![movementAnimation]!!.getPrimaryFrame!![displayedMovementFrames] 109 + var model = modelCache.get(hash) as Model? 110 + if (model == null) { 111 + var invalid = false 112 + for (bodyPart in 0 until 12) { 113 + var appearanceModel = appearance[bodyPart] 114 + if (weaponModel >= 0 && bodyPart == 3) appearanceModel = weaponModel 115 + if (shieldModel >= 0 && bodyPart == 5) appearanceModel = shieldModel 116 + if (appearanceModel in 256 until 512 && !IdentityKit.cache!![appearanceModel - 256]!!.isBodyModelCached()) 117 + invalid = true 118 + if (appearanceModel >= 512 && !ItemDefinition.lookup(appearanceModel - 512).equipmentReady(gender)) 119 + invalid = true 120 + } 121 + if (invalid) { 122 + if (cachedModel != -1L) 123 + model = modelCache.get(cachedModel) as Model? 124 + if (model == null) return null 125 + } 126 + } 127 + if (model == null) { 128 + val models = arrayOfNulls<Model>(12) 129 + var count = 0 130 + for (index in 0 until 12) { 131 + var part = appearance[index] 132 + if (weaponModel >= 0 && index == 3) part = weaponModel 133 + if (shieldModel >= 0 && index == 5) part = shieldModel 134 + if (part in 256 until 512) { 135 + val bodyModel = IdentityKit.cache!![part - 256]!!.getBodyModel() 136 + if (bodyModel != null) models[count++] = bodyModel 137 + } 138 + if (part >= 512) { 139 + val equipment = ItemDefinition.lookup(part - 512).asEquipment(gender) 140 + if (equipment != null) models[count++] = equipment 141 + } 142 + } 143 + model = Model(count, models) 144 + for (part in 0 until 5) 145 + if (appearanceColors[part] != 0) { 146 + model.replaceColor(Game.playerColours[part][0], Game.playerColours[part][appearanceColors[part]]) 147 + if (part == 1) 148 + model.replaceColor(Game.SKIN_COLOURS[0], Game.SKIN_COLOURS[appearanceColors[part]]) 149 + } 150 + model.createBones() 151 + model.applyLighting(64, 850, -30, -50, -30, true) 152 + modelCache.put(model, hash) 153 + cachedModel = hash 154 + } 155 + if (preventRotation) return model 156 + val empty = Model.EMPTY_MODEL 157 + empty.replaceWithModel(model, Animation.exists(primaryFrame) and Animation.exists(secondaryFrame)) 158 + if (primaryFrame != -1 && secondaryFrame != -1) 159 + empty.mixAnimationFrames(secondaryFrame, 0, primaryFrame, AnimationSequence.animations!![emoteAnimation]!!.flowControl) 160 + else if (primaryFrame != -1) 161 + empty.applyTransform(primaryFrame) 162 + empty.calculateDiagonals() 163 + empty.triangleSkin = null 164 + empty.vectorSkin = null 165 + return empty 166 + } 167 + 168 + override fun isVisible(): Boolean = visible 169 + 170 + override fun getRotatedModel(): Model? { 171 + if (!visible) return null 172 + var appearanceModel = getAnimatedModel() ?: return null 173 + modelHeight = appearanceModel.modelHeight 174 + appearanceModel.singleTile = true 175 + if (preventRotation) return appearanceModel 176 + if (graphic != -1 && currentAnimation != -1) { 177 + val spotAnimation = SpotAnimation.cache!![graphic]!! 178 + val spotAnimationModel = spotAnimation.getModel() 179 + if (spotAnimationModel != null) { 180 + val spotAnimationModel2 = Model(true, spotAnimationModel, Animation.exists(currentAnimation)) 181 + spotAnimationModel2.translate(0, 0, -spotGraphicHeight) 182 + spotAnimationModel2.createBones() 183 + spotAnimationModel2.applyTransform(spotAnimation.sequences!!.getPrimaryFrame!![currentAnimation]) 184 + spotAnimationModel2.triangleSkin = null 185 + spotAnimationModel2.vectorSkin = null 186 + if (spotAnimation.resizeXY != 128 || spotAnimation.resizeZ != 128) 187 + spotAnimationModel2.scaleT(spotAnimation.resizeZ, spotAnimation.resizeXY, 9, spotAnimation.resizeXY) 188 + spotAnimationModel2.applyLighting(64 + spotAnimation.modelLightFalloff, 850 + spotAnimation.modelLightAmbient, -30, -50, -30, true) 189 + appearanceModel = Model(arrayOf(appearanceModel, spotAnimationModel2)) 190 + } 191 + } 192 + if (playerModel != null) { 193 + if (Game.pulseCycle >= objectAppearanceEndTick) 194 + playerModel = null 195 + if (Game.pulseCycle >= objectAppearanceStartTick && Game.pulseCycle < objectAppearanceEndTick) { 196 + val model = playerModel!! 197 + model.translate(objectX - worldX, objectY - worldY, drawHeight - drawHeight2) 198 + if (nextStepOrientation == 512) { 199 + model.rotate90Degrees() 200 + model.rotate90Degrees() 201 + model.rotate90Degrees() 202 + } else if (nextStepOrientation == 1024) { 203 + model.rotate90Degrees() 204 + model.rotate90Degrees() 205 + } else if (nextStepOrientation == 1536) 206 + model.rotate90Degrees() 207 + appearanceModel = Model(arrayOf(appearanceModel, model)) 208 + if (nextStepOrientation == 512) 209 + model.rotate90Degrees() 210 + else if (nextStepOrientation == 1024) { 211 + model.rotate90Degrees() 212 + model.rotate90Degrees() 213 + } else if (nextStepOrientation == 1536) { 214 + model.rotate90Degrees() 215 + model.rotate90Degrees() 216 + model.rotate90Degrees() 217 + } 218 + model.translate(worldX - objectX, worldY - objectY, drawHeight2 - drawHeight) 219 + } 220 + } 221 + appearanceModel.singleTile = true 222 + return appearanceModel 223 + } 224 + 225 + fun updateAppearance(buffer: Buffer) { 226 + buffer.currentPosition = 0 227 + gender = buffer.getUnsignedByte() 228 + isSkulled = buffer.getByte().toInt() 229 + headIcon = buffer.getByte().toInt() 230 + npcDefinition = null 231 + teamId = 0 232 + for (index in 0 until 12) { 233 + val upperByte = buffer.getUnsignedByte() 234 + if (upperByte == 0) { 235 + appearance[index] = 0 236 + continue 237 + } 238 + val lowerByte = buffer.getUnsignedByte() 239 + appearance[index] = (upperByte shl 8) + lowerByte 240 + if (index == 0 && appearance[0] == 65535) { 241 + npcDefinition = ActorDefinition.getDefinition(buffer.getUnsignedShortBE()) 242 + break 243 + } 244 + if (appearance[index] >= 512 && appearance[index] - 512 < ItemDefinition.count) { 245 + val itemTeam = ItemDefinition.lookup(appearance[index] - 512).team 246 + if (itemTeam != 0) teamId = itemTeam 247 + } 248 + } 249 + for (l in 0 until 5) { 250 + var j1 = buffer.getUnsignedByte() 251 + if (j1 < 0 || j1 >= Game.playerColours[l].size) j1 = 0 252 + appearanceColors[l] = j1 253 + } 254 + idleAnimation = buffer.getUnsignedShortBE() 255 + if (idleAnimation == 65535) idleAnimation = -1 256 + standTurnAnimationId = buffer.getUnsignedShortBE() 257 + if (standTurnAnimationId == 65535) standTurnAnimationId = -1 258 + walkAnimationId = buffer.getUnsignedShortBE() 259 + if (walkAnimationId == 65535) walkAnimationId = -1 260 + turnAroundAnimationId = buffer.getUnsignedShortBE() 261 + if (turnAroundAnimationId == 65535) turnAroundAnimationId = -1 262 + turnRightAnimationId = buffer.getUnsignedShortBE() 263 + if (turnRightAnimationId == 65535) turnRightAnimationId = -1 264 + turnLeftAnimationId = buffer.getUnsignedShortBE() 265 + if (turnLeftAnimationId == 65535) turnLeftAnimationId = -1 266 + runAnimationId = buffer.getUnsignedShortBE() 267 + if (runAnimationId == 65535) runAnimationId = -1 268 + playerName = TextUtils.formatName(TextUtils.longToName(buffer.getLongBE())) 269 + combatLevel = buffer.getUnsignedByte() 270 + skillLevel = buffer.getUnsignedShortBE() 271 + visible = true 272 + appearanceHash = 0L 273 + val k1 = appearance[5] 274 + val i2 = appearance[9] 275 + appearance[5] = i2 276 + appearance[9] = k1 277 + for (j2 in 0 until 12) { 278 + appearanceHash = appearanceHash shl 4 279 + if (appearance[j2] >= 256) 280 + appearanceHash += (appearance[j2] - 256).toLong() 281 + } 282 + if (appearance[0] >= 256) 283 + appearanceHash += ((appearance[0] - 256) shr 4).toLong() 284 + if (appearance[1] >= 256) 285 + appearanceHash += ((appearance[1] - 256) shr 8).toLong() 286 + appearance[5] = k1 287 + appearance[9] = i2 288 + for (k2 in 0 until 5) { 289 + appearanceHash = appearanceHash shl 3 290 + appearanceHash += appearanceColors[k2].toLong() 291 + } 292 + appearanceHash = appearanceHash shl 1 293 + appearanceHash += gender.toLong() 294 + } 295 + 296 + companion object { 297 + @JvmField var modelCache: Cache = Cache(260) 298 + } 299 + }
-52
src/main/java/com/jagex/runescape/scene/util/TiledUtils.java
··· 1 - package com.jagex.runescape.scene.util; 2 - 3 - public class TiledUtils { 4 - 5 - public static int getRotatedMapChunkX(int x, int y, int rotation) { 6 - rotation &= 3; 7 - if (rotation == 0) 8 - return x; 9 - if (rotation == 1) 10 - return y; 11 - if (rotation == 2) 12 - return 7 - x; 13 - else 14 - return 7 - y; 15 - } 16 - 17 - public static int getRotatedMapChunkY(int x, int y, int rotation) { 18 - rotation &= 3; 19 - if (rotation == 0) 20 - return y; 21 - if (rotation == 1) 22 - return 7 - x; 23 - if (rotation == 2) 24 - return 7 - y; 25 - else 26 - return x; 27 - } 28 - 29 - public static int getRotatedLandscapeChunkX(int rotation, int objectSizeY, int x, int y, int objectSizeX) { 30 - rotation &= 3; 31 - if (rotation == 0) 32 - return x; 33 - if (rotation == 1) 34 - return y; 35 - if (rotation == 2) 36 - return 7 - x - (objectSizeX - 1); 37 - else 38 - return 7 - y - (objectSizeY - 1); 39 - } 40 - 41 - public static int getRotatedLandscapeChunkY(int y, int objectSizeY, int rotation, int objectSizeX, int x) { 42 - rotation &= 3; 43 - if (rotation == 0) 44 - return y; 45 - if (rotation == 1) 46 - return 7 - x - (objectSizeX - 1); 47 - if (rotation == 2) 48 - return 7 - y - (objectSizeY - 1); 49 - else 50 - return x; 51 - } 52 - }
+36
src/main/java/com/jagex/runescape/scene/util/TiledUtils.kt
··· 1 + package com.jagex.runescape.scene.util 2 + 3 + object TiledUtils { 4 + 5 + @JvmStatic 6 + fun getRotatedMapChunkX(x: Int, y: Int, rotation: Int): Int { 7 + val rot = rotation and 3 8 + if (rot == 0) return x 9 + if (rot == 1) return y 10 + return if (rot == 2) 7 - x else 7 - y 11 + } 12 + 13 + @JvmStatic 14 + fun getRotatedMapChunkY(x: Int, y: Int, rotation: Int): Int { 15 + val rot = rotation and 3 16 + if (rot == 0) return y 17 + if (rot == 1) return 7 - x 18 + return if (rot == 2) 7 - y else x 19 + } 20 + 21 + @JvmStatic 22 + fun getRotatedLandscapeChunkX(rotation: Int, objectSizeY: Int, x: Int, y: Int, objectSizeX: Int): Int { 23 + val rot = rotation and 3 24 + if (rot == 0) return x 25 + if (rot == 1) return y 26 + return if (rot == 2) 7 - x - (objectSizeX - 1) else 7 - y - (objectSizeY - 1) 27 + } 28 + 29 + @JvmStatic 30 + fun getRotatedLandscapeChunkY(y: Int, objectSizeY: Int, rotation: Int, objectSizeX: Int, x: Int): Int { 31 + val rot = rotation and 3 32 + if (rot == 0) return y 33 + if (rot == 1) return 7 - x - (objectSizeX - 1) 34 + return if (rot == 2) 7 - y - (objectSizeY - 1) else x 35 + } 36 + }
-64
src/test/java/com/jagex/runescape/net/BufferTests.java
··· 1 - package com.jagex.runescape.net; 2 - 3 - import org.junit.jupiter.api.Assertions; 4 - import org.junit.jupiter.api.DisplayName; 5 - import org.junit.jupiter.params.ParameterizedTest; 6 - import org.junit.jupiter.params.provider.CsvSource; 7 - import org.testng.annotations.Test; 8 - 9 - import java.util.Random; 10 - 11 - public class BufferTests { 12 - 13 - @ParameterizedTest(name = "Buffer allocate") 14 - @CsvSource({ 15 - "0, 100", 16 - "1, 5000", 17 - "2, 30000", 18 - "3, 30000" 19 - }) 20 - void allocateBuffer(int sizeMode, int expectedBufferSize) { 21 - Buffer buffer = Buffer.allocate(sizeMode); 22 - Assertions.assertEquals(0, buffer.currentPosition, "buffer position should be 0"); 23 - Assertions.assertArrayEquals(buffer.buffer, new byte[expectedBufferSize], "Buffer should be completely empty"); 24 - Assertions.assertEquals(expectedBufferSize, buffer.buffer.length, 25 - () -> "buffer length should be " + expectedBufferSize + " with sizeMode: " + sizeMode); 26 - 27 - } 28 - 29 - @Test 30 - @DisplayName("Byte test") 31 - void byteTest() { 32 - Buffer buffer = Buffer.allocate(0); 33 - Assertions.assertEquals(0, buffer.currentPosition, "buffer position should be 0"); 34 - Assertions.assertArrayEquals(buffer.buffer, new byte[100], "Buffer should be completely empty"); 35 - 36 - Random random = new Random(); 37 - int input = random.nextInt((55 - 2) + 1) + 2; 38 - buffer.putByte(input); 39 - Assertions.assertNotEquals(0, buffer.currentPosition, "buffer position should not be 0"); 40 - buffer.currentPosition = 0; 41 - Assertions.assertEquals(input, buffer.getByte(), "getByte should be the same as putByte"); 42 - } 43 - 44 - 45 - @Test 46 - @DisplayName("ShortBE test") 47 - void smallTest() { 48 - Buffer buffer = Buffer.allocate(0); 49 - Assertions.assertEquals(0, buffer.currentPosition, "buffer position should be 0"); 50 - Assertions.assertArrayEquals(buffer.buffer, new byte[100], "Buffer should be completely empty"); 51 - 52 - Random random = new Random(); 53 - int input = random.nextInt((55 - 2) + 1) + 2; 54 - buffer.putShortBE(input); 55 - Assertions.assertNotEquals(0, buffer.currentPosition, "buffer position should not be 0"); 56 - buffer.currentPosition = 0; 57 - Assertions.assertEquals(input, buffer.getShortBE(), "getShortBE should be the same as putShortBE"); 58 - buffer.putShortBE(0x2801); 59 - buffer.currentPosition--; 60 - Assertions.assertEquals(256, buffer.getShortBE(), "expect big endian behavior"); 61 - } 62 - 63 - 64 - }
+60
src/test/java/com/jagex/runescape/net/BufferTests.kt
··· 1 + package com.jagex.runescape.net 2 + 3 + import org.junit.jupiter.api.Assertions 4 + import org.junit.jupiter.api.DisplayName 5 + import org.junit.jupiter.params.ParameterizedTest 6 + import org.junit.jupiter.params.provider.CsvSource 7 + import org.testng.annotations.Test 8 + import java.util.Random 9 + 10 + class BufferTests { 11 + 12 + @ParameterizedTest(name = "Buffer allocate") 13 + @CsvSource( 14 + "0, 100", 15 + "1, 5000", 16 + "2, 30000", 17 + "3, 30000" 18 + ) 19 + fun allocateBuffer(sizeMode: Int, expectedBufferSize: Int) { 20 + val buffer = Buffer.allocate(sizeMode) 21 + Assertions.assertEquals(0, buffer.currentPosition, "buffer position should be 0") 22 + Assertions.assertArrayEquals(buffer.buffer, ByteArray(expectedBufferSize), "Buffer should be completely empty") 23 + Assertions.assertEquals( 24 + expectedBufferSize, buffer.buffer.size 25 + ) { "buffer length should be $expectedBufferSize with sizeMode: $sizeMode" } 26 + } 27 + 28 + @Test 29 + @DisplayName("Byte test") 30 + fun byteTest() { 31 + val buffer = Buffer.allocate(0) 32 + Assertions.assertEquals(0, buffer.currentPosition, "buffer position should be 0") 33 + Assertions.assertArrayEquals(buffer.buffer, ByteArray(100), "Buffer should be completely empty") 34 + 35 + val random = Random() 36 + val input = random.nextInt((55 - 2) + 1) + 2 37 + buffer.putByte(input) 38 + Assertions.assertNotEquals(0, buffer.currentPosition, "buffer position should not be 0") 39 + buffer.currentPosition = 0 40 + Assertions.assertEquals(input, buffer.getByte(), "getByte should be the same as putByte") 41 + } 42 + 43 + @Test 44 + @DisplayName("ShortBE test") 45 + fun smallTest() { 46 + val buffer = Buffer.allocate(0) 47 + Assertions.assertEquals(0, buffer.currentPosition, "buffer position should be 0") 48 + Assertions.assertArrayEquals(buffer.buffer, ByteArray(100), "Buffer should be completely empty") 49 + 50 + val random = Random() 51 + val input = random.nextInt((55 - 2) + 1) + 2 52 + buffer.putShortBE(input) 53 + Assertions.assertNotEquals(0, buffer.currentPosition, "buffer position should not be 0") 54 + buffer.currentPosition = 0 55 + Assertions.assertEquals(input, buffer.getShortBE(), "getShortBE should be the same as putShortBE") 56 + buffer.putShortBE(0x2801) 57 + buffer.currentPosition-- 58 + Assertions.assertEquals(256, buffer.getShortBE(), "expect big endian behavior") 59 + } 60 + }