652fd6d2cd8809d3580230e8e9f903a4ff432e09
[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 file is distributed under the GPL, see file COPYING for details 
11
12 */
13
14 #include "../rfxswf.h"
15
16 struct Action
17 {
18     int version;
19     char*name;
20     U8 op;
21     char*flags;
22 } static actions[] =
23 {
24 /*
25 f: frame (word)
26 u: url (string)
27 t: target (string)
28 l: label (string)
29 C: constant pool header (byte)
30 c: constant pool entry (string)
31 s: skip (byte) (number of actions)
32 m: method (byte) swf_GetUrl2:(0=none, 1=get, 2=post)/GotoFrame2:(1=play)
33 b: branch (word) (number of bytes)
34 p (push): type(byte), type=0:string, type=1:double
35 {: define function (name (string), num (word), params (num strings), codesize (word)
36 o: object (string)
37 r: register (byte)
38  */
39 {3,"End", 0x00, ""},
40 {3,"GotoFrame", 0x81, "f"},
41 {4,"GotoFrame2", 0x9f, "m"}, // -1 (/Movieclip:3)
42 {3,"GetUrl", 0x83, "ul"},
43 {4,"GetUrl2", 0x9a, "m"}, //-2
44 {3,"NextFrame", 0x04, ""},
45 {3,"PreviousFrame", 0x05, ""},
46 {3,"Play", 0x06, ""},
47 {3,"Stop", 0x07, ""},
48 {3,"ToggleQuality", 0x08, ""},
49 {3,"StopSounds", 0x09, ""},
50 {3,"WaitForFrame", 0x8a, "fs"},
51 {4,"WaitForFrame2", 0x8d, "s"}, // -1
52 {3,"SetTarget", 0x8b, "t"},
53 {4,"SetTarget2", 0x20, ""}, //-1
54 {3,"GotoLabel", 0x8c, "l"},
55 {4,"Add", 0x0a, ""}, //  -2, +1
56 {4,"Multiply", 0x0c, ""}, //  -2, +1
57 {4,"Divide", 0x0d, ""}, //  -2, +1
58 {4,"Subtract", 0x0b, ""}, //  -2, +1
59 {4,"Less", 0x0f, ""}, //  -2, +1
60 {4,"Equals", 0x0e, ""}, //  -2, +1
61 {4,"And", 0x10, ""}, //  -2, +1
62 {4,"Or", 0x11, ""}, //  -2, +1
63 {4,"Not", 0x12, ""}, //  -1, +1
64 {4,"StringAdd", 0x21, ""}, // -2,+1
65 {4,"StringLength", 0x14, ""}, // -1, +1
66 {4,"MBStringLength", 0x31, ""}, // -1, +1
67 {4,"StringEquals", 0x13, ""}, // -2, +1
68 {4,"StringLess", 0x29, ""}, //-2, +1
69 {4,"StringExtract", 0x15, ""}, // -3, +1
70 {4,"MBStringExtract", 0x35, ""}, //-3 +1
71 {4,"Push", 0x96, "p"}, //  +1
72 {4,"Pop", 0x17, ""}, //  -1
73 {4,"ToInteger", 0x18, ""}, // -1, +1
74 {4,"CharToAscii", 0x32, ""}, // -1, +1
75 {4,"AsciiToChar", 0x33, ""}, // -1, +1
76 {4,"MBCharToAscii", 0x36, ""}, // -1, +1
77 {4,"MBAsciiToChar", 0x37, ""}, // -1, +1
78 {4,"Jump", 0x99, "b"},
79 {4,"If", 0x9d, "b"}, // -1
80 {4,"Call", 0x9e, ""}, //-1 (frame label/number) (high bit is wrong.)
81 {4,"GetVariable", 0x1c,""}, // -1, +1
82 {4,"SetVariable", 0x1d,""}, // -2
83 {4,"GetProperty", 0x22,""}, //-2, +1
84 {4,"SetProperty", 0x23, ""}, // -3
85 {4,"RemoveSprite", 0x25, ""}, //-1
86 {4,"StartDrag", 0x27, ""}, // -2, -1, (-4)
87 {4,"EndDrag", 0x28, ""}, 
88 {4,"CloneSprite", 0x24, ""}, // -3
89 {4,"Trace", 0x26, ""}, //-1
90 {4,"GetTime", 0x34, ""}, //+1
91 {4,"RandomNumber", 0x30, ""}, //-1,+1
92 {5,"Modulo", 0x3f,""},
93 {5,"BitAnd", 0x60,""},
94 {5,"BitLShift", 0x63,""},
95 {5,"BitOr", 0x61,""},
96 {5,"BitRShift", 0x64,""},
97 {5,"BitURShift", 0x65,""},
98 {5,"BitXor", 0x62,""},//66?
99 {5,"Decrement", 0x51,""},
100 {5,"Increment", 0x50,""},
101 {5,"PushDuplicate", 0x4c,""},
102 {5,"StackSwap", 0x4d,""}, //?
103 {5,"StoreRegister", 0x87,"r"},
104 {5,"CallFunction", 0x3d,""},
105 {5,"DefineFunction", 0x9b, "{"},
106 {5,"Return", 0x3e,""},
107 {5,"GetMember", 0x4e,""},
108 {5,"SetMember", 0x4f,""},
109 {5,"CallMethod", 0x52,""},
110 {5,"Constantpool", 0x88, "Cc"},
111 {5,"DefineLocal", 0x3c,""},
112 {5,"DefineLocal2", 0x41,""},
113 {5,"Makehash", 0x43, ""}, //??
114 {5,"Delete", 0x3a,""}, //?
115 {5,"Delete2", 0x3b,""},
116 {5,"Enumerate", 0x46,""},
117 {5,"Equals2", 0x49,""},
118 {5,"InitArray", 0x42,""}, // InitObject?
119 {5,"NewMethod", 0x53,""}, //?
120 {5,"NewObject", 0x40,""},
121 {5,"TargetPath", 0x45,""}, //?
122 {5,"With", 0x94, "o"},
123 {5,"ToNumber", 0x4a,""}, //?
124 {5,"ToString", 0x4b,""}, //?
125 {5,"TypeOf", 0x44,""},
126 {5,"Add2", 0x47,""},
127 {5,"Less2", 0x48,""}
128 };
129 static int definedactions = sizeof(actions)/sizeof(struct Action);
130
131 ActionTAG* swf_ActionGet(TAG*tag) 
132 {
133     U8 op = 1;
134     int length;
135     ActionTAG tmp;
136     ActionTAG*action = &tmp;
137     U8*data;
138     while(op)
139     {
140         action->next = (ActionTAG*)malloc(sizeof(ActionTAG));
141         action->next->prev = action;
142         action->next->next = 0;
143         action = action->next;
144
145         op = swf_GetU8(tag);
146         if(op<0x80)
147             length = 0;
148         else
149             length = swf_GetU16(tag);
150
151         if(length) {
152             data = malloc(length);
153             swf_GetBlock(tag, data, length);
154         } else {
155           data = 0;
156         }
157         action->op = op;
158         action->len = length;
159         action->data = data;
160         action->parent = tag;
161     }
162     return tmp.next;
163 }
164
165 void swf_ActionFree(ActionTAG*action)
166 {
167     while(action)
168     {
169         ActionTAG*tmp;
170         if(action->data && action->data != action->tmp)
171             free(action->data);
172         tmp = action;
173         action=action->next;
174         free(tmp);
175     }
176 }
177
178 void swf_ActionSet(TAG*tag, ActionTAG*action)
179 {
180     while(action)
181     {
182         swf_SetU8(tag, action->op);
183         if(action->op & 128)
184           swf_SetU16(tag, action->len);
185
186         swf_SetBlock(tag, action->data, action->len);
187
188         action = action->next;
189     }
190 }
191
192 int OpAdvance(char c, char*data)
193 {
194     switch (c)
195     {
196         case 'f':
197             return 2;
198         case 'u':
199             return strlen(data)+1;
200         case 't':
201             return strlen(data)+1;
202         case 'l': 
203             return strlen(data)+1;
204         case 'c': 
205             return strlen(data)+1;
206         case 'C': 
207             return 2;
208         case 's':
209             return 1;
210         case 'm':
211             return 1;
212         case 'b':
213             return 2;
214         case 'p': {
215             U8 type = *data++;
216             if(type == 0) {
217                 return 1+strlen(data)+1; //string
218             } else if (type == 1) {
219                 return 1+4; //float
220             } else if (type == 2) {
221                 return 1+0; //NULL
222             } else if (type == 4) {
223                 return 1+1; //register
224             } else if (type == 5) {
225                 return 1+1; //bool
226             } else if (type == 6) {
227                 return 1+8; //double
228             } else if (type == 7) {
229                 return 1+4; //int
230             } else if (type == 8) {
231                 return 1+1; //lookup
232             }
233             break;
234         }
235     }
236     return 0;
237 }
238
239 /* TODO: this should be in swfdump.c */
240 void swf_DumpActions(ActionTAG*atag, char*prefix) 
241 {
242     int t;
243     U8*data;
244     char* cp;
245     if(!prefix) 
246         prefix="";
247     while(atag)
248     {
249         U8 poollen = 0;
250         for(t=0;t<definedactions;t++)
251             if(actions[t].op == atag->op)
252                 break;
253
254         if(t==definedactions) {
255             printf("%s (%5d bytes) action: %02x\n", prefix, atag->len, atag->op);
256             atag = atag->next;
257             continue;
258         }
259         printf("%s (%5d bytes) action: %s", prefix, atag->len, actions[t].name);
260         cp = actions[t].flags;
261         data = atag->data;
262         if(atag->len) //TODO: check for consistency: should we have a length?
263         while(*cp)
264         {
265             switch(*cp)
266             {
267                 case 'f': {
268                     printf(" %d", *(U16*)data); //FIXME: le/be
269                 } break;
270                 case 'u': {
271                     printf(" URL:\"%s\"", data);
272                 } break;
273                 case 't': {
274                     printf(" Target:\"%s\"", data);
275                 } break;
276                 case 'l': {
277                     printf(" Label:\"%s\"", data);
278                 } break;
279                 case 'c': {
280                     printf(" String:\"%s\"", data);
281                 } break;
282                 case 'C': {
283                     poollen = *data;
284                     printf("(%d entries)", poollen);
285                 } break;
286                 case 's': {
287                     printf(" +%d", *data);
288                 } break;
289                 case 'm': {
290                     //m: method (byte) url:(0=none, 1=get, 2=datat)/gf2:(1=play)
291                     printf(" %d", *data);
292                 } break;
293                 case 'b': {
294                     printf(" %d", *(U16*)data);
295                 } break;
296                 case 'p': {
297                     U8 type = *data;
298                     char*value = data+1;
299                     if(type == 0) {
300                         printf(" String:\"%s\"", value);
301                     } else if (type == 1) {
302                         printf(" Float:%f", *(float*)value);
303                     } else if (type == 2) {
304                         printf(" NULL");
305                     } else if (type == 4) {
306                         printf(" register:%d", *value);
307                     } else if (type == 5) {
308                         printf(" bool:%s", *value?"true":"false");
309                     } else if (type == 6) {
310                         printf(" float:%f", *(double*)value);
311                     } else if (type == 7) {
312                         printf(" int:%d", *(int*)value);
313                     } else if (type == 8) {
314                         printf(" Lookup:%d", *value);
315                     } else {
316                         printf(" UNKNOWN[%02x]",type);
317                     }
318                 } break;
319             }
320             data += OpAdvance(*cp, data);
321             if((*cp!='c' || !poollen) &&
322                (*cp!='p' || !(data<&atag->data[atag->len])))
323                 cp++;
324             if(poollen)
325                 poollen--;
326         }
327
328         if(data < atag->data + atag->len)
329         {
330             int nl = ((atag->data+atag->len)-data);
331             int t;
332             printf(" (remainder of %d bytes:\"", nl);
333             for(t=0;t<nl;t++) {
334                 if(data[t]<32)
335                     printf("\\%d",data[t]);
336                 else
337                     printf("%c", data[t]);
338             }
339             printf("\")");
340         }
341         printf("\n");
342         atag = atag->next;
343     }
344 }
345
346 static const char TYPE_URL = 1;
347 static const char TYPE_TARGET = 2;
348 static const char TYPE_STRING = 4;
349
350 int swf_ActionEnumerate(ActionTAG*atag, char*(*callback)(char*), int type)
351 {
352     int t;
353     U8*data;
354     char* cp;
355     int count = 0;
356     while(atag)
357     {
358         U8 poollen = 0;
359         for(t=0;t<definedactions;t++)
360             if(actions[t].op == atag->op)
361                 break;
362
363         if(t==definedactions) {
364             // unknown actiontag
365             atag = atag->next;
366             count++;
367             continue;
368         }
369         cp = actions[t].flags;
370         data = atag->data;
371         if(atag->len) {
372             while(*cp) {
373                 U8 * replacepos = 0;
374                 int replacelen = 0;
375                 U8 * replacement = 0;
376                 switch(*cp)
377                 {
378                     case 'u': {
379                         if(type&TYPE_URL)
380                         {
381                             replacelen = strlen(data);
382                             replacepos = data;
383                             replacement = callback(data); // may be null
384                         }
385                     } break;
386                     case 't': {
387                         if(type&TYPE_TARGET)
388                         {
389                             replacelen = strlen(data);
390                             replacepos = data;
391                             replacement = callback(data); // may be null
392                         }
393                     } break;
394                     case 'c': {
395                         if(type&TYPE_STRING)
396                         {
397                             replacelen = strlen(data);
398                             replacepos = data;
399                             replacement = callback(data); // may be null
400                         }
401                     } break;
402                     case 'C': {
403                         poollen = (*data);
404                     } break;
405                     case 'o': {
406                     } break;
407                     case 'p': {
408                         U8 datatype = *data;
409                         char*value = &data[1];
410                         if(datatype == 0) { //string
411                             if(type&TYPE_STRING)
412                             {
413                                 replacelen = strlen(value);
414                                 replacepos = value;
415                                 replacement = callback(value); // may be null
416                             }
417                         } else if (datatype == 8) { //lookup
418                         }
419                     } break;
420                 }
421                 data += OpAdvance(*cp, data);
422                 if(*cp!='c' || !poollen)
423                     cp++;
424                 if(poollen)
425                     poollen--;
426
427                 if(replacement)
428                 {
429                     int newlen = strlen(replacement);
430                     char * newdata = malloc(atag->len - replacelen + newlen);
431                     int rpos = replacepos - atag->data;
432                     memcpy(newdata, atag->data, rpos);
433                     memcpy(&newdata[rpos], replacement, newlen);
434                     memcpy(&newdata[rpos+newlen], &replacepos[replacelen],
435                             &data[atag->len] - &replacepos[replacelen]);
436                     free(atag->data);
437                     atag->data = newdata;
438                     data = &atag->data[rpos+newlen+1];
439                 }
440             }
441         }
442         atag = atag->next;
443         count ++;
444     }
445     return count;
446 }
447
448 void swf_ActionEnumerateTargets(ActionTAG*atag, char*(*callback)(char*))
449 {
450     swf_ActionEnumerate(atag, callback, TYPE_TARGET);
451 }
452 void swf_ActionEnumerateStrings(ActionTAG*atag, char*(*callback)(char*))
453 {
454     swf_ActionEnumerate(atag, callback, TYPE_STRING);
455 }
456 void swf_ActionEnumerateURLs(ActionTAG*atag, char*(*callback)(char*))
457 {
458     swf_ActionEnumerate(atag, callback, TYPE_URL);
459 }
460
461 static ActionTAG * currentatag;
462
463 ActionTAG* swf_ActionStart()
464 {
465     currentatag = (ActionTAG*)malloc(sizeof(ActionTAG));
466     currentatag->prev = 0;
467     currentatag->parent = 0;
468     currentatag->data = 0;
469     currentatag->len = 0;
470     return currentatag;
471 }
472
473 void swf_ActionEnd()
474 {
475     currentatag->prev->next = 0;
476     free(currentatag);
477 }
478
479 void swf_AddActionTAG(U8 op, U8*data, U16 len)
480 {
481     currentatag->next = (ActionTAG*)malloc(sizeof(ActionTAG));
482     currentatag->next->prev = currentatag;
483     currentatag->parent = 0;
484     currentatag->data = data;
485     currentatag->len = len;
486     currentatag->op = op;
487     currentatag = currentatag->next;
488 }
489
490 ActionMarker action_setMarker()
491 {
492     ActionMarker m;
493     m.atag = currentatag;
494     return m;
495 }
496
497 int inline ActionTagSize(ActionTAG*atag)
498 {
499     return (atag->op&0x80)?3+(atag->len):1+0;
500 }
501
502
503 #define ACTION_END            0x00
504 #define ACTION_NEXTFRAME      0x04
505 #define ACTION_PREVIOUSFRAME  0x05
506 #define ACTION_PLAY           0x06
507 #define ACTION_STOP           0x07
508 #define ACTION_TOGGLEQUALITY  0x08
509 #define ACTION_STOPSOUNDS     0x09
510 #define ACTION_ADD            0x0a
511 #define ACTION_SUBTRACT       0x0b
512 #define ACTION_MULTIPLY       0x0c
513 #define ACTION_DIVIDE         0x0d
514 #define ACTION_EQUALS         0x0e
515 #define ACTION_LESS           0x0f
516 #define ACTION_AND            0x10
517 #define ACTION_OR             0x11
518 #define ACTION_NOT            0x12
519 #define ACTION_STRINGEQUALS   0x13
520 #define ACTION_STRINGLENGTH   0x14
521 #define ACTION_STRINGEXTRACT  0x15
522 #define ACTION_POP            0x17
523 #define ACTION_TOINTEGER      0x18
524 #define ACTION_GETVARIABLE    0x1c
525 #define ACTION_SETVARIABLE    0x1d
526 #define ACTION_SETTARGET2     0x20
527 #define ACTION_STRINGADD      0x21
528 #define ACTION_GETPROPERTY    0x22
529 #define ACTION_SETPROPERTY    0x23
530 #define ACTION_CLONESPRITE    0x24
531 #define ACTION_REMOVESPRITE   0x25
532 #define ACTION_TRACE          0x26
533 #define ACTION_STARTDRAG      0x27
534 #define ACTION_ENDDRAG        0x28
535 #define ACTION_STRINGLESS     0x29
536 #define ACTION_RANDOMNUMBER   0x30
537 #define ACTION_MBSTRINGLENGTH 0x31
538 #define ACTION_CHARTOASCII    0x32
539 #define ACTION_ASCIITOCHAR    0x33
540 #define ACTION_GETTIME        0x34
541 #define ACTION_MBSTRINGEXTRACT 0x35
542 #define ACTION_MBCHARTOASCII  0x36
543 #define ACTION_MBASCIITOCHAR  0x37
544 #define ACTION_DELETE         0x3a
545 #define ACTION_DELETE2        0x3b
546 #define ACTION_DEFINELOCAL    0x3c
547 #define ACTION_CALLFUNCTION   0x3d
548 #define ACTION_RETURN         0x3e
549 #define ACTION_MODULO         0x3f
550 #define ACTION_NEWOBJECT      0x40
551 #define ACTION_DEFINELOCAL2   0x41
552 #define ACTION_INITARRAY      0x42
553 #define ACTION_MAKEHASH       0x43
554 #define ACTION_TYPEOF         0x44
555 #define ACTION_TARGETPATH     0x45
556 #define ACTION_ENUMERATE      0x46
557 #define ACTION_ADD2           0x47
558 #define ACTION_LESS2          0x48
559 #define ACTION_EQUALS2        0x49
560 #define ACTION_TONUMBER       0x4a
561 #define ACTION_TOSTRING       0x4b
562 #define ACTION_PUSHDUPLICATE  0x4c
563 #define ACTION_STACKSWAP      0x4d
564 #define ACTION_GETMEMBER      0x4e
565 #define ACTION_SETMEMBER      0x4f
566 #define ACTION_INCREMENT      0x50
567 #define ACTION_DECREMENT      0x51
568 #define ACTION_CALLMETHOD     0x52
569 #define ACTION_NEWMETHOD      0x53
570 #define ACTION_BITAND         0x60
571 #define ACTION_BITOR          0x61
572 #define ACTION_BITXOR         0x62
573 #define ACTION_BITLSHIFT      0x63
574 #define ACTION_BITRSHIFT      0x64
575 #define ACTION_BITURSHIFT     0x65
576 #define ACTION_GOTOFRAME      0x81
577 #define ACTION_GETURL         0x83
578 #define ACTION_STOREREGISTER  0x87
579 #define ACTION_CONSTANTPOOL   0x88
580 #define ACTION_WAITFORFRAME   0x8a
581 #define ACTION_SETTARGET      0x8b
582 #define ACTION_GOTOLABEL      0x8c
583 #define ACTION_WAITFORFRAME2  0x8d
584 #define ACTION_WITH           0x94
585 #define ACTION_PUSH           0x96
586 #define ACTION_JUMP           0x99
587 #define ACTION_GETURL2        0x9a
588 #define ACTION_DEFINEFUNCTION 0x9b
589 #define ACTION_IF             0x9d
590 #define ACTION_CALL           0x9e
591 #define ACTION_GOTOFRAME2     0x9f
592
593 void action_fixjump(ActionMarker m1, ActionMarker m2)
594 {
595     ActionTAG* a1 = m1.atag;
596     ActionTAG* a2 = m2.atag;
597     ActionTAG* a;
598     int len = 0;
599     int oplen = 0;
600     a = a1;
601     
602     a = a->next; //first one is free
603     while(a && a!=a2)
604     {
605         len += ActionTagSize(a);
606         oplen ++;
607         a = a->next;
608     }
609     if(!a)
610     { len = 0;
611       oplen = 0;
612       a = a2;
613       while(a && a!=a1) {
614           len -= ActionTagSize(a);
615           oplen --;
616           a = a->next;
617       }
618       if(!a) {
619           fprintf(stderr, "action_fixjump: couldn't find second tag\n");
620           return;
621       }
622       len -= ActionTagSize(a);
623       oplen --;
624     }
625
626     if (a1->op == ACTION_IF || a1->op == ACTION_JUMP) 
627     {
628         *(U16*)(a1->data) = len;
629     }
630     else if(a1->op == ACTION_WAITFORFRAME)
631     {
632         ((U8*)(a1->data))[2] = oplen;
633     }
634     else if(a1->op == ACTION_WAITFORFRAME2)
635     {
636         ((U8*)(a1->data))[0] = oplen;
637     }
638     
639 }
640
641
642 void action_NextFrame() {swf_AddActionTAG(ACTION_NEXTFRAME, 0, 0);}
643 void action_PreviousFrame() {swf_AddActionTAG(ACTION_PREVIOUSFRAME, 0, 0);}
644 void action_Play() {swf_AddActionTAG(ACTION_PLAY, 0, 0);}
645 void action_Stop() {swf_AddActionTAG(ACTION_STOP, 0, 0);}
646 void action_ToggleQuality() {swf_AddActionTAG(ACTION_TOGGLEQUALITY, 0, 0);}
647 void action_StopSounds() {swf_AddActionTAG(ACTION_STOPSOUNDS, 0, 0);}
648 void action_Add() {swf_AddActionTAG(ACTION_ADD, 0, 0);}
649 void action_Subtract() {swf_AddActionTAG(ACTION_SUBTRACT, 0, 0);}
650 void action_Multiply() {swf_AddActionTAG(ACTION_MULTIPLY, 0, 0);}
651 void action_Divide() {swf_AddActionTAG(ACTION_DIVIDE, 0, 0);}
652 void action_Equals() {swf_AddActionTAG(ACTION_EQUALS, 0, 0);}
653 void action_Less() {swf_AddActionTAG(ACTION_LESS, 0, 0);}
654 void action_And() {swf_AddActionTAG(ACTION_AND, 0, 0);}
655 void action_Or() {swf_AddActionTAG(ACTION_OR, 0, 0);}
656 void action_Not() {swf_AddActionTAG(ACTION_NOT, 0, 0);}
657 void action_StringEquals() {swf_AddActionTAG(ACTION_STRINGEQUALS, 0, 0);}
658 void action_StringLength() {swf_AddActionTAG(ACTION_STRINGLENGTH, 0, 0);}
659 void action_StringExtract() {swf_AddActionTAG(ACTION_STRINGEXTRACT, 0, 0);}
660 void action_Pop() {swf_AddActionTAG(ACTION_POP, 0, 0);}
661 void action_ToInteger() {swf_AddActionTAG(ACTION_TOINTEGER, 0, 0);}
662 void action_GetVariable() {swf_AddActionTAG(ACTION_GETVARIABLE, 0, 0);}
663 void action_SetVariable() {swf_AddActionTAG(ACTION_SETVARIABLE, 0, 0);}
664 void action_SetTarget2() {swf_AddActionTAG(ACTION_SETTARGET2, 0, 0);}
665 void action_StringAdd() {swf_AddActionTAG(ACTION_STRINGADD, 0, 0);}
666 void action_GetProperty() {swf_AddActionTAG(ACTION_GETPROPERTY, 0, 0);}
667 void action_SetProperty() {swf_AddActionTAG(ACTION_SETPROPERTY, 0, 0);}
668 void action_CloneSprite() {swf_AddActionTAG(ACTION_CLONESPRITE, 0, 0);}
669 void action_RemoveSprite() {swf_AddActionTAG(ACTION_REMOVESPRITE, 0, 0);}
670 void action_Trace() {swf_AddActionTAG(ACTION_TRACE, 0, 0);}
671 void action_StartDrag() {swf_AddActionTAG(ACTION_STARTDRAG, 0, 0);}
672 void action_EndDrag() {swf_AddActionTAG(ACTION_ENDDRAG, 0, 0);}
673 void action_StringLess() {swf_AddActionTAG(ACTION_STRINGLESS, 0, 0);}
674 void action_RandomNumber() {swf_AddActionTAG(ACTION_RANDOMNUMBER, 0, 0);}
675 void action_MBStringLength() {swf_AddActionTAG(ACTION_MBSTRINGLENGTH, 0, 0);}
676 void action_CharToAscii() {swf_AddActionTAG(ACTION_CHARTOASCII, 0, 0);}
677 void action_AsciiToChar() {swf_AddActionTAG(ACTION_ASCIITOCHAR, 0, 0);}
678 void action_GetTime() {swf_AddActionTAG(ACTION_GETTIME, 0, 0);}
679 void action_MBStringExtract() {swf_AddActionTAG(ACTION_MBSTRINGEXTRACT, 0, 0);}
680 void action_MBCharToAscii() {swf_AddActionTAG(ACTION_MBCHARTOASCII, 0, 0);}
681 void action_MBAsciiToChar() {swf_AddActionTAG(ACTION_MBASCIITOCHAR, 0, 0);}
682 void action_Delete() {swf_AddActionTAG(ACTION_DELETE, 0, 0);}
683 void action_Delete2() {swf_AddActionTAG(ACTION_DELETE2, 0, 0);}
684 void action_DefineLocal() {swf_AddActionTAG(ACTION_DEFINELOCAL, 0, 0);}
685 void action_CallFunction() {swf_AddActionTAG(ACTION_CALLFUNCTION, 0, 0);}
686 void action_Return() {swf_AddActionTAG(ACTION_RETURN, 0, 0);}
687 void action_Modulo() {swf_AddActionTAG(ACTION_MODULO, 0, 0);}
688 void action_NewObject() {swf_AddActionTAG(ACTION_NEWOBJECT, 0, 0);}
689 void action_DefineLocal2() {swf_AddActionTAG(ACTION_DEFINELOCAL2, 0, 0);}
690 void action_InitArray() {swf_AddActionTAG(ACTION_INITARRAY, 0, 0);}
691 void action_Makehash() {swf_AddActionTAG(ACTION_MAKEHASH, 0, 0);}
692 void action_TypeOf() {swf_AddActionTAG(ACTION_TYPEOF, 0, 0);}
693 void action_TargetPath() {swf_AddActionTAG(ACTION_TARGETPATH, 0, 0);}
694 void action_Enumerate() {swf_AddActionTAG(ACTION_ENUMERATE, 0, 0);}
695 void action_Add2() {swf_AddActionTAG(ACTION_ADD2, 0, 0);}
696 void action_Less2() {swf_AddActionTAG(ACTION_LESS2, 0, 0);}
697 void action_Equals2() {swf_AddActionTAG(ACTION_EQUALS2, 0, 0);}
698 void action_ToNumber() {swf_AddActionTAG(ACTION_TONUMBER, 0, 0);}
699 void action_ToString() {swf_AddActionTAG(ACTION_TOSTRING, 0, 0);}
700 void action_PushDuplicate() {swf_AddActionTAG(ACTION_PUSHDUPLICATE, 0, 0);}
701 void action_StackSwap() {swf_AddActionTAG(ACTION_STACKSWAP, 0, 0);}
702 void action_GetMember() {swf_AddActionTAG(ACTION_GETMEMBER, 0, 0);}
703 void action_SetMember() {swf_AddActionTAG(ACTION_SETMEMBER, 0, 0);}
704 void action_Increment() {swf_AddActionTAG(ACTION_INCREMENT, 0, 0);}
705 void action_Decrement() {swf_AddActionTAG(ACTION_DECREMENT, 0, 0);}
706 void action_CallMethod() {swf_AddActionTAG(ACTION_CALLMETHOD, 0, 0);}
707 void action_NewMethod() {swf_AddActionTAG(ACTION_NEWMETHOD, 0, 0);}
708 void action_BitAnd() {swf_AddActionTAG(ACTION_BITAND, 0, 0);}
709 void action_BitOr() {swf_AddActionTAG(ACTION_BITOR, 0, 0);}
710 void action_BitXor() {swf_AddActionTAG(ACTION_BITXOR, 0, 0);}
711 void action_BitLShift() {swf_AddActionTAG(ACTION_BITLSHIFT, 0, 0);}
712 void action_BitRShift() {swf_AddActionTAG(ACTION_BITRSHIFT, 0, 0);}
713 void action_BitURShift() {swf_AddActionTAG(ACTION_BITURSHIFT, 0, 0);}
714 void action_Call() {swf_AddActionTAG(ACTION_CALL, 0, 0);}
715 void action_End() {swf_AddActionTAG(ACTION_END, 0, 0);}
716 void action_GotoFrame(U16 frame) 
717 {
718     *(U16*)currentatag->tmp = frame;
719     swf_AddActionTAG(ACTION_GOTOFRAME, (U8*)currentatag->tmp, 2);
720 }
721 void action_Jump(U16 branch) 
722 {
723     *(U16*)currentatag->tmp = branch;
724     swf_AddActionTAG(ACTION_JUMP, (U8*)currentatag->tmp, 2);
725 }
726 void action_If(U16 branch) 
727 {
728     *(U16*)currentatag->tmp = branch;
729     swf_AddActionTAG(ACTION_IF, (U8*)currentatag->tmp, 2);
730 }
731 void action_StoreRegister(U8 reg) 
732 {
733     *(U8*)currentatag->tmp = reg;
734     swf_AddActionTAG(ACTION_STOREREGISTER, (U8*)currentatag->tmp, 1);
735 }
736 void action_GotoFrame2(U8 method) 
737 {
738     *(U8*)currentatag->tmp = method;
739     swf_AddActionTAG(ACTION_GOTOFRAME2, (U8*)currentatag->tmp, 1);
740 }
741 void action_GetUrl2(U8 method) 
742 {
743     *(U8*)currentatag->tmp = method;
744     swf_AddActionTAG(ACTION_GETURL2, (U8*)currentatag->tmp, 1);
745 }
746 void action_WaitForFrame2(U8 skip) 
747 {
748     *(U8*)currentatag->tmp = skip;
749     swf_AddActionTAG(ACTION_WAITFORFRAME2, (U8*)currentatag->tmp, 1);
750 }
751 void action_WaitForFrame(U16 frame, U8 skip) 
752 {
753     *(U16*)currentatag->tmp = frame;
754     *(U8*)&currentatag->tmp[2] = skip;
755     swf_AddActionTAG(ACTION_WAITFORFRAME, (U8*)currentatag->tmp, 3);
756 }
757 void action_SetTarget(char* target)
758 {
759     char*ptr = strdup(target);
760     swf_AddActionTAG(ACTION_SETTARGET, (U8*)ptr, strlen(ptr)+1);
761 }
762 void action_PushNULL() 
763 {
764     *(U8*)currentatag->tmp = 2; //NULL
765     swf_AddActionTAG(ACTION_PUSH, (U8*)currentatag->tmp, 1);
766 }
767 void action_PushBoolean(char c) 
768 {
769     *(U8*)currentatag->tmp = 5; //bool
770     *(U8*)&currentatag->tmp[1] = c;
771     swf_AddActionTAG(ACTION_PUSH, (U8*)currentatag->tmp, 2);
772 }
773 void action_PushRegister(U8 reg) 
774 {
775     *(U8*)currentatag->tmp = 4; //register
776     *(U8*)&currentatag->tmp[1] = reg;
777     swf_AddActionTAG(ACTION_PUSH, (U8*)currentatag->tmp, 2);
778 }
779 void action_PushLookup(U8 index) 
780 {
781     *(U8*)currentatag->tmp = 8; //lookup
782     *(U8*)&currentatag->tmp[1] = index;
783     swf_AddActionTAG(ACTION_PUSH, (U8*)currentatag->tmp, 2);
784 }
785 void action_PushString(char*str) 
786 {
787     int l = strlen(str);
788     char*ptr = (char*)malloc(l+2);
789     ptr[0] = 0; // string
790     strcpy(&ptr[1], str);
791     swf_AddActionTAG(ACTION_PUSH, (U8*)ptr, l+2);
792 }
793 void action_PushFloat(float f)
794 {
795     char*ptr = (char*)malloc(5);
796     ptr[0] = 1; //float
797     *(float*)&ptr[1]  = f;
798     swf_AddActionTAG(ACTION_PUSH, (U8*)ptr, 5);
799 }
800 void action_PushDouble(double d) 
801 {
802     char*ptr = (char*)malloc(9);
803     ptr[0] = 6; //double
804     *(double*)&ptr[1]  = d;
805     swf_AddActionTAG(ACTION_PUSH, (U8*)ptr, 9);
806 }
807 void action_PushInt(int i)
808 {
809     *(U8*)currentatag->tmp = 7; //int
810     *(U32*)&currentatag->tmp[1] = i;
811     swf_AddActionTAG(ACTION_PUSH, (U8*)currentatag->tmp, 5);
812 }
813 void action_GotoLabel(char* label)
814 {
815     char*ptr = strdup(label);
816     swf_AddActionTAG(ACTION_GOTOLABEL, (U8*)ptr, strlen(ptr));
817 }
818 void action_GetUrl(char* url, char* label) 
819 {
820     int l1= strlen(url);
821     int l2= strlen(label);
822     char*ptr = malloc(l1+l2+2);
823     strcpy(ptr, url);
824     strcpy(&ptr[l1+1], label);
825     swf_AddActionTAG(ACTION_GETURL, ptr, l1+l2+2);
826 }
827 //TODO:
828 void action_DefineFunction(U8*data, int len) {}
829 void action_Constantpool(char* constantpool) {}
830 void action_With(char*object) {}
831
832 /*
833   Properties:
834
835   _X 0
836   _Y 1
837   _xscale 2
838   _yscale 3
839   _currentframe 4
840   _totalframes 5
841   _alpha 6
842   _visible 7
843   _width 8
844   _height 9
845   _rotation 10
846   _target 11
847   _framesloaded 12
848   _name 13
849   _droptarget 14
850   _url 15
851   _highquality 16
852   _focusrect 17
853   _soundbuftime 18
854   _quality* 19
855   _xmouse* 20
856   _ymouse* 21
857 */