brought up to date.
[swftools.git] / src / combine.c
index 10b8efc..ebe89be 100644 (file)
@@ -20,6 +20,7 @@
 // * readers should be object-oriented
 
 static char* slavename;
+static int slaveid;
 
 static char* tag_placeobject2_name (struct swf_tag* tag)
 {
@@ -157,8 +158,15 @@ void write_sprite_defines(struct writer_t*w)
                         * Anyway we can't throw it out, so we just pass it
                         * through.
                         */
+                       writer_write(w, tag->fulldata, tag->fulllength);
                        break;
                    }
+                case TAGID_JPEGTABLES:
+                       /* according to the flash specs, there may only 
+                          be one JPEGTABLES tag per swf. This is maybe
+                          a big FIXME */
+                       writer_write(w, tag->fulldata, tag->fulllength);
+                   break;
                 case TAGID_EXPORTASSETS:
                    logf("<debug> deliberately ignoring EXPORTASSETS tag");
                    break;
@@ -198,12 +206,6 @@ void write_sprite(struct writer_t*w, int spriteid, int replaceddefine)
     
     startpos = (u8*)writer_getpos(w);
 
-    if (spriteid<0)
-    {
-       logf("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
-       spriteid = get_free_id();
-    }
-
     logf ("<notice> sprite id is %d", spriteid);
     tmp = spriteid;
     writer_write(w, &tmp, 2);
@@ -333,6 +335,11 @@ uchar * combine(uchar*masterdata, int masterlength, char*_slavename, uchar*slave
     char master_flash = 0;
     char slave_flash = 0;
     slavename = _slavename;
+    if(slavename[0] == '#')
+    {
+       slaveid = atoi(&slavename[1]);
+       slavename = 0;
+    }
 
     logf("<debug> move x (%d)", config.movex);
     logf("<debug> move y (%d)", config.movey);
@@ -358,6 +365,9 @@ uchar * combine(uchar*masterdata, int masterlength, char*_slavename, uchar*slave
        logf("<notice> the master file is flash (swf) format\n");
        master_flash = 1;
     }
+    else
+       logf("<notice> the master file is not flash (swf) format!\n");
+
     if(slavedata[2] == 'S' &&
        slavedata[1] == 'W' &&
        slavedata[0] == 'F')
@@ -365,6 +375,8 @@ uchar * combine(uchar*masterdata, int masterlength, char*_slavename, uchar*slave
        logf("<notice> the slave file is flash (swf) format\n");
        slave_flash = 1;
     }
+    else
+       logf("<notice> the slave file is not flash (swf) format!\n");
 
     if(master_flash && slave_flash)
     {
@@ -405,7 +417,8 @@ uchar * combine(uchar*masterdata, int masterlength, char*_slavename, uchar*slave
                else
                  logf("<verbose> tagid %02x places object %d (no name)", tag, id);
 
-               if (name && !strcmp(name,slavename)) {
+               if ((name && slavename && !strcmp(name,slavename)) || 
+                   (!slavename && id==slaveid)) {
                    if(id>=0) {
                      spriteid = id;
                      logf("<notice> Slave file attached to object %d.", id);
@@ -415,6 +428,17 @@ uchar * combine(uchar*masterdata, int masterlength, char*_slavename, uchar*slave
        }
        while(master.tags[pos++].id != 0);
 
+       if (spriteid<0)
+       {
+           if(slavename) {
+               if(strcmp(slavename,"!!dummy!!"))
+                   logf("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
+           }
+           else
+               logf("<warning> Didn't find id %d in file. No substitutions will occur.", slaveid);
+           spriteid = get_free_id();
+       }
+
        swf_relocate (slavedata, slavelength, masterids);
 
        read_swf(&slave, slavedata, slavelength);