#include "./reloc.h"
#include "./settings.h"
-// TODO:
-// * readers should be object-oriented
-
static char* slavename = 0;
static int slaveid = -1;
static int slaveframe = -1;
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
}
}
-
void write_sprite(struct writer_t*w, int spriteid, int replaceddefine)
{
u16 tmp;
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);
logf("<debug> %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);
}
}
while(slave.tags[pos++].id != TAGID_END);
- *tagidpos = (u8*)writer_getpos(w) - startpos; // set length of sprite (in header)
- logf("<verbose> sprite length is %d",*tagidpos);
+ *tagidpos = SWAP32((u8*)writer_getpos(w) - startpos); // set length of sprite (in header)
+ logf("<verbose> sprite length is %d",SWAP32(*tagidpos));
}
static char tag_ok_for_slave(int id)
{
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 */
if(config.clip) {
logf("<fatal> 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);
{
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);
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
}
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
}
}
writer_resetbits(w);
- *(u32*)lenpos = (u8*)writer_getpos(w) - pos;
+ *(u32*)lenpos = SWAP32((u8*)writer_getpos(w) - pos);
}
void placeobject2_init (struct PlaceObject2*obj,struct swf_tag*tag)
{
u8 flags = obj->reserved<<7 | obj->hasclipactions<<6 | obj->hasname<<5 | obj->hasratio<<4 |
obj->hascolortransform<<3 | obj->hasmatrix<<2 | obj->hascharacter<<1 | obj->hasmove;
- u16 taghead = 0x3f | TAGID_PLACEOBJECT2<<6;
+ u16 taghead = SWAP16(0x3f | TAGID_PLACEOBJECT2<<6);
u8*pos;
u8*lenpos;
writer_resetbits(w);
if(obj->hasclipactions)
writer_writeu16(w, obj->clipactions);
writer_resetbits(w);
- *(u32*)lenpos = (u8*)writer_getpos(w) - pos;
+ *(u32*)lenpos = SWAP32((u8*)writer_getpos(w) - pos);
}
void read_swf(struct swffile*swf, uchar*data, int length)
void setidintag(struct swf_tag* tag, int id)
{
- *(u16*)tag->data = id;
+ *(u16*)tag->data = SWAP16(id);
}
char is_sprite_tag (int id)
{
-
int t=0;
while(spritetagids[t]>=0)
{
char is_defining_tag (int id)
{
-
int t=0;
while(definingtagids[t]>=0)
{