sprite export fix (missing objects)

This commit is contained in:
honfika@gmail.com
2015-04-07 13:56:25 +02:00
parent 073fc4d064
commit 0d847f2d13
33 changed files with 179 additions and 53 deletions

View File

@@ -371,6 +371,12 @@ public final class SWF implements SWFContainerItem, Timelined {
return getCharacters().get(characterId);
}
public String getExportName(int characterId) {
CharacterTag characterTag = getCharacters().get(characterId);
String exportName = characterTag != null ? characterTag.getExportName() : null;
return exportName;
}
public FontTag getFont(int fontId) {
CharacterTag characterTag = getCharacters().get(fontId);
if (characterTag instanceof FontTag) {
@@ -512,7 +518,14 @@ public final class SWF implements SWFContainerItem, Timelined {
private void parseCharacters(List<Tag> list, Map<Integer, CharacterTag> characters) {
for (Tag t : list) {
if (t instanceof CharacterTag) {
characters.put(((CharacterTag) t).getCharacterId(), (CharacterTag) t);
int characterId = ((CharacterTag) t).getCharacterId();
if (characters.containsKey(characterId)) {
logger.log(Level.SEVERE, "SWF already contains characterId={0}", characterId);
}
if (characterId != 0) {
characters.put(characterId, (CharacterTag) t);
}
}
if (t instanceof DefineSpriteTag) {
parseCharacters(((DefineSpriteTag) t).getSubTags(), characters);
@@ -1940,10 +1953,11 @@ public final class SWF implements SWFContainerItem, Timelined {
cnt++;
informListeners("rename", "class " + cnt + "/" + classCount);
DoInitActionTag dia = (DoInitActionTag) t;
String exportName = characters.containsKey(dia.spriteId) ? characters.get(dia.spriteId).getExportName() : "_unk_";
String exportName = getExportName(dia.spriteId);
exportName = exportName != null ? exportName : "_unk_";
final String pkgPrefix = "__Packages.";
String[] classNameParts = null;
if ((exportName != null) && exportName.startsWith(pkgPrefix)) {
if (exportName.startsWith(pkgPrefix)) {
String className = exportName.substring(pkgPrefix.length());
if (className.contains(".")) {
classNameParts = className.split("\\.");

View File

@@ -83,17 +83,14 @@ import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.action.swf4.ActionIf;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.AndItem;
import com.jpexs.decompiler.graph.model.BinaryOp;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.BlockItem;
import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.CommaExpressionItem;
@@ -101,7 +98,6 @@ import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.DoWhileItem;
import com.jpexs.decompiler.graph.model.ForItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.decompiler.graph.model.NotItem;
import com.jpexs.decompiler.graph.model.OrItem;
import com.jpexs.decompiler.graph.model.ParenthesisItem;

View File

@@ -35,7 +35,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceAIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceSIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertBIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertDIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertIIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertUIns;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;

View File

@@ -128,7 +128,6 @@ import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.model.AndItem;
import com.jpexs.decompiler.graph.model.BinaryOp;
import com.jpexs.decompiler.graph.model.BlockItem;
import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.CommaExpressionItem;

View File

@@ -51,6 +51,10 @@ public class BinaryDataExporter {
count++;
}
}
if (count == 0) {
return ret;
}
int currentIndex = 1;
for (final Tag t : tags) {

View File

@@ -71,6 +71,10 @@ public class FontExporter {
}
}
if (count == 0) {
return ret;
}
int currentIndex = 1;
for (Tag t : tags) {
if (t instanceof FontTag) {

View File

@@ -56,6 +56,10 @@ public class ImageExporter {
}
}
if (count == 0) {
return ret;
}
int currentIndex = 1;
for (Tag t : tags) {
if (t instanceof ImageTag) {

View File

@@ -66,6 +66,10 @@ public class MorphShapeExporter {
}
}
if (count == 0) {
return ret;
}
int currentIndex = 1;
for (final Tag t : tags) {
if (t instanceof MorphShapeTag) {

View File

@@ -64,6 +64,10 @@ public class MovieExporter {
}
}
if (count == 0) {
return ret;
}
int currentIndex = 1;
for (Tag t : tags) {
if (t instanceof DefineVideoStreamTag) {

View File

@@ -71,6 +71,10 @@ public class ShapeExporter {
}
}
if (count == 0) {
return ret;
}
int currentIndex = 1;
for (final Tag t : tags) {
if (t instanceof ShapeTag) {

View File

@@ -67,6 +67,10 @@ public class SoundExporter {
}
}
if (count == 0) {
return ret;
}
int currentIndex = 1;
for (Tag t : tags) {
if (t instanceof SoundTag) {

View File

@@ -65,6 +65,10 @@ public class TextExporter {
}
}
if (count == 0) {
return ret;
}
int currentIndex = 1;
if (settings.mode == TextExportMode.SVG) {
for (Tag t : tags) {

View File

@@ -267,6 +267,7 @@ public class DefineButton2Tag extends ButtonTag implements ASMSourceContainer {
if (timeline != null) {
return timeline;
}
timeline = new Timeline(swf, this, new ArrayList<Tag>(), buttonId, getRect());
int maxDepth = 0;
@@ -300,18 +301,25 @@ public class DefineButton2Tag extends ButtonTag implements ASMSourceContainer {
}
}
timeline.addFrame(frameUp);
if (frameOver.layers.isEmpty()) {
frameOver = frameUp;
}
timeline.addFrame(frameOver);
if (frameDown.layers.isEmpty()) {
frameDown = frameOver;
}
timeline.addFrame(frameDown);
if (frameHit.layers.isEmpty()) {
frameHit = frameUp;
}
timeline.addFrame(frameHit);
return timeline;
}

View File

@@ -20,7 +20,6 @@ import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.CharacterIdTag;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.SOUNDINFO;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
@@ -34,7 +33,7 @@ import java.io.OutputStream;
*
* @author JPEXS
*/
public class DefineButtonSoundTag extends CharacterTag {
public class DefineButtonSoundTag extends Tag implements CharacterIdTag {
@SWFType(BasicType.UI16)
public int buttonId;

View File

@@ -194,8 +194,7 @@ public class DoInitActionTag extends Tag implements CharacterIdTag,ASMSource {
@Override
public String getExportFileName() {
CharacterTag sprite=swf.getCharacter(spriteId);
String expName = sprite!=null?sprite.getExportName():null;
String expName = swf.getExportName(spriteId);
if ((expName == null) || expName.isEmpty()) {
return super.getExportFileName();
}
@@ -210,8 +209,7 @@ public class DoInitActionTag extends Tag implements CharacterIdTag,ASMSource {
@Override
public String getName() {
CharacterTag sprite=swf.getCharacter(spriteId);
String expName = sprite!=null?sprite.getExportName():null;
String expName = swf.getExportName(spriteId);
if ((expName == null) || expName.isEmpty()) {
return super.getName();
}

View File

@@ -27,7 +27,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class RemoveObject2Tag extends Tag implements RemoveTag {
public class RemoveObject2Tag extends RemoveTag {
@SWFType(BasicType.UI16)
public int depth;

View File

@@ -33,7 +33,7 @@ import java.io.OutputStream;
*
* @author JPEXS
*/
public class RemoveObjectTag extends Tag implements CharacterIdTag,RemoveTag {
public class RemoveObjectTag extends RemoveTag implements CharacterIdTag {
/**
* ID of character to place

View File

@@ -19,8 +19,6 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.CharacterIdTag;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.tags.base.SoundStreamHeadTypeTag;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.Conditional;
@@ -41,7 +39,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class SoundStreamHead2Tag extends CharacterTag implements SoundStreamHeadTypeTag {
public class SoundStreamHead2Tag extends Tag implements SoundStreamHeadTypeTag {
@Reserved
@SWFType(value = BasicType.UB, count = 4)
@@ -239,4 +237,10 @@ public class SoundStreamHead2Tag extends CharacterTag implements SoundStreamHead
final int[] rateMap = {5512, 11025, 22050, 44100};
return new SoundFormat(getSoundFormatId(), rateMap[getSoundRate()], getSoundType());
}
@Override
public String getCharacterExportFileName() {
String exportName = swf.getExportName(getCharacterId());
return getCharacterId() + (exportName != null ? "_" + exportName : "");
}
}

View File

@@ -19,8 +19,6 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.CharacterIdTag;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.tags.base.SoundStreamHeadTypeTag;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.Conditional;
@@ -41,7 +39,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class SoundStreamHeadTag extends CharacterTag implements SoundStreamHeadTypeTag {
public class SoundStreamHeadTag extends Tag implements SoundStreamHeadTypeTag {
@Reserved
@SWFType(value = BasicType.UB, count = 4)
@@ -263,5 +261,9 @@ public class SoundStreamHeadTag extends CharacterTag implements SoundStreamHeadT
return new SoundFormat(getSoundFormatId(), rateMap[getSoundRate()], getSoundType());
}
@Override
public String getCharacterExportFileName() {
String exportName = swf.getExportName(getCharacterId());
return getCharacterId() + (exportName != null ? "_" + exportName : "");
}
}

View File

@@ -74,11 +74,32 @@ public abstract class PlaceObjectTypeTag extends Tag implements CharacterIdTag {
@Override
public String getName() {
return super.getName() + " Depth: " + getDepth();
String result = super.getName();
String exportName = swf.getExportName(getCharacterId());
String nameAppend = "";
if (exportName != null) {
nameAppend = ": " + exportName;
}
if (getCharacterId() != -1) {
result += " (" + getCharacterId() + nameAppend + ")";
}
if (!nameAppend.isEmpty()) {
result += " (" + nameAppend + ")";
}
return result + " Depth: " + getDepth();
}
@Override
public String getExportFileName() {
return super.getExportFileName() + "_" + getDepth();
String result = super.getExportFileName() + "_" + getCharacterId() + "_" + getDepth();
String exportName = swf.getExportName(getCharacterId());
if (exportName != null) {
result += "_" + exportName;
}
result += "_" + getDepth();
return result;
}
}

View File

@@ -12,14 +12,67 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.tags.base;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.helpers.ByteArrayRange;
/**
*
* @author JPEXS
*/
*/
public abstract class RemoveTag extends Tag {
public RemoveTag(SWF swf, int id, String name, ByteArrayRange data) {
super(swf, id, name, data);
}
public abstract int getDepth();
@Override
public String getName() {
String result = super.getName();
String exportName = swf.getExportName(getCharacterId());
String nameAppend = "";
if (exportName != null) {
nameAppend = ": " + exportName;
}
if (getCharacterId() != -1) {
result += " (" + getCharacterId() + nameAppend + ")";
}
if (!nameAppend.isEmpty()) {
result += " (" + nameAppend + ")";
}
return result + " Depth: " + getDepth();
}
@Override
public String getExportFileName() {
String result = super.getExportFileName();
if (getCharacterId() != -1) {
result += "_" + getCharacterId();
}
String exportName = swf.getExportName(getCharacterId());
if (exportName != null) {
result += "_" + exportName;
}
result += "_" + getDepth();
return result;
}
private int getCharacterId() {
if (this instanceof CharacterIdTag) {
return ((CharacterIdTag) this).getCharacterId();
}
return -1;
}
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.tags.base;
import com.jpexs.decompiler.flash.tags.SoundStreamBlockTag;
@@ -22,7 +23,7 @@ import java.util.List;
*
* @author JPEXS
*/
*/
public interface SoundStreamHeadTypeTag extends CharacterIdTag, SoundTag {
@Override
public boolean getSoundSize();

View File

@@ -360,9 +360,9 @@ public class Timeline {
for (ASMSource asm : asmSources) {
if (asm instanceof DoInitActionTag) {
DoInitActionTag initAction = (DoInitActionTag) asm;
CharacterTag cht=swf.getCharacter(initAction.spriteId);
String path = cht!=null?cht.getExportName():"_unk_";
if (path == null || path.isEmpty()) {
String path = swf.getExportName(initAction.spriteId);
path = path != null ? path : "_unk_";
if (path.isEmpty()) {
path = initAction.getExportFileName();
}

View File

@@ -2728,10 +2728,9 @@ public class XFLConverter {
DefineSpriteTag sprite = (DefineSpriteTag) characters.get(chid);
if (sprite.subTags.isEmpty()) {
String data = convertActionScript(dia);
CharacterTag spr = dia.getSwf().getCharacter(dia.spriteId);
String expName = spr != null ? spr.getExportName() : "_unk_";
String expPath = spr.getExportName();
String expName = dia.getSwf().getExportName(dia.spriteId);
expName = expName != null ? expName : "_unk_";
String expPath = expName;
final String prefix = "__Packages.";
if (expPath.startsWith(prefix)) {
expPath = expPath.substring(prefix.length());