Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.86 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.Socket;
  3. import java.util.zip.CRC32;
  4. import java.util.zip.GZIPInputStream;
  5. import sign.signlink;
  6.  
  7. public final class OnDemandFetcher extends OnDemandFetcherParent implements Runnable {
  8.  
  9. private boolean crcMatches(int j, byte abyte0[])
  10. {
  11. System.out.println("Checking CRC "+j+"");
  12. if(abyte0 == null || abyte0.length < 2)
  13. return false;
  14. int k = abyte0.length - 2;
  15. crc32.reset();
  16. crc32.update(abyte0, 0, k);
  17. int i1 = (int) crc32.getValue();
  18. if(i1 != j)
  19. System.out.println("CRC Does not Match");
  20. return i1 == j;
  21. }
  22.  
  23. private void readData()
  24. {
  25. try
  26. {
  27. int j = inputStream.available();
  28. if(expectedSize == 0 && j >= 6)
  29. {
  30. waiting = true;
  31. for(int k = 0; k < 6; k += inputStream.read(ioBuffer, k, 6 - k));
  32. int l = ioBuffer[0] & 0xff;
  33. int j1 = ((ioBuffer[1] & 0xff) << 8) + (ioBuffer[2] & 0xff);
  34. int l1 = ((ioBuffer[3] & 0xff) << 8) + (ioBuffer[4] & 0xff);
  35. int i2 = ioBuffer[5] & 0xff;
  36. current = null;
  37. for(OnDemandData onDemandData = (OnDemandData) requested.reverseGetFirst(); onDemandData != null; onDemandData = (OnDemandData) requested.reverseGetNext())
  38. {
  39. if(onDemandData.dataType == l && onDemandData.ID == j1)
  40. current = onDemandData;
  41. if(current != null)
  42. onDemandData.loopCycle = 0;
  43. }
  44.  
  45. if(current != null)
  46. {
  47. loopCycle = 0;
  48. if(l1 == 0)
  49. {
  50. signlink.reporterror("Rej: " + l + "," + j1);
  51. current.buffer = null;
  52. if(current.incomplete)
  53. synchronized(aClass19_1358)
  54. {
  55. aClass19_1358.insertHead(current);
  56. }
  57. else
  58. current.unlink();
  59. current = null;
  60. } else
  61. {
  62. if(current.buffer == null && i2 == 0)
  63. current.buffer = new byte[l1];
  64. if(current.buffer == null && i2 != 0)
  65. throw new IOException("missing start of file");
  66. }
  67. }
  68. completedSize = i2 * 500;
  69. expectedSize = 500;
  70. if(expectedSize > l1 - i2 * 500)
  71. expectedSize = l1 - i2 * 500;
  72. }
  73. if(expectedSize > 0 && j >= expectedSize)
  74. {
  75. waiting = true;
  76. byte abyte0[] = ioBuffer;
  77. int i1 = 0;
  78. if(current != null)
  79. {
  80. abyte0 = current.buffer;
  81. i1 = completedSize;
  82. }
  83. for(int k1 = 0; k1 < expectedSize; k1 += inputStream.read(abyte0, k1 + i1, expectedSize - k1));
  84. if(expectedSize + completedSize >= abyte0.length && current != null)
  85. {
  86. if(clientInstance.decompressors[0] != null)
  87. clientInstance.decompressors[current.dataType + 1].method234(abyte0.length, abyte0, current.ID);
  88. if(!current.incomplete && current.dataType == 3)
  89. {
  90. current.incomplete = true;
  91. current.dataType = 93;
  92. }
  93. if(current.incomplete)
  94. synchronized(aClass19_1358)
  95. {
  96. aClass19_1358.insertHead(current);
  97. }
  98. else
  99. current.unlink();
  100. }
  101. expectedSize = 0;
  102. }
  103. }
  104. catch(IOException ioexception)
  105. {
  106. try
  107. {
  108. socket.close();
  109. }
  110. catch(Exception _ex) { }
  111. socket = null;
  112. inputStream = null;
  113. outputStream = null;
  114. expectedSize = 0;
  115. }
  116. }
  117.  
  118. public void start(StreamLoader streamLoader, client client1) {
  119. String as1[] = {
  120. "model_crc", "anim_crc", "midi_crc", "map_crc"
  121. };
  122. for(int k = 0; k < 4; k++)
  123. {
  124. byte abyte1[] = streamLoader.getDataForName(as1[k]);
  125. //byte abyte1[] = FileOperations.ReadFile("./CRC/"+as1[k]+"");
  126. int i1 = abyte1.length / 4;
  127. Stream stream_1 = new Stream(abyte1);
  128. crcs[k] = new int[i1];
  129. for(int l1 = 0; l1 < i1; l1++)
  130. crcs[k][l1] = stream_1.readDWord();
  131.  
  132. }
  133.  
  134. byte[] abyte2 = streamLoader.getDataForName("map_index");
  135. Stream stream2 = new Stream(abyte2);
  136. int j1 = abyte2.length / 6;
  137. mapIndices1 = new int[j1];
  138. mapIndices2 = new int[j1];
  139. mapIndices3 = new int[j1];
  140. for(int i2 = 0; i2 < j1; i2++) {
  141. mapIndices1[i2] = stream2.readUnsignedWord();
  142. mapIndices2[i2] = stream2.readUnsignedWord();
  143. mapIndices3[i2] = stream2.readUnsignedWord();
  144. }
  145.  
  146. abyte2 = streamLoader.getDataForName("midi_index");
  147. stream2 = new Stream(abyte2);
  148. j1 = abyte2.length;
  149. anIntArray1348 = new int[j1];
  150. for(int k2 = 0; k2 < j1; k2++)
  151. anIntArray1348[k2] = stream2.readUnsignedByte();
  152.  
  153. clientInstance = client1;
  154. running = true;
  155. clientInstance.startRunnable(this, 2);
  156. }
  157.  
  158. public int getNodeCount()
  159. {
  160. synchronized(nodeSubList)
  161. {
  162. return nodeSubList.getNodeCount();
  163. }
  164. }
  165.  
  166. public void disable()
  167. {
  168. running = false;
  169. }
  170.  
  171. public void method554(boolean flag)
  172. {
  173. int j = mapIndices1.length;
  174. for(int k = 0; k < j; k++)
  175. if(flag || mapIndices4[k] != 0)
  176. {
  177. method563((byte)2, 3, mapIndices3[k]);
  178. method563((byte)2, 3, mapIndices2[k]);
  179. }
  180.  
  181. }
  182.  
  183. public int getModelCount()
  184. {
  185. return 56929;
  186. }
  187.  
  188. private void closeRequest(OnDemandData onDemandData)
  189. {
  190. try
  191. {
  192. if(socket == null)
  193. {
  194. long l = System.currentTimeMillis();
  195. if(l - openSocketTime < 4000L)
  196. return;
  197. openSocketTime = l;
  198. socket = clientInstance.openSocket(43594 + client.portOff);
  199. inputStream = socket.getInputStream();
  200. outputStream = socket.getOutputStream();
  201. outputStream.write(15);
  202. for(int j = 0; j < 8; j++)
  203. inputStream.read();
  204.  
  205. loopCycle = 0;
  206. }
  207. ioBuffer[0] = (byte)onDemandData.dataType;
  208. ioBuffer[1] = (byte)(onDemandData.ID >> 8);
  209. ioBuffer[2] = (byte)onDemandData.ID;
  210. if(onDemandData.incomplete)
  211. ioBuffer[3] = 2;
  212. else
  213. if(!clientInstance.loggedIn)
  214. ioBuffer[3] = 1;
  215. else
  216. ioBuffer[3] = 0;
  217. outputStream.write(ioBuffer, 0, 4);
  218. writeLoopCycle = 0;
  219. anInt1349 = -10000;
  220. return;
  221. }
  222. catch(IOException ioexception) { }
  223. try
  224. {
  225. socket.close();
  226. }
  227. catch(Exception _ex) { }
  228. socket = null;
  229. inputStream = null;
  230. outputStream = null;
  231. expectedSize = 0;
  232. anInt1349++;
  233. }
  234.  
  235. public int getAnimCount()
  236. {
  237. return 3229;
  238. }
  239.  
  240. public void method558(int i, int j)
  241. {
  242. if(i < 0 || j < 0)
  243. return;
  244. synchronized(nodeSubList)
  245. {
  246. for(OnDemandData onDemandData = (OnDemandData) nodeSubList.reverseGetFirst(); onDemandData != null; onDemandData = (OnDemandData) nodeSubList.reverseGetNext())
  247. if(onDemandData.dataType == i && onDemandData.ID == j)
  248. return;
  249.  
  250. OnDemandData onDemandData_1 = new OnDemandData();
  251. onDemandData_1.dataType = i;
  252. onDemandData_1.ID = j;
  253. onDemandData_1.incomplete = true;
  254. synchronized(aClass19_1370)
  255. {
  256. aClass19_1370.insertHead(onDemandData_1);
  257. }
  258. nodeSubList.insertHead(onDemandData_1);
  259. }
  260. }
  261.  
  262. public void run()
  263. {
  264. try
  265. {
  266. while(running)
  267. {
  268. onDemandCycle++;
  269. int i = 20;
  270. if(anInt1332 == 0 && clientInstance.decompressors[0] != null)
  271. i = 50;
  272. try
  273. {
  274. Thread.sleep(i);
  275. }
  276. catch(Exception _ex) { }
  277. waiting = true;
  278. for(int j = 0; j < 100; j++)
  279. {
  280. if(!waiting)
  281. break;
  282. waiting = false;
  283. checkReceived();
  284. handleFailed();
  285. if(uncompletedCount == 0 && j >= 5)
  286. break;
  287. method568();
  288. if(inputStream != null)
  289. readData();
  290. }
  291.  
  292. boolean flag = false;
  293. for(OnDemandData onDemandData = (OnDemandData) requested.reverseGetFirst(); onDemandData != null; onDemandData = (OnDemandData) requested.reverseGetNext())
  294. if(onDemandData.incomplete)
  295. {
  296. flag = true;
  297. onDemandData.loopCycle++;
  298. if(onDemandData.loopCycle > 50)
  299. {
  300. onDemandData.loopCycle = 0;
  301. closeRequest(onDemandData);
  302. }
  303. }
  304.  
  305. if(!flag)
  306. {
  307. for(OnDemandData onDemandData_1 = (OnDemandData) requested.reverseGetFirst(); onDemandData_1 != null; onDemandData_1 = (OnDemandData) requested.reverseGetNext())
  308. {
  309. flag = true;
  310. onDemandData_1.loopCycle++;
  311. if(onDemandData_1.loopCycle > 50)
  312. {
  313. onDemandData_1.loopCycle = 0;
  314. closeRequest(onDemandData_1);
  315. }
  316. }
  317.  
  318. }
  319. if(flag)
  320. {
  321. loopCycle++;
  322. if(loopCycle > 750)
  323. {
  324. try
  325. {
  326. socket.close();
  327. }
  328. catch(Exception _ex) { }
  329. socket = null;
  330. inputStream = null;
  331. outputStream = null;
  332. expectedSize = 0;
  333. }
  334. } else
  335. {
  336. loopCycle = 0;
  337. statusString = "";
  338. }
  339. if(clientInstance.loggedIn && socket != null && outputStream != null && (anInt1332 > 0 || clientInstance.decompressors[0] == null))
  340. {
  341. writeLoopCycle++;
  342. if(writeLoopCycle > 500)
  343. {
  344. writeLoopCycle = 0;
  345. ioBuffer[0] = 0;
  346. ioBuffer[1] = 0;
  347. ioBuffer[2] = 0;
  348. ioBuffer[3] = 10;
  349. try
  350. {
  351. outputStream.write(ioBuffer, 0, 4);
  352. }
  353. catch(IOException _ex)
  354. {
  355. loopCycle = 5000;
  356. }
  357. }
  358. }
  359. }
  360. }
  361. catch(Exception exception)
  362. {
  363. signlink.reporterror("od_ex " + exception.getMessage());
  364. exception.printStackTrace();
  365. }
  366. }
  367.  
  368. public void method560(int i, int j)
  369. {
  370. if(clientInstance.decompressors[0] == null)
  371. return;
  372. if(fileStatus[j][i] == 0)
  373. return;
  374. if(anInt1332 == 0)
  375. return;
  376. OnDemandData onDemandData = new OnDemandData();
  377. onDemandData.dataType = j;
  378. onDemandData.ID = i;
  379. onDemandData.incomplete = false;
  380. synchronized(aClass19_1344)
  381. {
  382. aClass19_1344.insertHead(onDemandData);
  383. }
  384. }
  385.  
  386. public OnDemandData getNextNode()
  387. {
  388. OnDemandData onDemandData;
  389. synchronized(aClass19_1358)
  390. {
  391. onDemandData = (OnDemandData)aClass19_1358.popHead();
  392. }
  393. if(onDemandData == null)
  394. return null;
  395. synchronized(nodeSubList)
  396. {
  397. onDemandData.unlinkSub();
  398. }
  399. if(onDemandData.buffer == null)
  400. return onDemandData;
  401. int i = 0;
  402. try
  403. {
  404. GZIPInputStream gzipinputstream = new GZIPInputStream(new ByteArrayInputStream(onDemandData.buffer));
  405. do
  406. {
  407. if(i == gzipInputBuffer.length)
  408. throw new RuntimeException("buffer overflow!");
  409. int k = gzipinputstream.read(gzipInputBuffer, i, gzipInputBuffer.length - i);
  410. if(k == -1)
  411. break;
  412. i += k;
  413. } while(true);
  414. }
  415. catch(IOException _ex)
  416. {
  417. throw new RuntimeException("error unzipping");
  418. }
  419. onDemandData.buffer = new byte[i];
  420. System.arraycopy(gzipInputBuffer, 0, onDemandData.buffer, 0, i);
  421.  
  422. return onDemandData;
  423. }
  424.  
  425. public int method562(int i, int k, int l)
  426. {
  427. int i1 = (l << 8) + k;
  428. for(int j1 = 0; j1 < mapIndices1.length; j1++)
  429. {
  430. if(mapIndices1[j1] == i1)
  431. {
  432. if(i == 0)
  433. return mapIndices2[j1];
  434. else
  435. return mapIndices3[j1];
  436. }
  437. }
  438. return -1;
  439. }
  440.  
  441. public void method548(int i)
  442. {
  443. method558(0, i);
  444. }
  445.  
  446. public void method563(byte byte0, int i, int j)
  447. {
  448. if(clientInstance.decompressors[0] == null)
  449. return;
  450. byte abyte0[] = clientInstance.decompressors[i + 1].decompress(j);
  451. if(crcMatches(crcs[i][j], abyte0))
  452. return;
  453. fileStatus[i][j] = byte0;
  454. if(byte0 > anInt1332)
  455. anInt1332 = byte0;
  456. totalFiles++;
  457. }
  458.  
  459. public boolean method564(int i)
  460. {
  461. for(int k = 0; k < mapIndices1.length; k++)
  462. if(mapIndices3[k] == i)
  463. return true;
  464. return false;
  465. }
  466.  
  467. private void handleFailed()
  468. {
  469. uncompletedCount = 0;
  470. completedCount = 0;
  471. for(OnDemandData onDemandData = (OnDemandData) requested.reverseGetFirst(); onDemandData != null; onDemandData = (OnDemandData) requested.reverseGetNext())
  472. if(onDemandData.incomplete)
  473. uncompletedCount++;
  474. else
  475. completedCount++;
  476.  
  477. while(uncompletedCount < 10)
  478. {
  479. OnDemandData onDemandData_1 = (OnDemandData)aClass19_1368.popHead();
  480. if(onDemandData_1 == null)
  481. break;
  482. if(fileStatus[onDemandData_1.dataType][onDemandData_1.ID] != 0)
  483. filesLoaded++;
  484. fileStatus[onDemandData_1.dataType][onDemandData_1.ID] = 0;
  485. requested.insertHead(onDemandData_1);
  486. uncompletedCount++;
  487. closeRequest(onDemandData_1);
  488. waiting = true;
  489. }
  490. }
  491.  
  492. public void method566()
  493. {
  494. synchronized(aClass19_1344)
  495. {
  496. aClass19_1344.removeAll();
  497. }
  498. }
  499.  
  500. private void checkReceived()
  501. {
  502. OnDemandData onDemandData;
  503. synchronized(aClass19_1370)
  504. {
  505. onDemandData = (OnDemandData)aClass19_1370.popHead();
  506. }
  507. while(onDemandData != null)
  508. {
  509. waiting = true;
  510. byte abyte0[] = null;
  511. if(clientInstance.decompressors[0] != null)
  512. abyte0 = clientInstance.decompressors[onDemandData.dataType + 1].decompress(onDemandData.ID);
  513. if(!crcMatches(crcs[onDemandData.dataType][onDemandData.ID], abyte0))
  514. abyte0 = null;
  515. synchronized(aClass19_1370)
  516. {
  517. if(abyte0 == null)
  518. {
  519. aClass19_1368.insertHead(onDemandData);
  520. } else
  521. {
  522. onDemandData.buffer = abyte0;
  523. synchronized(aClass19_1358)
  524. {
  525. aClass19_1358.insertHead(onDemandData);
  526. }
  527. }
  528. onDemandData = (OnDemandData)aClass19_1370.popHead();
  529. }
  530. }
  531. }
  532.  
  533. public void method568()
  534. {
  535. while(uncompletedCount == 0 && completedCount < 10)
  536. {
  537. if(anInt1332 == 0)
  538. break;
  539. OnDemandData onDemandData;
  540. synchronized(aClass19_1344)
  541. {
  542. onDemandData = (OnDemandData)aClass19_1344.popHead();
  543. }
  544. while(onDemandData != null)
  545. {
  546. if(fileStatus[onDemandData.dataType][onDemandData.ID] != 0)
  547. {
  548. fileStatus[onDemandData.dataType][onDemandData.ID] = 0;
  549. requested.insertHead(onDemandData);
  550. closeRequest(onDemandData);
  551. waiting = true;
  552. if(filesLoaded < totalFiles)
  553. filesLoaded++;
  554. statusString = "Loading extra files - " + (filesLoaded * 100) / totalFiles + "%";
  555. completedCount++;
  556. if(completedCount == 10)
  557. return;
  558. }
  559. synchronized(aClass19_1344)
  560. {
  561. onDemandData = (OnDemandData)aClass19_1344.popHead();
  562. }
  563. }
  564. for(int j = 0; j < 4; j++)
  565. {
  566. byte abyte0[] = fileStatus[j];
  567. int k = abyte0.length;
  568. for(int l = 0; l < k; l++)
  569. if(abyte0[l] == anInt1332)
  570. {
  571. abyte0[l] = 0;
  572. OnDemandData onDemandData_1 = new OnDemandData();
  573. onDemandData_1.dataType = j;
  574. onDemandData_1.ID = l;
  575. onDemandData_1.incomplete = false;
  576. requested.insertHead(onDemandData_1);
  577. closeRequest(onDemandData_1);
  578. waiting = true;
  579. if(filesLoaded < totalFiles)
  580. filesLoaded++;
  581. statusString = "Loading extra files - " + (filesLoaded * 100) / totalFiles + "%";
  582. completedCount++;
  583. if(completedCount == 10)
  584. return;
  585. }
  586.  
  587. }
  588.  
  589. anInt1332--;
  590. }
  591. }
  592.  
  593. public void crcPack(int index, int index_length) {
  594. try {
  595. DataOutputStream crc_output = new DataOutputStream(new FileOutputStream("./CRC/"+index+"_crc"));
  596. for(int j = 0; j < index_length + 1; j++) {
  597. byte abyte0[] = clientInstance.decompressors[index].decompress(j); // grabs the data from the cache
  598. if(abyte0 != null) {
  599. int k = abyte0.length - 2;
  600. crc32.reset();
  601. crc32.update(abyte0, 0, k);
  602. int crc = (int) crc32.getValue();
  603. System.out.println("FileID: "+j+" CRC: "+crc+"");
  604. crc_output.writeInt(crc); // writes the crc value
  605. } else {
  606. crc_output.writeInt(0);
  607. }
  608. }
  609. crc_output.close();
  610. } catch(Exception e) {
  611. e.printStackTrace();
  612. }
  613. }
  614.  
  615. public boolean method569(int i)
  616. {
  617. return anIntArray1348[i] == 1;
  618. }
  619.  
  620. public int getVersionCount(int j) {
  621. if(j == 0) {
  622. return 56929;
  623. } else if(j == 1) {
  624. return 1000;
  625. } else {
  626. return 0;
  627. }
  628. }
  629.  
  630.  
  631. public int getModelIndex(int i) {
  632. return modelIndices[i] & 0xff;
  633. }
  634.  
  635. public OnDemandFetcher()
  636. {
  637. requested = new NodeList();
  638. statusString = "";
  639. crc32 = new CRC32();
  640. ioBuffer = new byte[500];
  641. fileStatus = new byte[4][];
  642. aClass19_1344 = new NodeList();
  643. running = true;
  644. waiting = false;
  645. aClass19_1358 = new NodeList();
  646. gzipInputBuffer = new byte[0x71868];
  647. nodeSubList = new NodeSubList();
  648. versions = new int[4][];
  649. crcs = new int[4][];
  650. aClass19_1368 = new NodeList();
  651. aClass19_1370 = new NodeList();
  652. }
  653.  
  654. public int totalFiles;
  655. public final NodeList requested;
  656. public int anInt1332;
  657. public String statusString;
  658. public int writeLoopCycle;
  659. public long openSocketTime;
  660. public int[] mapIndices3;
  661. public final CRC32 crc32;
  662. public final byte[] ioBuffer;
  663. public int onDemandCycle;
  664. public final byte[][] fileStatus;
  665. public client clientInstance;
  666. public final NodeList aClass19_1344;
  667. public int completedSize;
  668. public int expectedSize;
  669. public int[] anIntArray1348;
  670. public int anInt1349;
  671. public int[] mapIndices2;
  672. public int filesLoaded;
  673. public boolean running;
  674. public OutputStream outputStream;
  675. public int[] mapIndices4;
  676. public boolean waiting;
  677. public final NodeList aClass19_1358;
  678. public final byte[] gzipInputBuffer;
  679. public int[] anIntArray1360;
  680. public final NodeSubList nodeSubList;
  681. public InputStream inputStream;
  682. public Socket socket;
  683. public final int[][] crcs;
  684. public int uncompletedCount;
  685. public int completedCount;
  686. public final NodeList aClass19_1368;
  687. public OnDemandData current;
  688. public final NodeList aClass19_1370;
  689. public int[] mapIndices1;
  690. public byte[] modelIndices;
  691. public int loopCycle;
  692. public final int[][] versions;
  693. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement