From db77557dcebc103ac5b1b88a15f4bcf1f76a25c7 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 23 Sep 2018 09:40:05 +0200 Subject: [PATCH] ValidatePlayer (#318) * ValidatePlayer * Add MAX_SPELLS define --- Source/control.cpp | 10 ++--- Source/control.h | 2 +- Source/debug.cpp | 2 +- Source/items.cpp | 8 ++-- Source/objects.cpp | 4 +- Source/pack.cpp | 4 +- Source/player.cpp | 108 ++++++++++++++++----------------------------- Source/spells.cpp | 2 +- Source/spells.h | 2 +- defs.h | 1 + structs.h | 2 +- 11 files changed, 58 insertions(+), 87 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index fc95e66af..13e1906ba 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -143,7 +143,7 @@ const unsigned char fontidx[256] = /* data */ -unsigned char SpellITbl[37] = +unsigned char SpellITbl[MAX_SPELLS] = { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 28, 13, 12, 18, 16, 14, 18, 19, 11, 20, @@ -611,7 +611,7 @@ LABEL_68: v26 *= (__int64)2; v23 = v4; } - while ( (signed int)v20 < (signed int)&spelldata[37].sTownSpell ); + while ( (signed int)v20 < (signed int)&spelldata[MAX_SPELLS].sTownSpell ); if ( v25 && v17 != 636 ) v17 -= 56; if ( v17 == 20 ) @@ -1382,7 +1382,7 @@ void __cdecl DoSpeedBook() ++v10; v7 = v4; } - while ( v10 < 37 ); + while ( v10 < MAX_SPELLS ); if ( v3 && v13 != 636 ) v13 -= 56; if ( v13 == 20 ) @@ -2748,11 +2748,11 @@ void __cdecl DrawSpellBook() { v7 = GetSBookTrans(v2, 1u); SetSpellTrans(v7); - DrawSpellCel(395, v8 + 1, (char *)pSBkIconCels, (char)SpellITbl[v2], 37); + DrawSpellCel(395, v8 + 1, (char *)pSBkIconCels, (char)SpellITbl[v2], MAX_SPELLS); if ( v2 == plr[myplr]._pRSpell && v7 == _LOBYTE(plr[myplr]._pRSplType) ) { SetSpellTrans(0); - DrawSpellCel(395, v8 + 1, (char *)pSBkIconCels, 43, 37); + DrawSpellCel(395, v8 + 1, (char *)pSBkIconCels, 43, MAX_SPELLS); } PrintSBookStr(10, v8 - 22, 0, spelldata[v2].sNameText, 0); v3 = GetSBookTrans(v2, 0); diff --git a/Source/control.h b/Source/control.h index 7a3bc1850..db1b10ab7 100644 --- a/Source/control.h +++ b/Source/control.h @@ -131,7 +131,7 @@ extern const unsigned char fontidx[256]; /* data */ -extern unsigned char SpellITbl[37]; +extern unsigned char SpellITbl[MAX_SPELLS]; extern int PanBtnPos[8][5]; extern char *PanBtnHotKey[8]; extern char *PanBtnStr[8]; diff --git a/Source/debug.cpp b/Source/debug.cpp index 03e11200d..022cac0e1 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -105,7 +105,7 @@ void __cdecl MaxSpellsCheat() { int i; // ebp - for(i = 1; i < 37; i++) + for(i = 1; i < MAX_SPELLS; i++) { if ( spelldata[i].sBookLvl != -1 ) { diff --git a/Source/items.cpp b/Source/items.cpp index 6bf10f2e4..6e8166884 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1883,7 +1883,7 @@ void __fastcall GetBookSpell(int i, int lvl) v3 = i; if ( !lvl ) v2 = lvl + 1; - v4 = random(14, 37) + 1; + v4 = random(14, MAX_SPELLS) + 1; LABEL_13: v6 = 1; while ( v4 > 0 ) @@ -1902,7 +1902,7 @@ LABEL_13: if ( v6 == SPL_HEALOTHER ) v6 = SPL_FLARE; } - if ( v6 == 37 ) + if ( v6 == MAX_SPELLS ) goto LABEL_13; } v7 = v3; @@ -2017,7 +2017,7 @@ void __fastcall GetStaffSpell(int i, int lvl, unsigned char onlygood) l = lvl >> 1; if ( !l ) l = 1; - rv = random(18, 37) + 1; + rv = random(18, MAX_SPELLS) + 1; LABEL_15: s = 1; while ( rv > 0 ) @@ -2035,7 +2035,7 @@ LABEL_15: if ( s == SPL_HEALOTHER ) s = SPL_FLARE; } - if ( s == 37 ) + if ( s == MAX_SPELLS ) goto LABEL_15; } sprintf(istr, "%s of %s", item[i]._iName, spelldata[bs].sNameText); diff --git a/Source/objects.cpp b/Source/objects.cpp index 2eaaa5a77..c7e718732 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -5287,10 +5287,10 @@ LABEL_47: v57 *= 2; ++v59; } - while ( v59 <= 37 ); + while ( v59 <= MAX_SPELLS ); do { - v60 = random(0, 37); + v60 = random(0, MAX_SPELLS); v7 = v60; } while ( !(plr[v53]._pMemSpells[1] & ((unsigned __int64)((__int64)1 << v60) >> 32) | plr[v53]._pMemSpells[0] & (unsigned int)((__int64)1 << v60)) ); diff --git a/Source/pack.cpp b/Source/pack.cpp index a5c601941..12d3b432a 100644 --- a/Source/pack.cpp +++ b/Source/pack.cpp @@ -50,7 +50,7 @@ void __fastcall PackPlayer(PkPlayerStruct *pPack, int pnum, bool manashield) pPack->pMemSpells = pPlayer->_pMemSpells[0]; pPack->pMemSpells2 = pPlayer->_pMemSpells[1]; - for(i = 0; i < 37; i++) + for(i = 0; i < MAX_SPELLS; i++) pPack->pSplLvl[i] = pPlayer->_pSplLvl[i]; pki = pPack->InvBody; @@ -199,7 +199,7 @@ void __fastcall UnPackPlayer(PkPlayerStruct *pPack, int pnum, bool killok) pPlayer->_pMemSpells[0] = pPack->pMemSpells; pPlayer->_pMemSpells[1] = pPack->pMemSpells2; - for(i = 0; i < 37; i++) + for(i = 0; i < MAX_SPELLS; i++) pPlayer->_pSplLvl[i] = pPack->pSplLvl[i]; pki = pPack->InvBody; diff --git a/Source/player.cpp b/Source/player.cpp index 077bedad5..21a4b0ec4 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3810,81 +3810,51 @@ BOOL __fastcall PlrDeathModeOK(int pnum) void __cdecl ValidatePlayer() { - int v0; // edi - int v1; // esi - char *v2; // eax - int v3; // ecx - int v4; // ecx - int *v5; // eax - int v6; // eax - int v7; // edx - int v8; // edx - int v9; // edx - int v10; // eax - int *v11; // ebx - signed int v12; // edi - char *v13; // eax - __int64 v14; // [esp+Ch] [ebp-8h] + __int64 msk = 0; - v0 = 0; - v14 = (__int64)0; - if ( (unsigned int)myplr >= 4 ) + if ( (DWORD)myplr >= MAX_PLRS ) { TermMsg("ValidatePlayer: illegal player %d", myplr); - v1 = myplr; - v2 = &plr[myplr]._pLevel; - if ( *v2 > 50 ) - *v2 = 50; - v3 = plr[v1]._pNextExper; - if ( plr[v1]._pExperience > v3 ) - plr[v1]._pExperience = v3; - v4 = 0; - if ( plr[v1]._pNumInv > 0 ) - { - v5 = &plr[v1].InvList[0]._ivalue; - do - { - if ( *(v5 - 47) == 11 ) - { - if ( *v5 > 5000 ) - *v5 = 5000; - v4 += *v5; + } + if ( plr[myplr]._pLevel > 50 ) + plr[myplr]._pLevel = 50; + if ( plr[myplr]._pExperience > plr[myplr]._pNextExper ) + plr[myplr]._pExperience = plr[myplr]._pNextExper; + + int gt = 0; + for ( int i = 0; i < plr[myplr]._pNumInv; i++ ) { + if ( plr[myplr].InvList[i]._itype == ITYPE_GOLD ) { + if ( plr[myplr].InvList[i]._ivalue > 5000 ) { + plr[myplr].InvList[i]._ivalue = 5000; } - ++v0; - v5 += 92; + gt += plr[myplr].InvList[i]._ivalue; } - while ( v0 < plr[v1]._pNumInv ); - } - if ( v4 != plr[v1]._pGold ) - plr[v1]._pGold = v4; - v6 = SLOBYTE(plr[v1]._pClass); - v7 = MaxStats[v6][0]; - if ( plr[v1]._pBaseStr > v7 ) - plr[v1]._pBaseStr = v7; - v8 = MaxStats[v6][1]; - if ( plr[v1]._pBaseMag > v8 ) - plr[v1]._pBaseMag = v8; - v9 = MaxStats[v6][2]; - if ( plr[v1]._pBaseDex > v9 ) - plr[v1]._pBaseDex = v9; - v10 = MaxStats[v6][3]; - if ( plr[v1]._pBaseVit > v10 ) - plr[v1]._pBaseVit = v10; - v11 = &spelldata[1].sBookLvl; - v12 = 1; - do - { - if ( *v11 != -1 ) - { - v14 |= (__int64)1 << ((unsigned char)v12 - 1); - v13 = &plr[v1]._pSplLvl[v12]; - if ( *v13 > 15 ) - *v13 = 15; + } + if ( gt != plr[myplr]._pGold ) + plr[myplr]._pGold = gt; + + int pc = plr[myplr]._pClass; + if ( plr[myplr]._pBaseStr > MaxStats[pc][ATTRIB_STR] ) { + plr[myplr]._pBaseStr = MaxStats[pc][ATTRIB_STR]; + } + if ( plr[myplr]._pBaseMag > MaxStats[pc][ATTRIB_MAG] ) { + plr[myplr]._pBaseMag = MaxStats[pc][ATTRIB_MAG]; + } + if ( plr[myplr]._pBaseDex > MaxStats[pc][ATTRIB_DEX] ) { + plr[myplr]._pBaseDex = MaxStats[pc][ATTRIB_DEX]; + } + if ( plr[myplr]._pBaseVit > MaxStats[pc][ATTRIB_VIT] ) { + plr[myplr]._pBaseVit = MaxStats[pc][ATTRIB_VIT]; + } + + for ( int b = 1; b < MAX_SPELLS; b++) { + if ( spelldata[b].sBookLvl != -1 ) { + msk |= (__int64)1 << (b - 1); + if ( plr[myplr]._pSplLvl[b] > 15 ) + plr[myplr]._pSplLvl[b] = 15; } - v11 += 14; - ++v12; } - while ( (signed int)v11 < (signed int)&spelldata[37].sBookLvl ); - *(_QWORD *)plr[v1]._pMemSpells &= v14; + + plr[myplr]._pMemSpells64 &= msk; } void __cdecl ProcessPlayers() diff --git a/Source/spells.cpp b/Source/spells.cpp index 1c393fed4..e5a1b2f94 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -2,7 +2,7 @@ #include "../types.h" -SpellData spelldata[37] = +SpellData spelldata[MAX_SPELLS] = { { 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, { 0, 0, 0 }, 0, 0, 40, 80, 0, 0 }, { SPL_FIREBOLT, 6, STYPE_FIRE, "Firebolt", "Firebolt", 1, 1, 1, 0, 15, IS_CAST2, { MIS_FIREBOLT, 0, 0 }, 1, 3, 40, 80, 1000, 50 }, diff --git a/Source/spells.h b/Source/spells.h index 52aae6c95..3e23547be 100644 --- a/Source/spells.h +++ b/Source/spells.h @@ -12,6 +12,6 @@ void __fastcall DoHealOther(int pnum, int rid); /* rdata */ -extern SpellData spelldata[37]; +extern SpellData spelldata[MAX_SPELLS]; #endif /* __SPELLS_H__ */ diff --git a/defs.h b/defs.h index 8671cd043..f0f6d829d 100644 --- a/defs.h +++ b/defs.h @@ -12,6 +12,7 @@ #define MAX_LVLMTYPES 16 // #define MAX_PATH 260 #define MAX_SEND_STR_LEN 80 +#define MAX_SPELLS 37 #define MAXDEAD 31 #define MAXDUNX 112 diff --git a/structs.h b/structs.h index 26180816e..0c1fa845d 100644 --- a/structs.h +++ b/structs.h @@ -1471,7 +1471,7 @@ struct PkPlayerStruct int pMaxHPBase; int pManaBase; int pMaxManaBase; - char pSplLvl[37]; + char pSplLvl[MAX_SPELLS]; int pMemSpells; /* __int64 */ int pMemSpells2; PkItemStruct InvBody[7];