Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] V0.1 zip filestore feature branch #71

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/main/java/org/runejs/client/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ else if (gameInterface.xTextAlignment == 1)

public static void method37(CacheArchive cacheArchive, int arg2) {
if (UpdateServer.crcTableBuffer == null) {
UpdateServer.method327(true, null, 255, 255, (byte) 0, 0);
UpdateServer.requestFile(true, null, 255, 255, (byte) 0, 0);
Class24.aClass6_Sub1Array580[arg2] = cacheArchive;
} else {
UpdateServer.crcTableBuffer.currentPosition = 5 + arg2 * 4;
Expand Down Expand Up @@ -1930,16 +1930,19 @@ else if (Class51.gameStatusCode == 5) {
} else if (Class51.gameStatusCode == 20) {
WallDecoration.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall);
} else if (Class51.gameStatusCode == 25) {
final StringBuilder percentageBuilder = new StringBuilder(Native.leftParenthasis);
if (ProducingGraphicsBuffer.anInt1634 == 1) {
if (Class37.anInt874 > PacketBuffer.anInt2231)
PacketBuffer.anInt2231 = Class37.anInt874;
int i = (-Class37.anInt874 + PacketBuffer.anInt2231) * 50 / PacketBuffer.anInt2231;
Class51.method940(0, English.loadingPleaseWait, true, Native.leftParenthasis + i + Native.aClass1_698);
percentageBuilder.append(i).append(Native.percentChar).append(Native.rightParenthasis);
Class51.method940(0, English.loadingPleaseWait, true, percentageBuilder.toString());
} else if (ProducingGraphicsBuffer.anInt1634 == 2) {
if (IdentityKit.anInt2591 > GameObject.anInt3048)
GameObject.anInt3048 = IdentityKit.anInt2591;
int i = 50 * (-IdentityKit.anInt2591 + GameObject.anInt3048) / GameObject.anInt3048 + 50;
Class51.method940(0, English.loadingPleaseWait, true, Native.leftParenthasis + i + Native.aClass1_698);
percentageBuilder.append(i).append(Native.percentChar).append(Native.rightParenthasis);
Class51.method940(0, English.loadingPleaseWait, true, percentageBuilder.toString());
} else
Class51.method940(0, English.loadingPleaseWait, false, null);
} else if (Class51.gameStatusCode == 30) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/runejs/client/MovedStatics.java
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,9 @@ public static void method188() {

public static void method399(int arg0, int arg2) {
long l = (arg0 << 16) + arg2;
UpdateServerNode updateServerNode = (UpdateServerNode) UpdateServer.aClass23_2545.getNode(l);
UpdateServerNode updateServerNode = (UpdateServerNode) UpdateServer.queuedFileResponses.getNode(l);
if (updateServerNode != null) {
InteractiveObject.aNodeQueue_485.unshift(updateServerNode);
UpdateServer.activeQueuedRequests.unshift(updateServerNode);
}
}

Expand Down Expand Up @@ -784,9 +784,9 @@ public static void method527(int currentTabId, int arg1, int[] tabWidgetIds, boo

public static int calculateDataLoaded(int arg1, int arg2) {
long l = (long) ((arg1 << 16) + arg2);
if (UpdateServer.aUpdateServerNode_2250 == null || UpdateServer.aUpdateServerNode_2250.key != l)
if (UpdateServer.activeNode == null || UpdateServer.activeNode.key != l)
return 0;
return 1 + UpdateServer.aClass40_Sub1_2752.currentPosition * 99 / (UpdateServer.aClass40_Sub1_2752.buffer.length + -UpdateServer.aUpdateServerNode_2250.aByte2758);
return 1 + UpdateServer.fileDataBuffer.currentPosition * 99 / (UpdateServer.fileDataBuffer.buffer.length + -UpdateServer.activeNode.versionSize);
}

public static boolean method416(byte arg0) {
Expand Down
137 changes: 70 additions & 67 deletions src/main/java/org/runejs/client/cache/CacheArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public class CacheArchive {
public static CacheArchive clientScriptCacheArchive;
public static CacheArchive definitionCache;

public byte[][] aByteArrayArray212;
public byte[][] fileData;
public int crc8;
public NameHashCollection[] aNameHashCollectionArray217;
public boolean aBoolean220;
public boolean clearMemoryBuffer;
public int fileCount;
public int[] anIntArray224;
public int[] fileIds;
Expand All @@ -55,29 +55,29 @@ public class CacheArchive {
public CacheIndex metaIndex;
public int cacheIndexId;
public int archiveCrcValue;
public boolean aBoolean1811;
public boolean hasVersionNumbers;
public CacheIndex dataIndex;

static {
Player.npcs = new Npc[32768];
}

public CacheArchive(CacheIndex dataIndex, CacheIndex metaIndex, int cacheIndexId, boolean arg3, boolean arg4, boolean arg5) {
aBoolean220 = arg4;
public CacheArchive(CacheIndex dataIndex, CacheIndex metaIndex, int cacheIndexId, boolean arg3, boolean clearMemoryBuffer, boolean hasVersionNumbers) {
this.clearMemoryBuffer = clearMemoryBuffer;
aBoolean233 = arg3;
this.dataIndex = dataIndex;
aBoolean1811 = arg5;
this.hasVersionNumbers = hasVersionNumbers;
this.metaIndex = metaIndex;
this.cacheIndexId = cacheIndexId;
Main.method37(this, this.cacheIndexId);
}

public static CacheArchive loadArchive(int cacheIndexId, boolean arg1, boolean arg2, boolean arg4) {
public static CacheArchive loadArchive(int cacheIndexId, boolean hasVersionNumbers, boolean arg2, boolean arg4) {
CacheIndex dataIndex = null;
if(Main.dataChannel != null) {
dataIndex = new CacheIndex(cacheIndexId, Main.dataChannel, Main.indexChannels[cacheIndexId], 1000000);
}
return new CacheArchive(dataIndex, Main.metaIndex, cacheIndexId, arg2, arg4, arg1);
return new CacheArchive(dataIndex, Main.metaIndex, cacheIndexId, arg2, arg4, hasVersionNumbers);
}

public static byte[] decompress(byte[] cacheData) {
Expand Down Expand Up @@ -145,15 +145,15 @@ public void method196(boolean arg0, int arg2, boolean arg3, byte[] data) {
aBooleanArray1796[arg2] = true;
}
if(arg3) {
aByteArrayArray212[arg2] = data;
fileData[arg2] = data;
}
}
}

public int getPercentLoaded() {
if(aBoolean1800)
return 100;
if(aByteArrayArray212 != null)
if(fileData != null)
return 99;
int i = MovedStatics.calculateDataLoaded(255, cacheIndexId);
if(i >= 100)
Expand All @@ -162,64 +162,65 @@ public int getPercentLoaded() {

}

public void method198(boolean arg1, byte[] arg2, int arg3, CacheIndex arg4) {
if(metaIndex == arg4) {
public void method198(boolean immediate, byte[] fileData, int fileIndex, CacheIndex cacheIndex) {
if(metaIndex == cacheIndex) {
if(aBoolean1800)
throw new RuntimeException();
if(arg2 == null) {
UpdateServer.method327(true, this, 255, cacheIndexId, (byte) 0,
if(fileData == null) {
UpdateServer.requestFile(true, this, 255, cacheIndexId, (byte) 0,
archiveCrcValue);
return;
}
crc32.reset();
crc32.update(arg2, 0, arg2.length);
crc32.update(fileData, 0, fileData.length);
int i = (int) crc32.getValue();
if(i != archiveCrcValue) {
UpdateServer.method327(true, this, 255, cacheIndexId, (byte) 0,
archiveCrcValue);
return;
// @TODO still broken
// UpdateServer.method327(true, this, 255, cacheIndexId, (byte) 0,
// archiveCrcValue);
// return;
}

decodeArchive(arg2);
decodeArchive(fileData);
method199();
} else {
if(!arg1 && anInt1797 == arg3)
if(!immediate && anInt1797 == fileIndex)
aBoolean1800 = true;
if(arg2 == null || arg2.length <= 2) {
aBooleanArray1796[arg3] = false;
if(aBoolean1811 || arg1)
UpdateServer.method327(arg1, this, cacheIndexId, arg3, (byte) 2, anIntArray252[arg3]);
if(fileData == null || fileData.length <= 2) {
aBooleanArray1796[fileIndex] = false;
if(hasVersionNumbers || immediate)
UpdateServer.requestFile(immediate, this, cacheIndexId, fileIndex, (byte) 2, anIntArray252[fileIndex]);
return;
}
crc32.reset();
crc32.update(arg2, 0, arg2.length - 2);
crc32.update(fileData, 0, fileData.length - 2);
int i = (int) crc32.getValue();
int i_0_ = ((arg2[-2 + arg2.length] & 0xff) << 8) + (0xff & arg2[arg2.length + -1]);
if(i != anIntArray252[arg3] || i_0_ != anIntArray224[arg3]) {
aBooleanArray1796[arg3] = false;
if(aBoolean1811 || arg1)
UpdateServer.method327(arg1, this, cacheIndexId, arg3, (byte) 2, anIntArray252[arg3]);
int i_0_ = ((fileData[-2 + fileData.length] & 0xff) << 8) + (0xff & fileData[fileData.length + -1]);
if(i != anIntArray252[fileIndex] || i_0_ != anIntArray224[fileIndex]) {
aBooleanArray1796[fileIndex] = false;
if(hasVersionNumbers || immediate)
UpdateServer.requestFile(immediate, this, cacheIndexId, fileIndex, (byte) 2, anIntArray252[fileIndex]);
return;
}
aBooleanArray1796[arg3] = true;
if(arg1)
aByteArrayArray212[arg3] = arg2;
aBooleanArray1796[fileIndex] = true;
if(immediate)
this.fileData[fileIndex] = fileData;
}
}

public void method177(int arg1) {
if(dataIndex != null && aBooleanArray1796 != null && aBooleanArray1796[arg1])
GameObjectDefinition.method602(this, arg1, dataIndex);
else
UpdateServer.method327(true, this, cacheIndexId, arg1, (byte) 2, anIntArray252[arg1]);
UpdateServer.requestFile(true, this, cacheIndexId, arg1, (byte) 2, anIntArray252[arg1]);
}

public void method174(int arg0) {
MovedStatics.method399(cacheIndexId, arg0);
}

public void method199() {
aBooleanArray1796 = new boolean[aByteArrayArray212.length];
aBooleanArray1796 = new boolean[fileData.length];
for(int i_1_ = 0; i_1_ < aBooleanArray1796.length; i_1_++)
aBooleanArray1796[i_1_] = false;
if(dataIndex == null)
Expand All @@ -240,13 +241,13 @@ public void method199() {
public void requestLatestVersion(int crcValue) {
archiveCrcValue = crcValue;
if(metaIndex == null)
UpdateServer.method327(true, this, 255, cacheIndexId, (byte) 0, archiveCrcValue);
UpdateServer.requestFile(true, this, 255, cacheIndexId, (byte) 0, archiveCrcValue);
else
GameObjectDefinition.method602(this, cacheIndexId, metaIndex);
}

public int method201(int arg0) {
if(aByteArrayArray212[arg0] != null)
if(fileData[arg0] != null)
return 100;
if(aBooleanArray1796[arg0])
return 100;
Expand All @@ -256,7 +257,7 @@ public int method201(int arg0) {
public int method202() {
int i = 0;
int i_3_ = 0;
for(int i_4_ = 0; i_4_ < aByteArrayArray212.length; i_4_++) {
for(int i_4_ = 0; i_4_ < fileData.length; i_4_++) {
if(anIntArray261[i_4_] > 0) {
i += 100;
i_3_ += method201(i_4_);
Expand Down Expand Up @@ -300,31 +301,31 @@ public boolean loaded(int arg0, int arg2) {
return false;
if(inMemoryCacheBuffer[arg0][arg2] != null)
return true;
if(aByteArrayArray212[arg0] != null)
if(fileData[arg0] != null)
return true;
method177(arg0);
return aByteArrayArray212[arg0] != null;
return fileData[arg0] != null;
}

public int getLength() {
return inMemoryCacheBuffer.length;
}

public byte[] method176(int arg0, int arg1, int[] arg2) {
if(arg0 < 0 || arg0 >= inMemoryCacheBuffer.length || inMemoryCacheBuffer[arg0] == null || arg1 < 0 || arg1 >= inMemoryCacheBuffer[arg0].length)
public byte[] method176(int archiveId, int fileId, int[] arg2) {
if(archiveId < 0 || archiveId >= inMemoryCacheBuffer.length || inMemoryCacheBuffer[archiveId] == null || fileId < 0 || fileId >= inMemoryCacheBuffer[archiveId].length)
return null;
if(inMemoryCacheBuffer[arg0][arg1] == null) {
boolean bool = method181(arg0, arg2);
if(inMemoryCacheBuffer[archiveId][fileId] == null) {
boolean bool = method181(archiveId, arg2);
if(!bool) {
method177(arg0);
bool = method181(arg0, arg2);
method177(archiveId);
bool = method181(archiveId, arg2);
if(!bool)
return null;
}
}
byte[] is = inMemoryCacheBuffer[arg0][arg1];
if(aBoolean220)
inMemoryCacheBuffer[arg0][arg1] = null;
byte[] is = inMemoryCacheBuffer[archiveId][fileId];
if(clearMemoryBuffer)
inMemoryCacheBuffer[archiveId][fileId] = null;
return is;
}

Expand All @@ -349,7 +350,7 @@ public void decodeArchive(byte[] data) {
anIntArray252 = new int[size + 1];
inMemoryCacheBuffer = new byte[1 + size][][];
anIntArray261 = new int[1 + size];
aByteArrayArray212 = new byte[size + 1][];
fileData = new byte[size + 1][];

if(settings != 0) {
nameHashes = new int[size + 1];
Expand Down Expand Up @@ -393,11 +394,12 @@ public void decodeArchive(byte[] data) {

public int method179(int arg1, String arg2) {
arg2 = arg2.toLowerCase();
return aNameHashCollectionArray217[arg1].method882(RSString.stringHash(arg2));
int newHash = RSString.stringHash(arg2);
return aNameHashCollectionArray217[arg1].method882(newHash);
}

public boolean method181(int arg0, int[] arg2) {
if(aByteArrayArray212[arg0] == null)
if(fileData[arg0] == null)
return false;
int i = anIntArray261[arg0];
byte[][] is = inMemoryCacheBuffer[arg0];
Expand All @@ -413,17 +415,17 @@ public boolean method181(int arg0, int[] arg2) {
return true;
byte[] is_21_;
if(arg2 == null || arg2[0] == 0 && arg2[1] == 0 && arg2[2] == 0 && arg2[3] == 0)
is_21_ = aByteArrayArray212[arg0];
is_21_ = fileData[arg0];
else {
is_21_ = new byte[aByteArrayArray212[arg0].length];
Class18.method278(aByteArrayArray212[arg0], 0, is_21_, 0, is_21_.length);
is_21_ = new byte[fileData[arg0].length];
Class18.method278(fileData[arg0], 0, is_21_, 0, is_21_.length);
Buffer class40_sub1 = new Buffer(is_21_);
class40_sub1.method483(arg2, class40_sub1.buffer.length, 5);
}
byte[] is_22_;
is_22_ = decompress(is_21_);
if(aBoolean233)
aByteArrayArray212[arg0] = null;
fileData[arg0] = null;
if(i > 1) {
int i_23_ = is_22_.length;
int i_24_ = is_22_[--i_23_] & 0xff;
Expand Down Expand Up @@ -477,7 +479,8 @@ public byte[] method182(int arg0, int arg2) {

public int getHash(String arg1) {
arg1 = arg1.toLowerCase();
return nameHashCollection.method882(RSString.stringHash(arg1));
int newHash = RSString.stringHash(arg1);
return nameHashCollection.method882(newHash);
}

public boolean method185(byte arg0) {
Expand All @@ -486,29 +489,29 @@ public boolean method185(byte arg0) {
return true;
for(int i = 0; i < fileIds.length; i++) {
int i_47_ = fileIds[i];
if(aByteArrayArray212[i_47_] == null) {
if(fileData[i_47_] == null) {
method177(i_47_);
if(aByteArrayArray212[i_47_] == null)
if(fileData[i_47_] == null)
bool = false;
}
}
return bool;
}

public boolean fileExists(int arg1) {
if(aByteArrayArray212[arg1] != null)
public boolean fileExists(int fileIndex) {
if(fileData[fileIndex] != null)
return true;
method177(arg1);
if(aByteArrayArray212[arg1] != null)
method177(fileIndex);
if(fileData[fileIndex] != null)
return true;
return false;
}

public byte[] method187(int arg0) {
public byte[] method187(int fileIndex) {
if(inMemoryCacheBuffer.length == 1)
return getFile(0, arg0);
if(inMemoryCacheBuffer[arg0].length == 1)
return getFile(arg0, 0);
return getFile(0, fileIndex);
if(inMemoryCacheBuffer[fileIndex].length == 1)
return getFile(fileIndex, 0);
throw new RuntimeException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ public static GameInterface getInterface(int interfaceData) {
}
}

return cachedInterfaces[parentInterfaceId][childInterfaceId];
try {
return cachedInterfaces[parentInterfaceId][childInterfaceId];
} catch(Exception error) {
System.out.println(parentInterfaceId + " " + childInterfaceId);
error.printStackTrace();
return null;
}
}

public static void updateGameInterface(GameInterface gameInterface) {
Expand Down
Loading