diff mm7_3.cpp @ 82:1faa29fd4c2d

many type, memory, boundary fixes
author zipi
date Sun, 03 Feb 2013 23:37:17 +0000
parents 377535d6e366
children 170259c8c71f
line wrap: on
line diff
--- a/mm7_3.cpp	Sun Feb 03 15:36:54 2013 +0000
+++ b/mm7_3.cpp	Sun Feb 03 23:37:17 2013 +0000
@@ -18366,9 +18366,9 @@
   unsigned int v3; // ebx@1
   unsigned int v4; // ebp@1
   signed int v5; // edi@1
-  char *v6; // esi@4
+  Actor *v6; // esi@4
   size_t v7; // ecx@10
-  char *v8; // eax@11
+  Actor *v8; // eax@11
   unsigned __int16 v9; // dx@14
 
   v4 = uGroupID;
@@ -18380,20 +18380,20 @@
     {
       if ( (signed int)uNumActors > Standing )
       {
-        v6 = (char *)&pActors[0].uAttributes;
+        v6 = pActors;//[0].uAttributes;
         do
         {
-          if ( *((_DWORD *)v6 + 168) == v4 )
-          {
-            *(_DWORD *)v6 |= v3;
+          if ( v6->uGroup == v4 )
+          {
+            v6->uAttributes |= v3;
             if ( v3 == 0x10000 )
             {
-              *((_WORD *)v6 + 70) = Disabled;
-              ((Actor *)(v6 - 36))->UpdateAnimation();
+              v6->uAIState = Disabled;
+              v6->UpdateAnimation();
             }
           }
           ++v5;
-          v6 += 836;
+          ++v6;
         }
         while ( v5 < (signed int)uNumActors );
       }
@@ -18403,23 +18403,23 @@
       v7 = uNumActors;
       if ( (signed int)uNumActors > Standing )
       {
-        v8 = (char *)&pActors[0].uAIState;
+        v8 = pActors;//[0].uAIState;
         do
         {
-          if ( *((_DWORD *)v8 + 133) == v4 )
+          if ( v8->uGroup == v4 )
           {
             if ( v3 == 0x10000 )
             {
-              v9 = *(_WORD *)v8;
-              if ( *(_WORD *)v8 != Dead )
+              v9 = v8->uAIState;
+              if ( v8->uAIState != Dead )
               {
                 if ( v9 != 4 && v9 != 11 )
-                  *(_WORD *)v8 = Standing;
-              }
-            }
-            *((_DWORD *)v8 - 35) &= ~v3;
-          }
-          v8 += 836;
+                  v8->uAIState = Standing;
+              }
+            }
+			LODWORD(v8->uAttributes) &= ~v3;
+          }
+          ++v8;
           --v7;
         }
         while ( v7 );
