# HG changeset patch # User Ritor1 # Date 1380183454 -21600 # Node ID cacde83196e4eea293c2e7c90142a7838d97dade # Parent dc5f145b3d5dcf93ee4a0ca875af903f111ad5e0# Parent e8d477b4859606177116f368a2dcbd75e5b7fea5 Слияние diff -r dc5f145b3d5d -r cacde83196e4 Events.h --- a/Events.h Thu Sep 26 14:17:25 2013 +0600 +++ b/Events.h Thu Sep 26 14:17:34 2013 +0600 @@ -266,26 +266,34 @@ VAR_Reputation = 0xD7, VAR_ActiveSpells = 0xDE, VAR_AutoNotes = 0xDF, - VAR_MonthEquals = 0xE2, + VAR_IsMightMoreThanBase = 0xE0, + VAR_IsIntellectMoreThanBase = 0xE1, + VAR_IsPersonalityMoreThanBase = 0xE2, + VAR_IsEnduranceMoreThanBase = 0xE3, + VAR_IsSpeedMoreThanBase = 0xE4, + VAR_IsAccuracyMoreThanBase = 0xE5, + VAR_IsLuckMoreThanBase = 0xE6, + VAR_PlayerBits = 0xE7, VAR_NPCs2 = 0xE8, VAR_IsFlying = 0xF0, VAR_HiredNPCHasSpeciality = 0xF1, VAR_CircusPrises = 0xF2, VAR_NumSkillPoints = 0xF3, - VAR_MonthEquals2 = 0xF4, - VAR_Counter1 = 0xF7, - VAR_Counter2 = 0xF8, - VAR_Counter3 = 0xF9, - VAR_Counter4 = 0xFA, - VAR_Counter5 = 0xFB, - VAR_Counter6 = 0xFC, - VAR_Counter7 = 0xFD, - VAR_Counter8 = 0xFE, - VAR_Counter9 = 0xFF, - VAR_CounterA = 0x100, + VAR_MonthIs = 0xF4, + VAR_Counter1 = 0xF5, + VAR_Counter2 = 0xF6, + VAR_Counter3 = 0xF7, + VAR_Counter4 = 0xF8, + VAR_Counter5 = 0xF9, + VAR_Counter6 = 0xFa, + VAR_Counter7 = 0xFB, + VAR_Counter8 = 0xFC, + VAR_Counter9 = 0xFD, + VAR_Counter10 = 0xFE, VAR_ReputationInCurrentLocation = 0x113, VAR_History_0 = 0x114, VAR_History_28 = 0x130, + VAR_Unknown1 = 0x131, VAR_GoldInBank = 0x132, VAR_NumDeaths = 0x133, VAR_NumBounties = 0x134, diff -r dc5f145b3d5d -r cacde83196e4 Player.cpp --- a/Player.cpp Thu Sep 26 14:17:25 2013 +0600 +++ b/Player.cpp Thu Sep 26 14:17:34 2013 +0600 @@ -2595,7 +2595,7 @@ { if (base_recovery_times_per_weapon_type[GetOffHandItem()->GetPlayerSkillType()] > weapon_recovery) { - weapon = GetOffHandItem(); + weapon = GetOffHandItem(); weapon_recovery = base_recovery_times_per_weapon_type[weapon->GetPlayerSkillType()]; } } @@ -4986,9 +4986,10 @@ } //----- (00449BB4) -------------------------------------------------------- -bool Player::CompareVariable( enum VariableType VarNum, signed int pValue ) -{ - Player *v3; // esi@1 +bool Player::CompareVariable( enum VariableType VarNum, signed int pValue ) // in some cases this calls only calls v4 >= pValue, which i've changed to return false, since these values are supposed to be positive +{ + Assert(pValue >= 0, "Compare variable shouldn't have negative arguments"); + signed int v4; // edi@1 unsigned int v5; // eax@8 int v6; // eax@9 @@ -4999,7 +5000,7 @@ int v11; // eax@19 unsigned int v12; // eax@20 unsigned int test_bit_value; // eax@25 - unsigned __int8 our_bit_value; // cl@25 + unsigned __int8 byteWithRequestedBit; // cl@25 signed int v15; // ecx@28 ItemGen *v16; // eax@28 int v18; // edi@90 @@ -5015,7 +5016,6 @@ int v29; // eax@161 v6 = 0; - v3 = this; v4 = -1; if ( VarNum > VAR_AutoNotes ) { @@ -5052,14 +5052,12 @@ v19 = &pIndoor->dlv; v6 = v19->uReputation >= pValue; return v6; - case VAR_History_28|VAR_Sex: + case VAR_Unknown1: v21 = &pOutdoor->ddm; if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor ) v21 = &pIndoor->dlv; v6 = v21->field_C_alert == pValue; return v6; - case VAR_MonthEquals2|VAR_Sex: - case VAR_MonthEquals2|VAR_Class: case VAR_Counter1: case VAR_Counter2: case VAR_Counter3: @@ -5068,6 +5066,8 @@ case VAR_Counter6: case VAR_Counter7: case VAR_Counter8: + case VAR_Counter9: + case VAR_Counter10: v22 = *(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44304]; if ( v22 | *(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44300] && (signed __int64)(__PAIR__(v22, *(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44300]) @@ -5077,36 +5077,29 @@ case VAR_NumSkillPoints: v4 = this->uSkillPoints; return v4 >= pValue; - case VAR_CircusPrises: + case VAR_CircusPrises: //isn't used in MM6 since 0x1D6u is a book of regeneration v4 = 0; - v23 = pParty->pPlayers;//[0].pInventoryItems; - do + for (int playerNum = 0; playerNum < 4; playerNum++) { - v24 = v23->pInventoryItemList; - v25 = 138; - do + for (int invPos = 0; invPos < 138; invPos++) { - switch ( v24->uItemID ) + int itemId = pParty->pPlayers[playerNum].pInventoryItemList[invPos].uItemID; + switch ( itemId ) { - case 0x1D6u: - ++v4; - break; - case 0x1D7u: - v4 += 3; - break; - case 0x1DDu: - v4 += 5; - break; + case 0x1D6u: + ++v4; + break; + case 0x1D7u: + v4 += 3; + break; + case 0x1DDu: + v4 += 5; + break; } - ++v24; - --v25; } - while ( v25 ); - ++v23; } - while ( v23 <= &pParty->pPlayers[3] ); return v4 >= pValue; - case VAR_MonthEquals2: + case VAR_MonthIs: v6 = pParty->uCurrentMonth == pValue; return v6; case VAR_IsFlying: @@ -5115,78 +5108,65 @@ return true; return false; case VAR_HiredNPCHasSpeciality: - LOBYTE(v6) = CheckHiredNPCSpeciality(pValue); - return v6; + return CheckHiredNPCSpeciality(pValue); case VAR_NPCs2: return pNPCStats->pNewNPCData[pValue].Hired(); - case VAR_MonthEquals|VAR_CurrentSP: + case VAR_PlayerBits: test_bit_value = 0x80u >> ((signed __int16)pValue - 1) % 8; - our_bit_value = this->field_1A50[((signed __int16)pValue - 1)/8]; - if ( !((unsigned __int8)test_bit_value & our_bit_value) ) + byteWithRequestedBit = this->field_1A50[((signed __int16)pValue - 1)/8]; + if ( !((unsigned __int8)test_bit_value & byteWithRequestedBit) ) return v4 >= pValue; v4 = pValue; return v4 >= pValue; case VAR_ItemEquipped: - v26 = (ITEM_EQUIP_TYPE)0; - v27 = (char *)&this->pEquipment; - break; + for (int i = 0; i < 16; i++) + { + if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) && GetNthEquippedIndexItem(i)->uItemID == pValue ) + { + return true; + } + } + return false; case VAR_GoldInBank: v4 = pParty->uNumGoldInBank; return v4 >= pValue; - case VAR_ThieverySkill|0x80: + case VAR_IsMightMoreThanBase: v28 = GetActualMight(); - v29 = v3->GetBaseStrength(); - goto LABEL_168; - case VAR_DisarmTrapSkill|0x80: + v29 = GetBaseStrength(); + return (v28 >= v29); + case VAR_IsIntellectMoreThanBase: v28 = GetActualIntelligence(); - v29 = v3->GetBaseIntelligence(); - goto LABEL_168; - case VAR_MonthEquals: + v29 = GetBaseIntelligence(); + return (v28 >= v29); + case VAR_IsPersonalityMoreThanBase: v28 = GetActualWillpower(); - v29 = v3->GetBaseWillpower(); - goto LABEL_168; - case VAR_MonthEquals|VAR_Sex: + v29 = GetBaseWillpower(); + return (v28 >= v29); + case VAR_IsEnduranceMoreThanBase: v28 = GetActualEndurance(); - v29 = v3->GetBaseEndurance(); - goto LABEL_168; - case VAR_IdentifyMonsterSkill|0x80: + v29 = GetBaseEndurance(); + return (v28 >= v29); + case VAR_IsSpeedMoreThanBase: v28 = GetActualSpeed(); - v29 = v3->GetBaseSpeed(); - goto LABEL_168; - case VAR_ArmsmasterSkill|0x80: + v29 = GetBaseSpeed(); + return (v28 >= v29); + case VAR_IsAccuracyMoreThanBase: v28 = GetActualAccuracy(); - v29 = v3->GetBaseAccuracy(); - goto LABEL_168; - case VAR_MonthEquals|VAR_MaxHP: + v29 = GetBaseAccuracy(); + return (v28 >= v29); + case VAR_IsLuckMoreThanBase: v28 = GetActualLuck(); - v29 = v3->GetBaseLuck(); -LABEL_168: - v10 = __OFSUB__(v28, v29); - v9 = v28 - v29 < 0; -LABEL_169: - if ( v9 ^ v10 ) - return v4 >= pValue; - return true; + v29 = GetBaseLuck(); + return (v28 >= v29); default: - return v4 >= pValue; - } - while ( !v3->HasItemEquipped(v26) - || *(int *)&v3->pInventoryItemList[*(int *)v27-1] != pValue ) - { - v26 = (ITEM_EQUIP_TYPE)((int)v26 + 1); - v27 += 4; - if ( (signed int)v26 >= 16 ) return false; } - return true; - } - if ( VarNum == VAR_AutoNotes ) - { - test_bit_value = 0x80u >> ((signed __int16)(pValue - 1) - 1) % 8; - our_bit_value = pParty->_autonote_bits[((signed __int16)(pValue - 1) - 1) /8]; - if ( !((unsigned __int8)test_bit_value & our_bit_value) ) - return false; - return true; + } + if ( VarNum == VAR_AutoNotes ) //TODO: find out why the double subtraction. or whether this is even used + { + test_bit_value = 0x80u >> (pValue - 2) % 8; + byteWithRequestedBit = pParty->_autonote_bits[(pValue - 2) /8]; + return (test_bit_value & byteWithRequestedBit); } if ( VarNum <= VAR_BaseLuck ) { @@ -5195,29 +5175,27 @@ switch ( VarNum ) { case VAR_Hour: - if ( (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60 / 60 % 24 == pValue ) + if ( (long long)(pParty->uTimePlayed * 0.234375) / 60 / 60 % 24 == pValue ) return true; return false; case VAR_DayOfYear: - v5 = (unsigned int)((signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60 / 60) / 0x18 % 0x150 + 1; - v6 = v5 == pValue; - return v6; + if (((long long)(pParty->uTimePlayed * 0.234375) / 60 / 60) / 24 % 336 + 1 == pValue) + return true; + return false; case VAR_DayOfWeek: - v5 = (unsigned int)((signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60 / 60) / 0x18 % 7; - v6 = v5 == pValue; - return v6; - case VAR_Sex: - if ( pValue == (CHARACTER_RACE)this->uSex ) + if (((long long)(pParty->uTimePlayed * 0.234375) / 60 / 60) / 24 % 7) return true; - return v4 >= pValue; - case VAR_Class: - v7 = (CHARACTER_RACE)this->classType; - if ( pValue == v7 ) + return false; + case VAR_Sex: + if ( pValue == this->uSex ) return true; - return v4 >= pValue; - case VAR_Race: - v7 = GetRace(); - if ( pValue == v7 ) + return false; + case VAR_Class: + if ( pValue == this->classType ) + return true; + return false; + case VAR_Race: + if ( pValue == GetRace() ) return true; return v4 >= pValue; case VAR_CurrentHP: @@ -5225,20 +5203,18 @@ return v4 >= pValue; case VAR_MaxHP: v8 = GetMaxHealth(); - v10 = __OFSUB__(v3->sHealth, v8); - v9 = v3->sHealth - v8 < 0; - goto LABEL_169; + v9 = this->sHealth; + return (v9 >= v8); case VAR_CurrentSP: v4 = this->sMana; return v4 >= pValue; case VAR_MaxSP: - v11 = GetMaxMana(); - v10 = __OFSUB__(v3->sMana, v11); - v9 = v3->sMana - v11 < 0; - goto LABEL_169; + v8 = GetMaxMana(); + v9 = this->sMana; + return (v9 >= v8); case VAR_ActualAC: - v12 = GetActualAC(); - goto _j_cmp_against_arg; + v4 = GetActualAC(); + return v4 >= pValue; case VAR_ACModifier: v4 = this->sACModifier; return v4 >= pValue; @@ -5249,27 +5225,28 @@ v4 = this->sLevelModifier; return v4 >= pValue; case VAR_Age: - v12 = GetActualAge(); - goto _j_cmp_against_arg; + v4 = GetActualAge(); + return v4 >= pValue; case VAR_Award: - test_bit_value = 0x80u >> ((signed __int16)pValue - 1) % 8; - our_bit_value = this->_achieved_awards_bits[((signed __int16)pValue - 1) /8]; - if ( !((unsigned __int8)test_bit_value & our_bit_value) ) - return true; - return false; + test_bit_value = 0x80u >> (pValue - 1) % 8; + byteWithRequestedBit = this->_achieved_awards_bits[(pValue - 1) /8]; + return ( test_bit_value & byteWithRequestedBit ); case VAR_Experience: v4 = LODWORD(this->uExperience); return v4 >= pValue; case VAR_QBits_QuestsDone: test_bit_value = 0x80u >> (pValue - 1) % 8; - our_bit_value = pParty->_quest_bits[(pValue - 1)/8]; - if ( test_bit_value & our_bit_value ) - return true; - return false; + byteWithRequestedBit = pParty->_quest_bits[(pValue - 1)/8]; + return ( test_bit_value & byteWithRequestedBit ); case VAR_PlayerItemInHands: - v15 = 0; - v16 = v3->pInventoryItemList; - break; + for (int i = 0; i < 138; i++) + { + if (pInventoryItemList[i].uItemID == pValue) + { + return true; + } + } + return pParty->pPickedItem.uItemID == pValue; case VAR_FixedGold: v4 = pParty->uNumGold; return v4 >= pValue; @@ -5316,19 +5293,8 @@ v4 = pParty->uNumFoodRations; return v4 >= pValue; default: - return v4 >= pValue; - } - while ( v16->uItemID != pValue ) - { - ++v15; - ++v16; - if ( v15 >= 138 ) - { - v6 = pParty->pPickedItem.uItemID == pValue; - return v6; - } - } - return true; + return false; + } } v4 = this->uLuck; return v4 >= pValue; @@ -5371,27 +5337,26 @@ v4 = this->sResDarkBase; return v4 >= pValue; case VAR_ActualMight: - v12 = GetActualMight(); - goto _j_cmp_against_arg; + v4 = GetActualMight(); + return v4 >= pValue; case VAR_ActualIntellect: - v12 = GetActualIntelligence(); - goto _j_cmp_against_arg; + v4 = GetActualIntelligence(); + return v4 >= pValue; case VAR_ActualPersonality: - v12 = GetActualWillpower(); - goto _j_cmp_against_arg; + v4 = GetActualWillpower(); + return v4 >= pValue; case VAR_ActualEndurance: - v12 = GetActualEndurance(); - goto _j_cmp_against_arg; + v4 = GetActualEndurance(); + return v4 >= pValue; case VAR_ActualSpeed: - v12 = GetActualSpeed(); - goto _j_cmp_against_arg; + v4 = GetActualSpeed(); + return v4 >= pValue; case VAR_ActualAccuracy: - v12 = GetActualAccuracy(); - goto _j_cmp_against_arg; + v4 = GetActualAccuracy(); + return v4 >= pValue; case VAR_ActualLuck: - v12 = GetActualLuck(); -_j_cmp_against_arg: - v4 = v12; + v4 = GetActualLuck(); + return v4 >= pValue; break; default: return v4 >= pValue; @@ -5409,24 +5374,23 @@ { case VAR_MindResistanceBonus: v4 = this->sResMindBonus; - break; + return v4 >= pValue; case VAR_FireResistanceBonus: v4 = this->sResFireBonus; - break; + return v4 >= pValue; case VAR_AirResistanceBonus: v4 = this->sResAirBonus; - break; + return v4 >= pValue; case VAR_WaterResistanceBonus: v4 = this->sResWaterBonus; - break; + return v4 >= pValue; case VAR_EarthResistanceBonus: v4 = this->sResEarthBonus; - break; + return v4 >= pValue; case VAR_SpiritResistanceBonus: v4 = this->sResSpiritBonus; - break; + return v4 >= pValue; } - return v4 >= pValue; } if ( VarNum == VAR_BodyResistanceBonus ) { @@ -5451,7 +5415,6 @@ if ( VarNum <= VAR_MagicResistanceBonus || VarNum > VAR_DiplomacySkill ) return v4 >= pValue; } -LABEL_90: v18 = *((short *)&this->pConditions[16] + VarNum); if ( pValue <= 63 ) v4 = v18 & 0x3F; @@ -5460,7 +5423,14 @@ return v4 >= pValue; } if ( VarNum == 104 ) - goto LABEL_90; + { + v18 = *((short *)&this->pConditions[16] + VarNum); + if ( pValue <= 63 ) + v4 = v18 & 0x3F; + else + v4 = pValue & v18; + return v4 >= pValue; + } if ( (signed int)VarNum <= 104 ) return v4 >= pValue; if ( (signed int)VarNum > 0x79 ) @@ -5479,7 +5449,7 @@ v4 = pValue; return v4 >= pValue; } - return &LODWORD(this->pConditions[VarNum]);// *((int *)this + 2 * VarNum - 210); + return (this->pConditions[VarNum - 105] > 0);// *((int *)this + 2 * VarNum - 210); the original was never used, which is why probably it wasn't correct } @@ -5548,7 +5518,7 @@ { switch ( var_type ) { - case VAR_MonthEquals|VAR_CurrentSP: + case VAR_PlayerBits: __debugbreak(); //how do I get here? _449B7E_toggle_bit((unsigned char *)field_1A50, var_value, 1u); break; @@ -6527,7 +6497,7 @@ { switch ( var_type ) { - case VAR_MonthEquals|VAR_CurrentSP: + case VAR_PlayerBits: _449B7E_toggle_bit((unsigned char *)Dst->field_1A50, val, 1u); break; case VAR_NPCs2: