Guest User

Untitled

a guest
Jan 14th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.29 KB | None | 0 0
  1. @FXML
  2.     private void dumpObjectDefs() {
  3.  
  4.         if (!cacheDirectory.isPresent()) {
  5.             DirectoryChooser cacheChooser = new DirectoryChooser();
  6.             cacheChooser.setTitle("Select directory containing osrs cache.");
  7.  
  8.             Optional<File> cacheResult = Optional.ofNullable(cacheChooser.showDialog(App.getStage()));
  9.  
  10.             if (!cacheResult.isPresent()) {
  11.                 return;
  12.             }
  13.  
  14.             cacheDirectory = cacheResult;
  15.         }
  16.  
  17.         createTask(new Task<Void>() {
  18.  
  19.             @Override
  20.             protected Void call() throws Exception {
  21.                 try (Cache cache = new Cache(FileStore.open(cacheDirectory.get().toPath().toString()))) {
  22.  
  23.                     File dir = new File("./dump/");
  24.  
  25.                     if (!dir.exists()) {
  26.                         dir.mkdirs();
  27.                     }
  28.  
  29.                     ObjectTypeList list = new ObjectTypeList();
  30.  
  31.                     list.initialize(cache);
  32.  
  33.                     try (DataOutputStream dat = new DataOutputStream(new FileOutputStream(new File(dir, "loc.dat")));
  34.                             DataOutputStream idx = new DataOutputStream(
  35.                                     new FileOutputStream(new File(dir, "loc.idx")))) {
  36.  
  37.                         int size = list.size();
  38.  
  39.                         idx.writeShort(size);
  40.                         dat.writeShort(size);
  41.                        
  42.                         ObjectType lastValidType = null;
  43.  
  44.                         for (int index = 0; index < list.size(); index++) {
  45.  
  46.                             int start = dat.size();
  47.  
  48.                             ObjectType obj = list.list(index);
  49.                            
  50.                             if(obj == null) {
  51.                                 if(lastValidType == null)
  52.                                     break;
  53.                                 else {
  54.                                     obj = lastValidType;
  55.                                     System.out.println("Object at index " + index + " is null!");
  56.                                 }
  57.                             } else
  58.                                 lastValidType = obj;
  59.  
  60.                             if (obj.getObjectModels() != null) {
  61.                                 if (obj.getObjectTypes() != null) {
  62.                                     dat.writeByte(1);
  63.                                     dat.writeByte(obj.getObjectModels().length);
  64.                                     if (obj.getObjectModels().length > 0) {
  65.  
  66.                                         for (int i = 0; i < obj.getObjectModels().length; i++) {
  67.                                             dat.writeShort(obj.getObjectModels()[i]);
  68.                                             dat.writeByte(obj.getObjectTypes()[i]);
  69.                                         }
  70.  
  71.                                     }
  72.                                 } else {
  73.                                     dat.writeByte(5);
  74.                                     dat.writeByte(obj.getObjectModels().length);
  75.                                     if (obj.getObjectModels().length > 0) {
  76.  
  77.                                         for (int i = 0; i < obj.getObjectModels().length; i++) {
  78.                                             dat.writeShort(obj.getObjectModels()[i]);
  79.                                         }
  80.  
  81.                                     }
  82.                                 }
  83.                             }
  84.  
  85.                             if (obj.getName() != null && !obj.getName().equalsIgnoreCase("null")) {
  86.                                 dat.writeByte(2);
  87.                                 dat.write(obj.getName().getBytes());
  88.                                 dat.writeByte(10);
  89.                             }
  90.  
  91.                             if (obj.getSizeX() != 1) {
  92.                                 dat.writeByte(14);
  93.                                 dat.writeByte(obj.getSizeX());
  94.                             }
  95.  
  96.                             if (obj.getSizeY() != 1) {
  97.                                 dat.writeByte(15);
  98.                                 dat.writeByte(obj.getSizeY());
  99.                             }
  100.  
  101.                             if (obj.getAnInt2094() == 0) {
  102.                                 dat.writeByte(17);
  103.                             }
  104.  
  105.                             if (!obj.isaBool2114()) {
  106.                                 dat.writeByte(18);
  107.                             }
  108.  
  109.                             if (obj.getAnInt2088() == 1) {
  110.                                 dat.writeByte(19);
  111.                                 dat.writeByte(1);
  112.                             }
  113.  
  114.                             if (obj.getAnInt2105() >= 0) {
  115.                                 dat.writeByte(21);
  116.                             }
  117.  
  118.                             if (obj.isNonFlatShading()) {
  119.                                 dat.writeByte(22);
  120.                             }
  121.  
  122.                             if (obj.isaBool2111()) {
  123.                                 dat.writeByte(23);
  124.                             }
  125.  
  126.                             if (obj.getAnimationID() != -1) {
  127.                                 dat.writeByte(24);
  128.                                 dat.writeShort(obj.getAnimationID());
  129.                             }
  130.  
  131.                             if (obj.getAnInt2069() != 16) {
  132.                                 dat.writeByte(28);
  133.                                 dat.writeByte(obj.getAnInt2069());
  134.                             }
  135.  
  136.                             if (obj.getAmbient() != 0) {
  137.                                 dat.writeByte(29);
  138.                                 dat.writeByte(obj.getAmbient());
  139.                             }
  140.  
  141.                             if (obj.getContrast() != 0) {
  142.                                 dat.writeByte(39);
  143.                                 dat.writeByte(obj.getContrast());
  144.                             }
  145.  
  146.                             if (!ArrayUtils.isEmpty(obj.getActions())) {
  147.                                 for (int i = 0; i < obj.getActions().length; i++) {
  148.                                     if (obj.getActions()[i] != null) {
  149.                                         dat.writeByte(i + 30);
  150.                                         dat.write(obj.getActions()[i].getBytes());
  151.                                         dat.writeByte(10);
  152.                                     }
  153.                                 }
  154.                             }
  155.  
  156.                             if (obj.getRecolorToFind() != null || obj.getRecolorToReplace() != null) {
  157.                                 dat.writeByte(40);
  158.                                 dat.writeByte(obj.getRecolorToFind().length);
  159.  
  160.                                 for (int i = 0; i < obj.getRecolorToFind().length; i++) {
  161.                                     dat.writeShort(obj.getRecolorToFind()[i]);
  162.                                     dat.writeShort(obj.getRecolorToReplace()[i]);
  163.                                 }
  164.  
  165.                             }
  166.  
  167.                             if (obj.getRetextureToFind() != null || obj.getTextureToReplace() != null) {
  168.                                 dat.writeByte(41);
  169.                                 dat.writeByte(obj.getRetextureToFind().length);
  170.  
  171.                                 for (int i = 0; i < obj.getRetextureToFind().length; i++) {
  172.                                     dat.writeShort(obj.getRetextureToFind()[i]);
  173.                                     dat.writeShort(obj.getTextureToReplace()[i]);
  174.                                 }
  175.  
  176.                             }
  177.  
  178.                             if (obj.isaBool2108()) {
  179.                                 dat.writeByte(62);
  180.                             }
  181.  
  182.                             if (!obj.isaBool2097()) {
  183.                                 dat.writeByte(64);
  184.                             }
  185.  
  186.                             if (obj.getModelSizeX() != 128) {
  187.                                 dat.writeByte(65);
  188.                                 dat.writeShort(obj.getModelSizeX());
  189.                             }
  190.  
  191.                             if (obj.getModelSizeHeight() != 128) {
  192.                                 dat.writeByte(66);
  193.                                 dat.writeShort(obj.getModelSizeHeight());
  194.                             }
  195.  
  196.                             if (obj.getModelSizeY() != 128) {
  197.                                 dat.writeByte(67);
  198.                                 dat.writeShort(obj.getModelSizeY());
  199.                             }
  200.  
  201.                             if (obj.getMapSceneID() != -1) {
  202.                                 dat.writeByte(68);
  203.                                 dat.writeShort(obj.getMapSceneID());
  204.                             }
  205.  
  206.                             if (obj.getAnInt768() != -1) {
  207.                                 dat.writeByte(69);
  208.                                 dat.writeByte(obj.getAnInt768());
  209.                             }
  210.  
  211.                             if (obj.getOffsetX() != 0) {
  212.                                 dat.writeByte(70);
  213.                                 dat.writeShort(obj.getOffsetX());
  214.                             }
  215.  
  216.                             if (obj.getOffsetHeight() != 0) {
  217.                                 dat.writeByte(71);
  218.                                 dat.writeShort(obj.getOffsetHeight());
  219.                             }
  220.  
  221.                             if (obj.getOffsetY() != 0) {
  222.                                 dat.writeByte(72);
  223.                                 dat.writeShort(obj.getOffsetY());
  224.                             }
  225.  
  226.                             if (obj.isaBool2104()) {
  227.                                 dat.writeByte(73);
  228.                             }
  229.  
  230.                             if (obj.isSolid()) {
  231.                                 dat.writeByte(74);
  232.                             }
  233.  
  234.                             if (obj.getAnInt2106() == 1) {
  235.                                 dat.writeByte(75);
  236.                                 dat.writeByte(obj.getAnInt2106());
  237.                             }
  238.  
  239.                             // TODO fix varbits
  240.  
  241.                             // if (obj.getVarpID() != -1 || obj.getConfigId() !=
  242.                             // -1 || obj.getConfigChangeDest() != null) {
  243.                             // dat.writeByte(77);
  244.                             // dat.writeShort(obj.getVarpID());
  245.                             // dat.writeShort(obj.getConfigId());
  246.                             // dat.writeByte(obj.getConfigChangeDest().length);
  247.                             //
  248.                             // for (int i = 0; i <
  249.                             // obj.getConfigChangeDest().length; i++) {
  250.                             // dat.writeShort(obj.getConfigChangeDest()[i]);
  251.                             // }
  252.                             //
  253.                             // }
  254.  
  255.                             if (obj.getMapAreaId() != -1) {
  256.                                 dat.writeByte(82);
  257.                                 dat.writeShort(obj.getMapAreaId());
  258.                             }
  259.  
  260.                             dat.writeByte(0);
  261.  
  262.                             int end = dat.size();
  263.  
  264.                             idx.writeShort(end - start);
  265.  
  266.                             double progress = ((double) (index + 1) / list.size()) * 100;
  267.  
  268.                             updateMessage(String.format("%.2f%s", progress, "%"));
  269.                             updateProgress((index + 1), list.size());
  270.  
  271.                         }
  272.  
  273.                         Platform.runLater(() -> {
  274.                             Dialogue.openDirectory("Would you like to view these files?", dir);
  275.                         });
  276.  
  277.                         System.out.println(String.format("Dumped %d Object Definitions into 317 format.", list.size()));
  278.  
  279.                     } catch(Exception ex) {
  280.                         ex.printStackTrace();
  281.                     }
  282.  
  283.                 }
  284.                 return null;
  285.             }
  286.  
  287.         });
  288.  
  289.     }
Advertisement
Add Comment
Please, Sign In to add comment