mulptiple xlf export fix (separate output directory for each swf), show definebuttontag(1) actions in tree, image export fix (sometimes throws ArrumentOutOfBounds exception)

This commit is contained in:
2016-03-06 15:35:46 +01:00
parent 4d6aed7e3d
commit fa9623bf9f
7 changed files with 218 additions and 127 deletions
@@ -58,7 +58,7 @@ public class ImageHelper {
CMYKJPEGImageReader r = new CMYKJPEGImageReader(new CMYKJPEGImageReaderSpi());
r.setInput(iis);
in = r.read(0);
} catch (IOException ex) {
} catch (IOException | ArrayIndexOutOfBoundsException ex) {
try {
in = ImageIO.read(ImageIO.createImageInputStream(new ByteArrayInputStream(data)));
} catch (IOException ex1) {
@@ -16,17 +16,13 @@
*/
package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionList;
import com.jpexs.decompiler.flash.action.ConstantPoolTooBigException;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.flash.tags.base.ASMSourceContainer;
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
import com.jpexs.decompiler.flash.tags.base.ButtonAction;
import com.jpexs.decompiler.flash.tags.base.ButtonTag;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.timeline.DepthState;
@@ -42,9 +38,9 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.Cache;
import com.jpexs.helpers.Helper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
@@ -54,7 +50,7 @@ import java.util.Set;
* @author JPEXS
*/
@SWFVersion(from = 1)
public class DefineButtonTag extends ButtonTag implements ASMSource {
public class DefineButtonTag extends ButtonTag implements ASMSourceContainer {
public static final int ID = 7;
@@ -77,13 +73,6 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
@HideInRawEdit
public ByteArrayRange actionBytes;
private String scriptName = "-";
@Override
public String getScriptName() {
return scriptName;
}
/**
* Constructor
*
@@ -108,11 +97,6 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
readData(sis, data, 0, false, false, false);
}
@Override
public void setScriptName(String scriptName) {
this.scriptName = scriptName;
}
@Override
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
buttonId = sis.readUI16("buttonId");
@@ -131,7 +115,6 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
sos.writeUI16(buttonId);
sos.writeBUTTONRECORDList(characters, false);
sos.write(getActionBytes());
//sos.write(Action.actionsToBytes(actions, true, version));
}
@Override
@@ -149,75 +132,27 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
return characters;
}
/**
* Converts actions to ASM source
*
* @param exportMode PCode or hex?
* @param writer
* @param actions
* @return ASM source
* @throws java.lang.InterruptedException
*/
@Override
public GraphTextWriter getASMSource(ScriptExportMode exportMode, GraphTextWriter writer, ActionList actions) throws InterruptedException {
if (actions == null) {
actions = getActions();
}
return Action.actionsToString(listeners, 0, actions, swf.version, exportMode, writer);
public List<ButtonAction> getSubItems() {
return Arrays.asList(new ButtonAction(this));
}
/**
* Whether or not this object contains ASM source
*
* @return True when contains
*/
@Override
public boolean containsSource() {
return true;
}
/**
* Returns actions associated with this object
*
* @return List of actions
* @throws java.lang.InterruptedException
*/
@Override
public ActionList getActions() throws InterruptedException {
return SWF.getCachedActionList(this, listeners);
}
@Override
public void setActions(List<Action> actions) {
actionBytes = Action.actionsToByteArrayRange(actions, true, swf.version);
}
@Override
public ByteArrayRange getActionBytes() {
return actionBytes;
}
@Override
public void setActionBytes(byte[] actionBytes) {
this.actionBytes = new ByteArrayRange(actionBytes);
SWF.uncache(this);
}
@Override
public void setConstantPools(List<List<String>> constantPools) throws ConstantPoolTooBigException {
Action.setConstantPools(this, constantPools, false);
}
@Override
public void setModified() {
setModified(true);
}
@Override
public GraphTextWriter getActionBytesAsHex(GraphTextWriter writer) {
return Helper.byteArrayToHexWithHeader(writer, actionBytes.getRangeData());
}
@Override
public boolean replaceCharacter(int oldCharacterId, int newCharacterId) {
boolean modified = false;
@@ -286,18 +221,6 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
return rect;
}
List<DisassemblyListener> listeners = new ArrayList<>();
@Override
public void addDisassemblyListener(DisassemblyListener listener) {
listeners.add(listener);
}
@Override
public void removeDisassemblyListener(DisassemblyListener listener) {
listeners.remove(listener);
}
@Override
public boolean trackAsMenu() {
return false;
@@ -308,26 +231,6 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
return 1;
}
@Override
public GraphTextWriter getActionSourcePrefix(GraphTextWriter writer) {
return writer;
}
@Override
public GraphTextWriter getActionSourceSuffix(GraphTextWriter writer) {
return writer;
}
@Override
public int getPrefixLineCount() {
return 0;
}
@Override
public String removePrefixAndSuffix(String source) {
return source;
}
@Override
protected void initTimeline(Timeline timeline) {
ColorTransform clrTrans = null;
@@ -389,14 +292,4 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
timeline.addFrame(frameHit);
}
@Override
public Tag getSourceTag() {
return this;
}
@Override
public void setSourceTag(Tag t) {
//nothing
}
}
@@ -0,0 +1,188 @@
/*
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.tags.base;
import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionList;
import com.jpexs.decompiler.flash.action.ConstantPoolTooBigException;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.tags.DefineButtonTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.Helper;
import java.util.ArrayList;
import java.util.List;
/**
* Object containing ASM source
*
* @author JPEXS
*/
public class ButtonAction implements ASMSource {
List<DisassemblyListener> listeners = new ArrayList<>();
private String scriptName = "-";
private final DefineButtonTag buttonTag;
public ButtonAction(DefineButtonTag buttonTag) {
this.buttonTag = buttonTag;
}
/**
* Converts actions to ASM source
*
* @param exportMode PCode or hex?
* @param writer
* @param actions
* @return ASM source
* @throws java.lang.InterruptedException
*/
@Override
public GraphTextWriter getASMSource(ScriptExportMode exportMode, GraphTextWriter writer, ActionList actions) throws InterruptedException {
if (actions == null) {
actions = getActions();
}
return Action.actionsToString(listeners, 0, actions, getSwf().version, exportMode, writer);
}
/**
* Whether or not this object contains ASM source
*
* @return True when contains
*/
@Override
public boolean containsSource() {
return true;
}
/**
* Returns actions associated with this object
*
* @return List of actions
* @throws java.lang.InterruptedException
*/
@Override
public ActionList getActions() throws InterruptedException {
return SWF.getCachedActionList(this, listeners);
}
@Override
public void setActions(List<Action> actions) {
buttonTag.setActions(actions);
}
@Override
public void setModified() {
buttonTag.setModified();
}
@Override
public ByteArrayRange getActionBytes() {
return buttonTag.getActionBytes();
}
@Override
public void setActionBytes(byte[] actionBytes) {
buttonTag.setActionBytes(actionBytes);
SWF.uncache(this);
}
@Override
public void setConstantPools(List<List<String>> constantPools) throws ConstantPoolTooBigException {
Action.setConstantPools(this, constantPools, false);
}
@Override
public GraphTextWriter getActionBytesAsHex(GraphTextWriter writer) {
return Helper.byteArrayToHexWithHeader(writer, buttonTag.getActionBytes().getRangeData());
}
@Override
public void addDisassemblyListener(DisassemblyListener listener) {
listeners.add(listener);
}
@Override
public void removeDisassemblyListener(DisassemblyListener listener) {
listeners.remove(listener);
}
@Override
public GraphTextWriter getActionSourcePrefix(GraphTextWriter writer) {
return writer;
}
@Override
public GraphTextWriter getActionSourceSuffix(GraphTextWriter writer) {
return writer;
}
@Override
public int getPrefixLineCount() {
return 0;
}
@Override
public String removePrefixAndSuffix(String source) {
return source;
}
@Override
public Tag getSourceTag() {
return buttonTag;
}
@Override
public void setSourceTag(Tag t) {
}
@Override
public String getScriptName() {
return scriptName;
}
@Override
public void setScriptName(String scriptName) {
this.scriptName = scriptName;
}
@Override
public String getExportFileName() {
return buttonTag.getExportFileName();
}
@Override
public SWF getSwf() {
return buttonTag.getSwf();
}
@Override
public boolean isModified() {
return buttonTag.isModified();
}
@Override
public String toString() {
return buttonTag.toString();
}
}
@@ -56,6 +56,7 @@ import com.jpexs.decompiler.flash.tags.StartSoundTag;
import com.jpexs.decompiler.flash.tags.SymbolClassTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.flash.tags.base.ButtonAction;
import com.jpexs.decompiler.flash.tags.base.ButtonTag;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.tags.base.FontTag;
@@ -247,13 +248,7 @@ public class XFLConverter {
if (ls.width == 1) {
params.append(" solidStyle=\"hairline\"");
}
if ((!ls.noHScaleFlag) && (!ls.noVScaleFlag)) {
params.append(" scaleMode=\"normal\"");
} else if ((!ls.noHScaleFlag) && ls.noVScaleFlag) {
params.append(" scaleMode=\"horizontal\"");
} else if (ls.noHScaleFlag && (!ls.noVScaleFlag)) {
params.append(" scaleMode=\"vertical\"");
}
params.append(" scaleMode=\"").append(getScaleMode(ls)).append("\"");
switch (ls.endCapStyle) { //What about endCapStyle?
case LINESTYLE2.NO_CAP:
@@ -276,7 +271,7 @@ public class XFLConverter {
break;
}
ret.append("<SolidStroke scaleMode=\"").append(getScaleMode(ls)).append("\" weight=\"").append(((float) ls.width) / SWF.unitDivisor).append("\"");
ret.append("<SolidStroke weight=\"").append(((float) ls.width) / SWF.unitDivisor).append("\"");
ret.append(params);
ret.append(">");
ret.append("<fill>");
@@ -1148,7 +1143,7 @@ public class XFLConverter {
if (tag instanceof DefineButtonTag) {
ret.append("<Actionscript><script><![CDATA[");
ret.append("on(press){\r\n");
ret.append(convertActionScript(((DefineButtonTag) tag)));
ret.append(convertActionScript(new ButtonAction((DefineButtonTag) tag)));
ret.append("}");
ret.append("]]></script></Actionscript>");
}
@@ -20,5 +20,4 @@ public class DefaultItem extends GraphTargetItem {
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}