use of net.runelite.cache.definitions.KitDefinition in project runelite by runelite.
the class KitLoader method load.
public KitDefinition load(int id, byte[] b) {
KitDefinition def = new KitDefinition(id);
InputStream is = new InputStream(b);
for (; ; ) {
int opcode = is.readUnsignedByte();
if (opcode == 0) {
break;
}
if (opcode == 1) {
def.bodyPartId = is.readUnsignedByte();
} else if (opcode == 2) {
int length = is.readUnsignedByte();
def.modelIds = new int[length];
for (int index = 0; index < length; ++index) {
def.modelIds[index] = is.readUnsignedShort();
}
} else if (opcode == 3) {
def.nonSelectable = true;
} else if (opcode == 40) {
int length = is.readUnsignedByte();
def.recolorToFind = new short[length];
def.recolorToReplace = new short[length];
for (int index = 0; index < length; ++index) {
def.recolorToFind[index] = is.readShort();
def.recolorToReplace[index] = is.readShort();
}
} else if (opcode == 41) {
int length = is.readUnsignedByte();
def.retextureToFind = new short[length];
def.retextureToReplace = new short[length];
for (int index = 0; index < length; ++index) {
def.retextureToFind[index] = is.readShort();
def.retextureToReplace[index] = is.readShort();
}
} else if (opcode >= 60 && opcode < 70) {
def.models[opcode - 60] = is.readShort();
}
}
return def;
}
use of net.runelite.cache.definitions.KitDefinition in project runelite by runelite.
the class KitManager method getKit.
public static KitDefinition getKit(int id) {
KitDefinition def = kits.get(id);
if (def != null) {
return def;
}
try (FileInputStream in = new FileInputStream(new File("kits/" + id + ".json"))) {
def = new Gson().fromJson(new InputStreamReader(in), KitDefinition.class);
kits.put(id, def);
return def;
} catch (IOException ex) {
logger.warn(null, ex);
return null;
}
}
use of net.runelite.cache.definitions.KitDefinition in project runelite by runelite.
the class KitDumperTest method test.
@Test
public void test() throws IOException {
File dumpDir = folder.newFolder();
int count = 0;
try (Store store = new Store(StoreLocation.LOCATION)) {
store.load();
Storage storage = store.getStorage();
Index index = store.getIndex(IndexType.CONFIGS);
Archive archive = index.getArchive(ConfigType.IDENTKIT.getId());
KitLoader loader = new KitLoader();
byte[] archiveData = storage.loadArchive(archive);
ArchiveFiles files = archive.getFiles(archiveData);
for (FSFile file : files.getFiles()) {
byte[] b = file.getContents();
KitDefinition def = loader.load(file.getFileId(), b);
Files.write(gson.toJson(def), new File(dumpDir, file.getFileId() + ".json"), Charset.defaultCharset());
++count;
}
}
logger.info("Dumped {} kits to {}", count, dumpDir);
}
use of net.runelite.cache.definitions.KitDefinition in project runelite by runelite.
the class ModelViewer method main.
public static void main(String[] args) throws Exception {
Options options = new Options();
options.addOption(null, "npcdir", true, "npc directory");
options.addOption(null, "mapdir", true, "maps directory");
options.addOption(null, "objectdir", true, "objects directory");
options.addOption(null, "npc", true, "npc to render");
options.addOption(null, "object", true, "object to render");
options.addOption(null, "model", true, "model to render");
options.addOption(null, "map", true, "map region to render");
options.addOption(null, "kits", true, "kits to render");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
String npcdir = cmd.getOptionValue("npcdir");
String mapdir = cmd.getOptionValue("mapdir");
String objectdir = cmd.getOptionValue("objectdir");
NpcDefinition npcdef = null;
ObjectDefinition objdef = null;
List<ModelDefinition> models = new ArrayList<>();
Region region = null;
if (cmd.hasOption("model")) {
// render model
String model = cmd.getOptionValue("model");
ModelDefinition md = ModelManager.getModel(Integer.parseInt(model), null, null);
models.add(md);
}
if (cmd.hasOption("npc")) {
String npc = cmd.getOptionValue("npc");
try (FileInputStream fin = new FileInputStream(npcdir + "/" + npc + ".json")) {
npcdef = new Gson().fromJson(new InputStreamReader(fin), NpcDefinition.class);
}
for (int model : npcdef.models) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
if (cmd.hasOption("object")) {
String obj = cmd.getOptionValue("object");
try (FileInputStream fin = new FileInputStream(objectdir + "/" + obj + ".json")) {
objdef = new Gson().fromJson(new InputStreamReader(fin), ObjectDefinition.class);
}
for (int model : objdef.getObjectModels()) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
if (cmd.hasOption("map")) {
String map = cmd.getOptionValue("map");
String[] s = map.split(",");
int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]);
region = new Region(x, y);
MapLoader mapLoader = new MapLoader();
LocationsLoader locationsLoader = new LocationsLoader();
try (FileInputStream fin = new FileInputStream(mapdir + "/m" + x + "_" + y + ".dat")) {
byte[] b = IOUtils.toByteArray(fin);
MapDefinition mapDef = mapLoader.load(x, y, b);
region.loadTerrain(mapDef);
}
try (FileInputStream fin = new FileInputStream(mapdir + "/l" + x + "_" + y + ".dat")) {
byte[] b = IOUtils.toByteArray(fin);
LocationsDefinition locDef = locationsLoader.load(x, y, b);
region.loadLocations(locDef);
} catch (FileNotFoundException ex) {
logger.info("No landscape file for {},{}", x, y);
}
loadUnderlays();
loadOverlays();
}
if (cmd.hasOption("kits")) {
String kits = cmd.getOptionValue("kits");
Integer[] kitIds = Arrays.stream(kits.split(",")).map(s -> Integer.parseInt(s)).toArray(Integer[]::new);
for (int kitId : kitIds) {
KitDefinition kit = KitManager.getKit(kitId);
for (int model : kit.modelIds) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
}
Display.setDisplayMode(new DisplayMode(800, 600));
Display.setTitle("Model Viewer");
Display.setInitialBackground((float) Color.gray.getRed() / 255f, (float) Color.gray.getGreen() / 255f, (float) Color.gray.getBlue() / 255f);
Display.create();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
double aspect = 1;
// near should be chosen as far into the scene as possible
double near = 1;
double far = 10000;
// 1 gives you a 90° field of view. It's tan(fov_angle)/2.
double fov = 1;
GL11.glFrustum(-aspect * near * fov, aspect * near * fov, -fov, fov, near, far);
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glCullFace(GL11.GL_BACK);
GL11.glEnable(GL11.GL_CULL_FACE);
long last = 0;
Camera camera = new Camera();
while (!Display.isCloseRequested()) {
// Clear the screen and depth buffer
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
for (ModelDefinition def : models) {
short[] recolourToFind = null, recolourToReplace = null;
if (npcdef != null) {
recolourToFind = npcdef.recolorToFind;
recolourToReplace = npcdef.recolorToReplace;
}
if (objdef != null) {
recolourToFind = objdef.getRecolorToFind();
recolourToReplace = objdef.getRecolorToReplace();
}
drawModel(def, recolourToFind, recolourToReplace);
}
drawRegion(region);
Display.update();
// fps
Display.sync(50);
long delta = System.currentTimeMillis() - last;
last = System.currentTimeMillis();
camera.acceptInput(delta);
camera.apply();
}
Display.destroy();
}
Aggregations