Continued progress:
I wanted to jump straight into getting textures loaded for models but had to take a crash course in that which can be called RSC fucked cache system. Having only really played with the rs2 cache you can really come to appreciate the progress they made with the organization of the cache system from the upgrade. The way that files are read and packed have not changed much between rsc and the initial release of rs2 but the organization is a bit fucked in RSC. I needed the texture count but found it was packed in this giant configuration file which is basically every important definition file for RSC. in RS2 they had the sense to separate this.
Also I removed the bzip2 compression on cache files simply because my http://www.jsweet.org/ conversion of the java class didn’t really function and alternatives would need to be modifed to fit with the rsc standard (removing the header and hard setting some options) I didn’t really feel like messing with it so just opted for just repacking the cache with no bzip compression. I wrote this quick pile of silab to get the job done.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* a shitty bypass for my BZIP2 issues in javascript this will repack the cache with no bzipped data.
* @author Silabsoft
*/
public class NoBZip {
public NoBZip() {
}
public void unBzip(String file) throws Exception {
FileOutputStream out = new FileOutputStream("data204_no_bzip/" + file+"t");
byte[] f = readDataFile(file);
Entry[] e = unpackData(f);
byte[] payload = this.writeEntries(e);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
this.putTri(bo, payload.length);
this.putTri(bo, payload.length);
bo.write(payload);
out.write(bo.toByteArray());
out.close();
}
public static void main(String[] args) {
try {
NoBZip ub = new NoBZip();
// ub.unBzip("textures" + Version.TEXTURES + ".jag");
ub.unBzip("config85.jag");
} catch (Exception ex) {
Logger.getLogger(NoBZip.class.getName()).log(Level.SEVERE, null, ex);
}
}
public byte[] readDataFile(String file) {
//System.out.println("Using default load");
file = "./data204_no_bzip/" + file;
int archiveSize = 0;
int archiveSizeCompressed = 0;
byte archiveData[] = null;
byte header[] = new byte[6];
try {
java.io.InputStream inputstream = Utility.openFile(file);
DataInputStream datainputstream = new DataInputStream(inputstream);
datainputstream.readFully(header, 0, 6);
archiveSize = ((header[0] & 0xff) << 16) + ((header[1] & 0xff) << 8) + (header[2] & 0xff);
archiveSizeCompressed = ((header[3] & 0xff) << 16) + ((header[4] & 0xff) << 8) + (header[5] & 0xff);
int read = 0;
archiveData = new byte[archiveSizeCompressed];
while (read < archiveSizeCompressed) {
int length = archiveSizeCompressed - read;
if (length > 1000) {
length = 1000;
}
datainputstream.readFully(archiveData, read, length);
read += length;
}
datainputstream.close();
} catch (IOException ignored) {
}
if (archiveSizeCompressed != archiveSize) {
byte decompressed[] = new byte[archiveSize];
BZLib.decompress(decompressed, archiveSize, archiveData, archiveSizeCompressed, 0);
return decompressed;
} else {
return archiveData;
}
}
public byte[] writeEntries(Entry[] entry) throws IOException {
ByteArrayOutputStream bb = new ByteArrayOutputStream();
putShort(bb, entry.length);
for (int i = 0; i < entry.length; i++) {
putInt(bb, entry[i].getFileHash());
putTri(bb, entry[i].getData().length);
putTri(bb, entry[i].getData().length);
}
for (int i = 0; i < entry.length; i++) {
for(int x = 0; x < entry[i].getData().length; x++){
bb.write(entry[i].getData()[x]);
}
}
return bb.toByteArray();
}
public void putShort(ByteArrayOutputStream out, int i) {
out.write((byte) (i >> 8));
out.write((byte) i);
}
public void putInt(ByteArrayOutputStream out, int i) {
out.write((byte) (i >> 24));
out.write((byte) (i >> 16));
out.write((byte) (i >> 8));
out.write((byte) i);
}
public void putTri(ByteArrayOutputStream out, int i) {
out.write((byte) (i >> 16));
out.write((byte) (i >> 8));
out.write((byte) i);
}
public Entry[] unpackData(byte archiveData[]) {
int numEntries = (archiveData[0] & 0xff) * 256 + (archiveData[1] & 0xff);
System.out.println(numEntries);
int offset = 2 + numEntries * 10;
Entry[] ent = new Entry[numEntries];
for (int entry = 0; entry < numEntries; entry++) {
int fileHash = (archiveData[entry * 10 + 2] & 0xff) * 0x1000000 + (archiveData[entry * 10 + 3] & 0xff) * 0x10000 + (archiveData[entry * 10 + 4] & 0xff) * 256 + (archiveData[entry * 10 + 5] & 0xff);
int fileSize = (archiveData[entry * 10 + 6] & 0xff) * 0x10000 + (archiveData[entry * 10 + 7] & 0xff) * 256 + (archiveData[entry * 10 + 8] & 0xff);
int fileSizeCompressed = (archiveData[entry * 10 + 9] & 0xff) * 0x10000 + (archiveData[entry * 10 + 10] & 0xff) * 256 + (archiveData[entry * 10 + 11] & 0xff);
System.out.println(fileHash+" "+fileSize+" "+fileSizeCompressed+" "+offset);
byte[] fileData = new byte[fileSize];
if (fileSize != fileSizeCompressed) {
BZLib.decompress(fileData, fileSize, archiveData, fileSizeCompressed, offset);
} else {
for (int j = 0; j < fileSize; j++) {
fileData[j] = archiveData[offset + j];
}
}
ent[entry] = new Entry(fileHash, fileData);
offset += fileSizeCompressed;
}
return ent;
}
public class Entry {
private final byte[] data;
private final int fileHash;
public Entry(int fileHash, byte[] data) {
this.data = data;
this.fileHash = fileHash;
}
public byte[] getData() {
return data;
}
public int getFileHash() {
return fileHash;
}
}
}
You can view the config data dumped in real time here: http://silabsoft.org/configTest.html