diff Player.cpp @ 232:c879446b4a22

inventory indexing fixed
author zipi
date Sun, 17 Feb 2013 15:04:56 +0100
parents 1bd823f52e3a
children 47e06334c564 ccf14ac29caf
line wrap: on
line diff
--- a/Player.cpp	Sun Feb 17 14:47:34 2013 +0100
+++ b/Player.cpp	Sun Feb 17 15:04:56 2013 +0100
@@ -257,7 +257,7 @@
     result = v2->uOffHand;
     if ( v2->uOffHand )
     {
-      result = *(int *)&this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * result + 5];
+      result = *(int *)&this->pInventoryItems[result-1];
       if ( result )
       {
         if ( result != 64 && result != 65 )
@@ -1761,8 +1761,7 @@
 
   pIndices = &this->pInventoryIndices[uSlot];
 
-  __debugbreak();  // the following indexing is invalid
-  v3 = (ItemGen *)&this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * *pIndices + 5];
+  v3 = &this->pInventoryItems[*pIndices-1];
   v4 = v3->uItemID;
   v3->Reset();
   v5 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v4].pIconName, TEXTURE_16BIT_PALETTE);
@@ -2391,7 +2390,7 @@
         goto LABEL_15;
       }
     }
-    memcpy(&v9->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v10 + 5], pItem, 0x24u);
+    memcpy(&v9->pInventoryItems[v10-1], pItem, 0x24u);
     pItem->Reset();
     pAudioPlayer->PlaySound(SOUND_GoldReceived, 0, 0, -1, 0, 0, 0, 0);
     v19->PlaySound(SPEECH_60, 0);
@@ -2786,7 +2785,7 @@
   }
   if ( HasItemEquipped(EQUIP_TWO_HANDED) )
   {
-    v6 = (ItemGen *)&v5->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v5->pEquipment.uMainHand + 5];
+    v6 = (ItemGen *)&v5->pInventoryItems[v5->pEquipment.uMainHand-1];
     v7 = v6->uItemID;
     v8 = v6->uItemID;
     v9 = pItemsTable->pItems[v8].uDamageDice;
@@ -2858,7 +2857,7 @@
   {
     if ( v5->HasItemEquipped((ITEM_EQUIP_TYPE)0) )
     {
-      v15 = (ItemGen *)&v5->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v5->pEquipment.uOffHand + 5];
+      v15 = (ItemGen *)&v5->pInventoryItems[v5->pEquipment.uOffHand-1];
       v16 = v15->uItemID;
       v17 = v15->uItemID;
       if ( pItemsTable->pItems[v17].uEquipType != 4 )
@@ -2951,7 +2950,7 @@
   int v7; // edi@4
 
   v1 = this;
-  v2 = *(int *)&this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * this->pEquipment.uMainHand + 5];
+  v2 = *(int *)&this->pInventoryItems[this->pEquipment.uMainHand-1];
   if ( v2 < 64 || v2 > 65 )
   {
     v4 = GetActualAccuracy();
@@ -3041,7 +3040,7 @@
   result = HasItemEquipped(EQUIP_BOW);
   if ( !result )
     return result;
-  v4 = (ItemGen *)&v2->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v2->pEquipment.uBow + 5];
+  v4 = (ItemGen *)&v2->pInventoryItems[v2->pEquipment.uBow-1];
   v5 = v4->uItemID;
   v6 = v4->uItemID;
   v15 = pItemsTable->pItems[v6].uDamageRoll;
@@ -3112,7 +3111,7 @@
   static char player__getmeleedamagestring_static_buff[40]; // idb
 
   v1 = this;
