From 6677d14daf83142977c953dccb08879e8dd6127e Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 18 Mar 2019 20:25:30 +0100 Subject: [PATCH 01/30] MoveMissilePos almost bin exact (flipped 1line) --- Source/missiles.cpp | 79 +++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 889a72da2..6e3e8720f 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -646,7 +646,7 @@ void __fastcall DeleteMissile(int mi, int i) void __fastcall GetMissileVel(int i, int sx, int sy, int dx, int dy, int v) { - double dxp,dyp,dr; + double dxp, dyp, dr; if (dx != sx || dy != sy) { dxp = (dx + sy - sx - dy) << 21; @@ -726,43 +726,47 @@ void __fastcall GetMissilePos(int i) void __fastcall MoveMissilePos(int i) { - int v1; // esi - signed int v2; // ebx - signed int v3; // edi - //signed int v4; // [esp+Ch] [ebp-4h] + int dx,dy; - v1 = i; switch (missile[i]._mimfnum) { - case 0: - case 1: - case 7: - v2 = 1; - goto LABEL_3; - case 2: - v2 = 0; - LABEL_3: - v3 = 1; + case DIR_S: + dx = 1; + dy = 1; break; - case 3: - case 4: - case 5: - v2 = 0; - goto LABEL_7; - case 6: - v2 = 1; - LABEL_7: - v3 = 0; + case DIR_SW: + dx = 1; + dy = 1; break; - default: - v2 = 0; // v4; /* check */ - v3 = 0; // v4; + case DIR_W: + dx = 0; + dy = 1; + break; + case DIR_NW: + dx = 0; + dy = 0; + break; + case DIR_N: + dx = 0; + dy = 0; + break; + case DIR_NE: + dx = 0; + dy = 0; + break; + case DIR_E: + dx = 1; + dy = 0; + break; + case DIR_SE: + dx = 1; + dy = 1; break; } - if (PosOkMonst(missile[v1]._misource, v2 + missile[v1]._mix, v3 + missile[v1]._miy)) { - missile[v1]._mix += v2; - missile[v1]._miy += v3; - missile[v1]._mixoff += 32 * v3 - 32 * v2; - missile[v1]._miyoff -= 16 * v2 + 16 * v3; + if (PosOkMonst(missile[i]._misource, missile[i]._mix + dx,missile[i]._miy + dy)) { + missile[i]._mix += dx; + missile[i]._miy += dy; + missile[i]._mixoff += (dy << 5) - (dx << 5); + missile[i]._miyoff -= (dy << 4) + (dx << 4); } } @@ -2156,7 +2160,7 @@ BOOL __fastcall CheckIfTrig(int x, int y) { int i; - for (i = 0; i < trigflag[4]; i++){ + for (i = 0; i < trigflag[4]; i++) { if ((x == trigs[i]._tx && y == trigs[i]._ty) || (abs(trigs[i]._tx - x) < 2 && abs(trigs[i]._ty - y) < 2)) return TRUE; } @@ -2168,7 +2172,6 @@ void __fastcall AddTown(int mi, int sx, int sy, int dx, int dy, int midir, int m int i, j, k, mx, tx, ty; int CrawlNum[6] = { 0, 3, 12, 45, 94, 159 }; - tx = dx; if (currlevel) { missile[mi]._miDelFlag = TRUE; @@ -3340,14 +3343,14 @@ void __fastcall MI_Dummy(int i) void __fastcall MI_Golem(int i) { int CrawlNum[6] = { 0, 3, 12, 45, 94, 159 }; - int tx, ty, dp, l,m, src, k, tid; + int tx, ty, dp, l, m, src, k, tid; src = missile[i]._misource; if (monster[src]._mx == 1 && !monster[src]._my) { for (l = 0; l < 6; l++) { k = CrawlNum[l]; tid = k + 2; - for (m = (unsigned char)CrawlTable[k];m > 0; m--){ + for (m = (unsigned char)CrawlTable[k]; m > 0; m--) { tx = missile[i]._miVar4 + CrawlTable[tid - 1]; ty = missile[i]._miVar5 + CrawlTable[tid]; if (0 < tx && tx < MAXDUNX && 0 < ty && ty < MAXDUNY) { @@ -3761,7 +3764,7 @@ void __fastcall MI_Acidpud(int i) void __fastcall MI_Firewall(int i) { - int ExpLight[14] = { 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 12}; + int ExpLight[14] = { 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 12 }; missile[i]._mirange--; if (missile[i]._mirange == missile[i]._miVar1) { @@ -4525,7 +4528,7 @@ void __fastcall MI_Weapexp(int i) void __fastcall MI_Misexp(int i) { - int ExpLight[10]={9, 10, 11, 12, 11, 10, 8, 6, 4, 2}; + int ExpLight[10] = { 9, 10, 11, 12, 11, 10, 8, 6, 4, 2 }; missile[i]._mirange--; if (!missile[i]._mirange) { From 86dc2bcafd85485afc27c9193a7206b719540025 Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 18 Mar 2019 22:22:11 +0100 Subject: [PATCH 02/30] GetDirection16 bin exact (#675) --- Source/missiles.cpp | 69 ++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 6e3e8720f..7a69e020a 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -557,19 +557,7 @@ int __fastcall GetDirection8(int x1, int y1, int x2, int y2) int __fastcall GetDirection16(int x1, int y1, int x2, int y2) { - int v5; // esi - int v6; // eax - int v7; // eax - int result; // eax - char lrtoul[5]; // [esp+10Ch] [ebp-20h] - char urtoll[5]; // [esp+114h] [ebp-18h] - char lltour[5]; // [esp+11Ch] [ebp-10h] - char ultolr[5]; // [esp+124h] [ebp-8h] - - int v9 = y1; - int v4 = x1; - - unsigned char Dirs[16][16] = { + BYTE Dirs[16][16] = { { 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 4, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, @@ -587,45 +575,30 @@ int __fastcall GetDirection16(int x1, int y1, int x2, int y2) { 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2 }, { 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2 } }; + BYTE urtoll[5] = { 6, 7, 8, 9, 10 }; + BYTE ultolr[5] = { 6, 5, 4, 3, 2 }; + BYTE lltour[5] = { 14, 13, 12, 11, 10 }; + BYTE lrtoul[5] = { 14, 15, 0, 1, 2 }; + int mx, my, md; - urtoll[0] = 6; - urtoll[1] = 7; - urtoll[2] = 8; - urtoll[3] = 9; - urtoll[4] = 10; - ultolr[0] = 6; - ultolr[1] = 5; - ultolr[2] = 4; - ultolr[3] = 3; - ultolr[4] = 2; - lltour[0] = 14; - lltour[1] = 13; - lltour[2] = 12; - lltour[3] = 11; - lltour[4] = 10; - lrtoul[0] = 14; - lrtoul[1] = 15; - lrtoul[2] = 0; - lrtoul[3] = 1; - lrtoul[4] = 2; - v5 = abs(x2 - x1); - if (v5 > 15) - v5 = 15; - v6 = abs(y2 - v9); - if (v6 > 15) - v6 = 15; - v7 = Dirs[v6][v5]; - if (v4 <= x2) { - if (v9 <= y2) - result = (unsigned char)lrtoul[v7]; + mx = abs(x2 - x1); + if (mx > 15) + mx = 15; + my = abs(y2 - y1); + if (my > 15) + my = 15; + md = Dirs[my][mx]; + if (x1 > x2) { + if (y1 > y2) + md = urtoll[md]; else - result = (unsigned char)lltour[v7]; - } else if (v9 <= y2) { - result = (unsigned char)ultolr[v7]; + md = ultolr[md]; + } else if (y1 > y2) { + md = lltour[md]; } else { - result = (unsigned char)urtoll[v7]; + md = lrtoul[md]; } - return result; + return md; } void __fastcall DeleteMissile(int mi, int i) From e29da25bd21b123b9b947176192234f6d944fd61 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 00:43:41 +0100 Subject: [PATCH 03/30] MI_Hbolt bin exact (#676) --- Source/missiles.cpp | 69 +++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 7a69e020a..f691f0e9b 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -699,7 +699,7 @@ void __fastcall GetMissilePos(int i) void __fastcall MoveMissilePos(int i) { - int dx,dy; + int dx, dy; switch (missile[i]._mimfnum) { case DIR_S: @@ -735,7 +735,7 @@ void __fastcall MoveMissilePos(int i) dy = 1; break; } - if (PosOkMonst(missile[i]._misource, missile[i]._mix + dx,missile[i]._miy + dy)) { + if (PosOkMonst(missile[i]._misource, missile[i]._mix + dx, missile[i]._miy + dy)) { missile[i]._mix += dx; missile[i]._miy += dy; missile[i]._mixoff += (dy << 5) - (dx << 5); @@ -5161,50 +5161,39 @@ void __fastcall MI_Cbolt(int i) void __fastcall MI_Hbolt(int i) { - int v1; // edi - int v2; // esi - int v3; // eax - int v4; // edx - int v5; // ecx - int v6; // ST10_4 - int v7; // ecx + int dam; - v1 = i; - v2 = i; - --missile[v2]._mirange; - if (_LOBYTE(missile[i]._miAnimType) == MFILE_HOLYEXPL) { - ChangeLight(missile[v2]._mlid, missile[v2]._mix, missile[v2]._miy, missile[v2]._miAnimFrame + 7); - if (!missile[v2]._mirange) { - v7 = missile[v2]._mlid; - missile[v2]._miDelFlag = TRUE; - AddUnLight(v7); - } - } else { - missile[v2]._mitxoff += missile[v2]._mixvel; - missile[v2]._mityoff += missile[v2]._miyvel; + missile[i]._mirange--; + if (missile[i]._miAnimType != MFILE_HOLYEXPL) { + missile[i]._mitxoff += missile[i]._mixvel; + missile[i]._mityoff += missile[i]._miyvel; GetMissilePos(i); - v3 = missile[v2]._mix; - if (v3 != missile[v2]._misx || missile[v2]._miy != missile[v2]._misy) - CheckMissileCol(v1, missile[v2]._midam, missile[v2]._midam, 0, v3, missile[v2]._miy, 0); - if (missile[v2]._mirange) { - v4 = missile[v2]._mix; - if (v4 != missile[v2]._miVar1 || missile[v2]._miy != missile[v2]._miVar2) { - v5 = missile[v2]._mlid; - missile[v2]._miVar1 = v4; - v6 = missile[v2]._miy; - missile[v2]._miVar2 = v6; - ChangeLight(v5, v4, v6, 8); + dam = missile[i]._midam; + if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) { + CheckMissileCol(i, dam, dam, 0, missile[i]._mix, missile[i]._miy, 0); } + if (!missile[i]._mirange) { + missile[i]._mitxoff -= missile[i]._mixvel; + missile[i]._mityoff -= missile[i]._miyvel; + GetMissilePos(i); + missile[i]._mimfnum = 0; + SetMissAnim(i, MFILE_HOLYEXPL); + missile[i]._mirange = missile[i]._miAnimLen - 1; } else { - missile[v2]._mitxoff -= missile[v2]._mixvel; - missile[v2]._mityoff -= missile[v2]._miyvel; - GetMissilePos(v1); - missile[v2]._mimfnum = 0; - SetMissAnim(v1, MFILE_HOLYEXPL); - missile[v2]._mirange = missile[v2]._miAnimLen - 1; + 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, 8); + } + } + } else { + ChangeLight(missile[i]._mlid, missile[i]._mix, missile[i]._miy, missile[i]._miAnimFrame + 7); + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + AddUnLight(missile[i]._mlid); } } - PutMissile(v1); + PutMissile(i); } void __fastcall MI_Element(int i) From a71462516a96a7f66ea69fc4165dc26f7192c4c4 Mon Sep 17 00:00:00 2001 From: sergi4ua Date: Tue, 19 Mar 2019 01:47:42 +0200 Subject: [PATCH 04/30] InitMissileGFX bin exact --- Source/missiles.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index f691f0e9b..9b19f15a8 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1527,19 +1527,12 @@ void __fastcall LoadMissileGFX(BYTE mi) void __cdecl InitMissileGFX() { - char v0; // bl - unsigned char *v1; // esi + int mi; - v0 = 0; - if (misfiledata[0].mAnimFAmt) { - v1 = &misfiledata[0].mAnimFAmt; - do { - if (!(v1[7] & 1)) - LoadMissileGFX(v0); - v1 += 236; - ++v0; - } while (*v1); - } + for (mi = 0; misfiledata[mi].mAnimFAmt; mi++) { + if (!(misfiledata[mi].mFlags & MFLAG_HIDDEN)) + LoadMissileGFX(mi); + } } void __fastcall FreeMissileGFX(int mi) From 1ceeefd289fe584f89404ebb9e165ee2719aa07e Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 00:49:29 +0100 Subject: [PATCH 05/30] FreeMissiles bin exact --- Source/missiles.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 9b19f15a8..8c712ee22 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1569,18 +1569,11 @@ void __fastcall FreeMissileGFX(int mi) void __cdecl FreeMissiles() { - int v0; // edi - unsigned char *v1; // esi + int mi; - v0 = 0; - if (misfiledata[0].mAnimFAmt) { - v1 = &misfiledata[0].mAnimFAmt; - do { - if (!(v1[7] & 1)) - FreeMissileGFX(v0); - v1 += 236; - ++v0; - } while (*v1); + for (mi = 0; misfiledata[mi].mAnimFAmt; mi++) { + if (!(misfiledata[mi].mFlags & MFLAG_HIDDEN)) + FreeMissileGFX(mi); } } @@ -5164,7 +5157,7 @@ void __fastcall MI_Hbolt(int i) dam = missile[i]._midam; if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) { CheckMissileCol(i, dam, dam, 0, missile[i]._mix, missile[i]._miy, 0); - } + } if (!missile[i]._mirange) { missile[i]._mitxoff -= missile[i]._mixvel; missile[i]._mityoff -= missile[i]._miyvel; From aff6ff86d1d0c47e735f7e307a37b9ee329125c5 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 00:54:21 +0100 Subject: [PATCH 06/30] Clean up Items.cpp * Clean up ItemMinStats * Clean up CalcPlrItemMin --- Source/items.cpp | 56 +++++++++++++++++++++++------------------------- Source/items.h | 2 +- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index fd19f153b..1f4d2b750 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1164,41 +1164,39 @@ void __fastcall CalcSelfItems(int pnum) void __fastcall CalcPlrItemMin(int pnum) { - PlayerStruct *v1; // ecx - PlayerStruct *v2; // esi - ItemStruct *v3; // edi - int v4; // ebp - ItemStruct *v6; // edi - signed int v7; // ebp + PlayerStruct *p; + ItemStruct *pi; + int i; - v1 = &plr[pnum]; - v2 = v1; - v3 = v1->InvList; - if (v1->_pNumInv) { - v4 = v1->_pNumInv; - do { - v3->_iStatFlag = ItemMinStats(v2, v3); - ++v3; - --v4; - } while (v4); + p = &plr[pnum]; + pi = p->InvList; + + for (i = p->_pNumInv; i; i--) { + pi->_iStatFlag = ItemMinStats(p, pi); + pi++; } - v6 = v2->SpdList; - v7 = MAXBELTITEMS; - do { - if (v6->_itype != -1) { - v6->_iStatFlag = ItemMinStats(v2, v6); + + pi = p->SpdList; + for (i = MAXBELTITEMS; i != 0; i--) { + if (pi->_itype != -1) { + pi->_iStatFlag = ItemMinStats(p, pi); } - ++v6; - --v7; - } while (v7); + pi++; + } } -BOOLEAN __fastcall ItemMinStats(PlayerStruct *p, ItemStruct *x) +BOOL __fastcall ItemMinStats(PlayerStruct *p, ItemStruct *x) { - if (p->_pStrength < x->_iMinStr || p->_pMagic < x->_iMinMag || p->_pDexterity < x->_iMinDex) - return 0; - else - return 1; + if (p->_pMagic < x->_iMinMag) + return FALSE; + + if (p->_pStrength < x->_iMinStr) + return FALSE; + + if (p->_pDexterity < x->_iMinDex) + return FALSE; + + return TRUE; } void __fastcall CalcPlrBookVals(int p) diff --git a/Source/items.h b/Source/items.h index e8c86fbab..e19e92f94 100644 --- a/Source/items.h +++ b/Source/items.h @@ -23,7 +23,7 @@ void __fastcall CalcPlrScrolls(int p); void __fastcall CalcPlrStaff(int pnum); void __fastcall CalcSelfItems(int pnum); void __fastcall CalcPlrItemMin(int pnum); -BOOLEAN __fastcall ItemMinStats(PlayerStruct *p, ItemStruct *x); +BOOL __fastcall ItemMinStats(PlayerStruct *p, ItemStruct *x); void __fastcall CalcPlrBookVals(int p); void __fastcall CalcPlrInv(int p, BOOL Loadgfx); void __fastcall SetPlrHandItem(ItemStruct *h, int idata); From 3aa8319d9b1a09df83116a5f5ccdf67c8ce1d5da Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 00:53:38 +0100 Subject: [PATCH 07/30] FreeMissiles2 bin exact --- Source/missiles.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 8c712ee22..ff44283f9 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1579,18 +1579,11 @@ void __cdecl FreeMissiles() void __cdecl FreeMissiles2() { - int v0; // edi - unsigned char *v1; // esi + int mi; - v0 = 0; - if (misfiledata[0].mAnimFAmt) { - v1 = &misfiledata[0].mAnimFAmt; - do { - if (v1[7] & 1) - FreeMissileGFX(v0); - v1 += 236; - ++v0; - } while (*v1); + for (mi = 0; misfiledata[mi].mAnimFAmt; mi++) { + if (misfiledata[mi].mFlags & MFLAG_HIDDEN) + FreeMissileGFX(mi); } } From 2e42493a7b7d5172d107599acb31b74a08464a2e Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 02:22:03 +0100 Subject: [PATCH 08/30] LoadMissileGFX bin exact (#682) * LoadMissileGFX bin exact --- Source/missiles.cpp | 64 ++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 44 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index ff44283f9..436db34db 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1473,53 +1473,29 @@ void __fastcall SetMissDir(int mi, int dir) SetMissAnim(mi, missile[mi]._miAnimType); } -// TODO: replace `int mi` parameter with `missile_graphic_id mi` -// to enable the compiler to optimize int to char properly -// check for example the calls in `InitMonsterGFX` void __fastcall LoadMissileGFX(BYTE mi) { - MisFileData *v1; // esi - unsigned char *v2; // eax - signed int v3; // ecx - int *v4; // edx - int v5; // edi - unsigned char v6; // cl - int v7; // eax - _DWORD *v8; // edi - int v9; // ebx - char arglist[256]; // [esp+8h] [ebp-100h] - - v1 = &misfiledata[(unsigned char)mi]; - if (v1->mFlags & MFLAG_ALLOW_SPECIAL) { - sprintf(arglist, "Missiles\\%s.CL2", v1->mName); - v2 = LoadFileInMem(arglist, 0); - v3 = 0; - if (v1->mAnimFAmt) { - v4 = (int *)v1->mAnimData; - do { - v5 = (int)&v2[*(_DWORD *)&v2[4 * v3++]]; - *v4 = v5; - ++v4; - } while (v3 < v1->mAnimFAmt); - } + char pszName[256]; + int i; + BYTE *file; + MisFileData *mfd; + + mfd = &misfiledata[mi]; + if (mfd->mFlags & MFLAG_ALLOW_SPECIAL) { + sprintf(pszName, "Missiles\\%s.CEL", mfd->mName); + file = LoadFileInMem(pszName, 0); + for (i = 0; i < mfd->mAnimFAmt; i++) + mfd->mAnimData[i] = &file[((int *)file)[i]]; + } else if (mfd->mAnimFAmt == 1) { + sprintf(pszName, "Missiles\\%s.CEL", mfd->mName); + if (!mfd->mAnimData[0]) + mfd->mAnimData[0] = LoadFileInMem(pszName, 0); } else { - v6 = v1->mAnimFAmt; - if (v6 == 1) { - sprintf(arglist, "Missiles\\%s.CL2", v1->mName); - if (!v1->mAnimData[0]) - v1->mAnimData[0] = LoadFileInMem(arglist, 0); - } else { - v7 = 0; - if (v6) { - v8 = (unsigned int *)v1->mAnimData; - do { - v9 = v7 + 1; - sprintf(arglist, "Missiles\\%s%i.CL2", v1->mName, v7 + 1); - if (!*v8) - *v8 = (unsigned int)LoadFileInMem(arglist, 0); - v7 = v9; - ++v8; - } while (v9 < v1->mAnimFAmt); + for (i = 0; i < mfd->mAnimFAmt; i++) { + sprintf(pszName, "Missiles\\%s%i.CEL", mfd->mName, i + 1); + if (!mfd->mAnimData[i]) { + file = LoadFileInMem(pszName, 0); + mfd->mAnimData[i] = file; } } } From e2090503e110f842eec984df97fcfbc4c8e600b2 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 03:37:23 +0100 Subject: [PATCH 09/30] InitMissiles bin exact (#686) --- Source/missiles.cpp | 75 +++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 436db34db..537b8fd6e 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1503,12 +1503,12 @@ void __fastcall LoadMissileGFX(BYTE mi) void __cdecl InitMissileGFX() { - int mi; + int mi; - for (mi = 0; misfiledata[mi].mAnimFAmt; mi++) { - if (!(misfiledata[mi].mFlags & MFLAG_HIDDEN)) - LoadMissileGFX(mi); - } + for (mi = 0; misfiledata[mi].mAnimFAmt; mi++) { + if (!(misfiledata[mi].mFlags & MFLAG_HIDDEN)) + LoadMissileGFX(mi); + } } void __fastcall FreeMissileGFX(int mi) @@ -1565,54 +1565,35 @@ void __cdecl FreeMissiles2() void __cdecl InitMissiles() { - int v0; // eax - int i; // esi - int v2; // eax - int v3; // eax - int v4; // edx - int *v5; // eax - signed int v6; // ecx - _BYTE *v7; // eax - signed int v8; // edx - - v0 = myplr; - _LOBYTE(plr[v0]._pSpellFlags) &= 0xFEu; - if (plr[v0]._pInfraFlag == 1) { + int mi, src, i, j; + + plr[myplr]._pSpellFlags &= ~0x1; + if (plr[myplr]._pInfraFlag == TRUE) { for (i = 0; i < nummissiles; ++i) { - v2 = missileactive[i]; - if (missile[v2]._mitype == MIS_INFRA) { - v3 = missile[v2]._misource; - if (v3 == myplr) - CalcPlrItemVals(v3, 1); + mi = missileactive[i]; + if (missile[mi]._mitype == MIS_INFRA) { + src = missile[mi]._misource; + if (src == myplr) + CalcPlrItemVals(src, 1); } } } - v4 = 0; - memset(missileactive, 0, sizeof(missileactive)); nummissiles = 0; - do { - missileavail[v4] = v4; - ++v4; - } while (v4 < MAXMISSILES); + for (i = 0; i < MAXMISSILES; i++) { + missileavail[i] = i; + missileactive[i] = 0; + } numchains = 0; - v5 = &chain[0]._mitype; - do { - *(v5 - 1) = -1; - *v5 = 0; - v5[1] = 0; - v5 += 3; - } while ((signed int)v5 < (signed int)&chain[MAXMISSILES]._mitype); - v6 = 0; - do { - v7 = (unsigned char *)dFlags + v6; - v8 = 112; - do { - *v7 &= ~DFLAG_MISSILE; - v7 += 112; - --v8; - } while (v8); - ++v6; - } while (v6 < 112); + for (i = 0; i < MAXMISSILES; i++) { + chain[i].idx = -1; + chain[i]._mitype = 0; + chain[i]._mirange = 0; + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) { + dFlags[i][j] &= ~DFLAG_MISSILE; + } + } } // 64CCD8: using guessed type int numchains; From 87a0846a38cbe414acd0875bfc5636be72a13e3f Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Mon, 18 Mar 2019 22:24:23 -0500 Subject: [PATCH 10/30] Clean CPrintString + Font index (#687) --- Source/control.cpp | 498 +++++++++++++++++++++++++++----------------- Source/control.h | 6 +- Source/error.cpp | 4 +- Source/gmenu.cpp | 4 +- Source/help.cpp | 6 +- Source/inv.cpp | 2 +- Source/items.cpp | 4 +- Source/minitext.cpp | 4 +- Source/plrmsg.cpp | 4 +- Source/quests.cpp | 4 +- Source/stores.cpp | 8 +- 11 files changed, 334 insertions(+), 210 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index ebe526221..71ef87252 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -19,7 +19,7 @@ int dropGoldValue; // idb BOOL drawmanaflag; // idb BOOL chrbtnactive; char sgszTalkMsg[80]; -void *pPanelText; +BYTE *pPanelText; int frame_4B8800; // idb char *pLifeBuff; void *pBtmBuff; @@ -109,33 +109,23 @@ const int lineoffset[25] = { 768 * 606 + 241, 768 * 617 + 241 }; -const unsigned char fontidx[256] = { - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, - 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 1, 67, 117, - 101, 97, 97, 97, 97, 99, 101, 101, 101, 105, - 105, 105, 65, 65, 69, 97, 65, 111, 111, 111, - 117, 117, 121, 79, 85, 99, 76, 89, 80, 102, - 97, 105, 111, 117, 110, 78, 97, 111, 63, 1, - 1, 1, 1, 33, 60, 62, 111, 43, 50, 51, - 39, 117, 80, 46, 44, 49, 48, 62, 1, 1, - 1, 63, 65, 65, 65, 65, 65, 65, 65, 67, - 69, 69, 69, 69, 73, 73, 73, 73, 68, 78, - 79, 79, 79, 79, 79, 88, 48, 85, 85, 85, - 85, 89, 98, 66, 97, 97, 97, 97, 97, 97, - 97, 99, 101, 101, 101, 101, 105, 105, 105, 105, - 111, 110, 111, 111, 111, 111, 111, 47, 48, 117, - 117, 117, 117, 121, 98, 121 +const unsigned char gbFontTransTbl[256] = { + '\0', 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0x01, + 'C', 'u', 'e', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'i', 'i', 'i', 'A', 'A', + 'E', 'a', 'A', 'o', 'o', 'o', 'u', 'u', 'y', 'O', 'U', 'c', 'L', 'Y', 'P', 'f', + 'a', 'i', 'o', 'u', 'n', 'N', 'a', 'o', '?', 0x01, 0x01, 0x01, 0x01, '!', '<', '>', + 'o', '+', '2', '3', '\'', 'u', 'P', '.', ',', '1', '0', '>', 0x01, 0x01, 0x01, '?', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', + 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'X', '0', 'U', 'U', 'U', 'U', 'Y', 'b', 'B', + 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', + 'o', 'n', 'o', 'o', 'o', 'o', 'o', '/', '0', 'u', 'u', 'u', 'u', 'y', 'b', 'y' }; /* data */ @@ -660,162 +650,296 @@ void __fastcall ToggleSpell(int slot) } // 52571C: using guessed type int drawpanflag; -void __fastcall CPrintString(int No, unsigned int glyph, unsigned char col) +void __fastcall CPrintString(int nOffset, int nCel, char col) { - int *v3; // ebx - char *v4; // esi - char *v5; // edi - int v6; // ebx - signed int v7; // edx - unsigned int v8; // eax - unsigned int v9; // ecx - char v10; // cf - unsigned int v11; // ecx - signed int v12; // edx - int v13; // eax - int v14; // ecx - char v15; // al - signed int v16; // edx - int v17; // eax - int v18; // ecx - char v19; // al - signed int v20; // edx - int v21; // eax - int v22; // ecx - char v23; // al - - v3 = (int *)((char *)pPanelText + 4 * glyph); - v4 = (char *)pPanelText + *v3; - v5 = (char *)gpBuffer + No; - v6 = (int)&v4[v3[1] - *v3]; - if ((_BYTE)col) { - if ((unsigned char)col == 1) { - do { - v12 = 13; - do { - while (1) { - v13 = (unsigned char)*v4++; - if ((v13 & 0x80u) == 0) - break; - _LOBYTE(v13) = -(char)v13; - v5 += v13; - v12 -= v13; - if (!v12) - goto LABEL_28; + /// ASSERT: assert(gpBuffer); + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov ebx, pPanelText + mov eax, nCel + shl eax, 2 + add ebx, eax + mov edx, [ebx+4] + sub edx, [ebx] + mov esi, pPanelText + add esi, [ebx] + mov edi, gpBuffer + add edi, nOffset + mov ebx, edx + add ebx, esi + xor edx, edx + mov dl, col + cmp edx, COL_WHITE + jz c0_label1 + cmp edx, COL_BLUE + jz c1_label1 + cmp edx, COL_RED + jz c2_label1 + jmp d_label1 + + // Case 0 + c0_label1: + mov edx, 13 + c0_label2: + xor eax, eax + lodsb + or al, al + js c0_label6 + sub edx, eax + mov ecx, eax + shr ecx, 1 + jnb c0_label3 + movsb + jecxz c0_label5 + c0_label3: + shr ecx, 1 + jnb c0_label4 + movsw + jecxz c0_label5 + c0_label4: + rep movsd + c0_label5: + or edx, edx + jz c0_label7 + jmp c0_label2 + c0_label6: + neg al + add edi, eax + sub edx, eax + jnz c0_label2 + c0_label7: + sub edi, 768 + 13 + cmp ebx, esi + jnz c0_label1 + jmp labret + + // Case 1 + c1_label1: + mov edx, 13 + c1_label2: + xor eax, eax + lodsb + or al, al + js c1_label6 + sub edx, eax + mov ecx, eax + c1_label3: + lodsb + cmp al, PAL16_GRAY + 13 + ja c1_label4 + cmp al, PAL16_GRAY + jb c1_label5 + sub al, PAL16_GRAY - (PAL16_BLUE + 2) + jmp c1_label5 + c1_label4: + mov al, PAL16_BLUE + 15 + c1_label5: + stosb + loop c1_label3 + or edx, edx + jz c1_label7 + jmp c1_label2 + c1_label6: + neg al + add edi, eax + sub edx, eax + jnz c1_label2 + c1_label7: + sub edi, 768 + 13 + cmp ebx, esi + jnz c1_label1 + jmp labret + + // Case 2 + c2_label1: + mov edx, 13 + c2_label2: + xor eax, eax + lodsb + or al, al + js c2_label5 + sub edx, eax + mov ecx, eax + c2_label3: + lodsb + cmp al, PAL16_GRAY + jb c2_label4 + sub al, PAL16_GRAY - PAL16_RED + c2_label4: + stosb + loop c2_label3 + or edx, edx + jz c2_label6 + jmp c2_label2 + c2_label5: + neg al + add edi, eax + sub edx, eax + jnz c2_label2 + c2_label6: + sub edi, 768 + 13 + cmp ebx, esi + jnz c2_label1 + jmp labret + + // Default + d_label1: + mov edx, 13 + d_label2: + xor eax, eax + lodsb + or al, al + js d_label6 + sub edx, eax + mov ecx, eax + d_label3: + lodsb + cmp al, PAL16_GRAY + jb d_label5 + cmp al, PAL16_GRAY + 14 + jnb d_label4 + sub al, PAL16_GRAY - (PAL16_YELLOW + 2) + jmp d_label5 + d_label4: + mov al, PAL16_YELLOW + 15 + d_label5: + stosb + loop d_label3 + or edx, edx + jz d_label7 + jmp d_label2 + d_label6: + neg al + add edi, eax + sub edx, eax + jnz d_label2 + d_label7: + sub edi, 768 + 13 + cmp ebx, esi + jnz d_label1 + + labret: + } +#else + int i; + BYTE width, pix; + BYTE *src, *dst, *end; + DWORD *pFrameTable; + + pFrameTable = (DWORD *)&pPanelText[4 * nCel]; + src = &pPanelText[pFrameTable[0]]; + end = &src[pFrameTable[1] - pFrameTable[0]]; + dst = &gpBuffer[nOffset]; + + switch(col) { + case COL_WHITE: + for(; src != end; dst -= 768 + 13) { + for(i = 13; i;) { + width = *src++; + if(!(width & 0x80)) { + i -= width; + if(width & 1) { + dst[0] = src[0]; + src++; + dst++; } - v12 -= v13; - v14 = v13; - do { - v15 = *v4++; - if ((unsigned char)v15 > 0xFDu) { - v15 = -65; - } else if ((unsigned char)v15 >= 0xF0u) { - v15 -= 62; - } - *v5++ = v15; - --v14; - } while (v14); - } while (v12); - LABEL_28: - v5 -= 781; - } while ((char *)v6 != v4); - } else if ((unsigned char)col == 2) { - do { - v16 = 13; - do { - while (1) { - v17 = (unsigned char)*v4++; - if ((v17 & 0x80u) == 0) - break; - _LOBYTE(v17) = -(char)v17; - v5 += v17; - v16 -= v17; - if (!v16) - goto LABEL_39; + width >>= 1; + if(width & 1) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 2; + dst += 2; } - v16 -= v17; - v18 = v17; - do { - v19 = *v4++; - if ((unsigned char)v19 >= 0xF0u) - v19 -= 16; - *v5++ = v19; - --v18; - } while (v18); - } while (v16); - LABEL_39: - v5 -= 781; - } while ((char *)v6 != v4); - } else { - do { - v20 = 13; - do { - while (1) { - v21 = (unsigned char)*v4++; - if ((v21 & 0x80u) == 0) - break; - _LOBYTE(v21) = -(char)v21; - v5 += v21; - v20 -= v21; - if (!v20) - goto LABEL_52; + width >>= 1; + while(width) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + src += 4; + dst += 4; + width--; } - v20 -= v21; - v22 = v21; - do { - v23 = *v4++; - if ((unsigned char)v23 >= 0xF0u) { - if ((unsigned char)v23 >= 0xFEu) - v23 = -49; - else - v23 -= 46; - } - *v5++ = v23; - --v22; - } while (v22); - } while (v20); - LABEL_52: - v5 -= 781; - } while ((char *)v6 != v4); + } else { + width = -(char)width; + dst += width; + i -= width; + } + } } - } else { - do { - v7 = 13; - do { - while (1) { - v8 = (unsigned char)*v4++; - if ((v8 & 0x80u) == 0) - break; - _LOBYTE(v8) = -(char)v8; - v5 += v8; - v7 -= v8; - if (!v7) - goto LABEL_15; + break; + case COL_BLUE: + for(; src != end; dst -= 768 + 13) { + for(i = 13; i;) { + width = *src++; + if(!(width & 0x80)) { + i -= width; + while(width) { + pix = *src++; + if(pix > PAL16_GRAY + 13) + pix = PAL16_BLUE + 15; + else if(pix >= PAL16_GRAY) + pix -= PAL16_GRAY - (PAL16_BLUE + 2); + *dst++ = pix; + width--; + } + } else { + width = -(char)width; + dst += width; + i -= width; } - v7 -= v8; - v9 = v8 >> 1; - if (v8 & 1) { - *v5++ = *v4++; - if (!v9) - continue; + } + } + break; + case COL_RED: + for(; src != end; dst -= 768 + 13) { + for(i = 13; i;) { + width = *src++; + if(!(width & 0x80)) { + i -= width; + while(width) { + pix = *src++; + if(pix >= PAL16_GRAY) + pix -= PAL16_GRAY - PAL16_RED; + *dst++ = pix; + width--; + } + } else { + width = -(char)width; + dst += width; + i -= width; } - v10 = v9 & 1; - v11 = v8 >> 2; - if (v10) { - *(_WORD *)v5 = *(_WORD *)v4; - v4 += 2; - v5 += 2; - if (!v11) - continue; + } + } + break; + default: + for(; src != end; dst -= 768 + 13) { + for(i = 13; i;) { + width = *src++; + if(!(width & 0x80)) { + i -= width; + while(width) { + pix = *src++; + if(pix >= PAL16_GRAY) { + if(pix >= PAL16_GRAY + 14) + pix = PAL16_YELLOW + 15; + else + pix -= PAL16_GRAY - (PAL16_YELLOW + 2); + } + *dst++ = pix; + width--; + } + } else { + width = -(char)width; + dst += width; + i -= width; } - qmemcpy(v5, v4, 4 * v11); - v4 += 4 * v11; - v5 += 4 * v11; - } while (v7); - LABEL_15: - v5 -= 781; - } while ((char *)v6 != v4); + } + } + break; } +#endif } void __fastcall AddPanelString(char *str, BOOL just) @@ -1558,7 +1682,7 @@ int __fastcall control_WriteStringToBuffer(char *str) if (!*str) return 1; ++str; - v1 += fontkern[fontframe[fontidx[v2]]]; + v1 += fontkern[fontframe[gbFontTransTbl[v2]]]; } while (v1 < 125); return 0; } @@ -1694,7 +1818,7 @@ void __fastcall control_print_info_str(int y, char *str, BOOLEAN center, int lin goto LABEL_14; do { ++v8; - v7 += fontkern[fontframe[fontidx[v6]]] + 2; + v7 += fontkern[fontframe[gbFontTransTbl[v6]]] + 2; v6 = *v8; } while (*v8); if (v7 < 288) @@ -1707,7 +1831,7 @@ void __fastcall control_print_info_str(int y, char *str, BOOLEAN center, int lin if (!*v5) break; ++v5; - v9 = fontidx[v11]; + v9 = gbFontTransTbl[v11]; _LOBYTE(v9) = fontframe[v9]; v10 = (unsigned char)v9; v4 += fontkern[(unsigned char)v9] + 2; @@ -1732,7 +1856,7 @@ void __fastcall PrintGameStr(int x, int y, char *str, int color) v5 = screen_y_times_768[y + 160] + x + 64; for (i = *str; *v4; i = *v4) { ++v4; - v7 = fontframe[fontidx[i]]; + v7 = fontframe[gbFontTransTbl[i]]; if (v7) CPrintString(v5, v7, color); v5 += fontkern[v7] + 1; @@ -1989,7 +2113,7 @@ void __fastcall ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col) v11 = *pszStr; do { ++v6; - v10 += fontkern[fontframe[fontidx[v11]]] + 1; + v10 += fontkern[fontframe[gbFontTransTbl[v11]]] + 1; v11 = *v6; } while (*v6); } @@ -1998,7 +2122,7 @@ void __fastcall ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col) widthb = v9 + widtha; while (v7) { ++pszStr; - v12 = fontframe[fontidx[v7]]; + v12 = fontframe[gbFontTransTbl[v7]]; v13 = v12; v9 += fontkern[v12] + 1; if (v12) { @@ -2035,7 +2159,7 @@ void __fastcall MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, v11 = *pszStr; do { ++v10; - v8 += base + fontkern[fontframe[fontidx[v11]]]; + v8 += base + fontkern[fontframe[gbFontTransTbl[v11]]]; v11 = *v10; } while (*v10); } @@ -2044,7 +2168,7 @@ void __fastcall MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, widthb = v16 + widtha; while (v7) { ++v6; - v12 = fontframe[fontidx[v7]]; + v12 = fontframe[gbFontTransTbl[v7]]; v13 = v12; v16 += base + fontkern[v12]; if (v12) { @@ -2413,7 +2537,7 @@ void __fastcall PrintSBookStr(int x, int y, BOOLEAN cjustflag, char *pszStr, int goto LABEL_14; do { ++v9; - v6 += fontkern[fontframe[fontidx[v8]]] + 1; + v6 += fontkern[fontframe[gbFontTransTbl[v8]]] + 1; v8 = *v9; } while (*v9); if (v6 < 222) @@ -2426,7 +2550,7 @@ void __fastcall PrintSBookStr(int x, int y, BOOLEAN cjustflag, char *pszStr, int if (!*v5) break; ++v5; - v10 = fontframe[fontidx[v12]]; + v10 = fontframe[gbFontTransTbl[v12]]; v11 = v10; v7 += fontkern[v10] + 1; if (v10) { @@ -2496,7 +2620,7 @@ void __fastcall DrawGoldSplit(int amount) v3 = tempstr[0]; for (i = 0; i < v3; v3 = tempstr[i]) { ++i; - screen_x += fontkern[fontframe[fontidx[(unsigned char)v3]]] + 1; + screen_x += fontkern[fontframe[gbFontTransTbl[(unsigned char)v3]]] + 1; } screen_xa = screen_x + 452; } @@ -2701,7 +2825,7 @@ char *__fastcall control_print_talk_msg(char *msg, int x, int y, int *a4, int ju if (!v7) return 0; while (1) { - v10 = fontframe[fontidx[v7]]; + v10 = fontframe[gbFontTransTbl[v7]]; v11 = v10; a3 = v8 + fontkern[v10] + 1; if (a3 > 514) diff --git a/Source/control.h b/Source/control.h index 23299e68c..878490e75 100644 --- a/Source/control.h +++ b/Source/control.h @@ -15,7 +15,7 @@ extern int lvlbtndown; // weak extern int dropGoldValue; // idb extern BOOL drawmanaflag; // idb extern BOOL chrbtnactive; -extern void *pPanelText; +extern BYTE *pPanelText; extern int frame_4B8800; // idb extern char *pLifeBuff; extern void *pBtmBuff; @@ -60,7 +60,7 @@ void __cdecl DrawSpellList(); void __cdecl SetSpell(); void __fastcall SetSpeedSpell(int slot); void __fastcall ToggleSpell(int slot); -void __fastcall CPrintString(int No, unsigned int glyph, unsigned char col); /* check arg names */ +void __fastcall CPrintString(int nOffset, int nCel, char col); 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); @@ -123,7 +123,7 @@ void __fastcall control_up_down(char a1); extern const unsigned char fontframe[127]; extern const unsigned char fontkern[68]; extern const int lineoffset[25]; -extern const unsigned char fontidx[256]; +extern const unsigned char gbFontTransTbl[256]; /* data */ diff --git a/Source/error.cpp b/Source/error.cpp index 6c0952131..d4ae5e3d2 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -135,7 +135,7 @@ void __cdecl DrawDiabloMsg() goto LABEL_27; do { v12 = (unsigned char)tempstr[v11++]; - v10 += fontkern[fontframe[fontidx[v12]]] + 1; + v10 += fontkern[fontframe[gbFontTransTbl[v12]]] + 1; } while (v11 < v9); if (v10 < 442) LABEL_27: @@ -143,7 +143,7 @@ void __cdecl DrawDiabloMsg() v13 = 0; if (v9 > 0) { do { - v14 = fontframe[fontidx[(unsigned char)tempstr[v13]]]; + v14 = fontframe[gbFontTransTbl[(unsigned char)tempstr[v13]]]; if (v14) CPrintString(v8, v14, 3); ++v13; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index f41ff3e7a..09cb8bc7f 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -63,7 +63,7 @@ void __fastcall gmenu_print_text(int x, int y, char *pszStr) v5 = x; for (i = *pszStr; *v3; i = *v3) { ++v3; - v7 = lfontframe[fontidx[i]]; + v7 = lfontframe[gbFontTransTbl[i]]; if (v7) CelDecodeLightOnly(v5, v4, (BYTE *)BigTGold_cel, v7, 46); v5 += lfontkern[v7] + 2; @@ -280,7 +280,7 @@ int __fastcall gmenu_get_lfont(TMenuItem *pItem) if (pItem->dwFlags & 0x40000000) return 490; v2 = pItem->pszStr; - for (i = 0;; i += lfontkern[lfontframe[fontidx[v4]]] + 2) { + for (i = 0;; i += lfontkern[lfontframe[gbFontTransTbl[v4]]] + 2) { v4 = *v2; if (!*v2) break; diff --git a/Source/help.cpp b/Source/help.cpp index c04fec503..c7a22ddd2 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -129,7 +129,7 @@ void __cdecl DrawHelp() } v5 = *v1; tempstr[v2++] = *v1++; - v3 += fontkern[fontframe[fontidx[v5]]] + 1; + v3 += fontkern[fontframe[gbFontTransTbl[v5]]] + 1; v4 = *v1; if (*v1 == ('|')) { if (v3 < 577) @@ -173,7 +173,7 @@ void __cdecl DrawHelp() } v10 = *v1; tempstr[v7++] = *v1++; - v8 += fontkern[fontframe[fontidx[v10]]] + 1; + v8 += fontkern[fontframe[gbFontTransTbl[v10]]] + 1; v9 = *v1; if (*v1 == ('|')) { if (v8 < 577) @@ -212,7 +212,7 @@ void __fastcall DrawHelpLine(int always_0, int help_line_nr, char *text, text_co v5 = screen_y_times_768[SStringY[help_line_nr] + 204] + always_0 + 96; for (i = *text; *text; i = *text) { ++text; - v7 = fontframe[fontidx[i]]; + v7 = fontframe[gbFontTransTbl[i]]; v8 = v7; v4 += fontkern[v7] + 1; if (v7) { diff --git a/Source/inv.cpp b/Source/inv.cpp index 403421673..dc7a2cc6f 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -430,7 +430,7 @@ void __cdecl DrawInvBelt() && plr[myplr].SpdList[i]._iStatFlag && plr[myplr].SpdList[i]._itype != ITYPE_GOLD) { fi = i + 49; - ff = fontframe[fontidx[fi]]; + ff = fontframe[gbFontTransTbl[fi]]; CPrintString(InvRect[i + 65].X + 64 + screen_y_times_768[InvRect[i + 65].Y + 159] - fontkern[ff] + 28, ff, 0); } } diff --git a/Source/items.cpp b/Source/items.cpp index 1f4d2b750..3b1caf384 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3730,7 +3730,7 @@ void __fastcall PrintUString(int x, int y, int cjustflag, char *str, int col) goto LABEL_16; do { v11 = (unsigned char)str[v9++]; - v10 += fontkern[fontframe[fontidx[v11]]] + 1; + v10 += fontkern[fontframe[gbFontTransTbl[v11]]] + 1; } while (v9 < v15); if (v10 < 257) LABEL_16: @@ -3741,7 +3741,7 @@ void __fastcall PrintUString(int x, int y, int cjustflag, char *str, int col) a3 = 0; if (v15 > 0) { while (1) { - v13 = fontframe[fontidx[(unsigned char)v5[v12]]]; + v13 = fontframe[gbFontTransTbl[(unsigned char)v5[v12]]]; v14 = v13; v8 += fontkern[v13] + 1; if (v13) { diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 425b79ac0..07d3ed596 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -244,7 +244,7 @@ void __cdecl DrawQText() if (*i == 124 || v1 >= 543) break; v4 = *i++; - v5 = fontidx[v4]; + v5 = gbFontTransTbl[v4]; if (v5) { qstr[v2] = v5; v1 += mfontkern[mfontframe[v5]] + 2; @@ -269,7 +269,7 @@ void __cdecl DrawQText() v9 = qstr; do { ++v0; - v10 = mfontframe[fontidx[v8]]; + v10 = mfontframe[gbFontTransTbl[v8]]; if (*v0 == 10) ++v0; if (v10) diff --git a/Source/plrmsg.cpp b/Source/plrmsg.cpp index aa6015e6e..8e80425a2 100644 --- a/Source/plrmsg.cpp +++ b/Source/plrmsg.cpp @@ -118,7 +118,7 @@ void __fastcall PrintPlrMsg(unsigned int x, unsigned int y, unsigned int width, while (1) { if (*sstr) { - c = fontidx[(unsigned char)*sstr++]; + c = gbFontTransTbl[(unsigned char)*sstr++]; c = fontframe[c]; len += fontkern[c] + 1; if (!c) // allow wordwrap on blank glyph @@ -132,7 +132,7 @@ void __fastcall PrintPlrMsg(unsigned int x, unsigned int y, unsigned int width, } while (str < endstr) { - c = fontidx[(unsigned char)*str++]; + c = gbFontTransTbl[(unsigned char)*str++]; c = fontframe[c]; if (c) CPrintString(screen, c, col); diff --git a/Source/quests.cpp b/Source/quests.cpp index 45dedf12a..84a68a547 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -929,7 +929,7 @@ void __fastcall PrintQLString(int x, int y, unsigned char cjustflag, char *str, goto LABEL_24; do { v11 = (unsigned char)str[v9++]; - v10 += fontkern[fontframe[fontidx[v11]]] + 1; + v10 += fontkern[fontframe[gbFontTransTbl[v11]]] + 1; } while (v9 < v20); if (v10 < 257) LABEL_24: @@ -946,7 +946,7 @@ void __fastcall PrintQLString(int x, int y, unsigned char cjustflag, char *str, v19 = 0; if (v20 > 0) { do { - v14 = fontframe[fontidx[(unsigned char)str[v13]]]; + v14 = fontframe[gbFontTransTbl[(unsigned char)str[v13]]]; v15 = v14; v8 += fontkern[v14] + 1; if (v14 && v8 <= 257) { diff --git a/Source/stores.cpp b/Source/stores.cpp index 268521e62..db7863c01 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -202,7 +202,7 @@ void __fastcall PrintSString(int x, int y, unsigned char cjustflag, char *str, i if (v28 > 0) { do { v13 = (unsigned char)str[v11++]; - v12 += fontkern[fontframe[fontidx[v13]]] + 1; + v12 += fontkern[fontframe[gbFontTransTbl[v13]]] + 1; } while (v11 < v28); } if (v12 < v25) @@ -219,7 +219,7 @@ void __fastcall PrintSString(int x, int y, unsigned char cjustflag, char *str, i v29 = 0; if (v28 > 0) { do { - v15 = fontframe[fontidx[(unsigned char)str[v29]]]; + v15 = fontframe[gbFontTransTbl[(unsigned char)str[v29]]]; v16 = v15; v17 = v30 + fontkern[v15] + 1; v30 += fontkern[v15] + 1; @@ -236,9 +236,9 @@ void __fastcall PrintSString(int x, int y, unsigned char cjustflag, char *str, i v19 = screen_y_times_768[v6 + 204] - v8 + 656; v20 = strlen(valstr); while ((--v20 & 0x80000000) == 0) { - v21 = fontframe[fontidx[(unsigned char)valstr[v20]]]; + v21 = fontframe[gbFontTransTbl[(unsigned char)valstr[v20]]]; v19 += -1 - fontkern[v21]; - if (fontframe[fontidx[(unsigned char)valstr[v20]]]) + if (fontframe[gbFontTransTbl[(unsigned char)valstr[v20]]]) CPrintString(v19, v21, col); } v8 = v26; From 5ef1c76289576e4b56b149f4978449ba8ead6d4e Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 07:33:20 +0100 Subject: [PATCH 11/30] Clean up ItemPlace (#683) --- Source/gendung.cpp | 2 +- Source/gendung.h | 2 +- Source/items.cpp | 25 ++++++++++++++----------- Source/items.h | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Source/gendung.cpp b/Source/gendung.cpp index be001b97d..a3cf0129c 100644 --- a/Source/gendung.cpp +++ b/Source/gendung.cpp @@ -32,7 +32,7 @@ BOOLEAN nTrapTable[2049]; BYTE leveltype; unsigned char currlevel; // idb char TransList[256]; -BYTE nSolidTable[2049]; +BOOLEAN nSolidTable[2049]; int level_frame_count[2048]; ScrollStruct ScrollInfo; void *pDungeonCels; diff --git a/Source/gendung.h b/Source/gendung.h index 83067f16b..798183b30 100644 --- a/Source/gendung.h +++ b/Source/gendung.h @@ -32,7 +32,7 @@ extern BOOLEAN nTrapTable[2049]; extern BYTE leveltype; extern unsigned char currlevel; // idb extern char TransList[256]; -extern BYTE nSolidTable[2049]; +extern BOOLEAN nSolidTable[2049]; extern int level_frame_count[2048]; extern ScrollStruct ScrollInfo; extern void *pDungeonCels; diff --git a/Source/items.cpp b/Source/items.cpp index 3b1caf384..d32788fdb 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -649,19 +649,22 @@ void __cdecl InitItemGFX() memset(UniqueItemFlag, 0, sizeof(UniqueItemFlag)); } -BOOLEAN __fastcall ItemPlace(int xp, int yp) +BOOL __fastcall ItemPlace(int xp, int yp) { - int v2; // ecx - int v3; // eax - BOOLEAN result; // al + if (dMonster[xp][yp]) + return FALSE; + if (dPlayer[xp][yp]) + return FALSE; + if (dItem[xp][yp]) + return FALSE; + if (dObject[xp][yp]) + return FALSE; + if (dFlags[xp][yp] & DFLAG_POPULATED) + return FALSE; + if (nSolidTable[dPiece[xp][yp]]) + return FALSE; - v2 = xp; - v3 = v2 * 112 + yp; - if (dMonster[0][v3] || dPlayer[v2][yp] || dItem[v2][yp] || dObject[v2][yp] || dFlags[v2][yp] & DFLAG_POPULATED) - result = 0; - else - result = nSolidTable[dPiece[0][v3]] == 0; - return result; + return TRUE; } void __cdecl AddInitItems() diff --git a/Source/items.h b/Source/items.h index e19e92f94..bd6341b14 100644 --- a/Source/items.h +++ b/Source/items.h @@ -15,7 +15,7 @@ extern int numitems; extern int gnNumGetRecords; void __cdecl InitItemGFX(); -BOOLEAN __fastcall ItemPlace(int xp, int yp); +BOOL __fastcall ItemPlace(int xp, int yp); void __cdecl AddInitItems(); void __cdecl InitItems(); void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx); From ae2630cc46cce99073afabce20f36dd9aecad1cb Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 07:37:07 +0100 Subject: [PATCH 12/30] Mem free dbg (#685) * FreeQuestText * DRLG_FreeL2SP * GetHall * FreeGMenu * FreeObjectGFX * DRLG_FreeL1SP * FreeControlPan * FreeLightTable * Clean up DRLG_LoadDiabQuads * DRLG_FreeL4SP * FreeInterface --- Source/control.cpp | 115 +++++++++++++++++++------------------------- Source/drlg_l1.cpp | 8 +-- Source/drlg_l2.cpp | 24 ++++----- Source/drlg_l4.cpp | 71 +++++++++++++-------------- Source/drlg_l4.h | 2 +- Source/gmenu.cpp | 38 +++++++-------- Source/interfac.cpp | 8 +-- Source/lighting.cpp | 8 +-- Source/minitext.cpp | 15 +++--- Source/objects.cpp | 20 ++++---- 10 files changed, 143 insertions(+), 166 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 71ef87252..632f9e27a 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1604,71 +1604,56 @@ void __cdecl CheckBtnUp() void __cdecl FreeControlPan() { - void *v0; // ecx - void *v1; // ecx - void *v2; // ecx - void *v3; // ecx - void *v4; // ecx - void *v5; // ecx - void *v6; // ecx - void *v7; // ecx - void *v8; // ecx - void *v9; // ecx - void *v10; // ecx - void *v11; // ecx - void *v12; // ecx - void *v13; // ecx - void *v14; // ecx - void *v15; // ecx - - v0 = pBtmBuff; - pBtmBuff = 0; - mem_free_dbg(v0); - v1 = pManaBuff; - pManaBuff = 0; - mem_free_dbg(v1); - v2 = pLifeBuff; - pLifeBuff = 0; - mem_free_dbg(v2); - v3 = pPanelText; - pPanelText = 0; - mem_free_dbg(v3); - v4 = pChrPanel; - pChrPanel = 0; - mem_free_dbg(v4); - v5 = pSpellCels; - pSpellCels = 0; - mem_free_dbg(v5); - v6 = pPanelButtons; - pPanelButtons = 0; - mem_free_dbg(v6); - v7 = pMultiBtns; - pMultiBtns = 0; - mem_free_dbg(v7); - v8 = pTalkBtns; - pTalkBtns = 0; - mem_free_dbg(v8); - v9 = pChrButtons; - pChrButtons = 0; - mem_free_dbg(v9); - v10 = pDurIcons; - pDurIcons = 0; - mem_free_dbg(v10); - v11 = pQLogCel; - pQLogCel = 0; - mem_free_dbg(v11); - v12 = pSpellBkCel; - pSpellBkCel = 0; - mem_free_dbg(v12); - v13 = pSBkBtnCel; - pSBkBtnCel = 0; - mem_free_dbg(v13); - v14 = pSBkIconCels; - pSBkIconCels = 0; - mem_free_dbg(v14); - v15 = pGBoxBuff; - pGBoxBuff = 0; - mem_free_dbg(v15); + void *ptr; + + ptr = pBtmBuff; + pBtmBuff = NULL; + mem_free_dbg(ptr); + ptr = pManaBuff; + pManaBuff = NULL; + mem_free_dbg(ptr); + ptr = pLifeBuff; + pLifeBuff = NULL; + mem_free_dbg(ptr); + ptr = pPanelText; + pPanelText = NULL; + mem_free_dbg(ptr); + ptr = pChrPanel; + pChrPanel = NULL; + mem_free_dbg(ptr); + ptr = pSpellCels; + pSpellCels = NULL; + mem_free_dbg(ptr); + ptr = pPanelButtons; + pPanelButtons = NULL; + mem_free_dbg(ptr); + ptr = pMultiBtns; + pMultiBtns = NULL; + mem_free_dbg(ptr); + ptr = pTalkBtns; + pTalkBtns = NULL; + mem_free_dbg(ptr); + ptr = pChrButtons; + pChrButtons = NULL; + mem_free_dbg(ptr); + ptr = pDurIcons; + pDurIcons = NULL; + mem_free_dbg(ptr); + ptr = pQLogCel; + pQLogCel = NULL; + mem_free_dbg(ptr); + ptr = pSpellBkCel; + pSpellBkCel = NULL; + mem_free_dbg(ptr); + ptr = pSBkBtnCel; + pSBkBtnCel = NULL; + mem_free_dbg(ptr); + ptr = pSBkIconCels; + pSBkIconCels = NULL; + mem_free_dbg(ptr); + ptr = pGBoxBuff; + pGBoxBuff = NULL; + mem_free_dbg(ptr); } int __fastcall control_WriteStringToBuffer(char *str) diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 4fe2110c6..766ec40f6 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -472,11 +472,11 @@ void __cdecl DRLG_LoadL1SP() void __cdecl DRLG_FreeL1SP() { - void *v0; // ecx + void *ptr; - v0 = pSetPiece; - pSetPiece = 0; - mem_free_dbg(v0); + ptr = pSetPiece; + pSetPiece = NULL; + mem_free_dbg(ptr); } void __fastcall DRLG_L5(int entry) diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index c1324c892..6eb128e1b 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -756,11 +756,11 @@ void __cdecl DRLG_LoadL2SP() void __cdecl DRLG_FreeL2SP() { - char *v0; // ecx + char *ptr; - v0 = pSetPiece_2; - pSetPiece_2 = 0; - mem_free_dbg(v0); + ptr = pSetPiece_2; + pSetPiece_2 = NULL; + mem_free_dbg(ptr); } void __fastcall DRLG_L2(int entry) @@ -1857,19 +1857,21 @@ void __fastcall AddHall(int nX1, int nY1, int nX2, int nY2, int nHd) void __fastcall GetHall(int *nX1, int *nY1, int *nX2, int *nY2, int *nHd) { - HALLNODE *v5; // esi - HALLNODE *v6; // ecx + HALLNODE *p1; + HALLNODE *p2; - v5 = pHallList->pNext; + p1 = pHallList->pNext; *nX1 = pHallList->nHallx1; *nY1 = pHallList->nHally1; *nX2 = pHallList->nHallx2; *nY2 = pHallList->nHally2; *nHd = pHallList->nHalldir; - v6 = pHallList; - pHallList = 0; - mem_free_dbg(v6); - pHallList = v5; + + p2 = pHallList; + pHallList = NULL; + mem_free_dbg(p2); + + pHallList = p1; } void __fastcall ConnectHall(int nX1, int nY1, int nX2, int nY2, int nHd) diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index e2c1264da..ab88f182f 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -306,11 +306,11 @@ void __cdecl DRLG_LoadL4SP() void __cdecl DRLG_FreeL4SP() { - char *v0; // ecx + char *ptr; - v0 = pSetPiece_2; - pSetPiece_2 = 0; - mem_free_dbg(v0); + ptr = pSetPiece_2; + pSetPiece_2 = NULL; + mem_free_dbg(ptr); } void __fastcall DRLG_L4SetSPRoom(int rx1, int ry1) @@ -440,47 +440,42 @@ void __fastcall DRLG_L4SetRoom(unsigned char *pSetPiece, int rx1, int ry1) } } -void __fastcall DRLG_LoadDiabQuads(BOOLEAN preflag) +void __fastcall DRLG_LoadDiabQuads(BOOL preflag) { - BOOLEAN v1; // esi - unsigned char *v2; // edi - char *v3; // ecx - unsigned char *v4; // edi - char *v5; // ecx - unsigned char *v6; // edi - char *v7; // ecx - unsigned char *v8; // esi - - v1 = preflag; - v2 = LoadFileInMem("Levels\\L4Data\\diab1.DUN", 0); + BYTE *dun; + + dun = LoadFileInMem("Levels\\L4Data\\diab1.DUN", 0); diabquad1x = l4holdx + 4; diabquad1y = l4holdy + 4; - DRLG_L4SetRoom(v2, l4holdx + 4, l4holdy + 4); - mem_free_dbg(v2); - v3 = "Levels\\L4Data\\diab2b.DUN"; - if (!v1) - v3 = "Levels\\L4Data\\diab2a.DUN"; - v4 = LoadFileInMem(v3, 0); - diabquad2y = l4holdy + 1; + DRLG_L4SetRoom(dun, diabquad1x, diabquad1y); + mem_free_dbg(dun); + + if (!preflag) + dun = LoadFileInMem("Levels\\L4Data\\diab2a.DUN", 0); + else + dun = LoadFileInMem("Levels\\L4Data\\diab2b.DUN", 0); diabquad2x = 27 - l4holdx; - DRLG_L4SetRoom(v4, 27 - l4holdx, l4holdy + 1); - mem_free_dbg(v4); - v5 = "Levels\\L4Data\\diab3b.DUN"; - if (!v1) - v5 = "Levels\\L4Data\\diab3a.DUN"; - v6 = LoadFileInMem(v5, 0); + diabquad2y = l4holdy + 1; + DRLG_L4SetRoom(dun, diabquad2x, diabquad2y); + mem_free_dbg(dun); + + if (!preflag) + dun = LoadFileInMem("Levels\\L4Data\\diab3a.DUN", 0); + else + dun = LoadFileInMem("Levels\\L4Data\\diab3b.DUN", 0); diabquad3x = l4holdx + 1; diabquad3y = 27 - l4holdy; - DRLG_L4SetRoom(v6, l4holdx + 1, 27 - l4holdy); - mem_free_dbg(v6); - v7 = "Levels\\L4Data\\diab4b.DUN"; - if (!v1) - v7 = "Levels\\L4Data\\diab4a.DUN"; - v8 = LoadFileInMem(v7, 0); - diabquad4y = 28 - l4holdy; + DRLG_L4SetRoom(dun, diabquad3x, diabquad3y); + mem_free_dbg(dun); + + if (!preflag) + dun = LoadFileInMem("Levels\\L4Data\\diab4a.DUN", 0); + else + dun = LoadFileInMem("Levels\\L4Data\\diab4b.DUN", 0); diabquad4x = 28 - l4holdx; - DRLG_L4SetRoom(v8, 28 - l4holdx, 28 - l4holdy); - mem_free_dbg(v8); + diabquad4y = 28 - l4holdy; + DRLG_L4SetRoom(dun, diabquad4x, diabquad4y); + mem_free_dbg(dun); } // 5289C4: using guessed type int diabquad1x; // 5289C8: using guessed type int diabquad1y; diff --git a/Source/drlg_l4.h b/Source/drlg_l4.h index 6679a31a7..34b9ac7c2 100644 --- a/Source/drlg_l4.h +++ b/Source/drlg_l4.h @@ -26,7 +26,7 @@ void __cdecl DRLG_FreeL4SP(); void __fastcall DRLG_L4SetSPRoom(int rx1, int ry1); void __cdecl L4SaveQuads(); void __fastcall DRLG_L4SetRoom(unsigned char *pSetPiece, int rx1, int ry1); -void __fastcall DRLG_LoadDiabQuads(BOOLEAN preflag); +void __fastcall DRLG_LoadDiabQuads(BOOL preflag); BOOLEAN __fastcall IsDURWall(char d); BOOLEAN __fastcall IsDLLWall(char dd); void __cdecl L4FixRim(); diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 09cb8bc7f..aa0da2b0d 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -72,27 +72,23 @@ void __fastcall gmenu_print_text(int x, int y, char *pszStr) void __cdecl FreeGMenu() { - void *v0; // ecx - void *v1; // ecx - void *v2; // ecx - void *v3; // ecx - void *v4; // ecx - - v0 = sgpLogo; - sgpLogo = 0; - mem_free_dbg(v0); - v1 = BigTGold_cel; - BigTGold_cel = 0; - mem_free_dbg(v1); - v2 = PentSpin_cel; - PentSpin_cel = 0; - mem_free_dbg(v2); - v3 = option_cel; - option_cel = 0; - mem_free_dbg(v3); - v4 = optbar_cel; - optbar_cel = 0; - mem_free_dbg(v4); + void *ptr; + + ptr = sgpLogo; + sgpLogo = NULL; + mem_free_dbg(ptr); + ptr = BigTGold_cel; + BigTGold_cel = NULL; + mem_free_dbg(ptr); + ptr = PentSpin_cel; + PentSpin_cel = NULL; + mem_free_dbg(ptr); + ptr = option_cel; + option_cel = NULL; + mem_free_dbg(ptr); + ptr = optbar_cel; + optbar_cel = NULL; + mem_free_dbg(ptr); } void __cdecl gmenu_init_menu() diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 5403879bb..721a826a0 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -223,11 +223,11 @@ void __fastcall ShowProgress(unsigned int uMsg) void __cdecl FreeInterface() { - void *v0; // ecx + void *ptr; - v0 = sgpBackCel; - sgpBackCel = 0; - mem_free_dbg(v0); + ptr = sgpBackCel; + sgpBackCel = NULL; + mem_free_dbg(ptr); } void __fastcall InitCutscene(unsigned int uMsg) diff --git a/Source/lighting.cpp b/Source/lighting.cpp index e0d77cc54..bc02e1223 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -940,11 +940,11 @@ void __fastcall DoVision(int nXPos, int nYPos, int nRadius, unsigned char doauto void __cdecl FreeLightTable() { - char *v0; // ecx + char *ptr; - v0 = pLightTbl; - pLightTbl = 0; - mem_free_dbg(v0); + ptr = pLightTbl; + pLightTbl = NULL; + mem_free_dbg(ptr); } void __cdecl InitLightTable() diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 07d3ed596..d816d9c5c 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -41,15 +41,14 @@ int qscroll_spd_tbl[9] = { 2, 4, 6, 8, 0, -1, -2, -3, -4 }; void __cdecl FreeQuestText() { - void *v0; // ecx - void *v1; // ecx + void *ptr; - v0 = pMedTextCels; - pMedTextCels = 0; - mem_free_dbg(v0); - v1 = pTextBoxCels; - pTextBoxCels = 0; - mem_free_dbg(v1); + ptr = pMedTextCels; + pMedTextCels = NULL; + mem_free_dbg(ptr); + ptr = pTextBoxCels; + pTextBoxCels = NULL; + mem_free_dbg(ptr); } void __cdecl InitQuestText() diff --git a/Source/objects.cpp b/Source/objects.cpp index 9881d75dc..26f09b171 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -411,13 +411,13 @@ void __cdecl InitObjectGFX() void __cdecl FreeObjectGFX() { - int i; // esi - void *v1; // ecx + int i; + void *ptr; - for (i = 0; i < numobjfiles; ++i) { - v1 = (void *)pObjCels[i]; - pObjCels[i] = 0; - mem_free_dbg(v1); + for (i = 0; i < numobjfiles; i++) { + ptr = pObjCels[i]; + pObjCels[i] = NULL; + mem_free_dbg(ptr); } numobjfiles = 0; } @@ -2655,10 +2655,10 @@ void __fastcall ObjSetMini(int x, int y, int v) mov v4, eax } #else - v1 = *((WORD *)&pMegaTiles[((WORD)v-1)*8])+1; - v2 = *((WORD *)&pMegaTiles[((WORD)v-1)*8]+1)+1; - v3 = *((WORD *)&pMegaTiles[((WORD)v-1)*8]+2)+1; - v4 = *((WORD *)&pMegaTiles[((WORD)v-1)*8]+3)+1; + v1 = *((WORD *)&pMegaTiles[((WORD)v - 1) * 8]) + 1; + v2 = *((WORD *)&pMegaTiles[((WORD)v - 1) * 8] + 1) + 1; + v3 = *((WORD *)&pMegaTiles[((WORD)v - 1) * 8] + 2) + 1; + v4 = *((WORD *)&pMegaTiles[((WORD)v - 1) * 8] + 3) + 1; #endif xx = 2 * x + 16; From 1ca4253260ce9464680e124984672b0d42bc29b4 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 07:38:33 +0100 Subject: [PATCH 13/30] GetVileMissPos bin exact (#689) --- Source/missiles.cpp | 56 ++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 537b8fd6e..66917b60e 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1647,49 +1647,23 @@ void __fastcall AddArrow(int mi, int sx, int sy, int dx, int dy, int midir, int void __fastcall GetVileMissPos(int mi, int dx, int dy) { - signed int v3; // edi - int v4; // ebx - int v5; // esi - int v6; // eax - int v7; // eax - int v8; // [esp+Ch] [ebp-14h] - int v9; // [esp+10h] [ebp-10h] - signed int v10; // [esp+14h] [ebp-Ch] - signed int v11; // [esp+18h] [ebp-8h] - signed int v12; // [esp+1Ch] [ebp-4h] - - v8 = dx; - v9 = mi; - v12 = 1; - v3 = -1; - do { - v11 = v3; - if (v3 <= v12) { - while (2) { - v10 = v3; - v4 = v11 + dy; - v5 = v3 + v8; - do { - if (PosOkPlayer(myplr, v5, v4)) { - v7 = v9; - missile[v7]._mix = v5; - missile[v7]._miy = v4; - return; - } - ++v10; - ++v5; - } while (v10 <= v12); - if (++v11 <= v12) - continue; - break; + int xx, yy, k, j, i; + + for (k = 1; k < 50; k++) { + for (j = -k; j <= k; j++) { + yy = j + dy; + for (i = -k; i <= k; i++) { + xx = i + dx; + if (PosOkPlayer(myplr, xx, yy)) { + missile[mi]._mix = xx; + missile[mi]._miy = yy; + return; + } } } - ++v12; - --v3; - } while (v3 > -50); - v6 = v9; - missile[v6]._mix = v8; - missile[v6]._miy = dy; + } + missile[mi]._mix = dx; + missile[mi]._miy = dy; } void __fastcall AddRndTeleport(int mi, int sx, int sy, int dx, int dy, int midir, int mienemy, int id, int dam) From 9cb7cd15b8960c9a361e2a434614353129cf61c3 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Tue, 19 Mar 2019 01:38:57 -0500 Subject: [PATCH 14/30] Cleanup DrawSLine/ULine (#690) --- Source/items.cpp | 51 ++++++++++++++++++++----------- Source/items.h | 2 +- Source/stores.cpp | 76 ++++++++++++++++++++++++++--------------------- 3 files changed, 77 insertions(+), 52 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index d32788fdb..07653cc2b 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3695,7 +3695,7 @@ void __fastcall PrintItemPower(char plidx, ItemStruct *x) } } -void __cdecl DrawUBack() +void __cdecl DrawUTextBack() { CelDecodeOnly(88, 487, (BYTE *)pSTextBoxCels, 1, 271); @@ -3762,22 +3762,39 @@ void __fastcall PrintUString(int x, int y, int cjustflag, char *str, int col) void __fastcall DrawULine(int y) { - char *v1; // esi - char *v2; // edi - signed int v3; // edx + /// ASSERT: assert(gpBuffer); + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + int yy; + + yy = screen_y_times_768[SStringY[y] + 198] + 26 + 64; + + __asm { + mov esi, gpBuffer + mov edi, esi + add esi, SCREENXY(26, 25) + add edi, yy + mov ebx, 768 - 266 + mov edx, 3 + copyline: + mov ecx, 266 / 4 + rep movsd + movsw + add esi, ebx + add edi, ebx + dec edx + jnz copyline + } +#else + int i; + BYTE *src, *dst; - v1 = (char *)&gpBuffer[SCREENXY(26, 25)]; - v2 = (char *)&gpBuffer[screen_y_times_768[SStringY[y] + 198] + 26 + 64]; - v3 = 3; - do { - qmemcpy(v2, v1, 0x10A); /* find real fix */ - v1 += 264; - v2 += 264; - *v2 = *v1; - v1 += 504; - v2 += 504; - --v3; - } while (v3); + src = &gpBuffer[SCREENXY(26, 25)]; + dst = &gpBuffer[screen_y_times_768[SStringY[y] + 198] + 26 + 64]; + + for(i = 0; i < 3; i++, src += 768, dst += 768) + memcpy(dst, src, 266); +#endif } void __cdecl DrawUniqueInfo() @@ -3788,7 +3805,7 @@ void __cdecl DrawUniqueInfo() if (!chrflag && !questlog) { v0 = curruitem._iUid; - DrawUBack(); + DrawUTextBack(); v1 = v0; PrintUString(0, 2, 1, UniqueItemList[v1].UIName, 3); DrawULine(5); diff --git a/Source/items.h b/Source/items.h index bd6341b14..f5cf88004 100644 --- a/Source/items.h +++ b/Source/items.h @@ -80,7 +80,7 @@ void __fastcall DoRecharge(int pnum, int cii); void __fastcall RechargeItem(ItemStruct *i, int r); void __fastcall PrintItemOil(char IDidx); void __fastcall PrintItemPower(char plidx, ItemStruct *x); -void __cdecl DrawUBack(); +void __cdecl DrawUTextBack(); void __fastcall PrintUString(int x, int y, int cjustflag, char *str, int col); void __fastcall DrawULine(int y); void __cdecl DrawUniqueInfo(); diff --git a/Source/stores.cpp b/Source/stores.cpp index db7863c01..74957f67b 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -257,41 +257,49 @@ void __fastcall PrintSString(int x, int y, unsigned char cjustflag, char *str, i void __fastcall DrawSLine(int y) { - int v1; // eax - int v2; // eax - char *v3; // esi - char *v4; // edi - signed int v5; // edx - char *v6; // edi - char *v7; // esi - signed int v8; // [esp+0h] [ebp-10h] - signed int v9; // [esp+8h] [ebp-8h] - signed int v10; // [esp+Ch] [ebp-4h] - - v1 = screen_y_times_768[SStringY[y] + 198]; - if (stextsize == 1) { - v8 = 142170; - v2 = v1 + 90; - v10 = 146; - v9 = 182; + int xy, yy, width, line; + + if(stextsize == 1) { + xy = SCREENXY(26, 25); + yy = screen_y_times_768[SStringY[y] + 198] + 26 + 64; + width = 586 / 4; + line = 768 - 586; } else { - v8 = 142490; - v2 = v1 + 410; - v10 = 66; - v9 = 502; - } - v3 = (char *)gpBuffer + v8; - v4 = (char *)gpBuffer + v2; - v5 = 3; - do { - qmemcpy(v4, v3, 4 * v10); - v7 = &v3[4 * v10]; - v6 = &v4[4 * v10]; - *(_WORD *)v6 = *(_WORD *)v7; - v3 = &v7[v9 + 2]; - v4 = &v6[v9 + 2]; - --v5; - } while (v5); + xy = SCREENXY(346, 25); + yy = screen_y_times_768[SStringY[y] + 198] + 346 + 64; + width = 266 / 4; + line = 768 - 266; + } + + /// ASSERT: assert(gpBuffer); + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, gpBuffer + mov edi, esi + add esi, xy + add edi, yy + mov ebx, line + mov edx, 3 + copyline: + mov ecx, width + rep movsd + movsw + add esi, ebx + add edi, ebx + dec edx + jnz copyline + } +#else + int i; + BYTE *src, *dst; + + src = &gpBuffer[xy]; + dst = &gpBuffer[yy]; + + for(i = 0; i < 3; i++, src += 768, dst += 768) + memcpy(dst, src, 768 - line); +#endif } // 6A09E0: using guessed type char stextsize; From 7c292cef34e1c91db41a338826947e5e52ce669c Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 19 Mar 2019 10:55:47 +0100 Subject: [PATCH 15/30] Announce DevilutionX (#688) * Announce DevilutionX * Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3b2f5ebb..af7ea3f58 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ No, you'll need access to the data from the original game. Blizzard has disconti 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! However, this will be a **_side project_** based on Devilution. I have yet to announce the project. +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. ;) From f38847271332b17bdbbcface698fe6e1c7e6ef32 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Tue, 19 Mar 2019 04:57:23 -0500 Subject: [PATCH 16/30] ENG_set_pixel + engine_draw_pixel (#691) --- Source/engine.cpp | 66 +++++++++++++++++++++++++++++++++-------------- Source/engine.h | 4 +-- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index 646e7c87b..b3d3aa5c2 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -1970,34 +1970,62 @@ void __fastcall CelDrawHdrClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nC } // 69CF0C: using guessed type int gpBufEnd; -void __fastcall ENG_set_pixel(int screen_x, int screen_y, UCHAR pixel) +void __fastcall ENG_set_pixel(int sx, int sy, BYTE col) { - UCHAR *v3; // edi + BYTE *dst; + + /// ASSERT: assert(gpBuffer); + + if(sy < 0 || sy >= 640 || sx < 64 || sx >= 704) + return; + + dst = &gpBuffer[sx + screen_y_times_768[sy]]; - if (screen_y >= 0 && screen_y < 640 && screen_x >= 64 && screen_x < 704) { - v3 = (UCHAR *)gpBuffer + screen_y_times_768[screen_y] + screen_x; - if (v3 < gpBufEnd) - *v3 = pixel; +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov edi, dst + cmp edi, gpBufEnd + jnb label1 + mov al, col + mov [edi], al + label1: } +#else + if(dst < gpBufEnd) + *dst = col; +#endif } // 69CF0C: using guessed type int gpBufEnd; -void __fastcall engine_draw_pixel(int x, int y) +void __fastcall engine_draw_pixel(int sx, int sy) { - _BYTE *v2; // eax + BYTE *dst; - if (dword_52B970) { - if (!dword_52B99C || x >= 0 && x < 640 && y >= 64 && y < 704) { - v2 = (unsigned char *)gpBuffer + screen_y_times_768[x] + y; - goto LABEL_14; - } - } else if (!dword_52B99C || y >= 0 && y < 640 && x >= 64 && x < 704) { - v2 = (unsigned char *)gpBuffer + screen_y_times_768[y] + x; - LABEL_14: - if (v2 < gpBufEnd) - *v2 = gbPixelCol; - return; + /// ASSERT: assert(gpBuffer); + + if(dword_52B970) { + if(dword_52B99C && (sx < 0 || sx >= 640 || sy < 64 || sy >= 704)) + return; + dst = &gpBuffer[sy + screen_y_times_768[sx]]; + } else { + if(dword_52B99C && (sy < 0 || sy >= 640 || sx < 64 || sx >= 704)) + return; + dst = &gpBuffer[sx + screen_y_times_768[sy]]; } + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov edi, dst + cmp edi, gpBufEnd + jnb label1 + mov al, gbPixelCol + mov [edi], al + label1: + } +#else + if(dst < gpBufEnd) + *dst = gbPixelCol; +#endif } // 52B96C: using guessed type char gbPixelCol; // 52B970: using guessed type int dword_52B970; diff --git a/Source/engine.h b/Source/engine.h index 037ce85cf..7c5352b78 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -33,8 +33,8 @@ void __fastcall Cel2DrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, in void __fastcall CelDecodeRect(BYTE *pBuff, int always_0, int hgt, int wdt, BYTE *pCelBuff, int nCel, int nWidth); void __fastcall CelDecodeClr(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir); void __fastcall CelDrawHdrClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir); -void __fastcall ENG_set_pixel(int screen_x, int screen_y, UCHAR pixel); -void __fastcall engine_draw_pixel(int x, int y); +void __fastcall ENG_set_pixel(int sx, int sy, BYTE col); +void __fastcall engine_draw_pixel(int sx, int sy); void __fastcall DrawLine(int x0, int y0, int x1, int y1, UCHAR col); int __fastcall GetDirection(int x1, int y1, int x2, int y2); void __fastcall SetRndSeed(int s); From 1fd67918497f05178fa4fb6f779fa6c11cdf8a56 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 00:21:53 +0100 Subject: [PATCH 17/30] MI_Flame bin exact --- Source/missiles.cpp | 53 ++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 66917b60e..c206cb003 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -4905,43 +4905,28 @@ void __fastcall MI_Blodboil(int i) void __fastcall MI_Flame(int i) { - int v1; // ebx - int v2; // esi - int v3; // ST0C_4 - int v4; // edx - int v5; // edi - int v6; // ST08_4 - int v7; // eax - int v8; // eax - int v9; // ecx + int k; - v1 = i; - v2 = i; - v3 = missile[i]._miy; - v4 = missile[i]._midam; - --missile[v2]._mirange; - v5 = missile[i]._mirange; - v6 = missile[i]._mix; - --missile[v2]._miVar2; - CheckMissileCol(i, v4, v4, 1, v6, v3, 0); - if (!missile[v2]._mirange && missile[v2]._miHitFlag) - missile[v2]._mirange = v5; - v7 = missile[v2]._miVar2; - if (!v7) - missile[v2]._miAnimFrame = 20; - if (v7 <= 0) { - v8 = missile[v2]._miAnimFrame; - if (v8 > 11) - v8 = 24 - v8; - ChangeLight(missile[v2]._mlid, missile[v2]._mix, missile[v2]._miy, v8); + missile[i]._mirange--; + k = missile[i]._mirange; + missile[i]._miVar2--; + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix, missile[i]._miy, 0); + if (missile[i]._mirange == 0 && missile[i]._miHitFlag == TRUE) + missile[i]._mirange = k; + if (!missile[i]._miVar2) + missile[i]._miAnimFrame = 20; + if (missile[i]._miVar2 <= 0) { + k = missile[i]._miAnimFrame; + if (k > 11) + k = 24 - k; + ChangeLight(missile[i]._mlid, missile[i]._mix, missile[i]._miy, k); } - if (!missile[v2]._mirange) { - v9 = missile[v2]._mlid; - missile[v2]._miDelFlag = TRUE; - AddUnLight(v9); + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + AddUnLight(missile[i]._mlid); } - if (missile[v2]._miVar2 <= 0) - PutMissile(v1); + if (missile[i]._miVar2 <= 0) + PutMissile(i); } void __fastcall MI_Flamec(int i) From aa549a8c89b14850abc202d37a34d4a0cf0addd5 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 13:55:41 +0100 Subject: [PATCH 18/30] GetMissilePos bin exact --- Source/missiles.cpp | 61 +++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index c206cb003..c28c08c70 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -655,46 +655,31 @@ void __fastcall PutMissile(int i) void __fastcall GetMissilePos(int i) { - int v1; // ecx - int v2; // eax - int v3; // esi - int v4; // edi - int v5; // edx - int v6; // edi - int v7; // esi - int v8; // edi - int v9; // edx - int v10; // esi - int v11; // edx - int v12; // [esp+Ch] [ebp-8h] - - v1 = i; - v2 = missile[v1]._mityoff >> 16; - v3 = missile[v1]._mitxoff >> 16; - v4 = 2 * v2 + v3; - v5 = 2 * v2 - v3; - if (v4 >= 0) { - v7 = v4 >> 3; - v8 = v4 >> 6; + int mx, my, dx, dy, lx, ly; + + mx = missile[i]._mitxoff >> 16; + my = missile[i]._mityoff >> 16; + dx = mx + 2 * my; + dy = 2 * my - mx; + if (dx < 0) { + lx = -(-dx >> 3); + dx = -(-dx >> 6); } else { - v6 = -v4; - v7 = -(v6 >> 3); - v8 = -(v6 >> 6); - } - v12 = v7; - if (v5 >= 0) { - v10 = v5 >> 3; - v11 = v5 >> 6; + lx = dx >> 3; + dx = dx >> 6; + } + if (dy < 0) { + ly = -(-dy >> 3); + dy = -(-dy >> 6); } else { - v9 = -v5; - v10 = -(v9 >> 3); - v11 = -(v9 >> 6); - } - missile[v1]._mix = v8 + missile[v1]._misx; - missile[v1]._miy = v11 + missile[v1]._misy; - missile[v1]._mixoff = (missile[v1]._mitxoff >> 16) + 32 * v11 - 32 * v8; - missile[v1]._miyoff = v2 - 16 * v11 - 16 * v8; - ChangeLightOff(missile[v1]._mlid, v12 - 8 * v8, v10 - 8 * v11); + ly = dy >> 3; + dy = dy >> 6; + } + missile[i]._mix = dx + missile[i]._misx; + missile[i]._miy = dy + missile[i]._misy; + missile[i]._mixoff = mx + (dy << 5) - (dx << 5); + missile[i]._miyoff = my - (dx << 4) - (dy << 4); + ChangeLightOff(missile[i]._mlid, lx - (dx << 3), ly - (dy << 3)); } void __fastcall MoveMissilePos(int i) From da41d06293a059ddd038b54aca9d316bef4cb10d Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 14:55:33 +0100 Subject: [PATCH 19/30] MI_Element almost bin exact --- Source/missiles.cpp | 147 +++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 90 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index c28c08c70..0fa820cd3 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -5078,106 +5078,73 @@ void __fastcall MI_Hbolt(int i) void __fastcall MI_Element(int i) { - int v1; // esi - int v2; // edi - int v3; // eax - int v4; // ebx - int v5; // ebx - int v6; // ecx - int v7; // ebx - int v8; // eax - int v9; // edi - int v10; // eax - int v11; // edi - int v12; // ecx - int ty; // [esp+Ch] [ebp-18h] - int tya; // [esp+Ch] [ebp-18h] - //int tyb; // [esp+Ch] [ebp-18h] - int my; // [esp+10h] [ebp-14h] - //int mya; // [esp+10h] [ebp-14h] - //int myb; // [esp+10h] [ebp-14h] - int fx; // [esp+14h] [ebp-10h] - //int fxa; // [esp+14h] [ebp-10h] - int fy; // [esp+18h] [ebp-Ch] - int ia; // [esp+1Ch] [ebp-8h] - int y; // [esp+20h] [ebp-4h] - int ya; // [esp+20h] [ebp-4h] + int mid, sd, dam, cx, cy, px, py, id; - v1 = i; - ia = i; - --missile[v1]._mirange; - v2 = missile[i]._midam; - ty = missile[i]._misource; - if (_LOBYTE(missile[i]._miAnimType) == MFILE_KRULL) { - v3 = missile[i]._misource; - v4 = missile[v1]._mix; - y = missile[v1]._miy; - fx = plr[v3].WorldX; - fy = plr[v3].WorldY; - ChangeLight(missile[v1]._mlid, v4, y, missile[v1]._miAnimFrame); - if (!CheckBlock(fx, fy, v4, y)) - CheckMissileCol(ia, v2, v2, 1, v4, y, 1); - my = y + 1; - if (!CheckBlock(fx, fy, v4, y + 1)) - CheckMissileCol(ia, v2, v2, 1, v4, my, 1); - tya = y - 1; - if (!CheckBlock(fx, fy, v4, y - 1)) - CheckMissileCol(ia, v2, v2, 1, v4, tya, 1); - if (!CheckBlock(fx, fy, v4 + 1, y)) - CheckMissileCol(ia, v2, v2, 1, v4 + 1, y, 1); /* check x/y */ - if (!CheckBlock(fx, fy, v4 + 1, tya)) - CheckMissileCol(ia, v2, v2, 1, v4 + 1, tya, 1); - if (!CheckBlock(fx, fy, v4 + 1, my)) - CheckMissileCol(ia, v2, v2, 1, v4 + 1, my, 1); - v5 = v4 - 1; - if (!CheckBlock(fx, fy, v5, y)) - CheckMissileCol(ia, v2, v2, 1, v5, y, 1); - if (!CheckBlock(fx, fy, v5, my)) - CheckMissileCol(ia, v2, v2, 1, v5, my, 1); - if (!CheckBlock(fx, fy, v5, tya)) - CheckMissileCol(ia, v2, v2, 1, v5, tya, 1); - if (!missile[v1]._mirange) { - v6 = missile[v1]._mlid; - missile[v1]._miDelFlag = TRUE; - AddUnLight(v6); + missile[i]._mirange--; + dam = missile[i]._midam; + id = missile[i]._misource; + if (missile[i]._miAnimType == MFILE_BIGEXP) { + cx = missile[i]._mix; + cy = missile[i]._miy; + px = plr[id].WorldX; + py = plr[id].WorldY; + ChangeLight(missile[i]._mlid, cx, cy, missile[i]._miAnimFrame); + if (!CheckBlock(px, py, cx, cy)) + CheckMissileCol(i, dam, dam, 1, cx, cy, 1); + if (!CheckBlock(px, py, cx, cy + 1)) + CheckMissileCol(i, dam, dam, 1, cx, cy + 1, 1); + if (!CheckBlock(px, py, cx, cy - 1)) + CheckMissileCol(i, dam, dam, 1, cx, cy - 1, 1); + if (!CheckBlock(px, py, cx + 1, cy)) + CheckMissileCol(i, dam, dam, 1, cx + 1, cy, 1); /* check x/y */ + if (!CheckBlock(px, py, cx + 1, cy - 1)) + CheckMissileCol(i, dam, dam, 1, cx + 1, cy - 1, 1); + if (!CheckBlock(px, py, cx + 1, cy + 1)) + CheckMissileCol(i, dam, dam, 1, cx + 1, cy + 1, 1); + if (!CheckBlock(px, py, cx - 1, cy)) + CheckMissileCol(i, dam, dam, 1, cx - 1, cy, 1); + if (!CheckBlock(px, py, cx - 1, cy + 1)) + CheckMissileCol(i, dam, dam, 1, cx - 1, cy + 1, 1); + if (!CheckBlock(px, py, cx - 1, cy - 1)) + CheckMissileCol(i, dam, dam, 1, cx - 1, cy - 1, 1); + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + AddUnLight(missile[i]._mlid); } } else { - missile[v1]._mitxoff += missile[v1]._mixvel; - missile[v1]._mityoff += missile[v1]._miyvel; + missile[i]._mitxoff += missile[i]._mixvel; + missile[i]._mityoff += missile[i]._miyvel; GetMissilePos(i); - v7 = missile[v1]._mix; - ya = missile[v1]._miy; - CheckMissileCol(ia, v2, v2, 0, missile[v1]._mix, ya, 0); - if (!missile[v1]._miVar3 && v7 == missile[v1]._miVar4 && ya == missile[v1]._miVar5) - missile[v1]._miVar3 = 1; - if (missile[v1]._miVar3 == 1) { - missile[v1]._miVar3 = 2; - missile[v1]._mirange = 255; - v8 = FindClosest(v7, ya, 19); - if (v8 <= 0) { - v11 = plr[ty]._pdir; - SetMissDir(ia, plr[ty]._pdir); - GetMissileVel(ia, v7, ya, v7 + XDirAdd[v11], ya + YDirAdd[v11], 16); + cx = missile[i]._mix; + cy = missile[i]._miy; + CheckMissileCol(i, dam, dam, 0, cx, cy, 0); + if (!missile[i]._miVar3 && cx == missile[i]._miVar4 && cy == missile[i]._miVar5) + missile[i]._miVar3 = 1; + if (missile[i]._miVar3 == 1) { + missile[i]._miVar3 = 2; + missile[i]._mirange = 255; + mid = FindClosest(cx, cy, 19); + if (mid > 0) { + SetMissDir(i, GetDirection8(cx, cy, monster[mid]._mx, monster[mid]._my)); + GetMissileVel(i, cx, cy, monster[mid]._mx, monster[mid]._my, 16); } else { - v9 = v8; - v10 = GetDirection8(v7, ya, monster[v8]._mx, monster[v8]._my); - SetMissDir(ia, v10); - GetMissileVel(ia, v7, ya, monster[v9]._mx, monster[v9]._my, 16); + sd = plr[id]._pdir; + SetMissDir(i, sd); + GetMissileVel(i, cx, cy, cx + XDirAdd[sd], cy + YDirAdd[sd], 16); } } - if (v7 != missile[v1]._miVar1 || ya != missile[v1]._miVar2) { - missile[v1]._miVar2 = ya; - v12 = missile[v1]._mlid; - missile[v1]._miVar1 = v7; - ChangeLight(v12, v7, ya, 8); + if (cx != missile[i]._miVar1 || cy != missile[i]._miVar2) { + missile[i]._miVar1 = cx; + missile[i]._miVar2 = cy; + ChangeLight(missile[i]._mlid, cx, cy, 8); } - if (!missile[v1]._mirange) { - missile[v1]._mimfnum = 0; - SetMissAnim(ia, MFILE_BIGEXP); - missile[v1]._mirange = missile[v1]._miAnimLen - 1; + if (!missile[i]._mirange) { + missile[i]._mimfnum = 0; + SetMissAnim(i, MFILE_BIGEXP); + missile[i]._mirange = missile[i]._miAnimLen - 1; } } - PutMissile(ia); + PutMissile(i); } void __fastcall MI_Bonespirit(int i) From 7d646891c8317c3c0a722cfc6d26f83a32d46d03 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 15:52:18 +0100 Subject: [PATCH 20/30] MI_Lightning bin exact --- Source/missiles.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 0fa820cd3..e0b882f21 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3816,27 +3816,19 @@ LABEL_27: void __fastcall MI_Lightning(int i) { - int v1; // edi - int v2; // esi - int v3; // eax - int v4; // ebx - int v5; // ecx + int j; - v1 = i; - v2 = i; - v3 = missile[i]._mix; - --missile[v2]._mirange; - v4 = missile[i]._mirange; - if (v3 != missile[i]._misx || missile[v2]._miy != missile[v2]._misy) - CheckMissileCol(i, missile[v2]._midam, missile[v2]._midam, 1, v3, missile[v2]._miy, 0); - if (missile[v2]._miHitFlag) - missile[v2]._mirange = v4; - if (!missile[v2]._mirange) { - v5 = missile[v2]._mlid; - missile[v2]._miDelFlag = TRUE; - AddUnLight(v5); + missile[i]._mirange--; + j = missile[i]._mirange; + if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix, missile[i]._miy, 0); + if (missile[i]._miHitFlag == TRUE) + missile[i]._mirange = j; + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + AddUnLight(missile[i]._mlid); } - PutMissile(v1); + PutMissile(i); } void __fastcall MI_Town(int i) From 6a4c58828cacaeb3a400cf53e2bd4faa21a7a8bd Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 16:28:34 +0100 Subject: [PATCH 21/30] MI_Cbolt bin exact (#696) --- Source/missiles.cpp | 94 +++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 67 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index e0b882f21..69ac96126 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -4956,79 +4956,39 @@ void __fastcall MI_Flamec(int i) void __fastcall MI_Cbolt(int i) { - int v1; // esi - BOOLEAN v2; // zf - int v3; // eax - int v4; // edx - int v5; // eax - int v6; // ecx - int v7; // ecx - int v8; // ecx - int v9; // ecx - int bpath[16]; // [esp+Ch] [ebp-44h] - int ia; // [esp+4Ch] [ebp-4h] + int sx, sy, dy, md; + int bpath[16] = { -1, 0, 1, -1, 0, 1, -1, -1, 0, 0, 1, 1, 0, 1, -1, 0 }; - ia = i; - v1 = i; - --missile[v1]._mirange; - v2 = _LOBYTE(missile[i]._miAnimType) == MFILE_LGHNING; - bpath[0] = -1; - bpath[1] = 0; - bpath[2] = 1; - bpath[3] = -1; - bpath[4] = 0; - bpath[5] = 1; - bpath[6] = -1; - bpath[7] = -1; - bpath[8] = 0; - bpath[9] = 0; - bpath[10] = 1; - bpath[11] = 1; - bpath[12] = 0; - bpath[13] = 1; - bpath[14] = -1; - bpath[15] = 0; - if (!v2) { - v3 = missile[v1]._miVar3; - if (v3) { - missile[v1]._miVar3 = v3 - 1; + missile[i]._mirange--; + if (missile[i]._miAnimType != MFILE_LGHNING) { + if (!missile[i]._miVar3) { + md = (missile[i]._miVar2 + bpath[missile[i]._mirnd]) & 7; + missile[i]._mirnd = (missile[i]._mirnd + 1) & 0xF; + GetMissileVel(i, missile[i]._mix, missile[i]._miy, missile[i]._mix + XDirAdd[md], missile[i]._miy + YDirAdd[md], 8); + missile[i]._miVar3 = 16; } else { - v4 = missile[v1]._mirnd; - v5 = (missile[v1]._miVar2 + bpath[v4]) & 7; - missile[v1]._mirnd = ((_BYTE)v4 + 1) & 0xF; - GetMissileVel( - ia, - missile[v1]._mix, - missile[v1]._miy, - missile[v1]._mix + XDirAdd[v5], - missile[v1]._miy + YDirAdd[v5], - 8); - missile[v1]._miVar3 = 16; + missile[i]._miVar3--; } - v6 = ia; - missile[v1]._mitxoff += missile[v1]._mixvel; - missile[v1]._mityoff += missile[v1]._miyvel; - GetMissilePos(v6); - CheckMissileCol(ia, missile[v1]._midam, missile[v1]._midam, 0, missile[v1]._mix, missile[v1]._miy, 0); - if (missile[v1]._miHitFlag) { - v7 = ia; - missile[v1]._miVar1 = 8; - missile[v1]._mimfnum = 0; - missile[v1]._mixoff = 0; - missile[v1]._miyoff = 0; - SetMissAnim(v7, MFILE_LGHNING); - v8 = ia; - missile[v1]._mirange = missile[v1]._miAnimLen; - GetMissilePos(v8); + missile[i]._mitxoff += missile[i]._mixvel; + missile[i]._mityoff += missile[i]._miyvel; + GetMissilePos(i); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 0, missile[i]._mix, missile[i]._miy, 0); + if (missile[i]._miHitFlag == TRUE) { + missile[i]._miVar1 = 8; + missile[i]._mimfnum = 0; + missile[i]._mixoff = 0; + missile[i]._miyoff = 0; + SetMissAnim(i, MFILE_LGHNING); + missile[i]._mirange = missile[i]._miAnimLen; + GetMissilePos(i); } - ChangeLight(missile[v1]._mlid, missile[v1]._mix, missile[v1]._miy, missile[v1]._miVar1); + ChangeLight(missile[i]._mlid, missile[i]._mix, missile[i]._miy, missile[i]._miVar1); } - if (!missile[v1]._mirange) { - v9 = missile[v1]._mlid; - missile[v1]._miDelFlag = TRUE; - AddUnLight(v9); + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + AddUnLight(missile[i]._mlid); } - PutMissile(ia); + PutMissile(i); } void __fastcall MI_Hbolt(int i) From 9afd45cbeae038ef2c3a02d7408cb4fcbadd01a5 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Tue, 19 Mar 2019 10:48:36 -0500 Subject: [PATCH 22/30] Fix crash in draw town (#692) --- Source/engine.cpp | 6 +++--- Source/town.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index b3d3aa5c2..6643d7e3a 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -15,8 +15,8 @@ static CRITICAL_SECTION sgMemCrit; int SeedCount; // weak int dword_52B99C; // BOOLEAN valid - if x/y are in bounds -const int rand_increment = 1; // unused -const int rand_multiplier = 0x015A4E35; // unused +const int rand_increment = 1; +const int rand_multiplier = 0x015A4E35; void __fastcall CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { @@ -2321,7 +2321,7 @@ void __fastcall SetRndSeed(int s) int __cdecl GetRndSeed() { SeedCount++; - sglGameSeed = 0x015A4E35 * sglGameSeed + 1; + sglGameSeed = rand_multiplier * sglGameSeed + rand_increment; return abs(sglGameSeed); } // 52B97C: using guessed type int sglGameSeed; diff --git a/Source/town.cpp b/Source/town.cpp index 72d2340a7..4bbd04cd8 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -474,7 +474,7 @@ void __fastcall town_draw_clipped_town_2(int x, int y, int a3, int a4, int a5, i Cel2DrawHdrOnly(v13, sy, item[v12]._iAnimData, item[v12]._iAnimFrame, item[v12]._iAnimWidth, a5, 8); } if (dFlags[0][v9] & DFLAG_MONSTER) { - v14 = -1 - dMonster[x][y - 1]; // -1 - *(&dword_52D204 + v9); /* check */ + v14 = -1 - dMonster[y][a3 - 1]; // -1 - *(&dword_52D204 + v9); /* check */ v15 = sx - towner[v14]._tAnimWidth2; if (v14 == pcursmonst) CelDrawHdrClrHL( @@ -506,7 +506,7 @@ void __fastcall town_draw_clipped_town_2(int x, int y, int a3, int a4, int a5, i Cel2DrawHdrOnly(v19, sy, towner[v18]._tAnimData, towner[v18]._tAnimFrame, towner[v18]._tAnimWidth, a5, 8); } if (dFlags[0][v9] & DFLAG_PLAYER) { - v20 = -1 - dPlayer[x][y - 1]; // -1 - *((_BYTE *)&themeLoc[49].height + v9 + 3); + v20 = -1 - dPlayer[y][a3 - 1]; // -1 - *((_BYTE *)&themeLoc[49].height + v9 + 3); v21 = v20; v22 = sy + plr[v21]._pyoff; v23 = sx + plr[v21]._pxoff - plr[v21]._pAnimWidth2; From 80a73da04bdb6697b5efb8159ea160f06517a5a8 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 22:13:03 +0100 Subject: [PATCH 23/30] LoadMissileGFX fix - CEL -> CL2 (#701) --- Source/missiles.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 69ac96126..a719e9c56 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1467,17 +1467,17 @@ void __fastcall LoadMissileGFX(BYTE mi) mfd = &misfiledata[mi]; if (mfd->mFlags & MFLAG_ALLOW_SPECIAL) { - sprintf(pszName, "Missiles\\%s.CEL", mfd->mName); + sprintf(pszName, "Missiles\\%s.CL2", mfd->mName); file = LoadFileInMem(pszName, 0); for (i = 0; i < mfd->mAnimFAmt; i++) mfd->mAnimData[i] = &file[((int *)file)[i]]; } else if (mfd->mAnimFAmt == 1) { - sprintf(pszName, "Missiles\\%s.CEL", mfd->mName); + sprintf(pszName, "Missiles\\%s.CL2", mfd->mName); if (!mfd->mAnimData[0]) mfd->mAnimData[0] = LoadFileInMem(pszName, 0); } else { for (i = 0; i < mfd->mAnimFAmt; i++) { - sprintf(pszName, "Missiles\\%s%i.CEL", mfd->mName, i + 1); + sprintf(pszName, "Missiles\\%s%i.CL2", mfd->mName, i + 1); if (!mfd->mAnimData[i]) { file = LoadFileInMem(pszName, 0); mfd->mAnimData[i] = file; From efba395894ba22ea2660cf331f33528c1f128555 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 21:59:28 +0100 Subject: [PATCH 24/30] MI_Weapexp bin exact fix --- Source/missiles.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index a719e9c56..2fc2d1dfc 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -4361,6 +4361,7 @@ void __fastcall MI_Weapexp(int i) int ExpLight[10] = { 9, 10, 11, 12, 11, 10, 8, 6, 4, 2 }; missile[i]._mirange--; + id = missile[i]._misource; if (missile[i]._miVar2 == 1) { mind = plr[id]._pIFMinDam; maxd = plr[id]._pIFMaxDam; From a86c31b70a813c3af2956b4200a6989becc62dac Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 19:23:05 +0100 Subject: [PATCH 25/30] MI_Nova bin exact --- Source/missiles.cpp | 63 +++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 2fc2d1dfc..182452371 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -4829,51 +4829,34 @@ void __fastcall MI_Wave(int i) void __fastcall MI_Nova(int i) { - int v1; // edi - int v2; // edx - int eax1; // eax - int v4; // ebx - unsigned char *v5; // esi - int v6; // eax - BOOLEAN v7; // zf - int v8; // [esp+Ch] [ebp-18h] - int sy; // [esp+10h] [ebp-14h] - int id; // [esp+14h] [ebp-10h] - int v3; // [esp+18h] [ebp-Ch] - int midir; // [esp+1Ch] [ebp-8h] - signed int micaster; // [esp+20h] [ebp-4h] + int k, id, sx, sy, dir, en, sx1, sy1, dam; - v1 = i; - v2 = 0; - eax1 = missile[i]._misource; - v4 = missile[i]._mix; - v3 = missile[i]._midam; - v8 = 0; + sx1 = 0; + sy1 = 0; id = missile[i]._misource; + dam = missile[i]._midam; + sx = missile[i]._mix; sy = missile[i]._miy; - if (eax1 == -1) { - midir = 0; - micaster = 1; + if (id != -1) { + en = 0; + dir = plr[id]._pdir; } else { - micaster = 0; - midir = plr[eax1]._pdir; - } - v5 = &vCrawlTable[0][7]; - do { - v6 = *(v5 - 1); - if (v2 != v6 || v8 != *v5) { - AddMissile(v4, sy, v4 + v6, sy + *v5, midir, MIS_LIGHTBALL, micaster, id, v3, missile[v1]._mispllvl); - AddMissile(v4, sy, v4 - *(v5 - 1), sy - *v5, midir, MIS_LIGHTBALL, micaster, id, v3, missile[v1]._mispllvl); - AddMissile(v4, sy, v4 - *(v5 - 1), sy + *v5, midir, MIS_LIGHTBALL, micaster, id, v3, missile[v1]._mispllvl); - AddMissile(v4, sy, v4 + *(v5 - 1), sy - *v5, midir, MIS_LIGHTBALL, micaster, id, v3, missile[v1]._mispllvl); - v2 = *(v5 - 1); - v8 = *v5; + dir = 0; + en = 1; + } + for (k = 0; k < 23; k++) { + if (sx1 != vCrawlTable[k][6] || sy1 != vCrawlTable[k][7]) { + AddMissile(sx, sy, sx + vCrawlTable[k][6], sy + vCrawlTable[k][7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx - vCrawlTable[k][6], sy - vCrawlTable[k][7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx - vCrawlTable[k][6], sy + vCrawlTable[k][7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx + vCrawlTable[k][6], sy - vCrawlTable[k][7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); + sx1 = vCrawlTable[k][6]; + sy1 = vCrawlTable[k][7]; } - v5 += 30; - } while ((signed int)v5 < (signed int)&vCrawlTable[23][7]); - v7 = missile[v1]._mirange-- == 1; - if (v7) - missile[v1]._miDelFlag = TRUE; + } + missile[i]._mirange--; + if (missile[i]._mirange == 0) + missile[i]._miDelFlag = TRUE; } void __fastcall MI_Blodboil(int i) From 66d403b599347f501794aea11cfdcef96eb46855 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 22:11:53 +0100 Subject: [PATCH 26/30] MI_Etherealize bin exact --- Source/missiles.cpp | 62 ++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 182452371..79aad72eb 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -4078,52 +4078,34 @@ LABEL_33: void __fastcall MI_Etherealize(int i) { - int v1; // ebx - int v2; // esi - int v3; // edi - int v4; // edi - int v5; // edx - int v6; // eax - int v7; // ecx - int v8; // edx - BOOLEAN v9; // zf - char v10; // al + int src; - v1 = i; - v2 = i; - v3 = missile[i]._misource; - --missile[v2]._mirange; - v4 = v3; - v5 = plr[v4]._pxoff; - v6 = plr[v4].WorldX; - v7 = plr[v4].WorldY; - missile[v2]._mix = v6; - missile[v2]._mitxoff = v5 << 16; - v8 = plr[v4]._pyoff << 16; - v9 = plr[v4]._pmode == PM_WALK3; - missile[v2]._miy = v7; - missile[v2]._mityoff = v8; - if (v9) { - missile[v2]._misx = plr[v4]._px; - missile[v2]._misy = plr[v4]._py; + src = missile[i]._misource; + missile[i]._mirange--; + missile[i]._mix = plr[src].WorldX; + missile[i]._miy = plr[src].WorldY; + missile[i]._mitxoff = plr[src]._pxoff << 16; + missile[i]._mityoff = plr[src]._pyoff << 16; + if (plr[src]._pmode == PM_WALK3) { + missile[i]._misx = plr[src]._px; + missile[i]._misy = plr[src]._py; } else { - missile[v2]._misx = v6; - missile[v2]._misy = v7; + missile[i]._misx = missile[i]._mix; + missile[i]._misy = missile[i]._miy; } - GetMissilePos(v1); - if (plr[v4]._pmode == PM_WALK3) { - if (plr[v4]._pdir == 2) - ++missile[v2]._mix; + GetMissilePos(i); + if (plr[src]._pmode == PM_WALK3) { + if (plr[src]._pdir == 2) + missile[i]._mix++; else - ++missile[v2]._miy; + missile[i]._miy++; } - _LOBYTE(plr[v4]._pSpellFlags) |= 1u; - v10 = plr[v4]._pSpellFlags; - if (!missile[v2]._mirange || plr[v4]._pHitPoints <= 0) { - missile[v2]._miDelFlag = TRUE; - _LOBYTE(plr[v4]._pSpellFlags) = v10 & 0xFE; + plr[src]._pSpellFlags |= 1; + if (!missile[i]._mirange || plr[src]._pHitPoints <= 0) { + missile[i]._miDelFlag = TRUE; + plr[src]._pSpellFlags &= ~0x1; } - PutMissile(v1); + PutMissile(i); } void __fastcall MI_Firemove(int i) From d3ceb832b6e5ae69b92e2edeb4453a8af2f01e52 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 22:49:20 +0100 Subject: [PATCH 27/30] MI_Flash2 bin exact (#705) --- Source/missiles.cpp | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 79aad72eb..518f20a4d 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3936,35 +3936,22 @@ void __fastcall MI_Flash(int i) void __fastcall MI_Flash2(int i) { - int v1; // edi - int v2; // esi - int v3; // eax - int v4; // eax - BOOLEAN v5; // zf - int v6; // esi - - v1 = i; - v2 = i; if (!missile[i]._micaster) { - v3 = missile[v2]._misource; - if (v3 != -1) - plr[v3]._pInvincible = 1; + if (missile[i]._misource != -1) + plr[missile[i]._misource]._pInvincible = TRUE; } - v4 = missile[v2]._miy; - --missile[v2]._mirange; - CheckMissileCol(i, missile[v2]._midam, missile[v2]._midam, 1, missile[v2]._mix - 1, v4 - 1, 1); - CheckMissileCol(v1, missile[v2]._midam, missile[v2]._midam, 1, missile[v2]._mix, missile[v2]._miy - 1, 1); - CheckMissileCol(v1, missile[v2]._midam, missile[v2]._midam, 1, missile[v2]._mix + 1, missile[v2]._miy - 1, 1); - if (!missile[v2]._mirange) { - v5 = missile[v2]._micaster == 0; - missile[v2]._miDelFlag = TRUE; - if (v5) { - v6 = missile[v2]._misource; - if (v6 != -1) - plr[v6]._pInvincible = 0; + missile[i]._mirange--; + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix - 1, missile[i]._miy - 1, 1); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix, missile[i]._miy - 1, 1); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix + 1, missile[i]._miy - 1, 1); + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + if (missile[i]._micaster == 0) { + if (missile[i]._misource != -1) + plr[missile[i]._misource]._pInvincible = FALSE; } } - PutMissile(v1); + PutMissile(i); } void __fastcall MI_Manashield(int i) From 61b955550479b6585e9ac620247bee85d1df2f07 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 18:41:22 +0100 Subject: [PATCH 28/30] MI_Arrow bin exact --- Source/missiles.cpp | 58 +++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 518f20a4d..cbb008c22 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3373,45 +3373,31 @@ void __fastcall MI_LArrow(int i) void __fastcall MI_Arrow(int i) { - int v1; // esi - int v2; // eax - int v3; // eax - int v4; // eax - int v5; // eax - int v6; // edx - int v7; // eax - int v8; // eax - int v9; // ecx - int ia; // [esp+4h] [ebp-4h] + int p, mind, maxd; - v1 = i; - ia = i; - v2 = missile[i]._mixvel; - --missile[v1]._mirange; - missile[v1]._mitxoff += v2; - v3 = missile[i]._miyvel; - ++missile[v1]._midist; - missile[v1]._mityoff += v3; + missile[i]._mirange--; + missile[i]._midist++; + missile[i]._mitxoff += missile[i]._mixvel; + missile[i]._mityoff += missile[i]._miyvel; GetMissilePos(i); - v4 = missile[v1]._misource; - if (v4 == -1) { - v6 = currlevel; - v7 = 2 * currlevel; - } else if (missile[v1]._micaster) { - v8 = v4; - v6 = (unsigned char)monster[v8].mMinDamage; - v7 = (unsigned char)monster[v8].mMaxDamage; + p = missile[i]._misource; + if (p != -1) { + if (!missile[i]._micaster) { + mind = plr[p]._pIMinDam; + maxd = plr[p]._pIMaxDam; + } else { + mind = monster[p].mMinDamage; + maxd = monster[p].mMaxDamage; + } } else { - v5 = v4; - v6 = plr[v5]._pIMinDam; - v7 = plr[v5]._pIMaxDam; - } - v9 = missile[v1]._mix; - if (v9 != missile[v1]._misx || missile[v1]._miy != missile[v1]._misy) - CheckMissileCol(ia, v6, v7, 0, v9, missile[v1]._miy, 0); - if (!missile[v1]._mirange) - missile[v1]._miDelFlag = TRUE; - PutMissile(ia); + mind = currlevel; + maxd = 2 * currlevel; + } + if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) + CheckMissileCol(i, mind, maxd, 0, missile[i]._mix, missile[i]._miy, 0); + if (!missile[i]._mirange) + missile[i]._miDelFlag = TRUE; + PutMissile(i); } void __fastcall MI_Firebolt(int i) From 24c889c48649e7a3f9c06c2787dff533f442c6de Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 22:52:15 +0100 Subject: [PATCH 29/30] MI_Flash bin exact (#704) --- Source/missiles.cpp | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index cbb008c22..a8d5f6d93 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3886,38 +3886,25 @@ void __fastcall MI_Town(int i) void __fastcall MI_Flash(int i) { - int v1; // edi - int v2; // esi - int v3; // eax - int v4; // eax - BOOLEAN v5; // zf - int v6; // esi - - v1 = i; - v2 = i; if (!missile[i]._micaster) { - v3 = missile[v2]._misource; - if (v3 != -1) - plr[v3]._pInvincible = 1; + if (missile[i]._misource != -1) + plr[missile[i]._misource]._pInvincible = TRUE; } - v4 = missile[v2]._mix; - --missile[v2]._mirange; - CheckMissileCol(i, missile[v2]._midam, missile[v2]._midam, 1, v4 - 1, missile[v2]._miy, 1); - CheckMissileCol(v1, missile[v2]._midam, missile[v2]._midam, 1, missile[v2]._mix, missile[v2]._miy, 1); - CheckMissileCol(v1, missile[v2]._midam, missile[v2]._midam, 1, missile[v2]._mix + 1, missile[v2]._miy, 1); - CheckMissileCol(v1, missile[v2]._midam, missile[v2]._midam, 1, missile[v2]._mix - 1, missile[v2]._miy + 1, 1); - CheckMissileCol(v1, missile[v2]._midam, missile[v2]._midam, 1, missile[v2]._mix, missile[v2]._miy + 1, 1); - CheckMissileCol(v1, missile[v2]._midam, missile[v2]._midam, 1, missile[v2]._mix + 1, missile[v2]._miy + 1, 1); - if (!missile[v2]._mirange) { - v5 = missile[v2]._micaster == 0; - missile[v2]._miDelFlag = TRUE; - if (v5) { - v6 = missile[v2]._misource; - if (v6 != -1) - plr[v6]._pInvincible = 0; + missile[i]._mirange--; + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix - 1, missile[i]._miy, 1); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix, missile[i]._miy, 1); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix + 1, missile[i]._miy, 1); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix - 1, missile[i]._miy + 1, 1); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix, missile[i]._miy + 1, 1); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix + 1, missile[i]._miy + 1, 1); + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + if (missile[i]._micaster == 0) { + if (missile[i]._misource != -1) + plr[missile[i]._misource]._pInvincible = FALSE; } } - PutMissile(v1); + PutMissile(i); } void __fastcall MI_Flash2(int i) From fa59e036c8c1e5d3a5535c113092c98a9c9add7e Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 19 Mar 2019 23:13:06 +0100 Subject: [PATCH 30/30] MI_Town bin exact --- Source/missiles.cpp | 82 +++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 58 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index a8d5f6d93..98b0fa5dc 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3819,69 +3819,35 @@ void __fastcall MI_Lightning(int i) void __fastcall MI_Town(int i) { - int v1; // esi - int v2; // eax - int *v3; // edi - int v4; // ecx - int ExpLight[17]; // [esp+8h] [ebp-4Ch] - int ia; // [esp+4Ch] [ebp-8h] - int arglist; // [esp+50h] [ebp-4h] + int ExpLight[17] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15 }; + int p; - v1 = i; - ExpLight[14] = 15; - ExpLight[15] = 15; - ExpLight[16] = 15; - v2 = missile[i]._mirange; - ia = i; - ExpLight[0] = 1; - ExpLight[1] = 2; - ExpLight[2] = 3; - ExpLight[3] = 4; - ExpLight[4] = 5; - ExpLight[5] = 6; - ExpLight[6] = 7; - ExpLight[7] = 8; - ExpLight[8] = 9; - ExpLight[9] = 10; - ExpLight[10] = 11; - ExpLight[11] = 12; - ExpLight[12] = 13; - ExpLight[13] = 14; - if (v2 > 1) - missile[v1]._mirange = v2 - 1; - if (missile[v1]._mirange == missile[v1]._miVar1) + if (missile[i]._mirange > 1) + missile[i]._mirange--; + if (missile[i]._mirange == missile[i]._miVar1) SetMissDir(i, 1); - if (currlevel && missile[v1]._mimfnum != 1 && missile[v1]._mirange) { - if (!missile[v1]._miVar2) - missile[v1]._mlid = AddLight(missile[v1]._mix, missile[v1]._miy, 1); - ChangeLight(missile[v1]._mlid, missile[v1]._mix, missile[v1]._miy, ExpLight[missile[v1]._miVar2]); - ++missile[v1]._miVar2; - } - arglist = 0; - v3 = &plr[0].plrlevel; - do { - if (*((_BYTE *)v3 - 23)) { - if (currlevel == *v3 - && !*((_BYTE *)v3 + 267) - && !*(v3 - 13) - && v3[1] == missile[v1]._mix - && v3[2] == missile[v1]._miy) { - ClrPlrPath(arglist); - if (arglist == myplr) { - NetSendCmdParam1(TRUE, CMD_WARP, missile[v1]._misource); - *(v3 - 13) = 10; - } + if (currlevel && missile[i]._mimfnum != 1 && missile[i]._mirange) { + if (!missile[i]._miVar2) + missile[i]._mlid = AddLight(missile[i]._mix, missile[i]._miy, 1); + ChangeLight(missile[i]._mlid, missile[i]._mix, missile[i]._miy, ExpLight[missile[i]._miVar2]); + missile[i]._miVar2++; + } + + for (p = 0; p < 4; p++) { + if (plr[p].plractive && currlevel == plr[p].plrlevel && !plr[p]._pLvlChanging && !plr[p]._pmode && plr[p].WorldX == missile[i]._mix && plr[p].WorldY == missile[i]._miy) { + ClrPlrPath(p); + if (p == myplr) { + NetSendCmdParam1(TRUE, CMD_WARP, missile[i]._misource); + plr[p]._pmode = 10; } } - ++arglist; - v3 += 5430; - } while ((signed int)v3 < (signed int)&plr[4].plrlevel); - if (!missile[v1]._mirange) { - v4 = missile[v1]._mlid; - missile[v1]._miDelFlag = TRUE; - AddUnLight(v4); } - PutMissile(ia); + + if (!missile[i]._mirange) { + missile[i]._miDelFlag = TRUE; + AddUnLight(missile[i]._mlid); + } + PutMissile(i); } void __fastcall MI_Flash(int i)