diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index f9b5d0033..1829801f4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -102,6 +102,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; @@ -1211,7 +1212,7 @@ public class XFLConverter { return new Date().getTime() / 1000; } - public static String convertLibrary(SWF swf, Map characterVariables, Map characterClasses, List oneInstanceShapes, String backgroundColor, List tags, HashMap characters, HashMap files) { + public static String convertLibrary(SWF swf, Map characterVariables, Map characterClasses, List oneInstanceShapes, String backgroundColor, List tags, HashMap characters, HashMap files, HashMap datfiles) { //TODO: Imported assets //linkageImportForRS="true" linkageIdentifier="xxx" linkageURL="yyy.swf" @@ -1270,7 +1271,7 @@ public class XFLConverter { if (i == 1) { symbolStr += " current=\"true\" isSelected=\"true\""; } - symbolStr += ">"; //color=\"#4FFF4F\" + symbolStr += " color=\"" + randomOutlineColor() + "\">"; symbolStr += ""; int lastFrame = 0; loopframes: @@ -1311,9 +1312,9 @@ public class XFLConverter { MATRIX matrix = rec.placeMatrix; String recCharStr = ""; if (character instanceof TextTag) { - recCharStr = convertText(tags, (TextTag) character, matrix, filters); + recCharStr = convertText(null, tags, (TextTag) character, matrix, filters); } else if (character instanceof DefineVideoStreamTag) { - recCharStr = convertVideoInstance(matrix, (DefineVideoStreamTag) character); + recCharStr = convertVideoInstance(null, matrix, (DefineVideoStreamTag) character); } else { recCharStr = convertSymbolInstance(null, matrix, null, colorTransformAlpha, false, blendMode, filters, true, null, characters.get(rec.characterId), characters, tags); } @@ -1583,22 +1584,45 @@ public class XFLConverter { Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, null, ex); } String symbolFile = "movie" + symbol.getCharacterID() + "." + "flv"; - files.put(symbolFile, data); - String mediaLinkStr = ""; + //Use the dat file, otherwise it does not work + datfiles.put(datFileName, new byte[]{ //Magic numbers, if anybody knows why, please tell me + (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA0, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x78, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x59, (byte) 0x40, (byte) 0x18, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xFF, (byte) 0xFE, (byte) 0xFF, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 + }); + } else { + files.put(symbolFile, data); + mediaLinkStr = ""; + private static String convertVideoInstance(String instanceName, MATRIX matrix, DefineVideoStreamTag video) { + String ret = "" + ret = "" + "" + ret + "" @@ -2036,13 +2064,24 @@ public class XFLConverter { ret += convertFrame(false, characters, tags, lastSoundStreamHead, lastStartSound, frame, null, false, duration, "", ""); } if (!ret.equals("")) { - ret = "" + ret = "" + "" + ret + "" + ""; } return ret; } + private static String randomOutlineColor() { + RGB outlineColor = new RGB(); + Random rnd = new Random(); + do { + outlineColor.red = rnd.nextInt(256); + outlineColor.green = rnd.nextInt(256); + outlineColor.blue = rnd.nextInt(256); + } while ((outlineColor.red + outlineColor.green + outlineColor.blue) / 3 < 128); + return outlineColor.toHexRGB(); + } + public static String convertTimeline(int spriteId, List oneInstanceShapes, String backgroundColor, List tags, List timelineTags, HashMap characters, String name) { String ret = ""; ret += ""; @@ -2059,7 +2098,7 @@ public class XFLConverter { parentLayers.push(index); } - ret += " tags, TextTag tag, MATRIX matrix, List filters) { + public static String convertText(String instanceName, List tags, TextTag tag, MATRIX matrix, List filters) { String ret = ""; if (matrix == null) { matrix = new MATRIX(); @@ -2232,6 +2272,9 @@ public class XFLConverter { if (fontRenderingMode != null) { ret += " fontRenderingMode=\"" + fontRenderingMode + "\""; } + if (instanceName != null) { + ret += " instanceName=\"" + xmlString(instanceName) + "\""; + } ret += antiAlias; ret += " width=\"" + tag.getBounds().getWidth() / 2 + "\" height=\"" + tag.getBounds().getHeight() + "\" autoExpand=\"true\" isSelectable=\"false\">"; ret += matStr; @@ -2333,6 +2376,9 @@ public class XFLConverter { if (fontRenderingMode != null) { ret += " fontRenderingMode=\"" + fontRenderingMode + "\""; } + if (instanceName != null) { + ret += " name=\"" + xmlString(instanceName) + "\""; + } ret += antiAlias; double width = twipToPixel(bounds.getWidth()); double height = twipToPixel(bounds.getHeight()); @@ -2471,6 +2517,7 @@ public class XFLConverter { baseName = baseName.substring(0, baseName.lastIndexOf(".")); } HashMap files = new HashMap<>(); + HashMap datfiles = new HashMap<>(); HashMap characters = getCharacters(swf.tags); List oneInstaceShapes = getOneInstanceShapes(swf.tags, characters); Map characterClasses = getCharacterClasses(swf.tags); @@ -2510,7 +2557,7 @@ public class XFLConverter { } domDocument += ">"; - domDocument += convertLibrary(swf, characterVariables, characterClasses, oneInstaceShapes, backgroundColor, swf.tags, characters, files); + domDocument += convertLibrary(swf, characterVariables, characterClasses, oneInstaceShapes, backgroundColor, swf.tags, characters, files, datfiles); domDocument += ""; domDocument += convertTimeline(0, oneInstaceShapes, backgroundColor, swf.tags, swf.tags, characters, "Scene 1"); domDocument += ""; @@ -2769,6 +2816,10 @@ public class XFLConverter { out.putNextEntry(new ZipEntry("LIBRARY/" + fileName)); out.write(files.get(fileName)); } + for (String fileName : datfiles.keySet()) { + out.putNextEntry(new ZipEntry("bin/" + fileName)); + out.write(datfiles.get(fileName)); + } } catch (IOException ex) { Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, null, ex); } @@ -2788,9 +2839,14 @@ public class XFLConverter { } File libraryDir = new File(outDir.getAbsolutePath() + File.separator + "LIBRARY"); libraryDir.mkdir(); + File binDir = new File(outDir.getAbsolutePath() + File.separator + "bin"); + binDir.mkdir(); for (String fileName : files.keySet()) { writeFile(files.get(fileName), libraryDir.getAbsolutePath() + File.separator + fileName); } + for (String fileName : datfiles.keySet()) { + writeFile(datfiles.get(fileName), binDir.getAbsolutePath() + File.separator + fileName); + } try { writeFile("PROXY-CS5".getBytes("utf-8"), outfile); } catch (UnsupportedEncodingException ex) {