Browse Source

Clean up DeltaLoadLevel

pull/25/head
Anders Jenbo 7 years ago
parent
commit
5bc5da3597
  1. 2
      Source/items.cpp
  2. 2
      Source/items.h
  3. 347
      Source/msg.cpp
  4. 2
      Source/msg.h
  5. 6
      structs.h

2
Source/items.cpp

@ -3034,7 +3034,7 @@ void __fastcall RecreateItem(int ii, int idx, unsigned short ic, int iseed, int
} }
} }
void __fastcall RecreateEar(int ii, unsigned short ic, int iseed, unsigned char Id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff) void __fastcall RecreateEar(int ii, unsigned short ic, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff)
{ {
SetPlrHandItem(&item[ii], IDI_EAR); SetPlrHandItem(&item[ii], IDI_EAR);
tempstr[0] = (ic >> 8) & 0x7F; tempstr[0] = (ic >> 8) & 0x7F;

2
Source/items.h

@ -63,7 +63,7 @@ void __fastcall SetupAllUseful(int ii, int iseed, int lvl);
void __fastcall CreateRndUseful(int pnum, int x, int y, unsigned char sendmsg); void __fastcall CreateRndUseful(int pnum, int x, int y, unsigned char sendmsg);
void __fastcall CreateTypeItem(int x, int y, unsigned char onlygood, int itype, int imisc, int sendmsg, int delta); void __fastcall CreateTypeItem(int x, int y, unsigned char onlygood, int itype, int imisc, int sendmsg, int delta);
void __fastcall RecreateItem(int ii, int idx, unsigned short ic, int iseed, int ivalue); void __fastcall RecreateItem(int ii, int idx, unsigned short ic, int iseed, int ivalue);
void __fastcall RecreateEar(int ii, unsigned short ic, int iseed, unsigned char Id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff); void __fastcall RecreateEar(int ii, unsigned short ic, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff);
void __fastcall SpawnQuestItem(int itemid, int x, int y, int randarea, int selflag); void __fastcall SpawnQuestItem(int itemid, int x, int y, int randarea, int selflag);
void __cdecl SpawnRock(); void __cdecl SpawnRock();
void __fastcall RespawnItem(int i, BOOL FlipFlag); void __fastcall RespawnItem(int i, BOOL FlipFlag);

347
Source/msg.cpp

@ -15,7 +15,7 @@ static DJunk sgJunk;
static TMegaPkt *sgpMegaPkt; static TMegaPkt *sgpMegaPkt;
static BYTE sgbDeltaChanged; static BYTE sgbDeltaChanged;
static BYTE sgbDeltaChunks; static BYTE sgbDeltaChunks;
int deltaload; BOOL deltaload;
BYTE gbBufferMsgs; BYTE gbBufferMsgs;
int pkt_counter; int pkt_counter;
@ -331,7 +331,7 @@ void __cdecl delta_init()
memset(&sgJunk, 0xFF, sizeof(sgJunk)); memset(&sgJunk, 0xFF, sizeof(sgJunk));
memset(sgLevels, 0xFF, sizeof(sgLevels)); memset(sgLevels, 0xFF, sizeof(sgLevels));
memset(sgLocals, 0, sizeof(sgLocals)); memset(sgLocals, 0, sizeof(sgLocals));
deltaload = 0; deltaload = FALSE;
} }
// 67618C: using guessed type char sgbDeltaChanged; // 67618C: using guessed type char sgbDeltaChanged;
// 676190: using guessed type int deltaload; // 676190: using guessed type int deltaload;
@ -526,228 +526,153 @@ void __cdecl DeltaSaveLevel()
void __cdecl DeltaLoadLevel() void __cdecl DeltaLoadLevel()
{ {
int v0; // ebx int ii, ot;
int *v1; // esi int i, j, k, l;
int v2; // eax int x, y, xx, yy;
int v3; // ecx BOOL done;
int v4; // edx
int v5; // edi
char v6; // al
int v7; // eax
signed int v8; // esi
int v9; // eax
char v10; // cl
int v11; // eax
char *v12; // edx
int v13; // eax
int v14; // ebx
int *v15; // edx
unsigned short v16; // cx
int v17; // ST1C_4
int v18; // ST18_4
int v19; // eax
int v20; // ecx
int v21; // edx
int v22; // eax
int v23; // eax
int v24; // esi
int v25; // edi
int v26; // eax
int v27; // eax
int v28; // esi
unsigned char v29; // al
int j; // esi
int v31; // eax
signed int v32; // [esp+0h] [ebp-24h]
int v33; // [esp+4h] [ebp-20h]
int o2; // [esp+8h] [ebp-1Ch]
int i; // [esp+Ch] [ebp-18h]
signed int v36; // [esp+10h] [ebp-14h]
int v37; // [esp+14h] [ebp-10h]
signed int v38; // [esp+18h] [ebp-Ch]
signed int v39; // [esp+1Ch] [ebp-8h]
int v40; // [esp+20h] [ebp-4h]
signed int v41; // [esp+20h] [ebp-4h]
if (gbMaxPlayers != 1) { if (gbMaxPlayers == 1) {
deltaload = 1; return;
if (currlevel != 0) { }
v0 = 0;
if (nummonsters > 0) { deltaload = TRUE;
v40 = 0; if (currlevel != 0) {
v1 = &monster[0]._mfuty; for (i = 0; i < nummonsters; i++) {
do { if (sgLevels[currlevel].monster[i]._mx != 0xFF) {
if (sgLevels[currlevel].monster[v40]._mx != -1) { M_ClearSquares(i);
M_ClearSquares(v0); x = sgLevels[currlevel].monster[i]._mx;
v2 = v40 * 9 + 4721 * currlevel; y = sgLevels[currlevel].monster[i]._my;
v3 = *((unsigned char *)&sgLevels[0].monster[0]._mx + v2); monster[i]._mx = x;
v4 = *((unsigned char *)&sgLevels[0].monster[0]._my + v2); monster[i]._my = y;
v5 = *(int *)((char *)&sgLevels[0].monster[0]._mhitpoints + v2); monster[i]._moldx = x;
*(v1 - 3) = v3; monster[i]._moldy = y;
*(v1 - 2) = v4; monster[i]._mfutx = x;
v1[1] = v3; monster[i]._mfuty = y;
v1[2] = v4; if (sgLevels[currlevel].monster[i]._mhitpoints != -1)
*(v1 - 1) = v3; monster[i]._mhitpoints = sgLevels[currlevel].monster[i]._mhitpoints;
*v1 = v4; if (!sgLevels[currlevel].monster[i]._mhitpoints) {
if (v5 != -1) monster[i]._moldx = x;
v1[26] = v5; monster[i]._moldy = y;
if (v5) { M_ClearSquares(i);
decode_enemy(v0, *((unsigned char *)&sgLevels[0].monster[0]._menemy + v2)); if (monster[i]._mAi != AI_DIABLO) {
v7 = *(v1 - 3); if (!monster[i]._uniqtype)
if (v7 && v7 != 1 || *(v1 - 2)) /// ASSERT: assert(monster[i].MType != NULL);
dMonster[v7][*(v1 - 2)] = v0 + 1; AddDead(monster[i]._mx, monster[i]._my, monster[i].MType->mdeadval, (direction)monster[i]._mdir);
if ((signed int)v1 >= (signed int)&monster[4]._mfuty) { else
M_StartStand(v0, v1[7]); AddDead(monster[i]._mx, monster[i]._my, monster[i]._udeadval, (direction)monster[i]._mdir);
} else {
MAI_Golum(v0);
v1[28] |= 0x30u;
}
*((_BYTE *)v1 + 116) = sgLevels[currlevel].monster[v40]._mactive;
} else {
v1[1] = v3;
v1[2] = v4;
M_ClearSquares(v0);
if (*((_BYTE *)v1 + 108) != 27) {
if (*((_BYTE *)v1 + 144))
v6 = *((_BYTE *)v1 + 146);
else
v6 = *(_BYTE *)(v1[44] + 317);
AddDead(*(v1 - 3), *(v1 - 2), v6, (direction)v1[7]);
}
v1[16] = 1;
M_UpdateLeader(v0);
}
} }
++v40; monster[i]._mDelFlag = TRUE;
++v0; M_UpdateLeader(i);
v1 += 57; } else {
} while (v0 < nummonsters); decode_enemy(i, sgLevels[currlevel].monster[i]._menemy);
if (monster[i]._mx && monster[i]._mx != 1 || monster[i]._my)
dMonster[monster[i]._mx][monster[i]._my] = i + 1;
if (i < 4) {
MAI_Golum(i);
monster[i]._mFlags |= (MFLAG_TARGETS_MONSTER | MFLAG_GOLEM);
} else {
M_StartStand(i, monster[i]._mdir);
}
monster[i]._msquelch = sgLevels[currlevel].monster[i]._mactive;
}
} }
memcpy(automapview, &sgLocals[currlevel], sizeof(automapview));
} }
v8 = 0; memcpy(automapview, &sgLocals[currlevel], sizeof(automapview));
i = 0; }
v32 = 0;
do { for (i = 0; i < MAXITEMS; i++) {
v9 = v8 + 4721 * currlevel; if (sgLevels[currlevel].item[i].bCmd != 0xFF) {
v10 = *(&sgLevels[0].item[0].bCmd + v9); if (sgLevels[currlevel].item[i].bCmd == CMD_WALKXY) {
if (v10 != 0xFF) { ii = FindGetItem(
if (v10 == 1) { sgLevels[currlevel].item[i].wIndx,
v11 = FindGetItem( sgLevels[currlevel].item[i].wCI,
*(unsigned short *)((char *)&sgLevels[0].item[0].wIndx + v9), sgLevels[currlevel].item[i].dwSeed);
*(short *)((char *)&sgLevels[0].item[0].wCI + v9), if (ii != -1) {
*(int *)((char *)&sgLevels[0].item[0].dwSeed + v9)); if (dItem[item[ii]._ix][item[ii]._iy] == ii + 1)
if (v11 != -1) { dItem[item[ii]._ix][item[ii]._iy] = 0;
v12 = &dItem[item[v11]._ix][item[v11]._iy]; DeleteItem(ii, i);
if (*v12 == v11 + 1)
*v12 = 0;
DeleteItem(v11, i);
}
} }
v13 = v8 + 4721 * currlevel; }
if (*(&sgLevels[0].item[0].bCmd + v13) == 2) { if (sgLevels[currlevel].item[i].bCmd == CMD_ACK_PLRINFO) {
v14 = itemavail[0]; ii = itemavail[0];
v33 = itemavail[0]; itemavail[0] = itemavail[MAXITEMS - numitems - 1];
v15 = &itemavail[MAXITEMS - numitems - 1]; itemactive[numitems] = ii;
itemactive[numitems] = itemavail[0]; if (sgLevels[currlevel].item[i].wIndx == IDI_EAR) {
v16 = *(short *)((char *)&sgLevels[0].item[0].wIndx + v13); RecreateEar(
itemavail[0] = *v15; ii,
if (v16 == IDI_EAR) { sgLevels[currlevel].item[i].wCI,
RecreateEar( sgLevels[currlevel].item[i].dwSeed,
v14, sgLevels[currlevel].item[i].bId,
*(short *)((char *)&sgLevels[0].item[0].wCI + v13), sgLevels[currlevel].item[i].bDur,
*(int *)((char *)&sgLevels[0].item[0].dwSeed + v13), sgLevels[currlevel].item[i].bMDur,
*(&sgLevels[0].item[0].bId + v13), sgLevels[currlevel].item[i].bCh,
*((unsigned char *)&sgLevels[0].item[0].bDur + v13), sgLevels[currlevel].item[i].bMCh,
*((unsigned char *)&sgLevels[0].item[0].bMDur + v13), sgLevels[currlevel].item[i].wValue,
*((unsigned char *)&sgLevels[0].item[0].bCh + v13), sgLevels[currlevel].item[i].dwBuff);
*((unsigned char *)&sgLevels[0].item[0].bMCh + v13), } else {
*(unsigned short *)((char *)&sgLevels[0].item[0].wValue + v13), RecreateItem(
*(int *)((char *)&sgLevels[0].item[0].dwBuff + v13)); ii,
} else { sgLevels[currlevel].item[i].wIndx,
v17 = *(unsigned short *)((char *)&sgLevels[0].item[0].wValue + v13); sgLevels[currlevel].item[i].wCI,
v18 = *(int *)((char *)&sgLevels[0].item[0].dwSeed + v13); sgLevels[currlevel].item[i].dwSeed,
_LOWORD(v13) = *(short *)((char *)&sgLevels[0].item[0].wCI + v13); sgLevels[currlevel].item[i].wValue);
RecreateItem(v14, v16, v13, v18, v17); if (sgLevels[currlevel].item[i].bId)
v19 = v8 + 4721 * currlevel; item[ii]._iIdentified = TRUE;
if (*(&sgLevels[0].item[0].bId + v19)) item[ii]._iDurability = sgLevels[currlevel].item[i].bDur;
item[v14]._iIdentified = TRUE; item[ii]._iMaxDur = sgLevels[currlevel].item[i].bMDur;
v20 = v14; item[ii]._iCharges = sgLevels[currlevel].item[i].bCh;
item[v20]._iDurability = *((unsigned char *)&sgLevels[0].item[0].bDur + v19); item[ii]._iMaxCharges = sgLevels[currlevel].item[i].bMCh;
item[v20]._iMaxDur = *((unsigned char *)&sgLevels[0].item[0].bMDur + v19); }
v21 = *((unsigned char *)&sgLevels[0].item[0].bCh + v19); x = sgLevels[currlevel].item[i].x;
v22 = *((unsigned char *)&sgLevels[0].item[0].bMCh + v19); y = sgLevels[currlevel].item[i].y;
item[v20]._iCharges = v21; if (!CanPut(x, y)) {
item[v20]._iMaxCharges = v22; done = FALSE;
} for (k = 1; k < 50 && !done; k++) {
v23 = v8 + 4721 * currlevel; for (j = -k; j <= k && !done; j++) {
v24 = *((unsigned char *)&sgLevels[0].item[0].x + v23); yy = y + j;
v25 = *((unsigned char *)&sgLevels[0].item[0].y + v23); for (l = -k; l <= k && !done; l++) {
if (!CanPut(v24, v25)) { xx = x + l;
v39 = 0; if (CanPut(xx, yy)) {
v26 = -1; done = TRUE;
v41 = 1; x = xx;
v36 = -1; y = yy;
do { }
if (v39)
break;
v37 = v26;
while (v26 <= v41 && !v39) {
o2 = v25 + v37;
v38 = v36;
do {
if (v39)
break;
if (CanPut(v38 + v24, o2)) {
v25 = o2;
v39 = 1;
v24 += v38;
}
++v38;
v14 = v33;
} while (v38 <= v41);
v26 = ++v37;
} }
++v41; }
v26 = v36-- - 1;
} while (v36 > -50);
} }
v27 = v14;
item[v27]._ix = v24;
item[v27]._iy = v25;
dItem[v24][v25] = v14 + 1;
RespawnItem(v14, 0);
++numitems;
v8 = v32;
} }
item[ii]._ix = x;
item[ii]._iy = y;
dItem[x][y] = ii + 1;
RespawnItem(ii, 0);
numitems++;
} }
++i; }
v8 += 22; }
v32 = v8;
} while (v8 < 2794); if (currlevel != 0) {
if (currlevel != 0) { for (i = 0; i < MAXOBJECTS; i++) {
v28 = 0; switch (sgLevels[currlevel].object[i].bCmd) {
do { case CMD_OPENDOOR:
v29 = sgLevels[currlevel].object[v28].bCmd; case CMD_CLOSEDOOR:
if (v29 >= CMD_OPENDOOR) { case CMD_OPERATEOBJ:
if (v29 <= CMD_PLROPOBJ) { case CMD_PLROPOBJ:
SyncOpObject(-1, v29, v28); SyncOpObject(-1, sgLevels[currlevel].object[i].bCmd, i);
} else if (v29 == CMD_BREAKOBJ) { break;
SyncBreakObj(-1, v28); case CMD_BREAKOBJ:
} SyncBreakObj(-1, i);
} break;
++v28;
} while (v28 < 127);
for (j = 0; j < nobjects; ++j) {
v31 = object[objectactive[j]]._otype;
if (v31 == OBJ_TRAPL || v31 == OBJ_TRAPR)
Obj_Trap(objectactive[j]);
} }
} }
deltaload = 0;
for (i = 0; i < nobjects; i++) {
ot = object[objectactive[i]]._otype;
if (ot == OBJ_TRAPL || ot == OBJ_TRAPR)
Obj_Trap(objectactive[i]);
}
} }
deltaload = FALSE;
} }
// 676190: using guessed type int deltaload;
// 679660: using guessed type char gbMaxPlayers; // 679660: using guessed type char gbMaxPlayers;
void __fastcall NetSendCmd(BOOL bHiPri, BYTE bCmd) void __fastcall NetSendCmd(BOOL bHiPri, BYTE bCmd)

2
Source/msg.h

@ -2,7 +2,7 @@
#ifndef __MSG_H__ #ifndef __MSG_H__
#define __MSG_H__ #define __MSG_H__
extern int deltaload; extern BOOL deltaload;
extern BYTE gbBufferMsgs; extern BYTE gbBufferMsgs;
extern int pkt_counter; extern int pkt_counter;

6
structs.h

@ -898,10 +898,10 @@ typedef struct TPkt {
} TPkt; } TPkt;
typedef struct DMonsterStr { typedef struct DMonsterStr {
char _mx; BYTE _mx;
char _my; BYTE _my;
BYTE _mdir; BYTE _mdir;
char _menemy; BYTE _menemy;
char _mactive; char _mactive;
int _mhitpoints; int _mhitpoints;
} DMonsterStr; } DMonsterStr;

Loading…
Cancel
Save