diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..427cfa4 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/317.iml b/317.iml index 093c285..fa4dc61 100644 --- a/317.iml +++ b/317.iml @@ -11,8 +11,8 @@ - - - + + + \ No newline at end of file diff --git a/src/main/java/BZip2.java b/src/main/java/BZip2.java index 3d73136..89d2072 100644 --- a/src/main/java/BZip2.java +++ b/src/main/java/BZip2.java @@ -1,4 +1,5 @@ import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; +import org.apache.commons.compress.utils.IOUtils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -30,19 +31,12 @@ public class BZip2 extends InputStream { tmp = new ByteArrayOutputStream(); } - BZip2CompressorInputStream in = new BZip2CompressorInputStream(new BZip2(src, off, len)); - - byte[] buf = new byte[2048]; - int read; - int written = 0; - - while ((read = in.read(buf)) != -1) { + try(BZip2CompressorInputStream in = new BZip2CompressorInputStream(new BZip2(src, off, len))) { if (tmp != null) { - tmp.write(buf, 0, read); + IOUtils.copy(in, tmp); } else { - System.arraycopy(buf, 0, dst, written, read); + IOUtils.readFully(in, dst); } - written += read; } if (tmp != null) { diff --git a/src/main/java/Game.java b/src/main/java/Game.java index b7645b5..d3c9a2b 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -155,6 +155,7 @@ public class Game extends GameShell { SceneBuilder.lowmem = true; LocType.lowmem = true; } + public final int[] anIntArray1177 = {0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3}; public final int[] anIntArray864 = new int[SkillConstants.anInt733]; public final int[] anIntArray873 = new int[5]; @@ -237,7 +238,7 @@ public class Game extends GameShell { public int anInt860; public int anInt861; public int anInt862; - public int anInt863; + public int rights; public Image8 aImage_865; public Image8 aImage_866; public Image8 aImage_867; @@ -437,7 +438,7 @@ public class Game extends GameShell { public Image8[] aImageArray1152; public boolean aBoolean1153 = false; public int anInt1154; - public boolean aBoolean1157 = false; + public boolean ingame = false; public boolean aBoolean1158 = false; public boolean sceneInstanced = false; public boolean aBoolean1160 = false; @@ -688,7 +689,7 @@ public class Game extends GameShell { ondemand = new OnDemand(); ondemand.load(archiveVersionlist, this); - SeqFrame.init(ondemand.method557()); + SeqFrame.init(ondemand.getSeqFrameCount()); Model.init(ondemand.getFileCount(0), ondemand); if (!lowmem) { @@ -831,7 +832,7 @@ public class Game extends GameShell { byte0 = 3; } if (byte0 != 0) { - ondemand.method563(byte0, 0, k2); + ondemand.prefetch(byte0, 0, k2); } } ondemand.prefetchMaps(members); @@ -839,7 +840,7 @@ public class Game extends GameShell { int l = ondemand.getFileCount(2); for (int i3 = 1; i3 < l; i3++) { if (ondemand.method569(i3)) { - ondemand.method563((byte) 1, 2, i3); + ondemand.prefetch((byte) 1, 2, i3); } } } @@ -1050,7 +1051,7 @@ public class Game extends GameShell { return; } loopCycle++; - if (!aBoolean1157) { + if (!ingame) { method140(); } else { method62(); @@ -1071,7 +1072,7 @@ public class Game extends GameShell { method15(); if (aMouseRecorder_879 != null) { aMouseRecorder_879.aBoolean808 = false; - aMouseRecorder_879 = null; + aMouseRecorder_879 = null; } if (ondemand != null) { ondemand.stop(); @@ -1199,7 +1200,7 @@ public class Game extends GameShell { return; } drawCycle++; - if (!aBoolean1157) { + if (!ingame) { method135(false); } else { method102(); @@ -2837,7 +2838,7 @@ public class Game extends GameShell { } catch (Exception ignored) { } connection = null; - aBoolean1157 = false; + ingame = false; anInt833 = 0; aString1173 = ""; aString1174 = ""; @@ -3567,7 +3568,7 @@ public class Game extends GameShell { break; } } - if (!aBoolean1157) { + if (!ingame) { return; } synchronized (aMouseRecorder_879.lock) { @@ -4082,10 +4083,10 @@ public class Game extends GameShell { anInt1021 = 0; anInt1261 = 0; Connection connection = this.connection; - aBoolean1157 = false; + ingame = false; anInt1038 = 0; method84(aString1173, aString1174, true); - if (!aBoolean1157) { + if (!ingame) { method44(); } try { @@ -5066,11 +5067,17 @@ public class Game extends GameShell { System.out.println("flame-cycle:" + flameCycle); if (ondemand != null) { System.out.println("Od-cycle:" + ondemand.cycle); + System.out.println("Od-remaining:" + ondemand.remaining()); + for (OnDemandRequest request : ondemand.requests) { + System.out.println(request); + } } System.out.println("loop-cycle:" + loopCycle); System.out.println("draw-cycle:" + drawCycle); System.out.println("ptype:" + ptype); System.out.println("psize:" + psize); + System.out.println("scene-state:" + sceneState); + System.out.println("draw-state:" + method54()); if (connection != null) { connection.method272(); } @@ -5188,7 +5195,7 @@ public class Game extends GameShell { aBoolean1223 = true; } if (((j == 13) || (j == 10)) && (aString887.length() > 0)) { - if (anInt863 == 2) { + if (rights == 0) { if (aString887.equals("::clientdrop")) { method68(); } @@ -5197,7 +5204,7 @@ public class Game extends GameShell { } if (aString887.equals("::prefetchmusic")) { for (int j1 = 0; j1 < ondemand.getFileCount(2); j1++) { - ondemand.method563((byte) 1, 2, j1); + ondemand.prefetch((byte) 1, 2, j1); } } if (aString887.equals("::fpson")) { @@ -5293,9 +5300,9 @@ public class Game extends GameShell { aPlayer_1126.anInt1513 = j2; aPlayer_1126.anInt1531 = i3; aPlayer_1126.anInt1535 = 150; - if (anInt863 == 2) { + if (rights == 2) { method77(2, "@cr2@" + aPlayer_1126.aString1703, aPlayer_1126.aString1506); - } else if (anInt863 == 1) { + } else if (rights == 1) { method77(2, "@cr1@" + aPlayer_1126.aString1703, aPlayer_1126.aString1506); } else { method77(2, aPlayer_1126.aString1703, aPlayer_1126.aString1506); @@ -5339,7 +5346,7 @@ public class Game extends GameShell { } if (((j1 == 1) || (j1 == 2)) && ((j1 == 1) || (anInt1287 == 0) || ((anInt1287 == 1) && method109(s)))) { if ((j > (k1 - 14)) && (j <= k1) && !s.equals(aPlayer_1126.aString1703)) { - if (anInt863 >= 1) { + if (rights >= 1) { aStringArray1199[anInt1133] = "Report abuse @whi@" + s; anIntArray1093[anInt1133] = 606; anInt1133++; @@ -5355,7 +5362,7 @@ public class Game extends GameShell { } if (((j1 == 3) || (j1 == 7)) && (anInt1195 == 0) && ((j1 == 7) || (anInt845 == 0) || ((anInt845 == 1) && method109(s)))) { if ((j > (k1 - 14)) && (j <= k1)) { - if (anInt863 >= 1) { + if (rights >= 1) { aStringArray1199[anInt1133] = "Report abuse @whi@" + s; anIntArray1093[anInt1133] = 606; anInt1133++; @@ -5565,7 +5572,7 @@ public class Game extends GameShell { return; } if (j == 613) { - if (anInt863 >= 1) { + if (rights >= 1) { if (aBoolean1158) { component.anInt232 = 0xff0000; component.aString248 = "Moderator option: Mute player for 48 hours: "; @@ -6015,14 +6022,14 @@ public class Game extends GameShell { return; } if (k == 2) { - anInt863 = connection.method268(); + rights = connection.method268(); aBoolean1205 = connection.method268() == 1; aLong1220 = 0L; anInt1022 = 0; aMouseRecorder_879.anInt810 = 0; super.aBoolean17 = true; aBoolean954 = true; - aBoolean1157 = true; + ingame = true; aBuffer_1192.position = 0; in.position = 0; ptype = -1; @@ -6162,7 +6169,7 @@ public class Game extends GameShell { return; } if (k == 15) { - aBoolean1157 = true; + ingame = true; aBuffer_1192.position = 0; in.position = 0; ptype = -1; @@ -8771,7 +8778,7 @@ public class Game extends GameShell { i1 = 450; } if (super.anInt20 < (4 + i1)) { - if (anInt863 >= 1) { + if (rights >= 1) { aStringArray1199[anInt1133] = "Report abuse @whi@" + s; anIntArray1093[anInt1133] = 2606; anInt1133++; @@ -9010,7 +9017,7 @@ public class Game extends GameShell { char c1 = '\310'; if (anInt833 == 0) { int i = (c1 / 2) + 80; - fontPlain11.drawStringTaggableCenter(ondemand.aString1333, c / 2, i, 0x75a9a9, true); + fontPlain11.drawStringTaggableCenter(ondemand.message, c / 2, i, 0x75a9a9, true); i = (c1 / 2) - 20; fontBold12.drawStringTaggableCenter("Welcome to RuneScape", c / 2, i, 0xffff00, true); int l = (c / 2) - 80; @@ -9465,7 +9472,7 @@ public class Game extends GameShell { if ((super.mousePressButton == 1) && (super.mousePressX >= (i1 - 75)) && (super.mousePressX <= (i1 + 75)) && (super.mousePressY >= (k1 - 20)) && (super.mousePressY <= (k1 + 20))) { anInt1038 = 0; method84(aString1173, aString1174, false); - if (aBoolean1157) { + if (ingame) { return; } } diff --git a/src/main/java/OnDemand.java b/src/main/java/OnDemand.java index c23fdd9..244cce9 100644 --- a/src/main/java/OnDemand.java +++ b/src/main/java/OnDemand.java @@ -9,150 +9,167 @@ import java.util.zip.GZIPInputStream; public class OnDemand implements Runnable { - public final DoublyLinkedList aList_1331 = new DoublyLinkedList(); + public final DoublyLinkedList pending = new DoublyLinkedList(); public final CRC32 crc32 = new CRC32(); - public final byte[] aByteArray1339 = new byte[500]; - public final byte[][] storeFilePriority = new byte[4][]; + public final byte[] bbuf = new byte[500]; + public final byte[][] storeFilePriorities = new byte[4][]; public final DoublyLinkedList aList_1344 = new DoublyLinkedList(); - public final DoublyLinkedList aList_1358 = new DoublyLinkedList(); + public final DoublyLinkedList completed = new DoublyLinkedList(); public final byte[] aByteArray1359 = new byte[65000]; - private final Object lock = new Object(); - private final LinkedList requests = new LinkedList<>(); + public final LinkedList requests = new LinkedList<>(); public final int[][] storeFileVersions = new int[4][]; public final int[][] storeFileChecksums = new int[4][]; public final DoublyLinkedList aList_1368 = new DoublyLinkedList(); public final DoublyLinkedList aList_1370 = new DoublyLinkedList(); - public int anInt1330; + private final Object lock = new Object(); + public int totalPrefetchFiles; public int topPriority; - public String aString1333 = ""; - public int anInt1334; - public long aLong1335; + public String message = ""; + public int heartbeatCycle; + public long socketOpenTime; public int[] mapLocFile; public int cycle; public Game game; - public int anInt1346; - public int anInt1347; + public int partOffset; + public int partAvailable; public int[] midiIndex; public int anInt1349; public int[] mapLandFile; - public int anInt1351; + public int loadedPretechFiles; public boolean running = true; - public OutputStream anOutputStream1354; + public OutputStream out; public int[] mapPrefetched; public boolean aBoolean1357 = false; public int[] animIndex; - public InputStream anInputStream1362; - public Socket aSocket1363; - public int anInt1366; - public int anInt1367; - public OnDemandRequest aRequest_1369; + public InputStream in; + public Socket socket; + public int importantCount; + public int requestCount; + public OnDemandRequest current; public int[] mapIndex; public byte[] modelIndex; - public int anInt1373; + public int waitCycles; public OnDemand() { } - public boolean method549(int i, int j, byte[] abyte0) { - if ((abyte0 == null) || (abyte0.length < 2)) { + public boolean validate(int version, int crc, byte[] src) { + if ((src == null) || (src.length < 2)) { return false; } - int k = abyte0.length - 2; - int l = ((abyte0[k] & 0xff) << 8) + (abyte0[k + 1] & 0xff); + int foot = src.length - 2; + int footVersion = ((src[foot] & 0xff) << 8) + (src[foot + 1] & 0xff); crc32.reset(); - crc32.update(abyte0, 0, k); - int i1 = (int) crc32.getValue(); - if (l != i) { + crc32.update(src, 0, foot); + int srcCrc = (int) crc32.getValue(); + if (footVersion != version) { return false; } - return i1 == j; + return srcCrc == crc; } - public void method550() { + public void read() { try { - int j = anInputStream1362.available(); - if ((anInt1347 == 0) && (j >= 6)) { + int available = in.available(); + + if ((partAvailable == 0) && (available >= 6)) { aBoolean1357 = true; - for (int k = 0; k < 6; k += anInputStream1362.read(aByteArray1339, k, 6 - k)) { - } - int l = aByteArray1339[0] & 0xff; - int j1 = ((aByteArray1339[1] & 0xff) << 8) + (aByteArray1339[2] & 0xff); - int l1 = ((aByteArray1339[3] & 0xff) << 8) + (aByteArray1339[4] & 0xff); - int i2 = aByteArray1339[5] & 0xff; - aRequest_1369 = null; - for (OnDemandRequest request = (OnDemandRequest) aList_1331.peekFront(); request != null; request = (OnDemandRequest) aList_1331.prev()) { - if ((request.store == l) && (request.file == j1)) { - aRequest_1369 = request; + + in.read(bbuf, 0, 6); + + int store = bbuf[0] & 0xff; + int file = ((bbuf[1] & 0xff) << 8) + (bbuf[2] & 0xff); + int size = ((bbuf[3] & 0xff) << 8) + (bbuf[4] & 0xff); + int part = bbuf[5] & 0xff; + + current = null; + + for (OnDemandRequest request = (OnDemandRequest) pending.peekFront(); request != null; request = (OnDemandRequest) pending.prev()) { + if ((request.store == store) && (request.file == file)) { + current = request; } - if (aRequest_1369 != null) { - request.anInt1423 = 0; + if (current != null) { + request.cycle = 0; } } - if (aRequest_1369 != null) { - anInt1373 = 0; - if (l1 == 0) { - Signlink.reporterror("Rej: " + l + "," + j1); - aRequest_1369.data = null; - if (aRequest_1369.aBoolean1422) { - synchronized (aList_1358) { - aList_1358.pushBack(aRequest_1369); + + if (current != null) { + waitCycles = 0; + + if (size == 0) { + Signlink.reporterror("Rej: " + store + "," + file); + + current.data = null; + + if (current.important) { + synchronized (completed) { + completed.pushBack(current); } } else { - aRequest_1369.unlink(); + current.unlink(); } - aRequest_1369 = null; + + current = null; } else { - if ((aRequest_1369.data == null) && (i2 == 0)) { - aRequest_1369.data = new byte[l1]; + if ((current.data == null) && (part == 0)) { + current.data = new byte[size]; } - if ((aRequest_1369.data == null) && (i2 != 0)) { + + if (current.data == null) { throw new IOException("missing start of file"); } } } - anInt1346 = i2 * 500; - anInt1347 = 500; - if (anInt1347 > (l1 - (i2 * 500))) { - anInt1347 = l1 - (i2 * 500); + + partOffset = part * 500; + partAvailable = 500; + + if (partAvailable > (size - (part * 500))) { + partAvailable = size - (part * 500); } } - if ((anInt1347 > 0) && (j >= anInt1347)) { + + if ((partAvailable > 0) && (available >= partAvailable)) { aBoolean1357 = true; - byte[] abyte0 = aByteArray1339; - int i1 = 0; - if (aRequest_1369 != null) { - abyte0 = aRequest_1369.data; - i1 = anInt1346; + byte[] dst = bbuf; + int offset = 0; + + if (current != null) { + dst = current.data; + offset = partOffset; } - for (int k1 = 0; k1 < anInt1347; k1 += anInputStream1362.read(abyte0, k1 + i1, anInt1347 - k1)) { - } - if (((anInt1347 + anInt1346) >= abyte0.length) && (aRequest_1369 != null)) { + + in.read(dst, offset, partAvailable); + + if (((partAvailable + partOffset) >= dst.length) && (current != null)) { if (game.filestores[0] != null) { - game.filestores[aRequest_1369.store + 1].write(abyte0, aRequest_1369.file, abyte0.length); + game.filestores[current.store + 1].write(dst, current.file, dst.length); } - if (!aRequest_1369.aBoolean1422 && (aRequest_1369.store == 3)) { - aRequest_1369.aBoolean1422 = true; - aRequest_1369.store = 93; + + if (!current.important && (current.store == 3)) { + current.important = true; + current.store = 93; } - if (aRequest_1369.aBoolean1422) { - synchronized (aList_1358) { - aList_1358.pushBack(aRequest_1369); + + if (current.important) { + synchronized (completed) { + completed.pushBack(current); } } else { - aRequest_1369.unlink(); + current.unlink(); } } - anInt1347 = 0; + partAvailable = 0; } } catch (IOException ioexception) { try { - aSocket1363.close(); + socket.close(); } catch (Exception ignored) { } - aSocket1363 = null; - anInputStream1362 = null; - anOutputStream1354 = null; - anInt1347 = 0; + socket = null; + in = null; + out = null; + partAvailable = 0; } } @@ -166,7 +183,7 @@ public class OnDemand implements Runnable { Buffer buffer = new Buffer(data); storeFileVersions[i] = new int[count]; - storeFilePriority[i] = new byte[count]; + storeFilePriorities[i] = new byte[count]; for (int l = 0; l < count; l++) { storeFileVersions[i][l] = buffer.get2U(); @@ -251,8 +268,8 @@ public class OnDemand implements Runnable { int count = mapIndex.length; for (int i = 0; i < count; i++) { if (members || (mapPrefetched[i] != 0)) { - method563((byte) 2, 3, mapLocFile[i]); - method563((byte) 2, 3, mapLandFile[i]); + prefetch((byte) 2, 3, mapLocFile[i]); + prefetch((byte) 2, 3, mapLandFile[i]); } } } @@ -261,51 +278,55 @@ public class OnDemand implements Runnable { return storeFileVersions[store].length; } - public void method556(OnDemandRequest request) { + public void send(OnDemandRequest request) { try { - if (aSocket1363 == null) { - long l = System.currentTimeMillis(); - if ((l - aLong1335) < 4000L) { + if (socket == null) { + long now = System.currentTimeMillis(); + if ((now - socketOpenTime) < 4000L) { return; } - aLong1335 = l; - aSocket1363 = game.method19(43594 + Game.portOffset); - anInputStream1362 = aSocket1363.getInputStream(); - anOutputStream1354 = aSocket1363.getOutputStream(); - anOutputStream1354.write(15); + socketOpenTime = now; + socket = game.method19(43594 + Game.portOffset); + in = socket.getInputStream(); + out = socket.getOutputStream(); + out.write(15); for (int j = 0; j < 8; j++) { - anInputStream1362.read(); + in.read(); } - anInt1373 = 0; + waitCycles = 0; } - aByteArray1339[0] = (byte) request.store; - aByteArray1339[1] = (byte) (request.file >> 8); - aByteArray1339[2] = (byte) request.file; - if (request.aBoolean1422) { - aByteArray1339[3] = 2; - } else if (!game.aBoolean1157) { - aByteArray1339[3] = 1; + + bbuf[0] = (byte) request.store; + bbuf[1] = (byte) (request.file >> 8); + bbuf[2] = (byte) request.file; + + if (request.important) { + bbuf[3] = 2; + } else if (!game.ingame) { + bbuf[3] = 1; } else { - aByteArray1339[3] = 0; + bbuf[3] = 0; } - anOutputStream1354.write(aByteArray1339, 0, 4); - anInt1334 = 0; + + out.write(bbuf, 0, 4); + heartbeatCycle = 0; anInt1349 = -10000; return; } catch (IOException ignored) { } + try { - aSocket1363.close(); + socket.close(); } catch (Exception ignored) { } - aSocket1363 = null; - anInputStream1362 = null; - anOutputStream1354 = null; - anInt1347 = 0; + socket = null; + in = null; + out = null; + partAvailable = 0; anInt1349++; } - public int method557() { + public int getSeqFrameCount() { return animIndex.length; } @@ -326,7 +347,7 @@ public class OnDemand implements Runnable { OnDemandRequest request = new OnDemandRequest(); request.store = archive; request.file = file; - request.aBoolean1422 = true; + request.important = true; synchronized (aList_1370) { aList_1370.pushBack(request); } @@ -343,79 +364,99 @@ public class OnDemand implements Runnable { try { while (running) { cycle++; - int i = 20; + + int del = 20; + if ((topPriority == 0) && (game.filestores[0] != null)) { - i = 50; + del = 50; } + try { - Thread.sleep(i); + Thread.sleep(del); } catch (Exception ignored) { } + aBoolean1357 = true; + for (int j = 0; j < 100; j++) { if (!aBoolean1357) { break; } + aBoolean1357 = false; + method567(); method565(); - if ((anInt1366 == 0) && (j >= 5)) { + + if ((importantCount == 0) && (j >= 5)) { break; } + method568(); - if (anInputStream1362 != null) { - method550(); + + if (in != null) { + read(); } } - boolean flag = false; - for (OnDemandRequest request = (OnDemandRequest) aList_1331.peekFront(); request != null; request = (OnDemandRequest) aList_1331.prev()) { - if (request.aBoolean1422) { - flag = true; - request.anInt1423++; - if (request.anInt1423 > 50) { - request.anInt1423 = 0; - method556(request); + + boolean loading = false; + + for (OnDemandRequest request = (OnDemandRequest) pending.peekFront(); request != null; request = (OnDemandRequest) pending.prev()) { + if (request.important) { + loading = true; + request.cycle++; + + if (request.cycle > 50) { + request.cycle = 0; + send(request); } } } - if (!flag) { - for (OnDemandRequest request_1 = (OnDemandRequest) aList_1331.peekFront(); request_1 != null; request_1 = (OnDemandRequest) aList_1331.prev()) { - flag = true; - request_1.anInt1423++; - if (request_1.anInt1423 > 50) { - request_1.anInt1423 = 0; - method556(request_1); + + if (!loading) { + for (OnDemandRequest request = (OnDemandRequest) pending.peekFront(); request != null; request = (OnDemandRequest) pending.prev()) { + loading = true; + request.cycle++; + + if (request.cycle > 50) { + request.cycle = 0; + send(request); } } } - if (flag) { - anInt1373++; - if (anInt1373 > 750) { + + if (loading) { + waitCycles++; + + if (waitCycles > 750) { try { - aSocket1363.close(); + socket.close(); } catch (Exception ignored) { } - aSocket1363 = null; - anInputStream1362 = null; - anOutputStream1354 = null; - anInt1347 = 0; + socket = null; + in = null; + out = null; + partAvailable = 0; } } else { - anInt1373 = 0; - aString1333 = ""; + waitCycles = 0; + message = ""; } - if (game.aBoolean1157 && (aSocket1363 != null) && (anOutputStream1354 != null) && ((topPriority > 0) || (game.filestores[0] == null))) { - anInt1334++; - if (anInt1334 > 500) { - anInt1334 = 0; - aByteArray1339[0] = 0; - aByteArray1339[1] = 0; - aByteArray1339[2] = 0; - aByteArray1339[3] = 10; + + if (game.ingame && (socket != null) && (out != null) && ((topPriority > 0) || (game.filestores[0] == null))) { + heartbeatCycle++; + + if (heartbeatCycle > 500) { + heartbeatCycle = 0; + bbuf[0] = 0; + bbuf[1] = 0; + bbuf[2] = 0; + bbuf[3] = 10; + try { - anOutputStream1354.write(aByteArray1339, 0, 4); + out.write(bbuf, 0, 4); } catch (IOException _ex) { - anInt1373 = 5000; + waitCycles = 5000; } } } @@ -425,23 +466,23 @@ public class OnDemand implements Runnable { } } - public void method560(int i, int j) { + public void method560(int file, int store) { if (game.filestores[0] == null) { return; } - if (storeFileVersions[j][i] == 0) { + if (storeFileVersions[store][file] == 0) { return; } - if (storeFilePriority[j][i] == 0) { + if (storeFilePriorities[store][file] == 0) { return; } if (topPriority == 0) { return; } OnDemandRequest request = new OnDemandRequest(); - request.store = j; - request.file = i; - request.aBoolean1422 = false; + request.store = store; + request.file = file; + request.important = false; synchronized (aList_1344) { aList_1344.pushBack(request); } @@ -449,18 +490,23 @@ public class OnDemand implements Runnable { public OnDemandRequest poll() { OnDemandRequest request; - synchronized (aList_1358) { - request = (OnDemandRequest) aList_1358.pollFront(); + + synchronized (completed) { + request = (OnDemandRequest) completed.pollFront(); } + if (request == null) { return null; } - synchronized(lock) { + + synchronized (lock) { requests.remove(request); } + if (request.data == null) { return request; } + int i = 0; try { GZIPInputStream gzipinputstream = new GZIPInputStream(new ByteArrayInputStream(request.data)); @@ -502,7 +548,7 @@ public class OnDemand implements Runnable { request(0, i); } - public void method563(byte priority, int archive, int file) { + public void prefetch(byte priority, int archive, int file) { if (game.filestores[0] == null) { return; } @@ -512,17 +558,17 @@ public class OnDemand implements Runnable { byte[] data = game.filestores[archive + 1].read(file); - if (method549(storeFileVersions[archive][file], storeFileChecksums[archive][file], data)) { + if (validate(storeFileVersions[archive][file], storeFileChecksums[archive][file], data)) { return; } - storeFilePriority[archive][file] = priority; + storeFilePriorities[archive][file] = priority; if (priority > topPriority) { topPriority = priority; } - anInt1330++; + totalPrefetchFiles++; } public boolean method564(int i) { @@ -535,27 +581,32 @@ public class OnDemand implements Runnable { } public void method565() { - anInt1366 = 0; - anInt1367 = 0; - for (OnDemandRequest request = (OnDemandRequest) aList_1331.peekFront(); request != null; request = (OnDemandRequest) aList_1331.prev()) { - if (request.aBoolean1422) { - anInt1366++; + importantCount = 0; + requestCount = 0; + + for (OnDemandRequest request = (OnDemandRequest) pending.peekFront(); request != null; request = (OnDemandRequest) pending.prev()) { + if (request.important) { + importantCount++; } else { - anInt1367++; + requestCount++; } } - while (anInt1366 < 10) { - OnDemandRequest request_1 = (OnDemandRequest) aList_1368.pollFront(); - if (request_1 == null) { + + while (importantCount < 10) { + OnDemandRequest request = (OnDemandRequest) aList_1368.pollFront(); + + if (request == null) { break; } - if (storeFilePriority[request_1.store][request_1.file] != 0) { - anInt1351++; + + if (storeFilePriorities[request.store][request.file] != 0) { + loadedPretechFiles++; } - storeFilePriority[request_1.store][request_1.file] = 0; - aList_1331.pushBack(request_1); - anInt1366++; - method556(request_1); + + storeFilePriorities[request.store][request.file] = 0; + pending.pushBack(request); + importantCount++; + send(request); aBoolean1357 = true; } } @@ -571,22 +622,26 @@ public class OnDemand implements Runnable { synchronized (aList_1370) { request = (OnDemandRequest) aList_1370.pollFront(); } + while (request != null) { aBoolean1357 = true; - byte[] abyte0 = null; + byte[] data = null; + if (game.filestores[0] != null) { - abyte0 = game.filestores[request.store + 1].read(request.file); + data = game.filestores[request.store + 1].read(request.file); } - if (!method549(storeFileVersions[request.store][request.file], storeFileChecksums[request.store][request.file], abyte0)) { - abyte0 = null; + + if (!validate(storeFileVersions[request.store][request.file], storeFileChecksums[request.store][request.file], data)) { + data = null; } + synchronized (aList_1370) { - if (abyte0 == null) { + if (data == null) { aList_1368.pushBack(request); } else { - request.data = abyte0; - synchronized (aList_1358) { - aList_1358.pushBack(request); + request.data = data; + synchronized (completed) { + completed.pushBack(request); } } request = (OnDemandRequest) aList_1370.pollFront(); @@ -595,54 +650,63 @@ public class OnDemand implements Runnable { } public void method568() { - while ((anInt1366 == 0) && (anInt1367 < 10)) { + while ((importantCount == 0) && (requestCount < 10)) { if (topPriority == 0) { break; } - OnDemandRequest request; + + OnDemandRequest extra; + synchronized (aList_1344) { - request = (OnDemandRequest) aList_1344.pollFront(); + extra = (OnDemandRequest) aList_1344.pollFront(); } - while (request != null) { - if (storeFilePriority[request.store][request.file] != 0) { - storeFilePriority[request.store][request.file] = 0; - aList_1331.pushBack(request); - method556(request); + + while (extra != null) { + if (storeFilePriorities[extra.store][extra.file] != 0) { + storeFilePriorities[extra.store][extra.file] = 0; + pending.pushBack(extra); + send(extra); aBoolean1357 = true; - if (anInt1351 < anInt1330) { - anInt1351++; + + if (loadedPretechFiles < totalPrefetchFiles) { + loadedPretechFiles++; } - aString1333 = "Loading extra files - " + (anInt1351 * 100) / anInt1330 + "%"; - anInt1367++; - if (anInt1367 == 10) { + + message = "Loading extra files - " + (loadedPretechFiles * 100) / totalPrefetchFiles + "%"; + requestCount++; + + if (requestCount == 10) { return; } } synchronized (aList_1344) { - request = (OnDemandRequest) aList_1344.pollFront(); + extra = (OnDemandRequest) aList_1344.pollFront(); } } - for (int j = 0; j < 4; j++) { - byte[] abyte0 = storeFilePriority[j]; - int k = abyte0.length; - for (int l = 0; l < k; l++) { - if (abyte0[l] == topPriority) { - abyte0[l] = 0; - OnDemandRequest request_1 = new OnDemandRequest(); - request_1.store = j; - request_1.file = l; - request_1.aBoolean1422 = false; - aList_1331.pushBack(request_1); - method556(request_1); - aBoolean1357 = true; - if (anInt1351 < anInt1330) { - anInt1351++; - } - aString1333 = "Loading extra files - " + (anInt1351 * 100) / anInt1330 + "%"; - anInt1367++; - if (anInt1367 == 10) { - return; - } + + for (int store = 0; store < 4; store++) { + byte[] priorities = storeFilePriorities[store]; + for (int file = 0; file < priorities.length; file++) { + if (priorities[file] != topPriority) { + continue; + } + + priorities[file] = 0; + + OnDemandRequest request_1 = new OnDemandRequest(); + request_1.store = store; + request_1.file = file; + request_1.important = false; + pending.pushBack(request_1); + send(request_1); + aBoolean1357 = true; + if (loadedPretechFiles < totalPrefetchFiles) { + loadedPretechFiles++; + } + message = "Loading extra files - " + (loadedPretechFiles * 100) / totalPrefetchFiles + "%"; + requestCount++; + if (requestCount == 10) { + return; } } } diff --git a/src/main/java/OnDemandRequest.java b/src/main/java/OnDemandRequest.java index bd4c4d4..b384ed6 100644 --- a/src/main/java/OnDemandRequest.java +++ b/src/main/java/OnDemandRequest.java @@ -1,13 +1,20 @@ +import java.util.Arrays; + public class OnDemandRequest extends DoublyLinkedList.Node { public int store; - public byte[] data; public int file; - public boolean aBoolean1422; - public int anInt1423; + public boolean important; + public int cycle; + public byte[] data; public OnDemandRequest() { - aBoolean1422 = true; + important = true; + } + + @Override + public String toString() { + return "OnDemandRequest{" + "store=" + store + ", file=" + file + ", priority=" + important + ", cycle=" + cycle + ", data=" + Arrays.toString(data) + '}'; } } diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF similarity index 100% rename from src/main/java/META-INF/MANIFEST.MF rename to src/main/resources/META-INF/MANIFEST.MF