diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d6d648212..3c2c5af954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ All notable changes to this project will be documented in this file. - [#2314] AS3 direct editation - cannot save class initializer in some cases - [#2315] AS3 direct editation - switching scripts during editation causing missing scripts - [#2316] AS3 direct editation - private classes +- [#2317] AS3 direct editation - local register names colliding with parameter names ## [21.0.5] - 2024-09-05 ### Fixed @@ -3588,6 +3589,7 @@ Major version of SWF to XML export changed to 2. [#2314]: https://www.free-decompiler.com/flash/issues/2314 [#2315]: https://www.free-decompiler.com/flash/issues/2315 [#2316]: https://www.free-decompiler.com/flash/issues/2316 +[#2317]: https://www.free-decompiler.com/flash/issues/2317 [#2293]: https://www.free-decompiler.com/flash/issues/2293 [#2294]: https://www.free-decompiler.com/flash/issues/2294 [#2299]: https://www.free-decompiler.com/flash/issues/2299 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index 49b40e01a3..4b25806122 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -1209,21 +1209,32 @@ public int method(boolean isStatic, int name_index, boolean subMethod, boolean i String varName = n.getVariableName(); if (!needsActivation) { Matcher m = pat.matcher(varName); - //In first round, make all register that match standard loc_xx register + boolean addNew = false; + //In first round, make all register that match standard loc_xx register if ((round == 1) && (m.matches())) { String regIndexStr = m.group(1); int regIndex = Integer.parseInt(regIndexStr); - while (registerNames.size() <= regIndex) { - registerNames.add(UNUSED); - registerTypes.add(TypeItem.UNBOUNDED); - registerLines.add(paramLine); + + boolean alreadyExistsWithDifferentName = regIndex < registerNames.size() + && !registerNames.get(regIndex).equals(UNUSED) + && !registerNames.get(regIndex).equals(varName); + + if (alreadyExistsWithDifferentName) { + addNew = true; + } else { + while (registerNames.size() <= regIndex) { + registerNames.add(UNUSED); + registerTypes.add(TypeItem.UNBOUNDED); + registerLines.add(paramLine); + } + registerNames.set(regIndex, varName); + registerTypes.set(regIndex, n.type); + registerLines.set(regIndex, n.line); } - registerNames.set(regIndex, varName); - registerTypes.set(regIndex, n.type); - registerLines.set(regIndex, n.line); - } else if (round == 2 && !m.matches()) { //in second round the rest - + addNew = true; + } + if (addNew) { //search for some unused indices first: int newRegIndex = -1; for (int j = 0; j < registerNames.size(); j++) {