Browse Source

Merge commit '7e50e6f1d55468ff26382e132bbde42546f67124'

Fix invalid "unusable" spells
(https://github.com/diasurgical/devilution/pull/198)

Switched types to UINT64 and removed the remaining cleaned
up casts.
pull/4/head
Dennis Duda 8 years ago
parent
commit
4183da03ee
  1. 11
      Source/control.cpp
  2. 4
      Source/inv.cpp
  3. 3
      Source/items.cpp
  4. 4
      Source/player.cpp
  5. 1
      Support/TODO.md
  6. 28
      structs.h

11
Source/control.cpp

@ -2721,8 +2721,8 @@ int __fastcall GetSBookTrans(int ii, unsigned char townok)
void __cdecl DrawSpellBook()
{
int v0; // edi
int v1; // ebp
__int64 v0; // edi
__int64 v1; // ebp
int v2; // esi
char v3; // al
int v4; // eax
@ -2739,13 +2739,12 @@ void __cdecl DrawSpellBook()
CelDecodeOnly(76 * sbooktab + 391, 508, pSBkBtnCel, sbooktab + 1, 76);
v9 = 1;
v8 = 214;
v0 = plr[myplr]._pISpells[0] | plr[myplr]._pMemSpells[0] | plr[myplr]._pAblSpells[0];
v1 = plr[myplr]._pISpells[1] | plr[myplr]._pMemSpells[1] | plr[myplr]._pAblSpells[1];
v0 = plr[myplr]._pISpells64 | plr[myplr]._pMemSpells64 | plr[myplr]._pAblSpells64;
do
{
v2 = SpellPages[0][v9 + 7 * sbooktab - 1]; // *(&attribute_inc_rects[3].h + v9 + 7 * sbooktab); /* check */
if ( v2 != -1
&& v1 & ((unsigned __int64)((__int64)1 << ((unsigned char)v2 - 1)) >> 32) | v0 & (unsigned int)((__int64)1 << ((unsigned char)v2 - 1)) )
v1 = (__int64)1 << (v2 - 1);
if ( v2 != -1 && (v1 & v0) )
{
v7 = GetSBookTrans(v2, 1u);
SetSpellTrans(v7);

4
Source/inv.cpp

@ -1864,7 +1864,7 @@ void __fastcall RemoveInvItem(int pnum, int iv)
// BUGFIX: Cast the literal `1` to `UINT64` to make that bitshift 64bit
// this causes the last 4 skills to not reset correctly after use
if ( !(
*(UINT64 *)&plr[pnum]._pScrlSpells // TODO: remove cast when pScrlSpells is converted to UINT64
plr[pnum]._pScrlSpells64
& (1 << (plr[pnum]._pRSpell - 1))) )
{
plr[pnum]._pRSpell = SPL_INVALID;
@ -1888,7 +1888,7 @@ void __fastcall RemoveSpdBarItem(int pnum, int iv)
// BUGFIX: Cast the literal `1` to `UINT64` to make that bitshift 64bit
// this causes the last 4 skills to not reset correctly after use
if ( !(
*(UINT64 *)&plr[pnum]._pScrlSpells // TODO: remove cast when pScrlSpells is converted to UINT64
plr[pnum]._pScrlSpells64
& (1 << (plr[pnum]._pRSpell - 1))) )
{
plr[pnum]._pRSpell = SPL_INVALID;

3
Source/items.cpp

@ -934,8 +934,7 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx)
plr[p]._pDamageMod = plr[p]._pLevel * plr[p]._pStrength / 100;
}
// TODO: switch to normal 64bit assignment/remove case
*(UINT64 *)&plr[p]._pISpells = spl;
plr[p]._pISpells64 = spl;
// check if the current RSplType is a valid/allowed spell
if ( plr[p]._pRSplType == RSPLTYPE_CHARGES

4
Source/player.cpp

@ -3777,7 +3777,7 @@ BOOL __fastcall PM_DoSpell(int pnum)
if ( !plr[pnum]._pSplFrom ) {
if ( plr[pnum]._pRSplType == RSPLTYPE_SCROLL) {
if ( !(*(UINT64 *)&plr[pnum]._pScrlSpells // TODO: remove cast when pScrlSpells is converted to UINT64
if ( !(plr[pnum]._pScrlSpells64
& (UINT64)1 << (plr[pnum]._pRSpell - 1))
) {
plr[pnum]._pRSpell = SPL_INVALID;
@ -3787,7 +3787,7 @@ BOOL __fastcall PM_DoSpell(int pnum)
}
if ( plr[pnum]._pRSplType == RSPLTYPE_CHARGES) {
if ( !(*(UINT64 *)&plr[pnum]._pISpells // TODO: remove cast when pISpells is converted to UINT64
if ( !(plr[pnum]._pISpells64
& (UINT64)1 << (plr[pnum]._pRSpell - 1))
) {
plr[pnum]._pRSpell = SPL_INVALID;

1
Support/TODO.md

@ -8,7 +8,6 @@ Serious bugs (crash/fault)
- TBA
Minor bugs (noticeable but can be avoided)
- Players sometimes have level 0 unusable skills
- Server commands are broken and have been disabled `msgcmd.cpp`
Code issues (incorrect code that still works)

28
structs.h

@ -212,12 +212,19 @@ struct PlayerStruct
int _pSBkSpell;
char _pSBkSplType;
char _pSplLvl[64];
int remove_1; /* fix: remove and align 8 */
int _pMemSpells[2];
int _pAblSpells[2];
// should be UINT64
int _pScrlSpells[2];
char _pSpellFlags;
union {
UINT64 _pMemSpells64;
int _pMemSpells[2];
};
union {
UINT64 _pAblSpells64;
int _pAblSpells[2];
};
union {
UINT64 _pScrlSpells64;
int _pScrlSpells[2];
};
int _pSpellFlags;
int _pSplHotKey[4];
char _pSplTHotKey[4];
int _pwtype;
@ -316,9 +323,10 @@ struct PlayerStruct
int _pIBonusToHit;
int _pIBonusAC;
int _pIBonusDamMod;
int remove_2; /* fix: remove and align 8 */
// TODO: switch to UINT64
int _pISpells[2];
union {
UINT64 _pISpells64;
int _pISpells[2];
};
int _pIFlags;
int _pIGetHit;
char _pISplLvlAdd;
@ -1466,7 +1474,7 @@ struct PkPlayerStruct
int pManaBase;
int pMaxManaBase;
char pSplLvl[37];
int pMemSpells;
int pMemSpells; /* __int64 */
int pMemSpells2;
PkItemStruct InvBody[7];
PkItemStruct InvList[40];

Loading…
Cancel
Save