changeset 702:efde64b3e147

sub_4BDAAF clean some Chest pointer fixes
author zipi
date Mon, 18 Mar 2013 20:19:20 +0000
parents d5b16a44d9b3
children ef4d646d738d
files Allocator.cpp Chest.cpp mm7_1.cpp mm7_4.cpp
diffstat 4 files changed, 91 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/Allocator.cpp	Mon Mar 18 22:53:56 2013 +0400
+++ b/Allocator.cpp	Mon Mar 18 20:19:20 2013 +0000
@@ -201,8 +201,8 @@
 	  for (indx = 0; indx <=uNumBuffersUsed; ++indx)
 		  if (pMemoryBuffers[indx] == ptr)	
 			  break;
-	  if ((indx>uNumBuffersUsed)&& !aborting_app )
-		  AbortWithError(); //to detect memory problems - uncomment
+	  //if ((indx>uNumBuffersUsed)&& !aborting_app )
+		  //AbortWithError(); //to detect memory problems - uncomment
 	  if (!bUseBigBuffer)
 		  free(pMemoryBuffers[indx]);
 	  pMemoryBuffers[indx] = NULL;
--- a/Chest.cpp	Mon Mar 18 22:53:56 2013 +0400
+++ b/Chest.cpp	Mon Mar 18 20:19:20 2013 +0000
@@ -687,7 +687,7 @@
     {
       *strchr(&Buf, 10) = 0;
       memcpy(&v17, texture_frame_table_txt_parser(&Buf, &v16), sizeof(v17));
-      if ( v17.uPropCount && *v17.pProperties[0] != 47 )
+	  if ( v17.uPropCount && *v17.pProperties[0] != 47 )
         ++Argsa;
     }
     while ( fgets(&Buf, 490, File) );
@@ -708,7 +708,7 @@
   {
     *strchr(&Buf, 10) = 0;
     memcpy(&v17, texture_frame_table_txt_parser(&Buf, &v16), sizeof(v17));
-    if ( v17.uPropCount && *v17.pProperties[0] != 47 )
+	if ( v17.uPropCount && *v17.pProperties[0] != 47 )
     {
       strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]);
       v10 = atoi(v17.pProperties[1]);
@@ -726,7 +726,7 @@
 
 //----- (00420B13) --------------------------------------------------------
 void __fastcall sub_420B13(int a1, int a2)
-    {
+{
     void *v2; // eax@1
     ItemGen *v3; // ebx@1
     unsigned int v4; // eax@1
@@ -745,16 +745,18 @@
     int v17; // [sp+Ch] [bp-14h]@1
     int v18; // [sp+10h] [bp-10h]@3
     int v19; // [sp+14h] [bp-Ch]@1
-    void *v20; // [sp+18h] [bp-8h]@1
+    int v20; // [sp+18h] [bp-8h]@1
     int v21; // [sp+1Ch] [bp-4h]@5
     int v22; // [sp+1Ch] [bp-4h]@8
 
     v19 = a2;
     v2 = pChestWindow->ptr_1C;
-    v20 = v2;
+    v20 = (int)v2;
     v2 = (void *)(5324 * (int)v2);
-    v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4));
-    v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)];
+    //v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4));
+	v3 = &pChests[v20].igChestItems[a1];
+    //v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)];
+	v17 = pChestWidthsByType[pChests[v20].uChestBitmapID];
     v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v3->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
     v5 = (Texture *)(v4 != -1 ? (int)&pIcons_LOD->pTextures[v4] : 0);
     v6 = (v4 != -1 ? pIcons_LOD->pTextures[v4].uTextureWidth : 24);
@@ -769,37 +771,38 @@
     v10 = ((v8 - 14) >> 5) + 1;
     v21 = v10;
     if ( !areWeLoadingTexture )
-        {
+    {
         v5->Release();
         pIcons_LOD->_40F9C5();
         v10 = v21;
-        }
+    }
     if ( v10 > 0 )
-        {
+    {
         v11 = 0;
         v22 = v10;
         do
-            {
+        {
             if ( v9 > 0 )
-                {
+            {
                 v12 = v9;
-                v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20];
+                //v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20];
+				v13 = &pChests[v20].pInventoryIndices[v19 + v11];
                 v14 = v12 & 1;
                 v12 >>= 1;
                 memset(v13, 0, 4 * v12);
                 v15 = (int)((char *)v13 + 4 * v12);
                 for ( i = v14; i; --i )
-                    {
+                {
                     *(short *)v15 = 0;
                     v15 += 2;
-                    }
+                }
                 v9 = v18;
-                }
+            }
             v11 += v17;
             --v22;
-            }
-            while ( v22 );
         }
-    v3->Reset();
+        while ( v22 );
     }
+    v3->Reset();
+}
 // 506128: using guessed type int areWeLoadingTexture;
