Browse Source

Merge branch 'master' of github.com:diasurgical/devilution

pull/124/head
Anders Jenbo 7 years ago
parent
commit
6439861554
  1. 2
      DiabloUI/connect.cpp
  2. 4
      DiabloUI/selconn.cpp
  3. 38
      Source/codec.cpp
  4. 253
      Source/control.cpp
  5. 20
      Source/inv.cpp
  6. 23
      defs.h

2
DiabloUI/connect.cpp

@ -521,7 +521,7 @@ BOOL __stdcall UiDrawDescCallback(int game_type, COLORREF color, LPCSTR lpString
v16 = strlen(String);
TextOutA(v8[6], 0, 0, String, v16);
v17 = v8[6];
qmemcpy(a8a, v8, sizeof(a8a));
memcpy(a8a, v8, sizeof(a8a));
GetCurrentPositionEx(v17, (LPPOINT)&a8a[7]);
SetTextAlign(v8[6], 0);
connect_color_text = 1;

4
DiabloUI/selconn.cpp

@ -937,10 +937,10 @@ int UNKCALL SelConn_1000AC9E(HWND hWnd) { return 0; }
BNetGW_100028C2(&unk_10029480);
}
if ( dword_1002A364 )
qmemcpy(&v13, (const void *)dword_1002A364, 0x50u);
memcpy(&v13, (const void *)dword_1002A364, 0x50u);
v14 = v1;
if ( dword_1002A370 )
qmemcpy(&v15, (const void *)dword_1002A370, 0x3Cu);
memcpy(&v15, (const void *)dword_1002A370, 0x3Cu);
SelConn_1000ADA8(v1);
v6 = dword_1002A358;
v7 = dword_1002A34C;

38
Source/codec.cpp

