Skip to content

Commit

Permalink
Fixed #1961 Characters can use characterId 0, PlaceObject can use dep…
Browse files Browse the repository at this point in the history
…th 0

Changed #1961 SoundStreamHead on main timeline is exported/imported with identifier "-1"
  • Loading branch information
jindrapetrik committed Feb 12, 2023
1 parent d2c15e4 commit aaa3548
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ All notable changes to this project will be documented in this file.
### Fixed
- [#1960] Hide tag tree root handles as it was in previous versions
- [#1964] Freezing on releasing mouse while shape transforming (deadlock)
- [#1961] Characters can use characterId 0, PlaceObject can use depth 0

### Changed
- [#1960] Quick search does not search in SWF name or folder names
- [#1961] SoundStreamHead on main timeline is exported/imported with identifier "-1"

## [18.3.4] - 2023-01-30
### Added
Expand Down Expand Up @@ -2939,6 +2941,7 @@ All notable changes to this project will be documented in this file.
[alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7
[#1960]: https://www.free-decompiler.com/flash/issues/1960
[#1964]: https://www.free-decompiler.com/flash/issues/1964
[#1961]: https://www.free-decompiler.com/flash/issues/1961
[#1029]: https://www.free-decompiler.com/flash/issues/1029
[#1948]: https://www.free-decompiler.com/flash/issues/1948
[#1941]: https://www.free-decompiler.com/flash/issues/1941
Expand Down
6 changes: 2 additions & 4 deletions libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,8 @@ private void parseCharacters(Iterable<Tag> list, Map<Integer, DefineExternalImag
logger.log(Level.SEVERE, "SWF already contains characterId={0}", characterId);
}

if (characterId != 0) {
characters.put(characterId, (CharacterTag) t);
characterIdTags.put(characterId, new ArrayList<>());
}
characters.put(characterId, (CharacterTag) t);
characterIdTags.put(characterId, new ArrayList<>());
} else if (characterIdTags.containsKey(characterId)) {
characterIdTags.get(characterId).add((CharacterIdTag) t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class SoundStreamHead2Tag extends SoundStreamHeadTypeTag {
public int latencySeek;

@Internal
private int virtualCharacterId = 0;
private int virtualCharacterId = -1;

/**
* Constructor
Expand Down Expand Up @@ -251,7 +251,7 @@ public void getTagInfo(TagInfo tagInfo) {

@Override
public String toString() {
return getName() + (virtualCharacterId > 0 ? " (" + virtualCharacterId + ")" : "");
return getName() + " (" + virtualCharacterId + ")";
}

//getNeededCharacters intentionally not defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.jpexs.decompiler.flash.types.sound.SoundFormat;
import com.jpexs.helpers.ByteArrayRange;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -85,7 +84,7 @@ public class SoundStreamHeadTag extends SoundStreamHeadTypeTag {
public int latencySeek;

@Internal
private int virtualCharacterId = 0;
private int virtualCharacterId = -1;

/**
* Constructor
Expand Down Expand Up @@ -261,7 +260,7 @@ public void getTagInfo(TagInfo tagInfo) {

@Override
public String toString() {
return getName() + (virtualCharacterId > 0 ? " (" + virtualCharacterId + ")" : "");
return getName() + " (" + virtualCharacterId + ")";
}

//getNeededCharacters intentionally not defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class DefineExternalStreamSound extends Tag implements CharacterIdTag, So
public static final int SOUND_FORMAT_WAV = 0;

@Internal
private int virtualCharacterId = 0;
private int virtualCharacterId = -1;

/**
* Gets data bytes
Expand Down Expand Up @@ -243,7 +243,7 @@ public String getCharacterExportFileName() {

@Override
public String toString() {
return getName() + (virtualCharacterId > 0 ? " (" + virtualCharacterId + ")" : "");
return getName() + " (" + virtualCharacterId + ")";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,14 @@ private synchronized void initialize() {
createASPackages();
if (timelined instanceof SWF) {
// popuplate only for main timeline
populateSoundStreamBlocks(0, timelined.getTags());
populateSoundStreamBlocks(-1, timelined.getTags());
}

initialized = true;
}

private synchronized void detectTweens() {
for (int d = 1; d <= maxDepth; d++) {
for (int d = 0; d <= maxDepth; d++) {
int characterId = -1;
String charClassName = null;
int len = 0;
Expand Down Expand Up @@ -486,7 +486,7 @@ private synchronized void detectTweens() {

private synchronized void calculateMaxDepthFrames() {
depthMaxFrame.clear();
for (int d = 1; d <= maxDepth; d++) {
for (int d = 0; d <= maxDepth; d++) {
for (int f = frames.size() - 1; f >= 0; f--) {
if (frames.get(f).layers.get(d) != null) {
depthMaxFrame.put(d, f);
Expand Down Expand Up @@ -1037,7 +1037,7 @@ public void toImage(int frame, int time, RenderContext renderContext, Serializab

int maxDepth = getMaxDepth();
int clipCount = 0;
for (int i = 1; i <= maxDepth; i++) {
for (int i = 0; i <= maxDepth; i++) {
boolean clipChanged = clipCount != clips.size();
for (int c = 0; c < clips.size(); c++) {
if (clips.get(c).depth < i) {
Expand Down Expand Up @@ -1200,7 +1200,7 @@ public void toSVG(int frame, int time, DepthState stateUnderCursor, int mouseBut
int maxDepth = getMaxDepth();
int clipCount = 0;
Element clipGroup = null;
for (int i = 1; i <= maxDepth; i++) {
for (int i = 0; i <= maxDepth; i++) {
boolean clipChanged = clipCount != clips.size();
for (int c = 0; c < clips.size(); c++) {
if (clips.get(c).depth < i) {
Expand Down Expand Up @@ -1422,7 +1422,7 @@ public boolean isSingleFrame() {

public boolean isSingleFrame(int frame) {
Frame frameObj = getFrame(frame);
for (int i = 1; i <= maxDepth; i++) {
for (int i = 0; i <= maxDepth; i++) {
if (!frameObj.layers.containsKey(i)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ private static String removeOnlyStrokeEdgesBeforeSameFilled(String layer) {
return layer;
}

private static int getLayerCount(ReadOnlyTagList tags) {
private static int getMaxDepth(ReadOnlyTagList tags) {
int maxDepth = 0;
for (Tag t : tags) {
if (t instanceof PlaceObjectTypeTag) {
Expand Down Expand Up @@ -2944,7 +2944,7 @@ private void convertTimeline(AbcIndexing abcIndex, int spriteId, List<Integer> n
index++;
}

int layerCount = getLayerCount(timelineTags);
int maxDepth = getMaxDepth(timelineTags);

List<Integer> clipFrameSplitters = new ArrayList<>();
List<PlaceObjectTypeTag> clipPlaces = new ArrayList<>();
Expand Down Expand Up @@ -2995,13 +2995,13 @@ private void convertTimeline(AbcIndexing abcIndex, int spriteId, List<Integer> n
clipPlaces.add(null);

Map<Integer, List<Integer>> depthToFramesList = new HashMap<>();
for (int d = layerCount; d >= 1; d--) {
for (int d = maxDepth; d >= 0; d--) {
depthToFramesList.put(d, new ArrayList<>());
for (int i = 0; i < frameCount; i++) {
depthToFramesList.get(d).add(i);
}
}
for (int d = layerCount; d >= 1; d--) {
for (int d = maxDepth; d >= 0; d--) {

for (int p = 0; p < clipPlaces.size() - 1; p++) {
PlaceObjectTypeTag po = clipPlaces.get(p);
Expand Down Expand Up @@ -3054,8 +3054,8 @@ private void convertTimeline(AbcIndexing abcIndex, int spriteId, List<Integer> n
}
}

int soundLayerIndex = layerCount;
layerCount++;
int soundLayerIndex = maxDepth;
maxDepth++;
convertSoundLayer(soundLayerIndex, timelineTags, files, writer);
writer.writeEndElement();
writer.writeEndElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,12 @@ public static void printCmdLineUsage(PrintStream out, boolean webHelp, String fi

if (filter == null || filter.equals("replace")) {
out.println(" " + (cnt++) + ") -replace <infile> <outfile> (<characterId1>|<scriptName1>) <importDataFile1> [nofill] ([<format1>][<methodBodyIndex1>]) [(<characterId2>|<scriptName2>) <importDataFile2> [nofill] ([<format2>][<methodBodyIndex2>])]...");
out.println(" ...replaces the data of the specified BinaryData, Image, Shape, Text, DefineSound tag or Script");
out.println(" ...replaces the data of the specified BinaryData, Image, Shape, Text, Sound tag or Script");
out.println(" ...nofill parameter can be specified only for shape replace");
out.println(" ...<format> parameter can be specified for Image and Shape tags");
out.println(" ...valid formats: lossless, lossless2, jpeg2, jpeg3, jpeg4");
out.println(" ...<methodBodyIndexN> parameter should be specified if and only if the imported entity is an AS3 P-Code");
out.println(" ...use -1 as characterId to replace main timeline SoundStreamHead");

out.println(" " + (cnt++) + ") -replace <infile> <outfile> <argsfile>");
out.println(" ... same as -replace command, but the rest of arguments is read as lines from a text file <argsfile>");
Expand Down Expand Up @@ -3180,7 +3181,7 @@ private static void parseReplace(Stack<String> args, String charset, boolean air

SoundStreamHeadTypeTag soundStreamHead = null;
CharacterTag characterTag = null;
if (characterId == 0) {
if (characterId == -1) {
//replacing soundstreamhead on main timeline
} else if (swf.getCharacters().containsKey(characterId)) {
characterTag = swf.getCharacter(characterId);
Expand Down
2 changes: 1 addition & 1 deletion src/com/jpexs/decompiler/flash/gui/ImagePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3425,7 +3425,7 @@ private void drawFrame(Timer thisTimer, boolean display) {
first = false;
CharacterTag c = ds.getCharacter();
ret.append(c.toString());
if (ds.depth > 0) {
if (ds.depth > -1) {
ret.append(" ");
ret.append(AppStrings.translate("imagePanel.depth"));
ret.append(" ");
Expand Down

0 comments on commit aaa3548

Please sign in to comment.