changed from malloc to rfx_alloc.
[swftools.git] / lib / modules / swfaction.c
1 /* swfaction.c
2
3    Actionscript generation and parsing routines
4    
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
9  
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
23
24 #include "../rfxswf.h"
25
26 #define MAX_LOOKUP 1024   // make cross references in dumps
27
28 struct Action
29 {
30     int version;
31     char*name;
32     U8 op;
33     char*flags;
34 } static actions[] =
35 {
36 /*
37 f: frame (word)
38 u: url (string)
39 t: target (string)
40 l: label (string)
41 C: constant pool header (word)
42 c: constant pool entry (string)
43 s: skip (byte) (number of actions)
44 m: method (byte) swf_GetUrl2:(0=none, 1=get, 2=post)/GotoFrame2:(1=play)
45 b: branch (word) (number of bytes)
46 p (push): type(byte), type=0:string, type=1:double
47 {: define function (name (string), num (word), params (num strings), codesize (word)
48 o: codesize (word) object (string)
49 r: register (byte)
50  */
51 {3,"End", 0x00, ""},
52 {3,"GotoFrame", 0x81, "f"},
53 {4,"GotoFrame2", 0x9f, "m"}, // -1 (/Movieclip:3)
54 {3,"GetUrl", 0x83, "ul"},
55 {4,"GetUrl2", 0x9a, "m"}, //-2
56 {3,"NextFrame", 0x04, ""},
57 {3,"PreviousFrame", 0x05, ""},
58 {3,"Play", 0x06, ""},
59 {3,"Stop", 0x07, ""},
60 {3,"ToggleQuality", 0x08, ""},
61 {3,"StopSounds", 0x09, ""},
62 {3,"WaitForFrame", 0x8a, "fs"},
63 {4,"WaitForFrame2", 0x8d, "s"}, // -1
64 {3,"SetTarget", 0x8b, "t"},
65 {4,"SetTarget2", 0x20, ""}, //-1
66 {3,"GotoLabel", 0x8c, "l"},
67 {4,"Add", 0x0a, ""}, //  -2, +1
68 {4,"Multiply", 0x0c, ""}, //  -2, +1
69 {4,"Divide", 0x0d, ""}, //  -2, +1
70 {4,"Subtract", 0x0b, ""}, //  -2, +1
71 {4,"Less", 0x0f, ""}, //  -2, +1
72 {4,"Equals", 0x0e, ""}, //  -2, +1
73 {4,"And", 0x10, ""}, //  -2, +1
74 {4,"Or", 0x11, ""}, //  -2, +1
75 {4,"Not", 0x12, ""}, //  -1, +1
76 {4,"StringAdd", 0x21, ""}, // -2,+1
77 {4,"StringLength", 0x14, ""}, // -1, +1
78 {4,"MBStringLength", 0x31, ""}, // -1, +1
79 {4,"StringEquals", 0x13, ""}, // -2, +1
80 {4,"StringLess", 0x29, ""}, //-2, +1
81 {4,"StringExtract", 0x15, ""}, // -3, +1
82 {4,"MBStringExtract", 0x35, ""}, //-3 +1
83 {4,"Push", 0x96, "p"}, //  +1
84 {4,"Pop", 0x17, ""}, //  -1
85 {4,"ToInteger", 0x18, ""}, // -1, +1
86 {4,"CharToAscii", 0x32, ""}, // -1, +1
87 {4,"AsciiToChar", 0x33, ""}, // -1, +1
88 {4,"MBCharToAscii", 0x36, ""}, // -1, +1
89 {4,"MBAsciiToChar", 0x37, ""}, // -1, +1
90 {4,"Jump", 0x99, "b"},
91 {4,"If", 0x9d, "b"}, // -1
92 {4,"Call", 0x9e, ""}, //-1 (frame label/number) (high bit is wrong.)
93 {4,"GetVariable", 0x1c,""}, // -1, +1
94 {4,"SetVariable", 0x1d,""}, // -2
95 {4,"GetProperty", 0x22,""}, //-2, +1
96 {4,"SetProperty", 0x23, ""}, // -3
97 {4,"RemoveSprite", 0x25, ""}, //-1
98 {4,"StartDrag", 0x27, ""}, // -2, -1, (-4)
99 {4,"EndDrag", 0x28, ""}, 
100 {4,"CloneSprite", 0x24, ""}, // -3
101 {4,"Trace", 0x26, ""}, //-1
102 {4,"GetTime", 0x34, ""}, //+1
103 {4,"RandomNumber", 0x30, ""}, //-1,+1
104 {5,"Modulo", 0x3f,""},
105 {5,"BitAnd", 0x60,""},
106 {5,"BitLShift", 0x63,""},
107 {5,"BitOr", 0x61,""},
108 {5,"BitRShift", 0x64,""},
109 {5,"BitURShift", 0x65,""},
110 {5,"BitXor", 0x62,""},//66?
111 {5,"Decrement", 0x51,""},
112 {5,"Increment", 0x50,""},
113 {5,"PushDuplicate", 0x4c,""},
114 {5,"StackSwap", 0x4d,""}, //?
115 {5,"StoreRegister", 0x87,"r"},
116 {5,"CallFunction", 0x3d,""},
117 {5,"DefineFunction", 0x9b, "{"},
118 {5,"Return", 0x3e,""},
119 {5,"GetMember", 0x4e,""},
120 {5,"SetMember", 0x4f,""},
121 {5,"CallMethod", 0x52,""},
122 {5,"Constantpool", 0x88, "Cc"},
123 {5,"DefineLocal", 0x3c,""},
124 {5,"DefineLocal2", 0x41,""},
125 {5,"Makehash", 0x43, ""}, //??
126 {5,"Delete", 0x3a,""}, //?
127 {5,"Delete2", 0x3b,""},
128 {5,"Enumerate", 0x46,""},
129 {5,"Equals2", 0x49,""},
130 {5,"InitArray", 0x42,""}, // InitObject?
131 {5,"NewMethod", 0x53,""}, //?
132 {5,"NewObject", 0x40,""},
133 {5,"TargetPath", 0x45,""}, //?
134 {5,"With", 0x94, "o"},
135 {5,"ToNumber", 0x4a,""}, //?
136 {5,"ToString", 0x4b,""}, //?
137 {5,"TypeOf", 0x44,""},
138 {5,"Add2", 0x47,""},
139 {5,"Less2", 0x48,""},
140 {6,"Greater", 0x67,""},
141 {6,"StringGreater", 0x68,""},
142 {6,"Enumerate2", 0x55,""},
143 {6,"InstanceOf", 0x54,""},
144 {6,"StrictEquals", 0x66,""}
145 };
146 static int definedactions = sizeof(actions)/sizeof(struct Action);
147
148 ActionTAG* swf_ActionGet(TAG*tag) 
149 {
150     U8 op = 1;
151     int length;
152     ActionTAG tmp;
153     ActionTAG*action = &tmp;
154     U8*data;
155     while(op)
156     {
157         action->next = (ActionTAG*)rfx_calloc(sizeof(ActionTAG));
158         action->next->prev = action;
159         action->next->next = 0;
160         action->next->parent = tmp.next;
161         action = action->next;
162
163         op = swf_GetU8(tag);
164         if(op<0x80)
165             length = 0;
166         else
167             length = swf_GetU16(tag);
168
169         if(length) {
170             data = rfx_alloc(length);
171             swf_GetBlock(tag, data, length);
172         } else {
173           data = 0;
174         }
175         action->op = op;
176         action->len = length;
177         action->data = data;
178     }
179     return tmp.next;
180 }
181
182 void swf_ActionFree(ActionTAG*action)
183 {
184     if(!action) {
185         fprintf(stderr, "Warning: freeing zero action");
186         return;
187     }
188     action = action->parent;
189     if(!action) {
190         fprintf(stderr, "Warning: freeing zero action (no parent)");
191         return;
192     }
193
194     while(action)
195     {
196         ActionTAG*tmp;
197         if(action->data && action->data != action->tmp)
198             rfx_free(action->data);
199         
200         tmp = action;
201         action=action->next;
202         rfx_free(tmp);
203     }
204 }
205
206 void swf_ActionSet(TAG*tag, ActionTAG*action)
207 {
208     action=action->parent;
209     while(action)
210     {
211         swf_SetU8(tag, action->op);
212         if(action->op & 128)
213           swf_SetU16(tag, action->len);
214
215         swf_SetBlock(tag, action->data, action->len);
216
217         action = action->next;
218     }
219 }
220
221 int OpAdvance(char c, U8*data)
222 {
223     switch (c)
224     {
225         case 'f':
226             return 2;
227         case 'u':
228             return strlen(data)+1;
229         case 't':
230             return strlen(data)+1;
231         case 'l': 
232             return strlen(data)+1;
233         case 'c': 
234             return strlen(data)+1;
235         case 'C': 
236             return 2;
237         case 's':
238             return 1;
239         case 'm':
240             return 1;
241         case 'b':
242             return 2;
243         case 'r':
244             return 1;
245         case 'p': {
246             U8 type = *data++;
247             if(type == 0) {
248                 return 1+strlen(data)+1; //string
249             } else if (type == 1) {
250                 return 1+4; //float
251             } else if (type == 2) {
252                 return 1+0; //NULL
253             } else if (type == 3) {
254                 return 1+0; //Undefined
255             } else if (type == 4) {
256                 return 1+1; //register
257             } else if (type == 5) {
258                 return 1+1; //bool
259             } else if (type == 6) {
260                 return 1+8; //double
261             } else if (type == 7) {
262                 return 1+4; //int
263             } else if (type == 8) {
264                 return 1+1; //lookup
265             } else if (type == 9) {
266                 return 1+2; //lookup 16
267             } else return 1;
268             break;
269         }
270         case 'o': {
271             return 2;
272         }
273         case '{': {
274             U16 num;
275             U16 codesize;
276             U8* odata = data;
277             int t;
278             while(*data++); //name
279             num = (*data++)*256; //num
280             num += (*data++);
281             for(t=0;t<num;t++)
282                 while(*data++); //param
283             codesize = (*data++)*256; //num
284             codesize += (*data++);
285             return data-odata;
286         }
287     }
288     return 0;
289 }
290 #define ATAG_FULLLENGTH(atag) ((atag)->len + 1 + ((atag)->op&0x80?2:0))
291 #define MAX_LEVELS 16
292 /* TODO: * this should be in swfdump.c */
293 void swf_DumpActions(ActionTAG*atag, char*prefix) 
294 {
295     int t;
296     U8*data;
297     char* cp;
298     int entry = 0;
299     char spaces[MAX_LEVELS*4+1];
300     struct {
301         char*text;
302         int count;
303     } counter[MAX_LEVELS];
304     int countpos = 0;
305 #ifdef MAX_LOOKUP
306     char * lookup[MAX_LOOKUP];
307     memset(lookup,0x00,sizeof(lookup));
308 #endif
309     memset(spaces, 32, sizeof(spaces));
310     spaces[sizeof(spaces)-1] = 0;
311
312    if (!prefix)
313         prefix="";
314
315     while(atag)
316     {
317         char*indent = &spaces[sizeof(spaces)-1-countpos*4];
318         U16 poollen = 0;
319         for(t=0;t<definedactions;t++)
320             if(actions[t].op == atag->op)
321                 break;
322
323         if(t==definedactions) {
324             printf("%s (%5d bytes) action:%s unknown[%02x]", prefix, atag->len, indent, atag->op);
325         } else {
326             printf("%s (%5d bytes) action:%s %s", prefix, atag->len, indent, actions[t].name);
327         }
328         data = atag->data;
329         if(atag->len && t!=definedactions) //TODO: check for consistency: should we have a length?
330         {
331           cp = actions[t].flags;
332           while(*cp)
333           {
334               switch(*cp)
335               {
336                   case 'f': { //frame
337                       printf(" %d", data[0]+256*data[1]);
338                   } break;
339                   case 'u': {
340                       printf(" URL:\"%s\"", data);
341                   } break;
342                   case 't': {
343                       printf(" Target:\"%s\"", data);
344                   } break;
345                   case 'l': {
346                       printf(" Label:\"%s\"", data);
347                   } break;
348                   case 'c': {
349                       printf(" String:\"%s\"", data);
350 #ifdef MAX_LOOKUP
351                       if (entry<MAX_LOOKUP)
352                         lookup[entry++] = strdup(data);
353 #endif
354                   } break;
355                   case 'C': {
356                       poollen = data[0]+256*data[1];
357                       entry = 0;
358                       printf("(%d entries)", poollen);
359                   } break;
360                   case 's': {
361                       printf(" +%d", *data);
362                   } break;
363                   case 'm': {
364                       //m: method (byte) url:(0=none, 1=get, 2=datat)/gf2:(1=play)
365                       printf(" %d", *data);
366                   } break;
367                   case '{': {
368                       U16 num;
369                       U16 codesize;
370                       int s = 0;
371                       int t;
372                       printf(" %s(", data);
373                       while(data[s++]); //name
374                       num = (data[s++]); //num
375                       num += (data[s++])*256;
376                       for(t=0;t<num;t++) {
377                           printf("%s",data+s);  // 10/22/04 MD: added +s to
378                           if(t<num-1)
379                               printf(", ");
380                           while(data[s++]); //param
381                       }
382                       printf(")");
383                       codesize = (data[s++]); //num
384                       codesize += (data[s++])*256;
385                       printf(" codesize:%d ",codesize);
386                       printf("\n%s                       %s{", prefix, indent);
387                       if(countpos>=15) {
388                           printf("Error: nested too deep\n");
389                           continue;
390                       }
391                       counter[countpos].text = "}";
392                       counter[countpos].count = codesize + ATAG_FULLLENGTH(atag);
393                       countpos++;
394                   } break;
395                   case 'o': {
396                       int t;
397                       U16 codesize = data[0]+256*data[1];
398                       printf(" codesize:%d ", codesize);
399
400                       /* the following tries to find the "string"
401                          the flash documentation speaks of- I've
402                          never actually seen one yet. -mk */
403                       for(t=2;t<atag->len;t++)
404                           printf("[%02x]", atag->data[t]);
405
406                       printf("\n%s                       %s{", prefix, indent);
407                       if(countpos>=15) {
408                           printf("Error: nested too deep\n");
409                           continue;
410                       }
411                       counter[countpos].text = "}";
412                       counter[countpos].count = codesize + ATAG_FULLLENGTH(atag);
413                       countpos++;
414                   } break;
415                   case 'b': {
416                       printf(" %d", data[0]+256*(signed char)data[1]);
417                   } break;
418                   case 'r': {
419                       printf(" %d", data[0]);
420                   } break;
421                   case 'p': {
422                       U8 type = *data;
423                       unsigned char*value = data+1;
424                       if(type == 0) {
425                           printf(" String:\"%s\"", value);
426                       } else if (type == 1) {
427                           U32 f = value[0]+(value[1]<<8)+
428                                   (value[2]<<16)+(value[3]<<24);
429                           printf(" Float:%f", *(float*)&f);
430                       } else if (type == 2) {
431                           printf(" NULL");
432                       } else if (type == 3) {
433                           printf(" Undefined");
434                       } else if (type == 4) {
435                           printf(" register:%d", *value);
436                       } else if (type == 5) {
437                           printf(" bool:%s", *value?"true":"false");
438                       } else if (type == 6) {
439                           U8 a[8];
440                           int t;
441                           memcpy(&a[4],value,4);
442                           memcpy(a,&value[4],4);
443 #ifdef WORDS_BIGENDIAN
444                           for(t=0;t<4;t++) {
445                               U8 tmp = a[t];
446                               a[t]=a[7-t];
447                               a[7-t] = tmp;
448                           }
449 #endif
450                           printf(" double:%f", *(double*)a);
451                       } else if (type == 7) {
452                           printf(" int:%d", value[0]+(value[1]<<8)+
453                                             (value[2]<<16)+(value[3]<<24));
454                       } else if (type == 8) {
455                           printf(" Lookup:%d", *value);
456 #ifdef MAX_LOOKUP
457                           if (lookup[*value])
458                             printf(" (\"%s\")",lookup[*value]);
459 #endif
460                       } else if (type == 9) {
461                           U32 offset = value[0]+(value[1]<<8);
462                           printf(" Lookup16:%d", offset);
463 #ifdef MAX_LOOKUP
464                           if (lookup[offset])
465                             printf(" (\"%s\")",lookup[offset]);
466 #endif
467                       } else {
468                           printf(" UNKNOWN[%02x]",type);
469                       }
470                   } break;
471               }
472               data += OpAdvance(*cp, data);
473               if((*cp!='c' || !poollen) &&
474                  (*cp!='p' || !(data<&atag->data[atag->len])))
475                   cp++;
476               if(poollen)
477                   poollen--;
478           }
479         }
480
481         if(data < atag->data + atag->len)
482         {
483             int nl = ((atag->data+atag->len)-data);
484             int t;
485             printf(" (remainder of %d bytes:\"", nl);
486             for(t=0;t<nl;t++) {
487                 if(data[t]<32)
488                     printf("\\%d",data[t]);
489                 else
490                     printf("%c", data[t]);
491             }
492             printf("\")");
493         }
494         printf("\n");
495
496         for(t=0;t<countpos;t++) {
497             counter[t].count -= ATAG_FULLLENGTH(atag);
498             if(counter[t].count < 0) {
499                 printf("===== Error: Oplength errors =====\n");
500                 countpos = 0;
501                 break;
502             }
503         }
504
505         while(countpos && !counter[countpos-1].count)
506         {
507             printf("%s                   %s%s\n", 
508                 prefix, indent, counter[countpos-1].text);
509             indent += 4;
510             countpos--;
511         }
512
513         atag = atag->next;
514     }
515
516 #ifdef MAX_LOOKUP
517   for (t=0;t<MAX_LOOKUP;t++) if (lookup[t]) rfx_free(lookup[t]);
518 #endif
519 }
520
521 static const char TYPE_URL = 1;
522 static const char TYPE_TARGET = 2;
523 static const char TYPE_STRING = 4;
524
525 int swf_ActionEnumerate(ActionTAG*atag, char*(*callback)(char*), int type)
526 {
527     int t;
528     U8*data;
529     char* cp;
530     int count = 0;
531     while(atag)
532     {
533         U16 poollen = 0;
534         for(t=0;t<definedactions;t++)
535             if(actions[t].op == atag->op)
536                 break;
537
538         if(t==definedactions) {
539             // unknown actiontag
540             atag = atag->next;
541             count++;
542             continue;
543         }
544         cp = actions[t].flags;
545         data = atag->data;
546         if(atag->len) {
547             while(*cp) {
548                 U8 * replacepos = 0;
549                 int replacelen = 0;
550                 U8 * replacement = 0;
551                 switch(*cp)
552                 {
553                     case 'u': {
554                         if(type&TYPE_URL)
555                         {
556                             replacelen = strlen(data);
557                             replacepos = data;
558                             replacement = callback(data); // may be null
559                         }
560                     } break;
561                     case 't': {
562                         if(type&TYPE_TARGET)
563                         {
564                             replacelen = strlen(data);
565                             replacepos = data;
566                             replacement = callback(data); // may be null
567                         }
568                     } break;
569                     case 'c': {
570                         if(type&TYPE_STRING)
571                         {
572                             replacelen = strlen(data);
573                             replacepos = data;
574                             replacement = callback(data); // may be null
575                         }
576                     } break;
577                     case 'C': {
578                         poollen = (data[0]+256*data[1]);
579                     } break;
580                     case 'o': {
581                     } break;
582                     case 'p': {
583                         U8 datatype = *data;
584                         char*value = &data[1];
585                         if(datatype == 0) { //string
586                             if(type&TYPE_STRING)
587                             {
588                                 replacelen = strlen(value);
589                                 replacepos = value;
590                                 replacement = callback(value); // may be null
591                             }
592                         } else if (datatype == 8) { //lookup
593                         }
594                     } break;
595                 }
596                 data += OpAdvance(*cp, data);
597                 if(*cp!='c' || !poollen)
598                     cp++;
599                 if(poollen)
600                     poollen--;
601
602                 if(replacement)
603                 {
604                     int newlen = strlen(replacement);
605                     char * newdata = rfx_alloc(atag->len - replacelen + newlen);
606                     int rpos = replacepos - atag->data;
607                     memcpy(newdata, atag->data, rpos);
608                     memcpy(&newdata[rpos], replacement, newlen);
609                     memcpy(&newdata[rpos+newlen], &replacepos[replacelen],
610                             &data[atag->len] - &replacepos[replacelen]);
611                     rfx_free(atag->data);
612                     atag->data = newdata;
613                     data = &atag->data[rpos+newlen+1];
614                 }
615             }
616         }
617         atag = atag->next;
618         count ++;
619     }
620     return count;
621 }
622
623 void swf_ActionEnumerateTargets(ActionTAG*atag, char*(*callback)(char*))
624 {
625     swf_ActionEnumerate(atag, callback, TYPE_TARGET);
626 }
627 void swf_ActionEnumerateStrings(ActionTAG*atag, char*(*callback)(char*))
628 {
629     swf_ActionEnumerate(atag, callback, TYPE_STRING);
630 }
631 void swf_ActionEnumerateURLs(ActionTAG*atag, char*(*callback)(char*))
632 {
633     swf_ActionEnumerate(atag, callback, TYPE_URL);
634 }
635
636 /*static ActionTAG* swf_ActionStart()
637 {
638     ActionTAG*atag;
639     atag = (ActionTAG*)rfx_alloc(sizeof(ActionTAG));
640     atag->prev = 0;
641     atag->next = 0;
642     atag->parent = 0;
643     atag->data = 0;
644     atag->len = 0;
645     return atag;
646 }
647
648 void swf_ActionEnd(ActionTAG* atag)
649 {
650     ActionTAG*last;
651     while(atag) {
652         last = atag;
653         atag=atag->next;
654     } 
655
656     last->prev->next = 0;
657     rfx_free(last);
658 }*/
659
660 static ActionTAG*lastATAG(ActionTAG*atag)
661 {
662     ActionTAG*last = 0;
663     while(atag) {
664         last = atag;
665         atag=atag->next;
666     } 
667     return last;
668 }
669
670 ActionTAG* swf_AddActionTAG(ActionTAG*atag, U8 op, U8*data, U16 len)
671 {
672     ActionTAG*tmp;
673     tmp = (ActionTAG*)rfx_alloc(sizeof(ActionTAG));
674     tmp->next = 0;
675     if(atag) {
676         tmp->prev = atag;
677         atag->next = tmp;
678         tmp->parent = atag->parent;
679     } else {
680         tmp->prev = 0;
681         tmp->parent = tmp;
682     }
683     if(data || !len)
684         tmp->data = data;
685     else
686         tmp->data = tmp->tmp;
687
688     tmp->len = len;
689     tmp->op = op;
690     return tmp;
691 }
692
693 ActionMarker action_setMarker(ActionTAG*atag)
694 {
695     ActionMarker m;
696     m.atag = atag;
697     return m;
698 }
699
700 int inline ActionTagSize(ActionTAG*atag)
701 {
702     return (atag->op&0x80)?3+(atag->len):1+0;
703 }
704
705
706 #define ACTION_END            0x00
707 #define ACTION_NEXTFRAME      0x04
708 #define ACTION_PREVIOUSFRAME  0x05
709 #define ACTION_PLAY           0x06
710 #define ACTION_STOP           0x07
711 #define ACTION_TOGGLEQUALITY  0x08
712 #define ACTION_STOPSOUNDS     0x09
713 #define ACTION_ADD            0x0a
714 #define ACTION_SUBTRACT       0x0b
715 #define ACTION_MULTIPLY       0x0c
716 #define ACTION_DIVIDE         0x0d
717 #define ACTION_EQUALS         0x0e
718 #define ACTION_LESS           0x0f
719 #define ACTION_AND            0x10
720 #define ACTION_OR             0x11
721 #define ACTION_NOT            0x12
722 #define ACTION_STRINGEQUALS   0x13
723 #define ACTION_STRINGLENGTH   0x14
724 #define ACTION_STRINGEXTRACT  0x15
725 #define ACTION_POP            0x17
726 #define ACTION_TOINTEGER      0x18
727 #define ACTION_GETVARIABLE    0x1c
728 #define ACTION_SETVARIABLE    0x1d
729 #define ACTION_SETTARGET2     0x20
730 #define ACTION_STRINGADD      0x21
731 #define ACTION_GETPROPERTY    0x22
732 #define ACTION_SETPROPERTY    0x23
733 #define ACTION_CLONESPRITE    0x24
734 #define ACTION_REMOVESPRITE   0x25
735 #define ACTION_TRACE          0x26
736 #define ACTION_STARTDRAG      0x27
737 #define ACTION_ENDDRAG        0x28
738 #define ACTION_STRINGLESS     0x29
739 #define ACTION_RANDOMNUMBER   0x30
740 #define ACTION_MBSTRINGLENGTH 0x31
741 #define ACTION_CHARTOASCII    0x32
742 #define ACTION_ASCIITOCHAR    0x33
743 #define ACTION_GETTIME        0x34
744 #define ACTION_MBSTRINGEXTRACT 0x35
745 #define ACTION_MBCHARTOASCII  0x36
746 #define ACTION_MBASCIITOCHAR  0x37
747 #define ACTION_DELETE         0x3a
748 #define ACTION_DELETE2        0x3b
749 #define ACTION_DEFINELOCAL    0x3c
750 #define ACTION_CALLFUNCTION   0x3d
751 #define ACTION_RETURN         0x3e
752 #define ACTION_MODULO         0x3f
753 #define ACTION_NEWOBJECT      0x40
754 #define ACTION_DEFINELOCAL2   0x41
755 #define ACTION_INITARRAY      0x42
756 #define ACTION_MAKEHASH       0x43
757 #define ACTION_TYPEOF         0x44
758 #define ACTION_TARGETPATH     0x45
759 #define ACTION_ENUMERATE      0x46
760 #define ACTION_ADD2           0x47
761 #define ACTION_LESS2          0x48
762 #define ACTION_EQUALS2        0x49
763 #define ACTION_TONUMBER       0x4a
764 #define ACTION_TOSTRING       0x4b
765 #define ACTION_PUSHDUPLICATE  0x4c
766 #define ACTION_STACKSWAP      0x4d
767 #define ACTION_GETMEMBER      0x4e
768 #define ACTION_SETMEMBER      0x4f
769 #define ACTION_INCREMENT      0x50
770 #define ACTION_DECREMENT      0x51
771 #define ACTION_CALLMETHOD     0x52
772 #define ACTION_NEWMETHOD      0x53
773 #define ACTION_BITAND         0x60
774 #define ACTION_BITOR          0x61
775 #define ACTION_BITXOR         0x62
776 #define ACTION_BITLSHIFT      0x63
777 #define ACTION_BITRSHIFT      0x64
778 #define ACTION_BITURSHIFT     0x65
779 #define ACTION_GOTOFRAME      0x81
780 #define ACTION_GETURL         0x83
781 #define ACTION_STOREREGISTER  0x87
782 #define ACTION_CONSTANTPOOL   0x88
783 #define ACTION_WAITFORFRAME   0x8a
784 #define ACTION_SETTARGET      0x8b
785 #define ACTION_GOTOLABEL      0x8c
786 #define ACTION_WAITFORFRAME2  0x8d
787 #define ACTION_WITH           0x94
788 #define ACTION_PUSH           0x96
789 #define ACTION_JUMP           0x99
790 #define ACTION_GETURL2        0x9a
791 #define ACTION_DEFINEFUNCTION 0x9b
792 #define ACTION_IF             0x9d
793 #define ACTION_CALL           0x9e
794 #define ACTION_GOTOFRAME2     0x9f
795
796 void action_fixjump(ActionMarker m1, ActionMarker m2)
797 {
798     ActionTAG* a1 = m1.atag;
799     ActionTAG* a2 = m2.atag;
800     ActionTAG* a;
801     int len = 0;
802     int oplen = 0;
803     a = a1;
804     
805     a = a->next; //first one is free
806     while(a && a!=a2)
807     {
808         len += ActionTagSize(a);
809         oplen ++;
810         a = a->next;
811     }
812     if(!a)
813     { len = 0;
814       oplen = 0;
815       a = a2;
816       while(a && a!=a1) {
817           len -= ActionTagSize(a);
818           oplen --;
819           a = a->next;
820       }
821       if(!a) {
822           fprintf(stderr, "action_fixjump: couldn't find second tag\n");
823           return;
824       }
825       len -= ActionTagSize(a);
826       oplen --;
827     }
828
829     if (a1->op == ACTION_IF || a1->op == ACTION_JUMP) 
830     {
831         *(U16*)(a1->data) = SWAP16(len);
832     }
833     else if(a1->op == ACTION_WAITFORFRAME)
834     {
835         ((U8*)(a1->data))[2] = oplen;
836     }
837     else if(a1->op == ACTION_WAITFORFRAME2)
838     {
839         ((U8*)(a1->data))[0] = oplen;
840     }
841     
842 }
843
844 ActionTAG* action_NextFrame(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_NEXTFRAME, 0, 0);}
845 ActionTAG* action_PreviousFrame(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_PREVIOUSFRAME, 0, 0);}
846 ActionTAG* action_Play(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_PLAY, 0, 0);}
847 ActionTAG* action_Stop(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STOP, 0, 0);}
848 ActionTAG* action_ToggleQuality(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TOGGLEQUALITY, 0, 0);}
849 ActionTAG* action_StopSounds(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STOPSOUNDS, 0, 0);}
850 ActionTAG* action_Add(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ADD, 0, 0);}
851 ActionTAG* action_Subtract(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SUBTRACT, 0, 0);}
852 ActionTAG* action_Multiply(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MULTIPLY, 0, 0);}
853 ActionTAG* action_Divide(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DIVIDE, 0, 0);}
854 ActionTAG* action_Equals(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_EQUALS, 0, 0);}
855 ActionTAG* action_Less(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_LESS, 0, 0);}
856 ActionTAG* action_And(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_AND, 0, 0);}
857 ActionTAG* action_Or(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_OR, 0, 0);}
858 ActionTAG* action_Not(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_NOT, 0, 0);}
859 ActionTAG* action_StringEquals(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGEQUALS, 0, 0);}
860 ActionTAG* action_StringLength(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGLENGTH, 0, 0);}
861 ActionTAG* action_StringExtract(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGEXTRACT, 0, 0);}
862 ActionTAG* action_Pop(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_POP, 0, 0);}
863 ActionTAG* action_ToInteger(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TOINTEGER, 0, 0);}
864 ActionTAG* action_GetVariable(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_GETVARIABLE, 0, 0);}
865 ActionTAG* action_SetVariable(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SETVARIABLE, 0, 0);}
866 ActionTAG* action_SetTarget2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SETTARGET2, 0, 0);}
867 ActionTAG* action_StringAdd(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGADD, 0, 0);}
868 ActionTAG* action_GetProperty(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_GETPROPERTY, 0, 0);}
869 ActionTAG* action_SetProperty(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SETPROPERTY, 0, 0);}
870 ActionTAG* action_CloneSprite(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CLONESPRITE, 0, 0);}
871 ActionTAG* action_RemoveSprite(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_REMOVESPRITE, 0, 0);}
872 ActionTAG* action_Trace(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TRACE, 0, 0);}
873 ActionTAG* action_StartDrag(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STARTDRAG, 0, 0);}
874 ActionTAG* action_EndDrag(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ENDDRAG, 0, 0);}
875 ActionTAG* action_StringLess(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGLESS, 0, 0);}
876 ActionTAG* action_RandomNumber(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_RANDOMNUMBER, 0, 0);}
877 ActionTAG* action_MBStringLength(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MBSTRINGLENGTH, 0, 0);}
878 ActionTAG* action_CharToAscii(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CHARTOASCII, 0, 0);}
879 ActionTAG* action_AsciiToChar(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ASCIITOCHAR, 0, 0);}
880 ActionTAG* action_GetTime(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_GETTIME, 0, 0);}
881 ActionTAG* action_MBStringExtract(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MBSTRINGEXTRACT, 0, 0);}
882 ActionTAG* action_MBCharToAscii(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MBCHARTOASCII, 0, 0);}
883 ActionTAG* action_MBAsciiToChar(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MBASCIITOCHAR, 0, 0);}
884 ActionTAG* action_Delete(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DELETE, 0, 0);}
885 ActionTAG* action_Delete2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DELETE2, 0, 0);}
886 ActionTAG* action_DefineLocal(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DEFINELOCAL, 0, 0);}
887 ActionTAG* action_CallFunction(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CALLFUNCTION, 0, 0);}
888 ActionTAG* action_Return(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_RETURN, 0, 0);}
889 ActionTAG* action_Modulo(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MODULO, 0, 0);}
890 ActionTAG* action_NewObject(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_NEWOBJECT, 0, 0);}
891 ActionTAG* action_DefineLocal2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DEFINELOCAL2, 0, 0);}
892 ActionTAG* action_InitArray(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_INITARRAY, 0, 0);}
893 ActionTAG* action_Makehash(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MAKEHASH, 0, 0);}
894 ActionTAG* action_TypeOf(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TYPEOF, 0, 0);}
895 ActionTAG* action_TargetPath(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TARGETPATH, 0, 0);}
896 ActionTAG* action_Enumerate(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ENUMERATE, 0, 0);}
897 ActionTAG* action_Add2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ADD2, 0, 0);}
898 ActionTAG* action_Less2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_LESS2, 0, 0);}
899 ActionTAG* action_Equals2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_EQUALS2, 0, 0);}
900 ActionTAG* action_ToNumber(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TONUMBER, 0, 0);}
901 ActionTAG* action_ToString(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TOSTRING, 0, 0);}
902 ActionTAG* action_PushDuplicate(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_PUSHDUPLICATE, 0, 0);}
903 ActionTAG* action_StackSwap(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STACKSWAP, 0, 0);}
904 ActionTAG* action_GetMember(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_GETMEMBER, 0, 0);}
905 ActionTAG* action_SetMember(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SETMEMBER, 0, 0);}
906 ActionTAG* action_Increment(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_INCREMENT, 0, 0);}
907 ActionTAG* action_Decrement(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DECREMENT, 0, 0);}
908 ActionTAG* action_CallMethod(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CALLMETHOD, 0, 0);}
909 ActionTAG* action_NewMethod(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_NEWMETHOD, 0, 0);}
910 ActionTAG* action_BitAnd(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITAND, 0, 0);}
911 ActionTAG* action_BitOr(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITOR, 0, 0);}
912 ActionTAG* action_BitXor(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITXOR, 0, 0);}
913 ActionTAG* action_BitLShift(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITLSHIFT, 0, 0);}
914 ActionTAG* action_BitRShift(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITRSHIFT, 0, 0);}
915 ActionTAG* action_BitURShift(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITURSHIFT, 0, 0);}
916 ActionTAG* action_Call(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CALL, 0, 0);}
917 ActionTAG* action_End(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_END, 0, 0);}
918 ActionTAG* action_GotoFrame(ActionTAG*atag, U16 frame) 
919 {
920     atag = swf_AddActionTAG(atag, ACTION_GOTOFRAME, 0, 2);
921     *(U16*)atag->tmp = SWAP16(frame);
922     return atag;
923 }
924
925 ActionTAG* action_Jump(ActionTAG*atag, U16 branch) 
926 {
927     atag = swf_AddActionTAG(atag, ACTION_JUMP, 0, 2);
928     *(U16*)atag->tmp = SWAP16(branch);
929     return atag;
930 }
931 ActionTAG* action_If(ActionTAG*atag, U16 branch) 
932 {
933     atag = swf_AddActionTAG(atag, ACTION_IF, 0, 2);
934     *(U16*)atag->tmp = SWAP16(branch);
935     return atag;
936 }
937 ActionTAG* action_StoreRegister(ActionTAG*atag, U8 reg) 
938 {
939     atag = swf_AddActionTAG(atag, ACTION_STOREREGISTER, 0, 1);
940     *(U8*)atag->tmp = reg;
941     return atag;
942 }
943 ActionTAG* action_GotoFrame2(ActionTAG*atag, U8 method) 
944 {
945     atag = swf_AddActionTAG(atag, ACTION_GOTOFRAME2, 0, 1);
946     *(U8*)atag->tmp = method;
947     return atag;
948 }
949 ActionTAG* action_GetUrl2(ActionTAG*atag, U8 method) 
950 {
951     atag = swf_AddActionTAG(atag, ACTION_GETURL2, 0, 1);
952     *(U8*)atag->tmp = method;
953     return atag;
954 }
955 ActionTAG* action_WaitForFrame2(ActionTAG*atag, U8 skip) 
956 {
957     atag = swf_AddActionTAG(atag, ACTION_WAITFORFRAME2, 0, 1);
958     *(U8*)atag->tmp = skip;
959     return atag;
960 }
961 ActionTAG* action_WaitForFrame(ActionTAG*atag, U16 frame, U8 skip) 
962 {
963     atag = swf_AddActionTAG(atag, ACTION_WAITFORFRAME, 0, 3);
964     *(U16*)atag->tmp = SWAP16(frame);
965     *(U8*)&atag->tmp[2] = skip;
966     return atag;
967 }
968 ActionTAG* action_SetTarget(ActionTAG*atag, char* target)
969 {
970     char*ptr = strdup(target);
971     return swf_AddActionTAG(atag, ACTION_SETTARGET, (U8*)ptr, strlen(ptr)+1);
972 }
973 ActionTAG* action_PushNULL(ActionTAG*atag) 
974 {
975     atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 1);
976     *(U8*)atag->tmp = 2; //NULL
977     return atag;
978 }
979 ActionTAG* action_PushUndefined(ActionTAG*atag) 
980 {
981     atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 1);
982     *(U8*)atag->tmp = 3; //Undefined
983     return atag;
984 }
985 ActionTAG* action_PushBoolean(ActionTAG*atag, char c) 
986 {
987     atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 2);
988     *(U8*)atag->tmp = 5; //bool
989     *(U8*)&atag->tmp[1] = c;
990     return atag;
991 }
992 ActionTAG* action_PushRegister(ActionTAG*atag, U8 reg) 
993 {
994     atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 2);
995     *(U8*)atag->tmp = 4; //register
996     *(U8*)&atag->tmp[1] = reg;
997     return atag;
998 }
999 ActionTAG* action_PushLookup(ActionTAG*atag, U8 index) 
1000 {
1001     atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 2);
1002     *(U8*)atag->tmp = 8; //lookup
1003     *(U8*)&atag->tmp[1] = index;
1004     return atag;
1005 }
1006 ActionTAG* action_PushLookup16(ActionTAG*atag, U16 index) 
1007 {
1008     atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 3);
1009     *(U8*)atag->tmp = 9; //lookup
1010     *(U8*)&atag->tmp[1] = index;
1011     *(U8*)&atag->tmp[2] = index>>8;
1012     return atag;
1013 }
1014 ActionTAG* action_PushString(ActionTAG*atag, char*str) 
1015 {
1016     int l = strlen(str);
1017     char*ptr = (char*)rfx_alloc(l+2);
1018     ptr[0] = 0; // string
1019     strcpy(&ptr[1], str);
1020     return swf_AddActionTAG(atag, ACTION_PUSH, (U8*)ptr, l+2);
1021 }
1022 ActionTAG* action_PushFloat(ActionTAG*atag, float f)
1023 {
1024     char*ptr = (char*)rfx_alloc(5);
1025     U32 fd = *(U32*)&f;
1026     ptr[0] = 1; //float
1027     ptr[1]  = fd;
1028     ptr[2]  = fd>>8;
1029     ptr[3]  = fd>>16;
1030     ptr[4]  = fd>>24;
1031     return swf_AddActionTAG(atag, ACTION_PUSH, (U8*)ptr, 5);
1032 }
1033 ActionTAG* action_PushDouble(ActionTAG*atag, double d) 
1034 {
1035     char*ptr = (char*)rfx_alloc(9);
1036     U8*dd = (U8*)&d;
1037     ptr[0] = 6; //double
1038 #ifdef WORDS_BIGENDIAN
1039     ptr[1] = dd[7];ptr[2] = dd[6];
1040     ptr[3] = dd[5];ptr[4] = dd[4];
1041     ptr[5] = dd[3];ptr[6] = dd[2];
1042     ptr[7] = dd[1];ptr[8] = dd[0];
1043 #else
1044     ptr[1] = dd[0];ptr[2] = dd[1];
1045     ptr[3] = dd[2];ptr[4] = dd[3];
1046     ptr[5] = dd[4];ptr[6] = dd[5];
1047     ptr[7] = dd[6];ptr[8] = dd[7];
1048 #endif
1049     return swf_AddActionTAG(atag, ACTION_PUSH, (U8*)ptr, 9);
1050 }
1051 ActionTAG* action_PushInt(ActionTAG*atag, int i)
1052 {
1053     atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 5);
1054     *(U8*)atag->tmp = 7; //int
1055     atag->tmp[1] = i;
1056     atag->tmp[2] = i>>8;
1057     atag->tmp[3] = i>>16;
1058     atag->tmp[4] = i>>24;
1059     return atag;
1060 }
1061 ActionTAG* action_GotoLabel(ActionTAG*atag, char* label)
1062 {
1063     char*ptr = strdup(label);
1064     return swf_AddActionTAG(atag, ACTION_GOTOLABEL, (U8*)ptr, strlen(ptr));
1065 }
1066 ActionTAG* action_GetUrl(ActionTAG*atag, char* url, char* label) 
1067 {
1068     int l1= strlen(url);
1069     int l2= strlen(label);
1070     char*ptr = rfx_alloc(l1+l2+2);
1071     strcpy(ptr, url);
1072     strcpy(&ptr[l1+1], label);
1073     return swf_AddActionTAG(atag, ACTION_GETURL, ptr, l1+l2+2);
1074 }
1075 //TODO:
1076 ActionTAG* action_DefineFunction(ActionTAG*atag, U8*data, int len) {return atag;}
1077 ActionTAG* action_Constantpool(ActionTAG*atag, char* constantpool) {return atag;}
1078 ActionTAG*  action_With(ActionTAG*atag, char*object) {return atag;}
1079
1080 #include "../action/actioncompiler.h"
1081
1082 ActionTAG* swf_ActionCompile(const char* source, int version)
1083 {
1084     TAG* tag;
1085     ActionTAG* a = 0;
1086     void*buffer = 0;
1087     int len = 0;
1088     int ret;
1089     
1090     tag = swf_InsertTag(NULL, ST_DOACTION);
1091     ret = compileSWFActionCode(source, version, &buffer, &len);
1092     if(!ret || buffer==0 || len == 0)
1093         return 0;
1094
1095     swf_SetBlock(tag, buffer, len);
1096     swf_SetU8(tag, 0);
1097
1098     rfx_free(buffer);
1099
1100     a = swf_ActionGet(tag);
1101     swf_DeleteTag(tag);
1102     return a;
1103 }
1104
1105
1106 /*
1107   Properties:
1108
1109   _X 0
1110   _Y 1
1111   _xscale 2
1112   _yscale 3
1113   _currentframe 4
1114   _totalframes 5
1115   _alpha 6
1116   _visible 7
1117   _width 8
1118   _height 9
1119   _rotation 10
1120   _target 11
1121   _framesloaded 12
1122   _name 13
1123   _droptarget 14
1124   _url 15
1125   _highquality 16
1126   _focusrect 17
1127   _soundbuftime 18
1128   _quality* 19
1129   _xmouse* 20
1130   _ymouse* 21
1131 */