-  v2 = *(int *)&this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * this->pEquipment.uMainHand + 5];
+  v2 = *(int *)&this->pInventoryItems[this->pEquipment.uMainHand-1];
   if ( v2 < 64 || v2 > 65 )
   {
     v3 = GetMeleeDamageMinimal();
@@ -3138,7 +3137,7 @@
   v8 = v1->pEquipment.uMainHand;
   if ( v8 )
   {
-    v9 = *(int *)&v1->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v8 + 5];
+    v9 = *(int *)&v1->pInventoryItems[v8-1];
     if ( v9 >= 135 )
     {
       if ( v9 <= 159 )
@@ -3164,7 +3163,7 @@
   static char player__getrangeddamagestring_static_buff[40]; // idb
 
   v1 = this;
-  v2 = *(int *)&this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * this->pEquipment.uMainHand + 5];
+  v2 = *(int *)&this->pInventoryItems[this->pEquipment.uMainHand-1];
   if ( v2 < 64 || v2 > 65 )
   {
     v3 = GetRangedDamageMin();
@@ -3198,7 +3197,7 @@
   v8 = v1->pEquipment.uMainHand;
   if ( v8 )
   {
-    v9 = *(int *)&v1->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v8 + 5];
+    v9 = *(int *)&v1->pInventoryItems[v8-1];
     if ( v9 >= 135 )
     {
       if ( v9 <= 159 )
@@ -3862,7 +3861,7 @@
       {
         if ( *v20 > 0 )
         {
-          v21 = *(int *)&v5->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * *v20 + 5];
+          v21 = *(int *)&v5->pInventoryItems[*v20-1];
           if ( v21 > 0 )
           {
             if ( v21 <= 134 )
@@ -4142,7 +4141,7 @@
   {
     if ( !HasItemEquipped(EQUIP_BOW) )
       goto LABEL_17;
-    v5 = (int)&v4->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v4->pEquipment.uBow + 5];
+    v5 = (int)&v4->pInventoryItems[v4->pEquipment.uBow-1];
     v46 = v5;
     v3 = (char *)&pItemsTable->pItems[*(int *)v5].pIconName;
     v6 = (unsigned __int16)word_4EDED8[(unsigned __int8)v3[29]];
@@ -4161,7 +4160,7 @@
   }
   if ( HasItemEquipped(EQUIP_TWO_HANDED) )
   {
-    v8 = (int)&v4->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v4->pEquipment.uMainHand + 5];
+    v8 = (int)&v4->pInventoryItems[v4->pEquipment.uMainHand-1];
     v46 = v8;
     v9 = *(int *)v8;
     v3 = (char *)&pItemsTable->pItems[v9].pIconName;
@@ -4173,7 +4172,7 @@
   }
   if ( HasItemEquipped((ITEM_EQUIP_TYPE)0) )
   {
-    v12 = (int)&v4->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v4->pEquipment.uOffHand + 5];
+    v12 = (int)&v4->pInventoryItems[v4->pEquipment.uOffHand-1];
     v42 = (unsigned __int16)word_4EDED8[pItemsTable->pItems[*(int *)v12].uSkillType];
     if ( (signed int)v42 > v47 )
     {
@@ -4187,7 +4186,7 @@
 LABEL_17:
   if ( HasItemEquipped(EQUIP_ARMOUR) )
   {
-    v14 = pItemsTable->pItems[*(int *)&v4->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v4->pEquipment.uBody + 5]].uSkillType;
+    v14 = pItemsTable->pItems[*(int *)&v4->pInventoryItems[v4->pEquipment.uBody-1]].uSkillType;
     SkillToMastery(v4->pActiveSkills[9]);
     v15 = (unsigned __int16)word_4EDED8[v14];
     v35 = 1.0;
@@ -4870,14 +4869,14 @@
     if ( (signed int)attr <= 30 )
     {
       if ( HasItemEquipped(EQUIP_BOW) )
-        v5 = pItemsTable->pItems[*(int *)&v6->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v6->pEquipment.uBow + 5]].uDamageMod;
+        v5 = pItemsTable->pItems[*(int *)&v6->pInventoryItems[v6->pEquipment.uBow-1]].uDamageMod;
       return v5 + v62 + v61;
     }
     if ( attr == 31 )
     {
       if ( !HasItemEquipped(EQUIP_BOW) )
         return v5 + v62 + v61;
-      v57 = *(int *)&v6->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v6->pEquipment.uBow + 5];
+      v57 = *(int *)&v6->pInventoryItems[v6->pEquipment.uBow-1];
       v5 = pItemsTable->pItems[v57].uDamageMod;
       v56 = pItemsTable->pItems[v57].uDamageDice;
       goto LABEL_366;
@@ -4886,7 +4885,7 @@
     {
       if ( !HasItemEquipped(EQUIP_BOW) )
         return v5 + v62 + v61;
-      v20 = *(int *)&v6->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v6->pEquipment.uBow + 5];
+      v20 = *(int *)&v6->pInventoryItems[v6->pEquipment.uBow-1];
       v5 = pItemsTable->pItems[v20].uDamageDice * pItemsTable->pItems[v20].uDamageRoll;
 LABEL_365:
       v56 = pItemsTable->pItems[v20].uDamageMod;
@@ -5519,12 +5518,12 @@
       if ( v17 >= 0 )
       {
         if ( v17 <= 2 )
-          v5 = pItemsTable->pItems[*(int *)&v6->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v6->pEquipment.uMainHand + 5]].uDamageMod;
+          v5 = pItemsTable->pItems[*(int *)&v6->pInventoryItems[v6->pEquipment.uMainHand-1]].uDamageMod;
       }
     }
     if ( a3 || !v6->HasItemEquipped((ITEM_EQUIP_TYPE)0) || (v19 = v18->GetEquippedItemEquipType(0), v19 < 0) || v19 > 2 )
       return v5 + v62 + v61;
-    v20 = *(int *)&v6->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v6->pEquipment.uOffHand + 5];
+    v20 = *(int *)&v6->pInventoryItems[v6->pEquipment.uOffHand-1];
     goto LABEL_365;
   }
   if ( attr == 27 )