From e5f9df055df99b92b81ef9579fda5876c063d6cd Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 23:51:11 +0100 Subject: [PATCH 01/28] MI_LArrow bin exact --- Source/missiles.cpp | 166 ++++++++++++++++---------------------------- 1 file changed, 60 insertions(+), 106 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index a8d5f6d93..3566fff46 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3245,130 +3245,84 @@ void __fastcall MI_SetManashield(int i) void __fastcall MI_LArrow(int i) { - int v1; // esi - char v2; // al - int v3; // ebx - int v4; // eax - int v6; // edi - int v7; // ecx - int v8; // eax - int v9; // ecx - int v10; // edx - int v11; // ST0C_4 - unsigned char *v12; // eax - unsigned char v13; // bl - int v14; // eax - int v15; // edx - int v16; // ecx - int v17; // ST10_4 - int v18; // ecx - int v19; // edi - int v20; // eax - int v21; // eax - int v22; // ecx - int v23; // ST0C_4 - int v24; // edi - int v25; // eax - int v26; // eax - int v27; // ecx - int v28; // ST10_4 - int v29; // ecx - unsigned char v32; // [esp+Ch] [ebp-8h] - int ia; // [esp+10h] [ebp-4h] + int p, mind, maxd, rst; - v1 = i; - ia = i; - v2 = missile[i]._miAnimType; - --missile[v1]._mirange; - v3 = missile[i]._misource; - if (v2 == MFILE_MINILTNG || v2 == MFILE_MAGBLOS) { - ChangeLight(missile[v1]._mlid, missile[v1]._mix, missile[v1]._miy, missile[v1]._miAnimFrame + 5); - v18 = missiledata[missile[v1]._mitype].mResist; - v32 = missiledata[missile[v1]._mitype].mResist; - if (missile[v1]._mitype == MIS_LARROW) { - if (v3 == -1) { - v21 = random(68, 10); - v22 = currlevel; - v19 = v21 + currlevel + 1; - v20 = random(68, 10) + 2 * currlevel + 1; + missile[i]._mirange--; + p = missile[i]._misource; + if (missile[i]._miAnimType == MFILE_MINILTNG || missile[i]._miAnimType == MFILE_MAGBLOS) { + ChangeLight(missile[i]._mlid, missile[i]._mix, missile[i]._miy, missile[i]._miAnimFrame + 5); + rst = missiledata[missile[i]._mitype].mResist; + if (missile[i]._mitype == MIS_LARROW) { + if (p != -1) { + mind = plr[p]._pILMinDam; + maxd = plr[p]._pILMaxDam; } else { - v19 = plr[v3]._pILMinDam; - v20 = plr[v3]._pILMaxDam; + mind = random(68, 10) + currlevel + 1; + maxd = random(68, 10) + 2 * currlevel + 1; } - v23 = missile[v1]._miy; missiledata[MIS_LARROW].mResist = MISR_LIGHTNING; - CheckMissileCol(ia, v19, v20, 0, missile[v1]._mix, v23, 1); + CheckMissileCol(i, mind, maxd, 0, missile[i]._mix, missile[i]._miy, 1); } - if (missile[v1]._mitype == MIS_FARROW) { - if (v3 == -1) { - v26 = random(68, 10); - v27 = currlevel; - v24 = v26 + currlevel + 1; - v25 = random(68, 10) + 2 * currlevel + 1; + if (missile[i]._mitype == MIS_FARROW) { + if (p != -1) { + mind = plr[p]._pIFMinDam; + maxd = plr[p]._pIFMaxDam; } else { - v24 = plr[v3]._pIFMinDam; - v25 = plr[v3]._pIFMaxDam; + mind = random(68, 10) + currlevel + 1; + maxd = random(68, 10) + 2 * currlevel + 1; } - v28 = missile[v1]._miy; missiledata[MIS_FARROW].mResist = MISR_FIRE; - CheckMissileCol(ia, v24, v25, 0, missile[v1]._mix, v28, 1); + CheckMissileCol(i, mind, maxd, 0, missile[i]._mix, missile[i]._miy, 1); } - missiledata[missile[v1]._mitype].mResist = v32; + missiledata[missile[i]._mitype].mResist = rst; } else { - v4 = missile[v1]._mixvel; - ++missile[v1]._midist; - missile[v1]._mitxoff += v4; - missile[v1]._mityoff += missile[v1]._miyvel; + missile[i]._midist++; + missile[i]._mitxoff += missile[i]._mixvel; + missile[i]._mityoff += missile[i]._miyvel; GetMissilePos(i); - if (v3 == -1) { - v8 = random(68, 10); - v9 = currlevel; - v6 = v8 + currlevel + 1; - v7 = random(68, 10) + 2 * currlevel + 1; - } else if (missile[v1]._micaster) { - v6 = (unsigned char)monster[v3].mMinDamage; - v7 = (unsigned char)monster[v3].mMaxDamage; + + if (p != -1) { + if (!missile[i]._micaster) { + mind = plr[p]._pIMinDam; + maxd = plr[p]._pIMaxDam; + } else { + mind = (unsigned char)monster[p].mMinDamage; + maxd = (unsigned char)monster[p].mMaxDamage; + } } else { - v6 = plr[v3]._pIMinDam; - v7 = plr[v3]._pIMaxDam; + mind = random(68, 10) + currlevel + 1; + maxd = random(68, 10) + 2 * currlevel + 1; } - v10 = missile[v1]._mix; - if (v10 != missile[v1]._misx || missile[v1]._miy != missile[v1]._misy) { - v11 = missile[v1]._miy; - v12 = &missiledata[missile[v1]._mitype].mResist; - v13 = *v12; - *v12 = 0; - CheckMissileCol(ia, v6, v7, 0, v10, v11, 0); - missiledata[missile[v1]._mitype].mResist = v13; + + if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) { + rst = missiledata[missile[i]._mitype].mResist; + missiledata[missile[i]._mitype].mResist = 0; + CheckMissileCol(i, mind, maxd, 0, missile[i]._mix, missile[i]._miy, 0); + missiledata[missile[i]._mitype].mResist = rst; } - if (missile[v1]._mirange) { - v15 = missile[v1]._mix; - if (v15 != missile[v1]._miVar1 || missile[v1]._miy != missile[v1]._miVar2) { - v16 = missile[v1]._mlid; - missile[v1]._miVar1 = v15; - v17 = missile[v1]._miy; - missile[v1]._miVar2 = v17; - ChangeLight(v16, v15, v17, 5); - } - } else { - missile[v1]._mitxoff -= missile[v1]._mixvel; - v14 = missile[v1]._miyvel; - missile[v1]._mimfnum = 0; - missile[v1]._mityoff -= v14; - GetMissilePos(ia); - if (missile[v1]._mitype == MIS_LARROW) - SetMissAnim(ia, MFILE_MINILTNG); + if (!missile[i]._mirange) { + missile[i]._mimfnum = 0; + missile[i]._mitxoff -= missile[i]._mixvel; + missile[i]._mityoff -= missile[i]._miyvel; + GetMissilePos(i); + if (missile[i]._mitype == MIS_LARROW) + SetMissAnim(i, MFILE_MINILTNG); else - SetMissAnim(ia, MFILE_MAGBLOS); - missile[v1]._mirange = missile[v1]._miAnimLen - 1; + SetMissAnim(i, MFILE_MAGBLOS); + missile[i]._mirange = missile[i]._miAnimLen - 1; + } else { + if (missile[i]._mix != missile[i]._miVar1 || missile[i]._miy != missile[i]._miVar2) { + missile[i]._miVar1 = missile[i]._mix; + missile[i]._miVar2 = missile[i]._miy; + ChangeLight(missile[i]._mlid, missile[i]._mix, missile[i]._miy, 5); + } } } - if (!missile[v1]._mirange) { - v29 = missile[v1]._mlid; - missile[v1]._miDelFlag = TRUE; - AddUnLight(v29); + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + AddUnLight(missile[i]._mlid); } - PutMissile(ia); + PutMissile(i); } void __fastcall MI_Arrow(int i) From 73e700f856d01b323dd7e6c52bd05e010097a65b Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 23:54:58 +0100 Subject: [PATCH 02/28] MI_LArrow bin exact suggestion #1 Co-Authored-By: qndel --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 3566fff46..ef65ed47c 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3286,7 +3286,7 @@ void __fastcall MI_LArrow(int i) mind = plr[p]._pIMinDam; maxd = plr[p]._pIMaxDam; } else { - mind = (unsigned char)monster[p].mMinDamage; + mind = monster[p].mMinDamage; maxd = (unsigned char)monster[p].mMaxDamage; } } else { From acc8dd5773b304fd084f4a2697a105e3ace4aaac Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 23:57:40 +0100 Subject: [PATCH 03/28] MI_LArrow bin exact suggestion #1 Co-Authored-By: qndel --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index ef65ed47c..ed6c4f562 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3287,7 +3287,7 @@ void __fastcall MI_LArrow(int i) maxd = plr[p]._pIMaxDam; } else { mind = monster[p].mMinDamage; - maxd = (unsigned char)monster[p].mMaxDamage; + maxd = monster[p].mMaxDamage; } } else { mind = random(68, 10) + currlevel + 1; From 0e36b089245651ceb1127c3337322bb75c6775c1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 23:57:49 +0100 Subject: [PATCH 04/28] MI_LArrow bin exact suggestion #2 Co-Authored-By: qndel --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index ed6c4f562..40262930d 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3269,7 +3269,7 @@ void __fastcall MI_LArrow(int i) maxd = plr[p]._pIFMaxDam; } else { mind = random(68, 10) + currlevel + 1; - maxd = random(68, 10) + 2 * currlevel + 1; + maxd = random(68, 10) + 1 + currlevel * 2; } missiledata[MIS_FARROW].mResist = MISR_FIRE; CheckMissileCol(i, mind, maxd, 0, missile[i]._mix, missile[i]._miy, 1); From 8abc0f4a2a8b04d65c04243316b8424f2002ef78 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 23:57:59 +0100 Subject: [PATCH 05/28] MI_LArrow bin exact suggestion #3 Co-Authored-By: qndel --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 40262930d..8a3d904ad 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3268,7 +3268,7 @@ void __fastcall MI_LArrow(int i) mind = plr[p]._pIFMinDam; maxd = plr[p]._pIFMaxDam; } else { - mind = random(68, 10) + currlevel + 1; + mind = random(68, 10) + 1 + currlevel; maxd = random(68, 10) + 1 + currlevel * 2; } missiledata[MIS_FARROW].mResist = MISR_FIRE; From 4744824cfaf37a396c5bc6998be817725a0800a2 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 23:58:07 +0100 Subject: [PATCH 06/28] MI_LArrow bin exact suggestion #4 Co-Authored-By: qndel --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 8a3d904ad..4dd739076 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3258,7 +3258,7 @@ void __fastcall MI_LArrow(int i) maxd = plr[p]._pILMaxDam; } else { mind = random(68, 10) + currlevel + 1; - maxd = random(68, 10) + 2 * currlevel + 1; + maxd = random(68, 10) + 1 + currlevel * 2; } missiledata[MIS_LARROW].mResist = MISR_LIGHTNING; CheckMissileCol(i, mind, maxd, 0, missile[i]._mix, missile[i]._miy, 1); From 2625a952754ce946c4a9ef8c6d8141d99d413254 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 23:58:15 +0100 Subject: [PATCH 07/28] MI_LArrow bin exact suggestion #5 Co-Authored-By: qndel --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 4dd739076..1f3d0bcb2 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3257,7 +3257,7 @@ void __fastcall MI_LArrow(int i) mind = plr[p]._pILMinDam; maxd = plr[p]._pILMaxDam; } else { - mind = random(68, 10) + currlevel + 1; + mind = random(68, 10) + 1 + currlevel; maxd = random(68, 10) + 1 + currlevel * 2; } missiledata[MIS_LARROW].mResist = MISR_LIGHTNING; From 6da659ccc41a7d8a7c11fbc5cc1cb714adf62654 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 23:58:24 +0100 Subject: [PATCH 08/28] MI_LArrow bin exact suggestion #6 Co-Authored-By: qndel --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 1f3d0bcb2..cdb171a1b 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3291,7 +3291,7 @@ void __fastcall MI_LArrow(int i) } } else { mind = random(68, 10) + currlevel + 1; - maxd = random(68, 10) + 2 * currlevel + 1; + maxd = random(68, 10) + 1 + currlevel * 2; } if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) { From 2b493d4d86faf7a3b3b018b760ece48bb44f404f Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 23:58:32 +0100 Subject: [PATCH 09/28] MI_LArrow bin exact suggestion #7 Co-Authored-By: qndel --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index cdb171a1b..2e1ec1f25 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3290,7 +3290,7 @@ void __fastcall MI_LArrow(int i) maxd = monster[p].mMaxDamage; } } else { - mind = random(68, 10) + currlevel + 1; + mind = random(68, 10) + 1 + currlevel; maxd = random(68, 10) + 1 + currlevel * 2; } From 2f7a849eba9bda5b6dd07a9aad0a96e7d5cb2b6a Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Tue, 19 Mar 2019 18:37:08 -0500 Subject: [PATCH 10/28] Cleanup InvDrawSlotBack (#712) --- Source/inv.cpp | 81 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index dc7a2cc6f..e6f2c98f0 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -114,35 +114,60 @@ void __cdecl InitInv() void __fastcall InvDrawSlotBack(int X, int Y, int W, int H) { - unsigned char *v4; // edi - int v5; // edx - int v6; // ecx - unsigned char v7; // al - unsigned char v8; // al - - v4 = (unsigned char *)gpBuffer + screen_y_times_768[Y] + X; - v5 = (unsigned short)H; - do { - v6 = (unsigned short)W; - do { - v7 = *v4; - if (*v4 < 0xB0u) - goto LABEL_9; - if (v7 > 0xBFu) { - if (v7 < 0xF0u) - goto LABEL_9; - v8 = v7 - 80; - } else { - v8 = v7 - 16; + BYTE *dst; + + /// ASSERT: assert(gpBuffer); + + dst = &gpBuffer[X + screen_y_times_768[Y]]; + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov edi, dst + xor edx, edx + xor ebx, ebx + mov dx, word ptr H + mov bx, word ptr W + label1: + mov ecx, ebx + label2: + mov al, [edi] + cmp al, PAL16_BLUE + jb label5 + cmp al, PAL16_BLUE + 15 + ja label3 + sub al, PAL16_BLUE - PAL16_BEIGE + jmp label4 + label3: + cmp al, PAL16_GRAY + jb label5 + sub al, PAL16_GRAY - PAL16_BEIGE + label4: + mov [edi], al + label5: + inc edi + loop label2 + sub edi, 768 + sub edi, ebx + dec edx + jnz label1 + } +#else + int wdt, hgt; + BYTE pix; + + for(hgt = H; hgt; hgt--, dst -= 768 + W) { + for(wdt = W; wdt; wdt--) { + pix = *dst; + if(pix >= PAL16_BLUE) { + if(pix <= PAL16_BLUE + 15) + pix -= PAL16_BLUE - PAL16_BEIGE; + else if(pix >= PAL16_GRAY) + pix -= PAL16_GRAY - PAL16_BEIGE; } - *v4 = v8; - LABEL_9: - ++v4; - --v6; - } while (v6); - v4 = &v4[-(unsigned short)W - 768]; - --v5; - } while (v5); + *dst++ = pix; + } + } +#endif } void __cdecl DrawInv() From afe4d4d3a9b648a279b6be09f39ce9f5df466104 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Tue, 19 Mar 2019 18:37:22 -0500 Subject: [PATCH 11/28] Clean Control.cpp asm funcs (#707) --- Source/control.cpp | 331 +++++++++++++++++++++++++++++---------------- Source/control.h | 10 +- 2 files changed, 223 insertions(+), 118 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 632f9e27a..25fc99a72 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -21,15 +21,15 @@ BOOL chrbtnactive; char sgszTalkMsg[80]; BYTE *pPanelText; int frame_4B8800; // idb -char *pLifeBuff; -void *pBtmBuff; +BYTE *pLifeBuff; +BYTE *pBtmBuff; void *pTalkBtns; int pstrjust[4]; int pnumlines; // idb BOOL pinfoflag; int talkbtndown[3]; int pSpell; // weak -char *pManaBuff; +BYTE *pManaBuff; int infoclr; // weak int sgbPlrTalkTbl; // weak // should be char [4] void *pGBoxBuff; @@ -959,76 +959,155 @@ void __cdecl ClearPanel() void __fastcall DrawPanelBox(int x, int y, int w, int h, int sx, int sy) { - char *v6; // esi - char *v7; // edi - int v8; // edx - unsigned int v9; // ecx - char v10; // cf - unsigned int v11; // ecx + int nSrcOff, nDstOff; - v6 = (char *)pBtmBuff + 640 * y + x; - v7 = (char *)&gpBuffer[768 * sy + sx]; - v8 = h; - do { - v9 = w >> 1; - if (!(w & 1) || (*v7 = *v6, ++v6, ++v7, v9)) { - v10 = v9 & 1; - v11 = w >> 2; - if (!v10 || (*(_WORD *)v7 = *(_WORD *)v6, v6 += 2, v7 += 2, v11)) { - qmemcpy(v7, v6, 4 * v11); - v6 += 4 * v11; - v7 += 4 * v11; - } + /// ASSERT: assert(gpBuffer); + + nSrcOff = x + 640 * y; + nDstOff = sx + 768 * sy; + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, pBtmBuff + add esi, nSrcOff + mov edi, gpBuffer + add edi, nDstOff + xor ebx, ebx + mov bx, word ptr w + xor edx, edx + mov dx, word ptr h + label1: + mov ecx, ebx + shr ecx, 1 + jnb label2 + movsb + jecxz label4 + label2: + shr ecx, 1 + jnb label3 + movsw + jecxz label4 + label3: + rep movsd + label4: + add esi, 640 + sub esi, ebx + add edi, 768 + sub edi, ebx + dec edx + jnz label1 + } +#else + int wdt, hgt; + BYTE *src, *dst; + + src = &pBtmBuff[nSrcOff]; + dst = &gpBuffer[nDstOff]; + + for(hgt = h; hgt; hgt--, src += 640 - w, dst += 768 - w) { + wdt = w; + if(wdt & 1) { + dst[0] = src[0]; + src++; + dst++; + } + wdt >>= 1; + if(wdt & 1) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 2; + dst += 2; } - v6 = &v6[-w + 640]; - v7 = &v7[-w + 768]; - --v8; - } while (v8); + wdt >>= 1; + while(wdt) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + src += 4; + dst += 4; + wdt--; + } + } +#endif } -void __fastcall SetFlaskHeight(char *buf, int min, int max, int c, int r) +void __fastcall SetFlaskHeight(BYTE *pCelBuff, int min, int max, int c, int r) { - char *v5; // esi - char *v6; // edi - int v7; // edx + int nSrcOff, nDstOff, w; - v5 = &buf[88 * min]; - v6 = (char *)&gpBuffer[768 * r + c]; - v7 = max - min; - do { - qmemcpy(v6, v5, 0x58u); - v5 += 88; - v6 += 768; - --v7; - } while (v7); -} - -void __fastcall DrawFlask(void *a1, int a2, int a3, void *a4, int a5, int a6) -{ - char *v6; // esi - _BYTE *v7; // edi - int v8; // edx - signed int v9; // ecx - char v10; // al - int v11; // [esp+Ch] [ebp-4h] - - v11 = a2; - v6 = (char *)a1 + a3; - v7 = (unsigned char *)a4 + a5; - v8 = a6; - do { - v9 = 59; - do { - v10 = *v6++; - if (v10) - *v7 = v10; - ++v7; - --v9; - } while (v9); - v6 = &v6[v11 - 59]; - v7 += 709; - --v8; - } while (v8); + /// ASSERT: assert(gpBuffer); + + nSrcOff = 88 * min; + nDstOff = c + 768 * r; + w = max - min; + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, pCelBuff + add esi, nSrcOff + mov edi, gpBuffer + add edi, nDstOff + mov edx, w + label1: + mov ecx, 88 / 4 + rep movsd + add edi, 768 - 88 + dec edx + jnz label1 + } +#else + BYTE *src, *dst; + + src = &pCelBuff[nSrcOff]; + dst = &gpBuffer[nDstOff]; + + for(; w; w--, src += 88, dst += 768) + memcpy(dst, src, 88); +#endif +} + +void __fastcall DrawFlask(BYTE *pCelBuff, int w, int nSrcOff, BYTE *pBuff, int nDstOff, int h) +{ +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, pCelBuff + add esi, nSrcOff + mov edi, pBuff + add edi, nDstOff + mov edx, h + label1: + mov ecx, 59 + label2: + lodsb + or al, al + jz label3 + mov [edi], al + label3: + inc edi + loop label2 + add esi, w + sub esi, 59 + add edi, 768 - 59 + dec edx + jnz label1 + } +#else + int wdt, hgt; + BYTE *src, *dst; + + src = &pCelBuff[nSrcOff]; + dst = &pBuff[nDstOff]; + + for(hgt = h; hgt; hgt--, src += w - 59, dst += 768 - 59) { + for(wdt = 59; wdt; wdt--) { + if(*src) + *dst = *src; + src++; + dst++; + } + } +#endif } void __cdecl DrawLifeFlask() @@ -1135,9 +1214,9 @@ void __cdecl InitControlPan() v0 = 288 * 640; pBtmBuff = DiabloAllocPtr(v0); memset(pBtmBuff, 0, v0); - pManaBuff = (char *)DiabloAllocPtr(0x1E40); + pManaBuff = DiabloAllocPtr(0x1E40); memset(pManaBuff, 0, 0x1E40); - pLifeBuff = (char *)DiabloAllocPtr(0x1E40); + pLifeBuff = DiabloAllocPtr(0x1E40); memset(pLifeBuff, 0, 0x1E40); pPanelText = LoadFileInMem("CtrlPan\\SmalText.CEL", 0); pChrPanel = LoadFileInMem("Data\\Char.CEL", 0); @@ -2361,52 +2440,78 @@ LABEL_18: void __cdecl RedBack() { - int v0; // eax - char *v1; // edi - signed int v3; // edx - signed int v4; // ecx - char *v7; // edi - signed int v9; // edx - signed int v10; // ecx - int v12; // [esp+8h] [ebp-4h] - int _EAX; - char *_EBX; - - v0 = -(light4flag != 0); - _LOWORD(v0) = v0 & 0xF400; - v12 = v0 + 768 * 6; - if (leveltype == DTYPE_HELL) { - v7 = (char *)&gpBuffer[SCREENXY(0, 0)]; - _EBX = &pLightTbl[v12]; - v9 = 352; - do { - v10 = 640; - do { - _EAX = *v7; - if ((unsigned char)*v7 >= 32) - ASM_XLAT(_EAX, _EBX); - *v7++ = _EAX; - --v10; - } while (v10); - v7 += 128; - --v9; - } while (v9); + int idx; + + idx = light4flag ? 1536 : 4608; + + /// ASSERT: assert(gpBuffer); + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + if(leveltype != DTYPE_HELL) { + __asm { + mov edi, gpBuffer + add edi, SCREENXY(0, 0) + mov ebx, pLightTbl + add ebx, idx + mov edx, 352 + lx_label1: + mov ecx, 640 + lx_label2: + mov al, [edi] + xlat + stosb + loop lx_label2 + add edi, 768 - 640 + dec edx + jnz lx_label1 + } } else { - v1 = (char *)&gpBuffer[SCREENXY(0, 0)]; - _EBX = &pLightTbl[v12]; - v3 = 352; - do { - v4 = 640; - do { - _EAX = *v1; - ASM_XLAT(_EAX, _EBX); - *v1++ = _EAX; - --v4; - } while (v4); - v1 += 128; - --v3; - } while (v3); + __asm { + mov edi, gpBuffer + add edi, SCREENXY(0, 0) + mov ebx, pLightTbl + add ebx, idx + mov edx, 352 + l4_label1: + mov ecx, 640 + l4_label2: + mov al, [edi] + cmp al, 32 + jb l4_label3 + xlat + l4_label3: + stosb + loop l4_label2 + add edi, 768 - 640 + dec edx + jnz l4_label1 + } } +#else + int w, h; + BYTE *dst, *tbl; + + if(leveltype != DTYPE_HELL) { + dst = &gpBuffer[SCREENXY(0, 0)]; + tbl = (BYTE *)&pLightTbl[idx]; + for(h = 352; h; h--, dst += 768 - 640) { + for(w = 640; w; w--) { + *dst = tbl[*dst]; + dst++; + } + } + } else { + dst = &gpBuffer[SCREENXY(0, 0)]; + tbl = (BYTE *)&pLightTbl[idx]; + for(h = 352; h; h--, dst += 768 - 640) { + for(w = 640; w; w--) { + if(*dst >= 32) + *dst = tbl[*dst]; + dst++; + } + } + } +#endif } // 525728: using guessed type int light4flag; diff --git a/Source/control.h b/Source/control.h index 878490e75..d388d6c80 100644 --- a/Source/control.h +++ b/Source/control.h @@ -17,15 +17,15 @@ extern BOOL drawmanaflag; // idb extern BOOL chrbtnactive; extern BYTE *pPanelText; extern int frame_4B8800; // idb -extern char *pLifeBuff; -extern void *pBtmBuff; +extern BYTE *pLifeBuff; +extern BYTE *pBtmBuff; extern void *pTalkBtns; extern int pstrjust[4]; extern int pnumlines; // idb extern BOOL pinfoflag; extern int talkbtndown[3]; extern int pSpell; // weak -extern char *pManaBuff; +extern BYTE *pManaBuff; extern int infoclr; // weak extern void *pGBoxBuff; extern void *pSBkBtnCel; @@ -65,8 +65,8 @@ void __fastcall AddPanelString(char *str, BOOL just); void __cdecl ClearPanel(); void __fastcall DrawPanelBox(int x, int y, int w, int h, int sx, int sy); void __cdecl InitPanelStr(); -void __fastcall SetFlaskHeight(char *buf, int min, int max, int c, int r); -void __fastcall DrawFlask(void *a1, int a2, int a3, void *a4, int a5, int a6); +void __fastcall SetFlaskHeight(BYTE *pCelBuff, int min, int max, int c, int r); +void __fastcall DrawFlask(BYTE *pCelBuff, int w, int nSrcOff, BYTE *pBuff, int nDstOff, int h); void __cdecl DrawLifeFlask(); void __cdecl UpdateLifeFlask(); void __cdecl DrawManaFlask(); From 8d1ee9854acc99264982edc7240f9b71f809c16f Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 20 Mar 2019 01:32:30 +0100 Subject: [PATCH 12/28] AddChain bin exact (#718) --- Source/missiles.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index e9d13664d..3a6eefef8 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2290,12 +2290,9 @@ void __fastcall AddGuardian(int mi, int sx, int sy, int dx, int dy, int midir, i void __fastcall AddChain(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - int v9; // ecx - - v9 = mi; - missile[v9]._miVar1 = dx; - missile[v9]._miVar2 = dy; - missile[v9]._mirange = 1; + missile[mi]._miVar1 = dx; + missile[mi]._miVar2 = dy; + missile[mi]._mirange = 1; UseMana(id, 14); } From 2f1937c29d2af111ab25726e7daf2d63c0a91b2e Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 20 Mar 2019 01:32:56 +0100 Subject: [PATCH 13/28] miss_null_11 bin exact (#717) --- Source/missiles.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 3a6eefef8..254cadf40 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2298,15 +2298,10 @@ void __fastcall AddChain(int mi, int sx, int sy, int dx, int dy, int midir, int void __fastcall miss_null_11(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - int v9; // esi - int v10; // eax - - v9 = mi; SetMissDir(mi, dx); - v10 = v9; - missile[v10]._midam = 0; - missile[v10]._miLightFlag = TRUE; - missile[v10]._mirange = 250; + missile[mi]._midam = 0; + missile[mi]._miLightFlag = TRUE; + missile[mi]._mirange = 250; } void __fastcall miss_null_12(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) From 550478e30f48125f9fc71718817bb599c9492d91 Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 20 Mar 2019 01:33:20 +0100 Subject: [PATCH 14/28] miss_null_12 bin exact (#716) --- Source/missiles.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 254cadf40..8cec36474 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2306,19 +2306,12 @@ void __fastcall miss_null_11(int mi, int sx, int sy, int dx, int dy, int midir, void __fastcall miss_null_12(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - signed int v9; // edx - int v10; // esi - int v11; // eax - - v9 = dx; - v10 = mi; if (dx > 3) - v9 = 2; - SetMissDir(mi, v9); - v11 = v10; - missile[v11]._midam = 0; - missile[v11]._miLightFlag = TRUE; - missile[v11]._mirange = 250; + dx = 2; + SetMissDir(mi, dx); + missile[mi]._midam = 0; + missile[mi]._miLightFlag = TRUE; + missile[mi]._mirange = 250; } void __fastcall miss_null_13(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) From 49b15022869bba88ad706c409b481628ca313274 Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 20 Mar 2019 01:33:40 +0100 Subject: [PATCH 15/28] miss_null_13 bin exact (#715) --- Source/missiles.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 8cec36474..b8344db28 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2316,21 +2316,12 @@ void __fastcall miss_null_12(int mi, int sx, int sy, int dx, int dy, int midir, void __fastcall miss_null_13(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - signed int v9; // edx - int v10; // esi - int v11; // eax - int v12; // ecx - - v9 = dx; - v10 = mi; if (dx > 3) - v9 = 2; - SetMissDir(mi, v9); - v11 = v10; - v12 = missile[v10]._miAnimLen; - missile[v11]._midam = 0; - missile[v11]._miLightFlag = TRUE; - missile[v11]._mirange = v12; + dx = 2; + SetMissDir(mi, dx); + missile[mi]._midam = 0; + missile[mi]._miLightFlag = TRUE; + missile[mi]._mirange = missile[mi]._miAnimLen; } void __fastcall AddRhino(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) From 046e9a43e428df094773fb947bcf220f5d6b8081 Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 20 Mar 2019 01:34:04 +0100 Subject: [PATCH 16/28] miss_null_1D bin exact (#714) --- Source/missiles.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index b8344db28..46c31691e 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2428,17 +2428,12 @@ void __fastcall AddAcid(int mi, int sx, int sy, int dx, int dy, int midir, int m void __fastcall miss_null_1D(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - int v9; // ecx - int v10; // eax - - v9 = mi; - missile[v9]._midam = dam; - missile[v9]._mirange = 50; - v10 = 50 - missile[v9]._miAnimLen; - missile[v9]._mixvel = 0; - missile[v9]._miyvel = 0; - missile[v9]._miVar1 = v10; - missile[v9]._miVar2 = 0; + missile[mi]._midam = dam; + missile[mi]._mirange = 50; + missile[mi]._mixvel = 0; + missile[mi]._miyvel = 0; + missile[mi]._miVar1 = 50 - missile[mi]._miAnimLen; + missile[mi]._miVar2 = 0; } void __fastcall AddAcidpud(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) From 9867db34c0518ef87a9232974512d20c755f601c Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 20 Mar 2019 01:34:30 +0100 Subject: [PATCH 17/28] AddAcidpud bin exact (#713) --- Source/missiles.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 46c31691e..6fc77c28b 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2438,20 +2438,16 @@ void __fastcall miss_null_1D(int mi, int sx, int sy, int dx, int dy, int midir, void __fastcall AddAcidpud(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - int v9; // esi - int v10; // edi - int v11; // eax + int monst; - v9 = mi; - v10 = missile[mi]._misource; - missile[v9]._mixvel = 0; - missile[v9]._miyvel = 0; - missile[v9]._mixoff = 0; - missile[v9]._miyoff = 0; - missile[v9]._miLightFlag = TRUE; - v11 = random(50, 15); - missile[v9]._miPreFlag = TRUE; - missile[v9]._mirange = v11 + 40 * ((unsigned char)monster[v10]._mint + 1); + monst = missile[mi]._misource; + missile[mi]._mixvel = 0; + missile[mi]._miyvel = 0; + missile[mi]._mixoff = 0; + missile[mi]._miyoff = 0; + missile[mi]._miLightFlag = TRUE; + missile[mi]._mirange = random(50, 15) + 40 * (monster[monst]._mint + 1); + missile[mi]._miPreFlag = TRUE; } void __fastcall AddStone(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) From f3d570135d0af23e8f5444a2d2804c81ad2add6f Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 20 Mar 2019 01:39:35 +0100 Subject: [PATCH 18/28] AddRportal bin exact (#711) --- Source/missiles.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 6fc77c28b..ff727a31f 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3036,18 +3036,13 @@ void __fastcall AddBoneSpirit(int mi, int sx, int sy, int dx, int dy, int midir, void __fastcall AddRportal(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - int v9; // eax - int v10; // edx - - v9 = mi; - missile[v9]._miVar2 = 0; - missile[v9]._mix = sx; - missile[v9]._misx = sx; - missile[v9]._mirange = 100; - v10 = 100 - missile[mi]._miAnimLen; - missile[v9]._miy = sy; - missile[v9]._misy = sy; - missile[v9]._miVar1 = v10; + missile[mi]._mix = sx; + missile[mi]._miy = sy; + missile[mi]._misx = sx; + missile[mi]._misy = sy; + missile[mi]._miVar1 = 100 - missile[mi]._miAnimLen; + missile[mi]._miVar2 = 0; + missile[mi]._mirange = 100; PutMissile(mi); } From b10b206efddf12124a2d24cff48b689183cbd98e Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Wed, 20 Mar 2019 20:19:44 -0500 Subject: [PATCH 19/28] Cleanup DRLG Pass3 (#719) --- Source/drlg_l2.cpp | 151 +++++++++++++++++++++------------------ Source/drlg_l3.cpp | 172 +++++++++++++++++++++++--------------------- Source/drlg_l4.cpp | 174 ++++++++++++++++++++++++--------------------- 3 files changed, 265 insertions(+), 232 deletions(-) diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index 6eb128e1b..2166b38b3 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -521,77 +521,86 @@ void __fastcall LoadL2Dungeon(char *sFileName, int vx, int vy) void __cdecl DRLG_L2Pass3() { - int v0; // eax - int *v1; // edx - int *v2; // eax - signed int v3; // ecx - signed int v4; // ebx - int *v5; // ecx - unsigned char *v6; // edx - unsigned short *v7; // esi - unsigned short v8; // ax - int v9; // eax - int v10; // ST24_4 - int v11; // ST20_4 - int v12; // ST1C_4 - signed int v13; // [esp+Ch] [ebp-1Ch] - int *v14; // [esp+10h] [ebp-18h] - int v15; // [esp+14h] [ebp-14h] - int v16; // [esp+18h] [ebp-10h] - int v17; // [esp+1Ch] [ebp-Ch] - int v18; // [esp+20h] [ebp-8h] - - v0 = *((unsigned short *)pMegaTiles + 44) + 1; - v18 = *((unsigned short *)pMegaTiles + 44) + 1; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 45); - v17 = ++v0; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 46); - v16 = ++v0; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 47); - v15 = v0 + 1; - v1 = dPiece[1]; - do { - v2 = v1; - v3 = 56; - do { - *(v2 - 112) = v18; - *v2 = v17; - *(v2 - 111) = v16; - v2[1] = v15; - v2 += 224; - --v3; - } while (v3); - v1 += 2; - } while ((signed int)v1 < (signed int)dPiece[2]); - v4 = 0; - v14 = &dPiece[17][16]; - do { - v5 = v14; - v6 = (unsigned char *)dungeon + v4; - v13 = 40; - do { - v7 = (unsigned short *)((char *)pMegaTiles + 8 * (*v6 - 1)); - v8 = *v7; - ++v7; - v9 = v8 + 1; - v10 = v9; - _LOWORD(v9) = *v7; - ++v7; - v11 = ++v9; - _LOWORD(v9) = *v7; - v12 = ++v9; - _LOWORD(v9) = v7[1]; - v6 += 40; - *(v5 - 112) = v10; - *v5 = v11; - *(v5 - 111) = v12; - v5[1] = v9 + 1; - v5 += 224; - --v13; - } while (v13); - v14 += 2; - ++v4; - } while (v4 < 40); + int i, j, xx, yy; + long v1, v2, v3, v4, lv; + + lv = 12-1; + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } +#else + v1 = *((WORD *)&pMegaTiles[lv*8])+1; + v2 = *((WORD *)&pMegaTiles[lv*8]+1)+1; + v3 = *((WORD *)&pMegaTiles[lv*8]+2)+1; + v4 = *((WORD *)&pMegaTiles[lv*8]+3)+1; +#endif + + for(j = 0; j < MAXDUNY; j += 2) { + for(i = 0; i < MAXDUNX; i += 2) { + dPiece[i][j] = v1; + dPiece[i+1][j] = v2; + dPiece[i][j+1] = v3; + dPiece[i+1][j+1] = v4; + } + } + + yy = 16; + for(j = 0; j < DMAXY; j++) { + xx = 16; + for(i = 0; i < DMAXX; i++) { + lv = (unsigned char)dungeon[i][j]-1; +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } +#else + v1 = *((WORD *)&pMegaTiles[lv*8])+1; + v2 = *((WORD *)&pMegaTiles[lv*8]+1)+1; + v3 = *((WORD *)&pMegaTiles[lv*8]+2)+1; + v4 = *((WORD *)&pMegaTiles[lv*8]+3)+1; +#endif + dPiece[xx][yy] = v1; + dPiece[xx+1][yy] = v2; + dPiece[xx][yy+1] = v3; + dPiece[xx+1][yy+1] = v4; + xx += 2; + } + yy += 2; + } } void __fastcall LoadPreL2Dungeon(char *sFileName, int vx, int vy) diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index bea47fd4c..8cce4b5f5 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -2334,88 +2334,100 @@ BOOLEAN __fastcall WoodHorizR(int x, int j) void __cdecl DRLG_L3Pass3() { - int v0; // eax - int *v1; // esi - int *v2; // eax - signed int v3; // ecx - signed int v4; // ebx - int *v5; // ecx - unsigned char *v6; // edi - unsigned short *v7; // esi - unsigned short v8; // ax - int v9; // eax - signed int v10; // [esp+Ch] [ebp-1Ch] - int *v11; // [esp+10h] [ebp-18h] - int v12; // [esp+14h] [ebp-14h] - int v13; // [esp+18h] [ebp-10h] - int v14; // [esp+18h] [ebp-10h] - int v15; // [esp+1Ch] [ebp-Ch] - int v16; // [esp+1Ch] [ebp-Ch] - int v17; // [esp+20h] [ebp-8h] - int v18; // [esp+20h] [ebp-8h] - int v19; // [esp+24h] [ebp-4h] - int v20; // [esp+24h] [ebp-4h] - - v0 = *((unsigned short *)pMegaTiles + 28) + 1; - v19 = *((unsigned short *)pMegaTiles + 28) + 1; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 29); - v17 = ++v0; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 30); - v15 = ++v0; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 31); - v13 = v0 + 1; - v1 = dPiece[1]; - do { - v2 = v1; - v3 = 56; - do { - *(v2 - 112) = v19; - *v2 = v17; - *(v2 - 111) = v15; - v2[1] = v13; - v2 += 224; - --v3; - } while (v3); - v1 += 2; - } while ((signed int)v1 < (signed int)dPiece[2]); - v4 = 0; - v11 = &dPiece[17][16]; - do { - v5 = v11; - v6 = (unsigned char *)dungeon + v4; - v10 = 40; - do { - v12 = *v6 - 1; - if (v12 < 0) { - v20 = 0; - v18 = 0; - v16 = 0; - v14 = 0; + int i, j, xx, yy; + long v1, v2, v3, v4, lv; + + lv = 8-1; + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } +#else + v1 = *((WORD *)&pMegaTiles[lv*8])+1; + v2 = *((WORD *)&pMegaTiles[lv*8]+1)+1; + v3 = *((WORD *)&pMegaTiles[lv*8]+2)+1; + v4 = *((WORD *)&pMegaTiles[lv*8]+3)+1; +#endif + + for(j = 0; j < MAXDUNY; j += 2) { + for(i = 0; i < MAXDUNX; i += 2) { + dPiece[i][j] = v1; + dPiece[i+1][j] = v2; + dPiece[i][j+1] = v3; + dPiece[i+1][j+1] = v4; + } + } + + yy = 16; + for(j = 0; j < DMAXY; j++) { + xx = 16; + for(i = 0; i < DMAXX; i++) { + lv = (unsigned char)dungeon[i][j]-1; +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + if(lv >= 0) { + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } } else { - v7 = (unsigned short *)((char *)pMegaTiles + 8 * v12); - v8 = *v7; - ++v7; - v9 = v8 + 1; - v20 = v9; - _LOWORD(v9) = *v7; - ++v7; - v18 = ++v9; - _LOWORD(v9) = *v7; - v16 = ++v9; - _LOWORD(v9) = v7[1]; - v14 = v9 + 1; + v1 = 0; + v2 = 0; + v3 = 0; + v4 = 0; } - v6 += 40; - *(v5 - 112) = v20; - *v5 = v18; - *(v5 - 111) = v16; - v5[1] = v14; - v5 += 224; - --v10; - } while (v10); - v11 += 2; - ++v4; - } while (v4 < 40); +#else + if(lv >= 0) { + v1 = *((WORD *)&pMegaTiles[lv*8])+1; + v2 = *((WORD *)&pMegaTiles[lv*8]+1)+1; + v3 = *((WORD *)&pMegaTiles[lv*8]+2)+1; + v4 = *((WORD *)&pMegaTiles[lv*8]+3)+1; + } else { + v1 = 0; + v2 = 0; + v3 = 0; + v4 = 0; + } +#endif + dPiece[xx][yy] = v1; + dPiece[xx+1][yy] = v2; + dPiece[xx][yy+1] = v3; + dPiece[xx+1][yy+1] = v4; + xx += 2; + } + yy += 2; + } } void __fastcall LoadL3Dungeon(char *sFileName, int vx, int vy) diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index ab88f182f..69c0fd740 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -2856,86 +2856,98 @@ void __cdecl DRLG_L4Corners() void __cdecl DRLG_L4Pass3() { - int v0; // eax - int *v1; // esi - int *v2; // eax - signed int v3; // ecx - signed int v4; // ebx - int *v5; // ecx - unsigned char *v6; // edi - unsigned short *v7; // esi - unsigned short v8; // ax - int v9; // eax - signed int v10; // [esp+Ch] [ebp-1Ch] - int *v11; // [esp+10h] [ebp-18h] - int v12; // [esp+14h] [ebp-14h] - int v13; // [esp+18h] [ebp-10h] - int v14; // [esp+18h] [ebp-10h] - int v15; // [esp+1Ch] [ebp-Ch] - int v16; // [esp+1Ch] [ebp-Ch] - int v17; // [esp+20h] [ebp-8h] - int v18; // [esp+20h] [ebp-8h] - int v19; // [esp+24h] [ebp-4h] - int v20; // [esp+24h] [ebp-4h] - - v0 = *((unsigned short *)pMegaTiles + 116) + 1; - v19 = *((unsigned short *)pMegaTiles + 116) + 1; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 117); - v17 = ++v0; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 118); - v15 = ++v0; - _LOWORD(v0) = *((_WORD *)pMegaTiles + 119); - v13 = v0 + 1; - v1 = dPiece[1]; - do { - v2 = v1; - v3 = 56; - do { - *(v2 - 112) = v19; - *v2 = v17; - *(v2 - 111) = v15; - v2[1] = v13; - v2 += 224; - --v3; - } while (v3); - v1 += 2; - } while ((signed int)v1 < (signed int)dPiece[2]); - v4 = 0; - v11 = &dPiece[17][16]; - do { - v5 = v11; - v6 = (unsigned char *)dungeon + v4; - v10 = 40; - do { - v12 = *v6 - 1; - if (v12 < 0) { - v20 = 0; - v18 = 0; - v16 = 0; - v14 = 0; + int i, j, xx, yy; + long v1, v2, v3, v4, lv; + + lv = 30-1; + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } +#else + v1 = *((WORD *)&pMegaTiles[lv*8])+1; + v2 = *((WORD *)&pMegaTiles[lv*8]+1)+1; + v3 = *((WORD *)&pMegaTiles[lv*8]+2)+1; + v4 = *((WORD *)&pMegaTiles[lv*8]+3)+1; +#endif + + for(j = 0; j < MAXDUNY; j += 2) { + for(i = 0; i < MAXDUNX; i += 2) { + dPiece[i][j] = v1; + dPiece[i+1][j] = v2; + dPiece[i][j+1] = v3; + dPiece[i+1][j+1] = v4; + } + } + + yy = 16; + for(j = 0; j < DMAXY; j++) { + xx = 16; + for(i = 0; i < DMAXX; i++) { + lv = (unsigned char)dungeon[i][j]-1; +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + if(lv >= 0) { + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } } else { - v7 = (unsigned short *)((char *)pMegaTiles + 8 * v12); - v8 = *v7; - ++v7; - v9 = v8 + 1; - v20 = v9; - _LOWORD(v9) = *v7; - ++v7; - v18 = ++v9; - _LOWORD(v9) = *v7; - v16 = ++v9; - _LOWORD(v9) = v7[1]; - v14 = v9 + 1; - } - v6 += 40; - *(v5 - 112) = v20; - *v5 = v18; - *(v5 - 111) = v16; - v5[1] = v14; - v5 += 224; - --v10; - } while (v10); - v11 += 2; - ++v4; - } while (v4 < 40); + v1 = 0; + v2 = 0; + v3 = 0; + v4 = 0; + } +#else + if(lv >= 0) { + v1 = *((WORD *)&pMegaTiles[lv*8])+1; + v2 = *((WORD *)&pMegaTiles[lv*8]+1)+1; + v3 = *((WORD *)&pMegaTiles[lv*8]+2)+1; + v4 = *((WORD *)&pMegaTiles[lv*8]+3)+1; + } else { + v1 = 0; + v2 = 0; + v3 = 0; + v4 = 0; + } +#endif + dPiece[xx][yy] = v1; + dPiece[xx+1][yy] = v2; + dPiece[xx][yy+1] = v3; + dPiece[xx+1][yy+1] = v4; + xx += 2; + } + yy += 2; + } } From 1c8cadc26d6824a3726183240ce6b3e1ac32d7f8 Mon Sep 17 00:00:00 2001 From: JustAnotherGuid <46401660+JustAnotherGuid@users.noreply.github.com> Date: Thu, 21 Mar 2019 02:34:01 +0100 Subject: [PATCH 20/28] S_StartSBuy [request for feedback] (#668) --- Source/stores.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/Source/stores.cpp b/Source/stores.cpp index 74957f67b..752b286d3 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -701,33 +701,23 @@ void __fastcall PrintStoreItem(ItemStruct *x, int l, char iclr) void __cdecl S_StartSBuy() { - int v0; // ST10_4 - int v1; // eax - int *v2; // ecx + int i; - v0 = plr[myplr]._pGold; stextsize = 1; stextscrl = 1; stextsval = 0; - sprintf(tempstr, "I have these items for sale : Your gold : %i", v0); - AddSText(0, 1, 1u, tempstr, COL_GOLD, 0); + sprintf(tempstr, "I have these items for sale : Your gold : %i", plr[myplr]._pGold); + AddSText(0, 1, 1, tempstr, COL_GOLD, 0); AddSLine(3); AddSLine(21); S_ScrollSBuy(stextsval); - AddSText(0, 22, 1u, "Back", COL_WHITE, 0); + AddSText(0, 22, 1, "Back", COL_WHITE, 0); OffsetSTextY(22, 6); - v1 = 0; storenumh = 0; - if (smithitem[0]._itype != -1) { - v2 = &smithitem[0]._itype; - do { - v2 += 92; - ++v1; - } while (*v2 != -1); - storenumh = v1; - } - stextsmax = v1 - 4; - if (v1 - 4 < 0) + for (i = 0; smithitem[i]._itype != -1; i++) + storenumh++; + stextsmax = storenumh - 4; + if (stextsmax < 0) stextsmax = 0; } // 69F10C: using guessed type int storenumh; From 6b2e87064df278e4fc3ca769d0d9798c27d9c4e7 Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 20 Mar 2019 00:10:11 +0100 Subject: [PATCH 21/28] Sentfire bin exact --- Source/missiles.cpp | 46 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index ff727a31f..20342815e 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3128,41 +3128,21 @@ int __fastcall AddMissile(int sx, int sy, int dx, int dy, int midir, int mitype, int __fastcall Sentfire(int i, int sx, int sy) { - int v3; // esi - int v4; // ebx - int v5; // edi - //int v6; // eax - int v7; // eax - int v8; // eax - int v9; // edi - int midir; // ST30_4 - int v11; // ecx - int v12; // eax - //int v13; // edx - int mi; // [esp+Ch] [ebp-8h] - - mi = i; - v3 = i; - v4 = sx; - v5 = 0; - //_LOBYTE(v6) = LineClear(missile[i]._mix, missile[i]._miy, sx, sy); + int ex, dir; + + ex = 0; if (LineClear(missile[i]._mix, missile[i]._miy, sx, sy)) { - v7 = dMonster[v4][sy]; - if (v7 > 0 && monster[v7 - 1]._mhitpoints >> 6 > 0 && v7 - 1 > 3) /* fix monstactive */ - { - v8 = GetDirection(missile[v3]._mix, missile[v3]._miy, v4, sy); - v9 = missile[v3]._misource; - midir = v8; - v11 = missile[v3]._misource; - missile[v3]._miVar3 = missileavail[0]; - v12 = GetSpellLevel(v11, 1); - AddMissile(missile[v3]._mix, missile[v3]._miy, v4, sy, midir, MIS_FIREBOLT, 0, v9, missile[v3]._midam, v12); /* check mtype v13 */ - v5 = -1; - SetMissDir(mi, 2); - missile[v3]._miVar2 = 3; + if (dMonster[sx][sy] > 0 && monster[dMonster[sx][sy] - 1]._mhitpoints >> 6 > 0 && dMonster[sx][sy] - 1 > 3) { + dir = GetDirection(missile[i]._mix, missile[i]._miy, sx, sy); + missile[i]._miVar3 = missileavail[0]; + AddMissile(missile[i]._mix, missile[i]._miy, sx, sy, dir, MIS_FIREBOLT, 0, missile[i]._misource, missile[i]._midam, GetSpellLevel(missile[i]._misource, 1)); + ex = -1; + SetMissDir(i, 2); + missile[i]._miVar2 = 3; } } - return v5; + + return ex; } void __fastcall MI_Dummy(int i) @@ -4764,7 +4744,7 @@ void __fastcall MI_Flamec(int i) void __fastcall MI_Cbolt(int i) { - int sx, sy, dy, md; + int md; int bpath[16] = { -1, 0, 1, -1, 0, 1, -1, -1, 0, 0, 1, 1, 0, 1, -1, 0 }; missile[i]._mirange--; From 7c92fbd06bf0e3dbbc45633014e8c3b4d2d5d568 Mon Sep 17 00:00:00 2001 From: qndel Date: Thu, 21 Mar 2019 13:36:46 +0100 Subject: [PATCH 22/28] MI_Rhino bin exact (#721) --- Source/missiles.cpp | 93 ++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 57 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 20342815e..d33dd2085 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -4301,69 +4301,48 @@ void __fastcall MI_Boom(int i) void __fastcall MI_Rhino(int i) { - int v1; // ebx - int v2; // esi - int v3; // edi - int v4; // edi - int v5; // eax - int v6; // eax - int v7; // ebx - BOOLEAN v8; // zf - int x; // [esp+Ch] [ebp-1Ch] - int v10; // [esp+10h] [ebp-18h] - int y; // [esp+14h] [ebp-14h] - int a2; // [esp+18h] [ebp-10h] - int a3; // [esp+1Ch] [ebp-Ch] - int arglist; // [esp+20h] [ebp-8h] - int a1; // [esp+24h] [ebp-4h] + int mix, miy, mix2, miy2, omx, omy, monst; - v1 = i; - v2 = i; - arglist = i; - v3 = missile[i]._misource; - a1 = v3; - v4 = v3; - if (monster[v4]._mmode != MM_CHARGE) - goto LABEL_12; + monst = missile[i]._misource; + if (monster[monst]._mmode != MM_CHARGE) { + missile[i]._miDelFlag = TRUE; + return; + } GetMissilePos(i); - v5 = missile[v2]._mix; - x = v5; - v10 = missile[v2]._miy; - dMonster[v5][v10] = 0; - v6 = missile[v2]._mixvel; - if (monster[v4]._mAi == AI_SNAKE) { - missile[v2]._mitxoff += 2 * v6; - missile[v2]._mityoff += 2 * missile[v2]._miyvel; - GetMissilePos(v1); - a2 = missile[v2]._mix; - a3 = missile[v2]._miy; - missile[v2]._mitxoff -= missile[v2]._mixvel; - missile[v2]._mityoff -= missile[v2]._miyvel; + mix = missile[i]._mix; + miy = missile[i]._miy; + dMonster[mix][miy] = 0; + if (monster[monst]._mAi == AI_SNAKE) { + missile[i]._mitxoff += 2 * missile[i]._mixvel; + missile[i]._mityoff += 2 * missile[i]._miyvel; + GetMissilePos(i); + mix2 = missile[i]._mix; + miy2 = missile[i]._miy; + missile[i]._mitxoff -= missile[i]._mixvel; + missile[i]._mityoff -= missile[i]._miyvel; } else { - missile[v2]._mitxoff += v6; - missile[v2]._mityoff += missile[v2]._miyvel; + missile[i]._mitxoff += missile[i]._mixvel; + missile[i]._mityoff += missile[i]._miyvel; } - GetMissilePos(v1); - v7 = missile[v2]._mix; - y = missile[v2]._miy; - if (!PosOkMonst(a1, missile[v2]._mix, missile[v2]._miy) || monster[v4]._mAi == AI_SNAKE && !PosOkMonst(a1, a2, a3)) { - MissToMonst(arglist, x, v10); - LABEL_12: - missile[v2]._miDelFlag = TRUE; + GetMissilePos(i); + omx = missile[i]._mix; + omy = missile[i]._miy; + if (!PosOkMonst(monst, missile[i]._mix, missile[i]._miy) || (monster[monst]._mAi == AI_SNAKE && !PosOkMonst(monst, mix2, miy2))) { + MissToMonst(i, mix, miy); + missile[i]._miDelFlag = TRUE; return; } - v8 = monster[v4]._uniqtype == 0; - monster[v4]._mfutx = v7; - monster[v4]._moldx = v7; - dMonster[v7][y] = -1 - a1; - monster[v4]._mx = v7; - monster[v4]._mfuty = y; - monster[v4]._moldy = y; - monster[v4]._my = y; - if (!v8) - ChangeLightXY(missile[v2]._mlid, v7, y); - MoveMissilePos(arglist); - PutMissile(arglist); + monster[monst]._mfutx = omx; + monster[monst]._moldx = omx; + dMonster[omx][omy] = -1 - monst; + monster[monst]._mx = omx; + monster[monst]._mfuty = omy; + monster[monst]._moldy = omy; + monster[monst]._my = omy; + if (monster[monst]._uniqtype != 0) + ChangeLightXY(missile[i]._mlid, omx, omy); + MoveMissilePos(i); + PutMissile(i); } void __fastcall mi_null_32(int i) From 287dc74e2fc4e1af8c44a8b86920975dc3b2d4ff Mon Sep 17 00:00:00 2001 From: aperturesecurity Date: Thu, 21 Mar 2019 21:07:12 +0200 Subject: [PATCH 23/28] AddHeal Bin Exact --- Source/missiles.cpp | 68 +++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index d33dd2085..7e99ad780 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2609,50 +2609,38 @@ void __fastcall AddBoom(int mi, int sx, int sy, int dx, int dy, int midir, int m void __fastcall AddHeal(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - int v9; // esi - signed int v10; // ebx - int v12; // edi - int i; // ebx - int v15; // ecx - int *v16; // eax - int *v17; // eax - int v18; // esi - int v19; // [esp+Ch] [ebp-8h] - int v20; // [esp+10h] [ebp-4h] - - v19 = mi; - v9 = id; - v10 = 0; - v12 = (random(57, 10) + 1) << 6; - if (plr[id]._pLevel > 0) { - do { - v12 += (random(57, 4) + 1) << 6; - ++v10; - } while (v10 < plr[v9]._pLevel); - } - v20 = 0; - for (i = v19; v20 < missile[i]._mispllvl; ++v20) { - v12 += (random(57, 6) + 1) << 6; - } - if (plr[v9]._pClass == PC_WARRIOR) - v12 *= 2; - if (plr[v9]._pClass == PC_ROGUE) - v12 += v12 >> 1; - v15 = plr[v9]._pMaxHP; - v16 = &plr[v9]._pHitPoints; - *v16 += v12; - if (plr[v9]._pHitPoints > v15) - *v16 = v15; - v17 = &plr[v9]._pHPBase; - v18 = plr[v9]._pMaxHPBase; - *v17 += v12; - if (*v17 > v18) - *v17 = v18; + int i; + signed int HealAmount = (random(57, 10) + 1) << 6; + for(i = 0 ; i < plr[id]._pLevel ; i++){ + HealAmount += (random(57, 4) + 1) << 6; + } + for (i = 0; i < missile[mi]._mispllvl; i++) { + HealAmount += (random(57, 6) + 1) << 6; + } + + if (plr[id]._pClass == PC_WARRIOR) + HealAmount *= 2; + + if (plr[id]._pClass == PC_ROGUE) + HealAmount += HealAmount >> 1; + + plr[id]._pHitPoints += HealAmount; + if (plr[id]._pHitPoints > plr[id]._pMaxHP) + plr[id]._pHitPoints = plr[id]._pMaxHP; + + plr[id]._pHPBase += HealAmount; + if (plr[id]._pHPBase > plr[id]._pMaxHPBase) + plr[id]._pHPBase = plr[id]._pMaxHPBase; + UseMana(id, 2); - missile[i]._miDelFlag = TRUE; + missile[mi]._miDelFlag = TRUE; drawhpflag = TRUE; } + + + + void __fastcall AddHealOther(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { missile[mi]._miDelFlag = TRUE; From 6c910a445f4daf3c1b924dd01f1fa512b1523c7f Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 21 Mar 2019 20:29:27 +0100 Subject: [PATCH 24/28] Clean up code style --- Source/missiles.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 7e99ad780..efbad33ab 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2609,17 +2609,19 @@ void __fastcall AddBoom(int mi, int sx, int sy, int dx, int dy, int midir, int m void __fastcall AddHeal(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { - int i; - signed int HealAmount = (random(57, 10) + 1) << 6; - for(i = 0 ; i < plr[id]._pLevel ; i++){ + int i; + int HealAmount; + + HealAmount = (random(57, 10) + 1) << 6; + for (i = 0; i < plr[id]._pLevel; i++) { HealAmount += (random(57, 4) + 1) << 6; } for (i = 0; i < missile[mi]._mispllvl; i++) { HealAmount += (random(57, 6) + 1) << 6; } - + if (plr[id]._pClass == PC_WARRIOR) - HealAmount *= 2; + HealAmount += HealAmount; if (plr[id]._pClass == PC_ROGUE) HealAmount += HealAmount >> 1; @@ -2637,10 +2639,6 @@ void __fastcall AddHeal(int mi, int sx, int sy, int dx, int dy, int midir, int m drawhpflag = TRUE; } - - - - void __fastcall AddHealOther(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) { missile[mi]._miDelFlag = TRUE; From 5ed313ad996f02602e768209ff8dbff03bb79236 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Wed, 20 Mar 2019 20:48:39 -0500 Subject: [PATCH 25/28] Cleanup gendung crap --- Source/gendung.cpp | 67 +++++++++++++++++----------------------------- Source/gendung.h | 2 +- 2 files changed, 26 insertions(+), 43 deletions(-) diff --git a/Source/gendung.cpp b/Source/gendung.cpp index a3cf0129c..768715211 100644 --- a/Source/gendung.cpp +++ b/Source/gendung.cpp @@ -417,55 +417,38 @@ void __cdecl gendung_418D91() void __fastcall gendung_4191BF(int frames) { - int v1; // edi - signed int v2; // eax - int i; // esi + int i; + BOOL doneflag; - v1 = frames; - v2 = 0; - while (v1 > 0 && !v2) { - v2 = 1; - for (i = 0; i < v1; ++i) { - if (level_frame_count[i] < level_frame_count[i + 1]) { + doneflag = FALSE; + while(frames > 0 && !doneflag) { + doneflag = TRUE; + for(i = 0; i < frames; i++) { + if(level_frame_count[i] < level_frame_count[i + 1]) { gendung_4191FB(i, i + 1); - v2 = 0; + doneflag = FALSE; } } - --v1; + frames--; } } -void __fastcall gendung_4191FB(int a1, int a2) +void __fastcall gendung_4191FB(int f1, int f2) { - int v2; // esi - int *v3; // edi - short *v4; // edx - int v5; // ST10_4 - int *v6; // edi - int *v7; // eax - int v8; // ST10_4 - short *v9; // ecx - int v10; // edx + int swap; - v2 = a2; - v3 = &level_frame_count[a1]; - v4 = &level_frame_types[a2]; - v2 *= 4; - v5 = *v3; - *v3 = *(int *)((char *)level_frame_count + v2); - v6 = &tile_defs[a1]; - *(int *)((char *)level_frame_count + v2) = v5; - v7 = &level_frame_sizes[a1]; - v8 = *v6; - *v6 = *(int *)((char *)tile_defs + v2); - *(int *)((char *)tile_defs + v2) = v8; - v9 = &level_frame_types[a1]; - _LOWORD(v6) = *v9; - *v9 = *v4; - *v4 = (signed short)v6; - v10 = *v7; - *v7 = *(int *)((char *)level_frame_sizes + v2); - *(int *)((char *)level_frame_sizes + v2) = v10; + swap = level_frame_count[f1]; + level_frame_count[f1] = level_frame_count[f2]; + level_frame_count[f2] = swap; + swap = tile_defs[f1]; + tile_defs[f1] = tile_defs[f2]; + tile_defs[f2] = swap; + swap = (WORD)level_frame_types[f1]; + level_frame_types[f1] = level_frame_types[f2]; + level_frame_types[f2] = swap; + swap = level_frame_sizes[f1]; + level_frame_sizes[f1] = level_frame_sizes[f2]; + level_frame_sizes[f2] = swap; } int __fastcall gendung_get_dpiece_num_from_coord(int x, int y) @@ -473,9 +456,9 @@ int __fastcall gendung_get_dpiece_num_from_coord(int x, int y) if (x < MAXDUNY - y) return (y + y * y + x * (x + 2 * y + 3)) / 2; - x = MAXDUNY - x - 1; + x = MAXDUNX - x - 1; y = MAXDUNY - y - 1; - return MAXDUNX * MAXDUNY - (y + y * y + x * (x + 2 * y + 3)) / 2 - 1; + return MAXDUNX * MAXDUNY - ((y + y * y + x * (x + 2 * y + 3)) / 2 + 1); } void __cdecl gendung_4192C2() diff --git a/Source/gendung.h b/Source/gendung.h index 798183b30..ebf8f4396 100644 --- a/Source/gendung.h +++ b/Source/gendung.h @@ -72,7 +72,7 @@ extern short dpiece_defs_map_2[16][MAXDUNX][MAXDUNY]; void __cdecl FillSolidBlockTbls(); void __cdecl gendung_418D91(); void __fastcall gendung_4191BF(int frames); -void __fastcall gendung_4191FB(int a1, int a2); +void __fastcall gendung_4191FB(int f1, int f2); int __fastcall gendung_get_dpiece_num_from_coord(int x, int y); void __cdecl gendung_4192C2(); void __cdecl SetDungeonMicros(); From f59fd7de20dbbf0d335bf69aa2194d6ab53975d8 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sat, 23 Mar 2019 04:26:23 -0500 Subject: [PATCH 26/28] Fix gendung.cpp headache (#722) --- Source/gendung.cpp | 682 +++++++++++++++++++++++---------------------- Source/gendung.h | 18 +- types.h | 3 - 3 files changed, 352 insertions(+), 351 deletions(-) diff --git a/Source/gendung.cpp b/Source/gendung.cpp index 768715211..a362d0d82 100644 --- a/Source/gendung.cpp +++ b/Source/gendung.cpp @@ -2,14 +2,14 @@ #include "../types.h" -short level_frame_types[2048]; +WORD level_frame_types[MAXTILES]; int themeCount; char nTransTable[2049]; //int dword_52D204; int dMonster[MAXDUNX][MAXDUNY]; char dungeon[40][40]; char dObject[MAXDUNX][MAXDUNY]; -void *pSpeedCels; +BYTE *pSpeedCels; int nlevel_frames; // weak char pdungeon[40][40]; char dDead[MAXDUNX][MAXDUNY]; @@ -21,9 +21,9 @@ char dflags[40][40]; int dPiece[MAXDUNX][MAXDUNY]; char dTransVal[MAXDUNX][MAXDUNY]; int setloadflag_2; // weak -int tile_defs[2048]; +int tile_defs[MAXTILES]; BYTE *pMegaTiles; -void *pLevelPieces; +BYTE *pLevelPieces; int gnDifficulty; // idb char block_lvid[2049]; //char byte_5B78EB; @@ -33,10 +33,10 @@ BYTE leveltype; unsigned char currlevel; // idb char TransList[256]; BOOLEAN nSolidTable[2049]; -int level_frame_count[2048]; +int level_frame_count[MAXTILES]; ScrollStruct ScrollInfo; -void *pDungeonCels; -int speed_cel_frame_num_from_light_index_frame_num[16][128]; +BYTE *pDungeonCels; +int speed_cel_frame_num_from_light_index_frame_num[128][16]; THEME_LOC themeLoc[MAXTHEMES]; char dPlayer[MAXDUNX][MAXDUNY]; int dword_5C2FF8; // weak @@ -49,7 +49,7 @@ void *level_special_cel; char dFlags[MAXDUNX][MAXDUNY]; char dItem[MAXDUNX][MAXDUNY]; BYTE setlvlnum; -int level_frame_sizes[2048]; +int level_frame_sizes[MAXTILES]; char nMissileTable[2049]; char *pSetPiece_2; char setlvltype; // weak @@ -67,7 +67,7 @@ int setpc_y; // idb char dMissile[MAXDUNX][MAXDUNY]; int dminx; // weak int dminy; // weak -short dpiece_defs_map_2[16][MAXDUNX][MAXDUNY]; +WORD dpiece_defs_map_2[MAXDUNX][MAXDUNY][16]; void __cdecl FillSolidBlockTbls() { @@ -124,293 +124,324 @@ void __cdecl FillSolidBlockTbls() void __cdecl gendung_418D91() { - signed int v0; // edx - short(*v1)[MAXDUNX][MAXDUNY]; // edi - short(*v2)[MAXDUNX][MAXDUNY]; // esi - signed int v3; // ebx - int i; // edx - short v5; // ax - int v6; // ecx - signed int v7; // edx - int v8; // eax - int v9; // edi - char *v10; // esi - int j; // ecx - unsigned char v12; // al - unsigned char *v13; // esi - int v14; // ecx - signed int v15; // edx - int v16; // eax - int v17; // ecx - unsigned char v18; // al - signed int v19; // ecx - int v20; // edi - int v21; // edx - int v22; // edi - int v23; // eax - int v24; // eax - BOOLEAN v25; // zf - int v26; // edx - char *v27; // esi - char *v28; // edi - int k; // ecx - char *v33; // esi - char *v34; // edi - int v36; // ecx - signed int v37; // edx - int v38; // eax - int v39; // ecx - short(*v42)[MAXDUNX][MAXDUNY]; // esi - short v43; // ax - unsigned short v44; // dx - short v45; // ax - int v46; // [esp-4h] [ebp-38h] - int v47; // [esp-4h] [ebp-38h] - int v48; // [esp+Ch] [ebp-28h] - int(*v49)[128]; // [esp+10h] [ebp-24h] - int(*v50)[112]; // [esp+10h] [ebp-24h] - int v51; // [esp+14h] [ebp-20h] - short(*v52)[MAXDUNX][MAXDUNY]; // [esp+14h] [ebp-20h] - signed int v53; // [esp+18h] [ebp-1Ch] - int v54; // [esp+18h] [ebp-1Ch] - short(*v55)[MAXDUNX][MAXDUNY]; // [esp+18h] [ebp-1Ch] - int v56; // [esp+1Ch] [ebp-18h] - int(*v57)[112]; // [esp+1Ch] [ebp-18h] - signed int v58; // [esp+20h] [ebp-14h] - int v59; // [esp+20h] [ebp-14h] - int v60; // [esp+24h] [ebp-10h] - signed int v61; // [esp+24h] [ebp-10h] - int v62; // [esp+28h] [ebp-Ch] - int v63; // [esp+2Ch] [ebp-8h] - signed int v64; // [esp+30h] [ebp-4h] - signed int v65; // [esp+30h] [ebp-4h] - int _EAX; - char *_EBX; + int i, j, x, y; + int total_frames, blocks, total_size, frameidx, lfs_adder, blk_cnt, currtile, nDataSize; + WORD m; + BOOL blood_flag; + WORD *pMap; + DWORD *pFrameTable; +#if (_MSC_VER < 800) || (_MSC_VER > 1200) + int k, l; + BYTE width, pix; + BYTE *src, *dst, *tbl; +#endif - v0 = 0; - memset(level_frame_types, 0, sizeof(level_frame_types)); - memset(level_frame_count, 0, sizeof(level_frame_count)); - do { - tile_defs[v0] = v0; - ++v0; - } while (v0 < 2048); - v1 = dpiece_defs_map_2; - v48 = 2 * (leveltype == DTYPE_HELL) + 10; - do { - v2 = v1; - v3 = 112; - do { - for (i = 0; i < v48; ++i) { - v5 = (*v2)[0][i]; - if ((*v2)[0][i]) { - v6 = v5 & 0xFFF; - ++level_frame_count[v6]; - level_frame_types[v6] = v5 & 0x7000; + for(i = 0; i < MAXTILES; i++) { + tile_defs[i] = i; + level_frame_count[i] = 0; + level_frame_types[i] = 0; + } + + if(leveltype != DTYPE_HELL) + blocks = 10; + else + blocks = 12; + + for(y = 0; y < MAXDUNY; y++) { + for(x = 0; x < MAXDUNX; x++) { + for(i = 0; i < blocks; i++) { + pMap = dpiece_defs_map_2[x][y]; + if(pMap[i]) { + level_frame_count[pMap[i] & 0xFFF]++; + level_frame_types[pMap[i] & 0xFFF] = pMap[i] & 0x7000; } } - v2 = (short(*)[MAXDUNX][MAXDUNY])((char *)v2 + 3584); - --v3; - } while (v3); - v1 = (short(*)[MAXDUNX][MAXDUNY])((char *)v1 + 32); - } while ((signed int)v1 < (signed int)dpiece_defs_map_2[0][16]); /* check */ - v7 = 1; - nlevel_frames = *(_DWORD *)pDungeonCels & 0xFFFF; - v8 = nlevel_frames; - if (nlevel_frames > 1) { - do { - level_frame_sizes[v7] = (*((_DWORD *)pDungeonCels + v7 + 1) - *((_DWORD *)pDungeonCels + v7)) & 0xFFFF; - v8 = nlevel_frames; - ++v7; - } while (v7 < nlevel_frames); + } + } + + pFrameTable = (DWORD *)pDungeonCels; + nlevel_frames = pFrameTable[0] & 0xFFFF; + + for(i = 1; i < nlevel_frames; i++) { +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov ebx, pDungeonCels + mov eax, i + shl eax, 2 + add ebx, eax + mov eax, [ebx+4] + sub eax, [ebx] + mov nDataSize, eax + } +#else + nDataSize = pFrameTable[i + 1] - pFrameTable[i]; +#endif + level_frame_sizes[i] = nDataSize & 0xFFFF; } - v9 = 0; + level_frame_sizes[0] = 0; - if (leveltype == DTYPE_HELL && v8 > 0) { - do { - if (!v9) + + if(leveltype == DTYPE_HELL) { + for(i = 0; i < nlevel_frames; i++) { + if(!i) level_frame_count[0] = 0; - v53 = 1; - if (level_frame_count[v9]) { - if (level_frame_types[v9] == 4096) { - v13 = (unsigned char *)pDungeonCels + *((_DWORD *)pDungeonCels + v9); - v14 = 32; - do { - v46 = v14; - v15 = 32; - do { - while (1) { - v16 = *v13++; - if ((v16 & 0x80u) == 0) - break; - _LOBYTE(v16) = -(char)v16; - v15 -= v16; - if (!v15) - goto LABEL_36; - } - v15 -= v16; - v17 = v16; - do { - v18 = *v13++; - if (v18 && v18 < 0x20u) - v53 = 0; - --v17; - } while (v17); - } while (v15); - LABEL_36: - v14 = v46 - 1; - } while (v46 != 1); + blood_flag = TRUE; + if(level_frame_count[i]) { + if(level_frame_types[i] != 0x1000) { +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + j = level_frame_sizes[i]; + __asm { + mov ebx, pDungeonCels + mov eax, i + shl eax, 2 + add ebx, eax + mov esi, pDungeonCels + add esi, [ebx] + xor ebx, ebx + mov ecx, j + jecxz l1_label3 + l1_label1: + lodsb + cmp al, 0 + jz l1_label2 + cmp al, 32 + jnb l1_label2 + mov blood_flag, ebx + l1_label2: + loop l1_label1 + l1_label3: + nop + } +#else + src = &pDungeonCels[pFrameTable[i]]; + for(j = level_frame_sizes[i]; j; j--) { + pix = *src++; + if(pix && pix < 32) + blood_flag = FALSE; + } +#endif } else { - v10 = (char *)pDungeonCels + *((_DWORD *)pDungeonCels + v9); - for (j = level_frame_sizes[v9]; j; --j) { - v12 = *v10++; - if (v12 && v12 < 0x20u) - v53 = 0; +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov ebx, pDungeonCels + mov eax, i + shl eax, 2 + add ebx, eax + mov esi, pDungeonCels + add esi, [ebx] + xor ebx, ebx + mov ecx, 32 + l2_label1: + push ecx + mov edx, 32 + l2_label2: + xor eax, eax + lodsb + or al, al + js l2_label5 + sub edx, eax + mov ecx, eax + l2_label3: + lodsb + cmp al, 0 + jz l2_label4 + cmp al, 32 + jnb l2_label4 + mov blood_flag, ebx + l2_label4: + loop l2_label3 + or edx, edx + jz l2_label6 + jmp l2_label2 + l2_label5: + neg al + sub edx, eax + jnz l2_label2 + l2_label6: + pop ecx + loop l2_label1 + } +#else + src = &pDungeonCels[pFrameTable[i]]; + for(k = 32; k; k--) { + for(l = 32; l;) { + width = *src++; + if(!(width & 0x80)) { + l -= width; + while(width) { + pix = *src++; + if(pix && pix < 32) + blood_flag = FALSE; + width--; + } + } else { + width = -(char)width; + l -= width; + } + } } +#endif } - if (!v53) - level_frame_count[v9] = 0; + if(!blood_flag) + level_frame_count[i] = 0; } - ++v9; - } while (v9 < nlevel_frames); + } } - gendung_4191BF(2047); - v19 = 0; - v20 = 0; - if (light4flag) { - do { - v21 = level_frame_sizes[v20++]; - v19 += 2 * v21; - } while (v19 < 0x100000); + + gendung_4191BF(MAXTILES - 1); + total_size = 0; + total_frames = 0; + + if(light4flag) { + while(total_size < 0x100000) { + total_size += level_frame_sizes[total_frames] << 1; + total_frames++; + } } else { - do - v19 += 14 * level_frame_sizes[v20++]; - while (v19 < 0x100000); - } - v22 = v20 - 1; - v58 = v22; - if (v22 > 128) { - v58 = 128; - v22 = 128; + while(total_size < 0x100000) { + total_size += (level_frame_sizes[total_frames] << 4) - (level_frame_sizes[total_frames] << 1); + total_frames++; + } } - v23 = -(light4flag != 0); - v63 = 0; - _LOBYTE(v23) = v23 & 0xF4; - v54 = 0; - v60 = v23 + 15; - if (v22 > 0) { - v56 = 0; - v49 = speed_cel_frame_num_from_light_index_frame_num; - do { - v24 = v54; - v25 = level_frame_types[v54] == 4096; - v62 = tile_defs[v54]; - (*v49)[0] = v62; - if (v25) { - v65 = 1; - if (v60 > 1) { - do { - speed_cel_frame_num_from_light_index_frame_num[0][v65 + v56] = v63; - v33 = (char *)pDungeonCels + *((_DWORD *)pDungeonCels + v62); - v34 = (char *)pSpeedCels + v63; - _EBX = &pLightTbl[256 * v65]; - v36 = 32; - do { - v47 = v36; - v37 = 32; - do { - while (1) { - v38 = (unsigned char)*v33++; - *v34++ = v38; - if ((v38 & 0x80u) == 0) - break; - _LOBYTE(v38) = -(char)v38; - v37 -= v38; - if (!v37) - goto LABEL_63; - } - v37 -= v38; - v39 = v38; - do { - _EAX = *v33++; - ASM_XLAT(_EAX, _EBX); - *v34++ = _EAX; - --v39; - } while (v39); - } while (v37); - LABEL_63: - v36 = v47 - 1; - } while (v47 != 1); - v63 += level_frame_sizes[v54]; - ++v65; - } while (v65 < v60); - goto LABEL_65; + + total_frames--; + if(total_frames > 128) + total_frames = 128; + + frameidx = 0; /* move into loop ? */ + + if(light4flag) + blk_cnt = 3; + else + blk_cnt = 15; + + for(i = 0; i < total_frames; i++) { + currtile = tile_defs[i]; + speed_cel_frame_num_from_light_index_frame_num[i][0] = currtile; + if(level_frame_types[i] != 0x1000) { + lfs_adder = level_frame_sizes[i]; + for(j = 1; j < blk_cnt; j++) { + speed_cel_frame_num_from_light_index_frame_num[i][j] = frameidx; +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov ebx, pDungeonCels + mov eax, currtile + shl eax, 2 + add ebx, eax + mov esi, pDungeonCels + add esi, [ebx] + mov edi, pSpeedCels + add edi, frameidx + mov ebx, j + shl ebx, 8 + add ebx, pLightTbl + mov ecx, lfs_adder + jecxz l3_label2 + l3_label1: + lodsb + xlat + stosb + loop l3_label1 + l3_label2: + nop } - } else { - v26 = level_frame_sizes[v24]; - v51 = level_frame_sizes[v24]; - v64 = 1; - if (v60 > 1) { - do { - speed_cel_frame_num_from_light_index_frame_num[0][v64 + v56] = v63; - v27 = (char *)pDungeonCels + *((_DWORD *)pDungeonCels + v62); - v28 = (char *)pSpeedCels + v63; - _EBX = &pLightTbl[256 * v64]; - for (k = v51; k; --k) { - _EAX = *v27++; - ASM_XLAT(_EAX, _EBX); - *v28++ = _EAX; +#else + src = &pDungeonCels[pFrameTable[currtile]]; + dst = &pSpeedCels[frameidx]; + tbl = (BYTE *)&pLightTbl[256 * j]; + for(k = lfs_adder; k; k--) { + *dst++ = tbl[*src++]; + } +#endif + frameidx += lfs_adder; + } + } else { + for(j = 1; j < blk_cnt; j++) { + speed_cel_frame_num_from_light_index_frame_num[i][j] = frameidx; +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov ebx, pDungeonCels + mov eax, currtile + shl eax, 2 + add ebx, eax + mov esi, pDungeonCels + add esi, [ebx] + mov edi, pSpeedCels + add edi, frameidx + mov ebx, j + shl ebx, 8 + add ebx, pLightTbl + mov ecx, 32 + l4_label1: + push ecx + mov edx, 32 + l4_label2: + xor eax, eax + lodsb + stosb + or al, al + js l4_label4 + sub edx, eax + mov ecx, eax + l4_label3: + lodsb + xlat + stosb + loop l4_label3 + or edx, edx + jz l4_label5 + jmp l4_label2 + l4_label4: + neg al + sub edx, eax + jnz l4_label2 + l4_label5: + pop ecx + loop l4_label1 + } +#else + src = &pDungeonCels[pFrameTable[currtile]]; + dst = &pSpeedCels[frameidx]; + tbl = (BYTE *)&pLightTbl[256 * j]; + for(k = 32; k; k--) { + for(l = 32; l;) { + width = *src++; + *dst++ = width; + if(!(width & 0x80)) { + l -= width; + while(width) { + *dst++ = tbl[*src++]; + width--; + } + } else { + width = -(char)width; + l -= width; } - v63 += v26; - ++v64; - } while (v64 < v60); - LABEL_65: - v22 = v58; - goto LABEL_66; + } } +#endif + frameidx += level_frame_sizes[i]; } - LABEL_66: - ++v54; - v49 = (int(*)[128])((char *)v49 + 64); - v56 += 16; - } while (v54 < v22); + } } - v57 = dPiece; - v55 = dpiece_defs_map_2; - do { - v61 = 112; - v52 = v55; - v50 = v57; - do { - if ((*v50)[0] && v48 > 0) { - v42 = v52; - v59 = v48; - do { - v43 = *(_WORD *)v42; - if (*(_WORD *)v42) { - v44 = 0; - if (v22 > 0) { - do { - if ((v43 & 0xFFF) == tile_defs[v44]) { - v45 = v44 + level_frame_types[v44]; - v44 = v22; - v43 = v45 + -32768; - } - ++v44; - } while (v44 < v22); - *(_WORD *)v42 = v43; + + for(y = 0; y < MAXDUNY; y++) { + for(x = 0; x < MAXDUNX; x++) { + if(dPiece[x][y]) { + pMap = dpiece_defs_map_2[x][y]; + for(i = 0; i < blocks; i++) { + if(pMap[i]) { + for(m = 0; m < total_frames; m++) { + if((pMap[i] & 0xFFF) == tile_defs[m]) { + pMap[i] = m + level_frame_types[m] + 0x8000; + m = total_frames; + } } } - v42 = (short(*)[MAXDUNX][MAXDUNY])((char *)v42 + 2); - --v59; - } while (v59); + } } - ++v50; - v52 = (short(*)[MAXDUNX][MAXDUNY])((char *)v52 + 3584); - --v61; - } while (v61); - v55 = (short(*)[MAXDUNX][MAXDUNY])((char *)v55 + 32); - v57 = (int(*)[112])((char *)v57 + 4); - } while ((signed int)v55 < (signed int)dpiece_defs_map_2[0][16]); /* check */ + } + } } // 525728: using guessed type int light4flag; // 53CD4C: using guessed type int nlevel_frames; @@ -443,7 +474,7 @@ void __fastcall gendung_4191FB(int f1, int f2) swap = tile_defs[f1]; tile_defs[f1] = tile_defs[f2]; tile_defs[f2] = swap; - swap = (WORD)level_frame_types[f1]; + swap = level_frame_types[f1]; level_frame_types[f1] = level_frame_types[f2]; level_frame_types[f2] = swap; swap = level_frame_sizes[f1]; @@ -458,85 +489,58 @@ int __fastcall gendung_get_dpiece_num_from_coord(int x, int y) x = MAXDUNX - x - 1; y = MAXDUNY - y - 1; - return MAXDUNX * MAXDUNY - ((y + y * y + x * (x + 2 * y + 3)) / 2 + 1); + return MAXDUNX * MAXDUNY - ((y + y * y + x * (x + 2 * y + 3)) / 2) - 1; } void __cdecl gendung_4192C2() { - short(*v0)[MAXDUNX][MAXDUNY]; // ebx - int v1; // ebp - short(*v2)[MAXDUNX][MAXDUNY]; // esi - char *v3; // edi - int x; // [esp+10h] [ebp-4h] + int i, x, y; - x = 0; - v0 = dpiece_defs_map_2; - do { - v1 = 0; - do { - v2 = v0; - v3 = (char *)dpiece_defs_map_1 + 32 * gendung_get_dpiece_num_from_coord(x, v1++); - v0 = (short(*)[MAXDUNX][MAXDUNY])((char *)v0 + 32); - qmemcpy(v3, v2, 0x20u); - } while (v1 < 112); - ++x; - } while ((signed int)v0 < (signed int)&dpiece_defs_map_2[16][0][0]); + for(x = 0; x < MAXDUNX; x++) { + for(y = 0; y < MAXDUNY; y++) { + for(i = 0; i < 16; i++) { + dpiece_defs_map_1[gendung_get_dpiece_num_from_coord(x, y)][i] = dpiece_defs_map_2[x][y][i]; + } + } + } } void __cdecl SetDungeonMicros() { - signed int v0; // esi - short(*v1)[MAXDUNX][MAXDUNY]; // edx - int(*v2)[112]; // ebp - int v3; // eax - char *v4; // eax - signed int i; // ecx - _WORD *v6; // edi - int j; // ecx - short(*v8)[MAXDUNX][MAXDUNY]; // [esp+8h] [ebp-Ch] - int(*v9)[112]; // [esp+Ch] [ebp-8h] - signed int v10; // [esp+10h] [ebp-4h] + int i, x, y, lv, blocks; + WORD *pMap, *pPiece; - if (leveltype == DTYPE_HELL) { - dword_5A5594 = 12; - v0 = 16; - } else { + if(leveltype != DTYPE_HELL) { dword_5A5594 = 10; - v0 = 10; + blocks = 10; + } else { + dword_5A5594 = 12; + blocks = 16; } - v9 = dPiece; - v8 = dpiece_defs_map_2; - do { - v1 = v8; - v2 = v9; - v10 = 112; - do { - if ((*v2)[0]) { - v3 = (*v2)[0] - 1; - if (leveltype == DTYPE_HELL) - v4 = (char *)pLevelPieces + 32 * v3; + + for(y = 0; y < MAXDUNY; y++) { + for(x = 0; x < MAXDUNX; x++) { + lv = dPiece[x][y]; + pMap = dpiece_defs_map_2[x][y]; + if(lv) { + lv--; + if(leveltype != DTYPE_HELL) + pPiece = (WORD *)&pLevelPieces[20 * lv]; else - v4 = (char *)pLevelPieces + 20 * v3; - for (i = 0; i < v0; ++i) - (*v1)[0][i] = *(_WORD *)&v4[2 * (v0 + (i & 1) - (i & 0xE)) - 4]; - } else if (v0 > 0) { - memset(v1, 0, 4 * ((unsigned int)v0 >> 1)); - v6 = (_WORD *)((char *)v1 + 4 * ((unsigned int)v0 >> 1)); - for (j = v0 & 1; j; --j) { - *v6 = 0; - ++v6; - } + pPiece = (WORD *)&pLevelPieces[32 * lv]; + for(i = 0; i < blocks; i++) + pMap[i] = pPiece[(i & 1) + blocks - 2 - (i & 0xE)]; + } else { + for(i = 0; i < blocks; i++) + pMap[i] = 0; } - ++v2; - v1 = (short(*)[MAXDUNX][MAXDUNY])((char *)v1 + 3584); - --v10; - } while (v10); - v8 = (short(*)[MAXDUNX][MAXDUNY])((char *)v8 + 32); - v9 = (int(*)[112])((char *)v9 + 4); - } while ((signed int)v8 < (signed int)dpiece_defs_map_2[0][16]); /* check */ + } + } + gendung_418D91(); gendung_4192C2(); - if (zoomflag) { + + if(zoomflag) { scr_pix_width = 640; scr_pix_height = 352; dword_5C2FF8 = 10; diff --git a/Source/gendung.h b/Source/gendung.h index ebf8f4396..2e276cd74 100644 --- a/Source/gendung.h +++ b/Source/gendung.h @@ -2,14 +2,14 @@ #ifndef __GENDUNG_H__ #define __GENDUNG_H__ -extern short level_frame_types[2048]; +extern WORD level_frame_types[MAXTILES]; extern int themeCount; extern char nTransTable[2049]; //int dword_52D204; extern int dMonster[MAXDUNX][MAXDUNY]; extern char dungeon[40][40]; extern char dObject[MAXDUNX][MAXDUNY]; -extern void *pSpeedCels; +extern BYTE *pSpeedCels; extern int nlevel_frames; // weak extern char pdungeon[40][40]; extern char dDead[MAXDUNX][MAXDUNY]; @@ -21,9 +21,9 @@ extern char dflags[40][40]; extern int dPiece[MAXDUNX][MAXDUNY]; extern char dTransVal[MAXDUNX][MAXDUNY]; extern int setloadflag_2; // weak -extern int tile_defs[2048]; +extern int tile_defs[MAXTILES]; extern BYTE *pMegaTiles; -extern void *pLevelPieces; +extern BYTE *pLevelPieces; extern int gnDifficulty; // idb extern char block_lvid[2049]; //char byte_5B78EB; @@ -33,10 +33,10 @@ extern BYTE leveltype; extern unsigned char currlevel; // idb extern char TransList[256]; extern BOOLEAN nSolidTable[2049]; -extern int level_frame_count[2048]; +extern int level_frame_count[MAXTILES]; extern ScrollStruct ScrollInfo; -extern void *pDungeonCels; -extern int speed_cel_frame_num_from_light_index_frame_num[16][128]; +extern BYTE *pDungeonCels; +extern int speed_cel_frame_num_from_light_index_frame_num[128][16]; extern THEME_LOC themeLoc[MAXTHEMES]; extern char dPlayer[MAXDUNX][MAXDUNY]; extern int dword_5C2FF8; // weak @@ -49,7 +49,7 @@ extern void *level_special_cel; extern char dFlags[MAXDUNX][MAXDUNY]; extern char dItem[MAXDUNX][MAXDUNY]; extern BYTE setlvlnum; -extern int level_frame_sizes[2048]; +extern int level_frame_sizes[MAXTILES]; extern char nMissileTable[2049]; extern char *pSetPiece_2; extern char setlvltype; // weak @@ -67,7 +67,7 @@ extern int setpc_y; // idb extern char dMissile[MAXDUNX][MAXDUNY]; extern int dminx; // weak extern int dminy; // weak -extern short dpiece_defs_map_2[16][MAXDUNX][MAXDUNY]; +extern WORD dpiece_defs_map_2[MAXDUNX][MAXDUNY][16]; void __cdecl FillSolidBlockTbls(); void __cdecl gendung_418D91(); diff --git a/types.h b/types.h index 4801fcc3b..655f2cedb 100644 --- a/types.h +++ b/types.h @@ -58,9 +58,6 @@ // Will be replaced with [rep movsd] if optimization is used #define FAST_MEMCPY -/* temp macro for asm XLAT */ -#define ASM_XLAT(eax, ebx) eax = (eax & 0xFFFFFF00) + LOBYTE(ebx[LOBYTE(eax)]) - // header files #ifdef __cplusplus extern "C" { From 47d1cc954d4ec97f289711c506cba5b36b140243 Mon Sep 17 00:00:00 2001 From: JustAnotherGuid <46401660+JustAnotherGuid@users.noreply.github.com> Date: Sat, 23 Mar 2019 20:20:54 +0100 Subject: [PATCH 27/28] Freeupstairs bin exact --- Source/trigs.cpp | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/Source/trigs.cpp b/Source/trigs.cpp index d133a0a9f..a5d80688a 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -962,33 +962,17 @@ LABEL_17: void __cdecl Freeupstairs() { - int *v0; // ecx - int v1; // ebx - char *v2; // eax - signed int v3; // edi - char *v4; // edx - signed int v5; // esi + int i, yy, xx, tx, ty; - if (trigflag[4] > 0) { - v0 = &trigs[0]._ty; - v1 = trigflag[4]; - do { - v2 = &dFlags[*(v0 - 1) - 2][*v0 - 2]; /* v2 = &nBlockTable[112 * *(v0 - 1) + 1830 + *v0]; check */ - v3 = 5; - do { - v4 = v2; - v5 = 5; - do { - *v4 |= DFLAG_POPULATED; - v4 += 112; - --v5; - } while (v5); - ++v2; - --v3; - } while (v3); - v0 += 4; - --v1; - } while (v1); + for (i = 0; i < trigflag[4]; i++) { + tx = trigs[i]._tx; + ty = trigs[i]._ty; + + for (yy = 0; yy < MAXTRIGGERS; yy++) { + for (xx = 0; xx < MAXTRIGGERS; xx++) { + dFlags[tx - 2 + xx][ty - 2 + yy] |= DFLAG_POPULATED; + } + } } } From 1780717d023e07fb6c34d8b10c6d3ee5719f3dfa Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sat, 23 Mar 2019 17:00:17 -0500 Subject: [PATCH 28/28] Reeeeed meee (#724) * Update readme --- README.md | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index af7ea3f58..b1e60ffc0 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,12 @@ # Devilution Diablo devolved - magic behind the 1996 computer game -Reverse engineered by GalaXyHaXz in 2018 - **Note**, Devilution requires an original copy of `diabdat.mpq`. None of the Diablo 1 game assets are provided by this project. To get a legitimate copy of the game assets, please refer to the [GoG release of Diablo 1](https://www.gog.com/game/diablo). # Introduction -While most titles from Blizzard receive years of love and support, Diablo stayed in the shadows. Abandoned in favour of a sequel, it remained full of bugs and unfinished potential. The game was last patched in 2001 before being discontinued altogether, a problem I wanted to fix. I played Diablo extensively as a teenager, but as time passed it became difficult to run the game on newer hardware. The lack of many improvements found in the sequel also kept it from ageing well. At first the game appeared to be a lost cause, but thankfully a little oversight in 1997 made it not so. +While most titles from Blizzard receive years of love and support, Diablo stayed in the shadows. Abandoned in favor of a sequel, it remained full of bugs and unfinished potential. The game was last patched in 2001 before being discontinued altogether, a problem I wanted to fix. I played Diablo extensively as a teenager, but as time passed it became difficult to run the game on newer hardware. The lack of many improvements made in Diablo II also laid it to rest. At first the game appeared to be a lost cause, but thankfully a little oversight in 1997 made it not so. -With Diablo's development team moving on the source code was given to **Synergistic Software** to handle the expansion. Less known however is that it was also given to **Climax Studios** to create a PlayStation port. Now Sony has long been known for letting things slide; _especially_ in Japan. Anything from leaking prototypes to full source code and Diablo was no exception. Symbolic information was accidentally left on the Japanese port. Normally used for debugging, a symbol file contains a map of everything generated during compile time. This includes file names, functions, structures, variables, and more! To top it all off a special build is hidden on the PC release in `DIABDAT.MPQ -> D1221A.MPQ -> DIABLO.EXE`! This build contains debug tools and assert strings further giving away code information. +Diablo's development team moved on to Diablo II while passing the source code down to **Synergistic Software** for Hellfire. Less known however is that it was also given to **Climax Studios** to create a PlayStation port. Now Sony has long been known for letting things slide; _especially_ in Japan. Anything from leaking prototypes to entire game source codes and Diablo was no exception. Symbolic information was accidentally left on the Japanese port. Normally used for debugging, a symbol file contains a map of everything generated during compile time. This includes file names, functions, structures, variables, and more! To top it all off a special build is hidden on the PC release in `DIABDAT.MPQ -> D1221A.MPQ -> DIABLO.EXE`! This build contains debug tools and assert strings further giving away code information. After months of piecing these mistakes together, Devilution was born. I present to you a reconstructed form of Diablo's original source code! Once more shall the heroes of Sanctuary return to the depths below! @@ -26,14 +24,12 @@ In order to ensure that everything is preserved, Devilution keeps everything as As a side goal Devilution tries to document the unused and cut content from the final game. Development of Diablo was rushed near the end--many ideas were scrapped and multiplayer was quickly hacked in. By examining the source, we can see various quirks of planned development. # Compiling -Diablo was developed on Windows 95 using Visual C++ 4.20 and later 5.10 and 6 for newer patches. Devilution is optimized for the same tools originally used but is also compatible with modern setups. +Diablo was developed on Windows 95 using Visual C++ 4.20 and later 5.10 and 6 for newer patches. Devilution aims to be compatible with both the original and modern tools, but will adhere to standards used for the original compiler. ### Building with Visual C++ 6 - Open the project workspace `Diablo.dsw`, choose `Debug` or `Release`, and then `Build Diablo.exe`. -To build a binary with functions compiled as close as possible to the original, use [Visual C++ 6](https://winworldpc.com/product/visual-c/6x) with Service Pack 5 and the [Processor Pack](https://download.microsoft.com/download/vb60ent/update/6/w9x2kxp/en-us/vcpp5.exe) (**important for proper code generation!**) - -If you aim to build a binary as close as possible to the original one you will also need [Visual C++ 5](https://winworldpc.com/product/visual-c/5x) with [Service Pack 3](http://www.mediafire.com/file/jw4j4sd5dnzze4p/VS97SP3.zip), since the original binary as linked with the older linker from that. Sadly, you cannot use the old linker right out of VC6, so you'll need to link manually or via the `MakefileVC` in the project root. +To build a binary with functions compiled as close as possible to the original, use [Visual C++ 6](https://winworldpc.com/product/visual-c/6x) with Service Pack 5 and the [Processor Pack](https://download.microsoft.com/download/vb60ent/update/6/w9x2kxp/en-us/vcpp5.exe) (**important for proper code generation!**) You will also need [Visual C++ 5](https://winworldpc.com/product/visual-c/5x) with [Service Pack 3](http://www.mediafire.com/file/jw4j4sd5dnzze4p/VS97SP3.zip), since the original binary was linked with the older linker from that. Sadly, you cannot use the old linker right out of VC6, so you'll need to link manually or via the `MakefileVC` in the project root. ### Building with Visual Studio 2010-2017 - Open the project solution `Diablo.sln`, choose `Debug` or `Release`, and then `Build Solution`. @@ -63,48 +59,51 @@ Once compiled, the Devilution binary will serve as a replacement for `Diablo.exe Additionally, Strange Bytes' [DirectDraw patch](http://www.strangebytes.com/index.php/projects/1-diablo-1-windows-7-vista-patch) is recommended to help fix compatibility issues and run the game in windowed mode. # Multiplayer -TODO +Devilution is functional over both GoG's Battle.net server and IPX using an ipx-wrapper. Additionally if `Standard.snp` from StarCraft 1.16.1 is used, local UDP play also becomes available. There are programs like ZeroTier to connect UDP globally. # Contributing [Guidelines](docs/CONTRIBUTING.md) # Modding -Here are some screenshots of a few things I tinkered around with, to demonstrate the relative ease of improving the game: +Below are a few examples of some simple improvements made to the game. It is planned in the future to create tools for designing dungeons and graphics. -![Screenshot 1: Monster lifebar+items](https://s33.postimg.cc/6xnnhhlmn/diabuimon.png "Monster lifebar+items") +
Example 1: Monster lifebar and item highlighting -![Screenshot 2: New trade screen](https://s22.postimg.cc/5i5k91vht/diabstore.png "New trade screen, items that couldn't spawn") +![Monster lifebar+items](https://github.com/diasurgical/scalpel/blob/master/screens/mod1.png) +
+
Example 2: New Diablo 2-like trade screen + +![New trade screen](https://github.com/diasurgical/scalpel/blob/master/screens/mod2.png) +
# F.A.Q. +
Click to reveal + > Wow, does this mean I can download and play Diablo for free now? -No, you'll need access to the data from the original game. Blizzard has discontinued Diablo, but there's plenty of used copies floating around. (I'm still using an original 1996-disc in 2018 without problems) +No, you'll need access to the data from the original game. Blizzard discontinued Diablo, but it is available on the GOG.com platform. Additionally there are plenty of used copies for sale online. (I'm still using an original 1996-disc without problems) > Cool, so I fired your mod up, but there's no 1080p or new features? Devilution aims to keep the original code unaltered, for documentation purposes. > So will you ever add cross-platform support or new features in the future? Yes! This has been done as a side project, please see [DevilutionX](https://github.com/diasurgical/devilutionX). -> When and what can I expect from the upcoming project? - -Honestly I have no idea. More than 1,200 hours went into creating Devilution, and I have other things going on right now. Maybe in 6-12 months? The goal is to create a native Linux port, convert to OpenGL, modernize the UI, etc. you get the drill. There has to be some surprises. ;) > Ok, so I'm playing Devilution now and all the sudden it crashed. NOW WHAT?? Open an issue and provide as much information as possible (OS version, etc.) including any crash logs. > I thought I'd fix the crash myself, but after looking at the code its a disaster. Do you speak v2-34-v8? That is the result of decompiled code. Whenever a program is compiled, much of the source is optimized and stripped away, so it's nearly impossible to decompile it back. Have patience. Everything will be cleaned up eventually. :) -> Will you be reverse engineering Diablo II next? Ooooh please! - -Absolutely not. Diablo II would require far more work and is still supported by Blizzard. Setting that aside, there are rumours that the game will be remastered which takes the point out of it. -> Are you interested in working for me? I have this game I want you to reverse... +> What about Hellfire? -Sorry, but no. This project is time consuming enough as it is, and it's just a hobby. +Hellfire was a bit of a flop on the developer's part. Support may come in the future once the base game is finished. > I think that's about all, but is Devilution even legal? -That's a tricky question. Under the DMCA, reverse-engineering has exceptions for the purpose of documentation and interoperability. Devilution provides the necessary documentation needed to achieve the latter. However, it falls into an entirely grey area. The real question is whether or not Blizzard deems it necessary to take action. +That's a tricky question. Under the DMCA, reverse-engineering has exceptions for the purpose of documentation and interoperability. Devilution provides the necessary documentation needed to achieve the latter. However, it falls into an entirely gray area. The real question is whether or not Blizzard deems it necessary to take action. +
# Credits +- Reverse engineered by GalaXyHaXz in 2018 - [sanctuary](https://github.com/sanctuary) - extensively documenting Diablo's game engine - [BWAPI Team](https://github.com/bwapi) - providing library API to work with Storm - [Ladislav Zezula](https://github.com/ladislav-zezula) - reversing PKWARE library, further documenting Storm @@ -113,14 +112,16 @@ That's a tricky question. Under the DMCA, reverse-engineering has exceptions for - Blizzard North - wait, this was a typo! - Depression - reason to waste four months of my life doing this ;) +And a special thanks to all the support and people who work on this project to make it possible! <3 + # Changelog [From the beginning until release](docs/CHANGELOG.md) # Legal -This software is being released to the Public Domain. No assets of Diablo are being provided. You must own a copy of Diablo and have access to the assets beforehand in order to use this software. +Devilution is released to the Public Domain. The documentation and function provided by Devilution may only be utilized with assets provided by ownership of Diablo. Battle.net(R) - Copyright (C) 1996 Blizzard Entertainment, Inc. All rights reserved. Battle.net and Blizzard Entertainment are trademarks or registered trademarks of Blizzard Entertainment, Inc. in the U.S. and/or other countries. Diablo(R) - Copyright (C) 1996 Blizzard Entertainment, Inc. All rights reserved. Diablo and Blizzard Entertainment are trademarks or registered trademarks of Blizzard Entertainment, Inc. in the U.S. and/or other countries. -This software is in no way associated with or endorsed by Blizzard Entertainment(R). +Devilution and any of its' maintainers are in no way associated with or endorsed by Blizzard Entertainment(R).