コード例 #1
0
ファイル: AssetExtractor.java プロジェクト: GenialPP/disunity
  public void extract(boolean raw) throws IOException {
    List<ObjectPath> paths = asset.getPaths();
    Deserializer deser = new Deserializer(asset);

    for (AssetExtractHandler extractHandler : extractHandlerMap.values()) {
      extractHandler.setAssetFile(asset);
      extractHandler.setOutputDir(outputDir);
    }

    for (ObjectPath path : paths) {
      // skip filtered classes
      if (cf != null && !cf.accept(path)) {
        continue;
      }

      String className = ClassID.getNameForID(path.getClassID(), true);

      // write just the serialized object data or parsed and extracted content?
      if (raw) {
        String assetFileName = String.format("%06d.bin", path.getPathID());
        Path classDir = outputDir.resolve(className);
        if (Files.notExists(classDir)) {
          Files.createDirectories(classDir);
        }

        Path assetFile = classDir.resolve(assetFileName);

        L.log(Level.INFO, "Writing {0} {1}", new Object[] {className, assetFileName});

        ByteBuffer bbAsset = asset.getPathBuffer(path);

        try {
          ByteBufferUtils.save(assetFile, bbAsset);
        } catch (Exception ex) {
          L.log(Level.WARNING, "Can't write " + path + " to " + assetFile, ex);
        }
      } else {
        AssetExtractHandler handler = getHandler(className);

        if (handler != null) {
          UnityObject obj;

          try {
            obj = deser.deserialize(path);
          } catch (Exception ex) {
            L.log(Level.WARNING, "Can't deserialize " + path, ex);
            continue;
          }

          try {
            handler.setObjectPath(path);
            handler.extract(obj);
          } catch (Exception ex) {
            L.log(Level.WARNING, "Can't extract " + path, ex);
          }
        }
      }
    }
  }
コード例 #2
0
ファイル: AssetExtractor.java プロジェクト: GenialPP/disunity
  /**
   * Tries to get the name of an object by deserializing it and looking for the field "m_Name". If
   * it exists, return its value.
   *
   * @param asset asset file
   * @param path object path
   * @return Name string of the object or null if it doesn't have a name or if the deserialization
   *     failed.
   */
  public static String getObjectName(AssetFile asset, ObjectPath path) {
    Deserializer deser = new Deserializer(asset);
    String name = null;

    try {
      UnityObject obj = deser.deserialize(path);
      name = obj.getValue("m_Name");
    } catch (OutOfMemoryError ex) {
      // Deserializer choked on an array size and clogged the heap, try
      // to clean up this mess
      deser = null;
      System.gc();
    } catch (Throwable ex) {
    }

    return name;
  }