fixed two bugs in swfcombine
authorMatthias Kramm <kramm@quiss.org>
Wed, 5 Aug 2009 11:22:00 +0000 (13:22 +0200)
committerMatthias Kramm <kramm@quiss.org>
Wed, 5 Aug 2009 11:22:00 +0000 (13:22 +0200)
lib/modules/swftools.c
src/swfcombine.c

index d4275d3..42279bb 100644 (file)
@@ -974,7 +974,20 @@ char swf_Relocate (SWF*swf, char*bitmap)
     memset(slaveids, -1, sizeof(slaveids));
     tag = swf->firstTag;
     char ok = 1;
+
     int current_id=0;
+#define NEW_ID(n) \
+               for(current_id++;current_id<65536;current_id++) { \
+                   if(!bitmap[current_id]) { \
+                       n = current_id; \
+                       break; \
+                   } \
+               } \
+                if(current_id==65536) { \
+                    fprintf(stderr, "swf_Relocate: Couldn't relocate: Out of IDs\n"); \
+                    return 0; \
+                }
+
     while(tag)
     {
        int num; 
@@ -989,21 +1002,12 @@ char swf_Relocate (SWF*swf, char*bitmap)
 
            if(!bitmap[id]) { //free
                newid = id;
+           } else if(slaveids[id]>0) {
+               newid = slaveids[id];
            } else {
-               newid = 0;
-               for(current_id++;current_id<65536;current_id++)
-               {
-                   if(!bitmap[current_id])
-                   {
-                       newid = current_id;
-                       break;
-                   }
-               }
-                if(current_id==65536) {
-                    fprintf(stderr, "swf_Relocate: Couldn't relocate: Out of IDs\n");
-                    return 0;
-                }
+               NEW_ID(newid);
            }
+
            bitmap[newid] = 1;
            slaveids[id] = newid;
 
@@ -1023,17 +1027,8 @@ char swf_Relocate (SWF*swf, char*bitmap)
                           the main timeline. It's used in e.g. SYMBOLTAG tags, but
                           never defined, so if we're asked to reallocate it, we have 
                           to allocate an ID for it on the fly. */
-                       int newid = 0;
-                       for(current_id++;current_id<65536;current_id++) {
-                           if(!bitmap[current_id]) {
-                               newid = current_id;
-                               break;
-                           }
-                       }
-                       if(current_id==65536) {
-                           fprintf(stderr, "swf_Relocate: Couldn't relocate: Out of IDs\n");
-                           return 0;
-                       }
+                       int newid;
+                       NEW_ID(newid);
                        bitmap[newid] = 1;
                        slaveids[id] = newid;
                        id = newid;
@@ -1041,8 +1036,13 @@ char swf_Relocate (SWF*swf, char*bitmap)
                        /* well- we don't know this id, but it's not reserved anyway, so just
                           leave it alone */
                    } else {
-                       fprintf(stderr, "swf_Relocate: Mapping id (%d) never encountered before in %s\n", id,
+                       /* this actually happens with files created with Flash CS4 and never.
+                          Apparently e.g. DefineButton tags are able to use forward declarations of objects. */
+                       fprintf(stderr, "warning: Mapping id (%d) never encountered before in %s\n", id,
                                swf_TagGetName(tag));
+                       int newid;
+                       NEW_ID(newid);
+                       id = slaveids[id] = newid;
                        ok = 0;
                    }
                } else {
index 7181c5c..c488952 100644 (file)
@@ -1003,6 +1003,18 @@ void normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
                  msg("<notice> Slave file attached to object %d.", defineid);
                }
            }
+       } else if(tag->id == ST_EXPORTASSETS) {
+           int t;
+           int num = swf_GetU16(tag);
+           for(t=0;t<num;t++)
+           {
+               U16 id = swf_GetU16(tag);
+               char*name = swf_GetString(tag);
+               if(spriteid<0 && slavename && !strcmp(name,slavename)) {
+                   spriteid = id;
+                   msg("<notice> Slave file attached to object %d exported as %s.", id, name);
+               }
+           }
        } else if(tag->id == ST_SYMBOLCLASS) {
            /* a symbolclass tag is like a define tag: it defines id 0000 */
            int num = swf_GetU16(tag);