From e9a133058b60303ecfd553f7415a9fa8bf5ada76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Tue, 1 Nov 2022 20:01:22 +0100 Subject: [PATCH] Fixed Raw editor now checks whether field value can be placed inside this kind of tag --- CHANGELOG.md | 1 + .../decompiler/flash/types/BUTTONRECORD.java | 5 ++- .../flash/types/MORPHLINESTYLEARRAY.java | 5 +++ .../parser/ConditionEvaluator.java | 39 +++++++++++++++++-- .../decompiler/flash/gui/GenericTagPanel.java | 2 +- .../flash/gui/GenericTagTreePanel.java | 12 +++--- 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 265145c49..f85947558 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - Reloading SWF inside DefineBinaryData - Working with byte ranges - caused problems when cloning tags - All "mapped" tags have character id in parenthesis in the tag tree +- Raw editor now checks whether field value can be placed inside this kind of tag ## [16.0.1] - 2022-10-31 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONRECORD.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONRECORD.java index 078e7ec75..f00a86050 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONRECORD.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONRECORD.java @@ -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.types; import com.jpexs.decompiler.flash.tags.DefineButton2Tag; @@ -85,6 +86,7 @@ public class BUTTONRECORD implements Serializable { /** * If within DefineButton2Tag: Character color transform */ + @Conditional(tags = {DefineButton2Tag.ID}) public CXFORMWITHALPHA colorTransform; /** @@ -92,6 +94,7 @@ public class BUTTONRECORD implements Serializable { * this button */ @SWFArray("filter") + @Conditional(value = "buttonHasFilterList", tags = {DefineButton2Tag.ID}) public List filterList; /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MORPHLINESTYLEARRAY.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MORPHLINESTYLEARRAY.java index 16e8831ab..19b0efebd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MORPHLINESTYLEARRAY.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MORPHLINESTYLEARRAY.java @@ -16,6 +16,9 @@ */ package com.jpexs.decompiler.flash.types; +import com.jpexs.decompiler.flash.tags.DefineMorphShape2Tag; +import com.jpexs.decompiler.flash.tags.DefineMorphShapeTag; +import com.jpexs.decompiler.flash.types.annotations.Conditional; import java.io.Serializable; /** @@ -24,8 +27,10 @@ import java.io.Serializable; */ public class MORPHLINESTYLEARRAY implements Serializable { + @Conditional(tags = {DefineMorphShapeTag.ID}) public MORPHLINESTYLE[] lineStyles; + @Conditional(tags = {DefineMorphShape2Tag.ID}) public MORPHLINESTYLE2[] lineStyles2; public LINESTYLEARRAY getLineStylesAt(int shapeNum, int ratio) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/parser/ConditionEvaluator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/parser/ConditionEvaluator.java index 7fa83aea3..5055de1e2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/parser/ConditionEvaluator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/parser/ConditionEvaluator.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.types.annotations.Conditional; import com.jpexs.decompiler.flash.types.annotations.ConditionalType; import java.io.IOException; import java.io.StringReader; +import java.util.Arrays; import java.util.EmptyStackException; import java.util.HashSet; import java.util.Map; @@ -33,13 +34,19 @@ import java.util.Stack; public class ConditionEvaluator { private final String[] values; + private final int[] tags; + private final boolean revert; public ConditionEvaluator(Conditional cond) { values = cond.value(); + tags = cond.tags(); + revert = cond.revert(); } public ConditionEvaluator(ConditionalType cond) { values = cond.value(); + tags = cond.tags(); + revert = cond.revert(); } private void expressionRest(Map fields, Stack stack, ConditionLexer lex) throws IOException, AnnotationParseException { @@ -98,7 +105,25 @@ public class ConditionEvaluator { } } - public boolean eval(Map fields) throws AnnotationParseException { + public boolean eval(Map fields, int parentTagId) throws AnnotationParseException { + boolean result; + if (tags.length > 0) { + boolean tagFound = false; + for (int i = 0; i < tags.length; i++) { + if (tags[i] == parentTagId) { + tagFound = true; + break; + } + } + if (!tagFound) { + result = false; + if (revert) { + return !result; + } + return result; + } + } + ConditionLexer lex = new ConditionLexer(new StringReader(prepareCond())); Stack stack = new Stack<>(); @@ -109,13 +134,21 @@ public class ConditionEvaluator { throw new AnnotationParseException("Invalid condition:" + prepareCond(), lex.yyline()); } if (prepareCond().isEmpty()) { - return true; + result = true; + if (revert) { + return !result; + } + return result; } if (stack.size() != 1) { throw new AnnotationParseException("Invalid condition:" + prepareCond(), lex.yyline()); } - return stack.pop(); + result = stack.pop(); + if (revert) { + return !result; + } + return result; } private String prepareCond() { diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java index bd041f241..929aad817 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java @@ -571,7 +571,7 @@ public class GenericTagPanel extends JPanel implements ChangeListener { } } } - boolean ok = ev.eval(fields); + boolean ok = ev.eval(fields, tag.getId()); if (conditionMet) { conditionMet = ok; } diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java index 578e3c2ca..966cc579b 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java @@ -902,7 +902,7 @@ public class GenericTagTreePanel extends GenericTagPanel { private Object getChild(Object parent, int index, boolean limited) { if (parent == mtroot) { - return new FieldNode(mtroot, mtroot, filterFields(this, mtroot.getClass().getSimpleName(), mtroot.getClass(), limited).get(index), -1); + return new FieldNode(mtroot, mtroot, filterFields(this, mtroot.getClass().getSimpleName(), mtroot.getClass(), limited, mtroot.getId()).get(index), -1); } FieldNode fnode = (FieldNode) parent; Field field = fnode.fieldSet.get(FIELD_INDEX); @@ -910,7 +910,7 @@ public class GenericTagTreePanel extends GenericTagPanel { return new FieldNode(mtroot, fnode.obj, fnode.fieldSet, index); } parent = fnode.getValue(FIELD_INDEX); - return new FieldNode(mtroot, parent, filterFields(this, getNodePathName(fnode), parent.getClass(), limited).get(index), -1); + return new FieldNode(mtroot, parent, filterFields(this, getNodePathName(fnode), parent.getClass(), limited, mtroot.getId()).get(index), -1); } @Override @@ -925,7 +925,7 @@ public class GenericTagTreePanel extends GenericTagPanel { private int getChildCount(Object parent, boolean limited) { if (parent == mtroot) { - return filterFields(this, mtroot.getClass().getSimpleName(), mtroot.getClass(), limited).size(); + return filterFields(this, mtroot.getClass().getSimpleName(), mtroot.getClass(), limited, mtroot.getId()).size(); } FieldNode fnode = (FieldNode) parent; if (isLeaf(fnode)) { @@ -946,7 +946,7 @@ public class GenericTagTreePanel extends GenericTagPanel { } parent = fnode.getValue(FIELD_INDEX); - return filterFields(this, getNodePathName(fnode), parent.getClass(), limited).size(); + return filterFields(this, getNodePathName(fnode), parent.getClass(), limited, mtroot.getId()).size(); } @Override @@ -1109,7 +1109,7 @@ public class GenericTagTreePanel extends GenericTagPanel { } } - private static List
filterFields(MyTreeModel mod, String parentPath, Class cls, boolean limited) { + private static List
filterFields(MyTreeModel mod, String parentPath, Class cls, boolean limited, int parentTagId) { List
ret = new ArrayList<>(); List fields = getAvailableFields(cls); Map> tables = new HashMap<>(); @@ -1142,7 +1142,7 @@ public class GenericTagTreePanel extends GenericTagPanel { fieldMap.put(sf, true); } } - if (!ev.eval(fieldMap)) { + if (!ev.eval(fieldMap, parentTagId)) { continue; } } catch (AnnotationParseException | IllegalArgumentException | IllegalAccessException ex) {