@ -2,11 +2,20 @@
DEVILUTION_BEGIN_NAMESPACE
struct CodecSignature
{
DWORD checksum;
BYTE error;
BYTE last_chunk_size;
WORD unused;
};
int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword)
{
char buf[128];
char dst[20];
char dst[SHA1HashSize];
int i;
CodecSignature *sig;
codec_init_key(0, pszPassword);
if (size <= 8)
@ -18,7 +27,7 @@ int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword)
memcpy(buf, pbSrcDst, 64);
SHA1Result(0, dst);
for (int j = 0; j < 64; j++) {
buf[j] ^= dst[j % 20];
buf[j] ^= dst[j % SHA1HashSize];
}
SHA1Calculate(0, buf, NULL);
memset(dst, 0, sizeof(dst));
@ -26,17 +35,18 @@ int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword)
}
memset(buf, 0, sizeof(buf));
if (pbSrcDst[4] > 0) {
sig = (CodecSignature *)pbSrcDst;
if (sig->error > 0) {
size = 0;
SHA1Clear();
} else {
SHA1Result(0, dst);
if (*(DWORD *)pbSrcDst != *(DWORD *)dst) {
if (sig->checksum != *(DWORD *)dst) {
memset(dst, 0, sizeof(dst));
size = 0;
SHA1Clear();
} else {
size += pbSrcDst[5] - 64;
size += sig->last_chunk_size - 64;
SHA1Clear();
}
}
@ -69,7 +79,7 @@ void codec_init_key(int unused, char *pszPassword)
SHA1Calculate(0, pw, digest);
SHA1Clear();
for (i = 0; (DWORD)i < 136; i++)
key[i] ^= digest[i % 20];
key[i] ^= digest[i % SHA1HashSize];
memset(pw, 0, sizeof(pw));
memset(digest, 0, sizeof(digest));
for (n = 0; n < 3; n++) {
@ -89,10 +99,11 @@ DWORD codec_get_encoded_len(DWORD dwSrcBytes)
void codec_encode(BYTE* pbSrcDst, DWORD size, int size_64, char *pszPassword)
{
char buf[128];
char tmp[20];
char dst[20];
char tmp[SHA1HashSize];
char dst[SHA1HashSize];
DWORD chunk;
WORD last_chunk;
CodecSignature *sig;
if (size_64 != codec_get_encoded_len(size))
app_fatal("Invalid encode parameters");
@ -107,7 +118,7 @@ void codec_encode(BYTE* pbSrcDst, DWORD size, int size_64, char *pszPassword)
SHA1Result(0, dst);
SHA1Calculate(0, buf, NULL);
for (int j = 0; j < 64; j++) {
buf[j] ^= dst[j % 20];
buf[j] ^= dst[j % SHA1HashSize];
}
memset(dst, 0, sizeof(dst));
memcpy(pbSrcDst, buf, 64);
@ -117,10 +128,11 @@ void codec_encode(BYTE* pbSrcDst, DWORD size, int size_64, char *pszPassword)
}
memset(buf, 0, sizeof(buf));
SHA1Result(0, tmp);
pbSrcDst[4] = 0;
((WORD *)pbSrcDst)[3] = 0;
((DWORD *)pbSrcDst)[0] = ((DWORD *)tmp)[0];
pbSrcDst[5] = last_chunk;
sig = (CodecSignature*) pbSrcDst;
sig->error = 0;
sig->unused = 0;
sig->checksum = *(DWORD *)tmp;
sig->last_chunk_size = last_chunk;
SHA1Clear();
}

253
Source/control.cpp

@ -378,190 +378,127 @@ void DrawSpell()
void DrawSpellList()
{
int v0; // esi
signed int v1; // edi
signed int v4; // ebp
int v5; // eax
int v6; // esi
int v7; // eax
BOOLEAN v8; // sf
int v9; // esi
int v10; // eax
int v11; // ebp
int v12; // edx
int *v13; // ecx
int *v14; // eax
signed int v15; // edx
signed int v16; // edi
int v17; // [esp+Ch] [ebp-34h]
__int32 xp; // [esp+10h] [ebp-30h]
__int32 yp; // [esp+14h] [ebp-2Ch]
BOOL *v20; // [esp+18h] [ebp-28h]
__int32 nCel; // [esp+1Ch] [ebp-24h]
int v22; // [esp+20h] [ebp-20h]
__int32 v23; // [esp+24h] [ebp-1Ch]
signed int v24; // [esp+28h] [ebp-18h]
unsigned __int64 v25; // [esp+2Ch] [ebp-14h]
signed __int64 v26; // [esp+34h] [ebp-Ch]
int i, j, x, y, c, s, t, v, lx, ly, trans;
unsigned __int64 mask, spl;
pSpell = -1;
infostr[0] = 0;
v17 = 636;
xp = 495;
infostr[0] = '\0';
x = 636;
y = 495;
ClearPanel();
v0 = myplr;
v1 = RSPLTYPE_SKILL;
v24 = 0;
nCel = 0;
do {
switch (v1) {
for (i = 0; i < 4; i++) {
switch ((spell_type)i) {
case RSPLTYPE_SKILL:
SetSpellTrans(RSPLTYPE_SKILL);
yp = 46;
v25 = plr[v0]._pAblSpells;
c = 46;
mask = plr[myplr]._pAblSpells;
break;
case RSPLTYPE_SPELL:
yp = 47;
v25 = plr[v0]._pMemSpells;
c = 47;
mask = plr[myplr]._pMemSpells;
break;
case RSPLTYPE_SCROLL:
SetSpellTrans(RSPLTYPE_SCROLL);
yp = 44;
v25 = plr[v0]._pScrlSpells;
c = 44;
mask = plr[myplr]._pScrlSpells;
break;
case RSPLTYPE_CHARGES:
SetSpellTrans(RSPLTYPE_CHARGES);
yp = 45;
v25 = plr[v0]._pISpells;
c = 45;
mask = plr[myplr]._pISpells;
break;
}
v20 = &spelldata[1].sTownSpell;
v4 = 1;
v26 = (__int64)1;
v23 = 1;
v22 = xp - 216;
do {
if (!(v25 & v26))
goto LABEL_68;
if (v1 == RSPLTYPE_SPELL) {
v5 = v0;
v6 = plr[v0]._pSplLvl[v4];
v7 = plr[v5]._pISplLvlAdd;
v8 = v7 + v6 < 0;
v9 = v7 + v6;
nCel = v9;
if (v8) {
nCel = 0;
v9 = 0;
}
SetSpellTrans(v9 <= 0 ? RSPLTYPE_INVALID : RSPLTYPE_SPELL);
} else {
v9 = nCel;
for (spl = 1, j = 1; j < MAX_SPELLS; spl <<= 1, j++) {
if (!(mask & spl))
continue;
if (i == RSPLTYPE_SPELL) {
s = plr[myplr]._pISplLvlAdd + plr[myplr]._pSplLvl[j];
if (s < 0)
s = 0;
if (s > 0)
trans = RSPLTYPE_SPELL;
else
trans = RSPLTYPE_INVALID;
SetSpellTrans(trans);
}
if (!currlevel && !*v20)
if (currlevel == 0 && !spelldata[j].sTownSpell)
SetSpellTrans(RSPLTYPE_INVALID);
DrawSpellCel(v17, xp, pSpellCels, SpellITbl[v4], 56);
if (MouseX >= v17 - 64 && MouseX < v17 - 64 + 56 && MouseY >= v22 && MouseY < v22 + 56) {
pSpell = v4;
pSplType = v1;
DrawSpellCel(v17, xp, pSpellCels, yp, 56);
if (v1) {
switch (v1) {
case RSPLTYPE_SPELL:
sprintf(infostr, "%s Spell", spelldata[pSpell].sNameText);
if (pSpell == 31) {
sprintf(tempstr, "Damages undead only");
AddPanelString(tempstr, 1);
}
if (v9)
sprintf(tempstr, "Spell Level %i", v9);
else
sprintf(tempstr, "Spell Level 0 - Unusable");
LABEL_32:
DrawSpellCel(x, y, pSpellCels, SpellITbl[j], 56);
lx = x - 64;
ly = y - 216;
if (MouseX >= lx && MouseX < lx + 56 && MouseY >= ly && MouseY < ly + 56) {
pSpell = j;
pSplType = i;
DrawSpellCel(x, y, pSpellCels, c, 56);
switch (i) {
case RSPLTYPE_SKILL:
sprintf(infostr, "%s Skill", spelldata[pSpell].sSkillText);
break;
case RSPLTYPE_SPELL:
sprintf(infostr, "%s Spell", spelldata[pSpell].sNameText);
if (pSpell == SPL_HBOLT) {
sprintf(tempstr, "Damages undead only");
AddPanelString(tempstr, 1);
break;
case RSPLTYPE_SCROLL:
sprintf(infostr, "Scroll of %s", spelldata[pSpell].sNameText);
v10 = myplr;
v11 = 0;
v12 = plr[myplr]._pNumInv;
if (v12 > 0) {
v13 = &plr[v10].InvList[0]._iMiscId;
do {
if (*(v13 - 53) != -1
&& (*v13 == IMISC_SCROLL || *v13 == IMISC_SCROLLT)
&& v13[1] == pSpell) {
++v11;
}
v13 += 92;
--v12;
} while (v12);
}
if (s == 0)
sprintf(tempstr, "Spell Level 0 - Unusable");
else
sprintf(tempstr, "Spell Level %i", s);
AddPanelString(tempstr, TRUE);
break;
case RSPLTYPE_SCROLL:
sprintf(infostr, "Scroll of %s", spelldata[pSpell].sNameText);
v = 0;
for (t = 0; t < plr[myplr]._pNumInv; t++) {
if (plr[myplr].InvList[t]._itype != ITYPE_NONE
&& (plr[myplr].InvList[t]._iMiscId == IMISC_SCROLL || plr[myplr].InvList[t]._iMiscId == IMISC_SCROLLT)
&& plr[myplr].InvList[t]._iSpell == pSpell) {
v++;
}
v14 = &plr[v10].SpdList[0]._iMiscId;
v15 = MAXBELTITEMS;
do {
if (*(v14 - 53) != -1
&& (*v14 == IMISC_SCROLL || *v14 == IMISC_SCROLLT)
&& v14[1] == pSpell) {
++v11;
}
v14 += 92;
--v15;
} while (v15);
if (v11 == 1)
strcpy(tempstr, "1 Scroll");
else
sprintf(tempstr, "%i Scrolls", v11);
AddPanelString(tempstr, 1);
v4 = v23;
break;
case RSPLTYPE_CHARGES:
sprintf(infostr, "Staff of %s", spelldata[pSpell].sNameText);
if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges == 1)
strcpy(tempstr, "1 Charge");
else
sprintf(tempstr, "%i Charges", plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges);
goto LABEL_32;
}
} else {
sprintf(infostr, "%s Skill", spelldata[pSpell].sSkillText);
for (t = 0; t < MAXBELTITEMS; t++) {
if (plr[myplr].SpdList[t]._itype != ITYPE_NONE
&& (plr[myplr].SpdList[t]._iMiscId == IMISC_SCROLL || plr[myplr].SpdList[t]._iMiscId == IMISC_SCROLLT)
&& plr[myplr].SpdList[t]._iSpell == pSpell) {
v++;
}
}
if (v == 1)
strcpy(tempstr, "1 Scroll");
else
sprintf(tempstr, "%i Scrolls", v);
AddPanelString(tempstr, TRUE);
break;
case RSPLTYPE_CHARGES:
sprintf(infostr, "Staff of %s", spelldata[pSpell].sNameText);
if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges == 1)
strcpy(tempstr, "1 Charge");
else
sprintf(tempstr, "%i Charges", plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges);
AddPanelString(tempstr, TRUE);
break;
}
v0 = myplr;
v16 = 0;
do {
if (plr[v0]._pSplHotKey[v16] == pSpell && plr[v0]._pSplTHotKey[v16] == pSplType) {
DrawSpellCel(v17, xp, pSpellCels, v16 + 48, 56);
sprintf(tempstr, "Spell Hot Key #F%i", v16 + 5);
for (t = 0; t < 4; t++) {
if (plr[myplr]._pSplHotKey[t] == pSpell && plr[myplr]._pSplTHotKey[t] == pSplType) {
DrawSpellCel(x, y, pSpellCels, t + 48, 56);
printf(tempstr, "Spell Hot Key #F%i", t + 5);
AddPanelString(tempstr, 1);
v0 = myplr;
}
++v16;
} while (v16 < 4);
v1 = v24;
goto LABEL_66;
}
}
v0 = myplr;
LABEL_66:
v17 -= 56;
if (v17 == 20) {
xp -= 56;
v22 -= 56;
v17 = 636;
x -= 56;
if (x == 20) {
y -= 56;
x = 636;
}
LABEL_68:
v20 += 14;
++v4;
v26 *= (__int64)2;
v23 = v4;
} while ((INT_PTR)v20 < (INT_PTR)&spelldata[MAX_SPELLS].sTownSpell);
if (v25 && v17 != 636)
v17 -= 56;
if (v17 == 20) {
xp -= 56;
v17 = 636;
}
v24 = ++v1;
} while (v1 < 4);
if (mask != 0 && x != 636)
x -= 56;
if (x == 20) {
y -= 56;
x = 636;
}
}
}
// 4B8834: using guessed type int pSpell;
// 4B8954: using guessed type int pSplType;

20
Source/inv.cpp

@ -544,15 +544,15 @@ BOOL SpecialAutoPlace(int pnum, int ii, int sx, int sy, BOOL saveflag)
yy += 10;
}
if (!done) {
if (sx <= 1 && sy <= 1) {
if (sx > 1 || sy > 1) {
done = FALSE;
} else {
for (i = 0; i < MAXBELTITEMS; i++) {
if (plr[pnum].SpdList[i]._itype == ITYPE_NONE) {
done = TRUE;
break;
}
}
} else {
done = FALSE;
}
}
if (done && saveflag) {
@ -2092,7 +2092,7 @@ void StartGoldDrop()
BOOL UseInvItem(int pnum, int cii)
{
int c, idata, it;
int c, idata;
ItemStruct *Item;
BOOL speedlist;
@ -2113,8 +2113,8 @@ BOOL UseInvItem(int pnum, int cii)
if (talkflag)
return TRUE;
c = cii - 47;
speedlist = TRUE;
Item = &plr[pnum].SpdList[c];
speedlist = TRUE;
}
switch (Item->IDidx) {
@ -2154,9 +2154,7 @@ BOOL UseInvItem(int pnum, int cii)
return TRUE;
}
it = Item->_iMiscId;
if (it == IMISC_NONE && Item->_itype == ITYPE_GOLD) {
if (Item->_iMiscId == IMISC_NONE && Item->_itype == ITYPE_GOLD) {
StartGoldDrop();
return TRUE;
}
@ -2166,13 +2164,13 @@ BOOL UseInvItem(int pnum, int cii)
dropGoldValue = 0;
}
if (it == IMISC_SCROLL && currlevel == 0 && !spelldata[Item->_iSpell].sTownSpell
|| it == IMISC_SCROLLT && currlevel == 0 && !spelldata[Item->_iSpell].sTownSpell) {
if ((Item->_iMiscId == IMISC_SCROLL && currlevel == 0 && !spelldata[Item->_iSpell].sTownSpell)
|| (Item->_iMiscId == IMISC_SCROLLT && currlevel == 0 && !spelldata[Item->_iSpell].sTownSpell)) {
return TRUE;
}
idata = ItemCAnimTbl[Item->_iCurs];
if (it == IMISC_BOOK)
if (Item->_iMiscId == IMISC_BOOK)
PlaySFX(IS_RBOOK);
else if (pnum == myplr)
PlaySFX(ItemInvSnds[idata]);

23
defs.h

@ -145,12 +145,9 @@
#define _DWORD unsigned int
// Some convenience macros to make partial accesses nicer
#define LAST_IND(x,part_type) (sizeof(x)/sizeof(part_type) - 1)
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
# define LOW_IND(x,part_type) LAST_IND(x,part_type)
# define HIGH_IND(x,part_type) 0
# define LOW_IND(x,part_type) (sizeof(x)/sizeof(part_type) - 1)
#else
# define HIGH_IND(x,part_type) LAST_IND(x,part_type)
# define LOW_IND(x,part_type) 0
#endif
@ -160,24 +157,6 @@
#define _LOBYTE(x) BYTEn(x,LOW_IND(x,BYTE))
#define _LOWORD(x) WORDn(x,LOW_IND(x,WORD))
#define _HIBYTE(x) BYTEn(x,HIGH_IND(x,BYTE))
#define BYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0)
#define BYTE2(x) BYTEn(x, 2)
#define SLOBYTE(x) (*((char*)&(x)+LOW_IND(x,char)))
// Helper functions to represent some assembly instructions.
__inline void *qmemcpy(void *dst, const void *src, size_t cnt)
{
char *out = (char *)dst;
const char *in = (const char *)src;
while (cnt > 0) {
*out++ = *in++;
--cnt;
}
return dst;
}
#endif /* IDA_GARBAGE */

Loading…
Cancel
Save