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