Code:
package org.serious.client.cache.definition;
import java.io.File;
import java.io.FileOutputStream;
import org.serious.client.Client;
import org.serious.client.FrameReader;
import org.serious.client.List;
import org.serious.client.Signlink;
import org.serious.client.cache.Archive;
import org.serious.client.cache.ondemand.OnDemandFetcher;
import org.serious.client.io.ByteBuffer;
import org.serious.client.world.Model;
public final class ObjectDefinition {
private static int[] streamIndices;
private static int[] streamIndices667;
private static int[] streamIndicesOSRS;
private static ByteBuffer stream667;
private static ByteBuffer stream07;
public static ObjectDefinition forID(int id) {
for (int j = 0; j < 20; j++) {
if (cache[j].type == id) {
return cache[j];
}
}
cacheIndex = (cacheIndex + 1) % 20;
ObjectDefinition definition = cache[cacheIndex];
if (id < 0) {
id = 0;
}
if (isOSRSObject(id)) {
return forIDOSRS(id);
}
try {
if (id > streamIndices.length)
stream667.position = streamIndices667[id];
else
stream.position = streamIndices[id];
} catch (Exception e) {
e.printStackTrace();
}
definition.type = id;
definition.setDefaults();
definition.hasActions = true;
if (id > streamIndices.length)
definition.readValues(stream667);
else
definition.readValues(stream);
if (definition.description == null) {
definition.description = ("It's a " + definition.name + ".").getBytes();
}
if (definition.actions == null || definition.actions.length < 5) {
String[] newActions = new String[5];
if (definition.actions != null) {
for (int i = 0; i < 5; i++) {
if (i >= definition.actions.length) {
newActions[i] = null;
} else {
newActions[i] = definition.actions[i];
}
}
}
definition.actions = newActions;
}
return definition;
}
private static final int[] OBJECTS_OSRS = {
/** Cerberus **/
732, 4451, 6926, 7823, 7824, 7825, 7826, 7827, 7828, 7829, 7830, 7834, 11853, 14645, 14674, 14675, 17118,
20196, 21696, 21697, 21698, 21699, 21700, 21701, 21702, 21703, 21704, 21705, 21706, 21707, 21708, 21709,
21710, 21711, 21712, 21713, 21714, 21715, 21716, 21717, 21718, 21748, 21749, 21750, 21751, 21752, 21753,
21754, 21755, 21756, 21757, 21758, 21759, 21760, 21761, 21762, 21763, 21765, 21766, 21767, 21768, 21769,
21770, 21772, 21773, 21775, 21776, 21777, 21779, 21780, 21946, 21947, 22494, 22495, 23100, 23101, 26571,
26572, 1502, 12930, 12931, 12932, 20737, 23102, 23104, 23106, 23107, 23108, 23109, 23112, 23610, 26294,
6775,
/** Sire **/
2134, 5192, 7392, 12390, 12391, 12392, 25069, 28929, 28930, 28931, 28933, 28934, 38416 };
private static boolean isOSRSObject(int objectId) {
for (int i = 0; i < OBJECTS_OSRS.length; i++) {
if (objectId == OBJECTS_OSRS[i]) {
return true;
}
}
return false;
}
public static ObjectDefinition forIDOSRS(int i) {
if (i > streamIndicesOSRS.length)
i = streamIndicesOSRS.length - 1;
for (int j = 0; j < 20; j++)
if (cache[j].type == i)
return cache[j];
cacheIndex = (cacheIndex + 1) % 20;
ObjectDefinition class46 = cache[cacheIndex];
stream07.position = streamIndicesOSRS[i];
class46.type = i;
class46.setDefaults();
class46.readValues(stream07);
return class46;
}
public static void nullify() {
mruNodes1 = null;
mruNodes2 = null;
streamIndices = null;
cache = null;
stream = null;
}
public static void unpackConfig(Archive streamLoader) {
stream = new ByteBuffer(streamLoader.get("loc.dat"));
ByteBuffer stream = new ByteBuffer(streamLoader.get("loc.idx"));
stream667 = new ByteBuffer(streamLoader.get("667loc.dat"));
ByteBuffer stream667 = new ByteBuffer(streamLoader.get("667loc.idx"));
stream07 = new ByteBuffer(streamLoader.get("07loc.dat"));
ByteBuffer stream07 = new ByteBuffer(streamLoader.get("07loc.idx"));
int totalObjects = stream.getUnsignedShort();
int totalObjects667 = stream667.getUnsignedShort();
int totalObjectsOSRS = stream07.getUnsignedShort();
streamIndices = new int[totalObjects];
streamIndices667 = new int[totalObjects667];
streamIndicesOSRS = new int[totalObjectsOSRS];
System.out.println("Total Objects [" + totalObjects + "] 667 Objects [" + totalObjects667 + "] OSRS Objects ["
+ totalObjectsOSRS + "]");
int i = 2;
for (int j = 0; j < totalObjects; j++) {
streamIndices[j] = i;
i += stream.getUnsignedShort();
}
i = 2;
for (int j = 0; j < totalObjects667; j++) {
streamIndices667[j] = i;
i += stream667.getUnsignedShort();
}
i = 2;
for (int j = 0; j < totalObjectsOSRS; j++) {
streamIndicesOSRS[j] = i;
i += stream07.getUnsignedShort();
}
cache = new ObjectDefinition[20];
for (int k = 0; k < 20; k++)
cache[k] = new ObjectDefinition();
}
public boolean aBoolean736;
private byte brightness;
private int offsetX;
public String name;
private int modelSizeY;
private static final Model[] aModelArray741s = new Model[4];
private byte contrast;
public int sizeX;
private int offsetH;
public int mapFunctionID;
private int[] originalModelColors;
private int modelSizeX;
public int configID;
private boolean aBoolean751;
public static boolean lowDetail;
private static ByteBuffer stream;
public int type;
public boolean aBoolean757;
public int mapSceneID;
public int configObjectIDs[];
private int anInt760;
public int sizeY;
public boolean adjustToTerrain;
public boolean aBoolean764;
public static Client clientInstance;
private boolean isSolidObject;
public boolean isUnwalkable;
public int plane;
private boolean nonFlatShading;
private static int cacheIndex;
private int modelSizeH;
public int[] objectModelIDs;
public int varbitIndex;
public int anInt775;
private int[] anIntArray776;
public byte description[];
public boolean hasActions;
public boolean aBoolean779;
public static List mruNodes2 = new List(30);
public int animationID;
private static ObjectDefinition[] cache;
private int offsetY;
private int[] modifiedModelColors;
public static List mruNodes1 = new List(500);
public String actions[];
public void method574(OnDemandFetcher class42_sub1) {
if (objectModelIDs == null) {
return;
}
for (int objectModelID : objectModelIDs) {
class42_sub1.method560(objectModelID & 0xffff, 0);
}
}
public boolean method577(int i) {
if (anIntArray776 == null) {
if (objectModelIDs == null) {
return true;
}
if (i != 10) {
return true;
}
boolean flag1 = true;
for (int objectModelID : objectModelIDs) {
flag1 &= Model.method463(objectModelID & 0xffff);
}
return flag1;
}
for (int j = 0; j < anIntArray776.length; j++) {
if (anIntArray776[j] == i) {
return Model.method463(objectModelIDs[j] & 0xffff);
}
}
return true;
}
public Model renderObject(int i, int j, int k, int l, int i1, int j1, int k1) {
Model model = getAnimatedModel(i, k1, j);
if (model == null) {
return null;
}
if (adjustToTerrain || nonFlatShading) {
model = new Model(adjustToTerrain, nonFlatShading, model);
}
if (adjustToTerrain) {
int l1 = (k + l + i1 + j1) / 4;
for (int i2 = 0; i2 < model.numberOfVerticeCoordinates; i2++) {
int j2 = model.verticesXCoordinate[i2];
int k2 = model.verticesZCoordinate[i2];
int l2 = k + (l - k) * (j2 + 64) / 128;
int i3 = j1 + (i1 - j1) * (j2 + 64) / 128;
int j3 = l2 + (i3 - l2) * (k2 + 64) / 128;
model.verticesYCoordinate[i2] += j3 - l1;
}
model.method467();
}
return model;
}
public boolean method579() {
if (objectModelIDs == null) {
return true;
}
boolean flag1 = true;
for (int objectModelID : objectModelIDs) {
flag1 &= Model.method463(objectModelID & 0xffff);
}
return flag1;
}
public ObjectDefinition method580() {
int i = -1;
if (varbitIndex != -1) {
VarBit varBit = VarBit.cache[varbitIndex];
int j = varBit.configId;
int k = varBit.configValue;
int l = varBit.anInt650;
int i1 = Client.anIntArray1232[l - k];
// System.out.println("j: " + j + " k: " + k);
i = clientInstance.variousSettings[j] >> k & i1;
} else if (configID != -1) {
i = clientInstance.variousSettings[configID];
}
if (i < 0 || i >= configObjectIDs.length || configObjectIDs[i] == -1) {
return null;
} else {
return forID(configObjectIDs[i]);
}
}
private Model getAnimatedModel(int j, int k, int l) {
Model model = null;
long l1;
if (anIntArray776 == null) {
if (j != 10) {
return null;
}
l1 = (type << 8) + l + ((long) (k + 1) << 32);
Model model_1 = (Model) mruNodes2.insertFromCache(l1);
if (model_1 != null) {
return model_1;
}
if (objectModelIDs == null) {
return null;
}
boolean flag1 = aBoolean751 ^ l > 3;
int k1 = objectModelIDs.length;
for (int i2 = 0; i2 < k1; i2++) {
int l2 = objectModelIDs[i2];
if (flag1) {
l2 += 0x10000;
}
model = (Model) mruNodes1.insertFromCache(l2);
if (model == null) {
model = Model.fetchModel(l2 & 0xffff);
if (model == null) {
return null;
}
if (flag1) {
model.method477();
}
mruNodes1.removeFromCache(model, l2);
}
if (k1 > 1) {
aModelArray741s[i2] = model;
}
}
if (k1 > 1) {
model = new Model(k1, aModelArray741s);
}
} else {
int i1 = -1;
for (int j1 = 0; j1 < anIntArray776.length; j1++) {
if (anIntArray776[j1] != j) {
continue;
}
i1 = j1;
break;
}
if (i1 == -1) {
return null;
}
l1 = (type << 8) + (i1 << 3) + l + ((long) (k + 1) << 32);
Model model_2 = (Model) mruNodes2.insertFromCache(l1);
if (model_2 != null) {
return model_2;
}
if (objectModelIDs == null) {
return null;
}
int j2 = objectModelIDs[i1];
boolean flag3 = aBoolean751 ^ l > 3;
if (flag3) {
j2 += 0x10000;
}
model = (Model) mruNodes1.insertFromCache(j2);
if (model == null) {
model = Model.fetchModel(j2 & 0xffff);
if (model == null) {
return null;
}
if (flag3) {
model.method477();
}
mruNodes1.removeFromCache(model, j2);
}
}
boolean flag;
flag = modelSizeX != 128 || modelSizeH != 128 || modelSizeY != 128;
boolean flag2;
flag2 = offsetX != 0 || offsetH != 0 || offsetY != 0;
Model model_3 = new Model(modifiedModelColors == null, FrameReader.isNullFrame(k),
l == 0 && k == -1 && !flag && !flag2, model);
if (k != -1) {
model_3.createBones();
model_3.applyTransform(k);
model_3.triangleSkin = null;
model_3.vertexSkin = null;
}
while (l-- > 0) {
model_3.method473();
}
if (modifiedModelColors != null) {
for (int k2 = 0; k2 < modifiedModelColors.length; k2++) {
model_3.method476(modifiedModelColors[k2], originalModelColors[k2]);
}
}
if (flag) {
model_3.scaleT(modelSizeX, modelSizeY, modelSizeH);
}
if (flag2) {
model_3.translate(offsetX, offsetH, offsetY);
}
model_3.light(64 + brightness, 768 + contrast * 5, -50, -10, -50, !nonFlatShading);
if (anInt760 == 1) {
model_3.anInt1654 = model_3.modelHeight;
}
mruNodes2.removeFromCache(model_3, l1);
return model_3;
}
private void readValues(ByteBuffer stream) {
int i = -1;
label0: do {
int opcode;
do {
opcode = stream.getUnsignedByte();
if (opcode == 0)
break label0;
if (opcode == 1) {
int k = stream.getUnsignedByte();
if (k > 0)
if (objectModelIDs == null || lowDetail) {
anIntArray776 = new int[k];
objectModelIDs = new int[k];
for (int k1 = 0; k1 < k; k1++) {
objectModelIDs[k1] = stream.readUnsignedWord();
anIntArray776[k1] = stream.getUnsignedByte();
}
} else {
stream.position += k * 3;
}
} else if (opcode == 2)
name = stream.getString();
else if (opcode == 3)
description = stream.getBytes();
else if (opcode == 5) {
int l = stream.getUnsignedByte();
if (l > 0)
if (objectModelIDs == null || lowDetail) {
anIntArray776 = null;
objectModelIDs = new int[l];
for (int l1 = 0; l1 < l; l1++)
objectModelIDs[l1] = stream.readUnsignedWord();
// System.out.println("" + objectModelIDs[0] + "");
} else {
stream.position += l * 2;
}
} else if (opcode == 14)
sizeX = stream.getUnsignedByte();
else if (opcode == 15)
sizeY = stream.getUnsignedByte();
else if (opcode == 17)
isUnwalkable = false;
else if (opcode == 18)
aBoolean757 = false;
else if (opcode == 19) {
i = stream.getUnsignedByte();
if (i == 1)
hasActions = true;
} else if (opcode == 21)
adjustToTerrain = true;
else if (opcode == 22)
nonFlatShading = false;
else if (opcode == 23)
aBoolean764 = true;
else if (opcode == 24) {
animationID = stream.readUnsignedWord();
if (animationID == 65535)
animationID = -1;
} else if (opcode == 28)
anInt775 = stream.getUnsignedByte();
else if (opcode == 29)
brightness = stream.getSignedByte();
else if (opcode == 39)
contrast = stream.getSignedByte();
else if (opcode >= 30 && opcode < 39) {
if (actions == null)
actions = new String[10];
actions[opcode - 30] = stream.getString();
if (actions[opcode - 30].equalsIgnoreCase("hidden"))
actions[opcode - 30] = null;
} else if (opcode == 40) {
int i1 = stream.getUnsignedByte();
modifiedModelColors = new int[i1];
originalModelColors = new int[i1];
for (int i2 = 0; i2 < i1; i2++) {
modifiedModelColors[i2] = stream.readUnsignedWord();
originalModelColors[i2] = stream.readUnsignedWord();
}
} else if (opcode == 60)
mapFunctionID = stream.readUnsignedWord();
else if (opcode == 62)
aBoolean751 = true;
else if (opcode == 64)
aBoolean779 = false;
else if (opcode == 65)
modelSizeX = stream.readUnsignedWord();
else if (opcode == 66)
modelSizeH = stream.readUnsignedWord();
else if (opcode == 67)
modelSizeY = stream.readUnsignedWord();
else if (opcode == 68)
mapSceneID = stream.readUnsignedWord();
else if (opcode == 69)
plane = stream.getUnsignedByte();
else if (opcode == 70)
offsetX = stream.getSignedShort();
else if (opcode == 71)
offsetH = stream.getSignedShort();
else if (opcode == 72)
offsetY = stream.getSignedShort();
else if (opcode == 73)
aBoolean736 = true;
else if (opcode == 74) {
isSolidObject = true;
} else {
if (opcode != 75)
continue;
anInt760 = stream.getUnsignedByte();
}
continue label0;
} while (opcode != 77);
varbitIndex = stream.readUnsignedWord();
if (varbitIndex == 65535)
varbitIndex = -1;
configID = stream.readUnsignedWord();
if (configID == 65535)
configID = -1;
int j1 = stream.getUnsignedByte();
configObjectIDs = new int[j1 + 1];
for (int j2 = 0; j2 <= j1; j2++) {
configObjectIDs[j2] = stream.readUnsignedWord();
if (configObjectIDs[j2] == 65535)
configObjectIDs[j2] = -1;
}
} while (true);
if (i == -1) {
hasActions = objectModelIDs != null && (anIntArray776 == null || anIntArray776[0] == 10);
if (actions != null)
hasActions = true;
}
if (isSolidObject) {
isUnwalkable = false;
aBoolean757 = false;
}
if (anInt760 == -1)
anInt760 = isUnwalkable ? 1 : 0;
}
private void setDefaults() {
objectModelIDs = null;
anIntArray776 = null;
name = null;
description = null;
modifiedModelColors = null;
originalModelColors = null;
sizeX = 1;
sizeY = 1;
isUnwalkable = true;
aBoolean757 = true;
hasActions = false;
adjustToTerrain = false;
nonFlatShading = false;
aBoolean764 = false;
animationID = -1;
anInt775 = 16;
brightness = 0;
contrast = 0;
actions = null;
mapFunctionID = -1;
mapSceneID = -1;
aBoolean751 = false;
aBoolean779 = true;
modelSizeX = 128;
modelSizeH = 128;
modelSizeY = 128;
plane = 0;
offsetX = 0;
offsetH = 0;
offsetY = 0;
aBoolean736 = false;
isSolidObject = false;
anInt760 = -1;
varbitIndex = -1;
configID = -1;
configObjectIDs = null;
}
public static void dumpObjectModels() {
dumpObjectModels(streamIndices);
dumpObjectModels(streamIndices667);
}
public static void dumpObjectModels(int[] indices) {
int dumped = 0, exceptions = 0;
for (int i = 0; i < indices.length - 1; i++) {
ObjectDefinition object = forID(i);
if (object == null)
continue;
if (object.objectModelIDs == null)
continue;
for (int model : object.objectModelIDs) {
try {
byte abyte[] = clientInstance.decompressors[1].decompress(model);
File modelFile = new File(
Signlink.getCacheDirectory().toString() + "/objectModels/" + model + ".gz");
FileOutputStream fos = new FileOutputStream(modelFile);
fos.write(abyte);
fos.close();
dumped++;
} catch (Exception e) {
exceptions++;
}
}
}
System.out.println("Dumped " + dumped + " object models with " + exceptions + " exceptions.");
}
}