mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-03 11:25:10 +00:00
Recompile test fixed for as2 and as3.swf
This commit is contained in:
@@ -12,9 +12,11 @@
|
||||
* 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;
|
||||
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsLosslessTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.types.ALPHABITMAPDATA;
|
||||
@@ -398,6 +400,11 @@ public class SWFOutputStream extends OutputStream {
|
||||
nBits = enlargeBitCountS(nBits, xMax);
|
||||
nBits = enlargeBitCountS(nBits, yMin);
|
||||
nBits = enlargeBitCountS(nBits, yMax);
|
||||
|
||||
if (Configuration.debugCopy.get()) {
|
||||
nBits = Math.max(nBits, value.nbits);
|
||||
}
|
||||
|
||||
writeUB(5, nBits);
|
||||
writeSB(nBits, xMin);
|
||||
writeSB(nBits, xMax);
|
||||
@@ -454,7 +461,7 @@ public class SWFOutputStream extends OutputStream {
|
||||
* @param v Signed value
|
||||
* @return Number of bits
|
||||
*/
|
||||
*/
|
||||
private static int getNeededBitsS(int v) {
|
||||
int counter = 32;
|
||||
int mask = 0x80000000;
|
||||
final int val = (v < 0) ? -v : v;
|
||||
@@ -525,6 +532,9 @@ public class SWFOutputStream extends OutputStream {
|
||||
}
|
||||
|
||||
public static int enlargeBitCountS(int currentBitCount, int value) {
|
||||
if (value == 0) {
|
||||
return currentBitCount;
|
||||
}
|
||||
int neededNew = getNeededBitsS(value);
|
||||
if (neededNew > currentBitCount) {
|
||||
return neededNew;
|
||||
@@ -533,6 +543,9 @@ public class SWFOutputStream extends OutputStream {
|
||||
}
|
||||
|
||||
public static int enlargeBitCountU(int currentBitCount, int value) {
|
||||
if (value == 0) {
|
||||
return currentBitCount;
|
||||
}
|
||||
int neededNew = getNeededBitsU(value);
|
||||
if (neededNew > currentBitCount) {
|
||||
return neededNew;
|
||||
@@ -552,6 +565,11 @@ public class SWFOutputStream extends OutputStream {
|
||||
int nBits = 0;
|
||||
nBits = enlargeBitCountS(nBits, value.scaleX);
|
||||
nBits = enlargeBitCountS(nBits, value.scaleY);
|
||||
|
||||
if (Configuration.debugCopy.get()) {
|
||||
nBits = Math.max(nBits, value.nScaleBits);
|
||||
}
|
||||
|
||||
writeUB(5, nBits);
|
||||
writeSB(nBits, value.scaleX);
|
||||
writeSB(nBits, value.scaleY);
|
||||
@@ -561,6 +579,11 @@ public class SWFOutputStream extends OutputStream {
|
||||
int nBits = 0;
|
||||
nBits = enlargeBitCountS(nBits, value.rotateSkew0);
|
||||
nBits = enlargeBitCountS(nBits, value.rotateSkew1);
|
||||
|
||||
if (Configuration.debugCopy.get()) {
|
||||
nBits = Math.max(nBits, value.nRotateBits);
|
||||
}
|
||||
|
||||
writeUB(5, nBits);
|
||||
writeSB(nBits, value.rotateSkew0);
|
||||
writeSB(nBits, value.rotateSkew1);
|
||||
@@ -569,6 +592,10 @@ public class SWFOutputStream extends OutputStream {
|
||||
NTranslateBits = enlargeBitCountS(NTranslateBits, value.translateX);
|
||||
NTranslateBits = enlargeBitCountS(NTranslateBits, value.translateY);
|
||||
|
||||
if (Configuration.debugCopy.get()) {
|
||||
NTranslateBits = Math.max(NTranslateBits, value.nTranslateBits);
|
||||
}
|
||||
|
||||
writeUB(5, NTranslateBits);
|
||||
|
||||
writeSB(NTranslateBits, value.translateX);
|
||||
@@ -597,6 +624,11 @@ public class SWFOutputStream extends OutputStream {
|
||||
Nbits = enlargeBitCountS(Nbits, value.greenAddTerm);
|
||||
Nbits = enlargeBitCountS(Nbits, value.blueAddTerm);
|
||||
}
|
||||
|
||||
if (Configuration.debugCopy.get()) {
|
||||
Nbits = Math.max(Nbits, value.nbits);
|
||||
}
|
||||
|
||||
writeUB(4, Nbits);
|
||||
if (value.hasMultTerms) {
|
||||
writeSB(Nbits, value.redMultTerm);
|
||||
@@ -633,6 +665,11 @@ public class SWFOutputStream extends OutputStream {
|
||||
Nbits = enlargeBitCountS(Nbits, value.blueAddTerm);
|
||||
Nbits = enlargeBitCountS(Nbits, value.alphaAddTerm);
|
||||
}
|
||||
|
||||
if (Configuration.debugCopy.get()) {
|
||||
Nbits = Math.max(Nbits, value.nbits);
|
||||
}
|
||||
|
||||
writeUB(4, Nbits);
|
||||
if (value.hasMultTerms) {
|
||||
writeSB(Nbits, value.redMultTerm);
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
|
||||
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
|
||||
@@ -60,6 +61,8 @@ public class DefineText2Tag extends TextTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
private final int glyphBits;
|
||||
private final int advanceBits;
|
||||
public RECT textBounds;
|
||||
public MATRIX textMatrix;
|
||||
public List<TEXTRECORD> textRecords;
|
||||
@@ -452,6 +455,12 @@ public class DefineText2Tag extends TextTag {
|
||||
advanceBits = SWFOutputStream.enlargeBitCountS(advanceBits, ge.glyphAdvance);
|
||||
}
|
||||
}
|
||||
|
||||
if (Configuration.debugCopy.get()) {
|
||||
glyphBits = Math.max(glyphBits, this.glyphBits);
|
||||
advanceBits = Math.max(advanceBits, this.advanceBits);
|
||||
}
|
||||
|
||||
sos.writeUI8(glyphBits);
|
||||
sos.writeUI8(advanceBits);
|
||||
for (TEXTRECORD tr : textRecords) {
|
||||
@@ -476,8 +485,8 @@ public class DefineText2Tag extends TextTag {
|
||||
characterID = sis.readUI16("characterID");
|
||||
textBounds = sis.readRECT("textBounds");
|
||||
textMatrix = sis.readMatrix("textMatrix");
|
||||
int glyphBits = sis.readUI8("glyphBits");
|
||||
int advanceBits = sis.readUI8("advanceBits");
|
||||
glyphBits = sis.readUI8("glyphBits");
|
||||
advanceBits = sis.readUI8("advanceBits");
|
||||
textRecords = new ArrayList<>();
|
||||
TEXTRECORD tr;
|
||||
while ((tr = sis.readTEXTRECORD(true, glyphBits, advanceBits, "record")) != null) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.AppResources;
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
|
||||
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
|
||||
@@ -61,6 +62,8 @@ public class DefineTextTag extends TextTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
private final int glyphBits;
|
||||
private final int advanceBits;
|
||||
public RECT textBounds;
|
||||
public MATRIX textMatrix;
|
||||
public List<TEXTRECORD> textRecords;
|
||||
@@ -437,6 +440,8 @@ public class DefineTextTag extends TextTag {
|
||||
this.textBounds = textBounds;
|
||||
this.textMatrix = textMatrix;
|
||||
this.textRecords = textRecords;
|
||||
this.glyphBits = 0;
|
||||
this.advanceBits = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -463,6 +468,11 @@ public class DefineTextTag extends TextTag {
|
||||
}
|
||||
}
|
||||
|
||||
if (Configuration.debugCopy.get()) {
|
||||
glyphBits = Math.max(glyphBits, this.glyphBits);
|
||||
advanceBits = Math.max(advanceBits, this.advanceBits);
|
||||
}
|
||||
|
||||
sos.writeUI8(glyphBits);
|
||||
sos.writeUI8(advanceBits);
|
||||
for (TEXTRECORD tr : textRecords) {
|
||||
@@ -487,8 +497,8 @@ public class DefineTextTag extends TextTag {
|
||||
characterID = sis.readUI16("characterID");
|
||||
textBounds = sis.readRECT("textBounds");
|
||||
textMatrix = sis.readMatrix("textMatrix");
|
||||
int glyphBits = sis.readUI8("glyphBits");
|
||||
int advanceBits = sis.readUI8("advanceBits");
|
||||
glyphBits = sis.readUI8("glyphBits");
|
||||
advanceBits = sis.readUI8("advanceBits");
|
||||
textRecords = new ArrayList<>();
|
||||
TEXTRECORD tr;
|
||||
while ((tr = sis.readTEXTRECORD(false, glyphBits, advanceBits, "record")) != null) {
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.jpexs.decompiler.flash.tags.ABCContainerTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ASMSource;
|
||||
import com.jpexs.decompiler.flash.tags.base.ContainerItem;
|
||||
import com.jpexs.decompiler.flash.treeitems.TreeItem;
|
||||
import com.jpexs.decompiler.flash.treenodes.TagNode;
|
||||
import com.jpexs.decompiler.flash.treenodes.TreeNode;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.TranslateException;
|
||||
@@ -66,9 +65,11 @@ public class RecompileTest {
|
||||
@Test(dataProvider = "provideFiles")
|
||||
public void testRecompile(String filename) {
|
||||
try {
|
||||
SWF swf = new SWF(new BufferedInputStream(new FileInputStream(TESTDATADIR + File.separator + filename)), false);
|
||||
Configuration.debugCopy.set(true);
|
||||
swf.saveTo(new ByteArrayOutputStream());
|
||||
try (FileInputStream fis = new FileInputStream(TESTDATADIR + File.separator + filename)){
|
||||
Configuration.debugCopy.set(true);
|
||||
SWF swf = new SWF(new BufferedInputStream(fis), false);
|
||||
swf.saveTo(new ByteArrayOutputStream());
|
||||
}
|
||||
} catch (IOException | InterruptedException ex) {
|
||||
fail();
|
||||
} catch (NotSameException ex) {
|
||||
@@ -80,7 +81,7 @@ public class RecompileTest {
|
||||
for (TreeNode node : nodeList) {
|
||||
if (node.subNodes.isEmpty()) {
|
||||
TreeItem item = node.getItem();
|
||||
if ((item instanceof ASMSource) && (node.export)) {
|
||||
if (item instanceof ASMSource) {
|
||||
try {
|
||||
ASMSource asm = ((ASMSource) item);
|
||||
HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false);
|
||||
@@ -155,7 +156,6 @@ public class RecompileTest {
|
||||
list2.addAll(swf.tags);
|
||||
List<TreeNode> list = SWF.createASTagList(list2, null);
|
||||
|
||||
TagNode.setExport(list, true);
|
||||
testAS2DirectEditingOneRecursive(swf.version, list);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
||||
Reference in New Issue
Block a user