Brought up to date
[swftools.git] / lib / modules / swfaction.c
index 4c47d53..014730b 100644 (file)
@@ -13,6 +13,8 @@
 
 #include "../rfxswf.h"
 
+#define MAX_LOOKUP 1024   // make cross references in dumps
+
 struct Action
 {
     int version;
@@ -229,7 +231,7 @@ int OpAdvance(char c, char*data)
                return 1+4; //int
            } else if (type == 8) {
                return 1+1; //lookup
-           }
+           } else return 1;
            break;
        }
     }
@@ -242,8 +244,18 @@ void swf_DumpActions(ActionTAG*atag, char*prefix)
     int t;
     U8*data;
     char* cp;
-    if(!prefix) 
-       prefix="";
+    int entry = 0;
+
+#ifdef MAX_LOOKUP
+
+    char * lookup[MAX_LOOKUP];
+    memset(lookup,0x00,sizeof(lookup));
+
+#endif
+
+   if (!prefix)
+        prefix="";
+
     while(atag)
     {
        U8 poollen = 0;
@@ -278,9 +290,14 @@ void swf_DumpActions(ActionTAG*atag, char*prefix)
                } break;
                case 'c': {
                    printf(" String:\"%s\"", data);
+#ifdef MAX_LOOKUP
+                    if (entry<MAX_LOOKUP)
+                     lookup[entry++] = strdup(data);
+#endif
                } break;
                case 'C': {
                    poollen = *data;
+                    entry = 0;
                    printf("(%d entries)", poollen);
                } break;
                case 's': {
@@ -312,6 +329,10 @@ void swf_DumpActions(ActionTAG*atag, char*prefix)
                        printf(" int:%d", *(int*)value);
                    } else if (type == 8) {
                        printf(" Lookup:%d", *value);
+#ifdef MAX_LOOKUP
+                       if (lookup[*value])
+                         printf(" (\"%s\")",lookup[*value]);
+#endif
                    } else {
                        printf(" UNKNOWN[%02x]",type);
                    }
@@ -341,6 +362,10 @@ void swf_DumpActions(ActionTAG*atag, char*prefix)
        printf("\n");
        atag = atag->next;
     }
+
+#ifdef MAX_LOOKUP
+  for (t=0;t<MAX_LOOKUP;t++) if (lookup[t]) free(lookup[t]);
+#endif
 }
 
 static const char TYPE_URL = 1;
@@ -487,6 +512,19 @@ void swf_AddActionTAG(U8 op, U8*data, U16 len)
     currentatag = currentatag->next;
 }
 
+ActionMarker action_setMarker()
+{
+    ActionMarker m;
+    m.atag = currentatag;
+    return m;
+}
+
+int inline ActionTagSize(ActionTAG*atag)
+{
+    return (atag->op&0x80)?3+(atag->len):1+0;
+}
+
+
 #define ACTION_END            0x00
 #define ACTION_NEXTFRAME      0x04
 #define ACTION_PREVIOUSFRAME  0x05
@@ -577,6 +615,55 @@ void swf_AddActionTAG(U8 op, U8*data, U16 len)
 #define ACTION_CALL           0x9e
 #define ACTION_GOTOFRAME2     0x9f
 
+void action_fixjump(ActionMarker m1, ActionMarker m2)
+{
+    ActionTAG* a1 = m1.atag;
+    ActionTAG* a2 = m2.atag;
+    ActionTAG* a;
+    int len = 0;
+    int oplen = 0;
+    a = a1;
+    
+    a = a->next; //first one is free
+    while(a && a!=a2)
+    {
+       len += ActionTagSize(a);
+       oplen ++;
+       a = a->next;
+    }
+    if(!a)
+    { len = 0;
+      oplen = 0;
+      a = a2;
+      while(a && a!=a1) {
+         len -= ActionTagSize(a);
+         oplen --;
+         a = a->next;
+      }
+      if(!a) {
+         fprintf(stderr, "action_fixjump: couldn't find second tag\n");
+         return;
+      }
+      len -= ActionTagSize(a);
+      oplen --;
+    }
+
+    if (a1->op == ACTION_IF || a1->op == ACTION_JUMP) 
+    {
+       *(U16*)(a1->data) = len;
+    }
+    else if(a1->op == ACTION_WAITFORFRAME)
+    {
+       ((U8*)(a1->data))[2] = oplen;
+    }
+    else if(a1->op == ACTION_WAITFORFRAME2)
+    {
+       ((U8*)(a1->data))[0] = oplen;
+    }
+    
+}
+
+
 void action_NextFrame() {swf_AddActionTAG(ACTION_NEXTFRAME, 0, 0);}
 void action_PreviousFrame() {swf_AddActionTAG(ACTION_PREVIOUSFRAME, 0, 0);}
 void action_Play() {swf_AddActionTAG(ACTION_PLAY, 0, 0);}
@@ -745,7 +832,7 @@ void action_PushDouble(double d)
 void action_PushInt(int i)
 {
     *(U8*)currentatag->tmp = 7; //int
-    *(U8*)&currentatag->tmp[1] = i;
+    *(U32*)&currentatag->tmp[1] = i;
     swf_AddActionTAG(ACTION_PUSH, (U8*)currentatag->tmp, 5);
 }
 void action_GotoLabel(char* label)
@@ -766,3 +853,30 @@ void action_GetUrl(char* url, char* label)
 void action_DefineFunction(U8*data, int len) {}
 void action_Constantpool(char* constantpool) {}
 void action_With(char*object) {}
+
+/*
+  Properties:
+
+  _X 0
+  _Y 1
+  _xscale 2
+  _yscale 3
+  _currentframe 4
+  _totalframes 5
+  _alpha 6
+  _visible 7
+  _width 8
+  _height 9
+  _rotation 10
+  _target 11
+  _framesloaded 12
+  _name 13
+  _droptarget 14
+  _url 15
+  _highquality 16
+  _focusrect 17
+  _soundbuftime 18
+  _quality* 19
+  _xmouse* 20
+  _ymouse* 21
+*/