Guest User

Untitled

a guest
Oct 27th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.64 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class RSApplet extends Applet implements Runnable, MouseListener, MouseMotionListener, KeyListener, FocusListener, WindowListener {
  6.  
  7. final void createClientFrame(int i, int j) {
  8. myWidth = j;
  9. myHeight = i;
  10. gameFrame = new RSFrame(this, myWidth, myHeight);
  11. graphics = getGameComponent().getGraphics();
  12. fullGameScreen = new RSImageProducer(myWidth, myHeight, getGameComponent());
  13. startRunnable(this, 1);
  14. }
  15.  
  16. final void initClientFrame(int i, int j) {
  17. myWidth = j;
  18. myHeight = i;
  19. graphics = getGameComponent().getGraphics();
  20. fullGameScreen = new RSImageProducer(myWidth, myHeight, getGameComponent());
  21. startRunnable(this, 1);
  22. }
  23.  
  24. public void run()
  25. {
  26. getGameComponent().addMouseListener(this);
  27. getGameComponent().addMouseMotionListener(this);
  28. getGameComponent().addKeyListener(this);
  29. getGameComponent().addFocusListener(this);
  30. if(gameFrame != null)
  31. gameFrame.addWindowListener(this);
  32. drawLoadingText(0, "Loading...");
  33. startUp();
  34. int i = 0;
  35. int j = 256;
  36. int k = 1;
  37. int i1 = 0;
  38. int j1 = 0;
  39. for(int k1 = 0; k1 < 10; k1++)
  40. aLongArray7[k1] = System.currentTimeMillis();
  41.  
  42. long l = System.currentTimeMillis();
  43. while(anInt4 >= 0)
  44. {
  45. if(anInt4 > 0)
  46. {
  47. anInt4--;
  48. if(anInt4 == 0)
  49. {
  50. exit();
  51. return;
  52. }
  53. }
  54. int i2 = j;
  55. int j2 = k;
  56. j = 300;
  57. k = 1;
  58. long l1 = System.currentTimeMillis();
  59. if(aLongArray7[i] == 0L)
  60. {
  61. j = i2;
  62. k = j2;
  63. } else
  64. if(l1 > aLongArray7[i])
  65. j = (int)((long)(2560 * delayTime) / (l1 - aLongArray7[i]));
  66. if(j < 25)
  67. j = 25;
  68. if(j > 256)
  69. {
  70. j = 256;
  71. k = (int)((long) delayTime - (l1 - aLongArray7[i]) / 10L);
  72. }
  73. if(k > delayTime)
  74. k = delayTime;
  75. aLongArray7[i] = l1;
  76. i = (i + 1) % 10;
  77. if(k > 1)
  78. {
  79. for(int k2 = 0; k2 < 10; k2++)
  80. if(aLongArray7[k2] != 0L)
  81. aLongArray7[k2] += k;
  82.  
  83. }
  84. if(k < minDelay)
  85. k = minDelay;
  86. try
  87. {
  88. Thread.sleep(k);
  89. }
  90. catch(InterruptedException _ex)
  91. {
  92. j1++;
  93. }
  94. for(; i1 < 256; i1 += j)
  95. {
  96. clickMode3 = clickMode1;
  97. saveClickX = clickX;
  98. saveClickY = clickY;
  99. aLong29 = clickTime;
  100. clickMode1 = 0;
  101. processGameLoop();
  102. readIndex = writeIndex;
  103. }
  104.  
  105. i1 &= 0xff;
  106. if(delayTime > 0)
  107. fps = (1000 * j) / (delayTime * 256);
  108. processDrawing();
  109. if(shouldDebug)
  110. {
  111. System.out.println("ntime:" + l1);
  112. for(int l2 = 0; l2 < 10; l2++)
  113. {
  114. int i3 = ((i - l2 - 1) + 20) % 10;
  115. System.out.println("otim" + i3 + ":" + aLongArray7[i3]);
  116. }
  117.  
  118. System.out.println("fps:" + fps + " ratio:" + j + " count:" + i1);
  119. System.out.println("del:" + k + " deltime:" + delayTime + " mindel:" + minDelay);
  120. System.out.println("intex:" + j1 + " opos:" + i);
  121. shouldDebug = false;
  122. j1 = 0;
  123. }
  124. }
  125. if(anInt4 == -1)
  126. exit();
  127. }
  128.  
  129. private void exit()
  130. {
  131. anInt4 = -2;
  132. cleanUpForQuit();
  133. if(gameFrame != null)
  134. {
  135. try
  136. {
  137. Thread.sleep(1000L);
  138. }
  139. catch(Exception _ex) { }
  140. try
  141. {
  142. System.exit(0);
  143. }
  144. catch(Throwable _ex) { }
  145. }
  146. }
  147.  
  148. final void method4(int i)
  149. {
  150. delayTime = 1000 / i;
  151. }
  152.  
  153. public final void start()
  154. {
  155. if(anInt4 >= 0)
  156. anInt4 = 0;
  157. }
  158.  
  159. public final void stop()
  160. {
  161. if(anInt4 >= 0)
  162. anInt4 = 4000 / delayTime;
  163. }
  164.  
  165. public final void destroy()
  166. {
  167. anInt4 = -1;
  168. try
  169. {
  170. Thread.sleep(5000L);
  171. }
  172. catch(Exception _ex) { }
  173. if(anInt4 == -1)
  174. exit();
  175. }
  176.  
  177. public final void update(Graphics g)
  178. {
  179. if(graphics == null)
  180. graphics = g;
  181. shouldClearScreen = true;
  182. raiseWelcomeScreen();
  183. }
  184.  
  185. public final void paint(Graphics g)
  186. {
  187. if(graphics == null)
  188. graphics = g;
  189. shouldClearScreen = true;
  190. raiseWelcomeScreen();
  191. }
  192.  
  193. public boolean mouseWheelDown;
  194. public final void mousePressed(MouseEvent mouseevent)
  195. {
  196. int i = mouseevent.getX();
  197. int j = mouseevent.getY();
  198. if(gameFrame != null)
  199. {
  200. i -= 4;//4
  201. j -= 22;//22
  202. }
  203. idleTime = 0;
  204. clickX = i;
  205. clickY = j;
  206. clickTime = System.currentTimeMillis();
  207. if(mouseevent.isMetaDown())
  208. {
  209. clickMode1 = 2;
  210. clickMode2 = 2;
  211. } else
  212. {
  213. clickMode1 = 1;
  214. clickMode2 = 1;
  215. }
  216. if (mouseevent.isMetaDown()) {
  217. mouseWheelDown = true;
  218. mouseWheelX = x;
  219. mouseWheelY = y;
  220. return;
  221. }
  222. }
  223.  
  224. public final void mouseReleased(MouseEvent mouseevent)
  225. {
  226. idleTime = 0;
  227. clickMode2 = 0;
  228. mouseWheelDown = false;
  229. }
  230.  
  231. public final void mouseClicked(MouseEvent mouseevent)
  232. {
  233. }
  234.  
  235. public final void mouseEntered(MouseEvent mouseevent)
  236. {
  237. }
  238.  
  239. public final void mouseExited(MouseEvent mouseevent)
  240. {
  241. idleTime = 0;
  242. mouseX = -1;
  243. mouseY = -1;
  244. }
  245.  
  246. public int mouseWheelX;
  247. public int mouseWheelY;
  248. public final void mouseDragged(MouseEvent e) {
  249. int x = e.getX();
  250. int y = e.getY();
  251. if(gameFrame != null) {
  252. Insets insets = gameFrame.getInsets();
  253. x -= insets.left;//4
  254. y -= insets.top;//22
  255. }
  256. if (mouseWheelDown) {
  257. y = mouseWheelX - e.getX();
  258. int k = mouseWheelY - e.getY();
  259. mouseWheelDragged(y, -k);
  260. mouseWheelX = e.getX();
  261. mouseWheelY = e.getY();
  262. return;
  263. }
  264. idleTime = 0;
  265. mouseX = x;
  266. mouseY = y;
  267. //mouseWheelDown = true;
  268. }
  269.  
  270. void mouseWheelDragged(int param1, int param2) {
  271.  
  272. }
  273.  
  274. public final void mouseMoved(MouseEvent mouseevent)
  275. {
  276. int i = mouseevent.getX();
  277. int j = mouseevent.getY();
  278. if(gameFrame != null)
  279. {
  280. i -= 4;
  281. j -= 22;
  282. }
  283. if (System.currentTimeMillis() - clickTime >= 250L
  284. || Math.abs(saveClickX - i) > 5 || Math.abs(saveClickY - j) > 5) {
  285. idleTime = 0;
  286. mouseX = i;
  287. mouseY = j;
  288. }
  289. }
  290. public static int hotKey = 508;
  291. public final void keyPressed(KeyEvent keyevent)
  292. {
  293. idleTime = 0;
  294. int i = keyevent.getKeyCode();
  295. int j = keyevent.getKeyChar();
  296. //hotkeys here
  297. if (hotKey == 508) {
  298. /*if(i == KeyEvent.VK_ESCAPE){
  299. client.setTab(3);
  300. } else if(i == KeyEvent.VK_F1){
  301. client.setTab(0);
  302. } else if(i == KeyEvent.VK_F2){
  303. client.setTab(1);
  304. } else if(i == KeyEvent.VK_F3){
  305. client.setTab(2);
  306. } else if(i == KeyEvent.VK_F4){
  307. client.setTab(3);
  308. } else if(i == KeyEvent.VK_F5){
  309. client.setTab(4);
  310. } else if(i == KeyEvent.VK_F6){
  311. client.setTab(5);
  312. } else if(i == KeyEvent.VK_F7){
  313. client.setTab(6);
  314. } else if(i == KeyEvent.VK_F8){
  315. client.setTab(7);
  316. } else if(i == KeyEvent.VK_F9){
  317. client.setTab(8);
  318. } else if(i == KeyEvent.VK_F10){
  319. client.setTab(9);
  320. } else if(i == KeyEvent.VK_F11){
  321. client.setTab(10);
  322. } else if(i == KeyEvent.VK_F12){
  323. client.setTab(11);
  324. }*/
  325. if(i == KeyEvent.VK_F1) {
  326. client.setTab(3);
  327. } else if(i == KeyEvent.VK_F2){
  328. client.setTab(4);
  329. } else if(i == KeyEvent.VK_F3){
  330. client.setTab(5);
  331. } else if(i == KeyEvent.VK_F4){
  332. client.setTab(6);
  333. } else if(i == KeyEvent.VK_F5){
  334. client.setTab(0);
  335. }
  336. } else {
  337. if(i == KeyEvent.VK_ESCAPE){
  338. client.setTab(0);
  339. } else if(i == KeyEvent.VK_F1){
  340. client.setTab(3);
  341. } else if(i == KeyEvent.VK_F2){
  342. client.setTab(1);
  343. } else if(i == KeyEvent.VK_F3){
  344. client.setTab(2);
  345. } else if(i == KeyEvent.VK_F4){
  346. client.setTab(3);
  347. } else if(i == KeyEvent.VK_F5){
  348. client.setTab(4);
  349. } else if(i == KeyEvent.VK_F6){
  350. client.setTab(5);
  351. } else if(i == KeyEvent.VK_F7){
  352. client.setTab(6);
  353. } else if(i == KeyEvent.VK_F8){
  354. client.setTab(7);
  355. } else if(i == KeyEvent.VK_F9){
  356. client.setTab(8);
  357. } else if(i == KeyEvent.VK_F10){
  358. client.setTab(9);
  359. } else if(i == KeyEvent.VK_F11){
  360. client.setTab(10);
  361. } else if(i == KeyEvent.VK_F12){
  362. client.setTab(11);
  363. }
  364. }
  365. //end of hotkeys
  366. if(j < 30)
  367. j = 0;
  368. if(i == 37)
  369. j = 1;
  370. if(i == 39)
  371. j = 2;
  372. if(i == 38)
  373. j = 3;
  374. if(i == 40)
  375. j = 4;
  376. if(i == 17)
  377. j = 5;
  378. if(i == 8)
  379. j = 8;
  380. if(i == 127)
  381. j = 8;
  382. if(i == 9)
  383. j = 9;
  384. if(i == 10)
  385. j = 10;
  386. if(i >= 112 && i <= 123)
  387. j = (1008 + i) - 112;
  388. if(i == 36)
  389. j = 1000;
  390. if(i == 35)
  391. j = 1001;
  392. if(i == 33)
  393. j = 1002;
  394. if(i == 34)
  395. j = 1003;
  396. if(j > 0 && j < 128)
  397. keyArray[j] = 1;
  398. if(j > 4)
  399. {
  400. charQueue[writeIndex] = j;
  401. writeIndex = writeIndex + 1 & 0x7f;
  402. }
  403. }
  404.  
  405. public final void keyReleased(KeyEvent keyevent)
  406. {
  407. idleTime = 0;
  408. int i = keyevent.getKeyCode();
  409. char c = keyevent.getKeyChar();
  410. if(c < '\036')
  411. c = '\0';
  412. if(i == 37)
  413. c = '\001';
  414. if(i == 39)
  415. c = '\002';
  416. if(i == 38)
  417. c = '\003';
  418. if(i == 40)
  419. c = '\004';
  420. if(i == 17)
  421. c = '\005';
  422. if(i == 8)
  423. c = '\b';
  424. if(i == 127)
  425. c = '\b';
  426. if(i == 9)
  427. c = '\t';
  428. if(i == 10)
  429. c = '\n';
  430. if(c > 0 && c < '\200')
  431. keyArray[c] = 0;
  432. }
  433.  
  434. public final void keyTyped(KeyEvent keyevent)
  435. {
  436. }
  437.  
  438. final int readChar(int dummy)
  439. {
  440. while(dummy >= 0)
  441. {
  442. for(int j = 1; j > 0; j++);
  443. }
  444. int k = -1;
  445. if(writeIndex != readIndex)
  446. {
  447. k = charQueue[readIndex];
  448. readIndex = readIndex + 1 & 0x7f;
  449. }
  450. return k;
  451. }
  452.  
  453. public final void focusGained(FocusEvent focusevent)
  454. {
  455. awtFocus = true;
  456. shouldClearScreen = true;
  457. raiseWelcomeScreen();
  458. }
  459.  
  460. public final void focusLost(FocusEvent focusevent)
  461. {
  462. awtFocus = false;
  463. for(int i = 0; i < 128; i++)
  464. keyArray[i] = 0;
  465.  
  466. }
  467.  
  468. public final void windowActivated(WindowEvent windowevent)
  469. {
  470. }
  471.  
  472. public final void windowClosed(WindowEvent windowevent)
  473. {
  474. }
  475.  
  476. public final void windowClosing(WindowEvent windowevent)
  477. {
  478. destroy();
  479. }
  480.  
  481. public final void windowDeactivated(WindowEvent windowevent)
  482. {
  483. }
  484.  
  485. public final void windowDeiconified(WindowEvent windowevent)
  486. {
  487. }
  488.  
  489. public final void windowIconified(WindowEvent windowevent)
  490. {
  491. }
  492.  
  493. public final void windowOpened(WindowEvent windowevent)
  494. {
  495. }
  496.  
  497. void startUp()
  498. {
  499. }
  500.  
  501. void processGameLoop()
  502. {
  503. }
  504.  
  505. void cleanUpForQuit()
  506. {
  507. }
  508.  
  509. void processDrawing()
  510. {
  511. }
  512.  
  513. void raiseWelcomeScreen()
  514. {
  515. }
  516.  
  517. Component getGameComponent()
  518. {
  519. if(gameFrame != null)
  520. return gameFrame;
  521. else
  522. return this;
  523. }
  524.  
  525. public void startRunnable(Runnable runnable, int priority)
  526. {
  527. Thread thread = new Thread(runnable);
  528. thread.start();
  529. thread.setPriority(priority);
  530. }
  531.  
  532. void drawLoadingText(int i, String s)
  533. {
  534. while(graphics == null)
  535. {
  536. graphics = getGameComponent().getGraphics();
  537. try
  538. {
  539. getGameComponent().repaint();
  540. }
  541. catch(Exception _ex) { }
  542. try
  543. {
  544. Thread.sleep(1000L);
  545. }
  546. catch(Exception _ex) { }
  547. }
  548. Font font = new Font("Helvetica", 1, 13);
  549. FontMetrics fontmetrics = getGameComponent().getFontMetrics(font);
  550. Font font1 = new Font("Helvetica", 0, 13);
  551. getGameComponent().getFontMetrics(font1);
  552. if(shouldClearScreen)
  553. {
  554. graphics.setColor(Color.black);
  555. graphics.fillRect(0, 0, myWidth, myHeight);
  556. shouldClearScreen = false;
  557. }
  558. Color color = new Color(140, 17, 17);
  559. int j = myHeight / 2 - 18;
  560. graphics.setColor(color);
  561. graphics.drawRect(myWidth / 2 - 152, j, 304, 33);
  562. graphics.fillRect(myWidth / 2 - 150, j + 2, i * 3, 30);
  563. graphics.setColor(Color.black);
  564. graphics.fillRect((myWidth / 2 - 150) + i * 3, j + 2, 300 - i * 3, 30);
  565. graphics.setFont(font);
  566. graphics.setColor(Color.white);
  567. graphics.drawString("RuneScape is loading - please wait...", (myWidth -
  568. fontmetrics.stringWidth("RuneScape is loading - please wait...")) / 2, j - 11);
  569. graphics.drawString(s, (myWidth - fontmetrics.stringWidth(s)) / 2, j + 22);
  570. }
  571.  
  572. RSApplet()
  573. {
  574. delayTime = 20;
  575. minDelay = 1;
  576. aLongArray7 = new long[10];
  577. shouldDebug = false;
  578. shouldClearScreen = true;
  579. awtFocus = true;
  580. keyArray = new int[128];
  581. charQueue = new int[128];
  582. }
  583.  
  584. private int anInt4;
  585. private int delayTime;
  586. int minDelay;
  587. private final long[] aLongArray7;
  588. int fps;
  589. boolean shouldDebug;
  590. int myWidth;
  591. int myHeight;
  592. Graphics graphics;
  593. RSImageProducer fullGameScreen;
  594. RSFrame gameFrame;
  595. private boolean shouldClearScreen;
  596. boolean awtFocus;
  597. int idleTime;
  598. int clickMode2;
  599. public int mouseX;
  600. public int mouseY;
  601. private int clickMode1;
  602. private int clickX;
  603. public static int ClientSize;
  604. public static int ClientWidth, ClientHeight;
  605. private int clickY;
  606. private long clickTime;
  607. int clickMode3;
  608. int saveClickX;
  609. int saveClickY;
  610. long aLong29;
  611. final int[] keyArray;
  612. private final int[] charQueue;
  613. private int readIndex;
  614. private int writeIndex;
  615. public static int anInt34;
  616. }
Advertisement
Add Comment
Please, Sign In to add comment