X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcombine.c;fp=src%2Fcombine.c;h=a6a695a4ecfb40d3feb80c5a842a9b788251ccfc;hb=caacc3b7bc77a04e35891f73908f9c0a7c8c64fa;hp=4908912f5fceb20c8d313f77dc2fa981fe0497b8;hpb=7ddcc6604ef3a6004c8fefb59d2ecdedc440b2bc;p=swftools.git diff --git a/src/combine.c b/src/combine.c index 4908912..a6a695a 100644 --- a/src/combine.c +++ b/src/combine.c @@ -16,9 +16,6 @@ #include "./reloc.h" #include "./settings.h" -// TODO: -// * readers should be object-oriented - static char* slavename = 0; static int slaveid = -1; static int slaveframe = -1; @@ -58,14 +55,19 @@ static int get_free_id() void changedepth(struct swf_tag*tag, int add) { + /* fucking big endian byte order */ if(tag->id == TAGID_PLACEOBJECT) - (*(u16*)&tag->data[2]) += add; + (*(u16*)&tag->data[2]) = + SWAP16(SWAP16(*(u16*)&tag->data[2]) + add); if(tag->id == TAGID_PLACEOBJECT2) - (*(u16*)&tag->data[1]) += add; + (*(u16*)&tag->data[1]) = + SWAP16(SWAP16(*(u16*)&tag->data[1]) + add); if(tag->id == TAGID_REMOVEOBJECT) - (*(u16*)&tag->data[2]) += add; + (*(u16*)&tag->data[2]) = + SWAP16(SWAP16(*(u16*)&tag->data[2]) + add); if(tag->id == TAGID_REMOVEOBJECT2) - (*(u16*)&tag->data[0]) += add; + (*(u16*)&tag->data[0]) = + SWAP16(SWAP16(*(u16*)&tag->data[0]) + add); } /* applies the config move and scale parameters to @@ -191,7 +193,6 @@ void write_sprite_defines(struct writer_t*w) } } - void write_sprite(struct writer_t*w, int spriteid, int replaceddefine) { u16 tmp; @@ -200,7 +201,7 @@ void write_sprite(struct writer_t*w, int spriteid, int replaceddefine) u8*startpos; int pos = 0; // write slave(2) (header) - tmp = 0x3f + (TAGID_DEFINESPRITE << 6); + tmp = SWAP16(0x3f + (TAGID_DEFINESPRITE << 6)); writer_write(w, &tmp, 2); tagidpos = (u32*)writer_getpos(w); writer_write(w, &tmp32, 4); @@ -219,26 +220,26 @@ void write_sprite(struct writer_t*w, int spriteid, int replaceddefine) logf(" %d frames to go",tmp); if(config.clip) { - tmp = 7 + (TAGID_PLACEOBJECT2 << 6); + tmp = SWAP16(7 + (TAGID_PLACEOBJECT2 << 6)); writer_write(w, &tmp, 2); - tmp = 2+64; //flags: character + clipaction + tmp = SWAP16(2+64); //flags: character + clipaction writer_write(w, &tmp, 1); - tmp = 0; //depth + tmp = SWAP16(0); //depth writer_write(w, &tmp,2); - tmp = replaceddefine; //id + tmp = SWAP16(replaceddefine); //id writer_write(w, &tmp,2); - tmp = 65535; //clipdepth + tmp = SWAP16(65535); //clipdepth writer_write(w, &tmp,2); } if(config.overlay && !config.isframe) { - tmp = 5 + (TAGID_PLACEOBJECT2 << 6); + tmp = SWAP16(5 + (TAGID_PLACEOBJECT2 << 6)); writer_write(w, &tmp, 2); - tmp = 2; //flags: character + tmp = SWAP16(2); //flags: character writer_write(w, &tmp, 1); - tmp = 0; //depth + tmp = SWAP16(0); //depth writer_write(w, &tmp,2); - tmp = replaceddefine; //id + tmp = SWAP16(replaceddefine); //id writer_write(w, &tmp,2); } @@ -260,8 +261,8 @@ void write_sprite(struct writer_t*w, int spriteid, int replaceddefine) } while(slave.tags[pos++].id != TAGID_END); - *tagidpos = (u8*)writer_getpos(w) - startpos; // set length of sprite (in header) - logf(" sprite length is %d",*tagidpos); + *tagidpos = SWAP32((u8*)writer_getpos(w) - startpos); // set length of sprite (in header) + logf(" sprite length is %d",SWAP32(*tagidpos)); } static char tag_ok_for_slave(int id) @@ -308,7 +309,7 @@ void write_master(struct writer_t*w, int spriteid, int replaceddefine, int flags { if(config.overlay) { - *(u16*)master.tags[pos].data = replaceddefine; + *(u16*)master.tags[pos].data = SWAP16(replaceddefine); writer_write(w, master.tags[pos].fulldata, master.tags[pos].fulllength); } else { /* don't write this tag */ @@ -343,10 +344,10 @@ void write_master(struct writer_t*w, int spriteid, int replaceddefine, int flags if(config.clip) { logf(" Can't combine --clip and --frame"); } - *(u16*)&data[0] = (u16)(TAGID_PLACEOBJECT2<<6) + 5 ; - *(u8*)&data[2]= 2; //flags: id - *(u16*)&data[3]= depth; // depth - *(u16*)&data[5]= id; + *(u16*)&data[0] = SWAP16((u16)(TAGID_PLACEOBJECT2<<6) + 5); + *(u8*)&data[2]= SWAP16(2); //flags: id + *(u16*)&data[3]= SWAP16(depth); // depth + *(u16*)&data[5]= SWAP16(id); write_sprite_defines(w); write_sprite(w, id, -1); writer_write(w,data,7); @@ -508,8 +509,8 @@ uchar * catcombine(uchar*masterdata, int masterlength, char*_slavename, uchar*sl { char data[16]; int len; - *(u16*)(&data[0]) = (TAGID_REMOVEOBJECT2<<6) + 2; - *(u16*)(&data[2]) = t; + *(u16*)(&data[0]) = SWAP16((TAGID_REMOVEOBJECT2<<6) + 2); + *(u16*)(&data[2]) = SWAP16(t); writer_write(&w, data, 4); } free(depths); @@ -524,7 +525,7 @@ uchar * catcombine(uchar*masterdata, int masterlength, char*_slavename, uchar*sl tmp32 = (u8*)writer_getpos(&w) - (u8*)newdata; //length *newlength = tmp32; - *headlength = tmp32; // set the header to the correct length + *headlength = SWAP32(tmp32); // set the header to the correct length return newdata; //length } @@ -632,7 +633,7 @@ uchar * normalcombine(uchar*masterdata, int masterlength, char*_slavename, uchar tmp32 = (u8*)writer_getpos(&w) - (u8*)newdata; //length *newlength = tmp32; - *headlength = tmp32; // set the header to the correct length + *headlength = SWAP32(tmp32); // set the header to the correct length return newdata; //length }