Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @FXML
- private void dumpObjectDefs() {
- if (!cacheDirectory.isPresent()) {
- DirectoryChooser cacheChooser = new DirectoryChooser();
- cacheChooser.setTitle("Select directory containing osrs cache.");
- Optional<File> cacheResult = Optional.ofNullable(cacheChooser.showDialog(App.getStage()));
- if (!cacheResult.isPresent()) {
- return;
- }
- cacheDirectory = cacheResult;
- }
- createTask(new Task<Void>() {
- @Override
- protected Void call() throws Exception {
- try (Cache cache = new Cache(FileStore.open(cacheDirectory.get().toPath().toString()))) {
- File dir = new File("./dump/");
- if (!dir.exists()) {
- dir.mkdirs();
- }
- ObjectTypeList list = new ObjectTypeList();
- list.initialize(cache);
- try (DataOutputStream dat = new DataOutputStream(new FileOutputStream(new File(dir, "loc.dat")));
- DataOutputStream idx = new DataOutputStream(
- new FileOutputStream(new File(dir, "loc.idx")))) {
- int size = list.size();
- idx.writeShort(size);
- dat.writeShort(size);
- ObjectType lastValidType = null;
- for (int index = 0; index < list.size(); index++) {
- int start = dat.size();
- ObjectType obj = list.list(index);
- if(obj == null) {
- if(lastValidType == null)
- break;
- else {
- obj = lastValidType;
- System.out.println("Object at index " + index + " is null!");
- }
- } else
- lastValidType = obj;
- if (obj.getObjectModels() != null) {
- if (obj.getObjectTypes() != null) {
- dat.writeByte(1);
- dat.writeByte(obj.getObjectModels().length);
- if (obj.getObjectModels().length > 0) {
- for (int i = 0; i < obj.getObjectModels().length; i++) {
- dat.writeShort(obj.getObjectModels()[i]);
- dat.writeByte(obj.getObjectTypes()[i]);
- }
- }
- } else {
- dat.writeByte(5);
- dat.writeByte(obj.getObjectModels().length);
- if (obj.getObjectModels().length > 0) {
- for (int i = 0; i < obj.getObjectModels().length; i++) {
- dat.writeShort(obj.getObjectModels()[i]);
- }
- }
- }
- }
- if (obj.getName() != null && !obj.getName().equalsIgnoreCase("null")) {
- dat.writeByte(2);
- dat.write(obj.getName().getBytes());
- dat.writeByte(10);
- }
- if (obj.getSizeX() != 1) {
- dat.writeByte(14);
- dat.writeByte(obj.getSizeX());
- }
- if (obj.getSizeY() != 1) {
- dat.writeByte(15);
- dat.writeByte(obj.getSizeY());
- }
- if (obj.getAnInt2094() == 0) {
- dat.writeByte(17);
- }
- if (!obj.isaBool2114()) {
- dat.writeByte(18);
- }
- if (obj.getAnInt2088() == 1) {
- dat.writeByte(19);
- dat.writeByte(1);
- }
- if (obj.getAnInt2105() >= 0) {
- dat.writeByte(21);
- }
- if (obj.isNonFlatShading()) {
- dat.writeByte(22);
- }
- if (obj.isaBool2111()) {
- dat.writeByte(23);
- }
- if (obj.getAnimationID() != -1) {
- dat.writeByte(24);
- dat.writeShort(obj.getAnimationID());
- }
- if (obj.getAnInt2069() != 16) {
- dat.writeByte(28);
- dat.writeByte(obj.getAnInt2069());
- }
- if (obj.getAmbient() != 0) {
- dat.writeByte(29);
- dat.writeByte(obj.getAmbient());
- }
- if (obj.getContrast() != 0) {
- dat.writeByte(39);
- dat.writeByte(obj.getContrast());
- }
- if (!ArrayUtils.isEmpty(obj.getActions())) {
- for (int i = 0; i < obj.getActions().length; i++) {
- if (obj.getActions()[i] != null) {
- dat.writeByte(i + 30);
- dat.write(obj.getActions()[i].getBytes());
- dat.writeByte(10);
- }
- }
- }
- if (obj.getRecolorToFind() != null || obj.getRecolorToReplace() != null) {
- dat.writeByte(40);
- dat.writeByte(obj.getRecolorToFind().length);
- for (int i = 0; i < obj.getRecolorToFind().length; i++) {
- dat.writeShort(obj.getRecolorToFind()[i]);
- dat.writeShort(obj.getRecolorToReplace()[i]);
- }
- }
- if (obj.getRetextureToFind() != null || obj.getTextureToReplace() != null) {
- dat.writeByte(41);
- dat.writeByte(obj.getRetextureToFind().length);
- for (int i = 0; i < obj.getRetextureToFind().length; i++) {
- dat.writeShort(obj.getRetextureToFind()[i]);
- dat.writeShort(obj.getTextureToReplace()[i]);
- }
- }
- if (obj.isaBool2108()) {
- dat.writeByte(62);
- }
- if (!obj.isaBool2097()) {
- dat.writeByte(64);
- }
- if (obj.getModelSizeX() != 128) {
- dat.writeByte(65);
- dat.writeShort(obj.getModelSizeX());
- }
- if (obj.getModelSizeHeight() != 128) {
- dat.writeByte(66);
- dat.writeShort(obj.getModelSizeHeight());
- }
- if (obj.getModelSizeY() != 128) {
- dat.writeByte(67);
- dat.writeShort(obj.getModelSizeY());
- }
- if (obj.getMapSceneID() != -1) {
- dat.writeByte(68);
- dat.writeShort(obj.getMapSceneID());
- }
- if (obj.getAnInt768() != -1) {
- dat.writeByte(69);
- dat.writeByte(obj.getAnInt768());
- }
- if (obj.getOffsetX() != 0) {
- dat.writeByte(70);
- dat.writeShort(obj.getOffsetX());
- }
- if (obj.getOffsetHeight() != 0) {
- dat.writeByte(71);
- dat.writeShort(obj.getOffsetHeight());
- }
- if (obj.getOffsetY() != 0) {
- dat.writeByte(72);
- dat.writeShort(obj.getOffsetY());
- }
- if (obj.isaBool2104()) {
- dat.writeByte(73);
- }
- if (obj.isSolid()) {
- dat.writeByte(74);
- }
- if (obj.getAnInt2106() == 1) {
- dat.writeByte(75);
- dat.writeByte(obj.getAnInt2106());
- }
- // TODO fix varbits
- // if (obj.getVarpID() != -1 || obj.getConfigId() !=
- // -1 || obj.getConfigChangeDest() != null) {
- // dat.writeByte(77);
- // dat.writeShort(obj.getVarpID());
- // dat.writeShort(obj.getConfigId());
- // dat.writeByte(obj.getConfigChangeDest().length);
- //
- // for (int i = 0; i <
- // obj.getConfigChangeDest().length; i++) {
- // dat.writeShort(obj.getConfigChangeDest()[i]);
- // }
- //
- // }
- if (obj.getMapAreaId() != -1) {
- dat.writeByte(82);
- dat.writeShort(obj.getMapAreaId());
- }
- dat.writeByte(0);
- int end = dat.size();
- idx.writeShort(end - start);
- double progress = ((double) (index + 1) / list.size()) * 100;
- updateMessage(String.format("%.2f%s", progress, "%"));
- updateProgress((index + 1), list.size());
- }
- Platform.runLater(() -> {
- Dialogue.openDirectory("Would you like to view these files?", dir);
- });
- System.out.println(String.format("Dumped %d Object Definitions into 317 format.", list.size()));
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- }
- return null;
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment