Skip to content

Commit 2cade7d

Browse files
committed
fix: fix tellTarget handling on old AS version
1 parent e5142a4 commit 2cade7d

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ protected void finalProcess(GraphTargetItem parent, List<GraphTargetItem> list,
355355
SetTargetActionItem st = (SetTargetActionItem) it;
356356
if (st.target.isEmpty()) {
357357
if (targetStart > -1) {
358-
targetEnd = t;
359-
break;
358+
targetEnd = t;
359+
break;
360360
}
361361
} else {
362362
target = new DirectValueActionItem(null, null, 0, st.target, new ArrayList<>());
@@ -378,8 +378,8 @@ protected void finalProcess(GraphTargetItem parent, List<GraphTargetItem> list,
378378
}
379379
if ((st.target instanceof DirectValueActionItem) && st.target.getResult().equals("")) {
380380
if (targetStart > -1) {
381-
targetEnd = t;
382-
break;
381+
targetEnd = t;
382+
break;
383383
}
384384
} else {
385385
targetStart = t;
@@ -433,6 +433,8 @@ protected void finalProcess(GraphTargetItem parent, List<GraphTargetItem> list,
433433
targetStartItem = st;
434434
target = new DirectValueActionItem(null, null, 0, st.target, new ArrayList<>());
435435
}
436+
} else if (targetStart > -1) {
437+
targetEnd = t;
436438
}
437439
}
438440
if (it instanceof SetTarget2ActionItem) {
@@ -445,8 +447,14 @@ protected void finalProcess(GraphTargetItem parent, List<GraphTargetItem> list,
445447
targetStartItem = st;
446448
target = st.target;
447449
}
450+
} else if (targetStart > -1) {
451+
targetEnd = t;
448452
}
449453
}
454+
455+
if (it instanceof TellTargetActionItem && targetStart > -1) {
456+
targetEnd = t;
457+
}
450458

451459
if (targetStart > -1 && targetEnd > -1) {
452460
List<GraphTargetItem> newlist = new ArrayList<>();
@@ -459,15 +467,15 @@ protected void finalProcess(GraphTargetItem parent, List<GraphTargetItem> list,
459467
}
460468
newlist.add(new TellTargetActionItem(targetStartItem.getSrc(), targetStartItem.getLineStartItem(), target, tellist));
461469
//TODO: maybe set nested flag
462-
for (int i = targetEnd + 1; i < list.size(); i++) {
470+
for (int i = targetEnd + (it instanceof TellTargetActionItem ? 0 : 1); i < list.size(); i++) {
463471
newlist.add(list.get(i));
464472
}
465473
list.clear();
466474
list.addAll(newlist);
467475
targetStart = -1;
468476
targetEnd = -1;
469477
target = null;
470-
t = 0;
478+
t = -1;
471479
}
472480
}
473481
for (int t = 1/*not first*/; t < list.size(); t++) {

libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,4 +627,23 @@ public void testVariableCompoundDup() {
627627
assertEquals(res, "c += 1;");
628628
}
629629

630+
@Test
631+
public void testTellTarget() {
632+
String res = decompilePcode("SetTarget \"\"\n"
633+
+ "GotoFrame 1\n"
634+
+ "SetTarget \"../test\"\n"
635+
+ "GoToLabel \"MyLabel\"\n"
636+
+ "Play");
637+
res = cleanPCode(res);
638+
assertEquals(res, "tellTarget(\"\")\n"
639+
+ "{\n"
640+
+ "gotoAndStop(2);\n"
641+
+ "}\n"
642+
+ "tellTarget(\"../test\")\n"
643+
+ "{\n"
644+
+ "gotoAndStop(\"MyLabel\");\n"
645+
+ "play();\n"
646+
+ "}");
647+
}
648+
630649
}

0 commit comments

Comments
 (0)