--- a/mm7_1.cpp	Mon Mar 18 22:53:56 2013 +0400
+++ b/mm7_1.cpp	Mon Mar 18 20:19:20 2013 +0000
@@ -3838,6 +3838,9 @@
       auto _w = (ItemGen *)(&pOtherOverlayList->pOverlays[49].field_4 + 2662 * (unsigned int)pChestWindow->ptr_1C
                                              + 18 * *((short *)&pChests[0].igChestItems[139].uExpireTime
                                                + v1 + 2662 * (unsigned int)pChestWindow->ptr_1C + 3));
+
+      _w = (ItemGen *)(&pChests[(unsigned int)pChestWindow->ptr_1C] -32 
+		  + 18 * *((short *)&pChests[(unsigned int)pChestWindow->ptr_1C].igChestItems[139].uExpireTime + v1 + 3));
       v2 = _w->GetDisplayName();
       sub_41C0B8_set_status_string(v2);
     }
--- a/mm7_4.cpp	Mon Mar 18 22:53:56 2013 +0400
+++ b/mm7_4.cpp	Mon Mar 18 20:19:20 2013 +0000
@@ -11048,6 +11048,7 @@
   unsigned __int8 v9; // zf@16
   char v10; // sf@16
   unsigned __int8 v11; // of@16
+  bool test;
 
   auto a2 = _2da_idx;
   //v2 = p2DEvents_minus1___00[26 * a2];
@@ -11058,46 +11059,84 @@
   if ( (v2 != 4 || (signed int)v3 < 740 || (signed int)v3 > 771)
     && ((signed int)v3 >= 600 || (signed int)v3 >= 529 && (signed int)v3 <= 599) || a1->Stolen())
     return 0;
-  v6 = v2 - 1;
-  if ( !v6 )
+  switch( p2DEvents[a2 - 1].uType )
+  {
+	case BildingType_WeaponShop:
+		{
+		test = v5 <= 2;
+		break;
+		}
+	case BildingType_ArmorShop:
+		{
+		test = v5 >= 3;
+		break;
+		}
+	case BildingType_MagicShop:
+		{
+		test = pItemsTable->pItems[v4].uSkillType == 38 || v5 == 16;
+		break;
+		}
+	case BildingType_AlchemistShop:
+		{
+		__debugbreak(); // need to test
+		test = v5 == 13 || v5 == 14 || (v5 > 14 && !(v5 != 17 || (signed int)v3 < 740) && v3 != 771);
+		break;
+		}
+	default:
+		{
+		test = 0;
+		break;
+		}
+  }
+
+  return test;
+/*
+  if ( p2DEvents[a2 - 1].uType == 1 )
   {
     v11 = __OFSUB__(v5, 2);
     v9 = v5 == 2;
     v10 = v5 - 2 < 0;
     goto LABEL_23;
   }
-  v7 = v6 - 1;
-  if ( v7 )
-  {
-    v8 = v7 - 1;
-    if ( !v8 )
+  if ( p2DEvents[a2 - 1].uType > 2 )
+  {
+    if ( p2DEvents[a2 - 1].uType == 3 )
     {
       if ( pItemsTable->pItems[v4].uSkillType != 38 )
         return v5 == 16;
       return 1;
     }
-    if ( v8 != 1 || v5 < 13 )
+    if ( p2DEvents[a2 - 1].uType != 4 || v5 < 13 )
       return 0;
-    if ( v5 <= 14 )
-      return 1;
-    if ( v5 != 17 || (signed int)v3 < 740 )
-      return 0;
-    v11 = __OFSUB__(v3, 771);
-    v9 = v3 == 771;
-    v10 = ((v3 - 771) & 0x80000000u) != 0;
+	if ( p2DEvents[a2 - 1].uType == 4)
+	{
+		if ( v5 < 13 )
+		  return 0;
+		if ( v5 <= 14 )
+		  return 1;
+		if ( v5 != 17 || (signed int)v3 < 740 )
+		  return 0;
+		v11 = __OFSUB__(v3, 771);
+		v9 = v3 == 771;
+		v10 = ((v3 - 771) & 0x80000000u) != 0;
 LABEL_23:
-    if ( !((unsigned __int8)(v10 ^ v11) | v9) )
-      return 0;
-    return 1;
-  }
-  if ( v5 >= 3 )
-  {
-    v11 = __OFSUB__(v5, 9);
-    v9 = v5 == 9;
-    v10 = v5 - 9 < 0;
-    goto LABEL_23;
+		if ( !((unsigned __int8)(v10 ^ v11) | v9) )
+		  return 0;
+		return 1;
+	}
+  }
+  if ( p2DEvents[a2 - 1].uType == 2 )
+  {
+	  if ( v5 >= 3 )
+	  {
+		v11 = __OFSUB__(v5, 9);
+		v9 = v5 == 9;
+		v10 = v5 - 9 < 0;
+		goto LABEL_23;
+	  }
   }
   return 0;
+*/
 }