* fixed relocation of definebutton.
[swftools.git] / src / reloc.c
index 2f82afa..56831aa 100644 (file)
@@ -104,7 +104,8 @@ void map_ids_mem(u8*mem, int length)
                readu16(); //char
                readu16(); //layer
                readMATRIX();
-               readCXFORM();
+               if(num>1)
+                 readCXFORM();
            }
            // ...
        break;
@@ -124,23 +125,25 @@ void map_ids_mem(u8*mem, int length)
            num ++;
        case TAGID_DEFINETEXT: { 
            int glyphbits, advancebits;
+           int id;
            reader_init (newtag->data, newtag->length);
-           readu16(); //id
+           id = readu16(); //id
            readRECT(); //bounding box
            readMATRIX(); //matrix
            resetbits();
            glyphbits = readu8(); //glyphbits
            advancebits = readu8(); //advancebits
            while(1) {
-               u16 flags = getbits(8);
-               printf("define text flags: %02x\n", flags);
+               u16 flags;
+               resetbits();
+               flags = getbits(8);
                if(!flags) break;
                if(flags & 128) // text style record
                {
+                   resetbits();
                    if(flags & 8) { // hasfont
                        maponeid(getinputpos());
-                       resetbits();
-                       readu16();
+                       id = readu16();
                    }
                    if(flags & 4) { // hascolor
                        if(num==1) readRGB();
@@ -159,9 +162,12 @@ void map_ids_mem(u8*mem, int length)
                        readu16();
                    }
                } else { // glyph record
-                   getbits(glyphbits);
-                   getbits(advancebits);
-                   break;
+                   int t;
+                   resetbits();
+                   for(t=0;t<flags;t++) {
+                       getbits(glyphbits);
+                       getbits(advancebits);
+                   }
                }
            }
            break;
@@ -184,7 +190,7 @@ void map_ids_mem(u8*mem, int length)
 //         printf("%d shape bounds: %d %d %d %d\n",newtag->id,r.x1,r.y1,r.x2,r.y2);
            resetbits();
            count = readu8();
-           if(count == 0xff && num>1)
+           if(count == 0xff && num>1) // defineshape2,3 only
                count = readu16();
 //         printf("%d fillstyles\n", count);
            for(t=0;t<count;t++)
@@ -194,6 +200,7 @@ void map_ids_mem(u8*mem, int length)
                pos=getinputpos();
 //             printf("%02x %02x %02x %02x %02x %02x %02x %02x\n", 
 //                     pos[0],pos[1],pos[2],pos[3],pos[4],pos[5],pos[6],pos[7]);
+               resetbits();
                type = readu8(); //type
 //             printf("fillstyle %d is type 0x%02x\n", t, type);
                if(type == 0) {
@@ -254,6 +261,7 @@ void swf_relocate (u8*data, int length, int*_bitmap)
     while(file.tags[pos].id != 0) {
        struct swf_tag*tag = &file.tags[pos];
         
+       logf("<debug> relocator: processing tag %02x", tag->id);
        map_ids(&file.tags[pos]);
 
        if(is_defining_tag(tag->id))
@@ -272,11 +280,11 @@ void swf_relocate (u8*data, int length, int*_bitmap)
            bitmap[newid] = 1;
            slaveids[id] = newid;
 
-           logf("<debug> sprite id %d mapped to %d",id, newid);
+           logf("<debug> relocator: id %d mapped to %d",id, newid);
            
            setidintag(tag, newid);
 
-           logf("<debug> [sprite defs] write tag %02x (%d bytes in body)", 
+           logf("<debug> [reloc] write tag %02x (%d bytes in body)", 
                    tag->id, tag->length);
        } 
         pos++;