X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fmodules%2Fswftools.c;h=6baecd105477ed01f1b4bf1192854fc2dfc2dc61;hp=d4275d3b85528b8ab19ad5497b9dd1212baa34c2;hb=879d0eec420fe0fd5ddcd56c8fe62b82a6744edd;hpb=8978b24a969f73518ecde87b24d972c7030e91f6 diff --git a/lib/modules/swftools.c b/lib/modules/swftools.c index d4275d3..6baecd1 100644 --- a/lib/modules/swftools.c +++ b/lib/modules/swftools.c @@ -584,10 +584,13 @@ void enumerateUsedIDs(TAG * tag, int base, void (*callback)(TAG*, int, void*), v case ST_DEFINEBUTTONSOUND: { int t; callback(tag, tag->pos + base, callback_data); + swf_GetU16(tag); //button id for(t=0;t<4;t++) { int flags; callback(tag, tag->pos + base, callback_data); - swf_GetU16(tag); //sound id + U16 sound_id = swf_GetU16(tag); //sound id + if(!sound_id) + continue; flags = swf_GetU8(tag); if(flags&1) swf_GetU32(tag); // in point @@ -643,7 +646,6 @@ void enumerateUsedIDs(TAG * tag, int base, void (*callback)(TAG*, int, void*), v case ST_FREECHARACTER: /* unusual tags, which all start with an ID */ case ST_NAMECHARACTER: - case ST_DEFINEBINARY: case ST_DEFINEFONTNAME: case ST_GENERATORTEXT: callback(tag, tag->pos + base, callback_data); @@ -974,7 +976,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 +1004,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 +1029,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 +1038,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 { @@ -1166,6 +1168,7 @@ U8 swf_isFontTag(TAG*tag) { if(tag->id == ST_DEFINEFONT || tag->id == ST_DEFINEFONT2 || + tag->id == ST_DEFINEFONT3 || tag->id == ST_DEFINEFONTINFO) return 1; return 0;