From f600bdf84e025690aca563e295ab87fa6f032d51 Mon Sep 17 00:00:00 2001 From: Antoine Date: Thu, 15 Aug 2013 17:14:04 +0200 Subject: [PATCH] Add readDefineButtonTag and readButtonRecord2 --- .../src/com/swfwire/decompiler/SWF3Reader.as | 83 +++++++++---------- .../data/swf3/records/ButtonRecord2.as | 26 +++--- 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/SWFWireDecompiler/src/com/swfwire/decompiler/SWF3Reader.as b/SWFWireDecompiler/src/com/swfwire/decompiler/SWF3Reader.as index b3a3b8ea..5203f962 100644 --- a/SWFWireDecompiler/src/com/swfwire/decompiler/SWF3Reader.as +++ b/SWFWireDecompiler/src/com/swfwire/decompiler/SWF3Reader.as @@ -7,6 +7,7 @@ package com.swfwire.decompiler import com.swfwire.decompiler.data.swf.tags.EndTag; import com.swfwire.decompiler.data.swf.tags.SWFTag; import com.swfwire.decompiler.data.swf2.records.FillStyleArrayRecord2; + import com.swfwire.decompiler.data.swf3.actions.ButtonCondAction; import com.swfwire.decompiler.data.swf3.records.*; import com.swfwire.decompiler.data.swf3.tags.*; @@ -38,9 +39,6 @@ package com.swfwire.decompiler case 45: tag = readSoundStreamHead2Tag(context, header); case 46: tag = readDefineMorphShapeTag(context, header); case 48: tag = readDefineFont2Tag(context, header); - case 34: - tag = readDefineButton2Tag(context, header); - break; */ case 12: tag = readDoActionTag(context, header); @@ -51,6 +49,9 @@ package com.swfwire.decompiler case 32: tag = readDefineShape3Tag(context, header); break; + case 34: + tag = readDefineButton2Tag(context, header); + break; case 35: tag = readDefineBitsJPEG3Tag(context, header); break; @@ -339,60 +340,49 @@ package com.swfwire.decompiler tag.buttonId = context.bytes.readUI16(); tag.reserved = context.bytes.readUB(7); tag.trackAsMenu = context.bytes.readFlag(); + var actionOffsetPosition:uint = context.bytes.getBytePosition(); tag.actionOffset = context.bytes.readUI16(); tag.characters = new Vector.(); - while(true) + do { - var reserved:uint = context.bytes.readUB(2); - var hasBlendMode:Boolean = context.bytes.readFlag(); - var hasFilterList:Boolean = context.bytes.readFlag(); - var stateHitTest:Boolean = context.bytes.readFlag(); - var stateDown:Boolean = context.bytes.readFlag(); - var stateOver:Boolean = context.bytes.readFlag(); - var stateUp:Boolean = context.bytes.readFlag(); - if(reserved == 0 && - !hasBlendMode && - !hasFilterList && - !stateHitTest && - !stateDown && - !stateOver && - !stateUp) + tag.characters.push(readButtonRecord2(context)); + // Test if next byte is CharacterEndFlag + if (!context.bytes.readUI8()) { break; } - else + context.bytes.unreadBytes(1); + } + while(true); + tag.actions = new Vector.(); + if (tag.actionOffset == 0) + { + return tag; + } + if ((actionOffsetPosition + tag.actionOffset) != context.bytes.getBytePosition()) + { + throw new Error("Wrong ActionOffset value: " + tag.actionOffset + " instead of " + (context.bytes.getBytePosition() - actionOffsetPosition)); + } + do + { + var actionPosition:uint = context.bytes.getBytePosition(); + var action:ButtonCondAction = readButtonCondAction(context); + tag.actions.push(action); + if (action.condActionSize && ((actionPosition + action.condActionSize) != context.bytes.getBytePosition())) { - tag.characters.push(readButtonRecord2(context, reserved, hasBlendMode, hasFilterList, - stateHitTest, stateDown, stateOver, stateUp)); + throw new Error("Wrong CondActionSize value: " + action.condActionSize + " instead of " + (context.bytes.getBytePosition() - actionPosition)); } } - //tag.actions = readButtonCondAction(); + while(action.condActionSize) return tag; } - protected function readButtonRecord2(context:SWFReaderContext, reserved:uint, hasBlendMode:Boolean, hasFilterList:Boolean, - stateHitTest:Boolean, stateDown:Boolean, stateOver:Boolean, stateUp:Boolean):ButtonRecord2 - { - var record:ButtonRecord2 = new ButtonRecord2(); - record.reserved = reserved; - record.hasBlendMode = hasBlendMode; - record.hasFilterList = hasFilterList; - record.stateHitTest = stateHitTest; - record.stateDown = stateDown; - record.stateOver = stateOver; - record.stateUp = stateUp; - record.characterId = context.bytes.readUI16(); - record.placeDepth = context.bytes.readUI16(); - record.placeMatrix = readMatrixRecord(context); + protected function readButtonRecord2(context:SWFReaderContext):ButtonRecord2 + { + var record:ButtonRecord2 = new ButtonRecord2(readButtonRecord(context)); record.colorTransform = readCXFormWithAlphaRecord(context); - if(hasFilterList) - { - record.filterList = readFilterListRecord(context); - } - if(hasBlendMode) - { - record.blendMode = context.bytes.readUI8(); - } + record.filterList = readFilterListRecord(context); + record.blendMode = context.bytes.readUI8(); return record; } @@ -447,6 +437,11 @@ package com.swfwire.decompiler return record; } + protected function readButtonCondAction(context:SWFReaderContext):ButtonCondAction + { + throw new Error("Read ButtonCondAction not implemented."); + } + protected function readDefineSpriteTag(context:SWFReaderContext, header:TagHeaderRecord):DefineSpriteTag { var tag:DefineSpriteTag = new DefineSpriteTag(); diff --git a/SWFWireDecompiler/src/com/swfwire/decompiler/data/swf3/records/ButtonRecord2.as b/SWFWireDecompiler/src/com/swfwire/decompiler/data/swf3/records/ButtonRecord2.as index ab6247e8..7731afb8 100644 --- a/SWFWireDecompiler/src/com/swfwire/decompiler/data/swf3/records/ButtonRecord2.as +++ b/SWFWireDecompiler/src/com/swfwire/decompiler/data/swf3/records/ButtonRecord2.as @@ -2,20 +2,24 @@ package com.swfwire.decompiler.data.swf3.records { import com.swfwire.decompiler.data.swf.records.*; - public class ButtonRecord2 + public class ButtonRecord2 extends ButtonRecord { - public var reserved:uint; - public var hasBlendMode:Boolean; - public var hasFilterList:Boolean; - public var stateHitTest:Boolean; - public var stateDown:Boolean; - public var stateOver:Boolean; - public var stateUp:Boolean; - public var characterId:uint; - public var placeDepth:uint; - public var placeMatrix:MatrixRecord; public var colorTransform:CXFormWithAlphaRecord; public var filterList:FilterListRecord; public var blendMode:uint; + + public function ButtonRecord2(record:ButtonRecord) + { + reserved = record.reserved; + buttonHasBlendMode = record.buttonHasBlendMode; + buttonHasFilterList = record.buttonHasFilterList; + stateHitTest = record.stateHitTest; + stateDown = record.stateDown; + stateOver = record.stateOver; + stateUp = record.stateUp; + characterId = record.characterId; + placeDepth = record.placeDepth; + placeMatrix = record.placeMatrix; + } } } \ No newline at end of file