diff --git a/Source/control.cpp b/Source/control.cpp index 9f6f5ddee..f4e3a578b 100644 --- a/Source/control.cpp +++ b/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); diff --git a/Source/inv.cpp b/Source/inv.cpp index 44cece072..ce8afde04 100644 --- a/Source/inv.cpp +++ b/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; diff --git a/Source/items.cpp b/Source/items.cpp index d82e52357..18e19e9cf 100644 --- a/Source/items.cpp +++ b/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 diff --git a/Source/player.cpp b/Source/player.cpp index b891038b0..421ad22fc 100644 --- a/Source/player.cpp +++ b/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; diff --git a/Support/TODO.md b/Support/TODO.md index 546835e5e..239e3be1e 100644 --- a/Support/TODO.md +++ b/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) diff --git a/structs.h b/structs.h index 693edb6ca..023698699 100644 --- a/structs.h +++ b/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];