@@ -19905,7 +19905,7 @@
 //----- (004016FA) --------------------------------------------------------
 int __cdecl BLV_4016FA_AI()
 {
-  char *v0; // esi@2
+  Actor *v0; // esi@2
   int v1; // eax@4
   int v2; // ebx@4
   unsigned int v3; // ecx@4
@@ -19929,7 +19929,7 @@
   bool v21; // eax@33
   int v22; // eax@34
   signed int v23; // ebx@36
-  char *v24; // esi@37
+  Actor *v24; // esi@37
   signed int v25; // eax@40
   int v26; // eax@43
   int v27; // ebx@45
@@ -19957,15 +19957,15 @@
   v43 = 0;
   if ( (signed int)uNumActors > 0 )
   {
-    v0 = (char *)&pActors[0].uAttributes;
-    do
-    {
-      v0[1] &= 0xFBu;
-      if ( ! ((Actor *)(v0 - 36))->CanAct() )
+    v0 = pActors;//[0].uAttributes;
+    do
+    {
+      BYTE1(v0->uAttributes) &= 0xFBu;
+      if ( ! v0->CanAct() )
         goto LABEL_60;
-      v39 = abs(pParty->vPosition.z - *((short *)v0 + 55));
-      v38 = abs(pParty->vPosition.y - *((short *)v0 + 54));
-      v1 = abs(pParty->vPosition.x - *((short *)v0 + 53));
+	  v39 = abs(pParty->vPosition.z - v0->vPosition.z);
+	  v38 = abs(pParty->vPosition.y - v0->vPosition.y);
+	  v1 = abs(pParty->vPosition.x - v0->vPosition.x);
       v2 = v38;
       v3 = v39;
       if ( v1 < v38 )
@@ -19987,7 +19987,7 @@
         v2 = v6;
       }
       v7 = ((unsigned int)(11 * v2) >> 5) + (v3 >> 2) + v1;
-      v8 = *((short *)v0 + 50);
+      v8 = v0->uActorRadius;
       v9 = v7 - v8;
       v40 = v7 - v8;
       if ( v40 < 0 )
@@ -19997,12 +19997,12 @@
       }
       if ( v9 < 10240 )
       {
-        v10 = *(int *)v0 & 0xFEFFFFFF;
-        *(int *)v0 = v10;
-        if ( v10 & 0x80000 || ((Actor *)(v0 - 36))->GetActorsRelation(0) )
+        v10 = v0->uAttributes & 0xFEFFFFFF;
+        v0->uAttributes = v10;
+        if ( v10 & 0x80000 || v0->GetActorsRelation(0) )
         {
           v11 = (pParty->uFlags & 0x10) == 0;
-          *(int *)v0 = v10 | 0x1000000;
+          v0->uAttributes = v10 | 0x1000000;
           if ( v11 && (double)v40 < 307.2 )
             pParty->uFlags |= 0x10u;
           if ( !(pParty->uFlags & 0x20) && v9 < 5120 )
@@ -20015,10 +20015,10 @@
       else
       {
 LABEL_60:
-        v0[1] &= 0xBFu;
+        BYTE1(v0->uAttributes) &= 0xBFu;
       }
       ++v43;
-      v0 += 836;
+      ++v0;
     }
     while ( v43 < (signed int)uNumActors );
   }
@@ -20074,17 +20074,17 @@
   ai_arrays_size = v19;
   if ( (signed int)uNumActors > 0 )
   {
-    v24 = (char *)&pActors[0].uAttributes;
-    do
-    {
-      if ( ((Actor *)(v24 - 36))->CanAct() && *((short *)v24 + 61) == v37 )
+    v24 = pActors;//[0].uAttributes;
+    do
+    {
+      if ( v24->CanAct() && v24->uSectorID == v37 )
       {
         v25 = 0;
         if ( v19 <= 0 )
         {
 LABEL_43:
           v26 = ai_arrays_size;
-          v24[1] |= 0x40u;
+          BYTE1(v24->uAttributes) |= 0x40u;
           ++ai_arrays_size;
           ai_array_4F6638_actor_ids[v26] = v23;
         }
@@ -20099,7 +20099,7 @@
         }
       }
       ++v23;
-      v24 += 836;
+      ++v24;
     }
     while ( v23 < (signed int)uNumActors );
   }
@@ -20160,7 +20160,7 @@
   int v2; // ecx@7
   int v3; // eax@7
   signed int v4; // edi@10
-  char *v5; // esi@12
+  Actor *v5; // esi@12
   signed int v6; // eax@14
   __int16 v7; // cx@14
   Player **v8; // esi@20
@@ -20271,14 +20271,14 @@
         v84 = 0;
         if ( (signed int)uNumActors > 0 )
         {
-          v5 = (char *)&pActors[0].sCurrentHP;
+          v5 = pActors;//[0].sCurrentHP;
           do
           {
-            if ( ((Actor *)(v5 - 40))->CanAct() )
-            {
-              v6 = stru_50C198.CalcMagicalDamageToActor((Actor *)(v5 - 40), 5, v4);
-              v7 = *(short *)v5 - v6;
-              *(short *)v5 = v7;
+            if ( v5->CanAct() )
+            {
+              v6 = stru_50C198.CalcMagicalDamageToActor(v5, 5, v4);
+              v7 = v5->sCurrentHP - v6;
+              v5->sCurrentHP = v7;
               if ( v6 )
               {
                 if ( v7 >= 0 )
@@ -20288,13 +20288,13 @@
                 else
                 {
                   Actor::Die(v84);
-                  if ( *((int *)v5 + 19) )
-                    sub_4269A2_GivePartyExp(pMonsterStats->pInfos[*((short *)v5 + 28)].uExp);
+                  if ( v5->pMonsterInfo.uExp )
+                    sub_4269A2_GivePartyExp(pMonsterStats->pInfos[v5->pMonsterInfo.uID].uExp);
                 }
               }
             }
             ++v84;
-            v5 += 836;
+            ++v5;
           }
           while ( (signed int)v84 < (signed int)uNumActors );
         }