From 9c640ff14343809d3f0730fc0948fe0a1bee01f1 Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 02:07:18 -0700 Subject: [PATCH 01/11] Load 32 bit save files --- Source/loadsave.cpp | 533 +++++++++++++++++++++++++++++++++++++++++++- Source/loadsave.h | 7 +- structs.h | 20 +- 3 files changed, 546 insertions(+), 14 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index e5180d911d2..f490f108530 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -174,11 +174,13 @@ void LoadGame(BOOL firstflag) gbProcessPlayers = TRUE; } +// Load a byte-size char from the buffer char BLoad() { return *tbuff++; } +// Redundant? int WLoad() { int rv = *tbuff++ << 24; @@ -189,6 +191,7 @@ int WLoad() return rv; } +// Load a 32 bit integer from the buffer int ILoad() { int rv = *tbuff++ << 24; @@ -207,38 +210,548 @@ BOOL OLoad() return FALSE; } +// Consume an int from tbuff with memcpy - copies directly, doesn't change byte order +void CopyInt(int & dst) +{ + memcpy(&dst, tbuff, 4); + tbuff += 4; +} + +void CopyInt(unsigned int & dst) +{ + memcpy(&dst, tbuff, 4); + tbuff += 4; +} + +void CopyShort(unsigned short & dst) +{ + memcpy(&dst, tbuff, 2); + tbuff += 2; +} + +void CopyShort(short & dst) +{ + memcpy(&dst, tbuff, 2); + tbuff += 2; +} + +void CopyShorts(const int n, unsigned short * dst) +{ + memcpy(dst, tbuff, 2 * n); + tbuff += 2 * n; +} + +// Copy an int array of size n +void CopyInts(const int n, int* dst) +{ + memcpy(dst, tbuff, 4 * n); + tbuff += 4 * n; +} + +void CopyBytes(const int n, unsigned char *dst) +{ + memcpy(dst, tbuff, n); + tbuff += n; +} + +void CopyChar(unsigned char & dst) +{ + memcpy(&dst, tbuff, 1); + tbuff += 1; +} + +void CopyChar(char & dst) +{ + memcpy(&dst, tbuff, 1); + tbuff += 1; +} + +void CopyInt64(long long unsigned int & dst) +{ + memcpy(&dst, tbuff, 8); + tbuff += 8; +} + void LoadPlayer(int i) { - memcpy(&plr[i], tbuff, sizeof(*plr) - (10 * sizeof(void *))); - tbuff += sizeof(*plr) - (10 * sizeof(void *)); // omit last 10 pointers + PlayerStruct *pPlayer = &plr[i]; + CopyInt(pPlayer->_pmode); + CopyBytes(25, pPlayer->walkpath); + CopyBytes(1, &pPlayer->plractive); + tbuff += 2; // Some padding here? + CopyInt(pPlayer->destAction); + CopyInt(pPlayer->destParam1); + CopyInt(pPlayer->destParam2); + CopyInt(pPlayer->destParam3); + CopyInt(pPlayer->destParam4); + CopyInt(pPlayer->plrlevel); + CopyInt(pPlayer->WorldX); + CopyInt(pPlayer->WorldY); + CopyInt(pPlayer->_px); + CopyInt(pPlayer->_py); + CopyInt(pPlayer->_ptargx); + CopyInt(pPlayer->_ptargy); + CopyInt(pPlayer->_pownerx); + CopyInt(pPlayer->_pownery); + CopyInt(pPlayer->_poldx); + CopyInt(pPlayer->_poldy); + CopyInt(pPlayer->_pxoff); + CopyInt(pPlayer->_pyoff); + CopyInt(pPlayer->_pxvel); + CopyInt(pPlayer->_pyvel); + CopyInt(pPlayer->_pdir); + CopyInt(pPlayer->_nextdir); + CopyInt(pPlayer->_pgfxnum); + tbuff += 4; // Skip pointers + CopyInt(pPlayer->_pAnimDelay); + CopyInt(pPlayer->_pAnimCnt); + CopyInt(pPlayer->_pAnimLen); + CopyInt(pPlayer->_pAnimFrame); + CopyInt(pPlayer->_pAnimWidth); + CopyInt(pPlayer->_pAnimWidth2); + CopyInt(pPlayer->_peflag); + CopyInt(pPlayer->_plid); + CopyInt(pPlayer->_pvid); + + CopyInt(pPlayer->_pSpell); + CopyChar(pPlayer->_pSplType); + CopyChar(pPlayer->_pSplFrom); + CopyInt(pPlayer->_pTSpell); + CopyChar(pPlayer->_pTSplType); + tbuff += 5; + CopyInt(pPlayer->_pRSpell); + CopyChar(pPlayer->_pRSplType); + tbuff += 3; + CopyInt(pPlayer->_pSBkSpell); + CopyChar(pPlayer->_pSBkSplType); + + CopyBytes(64, pPlayer->_pSplLvl); + tbuff += 7; + CopyInt64(pPlayer->_pMemSpells); + CopyInt64(pPlayer->_pAblSpells); + CopyInt64(pPlayer->_pScrlSpells); + CopyChar(pPlayer->_pSpellFlags); + tbuff += 3; + CopyInts(4, pPlayer->_pSplHotKey); + CopyBytes(4, pPlayer->_pSplTHotKey); + CopyInt(pPlayer->_pwtype); + CopyChar(pPlayer->_pBlockFlag); + CopyChar(pPlayer->_pInvincible); + CopyChar(pPlayer->_pLightRad); + CopyChar(pPlayer->_pLvlChanging); + CopyBytes(PLR_NAME_LEN, pPlayer->_pName); + CopyChar(pPlayer->_pClass); + tbuff += 3; + CopyInt(pPlayer->_pStrength); + CopyInt(pPlayer->_pBaseStr); + CopyInt(pPlayer->_pMagic); + CopyInt(pPlayer->_pBaseMag); + CopyInt(pPlayer->_pDexterity); + CopyInt(pPlayer->_pBaseDex); + CopyInt(pPlayer->_pVitality); + CopyInt(pPlayer->_pBaseVit); + CopyInt(pPlayer->_pStatPts); + CopyInt(pPlayer->_pDamageMod); + CopyInt(pPlayer->_pBaseToBlk); + CopyInt(pPlayer->_pHPBase); + CopyInt(pPlayer->_pMaxHPBase); + CopyInt(pPlayer->_pHitPoints); + CopyInt(pPlayer->_pMaxHP); + CopyInt(pPlayer->_pHPPer); + CopyInt(pPlayer->_pManaBase); + CopyInt(pPlayer->_pMaxManaBase); + CopyInt(pPlayer->_pMana); + CopyInt(pPlayer->_pMaxMana); + CopyInt(pPlayer->_pManaPer); + CopyChar(pPlayer->_pLevel); + CopyChar(pPlayer->_pMaxLvl); + tbuff += 2; + CopyInt(pPlayer->_pExperience); + CopyInt(pPlayer->_pMaxExp); + CopyInt(pPlayer->_pNextExper); + CopyChar(pPlayer->_pArmorClass); + CopyChar(pPlayer->_pMagResist); + CopyChar(pPlayer->_pFireResist); + CopyChar(pPlayer->_pLghtResist); + CopyInt(pPlayer->_pGold); + CopyInt(pPlayer->_pInfraFlag); + CopyInt(pPlayer->_pVar1); + CopyInt(pPlayer->_pVar2); + CopyInt(pPlayer->_pVar3); + CopyInt(pPlayer->_pVar4); + CopyInt(pPlayer->_pVar5); + CopyInt(pPlayer->_pVar6); + CopyInt(pPlayer->_pVar7); + CopyInt(pPlayer->_pVar8); + CopyBytes(NUMLEVELS, pPlayer->_pLvlVisited); + CopyBytes(NUMLEVELS, pPlayer->_pSLvlVisited); // only 10 used + tbuff += 2; + CopyInt(pPlayer->_pGFXLoad); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + CopyInt(pPlayer->_pNFrames); + CopyInt(pPlayer->_pNWidth); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(pPlayer->_pWFrames); + CopyInt(pPlayer->_pWWidth); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(pPlayer->_pAFrames); + CopyInt(pPlayer->_pAWidth); + CopyInt(pPlayer->_pAFNum); + + tbuff += sizeof(__uint32_t) * 24; // Skip 24 pointers + + CopyInt(pPlayer->_pSFrames); + CopyInt(pPlayer->_pSWidth); + CopyInt(pPlayer->_pSFNum); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(pPlayer->_pHFrames); + CopyInt(pPlayer->_pHWidth); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(pPlayer->_pDFrames); + CopyInt(pPlayer->_pDWidth); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(pPlayer->_pBFrames); + CopyInt(pPlayer->_pBWidth); + + CopyItems(NUM_INVLOC, pPlayer->InvBody); + CopyItems(NUM_INV_GRID_ELEM, pPlayer->InvList); + + CopyInt(pPlayer->_pNumInv); + CopyBytes(NUM_INV_GRID_ELEM, pPlayer->InvGrid); + CopyItems(MAXBELTITEMS, pPlayer->SpdList); + CopyItem(&pPlayer->HoldItem); + CopyInt(pPlayer->_pIMinDam); + CopyInt(pPlayer->_pIMaxDam); + CopyInt(pPlayer->_pIAC); + CopyInt(pPlayer->_pIBonusDam); + CopyInt(pPlayer->_pIBonusToHit); + CopyInt(pPlayer->_pIBonusAC); + CopyInt(pPlayer->_pIBonusDamMod); + tbuff += 4; + CopyInt64(pPlayer->_pISpells); + CopyInt(pPlayer->_pIFlags); + CopyInt(pPlayer->_pIGetHit); + CopyChar(pPlayer->_pISplLvlAdd); + CopyChar(pPlayer->_pISplCost); + tbuff += 2; + CopyInt(pPlayer->_pISplDur); + CopyInt(pPlayer->_pIEnAc); + CopyInt(pPlayer->_pIFMinDam); + CopyInt(pPlayer->_pIFMaxDam); + CopyInt(pPlayer->_pILMinDam); + CopyInt(pPlayer->_pILMaxDam); + CopyInt(pPlayer->_pOilType); + CopyChar(pPlayer->pTownWarps); + CopyChar(pPlayer->pDungMsgs); + CopyChar(pPlayer->pLvlLoad); + CopyChar(pPlayer->pBattleNet); + CopyChar(pPlayer->pManaShield); + CopyBytes(3, pPlayer->bReserved); + CopyShorts(8, pPlayer->wReserved); + CopyInt(pPlayer->pDiabloKillLevel); + CopyInts(7, pPlayer->dwReserved); + + // Omit 10 pointers + } void LoadMonster(int i) { - memcpy(&monster[i], tbuff, sizeof(*monster) - (3 * sizeof(void *))); - tbuff += sizeof(*monster) - (3 * sizeof(void *)); // omit last 3 pointers + MonsterStruct *pMonster = &monster[i]; + + CopyInt(pMonster->_mMTidx); + CopyInt(pMonster->_mmode); + + CopyChar(pMonster->_mgoal); + tbuff += 3; + + CopyInt(pMonster->_mgoalvar1); + CopyInt(pMonster->_mgoalvar2); + CopyInt(pMonster->_mgoalvar3); + CopyInt(pMonster->field_18); + + CopyChar(pMonster->_pathcount); + tbuff += 3; + + CopyInt(pMonster->_mx); + CopyInt(pMonster->_my); + CopyInt(pMonster->_mfutx); + CopyInt(pMonster->_mfuty); + CopyInt(pMonster->_moldx); + CopyInt(pMonster->_moldy); + CopyInt(pMonster->_mxoff); + CopyInt(pMonster->_myoff); + CopyInt(pMonster->_mxvel); + CopyInt(pMonster->_myvel); + CopyInt(pMonster->_mdir); + CopyInt(pMonster->_menemy); + + CopyChar(pMonster->_menemyx); + CopyChar(pMonster->_menemyy); + CopyShort(pMonster->falign_52); + + tbuff += 4; // Skip pointer + CopyInt(pMonster->_mAnimDelay); + CopyInt(pMonster->_mAnimCnt); + CopyInt(pMonster->_mAnimLen); + CopyInt(pMonster->_mAnimFrame); + CopyInt(pMonster->_meflag); + CopyInt(pMonster->_mDelFlag); + CopyInt(pMonster->_mVar1); + CopyInt(pMonster->_mVar2); + CopyInt(pMonster->_mVar3); + CopyInt(pMonster->_mVar4); + CopyInt(pMonster->_mVar5); + CopyInt(pMonster->_mVar6); + CopyInt(pMonster->_mVar7); + CopyInt(pMonster->_mVar8); + CopyInt(pMonster->_mmaxhp); + CopyInt(pMonster->_mhitpoints); + + CopyChar(pMonster->_mAi); + CopyChar(pMonster->_mint); + CopyShort(pMonster->falign_9A); + + CopyInt(pMonster->_mFlags); + + CopyChar(pMonster->_msquelch); + tbuff += 3; + + CopyInt(pMonster->falign_A4); + CopyInt(pMonster->_lastx); + CopyInt(pMonster->_lasty); + CopyInt(pMonster->_mRndSeed); + CopyInt(pMonster->_mAISeed); + CopyInt(pMonster->falign_B8); + + CopyChar(pMonster->_uniqtype); + CopyChar(pMonster->_uniqtrans); + CopyChar(pMonster->_udeadval); + CopyChar(pMonster->mWhoHit); + + CopyChar(pMonster->mLevel); + CopyShort(pMonster->mExp); + tbuff += 1; + + CopyChar(pMonster->mHit); + CopyChar(pMonster->mMinDamage); + CopyChar(pMonster->mMaxDamage); + CopyChar(pMonster->mHit2); + + CopyChar(pMonster->mMinDamage2); + CopyChar(pMonster->mMaxDamage2); + CopyChar(pMonster->mArmorClass); + CopyChar(pMonster->falign_CB); + + CopyShort(pMonster->mMagicRes); + tbuff += 2; + + CopyInt(pMonster->mtalkmsg); + + CopyChar(pMonster->leader); + CopyChar(pMonster->leaderflag); + CopyChar(pMonster->packsize); + CopyChar(pMonster->mlid); + SyncMonsterAnim(i); } void LoadMissile(int i) { - memcpy(&missile[i], tbuff, sizeof(*missile)); - tbuff += sizeof(*missile); + MissileStruct *pMissile = &missile[i]; + + CopyInt(pMissile->_mitype); + CopyInt(pMissile->_mix); + CopyInt(pMissile->_miy); + CopyInt(pMissile->_mixoff); + CopyInt(pMissile->_miyoff); + CopyInt(pMissile->_mixvel); + CopyInt(pMissile->_miyvel); + CopyInt(pMissile->_misx); + CopyInt(pMissile->_misy); + CopyInt(pMissile->_mitxoff); + CopyInt(pMissile->_mityoff); + CopyInt(pMissile->_mimfnum); + CopyInt(pMissile->_mispllvl); + CopyInt(pMissile->_miDelFlag); + CopyChar(pMissile->_miAnimType); + tbuff += 3; + + CopyInt(pMissile->_miAnimFlags); + tbuff += 4; + CopyInt(pMissile->_miAnimDelay); + CopyInt(pMissile->_miAnimLen); + CopyInt(pMissile->_miAnimWidth); + CopyInt(pMissile->_miAnimWidth2); + CopyInt(pMissile->_miAnimCnt); + CopyInt(pMissile->_miAnimAdd); + CopyInt(pMissile->_miAnimFrame); + CopyInt(pMissile->_miDrawFlag); + CopyInt(pMissile->_miLightFlag); + CopyInt(pMissile->_miPreFlag); + CopyInt(pMissile->_miUniqTrans); + CopyInt(pMissile->_mirange); + CopyInt(pMissile->_misource); + CopyInt(pMissile->_micaster); + CopyInt(pMissile->_midam); + CopyInt(pMissile->_miHitFlag); + CopyInt(pMissile->_midist); + CopyInt(pMissile->_mlid); + CopyInt(pMissile->_mirnd); + CopyInt(pMissile->_miVar1); + CopyInt(pMissile->_miVar2); + CopyInt(pMissile->_miVar3); + CopyInt(pMissile->_miVar4); + CopyInt(pMissile->_miVar5); + CopyInt(pMissile->_miVar6); + CopyInt(pMissile->_miVar7); + CopyInt(pMissile->_miVar8); } void LoadObject(int i) { - memcpy(&object[i], tbuff, sizeof(*object)); - tbuff += sizeof(*object); + ObjectStruct *pObject = &object[i]; + CopyInt(pObject->_otype); + CopyInt(pObject->_ox); + CopyInt(pObject->_oy); + CopyInt(pObject->_oLight); + CopyInt(pObject->_oAnimFlag); + tbuff += 4; + CopyInt(pObject->_oAnimDelay); + CopyInt(pObject->_oAnimCnt); + CopyInt(pObject->_oAnimLen); + CopyInt(pObject->_oAnimFrame); + CopyInt(pObject->_oAnimWidth); + CopyInt(pObject->_oAnimWidth2); + CopyInt(pObject->_oDelFlag); + + CopyChar(pObject->_oBreak); + tbuff += 3; + + CopyInt(pObject->_oSolidFlag); + CopyInt(pObject->_oMissFlag); + + CopyChar(pObject->_oSelFlag); + tbuff += 3; + + CopyInt(pObject->_oPreFlag); + CopyInt(pObject->_oTrapFlag); + CopyInt(pObject->_oDoorFlag); + CopyInt(pObject->_olid); + CopyInt(pObject->_oRndSeed); + CopyInt(pObject->_oVar1); + CopyInt(pObject->_oVar2); + CopyInt(pObject->_oVar3); + CopyInt(pObject->_oVar4); + CopyInt(pObject->_oVar5); + CopyInt(pObject->_oVar6); + CopyInt(pObject->_oVar7); + CopyInt(pObject->_oVar8); } void LoadItem(int i) { - memcpy(&item[i], tbuff, sizeof(*item)); - tbuff += sizeof(*item); + CopyItem(&item[i]); GetItemFrm(i); } +void CopyItem(ItemStruct *pItem) +{ + CopyInt(pItem->_iSeed); + CopyShort(pItem->_iCreateInfo); + tbuff += 2; + CopyInt(pItem->_itype); + CopyInt(pItem->_ix); + CopyInt(pItem->_iy); + CopyInt(pItem->_iAnimFlag); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(pItem->_iAnimLen); + CopyInt(pItem->_iAnimFrame); + CopyInt(pItem->_iAnimWidth); + CopyInt(pItem->_iAnimWidth2); // width 2? + CopyInt(pItem->_isin); // set when item is flagged for deletion, deprecated in 1.02 + CopyChar(pItem->_iSelFlag); + tbuff += 3; + CopyInt(pItem->_iPostDraw); + CopyInt(pItem->_iIdentified); + CopyChar(pItem->_iMagical); + CopyBytes(64, pItem->_iName); + CopyBytes(64, pItem->_iIName); + CopyChar(pItem->_iLoc); + CopyChar(pItem->_iClass); + tbuff += 1; + CopyInt(pItem->_iCurs); + CopyInt(pItem->_ivalue); + CopyInt(pItem->_iIvalue); + CopyInt(pItem->_iMinDam); + CopyInt(pItem->_iMaxDam); + CopyInt(pItem->_iAC); + CopyInt(pItem->_iFlags); + CopyInt(pItem->_iMiscId); + CopyInt(pItem->_iSpell); + CopyInt(pItem->_iCharges); + CopyInt(pItem->_iMaxCharges); + CopyInt(pItem->_iDurability); + CopyInt(pItem->_iMaxDur); + CopyInt(pItem->_iPLDam); + CopyInt(pItem->_iPLToHit); + CopyInt(pItem->_iPLAC); + CopyInt(pItem->_iPLStr); + CopyInt(pItem->_iPLMag); + CopyInt(pItem->_iPLDex); + CopyInt(pItem->_iPLVit); + CopyInt(pItem->_iPLFR); + CopyInt(pItem->_iPLLR); + CopyInt(pItem->_iPLMR); + CopyInt(pItem->_iPLMana); + CopyInt(pItem->_iPLHP); + CopyInt(pItem->_iPLDamMod); + CopyInt(pItem->_iPLGetHit); + CopyInt(pItem->_iPLLight); + CopyChar(pItem->_iSplLvlAdd); + CopyChar(pItem->_iRequest); + tbuff += 2; + CopyInt(pItem->_iUid); + CopyInt(pItem->_iFMinDam); + CopyInt(pItem->_iFMaxDam); + CopyInt(pItem->_iLMinDam); + CopyInt(pItem->_iLMaxDam); + CopyInt(pItem->_iPLEnAc); + CopyChar(pItem->_iPrePower); + CopyChar(pItem->_iSufPower); + tbuff += 2; + CopyInt(pItem->_iVAdd1); + CopyInt(pItem->_iVMult1); + CopyInt(pItem->_iVAdd2); + CopyInt(pItem->_iVMult2); + CopyChar(pItem->_iMinStr); + CopyChar(pItem->_iMinMag); + CopyChar(pItem->_iMinDex); + tbuff += 1; + CopyInt(pItem->_iStatFlag); + CopyInt(pItem->IDidx); + CopyInt(pItem->offs016C); +} + +void CopyItems(const int n, ItemStruct *pItem) +{ + for (int i = 0; i < n; i++) + { + CopyItem(&pItem[i]); + } +} + void LoadPremium(int i) { memcpy(&premiumitem[i], tbuff, sizeof(*premiumitem)); diff --git a/Source/loadsave.h b/Source/loadsave.h index 71309f5feda..3ddf9cead38 100644 --- a/Source/loadsave.h +++ b/Source/loadsave.h @@ -9,12 +9,15 @@ char BLoad(); int WLoad(); int ILoad(); BOOL OLoad(); +void CopyItems(const int n, ItemStruct *pItem); +void CopyItem(ItemStruct *pItem); + void LoadPlayer(int i); void LoadMonster(int i); void LoadMissile(int i); void LoadObject(int i); -void LoadItem(int i); -void LoadPremium(int i); +void LoadItem(int t); +void LoadPremium(int t); void LoadQuest(int i); void LoadLighting(int i); void LoadVision(int i); diff --git a/structs.h b/structs.h index 454bd94e1f3..6e9d86de1e6 100644 --- a/structs.h +++ b/structs.h @@ -1,3 +1,5 @@ +#pragma once + ////////////////////////////////////////////////// // control ////////////////////////////////////////////////// @@ -90,6 +92,7 @@ typedef struct ItemGetRecordStruct { unsigned int dwTimestamp; } ItemGetRecordStruct; +#pragma pack(push, 4) typedef struct ItemStruct { int _iSeed; WORD _iCreateInfo; @@ -164,15 +167,17 @@ typedef struct ItemStruct { int IDidx; int offs016C; // _oldlight or _iInvalid } ItemStruct; +#pragma pack(pop) ////////////////////////////////////////////////// // player ////////////////////////////////////////////////// -typedef struct PlayerStruct { +#pragma pack(push, 4) +typedef struct PlayerStruct { int _pmode; char walkpath[25]; - BOOLEAN plractive; + uint8_t plractive; int destAction; int destParam1; int destParam2; @@ -349,6 +354,7 @@ typedef struct PlayerStruct { unsigned char *_pBData; void *pReserved; } PlayerStruct; +#pragma pack(pop) ////////////////////////////////////////////////// // textdat @@ -398,6 +404,7 @@ typedef struct ChainStruct { int _mirange; } ChainStruct; +#pragma pack(push, 4) typedef struct MissileStruct { int _mitype; int _mix; @@ -444,6 +451,7 @@ typedef struct MissileStruct { int _miVar7; int _miVar8; } MissileStruct; +#pragma pack(pop) ////////////////////////////////////////////////// // effects/sound @@ -537,6 +545,7 @@ typedef struct CMonster { BYTE *trans_file; } CMonster; +#pragma pack(push, 4) typedef struct MonsterStruct { // note: missing field _mAFNum int _mMTidx; int _mmode; /* MON_MODE */ @@ -613,6 +622,7 @@ typedef struct MonsterStruct { // note: missing field _mAFNum CMonster *MType; MonsterData *MData; } MonsterStruct; +#pragma pack(pop) typedef struct UniqMonstStruct { char mtype; @@ -655,6 +665,7 @@ typedef struct ObjDataStruct { BOOL oTrapFlag; } ObjDataStruct; +#pragma pack(push, 4) typedef struct ObjectStruct { int _otype; int _ox; @@ -687,11 +698,13 @@ typedef struct ObjectStruct { int _oVar7; int _oVar8; } ObjectStruct; +#pragma pack(pop) ////////////////////////////////////////////////// // portal ////////////////////////////////////////////////// +#pragma pack(push, 4) typedef struct PortalStruct { BOOL open; int x; @@ -700,6 +713,7 @@ typedef struct PortalStruct { int ltype; BOOL setlvl; } PortalStruct; +#pragma pack(pop) ////////////////////////////////////////////////// // msg @@ -1174,6 +1188,7 @@ typedef struct InvXY { // lighting ////////////////////////////////////////////////// +#pragma pack(push, 4) typedef struct LightListStruct { int _lx; int _ly; @@ -1201,6 +1216,7 @@ typedef struct DeadStruct { int _deadWidth2; char _deadtrans; } DeadStruct; +#pragma pack(pop) ////////////////////////////////////////////////// // diabloui From 4f5701a302e3d4ab6ae8257e00d54a859fce2404 Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 04:47:52 -0700 Subject: [PATCH 02/11] Refactor packing functions --- Source/loadsave.cpp | 1087 +++++++++++++++++++++++++++---------------- Source/loadsave.h | 2 + 2 files changed, 688 insertions(+), 401 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index f490f108530..510eb09788f 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -211,256 +211,461 @@ BOOL OLoad() } // Consume an int from tbuff with memcpy - copies directly, doesn't change byte order -void CopyInt(int & dst) +void CopyInt(const void *src, void * dst) { - memcpy(&dst, tbuff, 4); + memcpy(dst, src, 4); tbuff += 4; } -void CopyInt(unsigned int & dst) +/*void CopyInt(BYTE **src, unsigned int & dst) { - memcpy(&dst, tbuff, 4); + memcpy(&dst, src, 4); tbuff += 4; -} - -void CopyShort(unsigned short & dst) -{ - memcpy(&dst, tbuff, 2); - tbuff += 2; -} +}*/ -void CopyShort(short & dst) +void CopyShort(const void *src, void * dst) { - memcpy(&dst, tbuff, 2); + memcpy(dst, src, 2); tbuff += 2; } -void CopyShorts(const int n, unsigned short * dst) +void CopyShorts(const void *src, const int n, void * dst) { - memcpy(dst, tbuff, 2 * n); + memcpy(dst, src, 2 * n); tbuff += 2 * n; } // Copy an int array of size n -void CopyInts(const int n, int* dst) +void CopyInts(const void *src, const int n, void * dst) { - memcpy(dst, tbuff, 4 * n); + memcpy(dst, src, 4 * n); tbuff += 4 * n; } -void CopyBytes(const int n, unsigned char *dst) +void CopyBytes(const void *src, const int n, void * dst) { - memcpy(dst, tbuff, n); + memcpy(dst, src, n); tbuff += n; } -void CopyChar(unsigned char & dst) -{ - memcpy(&dst, tbuff, 1); - tbuff += 1; -} - -void CopyChar(char & dst) +void CopyChar(const void *src, void * dst) { - memcpy(&dst, tbuff, 1); + memcpy(&dst, src, 1); tbuff += 1; } -void CopyInt64(long long unsigned int & dst) +void CopyInt64(const void *src, void * dst) { - memcpy(&dst, tbuff, 8); + memcpy(&dst, src, 8); tbuff += 8; } void LoadPlayer(int i) { - PlayerStruct *pPlayer = &plr[i]; - CopyInt(pPlayer->_pmode); - CopyBytes(25, pPlayer->walkpath); - CopyBytes(1, &pPlayer->plractive); - tbuff += 2; // Some padding here? - CopyInt(pPlayer->destAction); - CopyInt(pPlayer->destParam1); - CopyInt(pPlayer->destParam2); - CopyInt(pPlayer->destParam3); - CopyInt(pPlayer->destParam4); - CopyInt(pPlayer->plrlevel); - CopyInt(pPlayer->WorldX); - CopyInt(pPlayer->WorldY); - CopyInt(pPlayer->_px); - CopyInt(pPlayer->_py); - CopyInt(pPlayer->_ptargx); - CopyInt(pPlayer->_ptargy); - CopyInt(pPlayer->_pownerx); - CopyInt(pPlayer->_pownery); - CopyInt(pPlayer->_poldx); - CopyInt(pPlayer->_poldy); - CopyInt(pPlayer->_pxoff); - CopyInt(pPlayer->_pyoff); - CopyInt(pPlayer->_pxvel); - CopyInt(pPlayer->_pyvel); - CopyInt(pPlayer->_pdir); - CopyInt(pPlayer->_nextdir); - CopyInt(pPlayer->_pgfxnum); + // Copy from tbuff to structures + PlayerStruct *pPlayer = &plr[i]; + + CopyInt(tbuff, &pPlayer->_pmode); + + CopyBytes(tbuff, 25, pPlayer->walkpath); + CopyBytes(tbuff, 1, &pPlayer->plractive); + tbuff += 2; + + CopyInt(tbuff, &pPlayer->destAction); + CopyInt(tbuff, &pPlayer->destParam1); + CopyInt(tbuff, &pPlayer->destParam2); + CopyInt(tbuff, &pPlayer->destParam3); + CopyInt(tbuff, &pPlayer->destParam4); + CopyInt(tbuff, &pPlayer->plrlevel); + CopyInt(tbuff, &pPlayer->WorldX); + CopyInt(tbuff, &pPlayer->WorldY); + CopyInt(tbuff, &pPlayer->_px); + CopyInt(tbuff, &pPlayer->_py); + CopyInt(tbuff, &pPlayer->_ptargx); + CopyInt(tbuff, &pPlayer->_ptargy); + CopyInt(tbuff, &pPlayer->_pownerx); + CopyInt(tbuff, &pPlayer->_pownery); + CopyInt(tbuff, &pPlayer->_poldx); + CopyInt(tbuff, &pPlayer->_poldy); + CopyInt(tbuff, &pPlayer->_pxoff); + CopyInt(tbuff, &pPlayer->_pyoff); + CopyInt(tbuff, &pPlayer->_pxvel); + CopyInt(tbuff, &pPlayer->_pyvel); + CopyInt(tbuff, &pPlayer->_pdir); + CopyInt(tbuff, &pPlayer->_nextdir); + CopyInt(tbuff, &pPlayer->_pgfxnum); tbuff += 4; // Skip pointers - CopyInt(pPlayer->_pAnimDelay); - CopyInt(pPlayer->_pAnimCnt); - CopyInt(pPlayer->_pAnimLen); - CopyInt(pPlayer->_pAnimFrame); - CopyInt(pPlayer->_pAnimWidth); - CopyInt(pPlayer->_pAnimWidth2); - CopyInt(pPlayer->_peflag); - CopyInt(pPlayer->_plid); - CopyInt(pPlayer->_pvid); - - CopyInt(pPlayer->_pSpell); - CopyChar(pPlayer->_pSplType); - CopyChar(pPlayer->_pSplFrom); - CopyInt(pPlayer->_pTSpell); - CopyChar(pPlayer->_pTSplType); + CopyInt(tbuff, &pPlayer->_pAnimDelay); + CopyInt(tbuff, &pPlayer->_pAnimCnt); + CopyInt(tbuff, &pPlayer->_pAnimLen); + CopyInt(tbuff, &pPlayer->_pAnimFrame); + CopyInt(tbuff, &pPlayer->_pAnimWidth); + CopyInt(tbuff, &pPlayer->_pAnimWidth2); + CopyInt(tbuff, &pPlayer->_peflag); + CopyInt(tbuff, &pPlayer->_plid); + CopyInt(tbuff, &pPlayer->_pvid); + + CopyInt(tbuff, &pPlayer->_pSpell); + CopyChar(tbuff, &pPlayer->_pSplType); + CopyChar(tbuff, &pPlayer->_pSplFrom); + CopyInt(tbuff, &pPlayer->_pTSpell); + CopyChar(tbuff, &pPlayer->_pTSplType); tbuff += 5; - CopyInt(pPlayer->_pRSpell); - CopyChar(pPlayer->_pRSplType); + CopyInt(tbuff, &pPlayer->_pRSpell); + CopyChar(tbuff, &pPlayer->_pRSplType); tbuff += 3; - CopyInt(pPlayer->_pSBkSpell); - CopyChar(pPlayer->_pSBkSplType); + CopyInt(tbuff, &pPlayer->_pSBkSpell); + CopyChar(tbuff, &pPlayer->_pSBkSplType); - CopyBytes(64, pPlayer->_pSplLvl); + CopyBytes(tbuff, 64, &pPlayer->_pSplLvl); tbuff += 7; - CopyInt64(pPlayer->_pMemSpells); - CopyInt64(pPlayer->_pAblSpells); - CopyInt64(pPlayer->_pScrlSpells); - CopyChar(pPlayer->_pSpellFlags); + CopyInt64(tbuff, &pPlayer->_pMemSpells); + CopyInt64(tbuff, &pPlayer->_pAblSpells); + CopyInt64(tbuff, &pPlayer->_pScrlSpells); + CopyChar(tbuff, &pPlayer->_pSpellFlags); tbuff += 3; - CopyInts(4, pPlayer->_pSplHotKey); - CopyBytes(4, pPlayer->_pSplTHotKey); - CopyInt(pPlayer->_pwtype); - CopyChar(pPlayer->_pBlockFlag); - CopyChar(pPlayer->_pInvincible); - CopyChar(pPlayer->_pLightRad); - CopyChar(pPlayer->_pLvlChanging); - CopyBytes(PLR_NAME_LEN, pPlayer->_pName); - CopyChar(pPlayer->_pClass); + CopyInts(tbuff, 4, &pPlayer->_pSplHotKey); + CopyBytes(tbuff, 4, &pPlayer->_pSplTHotKey); + CopyInt(tbuff, &pPlayer->_pwtype); + CopyChar(tbuff, &pPlayer->_pBlockFlag); + CopyChar(tbuff, &pPlayer->_pInvincible); + CopyChar(tbuff, &pPlayer->_pLightRad); + CopyChar(tbuff, &pPlayer->_pLvlChanging); + CopyBytes(tbuff, PLR_NAME_LEN, &pPlayer->_pName); + CopyChar(tbuff, &pPlayer->_pClass); tbuff += 3; - CopyInt(pPlayer->_pStrength); - CopyInt(pPlayer->_pBaseStr); - CopyInt(pPlayer->_pMagic); - CopyInt(pPlayer->_pBaseMag); - CopyInt(pPlayer->_pDexterity); - CopyInt(pPlayer->_pBaseDex); - CopyInt(pPlayer->_pVitality); - CopyInt(pPlayer->_pBaseVit); - CopyInt(pPlayer->_pStatPts); - CopyInt(pPlayer->_pDamageMod); - CopyInt(pPlayer->_pBaseToBlk); - CopyInt(pPlayer->_pHPBase); - CopyInt(pPlayer->_pMaxHPBase); - CopyInt(pPlayer->_pHitPoints); - CopyInt(pPlayer->_pMaxHP); - CopyInt(pPlayer->_pHPPer); - CopyInt(pPlayer->_pManaBase); - CopyInt(pPlayer->_pMaxManaBase); - CopyInt(pPlayer->_pMana); - CopyInt(pPlayer->_pMaxMana); - CopyInt(pPlayer->_pManaPer); - CopyChar(pPlayer->_pLevel); - CopyChar(pPlayer->_pMaxLvl); + CopyInt(tbuff, &pPlayer->_pStrength); + CopyInt(tbuff, &pPlayer->_pBaseStr); + CopyInt(tbuff, &pPlayer->_pMagic); + CopyInt(tbuff, &pPlayer->_pBaseMag); + CopyInt(tbuff, &pPlayer->_pDexterity); + CopyInt(tbuff, &pPlayer->_pBaseDex); + CopyInt(tbuff, &pPlayer->_pVitality); + CopyInt(tbuff, &pPlayer->_pBaseVit); + CopyInt(tbuff, &pPlayer->_pStatPts); + CopyInt(tbuff, &pPlayer->_pDamageMod); + CopyInt(tbuff, &pPlayer->_pBaseToBlk); + CopyInt(tbuff, &pPlayer->_pHPBase); + CopyInt(tbuff, &pPlayer->_pMaxHPBase); + CopyInt(tbuff, &pPlayer->_pHitPoints); + CopyInt(tbuff, &pPlayer->_pMaxHP); + CopyInt(tbuff, &pPlayer->_pHPPer); + CopyInt(tbuff, &pPlayer->_pManaBase); + CopyInt(tbuff, &pPlayer->_pMaxManaBase); + CopyInt(tbuff, &pPlayer->_pMana); + CopyInt(tbuff, &pPlayer->_pMaxMana); + CopyInt(tbuff, &pPlayer->_pManaPer); + CopyChar(tbuff, &pPlayer->_pLevel); + CopyChar(tbuff, &pPlayer->_pMaxLvl); tbuff += 2; - CopyInt(pPlayer->_pExperience); - CopyInt(pPlayer->_pMaxExp); - CopyInt(pPlayer->_pNextExper); - CopyChar(pPlayer->_pArmorClass); - CopyChar(pPlayer->_pMagResist); - CopyChar(pPlayer->_pFireResist); - CopyChar(pPlayer->_pLghtResist); - CopyInt(pPlayer->_pGold); - CopyInt(pPlayer->_pInfraFlag); - CopyInt(pPlayer->_pVar1); - CopyInt(pPlayer->_pVar2); - CopyInt(pPlayer->_pVar3); - CopyInt(pPlayer->_pVar4); - CopyInt(pPlayer->_pVar5); - CopyInt(pPlayer->_pVar6); - CopyInt(pPlayer->_pVar7); - CopyInt(pPlayer->_pVar8); - CopyBytes(NUMLEVELS, pPlayer->_pLvlVisited); - CopyBytes(NUMLEVELS, pPlayer->_pSLvlVisited); // only 10 used + CopyInt(tbuff, &pPlayer->_pExperience); + CopyInt(tbuff, &pPlayer->_pMaxExp); + CopyInt(tbuff, &pPlayer->_pNextExper); + CopyChar(tbuff, &pPlayer->_pArmorClass); + CopyChar(tbuff, &pPlayer->_pMagResist); + CopyChar(tbuff, &pPlayer->_pFireResist); + CopyChar(tbuff, &pPlayer->_pLghtResist); + CopyInt(tbuff, &pPlayer->_pGold); + CopyInt(tbuff, &pPlayer->_pInfraFlag); + CopyInt(tbuff, &pPlayer->_pVar1); + CopyInt(tbuff, &pPlayer->_pVar2); + CopyInt(tbuff, &pPlayer->_pVar3); + CopyInt(tbuff, &pPlayer->_pVar4); + CopyInt(tbuff, &pPlayer->_pVar5); + CopyInt(tbuff, &pPlayer->_pVar6); + CopyInt(tbuff, &pPlayer->_pVar7); + CopyInt(tbuff, &pPlayer->_pVar8); + CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pLvlVisited); + CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pSLvlVisited); // only 10 used tbuff += 2; - CopyInt(pPlayer->_pGFXLoad); + CopyInt(tbuff, &pPlayer->_pGFXLoad); tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - CopyInt(pPlayer->_pNFrames); - CopyInt(pPlayer->_pNWidth); + CopyInt(tbuff, &pPlayer->_pNFrames); + CopyInt(tbuff, &pPlayer->_pNWidth); tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - CopyInt(pPlayer->_pWFrames); - CopyInt(pPlayer->_pWWidth); + CopyInt(tbuff, &pPlayer->_pWFrames); + CopyInt(tbuff, &pPlayer->_pWWidth); tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - CopyInt(pPlayer->_pAFrames); - CopyInt(pPlayer->_pAWidth); - CopyInt(pPlayer->_pAFNum); + CopyInt(tbuff, &pPlayer->_pAFrames); + CopyInt(tbuff, &pPlayer->_pAWidth); + CopyInt(tbuff, &pPlayer->_pAFNum); tbuff += sizeof(__uint32_t) * 24; // Skip 24 pointers - CopyInt(pPlayer->_pSFrames); - CopyInt(pPlayer->_pSWidth); - CopyInt(pPlayer->_pSFNum); + CopyInt(tbuff, &pPlayer->_pSFrames); + CopyInt(tbuff, &pPlayer->_pSWidth); + CopyInt(tbuff, &pPlayer->_pSFNum); tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - CopyInt(pPlayer->_pHFrames); - CopyInt(pPlayer->_pHWidth); + CopyInt(tbuff, &pPlayer->_pHFrames); + CopyInt(tbuff, &pPlayer->_pHWidth); tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - CopyInt(pPlayer->_pDFrames); - CopyInt(pPlayer->_pDWidth); + CopyInt(tbuff, &pPlayer->_pDFrames); + CopyInt(tbuff, &pPlayer->_pDWidth); tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - CopyInt(pPlayer->_pBFrames); - CopyInt(pPlayer->_pBWidth); - + CopyInt(tbuff, &pPlayer->_pBFrames); + CopyInt(tbuff, &pPlayer->_pBWidth); CopyItems(NUM_INVLOC, pPlayer->InvBody); CopyItems(NUM_INV_GRID_ELEM, pPlayer->InvList); - - CopyInt(pPlayer->_pNumInv); - CopyBytes(NUM_INV_GRID_ELEM, pPlayer->InvGrid); + CopyInt(tbuff, &pPlayer->_pNumInv); + CopyBytes(tbuff, NUM_INV_GRID_ELEM, pPlayer->InvGrid); CopyItems(MAXBELTITEMS, pPlayer->SpdList); CopyItem(&pPlayer->HoldItem); - CopyInt(pPlayer->_pIMinDam); - CopyInt(pPlayer->_pIMaxDam); - CopyInt(pPlayer->_pIAC); - CopyInt(pPlayer->_pIBonusDam); - CopyInt(pPlayer->_pIBonusToHit); - CopyInt(pPlayer->_pIBonusAC); - CopyInt(pPlayer->_pIBonusDamMod); + CopyInt(tbuff, &pPlayer->_pIMinDam); + CopyInt(tbuff, &pPlayer->_pIMaxDam); + CopyInt(tbuff, &pPlayer->_pIAC); + CopyInt(tbuff, &pPlayer->_pIBonusDam); + CopyInt(tbuff, &pPlayer->_pIBonusToHit); + CopyInt(tbuff, &pPlayer->_pIBonusAC); + CopyInt(tbuff, &pPlayer->_pIBonusDamMod); + tbuff += 4; + CopyInt64(tbuff, &pPlayer->_pISpells); + CopyInt(tbuff, &pPlayer->_pIFlags); + CopyInt(tbuff, &pPlayer->_pIGetHit); + + CopyChar(tbuff, &pPlayer->_pISplLvlAdd); + CopyChar(tbuff, &pPlayer->_pISplCost); + tbuff += 2; + + CopyInt(tbuff, &pPlayer->_pISplDur); + CopyInt(tbuff, &pPlayer->_pIEnAc); + CopyInt(tbuff, &pPlayer->_pIFMinDam); + CopyInt(tbuff, &pPlayer->_pIFMaxDam); + CopyInt(tbuff, &pPlayer->_pILMinDam); + CopyInt(tbuff, &pPlayer->_pILMaxDam); + CopyInt(tbuff, &pPlayer->_pOilType); + + CopyChar(tbuff, &pPlayer->pTownWarps); + CopyChar(tbuff, &pPlayer->pDungMsgs); + CopyChar(tbuff, &pPlayer->pLvlLoad); + CopyChar(tbuff, &pPlayer->pBattleNet); + + CopyChar(tbuff, &pPlayer->pManaShield); + CopyBytes(tbuff, 3, &pPlayer->bReserved); + + CopyShorts(tbuff, 8, &pPlayer->wReserved); + + CopyInt(tbuff, &pPlayer->pDiabloKillLevel); + CopyInts(tbuff, 7, &pPlayer->dwReserved); + + // Omit 10 pointers + +} + +/*void SavePlayer(int i) +{ + memcpy(tbuff, &plr[i], sizeof(*plr) - (10 * sizeof(void *))); + tbuff += sizeof(*plr) - (10 * sizeof(void *)); // omit last 10 pointers +}*/ + + +void SavePlayer(int i) +{ + // Copy from tbuff to structures + PlayerStruct *pPlayer = &plr[i]; + + CopyInt(pPlayer->_pmode, tbuff); + + CopyBytes(pPlayer->walkpath, 25, tbuff); + CopyBytes(&pPlayer->plractive, 1, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->destAction, tbuff); + CopyInt(&pPlayer->destParam1, tbuff); + CopyInt(&pPlayer->destParam2, tbuff); + CopyInt(&pPlayer->destParam3, tbuff); + CopyInt(&pPlayer->destParam4, tbuff); + CopyInt(&pPlayer->plrlevel, tbuff); + CopyInt(&pPlayer->WorldX, tbuff); + CopyInt(&pPlayer->WorldY, tbuff); + CopyInt(&pPlayer->_px, tbuff); + CopyInt(&pPlayer->_py, tbuff); + CopyInt(&pPlayer->_ptargx, tbuff); + CopyInt(&pPlayer->_ptargy, tbuff); + CopyInt(&pPlayer->_pownerx, tbuff); + CopyInt(&pPlayer->_pownery, tbuff); + CopyInt(&pPlayer->_poldx, tbuff); + CopyInt(&pPlayer->_poldy, tbuff); + CopyInt(&pPlayer->_pxoff, tbuff); + CopyInt(&pPlayer->_pyoff, tbuff); + CopyInt(&pPlayer->_pxvel, tbuff); + CopyInt(&pPlayer->_pyvel, tbuff); + CopyInt(&pPlayer->_pdir, tbuff); + CopyInt(&pPlayer->_nextdir, tbuff); + CopyInt(&pPlayer->_pgfxnum, tbuff); + tbuff += 4; // Skip pointers + CopyInt(&pPlayer->_pAnimDelay, tbuff); + CopyInt(&pPlayer->_pAnimCnt, tbuff); + CopyInt(&pPlayer->_pAnimLen, tbuff); + CopyInt(&pPlayer->_pAnimFrame, tbuff); + CopyInt(&pPlayer->_pAnimWidth, tbuff); + CopyInt(&pPlayer->_pAnimWidth2, tbuff); + CopyInt(&pPlayer->_peflag, tbuff); + CopyInt(&pPlayer->_plid, tbuff); + CopyInt(&pPlayer->_pvid, tbuff); + + CopyInt(&pPlayer->_pSpell, tbuff); + CopyChar(&pPlayer->_pSplType, tbuff); + CopyChar(&pPlayer->_pSplFrom, tbuff); + CopyInt(&pPlayer->_pTSpell, tbuff); + CopyChar(&pPlayer->_pTSplType, tbuff); + tbuff += 5; + CopyInt(&pPlayer->_pRSpell, tbuff); + CopyChar(&pPlayer->_pRSplType, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pSBkSpell, tbuff); + CopyChar(&pPlayer->_pSBkSplType, tbuff); + + CopyBytes(&pPlayer->_pSplLvl, 64, tbuff); + tbuff += 7; + CopyInt64(&pPlayer->_pMemSpells, tbuff); + CopyInt64(&pPlayer->_pAblSpells, tbuff); + CopyInt64(&pPlayer->_pScrlSpells, tbuff); + CopyChar(&pPlayer->_pSpellFlags, tbuff); + tbuff += 3; + CopyInts(&pPlayer->_pSplHotKey, 4, tbuff); + CopyBytes(&pPlayer->_pSplTHotKey, 4, tbuff); + CopyInt(&pPlayer->_pwtype, tbuff); + CopyChar(&pPlayer->_pBlockFlag, tbuff); + CopyChar(&pPlayer->_pInvincible, tbuff); + CopyChar(&pPlayer->_pLightRad, tbuff); + CopyChar(&pPlayer->_pLvlChanging, tbuff); + CopyBytes(&pPlayer->_pName, PLR_NAME_LEN, tbuff); + CopyChar(&pPlayer->_pClass, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pStrength, tbuff); + CopyInt(&pPlayer->_pBaseStr, tbuff); + CopyInt(&pPlayer->_pMagic, tbuff); + CopyInt(&pPlayer->_pBaseMag, tbuff); + CopyInt(&pPlayer->_pDexterity, tbuff); + CopyInt(&pPlayer->_pBaseDex, tbuff); + CopyInt(&pPlayer->_pVitality, tbuff); + CopyInt(&pPlayer->_pBaseVit, tbuff); + CopyInt(&pPlayer->_pStatPts, tbuff); + CopyInt(&pPlayer->_pDamageMod, tbuff); + CopyInt(&pPlayer->_pBaseToBlk, tbuff); + CopyInt(&pPlayer->_pHPBase, tbuff); + CopyInt(&pPlayer->_pMaxHPBase, tbuff); + CopyInt(&pPlayer->_pHitPoints, tbuff); + CopyInt(&pPlayer->_pMaxHP, tbuff); + CopyInt(&pPlayer->_pHPPer, tbuff); + CopyInt(&pPlayer->_pManaBase, tbuff); + CopyInt(&pPlayer->_pMaxManaBase, tbuff); + CopyInt(&pPlayer->_pMana, tbuff); + CopyInt(&pPlayer->_pMaxMana, tbuff); + CopyInt(&pPlayer->_pManaPer, tbuff); + CopyChar(&pPlayer->_pLevel, tbuff); + CopyChar(&pPlayer->_pMaxLvl, tbuff); + tbuff += 2; + CopyInt(&pPlayer->_pExperience, tbuff); + CopyInt(&pPlayer->_pMaxExp, tbuff); + CopyInt(&pPlayer->_pNextExper, tbuff); + CopyChar(&pPlayer->_pArmorClass, tbuff); + CopyChar(&pPlayer->_pMagResist, tbuff); + CopyChar(&pPlayer->_pFireResist, tbuff); + CopyChar(&pPlayer->_pLghtResist, tbuff); + CopyInt(&pPlayer->_pGold, tbuff); + CopyInt(&pPlayer->_pInfraFlag, tbuff); + CopyInt(&pPlayer->_pVar1, tbuff); + CopyInt(&pPlayer->_pVar2, tbuff); + CopyInt(&pPlayer->_pVar3, tbuff); + CopyInt(&pPlayer->_pVar4, tbuff); + CopyInt(&pPlayer->_pVar5, tbuff); + CopyInt(&pPlayer->_pVar6, tbuff); + CopyInt(&pPlayer->_pVar7, tbuff); + CopyInt(&pPlayer->_pVar8, tbuff); + CopyBytes(&pPlayer->_pLvlVisited, NUMLEVELS, tbuff); + CopyBytes(&pPlayer->_pSLvlVisited, NUMLEVELS, tbuff); // only 10 used + tbuff += 2; + CopyInt(&pPlayer->_pGFXLoad, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + CopyInt(&pPlayer->_pNFrames, tbuff); + CopyInt(&pPlayer->_pNWidth, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pWFrames, tbuff); + CopyInt(&pPlayer->_pWWidth, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pAFrames, tbuff); + CopyInt(&pPlayer->_pAWidth, tbuff); + CopyInt(&pPlayer->_pAFNum, tbuff); + + tbuff += sizeof(__uint32_t) * 24; // Skip 24 pointers + + CopyInt(&pPlayer->_pSFrames, tbuff); + CopyInt(&pPlayer->_pSWidth, tbuff); + CopyInt(&pPlayer->_pSFNum, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pHFrames, tbuff); + CopyInt(&pPlayer->_pHWidth, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pDFrames, tbuff); + CopyInt(&pPlayer->_pDWidth, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pBFrames, tbuff); + CopyInt(&pPlayer->_pBWidth, tbuff); + SaveItems(pPlayer->InvBody, NUM_INVLOC); + SaveItems(pPlayer->InvList, NUM_INV_GRID_ELEM); + CopyInt(&pPlayer->_pNumInv, tbuff); + CopyBytes(pPlayer->InvGrid, NUM_INV_GRID_ELEM, tbuff); + SaveItems(pPlayer->SpdList, MAXBELTITEMS); + SaveItem(&pPlayer->HoldItem); + CopyInt(&pPlayer->_pIMinDam, tbuff); + CopyInt(&pPlayer->_pIMaxDam, tbuff); + CopyInt(&pPlayer->_pIAC, tbuff); + CopyInt(&pPlayer->_pIBonusDam, tbuff); + CopyInt(&pPlayer->_pIBonusToHit, tbuff); + CopyInt(&pPlayer->_pIBonusAC, tbuff); + CopyInt(&pPlayer->_pIBonusDamMod, tbuff); tbuff += 4; - CopyInt64(pPlayer->_pISpells); - CopyInt(pPlayer->_pIFlags); - CopyInt(pPlayer->_pIGetHit); - CopyChar(pPlayer->_pISplLvlAdd); - CopyChar(pPlayer->_pISplCost); + CopyInt64(&pPlayer->_pISpells, tbuff); + CopyInt(&pPlayer->_pIFlags, tbuff); + CopyInt(&pPlayer->_pIGetHit, tbuff); + + CopyChar(&pPlayer->_pISplLvlAdd, tbuff); + CopyChar(&pPlayer->_pISplCost, tbuff); tbuff += 2; - CopyInt(pPlayer->_pISplDur); - CopyInt(pPlayer->_pIEnAc); - CopyInt(pPlayer->_pIFMinDam); - CopyInt(pPlayer->_pIFMaxDam); - CopyInt(pPlayer->_pILMinDam); - CopyInt(pPlayer->_pILMaxDam); - CopyInt(pPlayer->_pOilType); - CopyChar(pPlayer->pTownWarps); - CopyChar(pPlayer->pDungMsgs); - CopyChar(pPlayer->pLvlLoad); - CopyChar(pPlayer->pBattleNet); - CopyChar(pPlayer->pManaShield); - CopyBytes(3, pPlayer->bReserved); - CopyShorts(8, pPlayer->wReserved); - CopyInt(pPlayer->pDiabloKillLevel); - CopyInts(7, pPlayer->dwReserved); + + CopyInt(&pPlayer->_pISplDur, tbuff); + CopyInt(&pPlayer->_pIEnAc, tbuff); + CopyInt(&pPlayer->_pIFMinDam, tbuff); + CopyInt(&pPlayer->_pIFMaxDam, tbuff); + CopyInt(&pPlayer->_pILMinDam, tbuff); + CopyInt(&pPlayer->_pILMaxDam, tbuff); + CopyInt(&pPlayer->_pOilType, tbuff); + + CopyChar(&pPlayer->pTownWarps, tbuff); + CopyChar(&pPlayer->pDungMsgs, tbuff); + CopyChar(&pPlayer->pLvlLoad, tbuff); + CopyChar(&pPlayer->pBattleNet, tbuff); + + CopyChar(&pPlayer->pManaShield, tbuff); + CopyBytes(&pPlayer->bReserved, 3, tbuff); + + CopyShorts(&pPlayer->wReserved, 8, tbuff); + + CopyInt(tbuff, pPlayer->pDiabloKillLevel); + CopyInts(&pPlayer->dwReserved, 7, tbuff); // Omit 10 pointers @@ -470,99 +675,99 @@ void LoadMonster(int i) { MonsterStruct *pMonster = &monster[i]; - CopyInt(pMonster->_mMTidx); - CopyInt(pMonster->_mmode); + CopyInt(tbuff, &pMonster->_mMTidx); + CopyInt(tbuff, &pMonster->_mmode); - CopyChar(pMonster->_mgoal); + CopyChar(tbuff, &pMonster->_mgoal); tbuff += 3; - CopyInt(pMonster->_mgoalvar1); - CopyInt(pMonster->_mgoalvar2); - CopyInt(pMonster->_mgoalvar3); - CopyInt(pMonster->field_18); + CopyInt(tbuff, &pMonster->_mgoalvar1); + CopyInt(tbuff, &pMonster->_mgoalvar2); + CopyInt(tbuff, &pMonster->_mgoalvar3); + CopyInt(tbuff, &pMonster->field_18); - CopyChar(pMonster->_pathcount); + CopyChar(tbuff, &pMonster->_pathcount); tbuff += 3; - CopyInt(pMonster->_mx); - CopyInt(pMonster->_my); - CopyInt(pMonster->_mfutx); - CopyInt(pMonster->_mfuty); - CopyInt(pMonster->_moldx); - CopyInt(pMonster->_moldy); - CopyInt(pMonster->_mxoff); - CopyInt(pMonster->_myoff); - CopyInt(pMonster->_mxvel); - CopyInt(pMonster->_myvel); - CopyInt(pMonster->_mdir); - CopyInt(pMonster->_menemy); - - CopyChar(pMonster->_menemyx); - CopyChar(pMonster->_menemyy); - CopyShort(pMonster->falign_52); + CopyInt(tbuff, &pMonster->_mx); + CopyInt(tbuff, &pMonster->_my); + CopyInt(tbuff, &pMonster->_mfutx); + CopyInt(tbuff, &pMonster->_mfuty); + CopyInt(tbuff, &pMonster->_moldx); + CopyInt(tbuff, &pMonster->_moldy); + CopyInt(tbuff, &pMonster->_mxoff); + CopyInt(tbuff, &pMonster->_myoff); + CopyInt(tbuff, &pMonster->_mxvel); + CopyInt(tbuff, &pMonster->_myvel); + CopyInt(tbuff, &pMonster->_mdir); + CopyInt(tbuff, &pMonster->_menemy); + + CopyChar(tbuff, &pMonster->_menemyx); + CopyChar(tbuff, &pMonster->_menemyy); + CopyShort(tbuff, &pMonster->falign_52); tbuff += 4; // Skip pointer - CopyInt(pMonster->_mAnimDelay); - CopyInt(pMonster->_mAnimCnt); - CopyInt(pMonster->_mAnimLen); - CopyInt(pMonster->_mAnimFrame); - CopyInt(pMonster->_meflag); - CopyInt(pMonster->_mDelFlag); - CopyInt(pMonster->_mVar1); - CopyInt(pMonster->_mVar2); - CopyInt(pMonster->_mVar3); - CopyInt(pMonster->_mVar4); - CopyInt(pMonster->_mVar5); - CopyInt(pMonster->_mVar6); - CopyInt(pMonster->_mVar7); - CopyInt(pMonster->_mVar8); - CopyInt(pMonster->_mmaxhp); - CopyInt(pMonster->_mhitpoints); - - CopyChar(pMonster->_mAi); - CopyChar(pMonster->_mint); - CopyShort(pMonster->falign_9A); - - CopyInt(pMonster->_mFlags); - - CopyChar(pMonster->_msquelch); + CopyInt(tbuff, &pMonster->_mAnimDelay); + CopyInt(tbuff, &pMonster->_mAnimCnt); + CopyInt(tbuff, &pMonster->_mAnimLen); + CopyInt(tbuff, &pMonster->_mAnimFrame); + CopyInt(tbuff, &pMonster->_meflag); + CopyInt(tbuff, &pMonster->_mDelFlag); + CopyInt(tbuff, &pMonster->_mVar1); + CopyInt(tbuff, &pMonster->_mVar2); + CopyInt(tbuff, &pMonster->_mVar3); + CopyInt(tbuff, &pMonster->_mVar4); + CopyInt(tbuff, &pMonster->_mVar5); + CopyInt(tbuff, &pMonster->_mVar6); + CopyInt(tbuff, &pMonster->_mVar7); + CopyInt(tbuff, &pMonster->_mVar8); + CopyInt(tbuff, &pMonster->_mmaxhp); + CopyInt(tbuff, &pMonster->_mhitpoints); + + CopyChar(tbuff, &pMonster->_mAi); + CopyChar(tbuff, &pMonster->_mint); + CopyShort(tbuff, &pMonster->falign_9A); + + CopyInt(tbuff, &pMonster->_mFlags); + + CopyChar(tbuff, &pMonster->_msquelch); tbuff += 3; - CopyInt(pMonster->falign_A4); - CopyInt(pMonster->_lastx); - CopyInt(pMonster->_lasty); - CopyInt(pMonster->_mRndSeed); - CopyInt(pMonster->_mAISeed); - CopyInt(pMonster->falign_B8); + CopyInt(tbuff, &pMonster->falign_A4); + CopyInt(tbuff, &pMonster->_lastx); + CopyInt(tbuff, &pMonster->_lasty); + CopyInt(tbuff, &pMonster->_mRndSeed); + CopyInt(tbuff, &pMonster->_mAISeed); + CopyInt(tbuff, &pMonster->falign_B8); - CopyChar(pMonster->_uniqtype); - CopyChar(pMonster->_uniqtrans); - CopyChar(pMonster->_udeadval); - CopyChar(pMonster->mWhoHit); + CopyChar(tbuff, &pMonster->_uniqtype); + CopyChar(tbuff, &pMonster->_uniqtrans); + CopyChar(tbuff, &pMonster->_udeadval); + CopyChar(tbuff, &pMonster->mWhoHit); - CopyChar(pMonster->mLevel); - CopyShort(pMonster->mExp); + CopyChar(tbuff, &pMonster->mLevel); + CopyShort(tbuff, &pMonster->mExp); tbuff += 1; - CopyChar(pMonster->mHit); - CopyChar(pMonster->mMinDamage); - CopyChar(pMonster->mMaxDamage); - CopyChar(pMonster->mHit2); + CopyChar(tbuff, &pMonster->mHit); + CopyChar(tbuff, &pMonster->mMinDamage); + CopyChar(tbuff, &pMonster->mMaxDamage); + CopyChar(tbuff, &pMonster->mHit2); - CopyChar(pMonster->mMinDamage2); - CopyChar(pMonster->mMaxDamage2); - CopyChar(pMonster->mArmorClass); - CopyChar(pMonster->falign_CB); + CopyChar(tbuff, &pMonster->mMinDamage2); + CopyChar(tbuff, &pMonster->mMaxDamage2); + CopyChar(tbuff, &pMonster->mArmorClass); + CopyChar(tbuff, &pMonster->falign_CB); - CopyShort(pMonster->mMagicRes); + CopyShort(tbuff, &pMonster->mMagicRes); tbuff += 2; - CopyInt(pMonster->mtalkmsg); + CopyInt(tbuff, &pMonster->mtalkmsg); - CopyChar(pMonster->leader); - CopyChar(pMonster->leaderflag); - CopyChar(pMonster->packsize); - CopyChar(pMonster->mlid); + CopyChar(tbuff, &pMonster->leader); + CopyChar(tbuff, &pMonster->leaderflag); + CopyChar(tbuff, &pMonster->packsize); + CopyChar(tbuff, &pMonster->mlid); SyncMonsterAnim(i); } @@ -571,93 +776,93 @@ void LoadMissile(int i) { MissileStruct *pMissile = &missile[i]; - CopyInt(pMissile->_mitype); - CopyInt(pMissile->_mix); - CopyInt(pMissile->_miy); - CopyInt(pMissile->_mixoff); - CopyInt(pMissile->_miyoff); - CopyInt(pMissile->_mixvel); - CopyInt(pMissile->_miyvel); - CopyInt(pMissile->_misx); - CopyInt(pMissile->_misy); - CopyInt(pMissile->_mitxoff); - CopyInt(pMissile->_mityoff); - CopyInt(pMissile->_mimfnum); - CopyInt(pMissile->_mispllvl); - CopyInt(pMissile->_miDelFlag); - CopyChar(pMissile->_miAnimType); + CopyInt(tbuff, &pMissile->_mitype); + CopyInt(tbuff, &pMissile->_mix); + CopyInt(tbuff, &pMissile->_miy); + CopyInt(tbuff, &pMissile->_mixoff); + CopyInt(tbuff, &pMissile->_miyoff); + CopyInt(tbuff, &pMissile->_mixvel); + CopyInt(tbuff, &pMissile->_miyvel); + CopyInt(tbuff, &pMissile->_misx); + CopyInt(tbuff, &pMissile->_misy); + CopyInt(tbuff, &pMissile->_mitxoff); + CopyInt(tbuff, &pMissile->_mityoff); + CopyInt(tbuff, &pMissile->_mimfnum); + CopyInt(tbuff, &pMissile->_mispllvl); + CopyInt(tbuff, &pMissile->_miDelFlag); + CopyChar(tbuff, &pMissile->_miAnimType); tbuff += 3; - CopyInt(pMissile->_miAnimFlags); + CopyInt(tbuff, &pMissile->_miAnimFlags); tbuff += 4; - CopyInt(pMissile->_miAnimDelay); - CopyInt(pMissile->_miAnimLen); - CopyInt(pMissile->_miAnimWidth); - CopyInt(pMissile->_miAnimWidth2); - CopyInt(pMissile->_miAnimCnt); - CopyInt(pMissile->_miAnimAdd); - CopyInt(pMissile->_miAnimFrame); - CopyInt(pMissile->_miDrawFlag); - CopyInt(pMissile->_miLightFlag); - CopyInt(pMissile->_miPreFlag); - CopyInt(pMissile->_miUniqTrans); - CopyInt(pMissile->_mirange); - CopyInt(pMissile->_misource); - CopyInt(pMissile->_micaster); - CopyInt(pMissile->_midam); - CopyInt(pMissile->_miHitFlag); - CopyInt(pMissile->_midist); - CopyInt(pMissile->_mlid); - CopyInt(pMissile->_mirnd); - CopyInt(pMissile->_miVar1); - CopyInt(pMissile->_miVar2); - CopyInt(pMissile->_miVar3); - CopyInt(pMissile->_miVar4); - CopyInt(pMissile->_miVar5); - CopyInt(pMissile->_miVar6); - CopyInt(pMissile->_miVar7); - CopyInt(pMissile->_miVar8); + CopyInt(tbuff, &pMissile->_miAnimDelay); + CopyInt(tbuff, &pMissile->_miAnimLen); + CopyInt(tbuff, &pMissile->_miAnimWidth); + CopyInt(tbuff, &pMissile->_miAnimWidth2); + CopyInt(tbuff, &pMissile->_miAnimCnt); + CopyInt(tbuff, &pMissile->_miAnimAdd); + CopyInt(tbuff, &pMissile->_miAnimFrame); + CopyInt(tbuff, &pMissile->_miDrawFlag); + CopyInt(tbuff, &pMissile->_miLightFlag); + CopyInt(tbuff, &pMissile->_miPreFlag); + CopyInt(tbuff, &pMissile->_miUniqTrans); + CopyInt(tbuff, &pMissile->_mirange); + CopyInt(tbuff, &pMissile->_misource); + CopyInt(tbuff, &pMissile->_micaster); + CopyInt(tbuff, &pMissile->_midam); + CopyInt(tbuff, &pMissile->_miHitFlag); + CopyInt(tbuff, &pMissile->_midist); + CopyInt(tbuff, &pMissile->_mlid); + CopyInt(tbuff, &pMissile->_mirnd); + CopyInt(tbuff, &pMissile->_miVar1); + CopyInt(tbuff, &pMissile->_miVar2); + CopyInt(tbuff, &pMissile->_miVar3); + CopyInt(tbuff, &pMissile->_miVar4); + CopyInt(tbuff, &pMissile->_miVar5); + CopyInt(tbuff, &pMissile->_miVar6); + CopyInt(tbuff, &pMissile->_miVar7); + CopyInt(tbuff, &pMissile->_miVar8); } void LoadObject(int i) { ObjectStruct *pObject = &object[i]; - CopyInt(pObject->_otype); - CopyInt(pObject->_ox); - CopyInt(pObject->_oy); - CopyInt(pObject->_oLight); - CopyInt(pObject->_oAnimFlag); + CopyInt(tbuff, &pObject->_otype); + CopyInt(tbuff, &pObject->_ox); + CopyInt(tbuff, &pObject->_oy); + CopyInt(tbuff, &pObject->_oLight); + CopyInt(tbuff, &pObject->_oAnimFlag); tbuff += 4; - CopyInt(pObject->_oAnimDelay); - CopyInt(pObject->_oAnimCnt); - CopyInt(pObject->_oAnimLen); - CopyInt(pObject->_oAnimFrame); - CopyInt(pObject->_oAnimWidth); - CopyInt(pObject->_oAnimWidth2); - CopyInt(pObject->_oDelFlag); - - CopyChar(pObject->_oBreak); + CopyInt(tbuff, &pObject->_oAnimDelay); + CopyInt(tbuff, &pObject->_oAnimCnt); + CopyInt(tbuff, &pObject->_oAnimLen); + CopyInt(tbuff, &pObject->_oAnimFrame); + CopyInt(tbuff, &pObject->_oAnimWidth); + CopyInt(tbuff, &pObject->_oAnimWidth2); + CopyInt(tbuff, &pObject->_oDelFlag); + + CopyChar(tbuff, &pObject->_oBreak); tbuff += 3; - CopyInt(pObject->_oSolidFlag); - CopyInt(pObject->_oMissFlag); + CopyInt(tbuff, &pObject->_oSolidFlag); + CopyInt(tbuff, &pObject->_oMissFlag); - CopyChar(pObject->_oSelFlag); + CopyChar(tbuff, &pObject->_oSelFlag); tbuff += 3; - CopyInt(pObject->_oPreFlag); - CopyInt(pObject->_oTrapFlag); - CopyInt(pObject->_oDoorFlag); - CopyInt(pObject->_olid); - CopyInt(pObject->_oRndSeed); - CopyInt(pObject->_oVar1); - CopyInt(pObject->_oVar2); - CopyInt(pObject->_oVar3); - CopyInt(pObject->_oVar4); - CopyInt(pObject->_oVar5); - CopyInt(pObject->_oVar6); - CopyInt(pObject->_oVar7); - CopyInt(pObject->_oVar8); + CopyInt(tbuff, &pObject->_oPreFlag); + CopyInt(tbuff, &pObject->_oTrapFlag); + CopyInt(tbuff, &pObject->_oDoorFlag); + CopyInt(tbuff, &pObject->_olid); + CopyInt(tbuff, &pObject->_oRndSeed); + CopyInt(tbuff, &pObject->_oVar1); + CopyInt(tbuff, &pObject->_oVar2); + CopyInt(tbuff, &pObject->_oVar3); + CopyInt(tbuff, &pObject->_oVar4); + CopyInt(tbuff, &pObject->_oVar5); + CopyInt(tbuff, &pObject->_oVar6); + CopyInt(tbuff, &pObject->_oVar7); + CopyInt(tbuff, &pObject->_oVar8); } void LoadItem(int i) @@ -668,80 +873,80 @@ void LoadItem(int i) void CopyItem(ItemStruct *pItem) { - CopyInt(pItem->_iSeed); - CopyShort(pItem->_iCreateInfo); + CopyInt(tbuff, &pItem->_iSeed); + CopyShort(tbuff, &pItem->_iCreateInfo); tbuff += 2; - CopyInt(pItem->_itype); - CopyInt(pItem->_ix); - CopyInt(pItem->_iy); - CopyInt(pItem->_iAnimFlag); + CopyInt(tbuff, &pItem->_itype); + CopyInt(tbuff, &pItem->_ix); + CopyInt(tbuff, &pItem->_iy); + CopyInt(tbuff, &pItem->_iAnimFlag); tbuff += 4; // Skip pointer _iAnimData - CopyInt(pItem->_iAnimLen); - CopyInt(pItem->_iAnimFrame); - CopyInt(pItem->_iAnimWidth); - CopyInt(pItem->_iAnimWidth2); // width 2? - CopyInt(pItem->_isin); // set when item is flagged for deletion, deprecated in 1.02 - CopyChar(pItem->_iSelFlag); + CopyInt(tbuff, &pItem->_iAnimLen); + CopyInt(tbuff, &pItem->_iAnimFrame); + CopyInt(tbuff, &pItem->_iAnimWidth); + CopyInt(tbuff, &pItem->_iAnimWidth2); // width 2? + CopyInt(tbuff, &pItem->_isin); // set when item is flagged for deletion, deprecated in 1.02 + CopyChar(tbuff, &pItem->_iSelFlag); tbuff += 3; - CopyInt(pItem->_iPostDraw); - CopyInt(pItem->_iIdentified); - CopyChar(pItem->_iMagical); - CopyBytes(64, pItem->_iName); - CopyBytes(64, pItem->_iIName); - CopyChar(pItem->_iLoc); - CopyChar(pItem->_iClass); + CopyInt(tbuff, &pItem->_iPostDraw); + CopyInt(tbuff, &pItem->_iIdentified); + CopyChar(tbuff, &pItem->_iMagical); + CopyBytes(tbuff, 64, &pItem->_iName); + CopyBytes(tbuff, 64, &pItem->_iIName); + CopyChar(tbuff, &pItem->_iLoc); + CopyChar(tbuff, &pItem->_iClass); tbuff += 1; - CopyInt(pItem->_iCurs); - CopyInt(pItem->_ivalue); - CopyInt(pItem->_iIvalue); - CopyInt(pItem->_iMinDam); - CopyInt(pItem->_iMaxDam); - CopyInt(pItem->_iAC); - CopyInt(pItem->_iFlags); - CopyInt(pItem->_iMiscId); - CopyInt(pItem->_iSpell); - CopyInt(pItem->_iCharges); - CopyInt(pItem->_iMaxCharges); - CopyInt(pItem->_iDurability); - CopyInt(pItem->_iMaxDur); - CopyInt(pItem->_iPLDam); - CopyInt(pItem->_iPLToHit); - CopyInt(pItem->_iPLAC); - CopyInt(pItem->_iPLStr); - CopyInt(pItem->_iPLMag); - CopyInt(pItem->_iPLDex); - CopyInt(pItem->_iPLVit); - CopyInt(pItem->_iPLFR); - CopyInt(pItem->_iPLLR); - CopyInt(pItem->_iPLMR); - CopyInt(pItem->_iPLMana); - CopyInt(pItem->_iPLHP); - CopyInt(pItem->_iPLDamMod); - CopyInt(pItem->_iPLGetHit); - CopyInt(pItem->_iPLLight); - CopyChar(pItem->_iSplLvlAdd); - CopyChar(pItem->_iRequest); + CopyInt(tbuff, &pItem->_iCurs); + CopyInt(tbuff, &pItem->_ivalue); + CopyInt(tbuff, &pItem->_iIvalue); + CopyInt(tbuff, &pItem->_iMinDam); + CopyInt(tbuff, &pItem->_iMaxDam); + CopyInt(tbuff, &pItem->_iAC); + CopyInt(tbuff, &pItem->_iFlags); + CopyInt(tbuff, &pItem->_iMiscId); + CopyInt(tbuff, &pItem->_iSpell); + CopyInt(tbuff, &pItem->_iCharges); + CopyInt(tbuff, &pItem->_iMaxCharges); + CopyInt(tbuff, &pItem->_iDurability); + CopyInt(tbuff, &pItem->_iMaxDur); + CopyInt(tbuff, &pItem->_iPLDam); + CopyInt(tbuff, &pItem->_iPLToHit); + CopyInt(tbuff, &pItem->_iPLAC); + CopyInt(tbuff, &pItem->_iPLStr); + CopyInt(tbuff, &pItem->_iPLMag); + CopyInt(tbuff, &pItem->_iPLDex); + CopyInt(tbuff, &pItem->_iPLVit); + CopyInt(tbuff, &pItem->_iPLFR); + CopyInt(tbuff, &pItem->_iPLLR); + CopyInt(tbuff, &pItem->_iPLMR); + CopyInt(tbuff, &pItem->_iPLMana); + CopyInt(tbuff, &pItem->_iPLHP); + CopyInt(tbuff, &pItem->_iPLDamMod); + CopyInt(tbuff, &pItem->_iPLGetHit); + CopyInt(tbuff, &pItem->_iPLLight); + CopyChar(tbuff, &pItem->_iSplLvlAdd); + CopyChar(tbuff, &pItem->_iRequest); tbuff += 2; - CopyInt(pItem->_iUid); - CopyInt(pItem->_iFMinDam); - CopyInt(pItem->_iFMaxDam); - CopyInt(pItem->_iLMinDam); - CopyInt(pItem->_iLMaxDam); - CopyInt(pItem->_iPLEnAc); - CopyChar(pItem->_iPrePower); - CopyChar(pItem->_iSufPower); + CopyInt(tbuff, &pItem->_iUid); + CopyInt(tbuff, &pItem->_iFMinDam); + CopyInt(tbuff, &pItem->_iFMaxDam); + CopyInt(tbuff, &pItem->_iLMinDam); + CopyInt(tbuff, &pItem->_iLMaxDam); + CopyInt(tbuff, &pItem->_iPLEnAc); + CopyChar(tbuff, &pItem->_iPrePower); + CopyChar(tbuff, &pItem->_iSufPower); tbuff += 2; - CopyInt(pItem->_iVAdd1); - CopyInt(pItem->_iVMult1); - CopyInt(pItem->_iVAdd2); - CopyInt(pItem->_iVMult2); - CopyChar(pItem->_iMinStr); - CopyChar(pItem->_iMinMag); - CopyChar(pItem->_iMinDex); + CopyInt(tbuff, &pItem->_iVAdd1); + CopyInt(tbuff, &pItem->_iVMult1); + CopyInt(tbuff, &pItem->_iVAdd2); + CopyInt(tbuff, &pItem->_iVMult2); + CopyChar(tbuff, &pItem->_iMinStr); + CopyChar(tbuff, &pItem->_iMinMag); + CopyChar(tbuff, &pItem->_iMinDex); tbuff += 1; - CopyInt(pItem->_iStatFlag); - CopyInt(pItem->IDidx); - CopyInt(pItem->offs016C); + CopyInt(tbuff, &pItem->_iStatFlag); + CopyInt(tbuff, &pItem->IDidx); + CopyInt(tbuff, &pItem->offs016C); } void CopyItems(const int n, ItemStruct *pItem) @@ -752,6 +957,92 @@ void CopyItems(const int n, ItemStruct *pItem) } } +void SaveItem(ItemStruct *pItem) +{ + CopyInt(&pItem->_iSeed, tbuff); + CopyShort(&pItem->_iCreateInfo, tbuff); + tbuff += 2; + CopyInt(&pItem->_itype, tbuff); + CopyInt(&pItem->_ix, tbuff); + CopyInt(&pItem->_iy, tbuff); + CopyInt(&pItem->_iAnimFlag, tbuff); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(&pItem->_iAnimLen, tbuff); + CopyInt(&pItem->_iAnimFrame, tbuff); + CopyInt(&pItem->_iAnimWidth, tbuff); + CopyInt(&pItem->_iAnimWidth2, tbuff); // width 2? + CopyInt(&pItem->_isin, tbuff); // set when item is flagged for deletion, deprecated in 1.02 + CopyChar(&pItem->_iSelFlag, tbuff); + tbuff += 3; + CopyInt(&pItem->_iPostDraw, tbuff); + CopyInt(&pItem->_iIdentified, tbuff); + CopyChar(&pItem->_iMagical, tbuff); + CopyBytes(&pItem->_iName, 64, tbuff); + CopyBytes(&pItem->_iIName, 64, tbuff); + CopyChar(&pItem->_iLoc, tbuff); + CopyChar(&pItem->_iClass, tbuff); + tbuff += 1; + CopyInt(&pItem->_iCurs, tbuff); + CopyInt(&pItem->_ivalue, tbuff); + CopyInt(&pItem->_iIvalue, tbuff); + CopyInt(&pItem->_iMinDam, tbuff); + CopyInt(&pItem->_iMaxDam, tbuff); + CopyInt(&pItem->_iAC, tbuff); + CopyInt(&pItem->_iFlags, tbuff); + CopyInt(&pItem->_iMiscId, tbuff); + CopyInt(&pItem->_iSpell, tbuff); + CopyInt(&pItem->_iCharges, tbuff); + CopyInt(&pItem->_iMaxCharges, tbuff); + CopyInt(&pItem->_iDurability, tbuff); + CopyInt(&pItem->_iMaxDur, tbuff); + CopyInt(&pItem->_iPLDam, tbuff); + CopyInt(&pItem->_iPLToHit, tbuff); + CopyInt(&pItem->_iPLAC, tbuff); + CopyInt(&pItem->_iPLStr, tbuff); + CopyInt(&pItem->_iPLMag, tbuff); + CopyInt(&pItem->_iPLDex, tbuff); + CopyInt(&pItem->_iPLVit, tbuff); + CopyInt(&pItem->_iPLFR, tbuff); + CopyInt(&pItem->_iPLLR, tbuff); + CopyInt(&pItem->_iPLMR, tbuff); + CopyInt(&pItem->_iPLMana, tbuff); + CopyInt(&pItem->_iPLHP, tbuff); + CopyInt(&pItem->_iPLDamMod, tbuff); + CopyInt(&pItem->_iPLGetHit, tbuff); + CopyInt(&pItem->_iPLLight, tbuff); + CopyChar(&pItem->_iSplLvlAdd, tbuff); + CopyChar(&pItem->_iRequest, tbuff); + tbuff += 2; + CopyInt(&pItem->_iUid, tbuff); + CopyInt(&pItem->_iFMinDam, tbuff); + CopyInt(&pItem->_iFMaxDam, tbuff); + CopyInt(&pItem->_iLMinDam, tbuff); + CopyInt(&pItem->_iLMaxDam, tbuff); + CopyInt(&pItem->_iPLEnAc, tbuff); + CopyChar(&pItem->_iPrePower, tbuff); + CopyChar(&pItem->_iSufPower, tbuff); + tbuff += 2; + CopyInt(&pItem->_iVAdd1, tbuff); + CopyInt(&pItem->_iVMult1, tbuff); + CopyInt(&pItem->_iVAdd2, tbuff); + CopyInt(&pItem->_iVMult2, tbuff); + CopyChar(&pItem->_iMinStr, tbuff); + CopyChar(&pItem->_iMinMag, tbuff); + CopyChar(&pItem->_iMinDex, tbuff); + tbuff += 1; + CopyInt(&pItem->_iStatFlag, tbuff); + CopyInt(&pItem->IDidx, tbuff); + CopyInt(&pItem->offs016C, tbuff); +} + +void SaveItems(ItemStruct *pItem, const int n) +{ + for (int i = 0; i < n; i++) + { + SaveItem(&pItem[i]); + } +} + void LoadPremium(int i) { memcpy(&premiumitem[i], tbuff, sizeof(*premiumitem)); @@ -959,12 +1250,6 @@ void OSave(BOOL v) *tbuff++ = FALSE; } -void SavePlayer(int i) -{ - memcpy(tbuff, &plr[i], sizeof(*plr) - (10 * sizeof(void *))); - tbuff += sizeof(*plr) - (10 * sizeof(void *)); // omit last 10 pointers -} - void SaveMonster(int i) { memcpy(tbuff, &monster[i], sizeof(*monster) - (3 * sizeof(void *))); diff --git a/Source/loadsave.h b/Source/loadsave.h index 3ddf9cead38..3d04e987670 100644 --- a/Source/loadsave.h +++ b/Source/loadsave.h @@ -11,6 +11,8 @@ int ILoad(); BOOL OLoad(); void CopyItems(const int n, ItemStruct *pItem); void CopyItem(ItemStruct *pItem); +void SaveItem(ItemStruct *pItem); +void SaveItems(ItemStruct *pItem, const int n); void LoadPlayer(int i); void LoadMonster(int i); From 8432f2593fe787ea9d4b8fda64961f58765d6ec7 Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 06:39:05 -0700 Subject: [PATCH 03/11] Bufix - pointers --- Source/loadsave.cpp | 258 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 204 insertions(+), 54 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 510eb09788f..dd057ff0fbd 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -174,13 +174,11 @@ void LoadGame(BOOL firstflag) gbProcessPlayers = TRUE; } -// Load a byte-size char from the buffer char BLoad() { return *tbuff++; } -// Redundant? int WLoad() { int rv = *tbuff++ << 24; @@ -191,7 +189,6 @@ int WLoad() return rv; } -// Load a 32 bit integer from the buffer int ILoad() { int rv = *tbuff++ << 24; @@ -210,19 +207,12 @@ BOOL OLoad() return FALSE; } -// Consume an int from tbuff with memcpy - copies directly, doesn't change byte order void CopyInt(const void *src, void * dst) { memcpy(dst, src, 4); tbuff += 4; } -/*void CopyInt(BYTE **src, unsigned int & dst) -{ - memcpy(&dst, src, 4); - tbuff += 4; -}*/ - void CopyShort(const void *src, void * dst) { memcpy(dst, src, 2); @@ -235,7 +225,6 @@ void CopyShorts(const void *src, const int n, void * dst) tbuff += 2 * n; } -// Copy an int array of size n void CopyInts(const void *src, const int n, void * dst) { memcpy(dst, src, 4 * n); @@ -250,19 +239,18 @@ void CopyBytes(const void *src, const int n, void * dst) void CopyChar(const void *src, void * dst) { - memcpy(&dst, src, 1); + memcpy(dst, src, 1); tbuff += 1; } void CopyInt64(const void *src, void * dst) { - memcpy(&dst, src, 8); + memcpy(dst, src, 8); tbuff += 8; } void LoadPlayer(int i) { - // Copy from tbuff to structures PlayerStruct *pPlayer = &plr[i]; CopyInt(tbuff, &pPlayer->_pmode); @@ -308,9 +296,10 @@ void LoadPlayer(int i) CopyInt(tbuff, &pPlayer->_pSpell); CopyChar(tbuff, &pPlayer->_pSplType); CopyChar(tbuff, &pPlayer->_pSplFrom); + tbuff += 2; CopyInt(tbuff, &pPlayer->_pTSpell); CopyChar(tbuff, &pPlayer->_pTSplType); - tbuff += 5; + tbuff += 3; CopyInt(tbuff, &pPlayer->_pRSpell); CopyChar(tbuff, &pPlayer->_pRSplType); tbuff += 3; @@ -376,42 +365,42 @@ void LoadPlayer(int i) CopyInt(tbuff, &pPlayer->_pVar7); CopyInt(tbuff, &pPlayer->_pVar8); CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pLvlVisited); - CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pSLvlVisited); // only 10 used + CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pSLvlVisited); tbuff += 2; CopyInt(tbuff, &pPlayer->_pGFXLoad); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(__uint32_t) * 8; CopyInt(tbuff, &pPlayer->_pNFrames); CopyInt(tbuff, &pPlayer->_pNWidth); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(__uint32_t) * 8 CopyInt(tbuff, &pPlayer->_pWFrames); CopyInt(tbuff, &pPlayer->_pWWidth); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(__uint32_t) * 8; CopyInt(tbuff, &pPlayer->_pAFrames); CopyInt(tbuff, &pPlayer->_pAWidth); CopyInt(tbuff, &pPlayer->_pAFNum); - tbuff += sizeof(__uint32_t) * 24; // Skip 24 pointers + tbuff += sizeof(__uint32_t) * 24; CopyInt(tbuff, &pPlayer->_pSFrames); CopyInt(tbuff, &pPlayer->_pSWidth); CopyInt(tbuff, &pPlayer->_pSFNum); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(__uint32_t) * 8; CopyInt(tbuff, &pPlayer->_pHFrames); CopyInt(tbuff, &pPlayer->_pHWidth); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(__uint32_t) * 8; CopyInt(tbuff, &pPlayer->_pDFrames); CopyInt(tbuff, &pPlayer->_pDWidth); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(__uint32_t) * 8; CopyInt(tbuff, &pPlayer->_pBFrames); CopyInt(tbuff, &pPlayer->_pBWidth); @@ -462,21 +451,13 @@ void LoadPlayer(int i) } -/*void SavePlayer(int i) -{ - memcpy(tbuff, &plr[i], sizeof(*plr) - (10 * sizeof(void *))); - tbuff += sizeof(*plr) - (10 * sizeof(void *)); // omit last 10 pointers -}*/ - - void SavePlayer(int i) { - // Copy from tbuff to structures PlayerStruct *pPlayer = &plr[i]; - CopyInt(pPlayer->_pmode, tbuff); + CopyInt(&pPlayer->_pmode, tbuff); - CopyBytes(pPlayer->walkpath, 25, tbuff); + CopyBytes(&pPlayer->walkpath, 25, tbuff); CopyBytes(&pPlayer->plractive, 1, tbuff); tbuff += 2; @@ -515,11 +496,14 @@ void SavePlayer(int i) CopyInt(&pPlayer->_pvid, tbuff); CopyInt(&pPlayer->_pSpell, tbuff); + CopyChar(&pPlayer->_pSplType, tbuff); CopyChar(&pPlayer->_pSplFrom, tbuff); + tbuff += 2; + CopyInt(&pPlayer->_pTSpell, tbuff); CopyChar(&pPlayer->_pTSplType, tbuff); - tbuff += 5; + tbuff += 3; CopyInt(&pPlayer->_pRSpell, tbuff); CopyChar(&pPlayer->_pRSplType, tbuff); tbuff += 3; @@ -664,7 +648,7 @@ void SavePlayer(int i) CopyShorts(&pPlayer->wReserved, 8, tbuff); - CopyInt(tbuff, pPlayer->pDiabloKillLevel); + CopyInt(&pPlayer->pDiabloKillLevel, tbuff); CopyInts(&pPlayer->dwReserved, 7, tbuff); // Omit 10 pointers @@ -884,8 +868,8 @@ void CopyItem(ItemStruct *pItem) CopyInt(tbuff, &pItem->_iAnimLen); CopyInt(tbuff, &pItem->_iAnimFrame); CopyInt(tbuff, &pItem->_iAnimWidth); - CopyInt(tbuff, &pItem->_iAnimWidth2); // width 2? - CopyInt(tbuff, &pItem->_isin); // set when item is flagged for deletion, deprecated in 1.02 + CopyInt(tbuff, &pItem->_iAnimWidth2); + CopyInt(tbuff, &pItem->_isin); CopyChar(tbuff, &pItem->_iSelFlag); tbuff += 3; CopyInt(tbuff, &pItem->_iPostDraw); @@ -1045,8 +1029,7 @@ void SaveItems(ItemStruct *pItem, const int n) void LoadPremium(int i) { - memcpy(&premiumitem[i], tbuff, sizeof(*premiumitem)); - tbuff += sizeof(*premiumitem); + CopyItem(&item[i]); } void LoadQuest(int i) @@ -1152,7 +1135,7 @@ void SaveGame() for (i = 0; i < MAXITEMS; i++) BSave(itemavail[i]); for (i = 0; i < numitems; i++) - SaveItem(itemactive[i]); + SaveItem(&item[itemactive[i]]); for (i = 0; i < 128; i++) OSave(UniqueItemFlag[i]); @@ -1252,32 +1235,199 @@ void OSave(BOOL v) void SaveMonster(int i) { - memcpy(tbuff, &monster[i], sizeof(*monster) - (3 * sizeof(void *))); - tbuff += sizeof(*monster) - (3 * sizeof(void *)); // omit last 3 pointers + MonsterStruct *pMonster = &monster[i]; + + CopyInt(&pMonster->_mMTidx, tbuff); + CopyInt(&pMonster->_mmode, tbuff); + + CopyChar(&pMonster->_mgoal, tbuff); + tbuff += 3; + + CopyInt(&pMonster->_mgoalvar1, tbuff); + CopyInt(&pMonster->_mgoalvar2, tbuff); + CopyInt(&pMonster->_mgoalvar3, tbuff); + CopyInt(&pMonster->field_18, tbuff); + + CopyChar(&pMonster->_pathcount, tbuff); + tbuff += 3; + + CopyInt(&pMonster->_mx, tbuff); + CopyInt(&pMonster->_my, tbuff); + CopyInt(&pMonster->_mfutx, tbuff); + CopyInt(&pMonster->_mfuty, tbuff); + CopyInt(&pMonster->_moldx, tbuff); + CopyInt(&pMonster->_moldy, tbuff); + CopyInt(&pMonster->_mxoff, tbuff); + CopyInt(&pMonster->_myoff, tbuff); + CopyInt(&pMonster->_mxvel, tbuff); + CopyInt(&pMonster->_myvel, tbuff); + CopyInt(&pMonster->_mdir, tbuff); + CopyInt(&pMonster->_menemy, tbuff); + + CopyChar(&pMonster->_menemyx, tbuff); + CopyChar(&pMonster->_menemyy, tbuff); + CopyShort(&pMonster->falign_52, tbuff); + + tbuff += 4; // Skip pointer + CopyInt(&pMonster->_mAnimDelay, tbuff); + CopyInt(&pMonster->_mAnimCnt, tbuff); + CopyInt(&pMonster->_mAnimLen, tbuff); + CopyInt(&pMonster->_mAnimFrame, tbuff); + CopyInt(&pMonster->_meflag, tbuff); + CopyInt(&pMonster->_mDelFlag, tbuff); + CopyInt(&pMonster->_mVar1, tbuff); + CopyInt(&pMonster->_mVar2, tbuff); + CopyInt(&pMonster->_mVar3, tbuff); + CopyInt(&pMonster->_mVar4, tbuff); + CopyInt(&pMonster->_mVar5, tbuff); + CopyInt(&pMonster->_mVar6, tbuff); + CopyInt(&pMonster->_mVar7, tbuff); + CopyInt(&pMonster->_mVar8, tbuff); + CopyInt(&pMonster->_mmaxhp, tbuff); + CopyInt(&pMonster->_mhitpoints, tbuff); + + CopyChar(&pMonster->_mAi, tbuff); + CopyChar(&pMonster->_mint, tbuff); + CopyShort(&pMonster->falign_9A, tbuff); + + CopyInt(&pMonster->_mFlags, tbuff); + + CopyChar(&pMonster->_msquelch, tbuff); + tbuff += 3; + + CopyInt(&pMonster->falign_A4, tbuff); + CopyInt(&pMonster->_lastx, tbuff); + CopyInt(&pMonster->_lasty, tbuff); + CopyInt(&pMonster->_mRndSeed, tbuff); + CopyInt(&pMonster->_mAISeed, tbuff); + CopyInt(&pMonster->falign_B8, tbuff); + + CopyChar(&pMonster->_uniqtype, tbuff); + CopyChar(&pMonster->_uniqtrans, tbuff); + CopyChar(&pMonster->_udeadval, tbuff); + CopyChar(&pMonster->mWhoHit, tbuff); + + CopyChar(&pMonster->mLevel, tbuff); + CopyShort(&pMonster->mExp, tbuff); + tbuff += 1; + + CopyChar(&pMonster->mHit, tbuff); + CopyChar(&pMonster->mMinDamage, tbuff); + CopyChar(&pMonster->mMaxDamage, tbuff); + CopyChar(&pMonster->mHit2, tbuff); + + CopyChar(&pMonster->mMinDamage2, tbuff); + CopyChar(&pMonster->mMaxDamage2, tbuff); + CopyChar(&pMonster->mArmorClass, tbuff); + CopyChar(&pMonster->falign_CB, tbuff); + + CopyShort(&pMonster->mMagicRes, tbuff); + tbuff += 2; + + CopyInt(&pMonster->mtalkmsg, tbuff); + + CopyChar(&pMonster->leader, tbuff); + CopyChar(&pMonster->leaderflag, tbuff); + CopyChar(&pMonster->packsize, tbuff); + CopyChar(&pMonster->mlid, tbuff); } void SaveMissile(int i) { - memcpy(tbuff, &missile[i], sizeof(*missile)); - tbuff += sizeof(*missile); + MissileStruct *pMissile = &missile[i]; + + CopyInt(&pMissile->_mitype, tbuff); + CopyInt(&pMissile->_mix, tbuff); + CopyInt(&pMissile->_miy, tbuff); + CopyInt(&pMissile->_mixoff, tbuff); + CopyInt(&pMissile->_miyoff, tbuff); + CopyInt(&pMissile->_mixvel, tbuff); + CopyInt(&pMissile->_miyvel, tbuff); + CopyInt(&pMissile->_misx, tbuff); + CopyInt(&pMissile->_misy, tbuff); + CopyInt(&pMissile->_mitxoff, tbuff); + CopyInt(&pMissile->_mityoff, tbuff); + CopyInt(&pMissile->_mimfnum, tbuff); + CopyInt(&pMissile->_mispllvl, tbuff); + CopyInt(&pMissile->_miDelFlag, tbuff); + CopyChar(&pMissile->_miAnimType, tbuff); + tbuff += 3; + + CopyInt(&pMissile->_miAnimFlags, tbuff); + tbuff += 4; + CopyInt(&pMissile->_miAnimDelay, tbuff); + CopyInt(&pMissile->_miAnimLen, tbuff); + CopyInt(&pMissile->_miAnimWidth, tbuff); + CopyInt(&pMissile->_miAnimWidth2, tbuff); + CopyInt(&pMissile->_miAnimCnt, tbuff); + CopyInt(&pMissile->_miAnimAdd, tbuff); + CopyInt(&pMissile->_miAnimFrame, tbuff); + CopyInt(&pMissile->_miDrawFlag, tbuff); + CopyInt(&pMissile->_miLightFlag, tbuff); + CopyInt(&pMissile->_miPreFlag, tbuff); + CopyInt(&pMissile->_miUniqTrans, tbuff); + CopyInt(&pMissile->_mirange, tbuff); + CopyInt(&pMissile->_misource, tbuff); + CopyInt(&pMissile->_micaster, tbuff); + CopyInt(&pMissile->_midam, tbuff); + CopyInt(&pMissile->_miHitFlag, tbuff); + CopyInt(&pMissile->_midist, tbuff); + CopyInt(&pMissile->_mlid, tbuff); + CopyInt(&pMissile->_mirnd, tbuff); + CopyInt(&pMissile->_miVar1, tbuff); + CopyInt(&pMissile->_miVar2, tbuff); + CopyInt(&pMissile->_miVar3, tbuff); + CopyInt(&pMissile->_miVar4, tbuff); + CopyInt(&pMissile->_miVar5, tbuff); + CopyInt(&pMissile->_miVar6, tbuff); + CopyInt(&pMissile->_miVar7, tbuff); + CopyInt(&pMissile->_miVar8, tbuff); } void SaveObject(int i) { - memcpy(tbuff, &object[i], sizeof(*object)); - tbuff += sizeof(*object); -} + ObjectStruct *pObject = &object[i]; + CopyInt(tbuff, &pObject->_otype); + CopyInt(&pObject->_ox, tbuff); + CopyInt(&pObject->_oy, tbuff); + CopyInt(&pObject->_oLight, tbuff); + CopyInt(&pObject->_oAnimFlag, tbuff); + tbuff += 4; + CopyInt(&pObject->_oAnimDelay, tbuff); + CopyInt(&pObject->_oAnimCnt, tbuff); + CopyInt(&pObject->_oAnimLen, tbuff); + CopyInt(&pObject->_oAnimFrame, tbuff); + CopyInt(&pObject->_oAnimWidth, tbuff); + CopyInt(&pObject->_oAnimWidth2, tbuff); + CopyInt(&pObject->_oDelFlag, tbuff); + + CopyChar(&pObject->_oBreak, tbuff); + tbuff += 3; -void SaveItem(int i) -{ - memcpy(tbuff, &item[i], sizeof(*item)); - tbuff += sizeof(*item); + CopyInt(&pObject->_oSolidFlag, tbuff); + CopyInt(&pObject->_oMissFlag, tbuff); + + CopyChar(&pObject->_oSelFlag, tbuff); + tbuff += 3; + + CopyInt(&pObject->_oPreFlag, tbuff); + CopyInt(&pObject->_oTrapFlag, tbuff); + CopyInt(&pObject->_oDoorFlag, tbuff); + CopyInt(&pObject->_olid, tbuff); + CopyInt(&pObject->_oRndSeed, tbuff); + CopyInt(&pObject->_oVar1, tbuff); + CopyInt(&pObject->_oVar2, tbuff); + CopyInt(&pObject->_oVar3, tbuff); + CopyInt(&pObject->_oVar4, tbuff); + CopyInt(&pObject->_oVar5, tbuff); + CopyInt(&pObject->_oVar6, tbuff); + CopyInt(&pObject->_oVar7, tbuff); + CopyInt(&pObject->_oVar8, tbuff); } void SavePremium(int i) { - memcpy(tbuff, &premiumitem[i], sizeof(*premiumitem)); - tbuff += sizeof(*premiumitem); + SaveItem(&item[i]); } void SaveQuest(int i) @@ -1352,7 +1502,7 @@ void SaveLevel() for (i = 0; i < MAXITEMS; i++) BSave(itemavail[i]); for (i = 0; i < numitems; i++) - SaveItem(itemactive[i]); + SaveItem(&item[itemactive[i]]); for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) From ce8a52daca7e6ded860a1a35ef8b7c621fb7304d Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 06:41:23 -0700 Subject: [PATCH 04/11] Add missing pragma pack to some structs --- Source/loadsave.cpp | 2 +- structs.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index dd057ff0fbd..d275ccdbc3c 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -373,7 +373,7 @@ void LoadPlayer(int i) CopyInt(tbuff, &pPlayer->_pNFrames); CopyInt(tbuff, &pPlayer->_pNWidth); - tbuff += sizeof(__uint32_t) * 8 + tbuff += sizeof(__uint32_t) * 8; CopyInt(tbuff, &pPlayer->_pWFrames); CopyInt(tbuff, &pPlayer->_pWWidth); diff --git a/structs.h b/structs.h index 6e9d86de1e6..eb2cb92aea8 100644 --- a/structs.h +++ b/structs.h @@ -979,7 +979,7 @@ typedef struct TBuffer { ////////////////////////////////////////////////// // quests ////////////////////////////////////////////////// - +#pragma pack(push, 4) typedef struct QuestStruct { unsigned char _qlevel; unsigned char _qtype; @@ -994,6 +994,7 @@ typedef struct QuestStruct { unsigned char _qvar2; int _qlog; } QuestStruct; +#pragma pack(pop) typedef struct QuestData { unsigned char _qdlvl; @@ -1204,6 +1205,7 @@ typedef struct LightListStruct { int _yoff; int _lflags; } LightListStruct; +#pragma pack(pop) ////////////////////////////////////////////////// // dead @@ -1216,7 +1218,6 @@ typedef struct DeadStruct { int _deadWidth2; char _deadtrans; } DeadStruct; -#pragma pack(pop) ////////////////////////////////////////////////// // diabloui From ca83513d801fc61718cb6ee4a6cd08b0d67c2afd Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 07:05:08 -0700 Subject: [PATCH 05/11] Style fixes --- Source/loadsave.cpp | 3292 +++++++++++++++++++++---------------------- structs.h | 40 +- 2 files changed, 1664 insertions(+), 1668 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index d275ccdbc3c..1d2ddeb958f 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -1,1648 +1,1644 @@ -#include "diablo.h" - -DEVILUTION_BEGIN_NAMESPACE - -BYTE *tbuff; - -void LoadGame(BOOL firstflag) -{ - int i, j; - DWORD dwLen; - char szName[MAX_PATH]; - BYTE *LoadBuff; - int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects; - - FreeGameMem(); - pfile_remove_temp_files(); - pfile_get_game_name(szName); - LoadBuff = pfile_read(szName, &dwLen); - tbuff = LoadBuff; - - if (ILoad() != 'RETL') - app_fatal("Invalid save file"); - - setlevel = OLoad(); - setlvlnum = WLoad(); - currlevel = WLoad(); - leveltype = WLoad(); - _ViewX = WLoad(); - _ViewY = WLoad(); - invflag = OLoad(); - chrflag = OLoad(); - _nummonsters = WLoad(); - _numitems = WLoad(); - _nummissiles = WLoad(); - _nobjects = WLoad(); - - for (i = 0; i < NUMLEVELS; i++) { - glSeedTbl[i] = ILoad(); - gnLevelTypeTbl[i] = WLoad(); - } - - LoadPlayer(myplr); - - for (i = 0; i < MAXQUESTS; i++) - LoadQuest(i); - for (i = 0; i < MAXPORTAL; i++) - LoadPortal(i); - - LoadGameLevel(firstflag, 4); - SyncInitPlr(myplr); - SyncPlrAnim(myplr); - - ViewX = _ViewX; - ViewY = _ViewY; - nummonsters = _nummonsters; - numitems = _numitems; - nummissiles = _nummissiles; - nobjects = _nobjects; - - for (i = 0; i < MAXMONSTERS; i++) - monstkills[i] = ILoad(); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - monstactive[i] = WLoad(); - for (i = 0; i < nummonsters; i++) - LoadMonster(monstactive[i]); - for (i = 0; i < MAXMISSILES; i++) - missileactive[i] = BLoad(); - for (i = 0; i < MAXMISSILES; i++) - missileavail[i] = BLoad(); - for (i = 0; i < nummissiles; i++) - LoadMissile(missileactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - objectactive[i] = BLoad(); - for (i = 0; i < MAXOBJECTS; i++) - objectavail[i] = BLoad(); - for (i = 0; i < nobjects; i++) - LoadObject(objectactive[i]); - for (i = 0; i < nobjects; i++) - SyncObjectAnim(objectactive[i]); - - numlights = WLoad(); - - for (i = 0; i < MAXLIGHTS; i++) - lightactive[i] = BLoad(); - for (i = 0; i < numlights; i++) - LoadLighting(lightactive[i]); - - visionid = WLoad(); - numvision = WLoad(); - - for (i = 0; i < numvision; i++) - LoadVision(i); - } - - for (i = 0; i < MAXITEMS; i++) - itemactive[i] = BLoad(); - for (i = 0; i < MAXITEMS; i++) - itemavail[i] = BLoad(); - for (i = 0; i < numitems; i++) - LoadItem(itemactive[i]); - for (i = 0; i < 128; i++) - UniqueItemFlag[i] = OLoad(); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dFlags[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPlayer[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dItem[i][j] = BLoad(); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMonster[i][j] = WLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dDead[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dObject[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPreLight[i][j] = BLoad(); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - automapview[i][j] = OLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMissile[i][j] = BLoad(); - } - } - - numpremium = WLoad(); - premiumlevel = WLoad(); - - for (i = 0; i < 6; i++) - LoadPremium(i); - - automapflag = OLoad(); - AutoMapScale = WLoad(); - mem_free_dbg(LoadBuff); - AutomapZoomReset(); - ResyncQuests(); - - if (leveltype != DTYPE_TOWN) - ProcessLightList(); - - RedoPlayerVision(); - ProcessVisionList(); - missiles_process_charge(); - ResetPal(); - SetCursor_(CURSOR_HAND); - gbProcessPlayers = TRUE; -} - -char BLoad() -{ - return *tbuff++; -} - -int WLoad() -{ - int rv = *tbuff++ << 24; - rv |= *tbuff++ << 16; - rv |= *tbuff++ << 8; - rv |= *tbuff++; - - return rv; -} - -int ILoad() -{ - int rv = *tbuff++ << 24; - rv |= *tbuff++ << 16; - rv |= *tbuff++ << 8; - rv |= *tbuff++; - - return rv; -} - -BOOL OLoad() -{ - if (*tbuff++ == TRUE) - return TRUE; - else - return FALSE; -} - -void CopyInt(const void *src, void * dst) -{ - memcpy(dst, src, 4); - tbuff += 4; -} - -void CopyShort(const void *src, void * dst) -{ - memcpy(dst, src, 2); - tbuff += 2; -} - -void CopyShorts(const void *src, const int n, void * dst) -{ - memcpy(dst, src, 2 * n); - tbuff += 2 * n; -} - -void CopyInts(const void *src, const int n, void * dst) -{ - memcpy(dst, src, 4 * n); - tbuff += 4 * n; -} - -void CopyBytes(const void *src, const int n, void * dst) -{ - memcpy(dst, src, n); - tbuff += n; -} - -void CopyChar(const void *src, void * dst) -{ - memcpy(dst, src, 1); - tbuff += 1; -} - -void CopyInt64(const void *src, void * dst) -{ - memcpy(dst, src, 8); - tbuff += 8; -} - -void LoadPlayer(int i) -{ - PlayerStruct *pPlayer = &plr[i]; - - CopyInt(tbuff, &pPlayer->_pmode); - - CopyBytes(tbuff, 25, pPlayer->walkpath); - CopyBytes(tbuff, 1, &pPlayer->plractive); - tbuff += 2; - - CopyInt(tbuff, &pPlayer->destAction); - CopyInt(tbuff, &pPlayer->destParam1); - CopyInt(tbuff, &pPlayer->destParam2); - CopyInt(tbuff, &pPlayer->destParam3); - CopyInt(tbuff, &pPlayer->destParam4); - CopyInt(tbuff, &pPlayer->plrlevel); - CopyInt(tbuff, &pPlayer->WorldX); - CopyInt(tbuff, &pPlayer->WorldY); - CopyInt(tbuff, &pPlayer->_px); - CopyInt(tbuff, &pPlayer->_py); - CopyInt(tbuff, &pPlayer->_ptargx); - CopyInt(tbuff, &pPlayer->_ptargy); - CopyInt(tbuff, &pPlayer->_pownerx); - CopyInt(tbuff, &pPlayer->_pownery); - CopyInt(tbuff, &pPlayer->_poldx); - CopyInt(tbuff, &pPlayer->_poldy); - CopyInt(tbuff, &pPlayer->_pxoff); - CopyInt(tbuff, &pPlayer->_pyoff); - CopyInt(tbuff, &pPlayer->_pxvel); - CopyInt(tbuff, &pPlayer->_pyvel); - CopyInt(tbuff, &pPlayer->_pdir); - CopyInt(tbuff, &pPlayer->_nextdir); - CopyInt(tbuff, &pPlayer->_pgfxnum); - tbuff += 4; // Skip pointers - CopyInt(tbuff, &pPlayer->_pAnimDelay); - CopyInt(tbuff, &pPlayer->_pAnimCnt); - CopyInt(tbuff, &pPlayer->_pAnimLen); - CopyInt(tbuff, &pPlayer->_pAnimFrame); - CopyInt(tbuff, &pPlayer->_pAnimWidth); - CopyInt(tbuff, &pPlayer->_pAnimWidth2); - CopyInt(tbuff, &pPlayer->_peflag); - CopyInt(tbuff, &pPlayer->_plid); - CopyInt(tbuff, &pPlayer->_pvid); - - CopyInt(tbuff, &pPlayer->_pSpell); - CopyChar(tbuff, &pPlayer->_pSplType); - CopyChar(tbuff, &pPlayer->_pSplFrom); - tbuff += 2; - CopyInt(tbuff, &pPlayer->_pTSpell); - CopyChar(tbuff, &pPlayer->_pTSplType); - tbuff += 3; - CopyInt(tbuff, &pPlayer->_pRSpell); - CopyChar(tbuff, &pPlayer->_pRSplType); - tbuff += 3; - CopyInt(tbuff, &pPlayer->_pSBkSpell); - CopyChar(tbuff, &pPlayer->_pSBkSplType); - - CopyBytes(tbuff, 64, &pPlayer->_pSplLvl); - tbuff += 7; - CopyInt64(tbuff, &pPlayer->_pMemSpells); - CopyInt64(tbuff, &pPlayer->_pAblSpells); - CopyInt64(tbuff, &pPlayer->_pScrlSpells); - CopyChar(tbuff, &pPlayer->_pSpellFlags); - tbuff += 3; - CopyInts(tbuff, 4, &pPlayer->_pSplHotKey); - CopyBytes(tbuff, 4, &pPlayer->_pSplTHotKey); - CopyInt(tbuff, &pPlayer->_pwtype); - CopyChar(tbuff, &pPlayer->_pBlockFlag); - CopyChar(tbuff, &pPlayer->_pInvincible); - CopyChar(tbuff, &pPlayer->_pLightRad); - CopyChar(tbuff, &pPlayer->_pLvlChanging); - CopyBytes(tbuff, PLR_NAME_LEN, &pPlayer->_pName); - CopyChar(tbuff, &pPlayer->_pClass); - tbuff += 3; - CopyInt(tbuff, &pPlayer->_pStrength); - CopyInt(tbuff, &pPlayer->_pBaseStr); - CopyInt(tbuff, &pPlayer->_pMagic); - CopyInt(tbuff, &pPlayer->_pBaseMag); - CopyInt(tbuff, &pPlayer->_pDexterity); - CopyInt(tbuff, &pPlayer->_pBaseDex); - CopyInt(tbuff, &pPlayer->_pVitality); - CopyInt(tbuff, &pPlayer->_pBaseVit); - CopyInt(tbuff, &pPlayer->_pStatPts); - CopyInt(tbuff, &pPlayer->_pDamageMod); - CopyInt(tbuff, &pPlayer->_pBaseToBlk); - CopyInt(tbuff, &pPlayer->_pHPBase); - CopyInt(tbuff, &pPlayer->_pMaxHPBase); - CopyInt(tbuff, &pPlayer->_pHitPoints); - CopyInt(tbuff, &pPlayer->_pMaxHP); - CopyInt(tbuff, &pPlayer->_pHPPer); - CopyInt(tbuff, &pPlayer->_pManaBase); - CopyInt(tbuff, &pPlayer->_pMaxManaBase); - CopyInt(tbuff, &pPlayer->_pMana); - CopyInt(tbuff, &pPlayer->_pMaxMana); - CopyInt(tbuff, &pPlayer->_pManaPer); - CopyChar(tbuff, &pPlayer->_pLevel); - CopyChar(tbuff, &pPlayer->_pMaxLvl); - tbuff += 2; - CopyInt(tbuff, &pPlayer->_pExperience); - CopyInt(tbuff, &pPlayer->_pMaxExp); - CopyInt(tbuff, &pPlayer->_pNextExper); - CopyChar(tbuff, &pPlayer->_pArmorClass); - CopyChar(tbuff, &pPlayer->_pMagResist); - CopyChar(tbuff, &pPlayer->_pFireResist); - CopyChar(tbuff, &pPlayer->_pLghtResist); - CopyInt(tbuff, &pPlayer->_pGold); - CopyInt(tbuff, &pPlayer->_pInfraFlag); - CopyInt(tbuff, &pPlayer->_pVar1); - CopyInt(tbuff, &pPlayer->_pVar2); - CopyInt(tbuff, &pPlayer->_pVar3); - CopyInt(tbuff, &pPlayer->_pVar4); - CopyInt(tbuff, &pPlayer->_pVar5); - CopyInt(tbuff, &pPlayer->_pVar6); - CopyInt(tbuff, &pPlayer->_pVar7); - CopyInt(tbuff, &pPlayer->_pVar8); - CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pLvlVisited); - CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pSLvlVisited); - tbuff += 2; - CopyInt(tbuff, &pPlayer->_pGFXLoad); - - tbuff += sizeof(__uint32_t) * 8; - CopyInt(tbuff, &pPlayer->_pNFrames); - CopyInt(tbuff, &pPlayer->_pNWidth); - - tbuff += sizeof(__uint32_t) * 8; - - CopyInt(tbuff, &pPlayer->_pWFrames); - CopyInt(tbuff, &pPlayer->_pWWidth); - - tbuff += sizeof(__uint32_t) * 8; - - CopyInt(tbuff, &pPlayer->_pAFrames); - CopyInt(tbuff, &pPlayer->_pAWidth); - CopyInt(tbuff, &pPlayer->_pAFNum); - - tbuff += sizeof(__uint32_t) * 24; - - CopyInt(tbuff, &pPlayer->_pSFrames); - CopyInt(tbuff, &pPlayer->_pSWidth); - CopyInt(tbuff, &pPlayer->_pSFNum); - - tbuff += sizeof(__uint32_t) * 8; - - CopyInt(tbuff, &pPlayer->_pHFrames); - CopyInt(tbuff, &pPlayer->_pHWidth); - - tbuff += sizeof(__uint32_t) * 8; - - CopyInt(tbuff, &pPlayer->_pDFrames); - CopyInt(tbuff, &pPlayer->_pDWidth); - - tbuff += sizeof(__uint32_t) * 8; - - CopyInt(tbuff, &pPlayer->_pBFrames); - CopyInt(tbuff, &pPlayer->_pBWidth); - CopyItems(NUM_INVLOC, pPlayer->InvBody); - CopyItems(NUM_INV_GRID_ELEM, pPlayer->InvList); - CopyInt(tbuff, &pPlayer->_pNumInv); - CopyBytes(tbuff, NUM_INV_GRID_ELEM, pPlayer->InvGrid); - CopyItems(MAXBELTITEMS, pPlayer->SpdList); - CopyItem(&pPlayer->HoldItem); - CopyInt(tbuff, &pPlayer->_pIMinDam); - CopyInt(tbuff, &pPlayer->_pIMaxDam); - CopyInt(tbuff, &pPlayer->_pIAC); - CopyInt(tbuff, &pPlayer->_pIBonusDam); - CopyInt(tbuff, &pPlayer->_pIBonusToHit); - CopyInt(tbuff, &pPlayer->_pIBonusAC); - CopyInt(tbuff, &pPlayer->_pIBonusDamMod); - tbuff += 4; - CopyInt64(tbuff, &pPlayer->_pISpells); - CopyInt(tbuff, &pPlayer->_pIFlags); - CopyInt(tbuff, &pPlayer->_pIGetHit); - - CopyChar(tbuff, &pPlayer->_pISplLvlAdd); - CopyChar(tbuff, &pPlayer->_pISplCost); - tbuff += 2; - - CopyInt(tbuff, &pPlayer->_pISplDur); - CopyInt(tbuff, &pPlayer->_pIEnAc); - CopyInt(tbuff, &pPlayer->_pIFMinDam); - CopyInt(tbuff, &pPlayer->_pIFMaxDam); - CopyInt(tbuff, &pPlayer->_pILMinDam); - CopyInt(tbuff, &pPlayer->_pILMaxDam); - CopyInt(tbuff, &pPlayer->_pOilType); - - CopyChar(tbuff, &pPlayer->pTownWarps); - CopyChar(tbuff, &pPlayer->pDungMsgs); - CopyChar(tbuff, &pPlayer->pLvlLoad); - CopyChar(tbuff, &pPlayer->pBattleNet); - - CopyChar(tbuff, &pPlayer->pManaShield); - CopyBytes(tbuff, 3, &pPlayer->bReserved); - - CopyShorts(tbuff, 8, &pPlayer->wReserved); - - CopyInt(tbuff, &pPlayer->pDiabloKillLevel); - CopyInts(tbuff, 7, &pPlayer->dwReserved); - - // Omit 10 pointers - -} - -void SavePlayer(int i) -{ - PlayerStruct *pPlayer = &plr[i]; - - CopyInt(&pPlayer->_pmode, tbuff); - - CopyBytes(&pPlayer->walkpath, 25, tbuff); - CopyBytes(&pPlayer->plractive, 1, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->destAction, tbuff); - CopyInt(&pPlayer->destParam1, tbuff); - CopyInt(&pPlayer->destParam2, tbuff); - CopyInt(&pPlayer->destParam3, tbuff); - CopyInt(&pPlayer->destParam4, tbuff); - CopyInt(&pPlayer->plrlevel, tbuff); - CopyInt(&pPlayer->WorldX, tbuff); - CopyInt(&pPlayer->WorldY, tbuff); - CopyInt(&pPlayer->_px, tbuff); - CopyInt(&pPlayer->_py, tbuff); - CopyInt(&pPlayer->_ptargx, tbuff); - CopyInt(&pPlayer->_ptargy, tbuff); - CopyInt(&pPlayer->_pownerx, tbuff); - CopyInt(&pPlayer->_pownery, tbuff); - CopyInt(&pPlayer->_poldx, tbuff); - CopyInt(&pPlayer->_poldy, tbuff); - CopyInt(&pPlayer->_pxoff, tbuff); - CopyInt(&pPlayer->_pyoff, tbuff); - CopyInt(&pPlayer->_pxvel, tbuff); - CopyInt(&pPlayer->_pyvel, tbuff); - CopyInt(&pPlayer->_pdir, tbuff); - CopyInt(&pPlayer->_nextdir, tbuff); - CopyInt(&pPlayer->_pgfxnum, tbuff); - tbuff += 4; // Skip pointers - CopyInt(&pPlayer->_pAnimDelay, tbuff); - CopyInt(&pPlayer->_pAnimCnt, tbuff); - CopyInt(&pPlayer->_pAnimLen, tbuff); - CopyInt(&pPlayer->_pAnimFrame, tbuff); - CopyInt(&pPlayer->_pAnimWidth, tbuff); - CopyInt(&pPlayer->_pAnimWidth2, tbuff); - CopyInt(&pPlayer->_peflag, tbuff); - CopyInt(&pPlayer->_plid, tbuff); - CopyInt(&pPlayer->_pvid, tbuff); - - CopyInt(&pPlayer->_pSpell, tbuff); - - CopyChar(&pPlayer->_pSplType, tbuff); - CopyChar(&pPlayer->_pSplFrom, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->_pTSpell, tbuff); - CopyChar(&pPlayer->_pTSplType, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pRSpell, tbuff); - CopyChar(&pPlayer->_pRSplType, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pSBkSpell, tbuff); - CopyChar(&pPlayer->_pSBkSplType, tbuff); - - CopyBytes(&pPlayer->_pSplLvl, 64, tbuff); - tbuff += 7; - CopyInt64(&pPlayer->_pMemSpells, tbuff); - CopyInt64(&pPlayer->_pAblSpells, tbuff); - CopyInt64(&pPlayer->_pScrlSpells, tbuff); - CopyChar(&pPlayer->_pSpellFlags, tbuff); - tbuff += 3; - CopyInts(&pPlayer->_pSplHotKey, 4, tbuff); - CopyBytes(&pPlayer->_pSplTHotKey, 4, tbuff); - CopyInt(&pPlayer->_pwtype, tbuff); - CopyChar(&pPlayer->_pBlockFlag, tbuff); - CopyChar(&pPlayer->_pInvincible, tbuff); - CopyChar(&pPlayer->_pLightRad, tbuff); - CopyChar(&pPlayer->_pLvlChanging, tbuff); - CopyBytes(&pPlayer->_pName, PLR_NAME_LEN, tbuff); - CopyChar(&pPlayer->_pClass, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pStrength, tbuff); - CopyInt(&pPlayer->_pBaseStr, tbuff); - CopyInt(&pPlayer->_pMagic, tbuff); - CopyInt(&pPlayer->_pBaseMag, tbuff); - CopyInt(&pPlayer->_pDexterity, tbuff); - CopyInt(&pPlayer->_pBaseDex, tbuff); - CopyInt(&pPlayer->_pVitality, tbuff); - CopyInt(&pPlayer->_pBaseVit, tbuff); - CopyInt(&pPlayer->_pStatPts, tbuff); - CopyInt(&pPlayer->_pDamageMod, tbuff); - CopyInt(&pPlayer->_pBaseToBlk, tbuff); - CopyInt(&pPlayer->_pHPBase, tbuff); - CopyInt(&pPlayer->_pMaxHPBase, tbuff); - CopyInt(&pPlayer->_pHitPoints, tbuff); - CopyInt(&pPlayer->_pMaxHP, tbuff); - CopyInt(&pPlayer->_pHPPer, tbuff); - CopyInt(&pPlayer->_pManaBase, tbuff); - CopyInt(&pPlayer->_pMaxManaBase, tbuff); - CopyInt(&pPlayer->_pMana, tbuff); - CopyInt(&pPlayer->_pMaxMana, tbuff); - CopyInt(&pPlayer->_pManaPer, tbuff); - CopyChar(&pPlayer->_pLevel, tbuff); - CopyChar(&pPlayer->_pMaxLvl, tbuff); - tbuff += 2; - CopyInt(&pPlayer->_pExperience, tbuff); - CopyInt(&pPlayer->_pMaxExp, tbuff); - CopyInt(&pPlayer->_pNextExper, tbuff); - CopyChar(&pPlayer->_pArmorClass, tbuff); - CopyChar(&pPlayer->_pMagResist, tbuff); - CopyChar(&pPlayer->_pFireResist, tbuff); - CopyChar(&pPlayer->_pLghtResist, tbuff); - CopyInt(&pPlayer->_pGold, tbuff); - CopyInt(&pPlayer->_pInfraFlag, tbuff); - CopyInt(&pPlayer->_pVar1, tbuff); - CopyInt(&pPlayer->_pVar2, tbuff); - CopyInt(&pPlayer->_pVar3, tbuff); - CopyInt(&pPlayer->_pVar4, tbuff); - CopyInt(&pPlayer->_pVar5, tbuff); - CopyInt(&pPlayer->_pVar6, tbuff); - CopyInt(&pPlayer->_pVar7, tbuff); - CopyInt(&pPlayer->_pVar8, tbuff); - CopyBytes(&pPlayer->_pLvlVisited, NUMLEVELS, tbuff); - CopyBytes(&pPlayer->_pSLvlVisited, NUMLEVELS, tbuff); // only 10 used - tbuff += 2; - CopyInt(&pPlayer->_pGFXLoad, tbuff); - - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - CopyInt(&pPlayer->_pNFrames, tbuff); - CopyInt(&pPlayer->_pNWidth, tbuff); - - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pWFrames, tbuff); - CopyInt(&pPlayer->_pWWidth, tbuff); - - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pAFrames, tbuff); - CopyInt(&pPlayer->_pAWidth, tbuff); - CopyInt(&pPlayer->_pAFNum, tbuff); - - tbuff += sizeof(__uint32_t) * 24; // Skip 24 pointers - - CopyInt(&pPlayer->_pSFrames, tbuff); - CopyInt(&pPlayer->_pSWidth, tbuff); - CopyInt(&pPlayer->_pSFNum, tbuff); - - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pHFrames, tbuff); - CopyInt(&pPlayer->_pHWidth, tbuff); - - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pDFrames, tbuff); - CopyInt(&pPlayer->_pDWidth, tbuff); - - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pBFrames, tbuff); - CopyInt(&pPlayer->_pBWidth, tbuff); - SaveItems(pPlayer->InvBody, NUM_INVLOC); - SaveItems(pPlayer->InvList, NUM_INV_GRID_ELEM); - CopyInt(&pPlayer->_pNumInv, tbuff); - CopyBytes(pPlayer->InvGrid, NUM_INV_GRID_ELEM, tbuff); - SaveItems(pPlayer->SpdList, MAXBELTITEMS); - SaveItem(&pPlayer->HoldItem); - CopyInt(&pPlayer->_pIMinDam, tbuff); - CopyInt(&pPlayer->_pIMaxDam, tbuff); - CopyInt(&pPlayer->_pIAC, tbuff); - CopyInt(&pPlayer->_pIBonusDam, tbuff); - CopyInt(&pPlayer->_pIBonusToHit, tbuff); - CopyInt(&pPlayer->_pIBonusAC, tbuff); - CopyInt(&pPlayer->_pIBonusDamMod, tbuff); - tbuff += 4; - CopyInt64(&pPlayer->_pISpells, tbuff); - CopyInt(&pPlayer->_pIFlags, tbuff); - CopyInt(&pPlayer->_pIGetHit, tbuff); - - CopyChar(&pPlayer->_pISplLvlAdd, tbuff); - CopyChar(&pPlayer->_pISplCost, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->_pISplDur, tbuff); - CopyInt(&pPlayer->_pIEnAc, tbuff); - CopyInt(&pPlayer->_pIFMinDam, tbuff); - CopyInt(&pPlayer->_pIFMaxDam, tbuff); - CopyInt(&pPlayer->_pILMinDam, tbuff); - CopyInt(&pPlayer->_pILMaxDam, tbuff); - CopyInt(&pPlayer->_pOilType, tbuff); - - CopyChar(&pPlayer->pTownWarps, tbuff); - CopyChar(&pPlayer->pDungMsgs, tbuff); - CopyChar(&pPlayer->pLvlLoad, tbuff); - CopyChar(&pPlayer->pBattleNet, tbuff); - - CopyChar(&pPlayer->pManaShield, tbuff); - CopyBytes(&pPlayer->bReserved, 3, tbuff); - - CopyShorts(&pPlayer->wReserved, 8, tbuff); - - CopyInt(&pPlayer->pDiabloKillLevel, tbuff); - CopyInts(&pPlayer->dwReserved, 7, tbuff); - - // Omit 10 pointers - -} - -void LoadMonster(int i) -{ - MonsterStruct *pMonster = &monster[i]; - - CopyInt(tbuff, &pMonster->_mMTidx); - CopyInt(tbuff, &pMonster->_mmode); - - CopyChar(tbuff, &pMonster->_mgoal); - tbuff += 3; - - CopyInt(tbuff, &pMonster->_mgoalvar1); - CopyInt(tbuff, &pMonster->_mgoalvar2); - CopyInt(tbuff, &pMonster->_mgoalvar3); - CopyInt(tbuff, &pMonster->field_18); - - CopyChar(tbuff, &pMonster->_pathcount); - tbuff += 3; - - CopyInt(tbuff, &pMonster->_mx); - CopyInt(tbuff, &pMonster->_my); - CopyInt(tbuff, &pMonster->_mfutx); - CopyInt(tbuff, &pMonster->_mfuty); - CopyInt(tbuff, &pMonster->_moldx); - CopyInt(tbuff, &pMonster->_moldy); - CopyInt(tbuff, &pMonster->_mxoff); - CopyInt(tbuff, &pMonster->_myoff); - CopyInt(tbuff, &pMonster->_mxvel); - CopyInt(tbuff, &pMonster->_myvel); - CopyInt(tbuff, &pMonster->_mdir); - CopyInt(tbuff, &pMonster->_menemy); - - CopyChar(tbuff, &pMonster->_menemyx); - CopyChar(tbuff, &pMonster->_menemyy); - CopyShort(tbuff, &pMonster->falign_52); - - tbuff += 4; // Skip pointer - CopyInt(tbuff, &pMonster->_mAnimDelay); - CopyInt(tbuff, &pMonster->_mAnimCnt); - CopyInt(tbuff, &pMonster->_mAnimLen); - CopyInt(tbuff, &pMonster->_mAnimFrame); - CopyInt(tbuff, &pMonster->_meflag); - CopyInt(tbuff, &pMonster->_mDelFlag); - CopyInt(tbuff, &pMonster->_mVar1); - CopyInt(tbuff, &pMonster->_mVar2); - CopyInt(tbuff, &pMonster->_mVar3); - CopyInt(tbuff, &pMonster->_mVar4); - CopyInt(tbuff, &pMonster->_mVar5); - CopyInt(tbuff, &pMonster->_mVar6); - CopyInt(tbuff, &pMonster->_mVar7); - CopyInt(tbuff, &pMonster->_mVar8); - CopyInt(tbuff, &pMonster->_mmaxhp); - CopyInt(tbuff, &pMonster->_mhitpoints); - - CopyChar(tbuff, &pMonster->_mAi); - CopyChar(tbuff, &pMonster->_mint); - CopyShort(tbuff, &pMonster->falign_9A); - - CopyInt(tbuff, &pMonster->_mFlags); - - CopyChar(tbuff, &pMonster->_msquelch); - tbuff += 3; - - CopyInt(tbuff, &pMonster->falign_A4); - CopyInt(tbuff, &pMonster->_lastx); - CopyInt(tbuff, &pMonster->_lasty); - CopyInt(tbuff, &pMonster->_mRndSeed); - CopyInt(tbuff, &pMonster->_mAISeed); - CopyInt(tbuff, &pMonster->falign_B8); - - CopyChar(tbuff, &pMonster->_uniqtype); - CopyChar(tbuff, &pMonster->_uniqtrans); - CopyChar(tbuff, &pMonster->_udeadval); - CopyChar(tbuff, &pMonster->mWhoHit); - - CopyChar(tbuff, &pMonster->mLevel); - CopyShort(tbuff, &pMonster->mExp); - tbuff += 1; - - CopyChar(tbuff, &pMonster->mHit); - CopyChar(tbuff, &pMonster->mMinDamage); - CopyChar(tbuff, &pMonster->mMaxDamage); - CopyChar(tbuff, &pMonster->mHit2); - - CopyChar(tbuff, &pMonster->mMinDamage2); - CopyChar(tbuff, &pMonster->mMaxDamage2); - CopyChar(tbuff, &pMonster->mArmorClass); - CopyChar(tbuff, &pMonster->falign_CB); - - CopyShort(tbuff, &pMonster->mMagicRes); - tbuff += 2; - - CopyInt(tbuff, &pMonster->mtalkmsg); - - CopyChar(tbuff, &pMonster->leader); - CopyChar(tbuff, &pMonster->leaderflag); - CopyChar(tbuff, &pMonster->packsize); - CopyChar(tbuff, &pMonster->mlid); - - SyncMonsterAnim(i); -} - -void LoadMissile(int i) -{ - MissileStruct *pMissile = &missile[i]; - - CopyInt(tbuff, &pMissile->_mitype); - CopyInt(tbuff, &pMissile->_mix); - CopyInt(tbuff, &pMissile->_miy); - CopyInt(tbuff, &pMissile->_mixoff); - CopyInt(tbuff, &pMissile->_miyoff); - CopyInt(tbuff, &pMissile->_mixvel); - CopyInt(tbuff, &pMissile->_miyvel); - CopyInt(tbuff, &pMissile->_misx); - CopyInt(tbuff, &pMissile->_misy); - CopyInt(tbuff, &pMissile->_mitxoff); - CopyInt(tbuff, &pMissile->_mityoff); - CopyInt(tbuff, &pMissile->_mimfnum); - CopyInt(tbuff, &pMissile->_mispllvl); - CopyInt(tbuff, &pMissile->_miDelFlag); - CopyChar(tbuff, &pMissile->_miAnimType); - tbuff += 3; - - CopyInt(tbuff, &pMissile->_miAnimFlags); - tbuff += 4; - CopyInt(tbuff, &pMissile->_miAnimDelay); - CopyInt(tbuff, &pMissile->_miAnimLen); - CopyInt(tbuff, &pMissile->_miAnimWidth); - CopyInt(tbuff, &pMissile->_miAnimWidth2); - CopyInt(tbuff, &pMissile->_miAnimCnt); - CopyInt(tbuff, &pMissile->_miAnimAdd); - CopyInt(tbuff, &pMissile->_miAnimFrame); - CopyInt(tbuff, &pMissile->_miDrawFlag); - CopyInt(tbuff, &pMissile->_miLightFlag); - CopyInt(tbuff, &pMissile->_miPreFlag); - CopyInt(tbuff, &pMissile->_miUniqTrans); - CopyInt(tbuff, &pMissile->_mirange); - CopyInt(tbuff, &pMissile->_misource); - CopyInt(tbuff, &pMissile->_micaster); - CopyInt(tbuff, &pMissile->_midam); - CopyInt(tbuff, &pMissile->_miHitFlag); - CopyInt(tbuff, &pMissile->_midist); - CopyInt(tbuff, &pMissile->_mlid); - CopyInt(tbuff, &pMissile->_mirnd); - CopyInt(tbuff, &pMissile->_miVar1); - CopyInt(tbuff, &pMissile->_miVar2); - CopyInt(tbuff, &pMissile->_miVar3); - CopyInt(tbuff, &pMissile->_miVar4); - CopyInt(tbuff, &pMissile->_miVar5); - CopyInt(tbuff, &pMissile->_miVar6); - CopyInt(tbuff, &pMissile->_miVar7); - CopyInt(tbuff, &pMissile->_miVar8); -} - -void LoadObject(int i) -{ - ObjectStruct *pObject = &object[i]; - CopyInt(tbuff, &pObject->_otype); - CopyInt(tbuff, &pObject->_ox); - CopyInt(tbuff, &pObject->_oy); - CopyInt(tbuff, &pObject->_oLight); - CopyInt(tbuff, &pObject->_oAnimFlag); - tbuff += 4; - CopyInt(tbuff, &pObject->_oAnimDelay); - CopyInt(tbuff, &pObject->_oAnimCnt); - CopyInt(tbuff, &pObject->_oAnimLen); - CopyInt(tbuff, &pObject->_oAnimFrame); - CopyInt(tbuff, &pObject->_oAnimWidth); - CopyInt(tbuff, &pObject->_oAnimWidth2); - CopyInt(tbuff, &pObject->_oDelFlag); - - CopyChar(tbuff, &pObject->_oBreak); - tbuff += 3; - - CopyInt(tbuff, &pObject->_oSolidFlag); - CopyInt(tbuff, &pObject->_oMissFlag); - - CopyChar(tbuff, &pObject->_oSelFlag); - tbuff += 3; - - CopyInt(tbuff, &pObject->_oPreFlag); - CopyInt(tbuff, &pObject->_oTrapFlag); - CopyInt(tbuff, &pObject->_oDoorFlag); - CopyInt(tbuff, &pObject->_olid); - CopyInt(tbuff, &pObject->_oRndSeed); - CopyInt(tbuff, &pObject->_oVar1); - CopyInt(tbuff, &pObject->_oVar2); - CopyInt(tbuff, &pObject->_oVar3); - CopyInt(tbuff, &pObject->_oVar4); - CopyInt(tbuff, &pObject->_oVar5); - CopyInt(tbuff, &pObject->_oVar6); - CopyInt(tbuff, &pObject->_oVar7); - CopyInt(tbuff, &pObject->_oVar8); -} - -void LoadItem(int i) -{ - CopyItem(&item[i]); - GetItemFrm(i); -} - -void CopyItem(ItemStruct *pItem) -{ - CopyInt(tbuff, &pItem->_iSeed); - CopyShort(tbuff, &pItem->_iCreateInfo); - tbuff += 2; - CopyInt(tbuff, &pItem->_itype); - CopyInt(tbuff, &pItem->_ix); - CopyInt(tbuff, &pItem->_iy); - CopyInt(tbuff, &pItem->_iAnimFlag); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(tbuff, &pItem->_iAnimLen); - CopyInt(tbuff, &pItem->_iAnimFrame); - CopyInt(tbuff, &pItem->_iAnimWidth); - CopyInt(tbuff, &pItem->_iAnimWidth2); - CopyInt(tbuff, &pItem->_isin); - CopyChar(tbuff, &pItem->_iSelFlag); - tbuff += 3; - CopyInt(tbuff, &pItem->_iPostDraw); - CopyInt(tbuff, &pItem->_iIdentified); - CopyChar(tbuff, &pItem->_iMagical); - CopyBytes(tbuff, 64, &pItem->_iName); - CopyBytes(tbuff, 64, &pItem->_iIName); - CopyChar(tbuff, &pItem->_iLoc); - CopyChar(tbuff, &pItem->_iClass); - tbuff += 1; - CopyInt(tbuff, &pItem->_iCurs); - CopyInt(tbuff, &pItem->_ivalue); - CopyInt(tbuff, &pItem->_iIvalue); - CopyInt(tbuff, &pItem->_iMinDam); - CopyInt(tbuff, &pItem->_iMaxDam); - CopyInt(tbuff, &pItem->_iAC); - CopyInt(tbuff, &pItem->_iFlags); - CopyInt(tbuff, &pItem->_iMiscId); - CopyInt(tbuff, &pItem->_iSpell); - CopyInt(tbuff, &pItem->_iCharges); - CopyInt(tbuff, &pItem->_iMaxCharges); - CopyInt(tbuff, &pItem->_iDurability); - CopyInt(tbuff, &pItem->_iMaxDur); - CopyInt(tbuff, &pItem->_iPLDam); - CopyInt(tbuff, &pItem->_iPLToHit); - CopyInt(tbuff, &pItem->_iPLAC); - CopyInt(tbuff, &pItem->_iPLStr); - CopyInt(tbuff, &pItem->_iPLMag); - CopyInt(tbuff, &pItem->_iPLDex); - CopyInt(tbuff, &pItem->_iPLVit); - CopyInt(tbuff, &pItem->_iPLFR); - CopyInt(tbuff, &pItem->_iPLLR); - CopyInt(tbuff, &pItem->_iPLMR); - CopyInt(tbuff, &pItem->_iPLMana); - CopyInt(tbuff, &pItem->_iPLHP); - CopyInt(tbuff, &pItem->_iPLDamMod); - CopyInt(tbuff, &pItem->_iPLGetHit); - CopyInt(tbuff, &pItem->_iPLLight); - CopyChar(tbuff, &pItem->_iSplLvlAdd); - CopyChar(tbuff, &pItem->_iRequest); - tbuff += 2; - CopyInt(tbuff, &pItem->_iUid); - CopyInt(tbuff, &pItem->_iFMinDam); - CopyInt(tbuff, &pItem->_iFMaxDam); - CopyInt(tbuff, &pItem->_iLMinDam); - CopyInt(tbuff, &pItem->_iLMaxDam); - CopyInt(tbuff, &pItem->_iPLEnAc); - CopyChar(tbuff, &pItem->_iPrePower); - CopyChar(tbuff, &pItem->_iSufPower); - tbuff += 2; - CopyInt(tbuff, &pItem->_iVAdd1); - CopyInt(tbuff, &pItem->_iVMult1); - CopyInt(tbuff, &pItem->_iVAdd2); - CopyInt(tbuff, &pItem->_iVMult2); - CopyChar(tbuff, &pItem->_iMinStr); - CopyChar(tbuff, &pItem->_iMinMag); - CopyChar(tbuff, &pItem->_iMinDex); - tbuff += 1; - CopyInt(tbuff, &pItem->_iStatFlag); - CopyInt(tbuff, &pItem->IDidx); - CopyInt(tbuff, &pItem->offs016C); -} - -void CopyItems(const int n, ItemStruct *pItem) -{ - for (int i = 0; i < n; i++) - { - CopyItem(&pItem[i]); - } -} - -void SaveItem(ItemStruct *pItem) -{ - CopyInt(&pItem->_iSeed, tbuff); - CopyShort(&pItem->_iCreateInfo, tbuff); - tbuff += 2; - CopyInt(&pItem->_itype, tbuff); - CopyInt(&pItem->_ix, tbuff); - CopyInt(&pItem->_iy, tbuff); - CopyInt(&pItem->_iAnimFlag, tbuff); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(&pItem->_iAnimLen, tbuff); - CopyInt(&pItem->_iAnimFrame, tbuff); - CopyInt(&pItem->_iAnimWidth, tbuff); - CopyInt(&pItem->_iAnimWidth2, tbuff); // width 2? - CopyInt(&pItem->_isin, tbuff); // set when item is flagged for deletion, deprecated in 1.02 - CopyChar(&pItem->_iSelFlag, tbuff); - tbuff += 3; - CopyInt(&pItem->_iPostDraw, tbuff); - CopyInt(&pItem->_iIdentified, tbuff); - CopyChar(&pItem->_iMagical, tbuff); - CopyBytes(&pItem->_iName, 64, tbuff); - CopyBytes(&pItem->_iIName, 64, tbuff); - CopyChar(&pItem->_iLoc, tbuff); - CopyChar(&pItem->_iClass, tbuff); - tbuff += 1; - CopyInt(&pItem->_iCurs, tbuff); - CopyInt(&pItem->_ivalue, tbuff); - CopyInt(&pItem->_iIvalue, tbuff); - CopyInt(&pItem->_iMinDam, tbuff); - CopyInt(&pItem->_iMaxDam, tbuff); - CopyInt(&pItem->_iAC, tbuff); - CopyInt(&pItem->_iFlags, tbuff); - CopyInt(&pItem->_iMiscId, tbuff); - CopyInt(&pItem->_iSpell, tbuff); - CopyInt(&pItem->_iCharges, tbuff); - CopyInt(&pItem->_iMaxCharges, tbuff); - CopyInt(&pItem->_iDurability, tbuff); - CopyInt(&pItem->_iMaxDur, tbuff); - CopyInt(&pItem->_iPLDam, tbuff); - CopyInt(&pItem->_iPLToHit, tbuff); - CopyInt(&pItem->_iPLAC, tbuff); - CopyInt(&pItem->_iPLStr, tbuff); - CopyInt(&pItem->_iPLMag, tbuff); - CopyInt(&pItem->_iPLDex, tbuff); - CopyInt(&pItem->_iPLVit, tbuff); - CopyInt(&pItem->_iPLFR, tbuff); - CopyInt(&pItem->_iPLLR, tbuff); - CopyInt(&pItem->_iPLMR, tbuff); - CopyInt(&pItem->_iPLMana, tbuff); - CopyInt(&pItem->_iPLHP, tbuff); - CopyInt(&pItem->_iPLDamMod, tbuff); - CopyInt(&pItem->_iPLGetHit, tbuff); - CopyInt(&pItem->_iPLLight, tbuff); - CopyChar(&pItem->_iSplLvlAdd, tbuff); - CopyChar(&pItem->_iRequest, tbuff); - tbuff += 2; - CopyInt(&pItem->_iUid, tbuff); - CopyInt(&pItem->_iFMinDam, tbuff); - CopyInt(&pItem->_iFMaxDam, tbuff); - CopyInt(&pItem->_iLMinDam, tbuff); - CopyInt(&pItem->_iLMaxDam, tbuff); - CopyInt(&pItem->_iPLEnAc, tbuff); - CopyChar(&pItem->_iPrePower, tbuff); - CopyChar(&pItem->_iSufPower, tbuff); - tbuff += 2; - CopyInt(&pItem->_iVAdd1, tbuff); - CopyInt(&pItem->_iVMult1, tbuff); - CopyInt(&pItem->_iVAdd2, tbuff); - CopyInt(&pItem->_iVMult2, tbuff); - CopyChar(&pItem->_iMinStr, tbuff); - CopyChar(&pItem->_iMinMag, tbuff); - CopyChar(&pItem->_iMinDex, tbuff); - tbuff += 1; - CopyInt(&pItem->_iStatFlag, tbuff); - CopyInt(&pItem->IDidx, tbuff); - CopyInt(&pItem->offs016C, tbuff); -} - -void SaveItems(ItemStruct *pItem, const int n) -{ - for (int i = 0; i < n; i++) - { - SaveItem(&pItem[i]); - } -} - -void LoadPremium(int i) -{ - CopyItem(&item[i]); -} - -void LoadQuest(int i) -{ - memcpy(&quests[i], tbuff, sizeof(*quests)); - tbuff += sizeof(*quests); - ReturnLvlX = WLoad(); - ReturnLvlY = WLoad(); - ReturnLvl = WLoad(); - ReturnLvlT = WLoad(); - DoomQuestState = WLoad(); -} - -void LoadLighting(int i) -{ - memcpy(&LightList[i], tbuff, sizeof(*LightList)); - tbuff += sizeof(*LightList); -} - -void LoadVision(int i) -{ - memcpy(&VisionList[i], tbuff, sizeof(*VisionList)); - tbuff += sizeof(*VisionList); -} - -void LoadPortal(int i) -{ - memcpy(&portal[i], tbuff, sizeof(*portal)); - tbuff += sizeof(*portal); -} - -void SaveGame() -{ - int i, j; - char szName[MAX_PATH]; - - DWORD dwLen = codec_get_encoded_len(FILEBUFF); - BYTE *SaveBuff = DiabloAllocPtr(dwLen); - tbuff = SaveBuff; - - ISave('RETL'); - OSave((unsigned char)setlevel); - WSave(setlvlnum); - WSave(currlevel); - WSave((unsigned char)leveltype); - WSave(ViewX); - WSave(ViewY); - OSave(invflag); - OSave(chrflag); - WSave(nummonsters); - WSave(numitems); - WSave(nummissiles); - WSave(nobjects); - - for (i = 0; i < NUMLEVELS; i++) { - ISave(glSeedTbl[i]); - WSave(gnLevelTypeTbl[i]); - } - - SavePlayer(myplr); - - for (i = 0; i < MAXQUESTS; i++) - SaveQuest(i); - for (i = 0; i < MAXPORTAL; i++) - SavePortal(i); - for (i = 0; i < MAXMONSTERS; i++) - ISave(monstkills[i]); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - WSave(monstactive[i]); - for (i = 0; i < nummonsters; i++) - SaveMonster(monstactive[i]); - for (i = 0; i < MAXMISSILES; i++) - BSave(missileactive[i]); - for (i = 0; i < MAXMISSILES; i++) - BSave(missileavail[i]); - for (i = 0; i < nummissiles; i++) - SaveMissile(missileactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - BSave(objectactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - BSave(objectavail[i]); - for (i = 0; i < nobjects; i++) - SaveObject(objectactive[i]); - - WSave(numlights); - - for (i = 0; i < MAXLIGHTS; i++) - BSave(lightactive[i]); - for (i = 0; i < numlights; i++) - SaveLighting(lightactive[i]); - - WSave(visionid); - WSave(numvision); - - for (i = 0; i < numvision; i++) - SaveVision(i); - } - - for (i = 0; i < MAXITEMS; i++) - BSave(itemactive[i]); - for (i = 0; i < MAXITEMS; i++) - BSave(itemavail[i]); - for (i = 0; i < numitems; i++) - SaveItem(&item[itemactive[i]]); - for (i = 0; i < 128; i++) - OSave(UniqueItemFlag[i]); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dPlayer[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dItem[i][j]); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - WSave(dMonster[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dDead[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dObject[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dPreLight[i][j]); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - OSave(automapview[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dMissile[i][j]); - } - } - - WSave(numpremium); - WSave(premiumlevel); - - for (i = 0; i < 6; i++) - SavePremium(i); - - OSave(automapflag); - WSave(AutoMapScale); - pfile_get_game_name(szName); - dwLen = codec_get_encoded_len(tbuff - SaveBuff); - pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); - mem_free_dbg(SaveBuff); - gbValidSaveFile = TRUE; - pfile_rename_temp_to_perm(); - pfile_write_hero(); -} - -void BSave(char v) -{ - *tbuff++ = v; -} - -void WSave(int v) -{ - *tbuff++ = v >> 24; - *tbuff++ = v >> 16; - *tbuff++ = v >> 8; - *tbuff++ = v; -} - -void ISave(int v) -{ - *tbuff++ = v >> 24; - *tbuff++ = v >> 16; - *tbuff++ = v >> 8; - *tbuff++ = v; -} - -void OSave(BOOL v) -{ - if (v != FALSE) - *tbuff++ = TRUE; - else - *tbuff++ = FALSE; -} - -void SaveMonster(int i) -{ - MonsterStruct *pMonster = &monster[i]; - - CopyInt(&pMonster->_mMTidx, tbuff); - CopyInt(&pMonster->_mmode, tbuff); - - CopyChar(&pMonster->_mgoal, tbuff); - tbuff += 3; - - CopyInt(&pMonster->_mgoalvar1, tbuff); - CopyInt(&pMonster->_mgoalvar2, tbuff); - CopyInt(&pMonster->_mgoalvar3, tbuff); - CopyInt(&pMonster->field_18, tbuff); - - CopyChar(&pMonster->_pathcount, tbuff); - tbuff += 3; - - CopyInt(&pMonster->_mx, tbuff); - CopyInt(&pMonster->_my, tbuff); - CopyInt(&pMonster->_mfutx, tbuff); - CopyInt(&pMonster->_mfuty, tbuff); - CopyInt(&pMonster->_moldx, tbuff); - CopyInt(&pMonster->_moldy, tbuff); - CopyInt(&pMonster->_mxoff, tbuff); - CopyInt(&pMonster->_myoff, tbuff); - CopyInt(&pMonster->_mxvel, tbuff); - CopyInt(&pMonster->_myvel, tbuff); - CopyInt(&pMonster->_mdir, tbuff); - CopyInt(&pMonster->_menemy, tbuff); - - CopyChar(&pMonster->_menemyx, tbuff); - CopyChar(&pMonster->_menemyy, tbuff); - CopyShort(&pMonster->falign_52, tbuff); - - tbuff += 4; // Skip pointer - CopyInt(&pMonster->_mAnimDelay, tbuff); - CopyInt(&pMonster->_mAnimCnt, tbuff); - CopyInt(&pMonster->_mAnimLen, tbuff); - CopyInt(&pMonster->_mAnimFrame, tbuff); - CopyInt(&pMonster->_meflag, tbuff); - CopyInt(&pMonster->_mDelFlag, tbuff); - CopyInt(&pMonster->_mVar1, tbuff); - CopyInt(&pMonster->_mVar2, tbuff); - CopyInt(&pMonster->_mVar3, tbuff); - CopyInt(&pMonster->_mVar4, tbuff); - CopyInt(&pMonster->_mVar5, tbuff); - CopyInt(&pMonster->_mVar6, tbuff); - CopyInt(&pMonster->_mVar7, tbuff); - CopyInt(&pMonster->_mVar8, tbuff); - CopyInt(&pMonster->_mmaxhp, tbuff); - CopyInt(&pMonster->_mhitpoints, tbuff); - - CopyChar(&pMonster->_mAi, tbuff); - CopyChar(&pMonster->_mint, tbuff); - CopyShort(&pMonster->falign_9A, tbuff); - - CopyInt(&pMonster->_mFlags, tbuff); - - CopyChar(&pMonster->_msquelch, tbuff); - tbuff += 3; - - CopyInt(&pMonster->falign_A4, tbuff); - CopyInt(&pMonster->_lastx, tbuff); - CopyInt(&pMonster->_lasty, tbuff); - CopyInt(&pMonster->_mRndSeed, tbuff); - CopyInt(&pMonster->_mAISeed, tbuff); - CopyInt(&pMonster->falign_B8, tbuff); - - CopyChar(&pMonster->_uniqtype, tbuff); - CopyChar(&pMonster->_uniqtrans, tbuff); - CopyChar(&pMonster->_udeadval, tbuff); - CopyChar(&pMonster->mWhoHit, tbuff); - - CopyChar(&pMonster->mLevel, tbuff); - CopyShort(&pMonster->mExp, tbuff); - tbuff += 1; - - CopyChar(&pMonster->mHit, tbuff); - CopyChar(&pMonster->mMinDamage, tbuff); - CopyChar(&pMonster->mMaxDamage, tbuff); - CopyChar(&pMonster->mHit2, tbuff); - - CopyChar(&pMonster->mMinDamage2, tbuff); - CopyChar(&pMonster->mMaxDamage2, tbuff); - CopyChar(&pMonster->mArmorClass, tbuff); - CopyChar(&pMonster->falign_CB, tbuff); - - CopyShort(&pMonster->mMagicRes, tbuff); - tbuff += 2; - - CopyInt(&pMonster->mtalkmsg, tbuff); - - CopyChar(&pMonster->leader, tbuff); - CopyChar(&pMonster->leaderflag, tbuff); - CopyChar(&pMonster->packsize, tbuff); - CopyChar(&pMonster->mlid, tbuff); -} - -void SaveMissile(int i) -{ - MissileStruct *pMissile = &missile[i]; - - CopyInt(&pMissile->_mitype, tbuff); - CopyInt(&pMissile->_mix, tbuff); - CopyInt(&pMissile->_miy, tbuff); - CopyInt(&pMissile->_mixoff, tbuff); - CopyInt(&pMissile->_miyoff, tbuff); - CopyInt(&pMissile->_mixvel, tbuff); - CopyInt(&pMissile->_miyvel, tbuff); - CopyInt(&pMissile->_misx, tbuff); - CopyInt(&pMissile->_misy, tbuff); - CopyInt(&pMissile->_mitxoff, tbuff); - CopyInt(&pMissile->_mityoff, tbuff); - CopyInt(&pMissile->_mimfnum, tbuff); - CopyInt(&pMissile->_mispllvl, tbuff); - CopyInt(&pMissile->_miDelFlag, tbuff); - CopyChar(&pMissile->_miAnimType, tbuff); - tbuff += 3; - - CopyInt(&pMissile->_miAnimFlags, tbuff); - tbuff += 4; - CopyInt(&pMissile->_miAnimDelay, tbuff); - CopyInt(&pMissile->_miAnimLen, tbuff); - CopyInt(&pMissile->_miAnimWidth, tbuff); - CopyInt(&pMissile->_miAnimWidth2, tbuff); - CopyInt(&pMissile->_miAnimCnt, tbuff); - CopyInt(&pMissile->_miAnimAdd, tbuff); - CopyInt(&pMissile->_miAnimFrame, tbuff); - CopyInt(&pMissile->_miDrawFlag, tbuff); - CopyInt(&pMissile->_miLightFlag, tbuff); - CopyInt(&pMissile->_miPreFlag, tbuff); - CopyInt(&pMissile->_miUniqTrans, tbuff); - CopyInt(&pMissile->_mirange, tbuff); - CopyInt(&pMissile->_misource, tbuff); - CopyInt(&pMissile->_micaster, tbuff); - CopyInt(&pMissile->_midam, tbuff); - CopyInt(&pMissile->_miHitFlag, tbuff); - CopyInt(&pMissile->_midist, tbuff); - CopyInt(&pMissile->_mlid, tbuff); - CopyInt(&pMissile->_mirnd, tbuff); - CopyInt(&pMissile->_miVar1, tbuff); - CopyInt(&pMissile->_miVar2, tbuff); - CopyInt(&pMissile->_miVar3, tbuff); - CopyInt(&pMissile->_miVar4, tbuff); - CopyInt(&pMissile->_miVar5, tbuff); - CopyInt(&pMissile->_miVar6, tbuff); - CopyInt(&pMissile->_miVar7, tbuff); - CopyInt(&pMissile->_miVar8, tbuff); -} - -void SaveObject(int i) -{ - ObjectStruct *pObject = &object[i]; - CopyInt(tbuff, &pObject->_otype); - CopyInt(&pObject->_ox, tbuff); - CopyInt(&pObject->_oy, tbuff); - CopyInt(&pObject->_oLight, tbuff); - CopyInt(&pObject->_oAnimFlag, tbuff); - tbuff += 4; - CopyInt(&pObject->_oAnimDelay, tbuff); - CopyInt(&pObject->_oAnimCnt, tbuff); - CopyInt(&pObject->_oAnimLen, tbuff); - CopyInt(&pObject->_oAnimFrame, tbuff); - CopyInt(&pObject->_oAnimWidth, tbuff); - CopyInt(&pObject->_oAnimWidth2, tbuff); - CopyInt(&pObject->_oDelFlag, tbuff); - - CopyChar(&pObject->_oBreak, tbuff); - tbuff += 3; - - CopyInt(&pObject->_oSolidFlag, tbuff); - CopyInt(&pObject->_oMissFlag, tbuff); - - CopyChar(&pObject->_oSelFlag, tbuff); - tbuff += 3; - - CopyInt(&pObject->_oPreFlag, tbuff); - CopyInt(&pObject->_oTrapFlag, tbuff); - CopyInt(&pObject->_oDoorFlag, tbuff); - CopyInt(&pObject->_olid, tbuff); - CopyInt(&pObject->_oRndSeed, tbuff); - CopyInt(&pObject->_oVar1, tbuff); - CopyInt(&pObject->_oVar2, tbuff); - CopyInt(&pObject->_oVar3, tbuff); - CopyInt(&pObject->_oVar4, tbuff); - CopyInt(&pObject->_oVar5, tbuff); - CopyInt(&pObject->_oVar6, tbuff); - CopyInt(&pObject->_oVar7, tbuff); - CopyInt(&pObject->_oVar8, tbuff); -} - -void SavePremium(int i) -{ - SaveItem(&item[i]); -} - -void SaveQuest(int i) -{ - memcpy(tbuff, &quests[i], sizeof(*quests)); - tbuff += sizeof(*quests); - WSave(ReturnLvlX); - WSave(ReturnLvlY); - WSave(ReturnLvl); - WSave(ReturnLvlT); - WSave(DoomQuestState); -} - -void SaveLighting(int i) -{ - memcpy(tbuff, &LightList[i], sizeof(*LightList)); - tbuff += sizeof(*LightList); -} - -void SaveVision(int i) -{ - memcpy(tbuff, &VisionList[i], sizeof(*VisionList)); - tbuff += sizeof(*VisionList); -} - -void SavePortal(int i) -{ - memcpy(tbuff, &portal[i], sizeof(*portal)); - tbuff += sizeof(*portal); -} - -void SaveLevel() -{ - int i, j; - char szName[MAX_PATH]; - int dwLen; - unsigned char *SaveBuff; - - if (!currlevel) - glSeedTbl[0] = GetRndSeed(); - - dwLen = codec_get_encoded_len(FILEBUFF); - SaveBuff = DiabloAllocPtr(dwLen); - tbuff = SaveBuff; - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dDead[i][j]); - } - } - - WSave(nummonsters); - WSave(numitems); - WSave(nobjects); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - WSave(monstactive[i]); - for (i = 0; i < nummonsters; i++) - SaveMonster(monstactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - BSave(objectactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - BSave(objectavail[i]); - for (i = 0; i < nobjects; i++) - SaveObject(objectactive[i]); - } - - for (i = 0; i < MAXITEMS; i++) - BSave(itemactive[i]); - for (i = 0; i < MAXITEMS; i++) - BSave(itemavail[i]); - for (i = 0; i < numitems; i++) - SaveItem(&item[itemactive[i]]); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dItem[i][j]); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - WSave(dMonster[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dObject[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dPreLight[i][j]); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - OSave(automapview[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dMissile[i][j]); - } - } - - GetTempLevelNames(szName); - dwLen = codec_get_encoded_len(tbuff - SaveBuff); - pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); - mem_free_dbg(SaveBuff); - - if (setlevel == 0) - plr[myplr]._pLvlVisited[currlevel] = 1; - else - plr[myplr]._pSLvlVisited[setlvlnum] = 1; -} - -void LoadLevel() -{ - int i, j; - DWORD dwLen; - char szName[MAX_PATH]; - BYTE *LoadBuff; - - GetPermLevelNames(szName); - LoadBuff = pfile_read(szName, &dwLen); - tbuff = LoadBuff; - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dDead[i][j] = BLoad(); - } - SetDead(); - } - - nummonsters = WLoad(); - numitems = WLoad(); - nobjects = WLoad(); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - monstactive[i] = WLoad(); - for (i = 0; i < nummonsters; i++) - LoadMonster(monstactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - objectactive[i] = BLoad(); - for (i = 0; i < MAXOBJECTS; i++) - objectavail[i] = BLoad(); - for (i = 0; i < nobjects; i++) - LoadObject(objectactive[i]); - for (i = 0; i < nobjects; i++) - SyncObjectAnim(objectactive[i]); - } - - for (i = 0; i < MAXITEMS; i++) - itemactive[i] = BLoad(); - for (i = 0; i < MAXITEMS; i++) - itemavail[i] = BLoad(); - for (i = 0; i < numitems; i++) - LoadItem(itemactive[i]); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dFlags[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dItem[i][j] = BLoad(); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMonster[i][j] = WLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dObject[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPreLight[i][j] = BLoad(); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - automapview[i][j] = OLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMissile[i][j] = 0; /// BUGFIX: supposed to load saved missiles with "BLoad()"? - } - } - - AutomapZoomReset(); - ResyncQuests(); - SyncPortals(); - dolighting = 1; - - for (i = 0; i < MAX_PLRS; i++) { - if (plr[i].plractive && currlevel == plr[i].plrlevel) - LightList[plr[i]._plid]._lunflag = 1; - } - - mem_free_dbg(LoadBuff); -} - -DEVILUTION_END_NAMESPACE +#include "diablo.h" + +DEVILUTION_BEGIN_NAMESPACE + +BYTE *tbuff; + +void LoadGame(BOOL firstflag) +{ + int i, j; + DWORD dwLen; + char szName[MAX_PATH]; + BYTE *LoadBuff; + int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects; + + FreeGameMem(); + pfile_remove_temp_files(); + pfile_get_game_name(szName); + LoadBuff = pfile_read(szName, &dwLen); + tbuff = LoadBuff; + + if (ILoad() != 'RETL') + app_fatal("Invalid save file"); + + setlevel = OLoad(); + setlvlnum = WLoad(); + currlevel = WLoad(); + leveltype = WLoad(); + _ViewX = WLoad(); + _ViewY = WLoad(); + invflag = OLoad(); + chrflag = OLoad(); + _nummonsters = WLoad(); + _numitems = WLoad(); + _nummissiles = WLoad(); + _nobjects = WLoad(); + + for (i = 0; i < NUMLEVELS; i++) { + glSeedTbl[i] = ILoad(); + gnLevelTypeTbl[i] = WLoad(); + } + + LoadPlayer(myplr); + + for (i = 0; i < MAXQUESTS; i++) + LoadQuest(i); + for (i = 0; i < MAXPORTAL; i++) + LoadPortal(i); + + LoadGameLevel(firstflag, 4); + SyncInitPlr(myplr); + SyncPlrAnim(myplr); + + ViewX = _ViewX; + ViewY = _ViewY; + nummonsters = _nummonsters; + numitems = _numitems; + nummissiles = _nummissiles; + nobjects = _nobjects; + + for (i = 0; i < MAXMONSTERS; i++) + monstkills[i] = ILoad(); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + monstactive[i] = WLoad(); + for (i = 0; i < nummonsters; i++) + LoadMonster(monstactive[i]); + for (i = 0; i < MAXMISSILES; i++) + missileactive[i] = BLoad(); + for (i = 0; i < MAXMISSILES; i++) + missileavail[i] = BLoad(); + for (i = 0; i < nummissiles; i++) + LoadMissile(missileactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + objectactive[i] = BLoad(); + for (i = 0; i < MAXOBJECTS; i++) + objectavail[i] = BLoad(); + for (i = 0; i < nobjects; i++) + LoadObject(objectactive[i]); + for (i = 0; i < nobjects; i++) + SyncObjectAnim(objectactive[i]); + + numlights = WLoad(); + + for (i = 0; i < MAXLIGHTS; i++) + lightactive[i] = BLoad(); + for (i = 0; i < numlights; i++) + LoadLighting(lightactive[i]); + + visionid = WLoad(); + numvision = WLoad(); + + for (i = 0; i < numvision; i++) + LoadVision(i); + } + + for (i = 0; i < MAXITEMS; i++) + itemactive[i] = BLoad(); + for (i = 0; i < MAXITEMS; i++) + itemavail[i] = BLoad(); + for (i = 0; i < numitems; i++) + LoadItem(itemactive[i]); + for (i = 0; i < 128; i++) + UniqueItemFlag[i] = OLoad(); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dLight[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dFlags[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dPlayer[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dItem[i][j] = BLoad(); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dMonster[i][j] = WLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dDead[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dObject[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dLight[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dPreLight[i][j] = BLoad(); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + automapview[i][j] = OLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dMissile[i][j] = BLoad(); + } + } + + numpremium = WLoad(); + premiumlevel = WLoad(); + + for (i = 0; i < 6; i++) + LoadPremium(i); + + automapflag = OLoad(); + AutoMapScale = WLoad(); + mem_free_dbg(LoadBuff); + AutomapZoomReset(); + ResyncQuests(); + + if (leveltype != DTYPE_TOWN) + ProcessLightList(); + + RedoPlayerVision(); + ProcessVisionList(); + missiles_process_charge(); + ResetPal(); + SetCursor_(CURSOR_HAND); + gbProcessPlayers = TRUE; +} + +char BLoad() +{ + return *tbuff++; +} + +int WLoad() +{ + int rv = *tbuff++ << 24; + rv |= *tbuff++ << 16; + rv |= *tbuff++ << 8; + rv |= *tbuff++; + + return rv; +} + +int ILoad() +{ + int rv = *tbuff++ << 24; + rv |= *tbuff++ << 16; + rv |= *tbuff++ << 8; + rv |= *tbuff++; + + return rv; +} + +BOOL OLoad() +{ + if (*tbuff++ == TRUE) + return TRUE; + else + return FALSE; +} + +void CopyInt(const void *src, void *dst) +{ + memcpy(dst, src, 4); + tbuff += 4; +} + +void CopyShort(const void *src, void *dst) +{ + memcpy(dst, src, 2); + tbuff += 2; +} + +void CopyShorts(const void *src, const int n, void *dst) +{ + memcpy(dst, src, 2 * n); + tbuff += 2 * n; +} + +void CopyInts(const void *src, const int n, void *dst) +{ + memcpy(dst, src, 4 * n); + tbuff += 4 * n; +} + +void CopyBytes(const void *src, const int n, void *dst) +{ + memcpy(dst, src, n); + tbuff += n; +} + +void CopyChar(const void *src, void *dst) +{ + memcpy(dst, src, 1); + tbuff += 1; +} + +void CopyInt64(const void *src, void *dst) +{ + memcpy(dst, src, 8); + tbuff += 8; +} + +void LoadPlayer(int i) +{ + PlayerStruct *pPlayer = &plr[i]; + + CopyInt(tbuff, &pPlayer->_pmode); + + CopyBytes(tbuff, 25, pPlayer->walkpath); + CopyBytes(tbuff, 1, &pPlayer->plractive); + tbuff += 2; + + CopyInt(tbuff, &pPlayer->destAction); + CopyInt(tbuff, &pPlayer->destParam1); + CopyInt(tbuff, &pPlayer->destParam2); + CopyInt(tbuff, &pPlayer->destParam3); + CopyInt(tbuff, &pPlayer->destParam4); + CopyInt(tbuff, &pPlayer->plrlevel); + CopyInt(tbuff, &pPlayer->WorldX); + CopyInt(tbuff, &pPlayer->WorldY); + CopyInt(tbuff, &pPlayer->_px); + CopyInt(tbuff, &pPlayer->_py); + CopyInt(tbuff, &pPlayer->_ptargx); + CopyInt(tbuff, &pPlayer->_ptargy); + CopyInt(tbuff, &pPlayer->_pownerx); + CopyInt(tbuff, &pPlayer->_pownery); + CopyInt(tbuff, &pPlayer->_poldx); + CopyInt(tbuff, &pPlayer->_poldy); + CopyInt(tbuff, &pPlayer->_pxoff); + CopyInt(tbuff, &pPlayer->_pyoff); + CopyInt(tbuff, &pPlayer->_pxvel); + CopyInt(tbuff, &pPlayer->_pyvel); + CopyInt(tbuff, &pPlayer->_pdir); + CopyInt(tbuff, &pPlayer->_nextdir); + CopyInt(tbuff, &pPlayer->_pgfxnum); + tbuff += 4; // Skip pointers + CopyInt(tbuff, &pPlayer->_pAnimDelay); + CopyInt(tbuff, &pPlayer->_pAnimCnt); + CopyInt(tbuff, &pPlayer->_pAnimLen); + CopyInt(tbuff, &pPlayer->_pAnimFrame); + CopyInt(tbuff, &pPlayer->_pAnimWidth); + CopyInt(tbuff, &pPlayer->_pAnimWidth2); + CopyInt(tbuff, &pPlayer->_peflag); + CopyInt(tbuff, &pPlayer->_plid); + CopyInt(tbuff, &pPlayer->_pvid); + + CopyInt(tbuff, &pPlayer->_pSpell); + CopyChar(tbuff, &pPlayer->_pSplType); + CopyChar(tbuff, &pPlayer->_pSplFrom); + tbuff += 2; + CopyInt(tbuff, &pPlayer->_pTSpell); + CopyChar(tbuff, &pPlayer->_pTSplType); + tbuff += 3; + CopyInt(tbuff, &pPlayer->_pRSpell); + CopyChar(tbuff, &pPlayer->_pRSplType); + tbuff += 3; + CopyInt(tbuff, &pPlayer->_pSBkSpell); + CopyChar(tbuff, &pPlayer->_pSBkSplType); + + CopyBytes(tbuff, 64, &pPlayer->_pSplLvl); + tbuff += 7; + CopyInt64(tbuff, &pPlayer->_pMemSpells); + CopyInt64(tbuff, &pPlayer->_pAblSpells); + CopyInt64(tbuff, &pPlayer->_pScrlSpells); + CopyChar(tbuff, &pPlayer->_pSpellFlags); + tbuff += 3; + CopyInts(tbuff, 4, &pPlayer->_pSplHotKey); + CopyBytes(tbuff, 4, &pPlayer->_pSplTHotKey); + CopyInt(tbuff, &pPlayer->_pwtype); + CopyChar(tbuff, &pPlayer->_pBlockFlag); + CopyChar(tbuff, &pPlayer->_pInvincible); + CopyChar(tbuff, &pPlayer->_pLightRad); + CopyChar(tbuff, &pPlayer->_pLvlChanging); + CopyBytes(tbuff, PLR_NAME_LEN, &pPlayer->_pName); + CopyChar(tbuff, &pPlayer->_pClass); + tbuff += 3; + CopyInt(tbuff, &pPlayer->_pStrength); + CopyInt(tbuff, &pPlayer->_pBaseStr); + CopyInt(tbuff, &pPlayer->_pMagic); + CopyInt(tbuff, &pPlayer->_pBaseMag); + CopyInt(tbuff, &pPlayer->_pDexterity); + CopyInt(tbuff, &pPlayer->_pBaseDex); + CopyInt(tbuff, &pPlayer->_pVitality); + CopyInt(tbuff, &pPlayer->_pBaseVit); + CopyInt(tbuff, &pPlayer->_pStatPts); + CopyInt(tbuff, &pPlayer->_pDamageMod); + CopyInt(tbuff, &pPlayer->_pBaseToBlk); + CopyInt(tbuff, &pPlayer->_pHPBase); + CopyInt(tbuff, &pPlayer->_pMaxHPBase); + CopyInt(tbuff, &pPlayer->_pHitPoints); + CopyInt(tbuff, &pPlayer->_pMaxHP); + CopyInt(tbuff, &pPlayer->_pHPPer); + CopyInt(tbuff, &pPlayer->_pManaBase); + CopyInt(tbuff, &pPlayer->_pMaxManaBase); + CopyInt(tbuff, &pPlayer->_pMana); + CopyInt(tbuff, &pPlayer->_pMaxMana); + CopyInt(tbuff, &pPlayer->_pManaPer); + CopyChar(tbuff, &pPlayer->_pLevel); + CopyChar(tbuff, &pPlayer->_pMaxLvl); + tbuff += 2; + CopyInt(tbuff, &pPlayer->_pExperience); + CopyInt(tbuff, &pPlayer->_pMaxExp); + CopyInt(tbuff, &pPlayer->_pNextExper); + CopyChar(tbuff, &pPlayer->_pArmorClass); + CopyChar(tbuff, &pPlayer->_pMagResist); + CopyChar(tbuff, &pPlayer->_pFireResist); + CopyChar(tbuff, &pPlayer->_pLghtResist); + CopyInt(tbuff, &pPlayer->_pGold); + CopyInt(tbuff, &pPlayer->_pInfraFlag); + CopyInt(tbuff, &pPlayer->_pVar1); + CopyInt(tbuff, &pPlayer->_pVar2); + CopyInt(tbuff, &pPlayer->_pVar3); + CopyInt(tbuff, &pPlayer->_pVar4); + CopyInt(tbuff, &pPlayer->_pVar5); + CopyInt(tbuff, &pPlayer->_pVar6); + CopyInt(tbuff, &pPlayer->_pVar7); + CopyInt(tbuff, &pPlayer->_pVar8); + CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pLvlVisited); + CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pSLvlVisited); + tbuff += 2; + CopyInt(tbuff, &pPlayer->_pGFXLoad); + + tbuff += sizeof(__uint32_t) * 8; + CopyInt(tbuff, &pPlayer->_pNFrames); + CopyInt(tbuff, &pPlayer->_pNWidth); + + tbuff += sizeof(__uint32_t) * 8; + + CopyInt(tbuff, &pPlayer->_pWFrames); + CopyInt(tbuff, &pPlayer->_pWWidth); + + tbuff += sizeof(__uint32_t) * 8; + + CopyInt(tbuff, &pPlayer->_pAFrames); + CopyInt(tbuff, &pPlayer->_pAWidth); + CopyInt(tbuff, &pPlayer->_pAFNum); + + tbuff += sizeof(__uint32_t) * 24; + + CopyInt(tbuff, &pPlayer->_pSFrames); + CopyInt(tbuff, &pPlayer->_pSWidth); + CopyInt(tbuff, &pPlayer->_pSFNum); + + tbuff += sizeof(__uint32_t) * 8; + + CopyInt(tbuff, &pPlayer->_pHFrames); + CopyInt(tbuff, &pPlayer->_pHWidth); + + tbuff += sizeof(__uint32_t) * 8; + + CopyInt(tbuff, &pPlayer->_pDFrames); + CopyInt(tbuff, &pPlayer->_pDWidth); + + tbuff += sizeof(__uint32_t) * 8; + + CopyInt(tbuff, &pPlayer->_pBFrames); + CopyInt(tbuff, &pPlayer->_pBWidth); + CopyItems(NUM_INVLOC, pPlayer->InvBody); + CopyItems(NUM_INV_GRID_ELEM, pPlayer->InvList); + CopyInt(tbuff, &pPlayer->_pNumInv); + CopyBytes(tbuff, NUM_INV_GRID_ELEM, pPlayer->InvGrid); + CopyItems(MAXBELTITEMS, pPlayer->SpdList); + CopyItem(&pPlayer->HoldItem); + CopyInt(tbuff, &pPlayer->_pIMinDam); + CopyInt(tbuff, &pPlayer->_pIMaxDam); + CopyInt(tbuff, &pPlayer->_pIAC); + CopyInt(tbuff, &pPlayer->_pIBonusDam); + CopyInt(tbuff, &pPlayer->_pIBonusToHit); + CopyInt(tbuff, &pPlayer->_pIBonusAC); + CopyInt(tbuff, &pPlayer->_pIBonusDamMod); + tbuff += 4; + CopyInt64(tbuff, &pPlayer->_pISpells); + CopyInt(tbuff, &pPlayer->_pIFlags); + CopyInt(tbuff, &pPlayer->_pIGetHit); + + CopyChar(tbuff, &pPlayer->_pISplLvlAdd); + CopyChar(tbuff, &pPlayer->_pISplCost); + tbuff += 2; + + CopyInt(tbuff, &pPlayer->_pISplDur); + CopyInt(tbuff, &pPlayer->_pIEnAc); + CopyInt(tbuff, &pPlayer->_pIFMinDam); + CopyInt(tbuff, &pPlayer->_pIFMaxDam); + CopyInt(tbuff, &pPlayer->_pILMinDam); + CopyInt(tbuff, &pPlayer->_pILMaxDam); + CopyInt(tbuff, &pPlayer->_pOilType); + + CopyChar(tbuff, &pPlayer->pTownWarps); + CopyChar(tbuff, &pPlayer->pDungMsgs); + CopyChar(tbuff, &pPlayer->pLvlLoad); + CopyChar(tbuff, &pPlayer->pBattleNet); + + CopyChar(tbuff, &pPlayer->pManaShield); + CopyBytes(tbuff, 3, &pPlayer->bReserved); + + CopyShorts(tbuff, 8, &pPlayer->wReserved); + + CopyInt(tbuff, &pPlayer->pDiabloKillLevel); + CopyInts(tbuff, 7, &pPlayer->dwReserved); + + // Omit 10 pointers +} + +void SavePlayer(int i) +{ + PlayerStruct *pPlayer = &plr[i]; + + CopyInt(&pPlayer->_pmode, tbuff); + + CopyBytes(&pPlayer->walkpath, 25, tbuff); + CopyBytes(&pPlayer->plractive, 1, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->destAction, tbuff); + CopyInt(&pPlayer->destParam1, tbuff); + CopyInt(&pPlayer->destParam2, tbuff); + CopyInt(&pPlayer->destParam3, tbuff); + CopyInt(&pPlayer->destParam4, tbuff); + CopyInt(&pPlayer->plrlevel, tbuff); + CopyInt(&pPlayer->WorldX, tbuff); + CopyInt(&pPlayer->WorldY, tbuff); + CopyInt(&pPlayer->_px, tbuff); + CopyInt(&pPlayer->_py, tbuff); + CopyInt(&pPlayer->_ptargx, tbuff); + CopyInt(&pPlayer->_ptargy, tbuff); + CopyInt(&pPlayer->_pownerx, tbuff); + CopyInt(&pPlayer->_pownery, tbuff); + CopyInt(&pPlayer->_poldx, tbuff); + CopyInt(&pPlayer->_poldy, tbuff); + CopyInt(&pPlayer->_pxoff, tbuff); + CopyInt(&pPlayer->_pyoff, tbuff); + CopyInt(&pPlayer->_pxvel, tbuff); + CopyInt(&pPlayer->_pyvel, tbuff); + CopyInt(&pPlayer->_pdir, tbuff); + CopyInt(&pPlayer->_nextdir, tbuff); + CopyInt(&pPlayer->_pgfxnum, tbuff); + tbuff += 4; // Skip pointers + CopyInt(&pPlayer->_pAnimDelay, tbuff); + CopyInt(&pPlayer->_pAnimCnt, tbuff); + CopyInt(&pPlayer->_pAnimLen, tbuff); + CopyInt(&pPlayer->_pAnimFrame, tbuff); + CopyInt(&pPlayer->_pAnimWidth, tbuff); + CopyInt(&pPlayer->_pAnimWidth2, tbuff); + CopyInt(&pPlayer->_peflag, tbuff); + CopyInt(&pPlayer->_plid, tbuff); + CopyInt(&pPlayer->_pvid, tbuff); + + CopyInt(&pPlayer->_pSpell, tbuff); + + CopyChar(&pPlayer->_pSplType, tbuff); + CopyChar(&pPlayer->_pSplFrom, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->_pTSpell, tbuff); + CopyChar(&pPlayer->_pTSplType, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pRSpell, tbuff); + CopyChar(&pPlayer->_pRSplType, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pSBkSpell, tbuff); + CopyChar(&pPlayer->_pSBkSplType, tbuff); + + CopyBytes(&pPlayer->_pSplLvl, 64, tbuff); + tbuff += 7; + CopyInt64(&pPlayer->_pMemSpells, tbuff); + CopyInt64(&pPlayer->_pAblSpells, tbuff); + CopyInt64(&pPlayer->_pScrlSpells, tbuff); + CopyChar(&pPlayer->_pSpellFlags, tbuff); + tbuff += 3; + CopyInts(&pPlayer->_pSplHotKey, 4, tbuff); + CopyBytes(&pPlayer->_pSplTHotKey, 4, tbuff); + CopyInt(&pPlayer->_pwtype, tbuff); + CopyChar(&pPlayer->_pBlockFlag, tbuff); + CopyChar(&pPlayer->_pInvincible, tbuff); + CopyChar(&pPlayer->_pLightRad, tbuff); + CopyChar(&pPlayer->_pLvlChanging, tbuff); + CopyBytes(&pPlayer->_pName, PLR_NAME_LEN, tbuff); + CopyChar(&pPlayer->_pClass, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pStrength, tbuff); + CopyInt(&pPlayer->_pBaseStr, tbuff); + CopyInt(&pPlayer->_pMagic, tbuff); + CopyInt(&pPlayer->_pBaseMag, tbuff); + CopyInt(&pPlayer->_pDexterity, tbuff); + CopyInt(&pPlayer->_pBaseDex, tbuff); + CopyInt(&pPlayer->_pVitality, tbuff); + CopyInt(&pPlayer->_pBaseVit, tbuff); + CopyInt(&pPlayer->_pStatPts, tbuff); + CopyInt(&pPlayer->_pDamageMod, tbuff); + CopyInt(&pPlayer->_pBaseToBlk, tbuff); + CopyInt(&pPlayer->_pHPBase, tbuff); + CopyInt(&pPlayer->_pMaxHPBase, tbuff); + CopyInt(&pPlayer->_pHitPoints, tbuff); + CopyInt(&pPlayer->_pMaxHP, tbuff); + CopyInt(&pPlayer->_pHPPer, tbuff); + CopyInt(&pPlayer->_pManaBase, tbuff); + CopyInt(&pPlayer->_pMaxManaBase, tbuff); + CopyInt(&pPlayer->_pMana, tbuff); + CopyInt(&pPlayer->_pMaxMana, tbuff); + CopyInt(&pPlayer->_pManaPer, tbuff); + CopyChar(&pPlayer->_pLevel, tbuff); + CopyChar(&pPlayer->_pMaxLvl, tbuff); + tbuff += 2; + CopyInt(&pPlayer->_pExperience, tbuff); + CopyInt(&pPlayer->_pMaxExp, tbuff); + CopyInt(&pPlayer->_pNextExper, tbuff); + CopyChar(&pPlayer->_pArmorClass, tbuff); + CopyChar(&pPlayer->_pMagResist, tbuff); + CopyChar(&pPlayer->_pFireResist, tbuff); + CopyChar(&pPlayer->_pLghtResist, tbuff); + CopyInt(&pPlayer->_pGold, tbuff); + CopyInt(&pPlayer->_pInfraFlag, tbuff); + CopyInt(&pPlayer->_pVar1, tbuff); + CopyInt(&pPlayer->_pVar2, tbuff); + CopyInt(&pPlayer->_pVar3, tbuff); + CopyInt(&pPlayer->_pVar4, tbuff); + CopyInt(&pPlayer->_pVar5, tbuff); + CopyInt(&pPlayer->_pVar6, tbuff); + CopyInt(&pPlayer->_pVar7, tbuff); + CopyInt(&pPlayer->_pVar8, tbuff); + CopyBytes(&pPlayer->_pLvlVisited, NUMLEVELS, tbuff); + CopyBytes(&pPlayer->_pSLvlVisited, NUMLEVELS, tbuff); // only 10 used + tbuff += 2; + CopyInt(&pPlayer->_pGFXLoad, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + CopyInt(&pPlayer->_pNFrames, tbuff); + CopyInt(&pPlayer->_pNWidth, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pWFrames, tbuff); + CopyInt(&pPlayer->_pWWidth, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pAFrames, tbuff); + CopyInt(&pPlayer->_pAWidth, tbuff); + CopyInt(&pPlayer->_pAFNum, tbuff); + + tbuff += sizeof(__uint32_t) * 24; // Skip 24 pointers + + CopyInt(&pPlayer->_pSFrames, tbuff); + CopyInt(&pPlayer->_pSWidth, tbuff); + CopyInt(&pPlayer->_pSFNum, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pHFrames, tbuff); + CopyInt(&pPlayer->_pHWidth, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pDFrames, tbuff); + CopyInt(&pPlayer->_pDWidth, tbuff); + + tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pBFrames, tbuff); + CopyInt(&pPlayer->_pBWidth, tbuff); + SaveItems(pPlayer->InvBody, NUM_INVLOC); + SaveItems(pPlayer->InvList, NUM_INV_GRID_ELEM); + CopyInt(&pPlayer->_pNumInv, tbuff); + CopyBytes(pPlayer->InvGrid, NUM_INV_GRID_ELEM, tbuff); + SaveItems(pPlayer->SpdList, MAXBELTITEMS); + SaveItem(&pPlayer->HoldItem); + CopyInt(&pPlayer->_pIMinDam, tbuff); + CopyInt(&pPlayer->_pIMaxDam, tbuff); + CopyInt(&pPlayer->_pIAC, tbuff); + CopyInt(&pPlayer->_pIBonusDam, tbuff); + CopyInt(&pPlayer->_pIBonusToHit, tbuff); + CopyInt(&pPlayer->_pIBonusAC, tbuff); + CopyInt(&pPlayer->_pIBonusDamMod, tbuff); + tbuff += 4; + CopyInt64(&pPlayer->_pISpells, tbuff); + CopyInt(&pPlayer->_pIFlags, tbuff); + CopyInt(&pPlayer->_pIGetHit, tbuff); + + CopyChar(&pPlayer->_pISplLvlAdd, tbuff); + CopyChar(&pPlayer->_pISplCost, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->_pISplDur, tbuff); + CopyInt(&pPlayer->_pIEnAc, tbuff); + CopyInt(&pPlayer->_pIFMinDam, tbuff); + CopyInt(&pPlayer->_pIFMaxDam, tbuff); + CopyInt(&pPlayer->_pILMinDam, tbuff); + CopyInt(&pPlayer->_pILMaxDam, tbuff); + CopyInt(&pPlayer->_pOilType, tbuff); + + CopyChar(&pPlayer->pTownWarps, tbuff); + CopyChar(&pPlayer->pDungMsgs, tbuff); + CopyChar(&pPlayer->pLvlLoad, tbuff); + CopyChar(&pPlayer->pBattleNet, tbuff); + + CopyChar(&pPlayer->pManaShield, tbuff); + CopyBytes(&pPlayer->bReserved, 3, tbuff); + + CopyShorts(&pPlayer->wReserved, 8, tbuff); + + CopyInt(&pPlayer->pDiabloKillLevel, tbuff); + CopyInts(&pPlayer->dwReserved, 7, tbuff); + + // Omit 10 pointers +} + +void LoadMonster(int i) +{ + MonsterStruct *pMonster = &monster[i]; + + CopyInt(tbuff, &pMonster->_mMTidx); + CopyInt(tbuff, &pMonster->_mmode); + + CopyChar(tbuff, &pMonster->_mgoal); + tbuff += 3; + + CopyInt(tbuff, &pMonster->_mgoalvar1); + CopyInt(tbuff, &pMonster->_mgoalvar2); + CopyInt(tbuff, &pMonster->_mgoalvar3); + CopyInt(tbuff, &pMonster->field_18); + + CopyChar(tbuff, &pMonster->_pathcount); + tbuff += 3; + + CopyInt(tbuff, &pMonster->_mx); + CopyInt(tbuff, &pMonster->_my); + CopyInt(tbuff, &pMonster->_mfutx); + CopyInt(tbuff, &pMonster->_mfuty); + CopyInt(tbuff, &pMonster->_moldx); + CopyInt(tbuff, &pMonster->_moldy); + CopyInt(tbuff, &pMonster->_mxoff); + CopyInt(tbuff, &pMonster->_myoff); + CopyInt(tbuff, &pMonster->_mxvel); + CopyInt(tbuff, &pMonster->_myvel); + CopyInt(tbuff, &pMonster->_mdir); + CopyInt(tbuff, &pMonster->_menemy); + + CopyChar(tbuff, &pMonster->_menemyx); + CopyChar(tbuff, &pMonster->_menemyy); + CopyShort(tbuff, &pMonster->falign_52); + + tbuff += 4; // Skip pointer + CopyInt(tbuff, &pMonster->_mAnimDelay); + CopyInt(tbuff, &pMonster->_mAnimCnt); + CopyInt(tbuff, &pMonster->_mAnimLen); + CopyInt(tbuff, &pMonster->_mAnimFrame); + CopyInt(tbuff, &pMonster->_meflag); + CopyInt(tbuff, &pMonster->_mDelFlag); + CopyInt(tbuff, &pMonster->_mVar1); + CopyInt(tbuff, &pMonster->_mVar2); + CopyInt(tbuff, &pMonster->_mVar3); + CopyInt(tbuff, &pMonster->_mVar4); + CopyInt(tbuff, &pMonster->_mVar5); + CopyInt(tbuff, &pMonster->_mVar6); + CopyInt(tbuff, &pMonster->_mVar7); + CopyInt(tbuff, &pMonster->_mVar8); + CopyInt(tbuff, &pMonster->_mmaxhp); + CopyInt(tbuff, &pMonster->_mhitpoints); + + CopyChar(tbuff, &pMonster->_mAi); + CopyChar(tbuff, &pMonster->_mint); + CopyShort(tbuff, &pMonster->falign_9A); + + CopyInt(tbuff, &pMonster->_mFlags); + + CopyChar(tbuff, &pMonster->_msquelch); + tbuff += 3; + + CopyInt(tbuff, &pMonster->falign_A4); + CopyInt(tbuff, &pMonster->_lastx); + CopyInt(tbuff, &pMonster->_lasty); + CopyInt(tbuff, &pMonster->_mRndSeed); + CopyInt(tbuff, &pMonster->_mAISeed); + CopyInt(tbuff, &pMonster->falign_B8); + + CopyChar(tbuff, &pMonster->_uniqtype); + CopyChar(tbuff, &pMonster->_uniqtrans); + CopyChar(tbuff, &pMonster->_udeadval); + CopyChar(tbuff, &pMonster->mWhoHit); + + CopyChar(tbuff, &pMonster->mLevel); + CopyShort(tbuff, &pMonster->mExp); + tbuff += 1; + + CopyChar(tbuff, &pMonster->mHit); + CopyChar(tbuff, &pMonster->mMinDamage); + CopyChar(tbuff, &pMonster->mMaxDamage); + CopyChar(tbuff, &pMonster->mHit2); + + CopyChar(tbuff, &pMonster->mMinDamage2); + CopyChar(tbuff, &pMonster->mMaxDamage2); + CopyChar(tbuff, &pMonster->mArmorClass); + CopyChar(tbuff, &pMonster->falign_CB); + + CopyShort(tbuff, &pMonster->mMagicRes); + tbuff += 2; + + CopyInt(tbuff, &pMonster->mtalkmsg); + + CopyChar(tbuff, &pMonster->leader); + CopyChar(tbuff, &pMonster->leaderflag); + CopyChar(tbuff, &pMonster->packsize); + CopyChar(tbuff, &pMonster->mlid); + + SyncMonsterAnim(i); +} + +void LoadMissile(int i) +{ + MissileStruct *pMissile = &missile[i]; + + CopyInt(tbuff, &pMissile->_mitype); + CopyInt(tbuff, &pMissile->_mix); + CopyInt(tbuff, &pMissile->_miy); + CopyInt(tbuff, &pMissile->_mixoff); + CopyInt(tbuff, &pMissile->_miyoff); + CopyInt(tbuff, &pMissile->_mixvel); + CopyInt(tbuff, &pMissile->_miyvel); + CopyInt(tbuff, &pMissile->_misx); + CopyInt(tbuff, &pMissile->_misy); + CopyInt(tbuff, &pMissile->_mitxoff); + CopyInt(tbuff, &pMissile->_mityoff); + CopyInt(tbuff, &pMissile->_mimfnum); + CopyInt(tbuff, &pMissile->_mispllvl); + CopyInt(tbuff, &pMissile->_miDelFlag); + CopyChar(tbuff, &pMissile->_miAnimType); + tbuff += 3; + + CopyInt(tbuff, &pMissile->_miAnimFlags); + tbuff += 4; + CopyInt(tbuff, &pMissile->_miAnimDelay); + CopyInt(tbuff, &pMissile->_miAnimLen); + CopyInt(tbuff, &pMissile->_miAnimWidth); + CopyInt(tbuff, &pMissile->_miAnimWidth2); + CopyInt(tbuff, &pMissile->_miAnimCnt); + CopyInt(tbuff, &pMissile->_miAnimAdd); + CopyInt(tbuff, &pMissile->_miAnimFrame); + CopyInt(tbuff, &pMissile->_miDrawFlag); + CopyInt(tbuff, &pMissile->_miLightFlag); + CopyInt(tbuff, &pMissile->_miPreFlag); + CopyInt(tbuff, &pMissile->_miUniqTrans); + CopyInt(tbuff, &pMissile->_mirange); + CopyInt(tbuff, &pMissile->_misource); + CopyInt(tbuff, &pMissile->_micaster); + CopyInt(tbuff, &pMissile->_midam); + CopyInt(tbuff, &pMissile->_miHitFlag); + CopyInt(tbuff, &pMissile->_midist); + CopyInt(tbuff, &pMissile->_mlid); + CopyInt(tbuff, &pMissile->_mirnd); + CopyInt(tbuff, &pMissile->_miVar1); + CopyInt(tbuff, &pMissile->_miVar2); + CopyInt(tbuff, &pMissile->_miVar3); + CopyInt(tbuff, &pMissile->_miVar4); + CopyInt(tbuff, &pMissile->_miVar5); + CopyInt(tbuff, &pMissile->_miVar6); + CopyInt(tbuff, &pMissile->_miVar7); + CopyInt(tbuff, &pMissile->_miVar8); +} + +void LoadObject(int i) +{ + ObjectStruct *pObject = &object[i]; + CopyInt(tbuff, &pObject->_otype); + CopyInt(tbuff, &pObject->_ox); + CopyInt(tbuff, &pObject->_oy); + CopyInt(tbuff, &pObject->_oLight); + CopyInt(tbuff, &pObject->_oAnimFlag); + tbuff += 4; + CopyInt(tbuff, &pObject->_oAnimDelay); + CopyInt(tbuff, &pObject->_oAnimCnt); + CopyInt(tbuff, &pObject->_oAnimLen); + CopyInt(tbuff, &pObject->_oAnimFrame); + CopyInt(tbuff, &pObject->_oAnimWidth); + CopyInt(tbuff, &pObject->_oAnimWidth2); + CopyInt(tbuff, &pObject->_oDelFlag); + + CopyChar(tbuff, &pObject->_oBreak); + tbuff += 3; + + CopyInt(tbuff, &pObject->_oSolidFlag); + CopyInt(tbuff, &pObject->_oMissFlag); + + CopyChar(tbuff, &pObject->_oSelFlag); + tbuff += 3; + + CopyInt(tbuff, &pObject->_oPreFlag); + CopyInt(tbuff, &pObject->_oTrapFlag); + CopyInt(tbuff, &pObject->_oDoorFlag); + CopyInt(tbuff, &pObject->_olid); + CopyInt(tbuff, &pObject->_oRndSeed); + CopyInt(tbuff, &pObject->_oVar1); + CopyInt(tbuff, &pObject->_oVar2); + CopyInt(tbuff, &pObject->_oVar3); + CopyInt(tbuff, &pObject->_oVar4); + CopyInt(tbuff, &pObject->_oVar5); + CopyInt(tbuff, &pObject->_oVar6); + CopyInt(tbuff, &pObject->_oVar7); + CopyInt(tbuff, &pObject->_oVar8); +} + +void LoadItem(int i) +{ + CopyItem(&item[i]); + GetItemFrm(i); +} + +void CopyItem(ItemStruct *pItem) +{ + CopyInt(tbuff, &pItem->_iSeed); + CopyShort(tbuff, &pItem->_iCreateInfo); + tbuff += 2; + CopyInt(tbuff, &pItem->_itype); + CopyInt(tbuff, &pItem->_ix); + CopyInt(tbuff, &pItem->_iy); + CopyInt(tbuff, &pItem->_iAnimFlag); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(tbuff, &pItem->_iAnimLen); + CopyInt(tbuff, &pItem->_iAnimFrame); + CopyInt(tbuff, &pItem->_iAnimWidth); + CopyInt(tbuff, &pItem->_iAnimWidth2); + CopyInt(tbuff, &pItem->_isin); + CopyChar(tbuff, &pItem->_iSelFlag); + tbuff += 3; + CopyInt(tbuff, &pItem->_iPostDraw); + CopyInt(tbuff, &pItem->_iIdentified); + CopyChar(tbuff, &pItem->_iMagical); + CopyBytes(tbuff, 64, &pItem->_iName); + CopyBytes(tbuff, 64, &pItem->_iIName); + CopyChar(tbuff, &pItem->_iLoc); + CopyChar(tbuff, &pItem->_iClass); + tbuff += 1; + CopyInt(tbuff, &pItem->_iCurs); + CopyInt(tbuff, &pItem->_ivalue); + CopyInt(tbuff, &pItem->_iIvalue); + CopyInt(tbuff, &pItem->_iMinDam); + CopyInt(tbuff, &pItem->_iMaxDam); + CopyInt(tbuff, &pItem->_iAC); + CopyInt(tbuff, &pItem->_iFlags); + CopyInt(tbuff, &pItem->_iMiscId); + CopyInt(tbuff, &pItem->_iSpell); + CopyInt(tbuff, &pItem->_iCharges); + CopyInt(tbuff, &pItem->_iMaxCharges); + CopyInt(tbuff, &pItem->_iDurability); + CopyInt(tbuff, &pItem->_iMaxDur); + CopyInt(tbuff, &pItem->_iPLDam); + CopyInt(tbuff, &pItem->_iPLToHit); + CopyInt(tbuff, &pItem->_iPLAC); + CopyInt(tbuff, &pItem->_iPLStr); + CopyInt(tbuff, &pItem->_iPLMag); + CopyInt(tbuff, &pItem->_iPLDex); + CopyInt(tbuff, &pItem->_iPLVit); + CopyInt(tbuff, &pItem->_iPLFR); + CopyInt(tbuff, &pItem->_iPLLR); + CopyInt(tbuff, &pItem->_iPLMR); + CopyInt(tbuff, &pItem->_iPLMana); + CopyInt(tbuff, &pItem->_iPLHP); + CopyInt(tbuff, &pItem->_iPLDamMod); + CopyInt(tbuff, &pItem->_iPLGetHit); + CopyInt(tbuff, &pItem->_iPLLight); + CopyChar(tbuff, &pItem->_iSplLvlAdd); + CopyChar(tbuff, &pItem->_iRequest); + tbuff += 2; + CopyInt(tbuff, &pItem->_iUid); + CopyInt(tbuff, &pItem->_iFMinDam); + CopyInt(tbuff, &pItem->_iFMaxDam); + CopyInt(tbuff, &pItem->_iLMinDam); + CopyInt(tbuff, &pItem->_iLMaxDam); + CopyInt(tbuff, &pItem->_iPLEnAc); + CopyChar(tbuff, &pItem->_iPrePower); + CopyChar(tbuff, &pItem->_iSufPower); + tbuff += 2; + CopyInt(tbuff, &pItem->_iVAdd1); + CopyInt(tbuff, &pItem->_iVMult1); + CopyInt(tbuff, &pItem->_iVAdd2); + CopyInt(tbuff, &pItem->_iVMult2); + CopyChar(tbuff, &pItem->_iMinStr); + CopyChar(tbuff, &pItem->_iMinMag); + CopyChar(tbuff, &pItem->_iMinDex); + tbuff += 1; + CopyInt(tbuff, &pItem->_iStatFlag); + CopyInt(tbuff, &pItem->IDidx); + CopyInt(tbuff, &pItem->offs016C); +} + +void CopyItems(const int n, ItemStruct *pItem) +{ + for (int i = 0; i < n; i++) { + CopyItem(&pItem[i]); + } +} + +void SaveItem(ItemStruct *pItem) +{ + CopyInt(&pItem->_iSeed, tbuff); + CopyShort(&pItem->_iCreateInfo, tbuff); + tbuff += 2; + CopyInt(&pItem->_itype, tbuff); + CopyInt(&pItem->_ix, tbuff); + CopyInt(&pItem->_iy, tbuff); + CopyInt(&pItem->_iAnimFlag, tbuff); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(&pItem->_iAnimLen, tbuff); + CopyInt(&pItem->_iAnimFrame, tbuff); + CopyInt(&pItem->_iAnimWidth, tbuff); + CopyInt(&pItem->_iAnimWidth2, tbuff); // width 2? + CopyInt(&pItem->_isin, tbuff); // set when item is flagged for deletion, deprecated in 1.02 + CopyChar(&pItem->_iSelFlag, tbuff); + tbuff += 3; + CopyInt(&pItem->_iPostDraw, tbuff); + CopyInt(&pItem->_iIdentified, tbuff); + CopyChar(&pItem->_iMagical, tbuff); + CopyBytes(&pItem->_iName, 64, tbuff); + CopyBytes(&pItem->_iIName, 64, tbuff); + CopyChar(&pItem->_iLoc, tbuff); + CopyChar(&pItem->_iClass, tbuff); + tbuff += 1; + CopyInt(&pItem->_iCurs, tbuff); + CopyInt(&pItem->_ivalue, tbuff); + CopyInt(&pItem->_iIvalue, tbuff); + CopyInt(&pItem->_iMinDam, tbuff); + CopyInt(&pItem->_iMaxDam, tbuff); + CopyInt(&pItem->_iAC, tbuff); + CopyInt(&pItem->_iFlags, tbuff); + CopyInt(&pItem->_iMiscId, tbuff); + CopyInt(&pItem->_iSpell, tbuff); + CopyInt(&pItem->_iCharges, tbuff); + CopyInt(&pItem->_iMaxCharges, tbuff); + CopyInt(&pItem->_iDurability, tbuff); + CopyInt(&pItem->_iMaxDur, tbuff); + CopyInt(&pItem->_iPLDam, tbuff); + CopyInt(&pItem->_iPLToHit, tbuff); + CopyInt(&pItem->_iPLAC, tbuff); + CopyInt(&pItem->_iPLStr, tbuff); + CopyInt(&pItem->_iPLMag, tbuff); + CopyInt(&pItem->_iPLDex, tbuff); + CopyInt(&pItem->_iPLVit, tbuff); + CopyInt(&pItem->_iPLFR, tbuff); + CopyInt(&pItem->_iPLLR, tbuff); + CopyInt(&pItem->_iPLMR, tbuff); + CopyInt(&pItem->_iPLMana, tbuff); + CopyInt(&pItem->_iPLHP, tbuff); + CopyInt(&pItem->_iPLDamMod, tbuff); + CopyInt(&pItem->_iPLGetHit, tbuff); + CopyInt(&pItem->_iPLLight, tbuff); + CopyChar(&pItem->_iSplLvlAdd, tbuff); + CopyChar(&pItem->_iRequest, tbuff); + tbuff += 2; + CopyInt(&pItem->_iUid, tbuff); + CopyInt(&pItem->_iFMinDam, tbuff); + CopyInt(&pItem->_iFMaxDam, tbuff); + CopyInt(&pItem->_iLMinDam, tbuff); + CopyInt(&pItem->_iLMaxDam, tbuff); + CopyInt(&pItem->_iPLEnAc, tbuff); + CopyChar(&pItem->_iPrePower, tbuff); + CopyChar(&pItem->_iSufPower, tbuff); + tbuff += 2; + CopyInt(&pItem->_iVAdd1, tbuff); + CopyInt(&pItem->_iVMult1, tbuff); + CopyInt(&pItem->_iVAdd2, tbuff); + CopyInt(&pItem->_iVMult2, tbuff); + CopyChar(&pItem->_iMinStr, tbuff); + CopyChar(&pItem->_iMinMag, tbuff); + CopyChar(&pItem->_iMinDex, tbuff); + tbuff += 1; + CopyInt(&pItem->_iStatFlag, tbuff); + CopyInt(&pItem->IDidx, tbuff); + CopyInt(&pItem->offs016C, tbuff); +} + +void SaveItems(ItemStruct *pItem, const int n) +{ + for (int i = 0; i < n; i++) { + SaveItem(&pItem[i]); + } +} + +void LoadPremium(int i) +{ + CopyItem(&item[i]); +} + +void LoadQuest(int i) +{ + memcpy(&quests[i], tbuff, sizeof(*quests)); + tbuff += sizeof(*quests); + ReturnLvlX = WLoad(); + ReturnLvlY = WLoad(); + ReturnLvl = WLoad(); + ReturnLvlT = WLoad(); + DoomQuestState = WLoad(); +} + +void LoadLighting(int i) +{ + memcpy(&LightList[i], tbuff, sizeof(*LightList)); + tbuff += sizeof(*LightList); +} + +void LoadVision(int i) +{ + memcpy(&VisionList[i], tbuff, sizeof(*VisionList)); + tbuff += sizeof(*VisionList); +} + +void LoadPortal(int i) +{ + memcpy(&portal[i], tbuff, sizeof(*portal)); + tbuff += sizeof(*portal); +} + +void SaveGame() +{ + int i, j; + char szName[MAX_PATH]; + + DWORD dwLen = codec_get_encoded_len(FILEBUFF); + BYTE *SaveBuff = DiabloAllocPtr(dwLen); + tbuff = SaveBuff; + + ISave('RETL'); + OSave((unsigned char)setlevel); + WSave(setlvlnum); + WSave(currlevel); + WSave((unsigned char)leveltype); + WSave(ViewX); + WSave(ViewY); + OSave(invflag); + OSave(chrflag); + WSave(nummonsters); + WSave(numitems); + WSave(nummissiles); + WSave(nobjects); + + for (i = 0; i < NUMLEVELS; i++) { + ISave(glSeedTbl[i]); + WSave(gnLevelTypeTbl[i]); + } + + SavePlayer(myplr); + + for (i = 0; i < MAXQUESTS; i++) + SaveQuest(i); + for (i = 0; i < MAXPORTAL; i++) + SavePortal(i); + for (i = 0; i < MAXMONSTERS; i++) + ISave(monstkills[i]); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + WSave(monstactive[i]); + for (i = 0; i < nummonsters; i++) + SaveMonster(monstactive[i]); + for (i = 0; i < MAXMISSILES; i++) + BSave(missileactive[i]); + for (i = 0; i < MAXMISSILES; i++) + BSave(missileavail[i]); + for (i = 0; i < nummissiles; i++) + SaveMissile(missileactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectavail[i]); + for (i = 0; i < nobjects; i++) + SaveObject(objectactive[i]); + + WSave(numlights); + + for (i = 0; i < MAXLIGHTS; i++) + BSave(lightactive[i]); + for (i = 0; i < numlights; i++) + SaveLighting(lightactive[i]); + + WSave(visionid); + WSave(numvision); + + for (i = 0; i < numvision; i++) + SaveVision(i); + } + + for (i = 0; i < MAXITEMS; i++) + BSave(itemactive[i]); + for (i = 0; i < MAXITEMS; i++) + BSave(itemavail[i]); + for (i = 0; i < numitems; i++) + SaveItem(&item[itemactive[i]]); + for (i = 0; i < 128; i++) + OSave(UniqueItemFlag[i]); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dLight[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dPlayer[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dItem[i][j]); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + WSave(dMonster[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dDead[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dObject[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dLight[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dPreLight[i][j]); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + OSave(automapview[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dMissile[i][j]); + } + } + + WSave(numpremium); + WSave(premiumlevel); + + for (i = 0; i < 6; i++) + SavePremium(i); + + OSave(automapflag); + WSave(AutoMapScale); + pfile_get_game_name(szName); + dwLen = codec_get_encoded_len(tbuff - SaveBuff); + pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); + mem_free_dbg(SaveBuff); + gbValidSaveFile = TRUE; + pfile_rename_temp_to_perm(); + pfile_write_hero(); +} + +void BSave(char v) +{ + *tbuff++ = v; +} + +void WSave(int v) +{ + *tbuff++ = v >> 24; + *tbuff++ = v >> 16; + *tbuff++ = v >> 8; + *tbuff++ = v; +} + +void ISave(int v) +{ + *tbuff++ = v >> 24; + *tbuff++ = v >> 16; + *tbuff++ = v >> 8; + *tbuff++ = v; +} + +void OSave(BOOL v) +{ + if (v != FALSE) + *tbuff++ = TRUE; + else + *tbuff++ = FALSE; +} + +void SaveMonster(int i) +{ + MonsterStruct *pMonster = &monster[i]; + + CopyInt(&pMonster->_mMTidx, tbuff); + CopyInt(&pMonster->_mmode, tbuff); + + CopyChar(&pMonster->_mgoal, tbuff); + tbuff += 3; + + CopyInt(&pMonster->_mgoalvar1, tbuff); + CopyInt(&pMonster->_mgoalvar2, tbuff); + CopyInt(&pMonster->_mgoalvar3, tbuff); + CopyInt(&pMonster->field_18, tbuff); + + CopyChar(&pMonster->_pathcount, tbuff); + tbuff += 3; + + CopyInt(&pMonster->_mx, tbuff); + CopyInt(&pMonster->_my, tbuff); + CopyInt(&pMonster->_mfutx, tbuff); + CopyInt(&pMonster->_mfuty, tbuff); + CopyInt(&pMonster->_moldx, tbuff); + CopyInt(&pMonster->_moldy, tbuff); + CopyInt(&pMonster->_mxoff, tbuff); + CopyInt(&pMonster->_myoff, tbuff); + CopyInt(&pMonster->_mxvel, tbuff); + CopyInt(&pMonster->_myvel, tbuff); + CopyInt(&pMonster->_mdir, tbuff); + CopyInt(&pMonster->_menemy, tbuff); + + CopyChar(&pMonster->_menemyx, tbuff); + CopyChar(&pMonster->_menemyy, tbuff); + CopyShort(&pMonster->falign_52, tbuff); + + tbuff += 4; // Skip pointer + CopyInt(&pMonster->_mAnimDelay, tbuff); + CopyInt(&pMonster->_mAnimCnt, tbuff); + CopyInt(&pMonster->_mAnimLen, tbuff); + CopyInt(&pMonster->_mAnimFrame, tbuff); + CopyInt(&pMonster->_meflag, tbuff); + CopyInt(&pMonster->_mDelFlag, tbuff); + CopyInt(&pMonster->_mVar1, tbuff); + CopyInt(&pMonster->_mVar2, tbuff); + CopyInt(&pMonster->_mVar3, tbuff); + CopyInt(&pMonster->_mVar4, tbuff); + CopyInt(&pMonster->_mVar5, tbuff); + CopyInt(&pMonster->_mVar6, tbuff); + CopyInt(&pMonster->_mVar7, tbuff); + CopyInt(&pMonster->_mVar8, tbuff); + CopyInt(&pMonster->_mmaxhp, tbuff); + CopyInt(&pMonster->_mhitpoints, tbuff); + + CopyChar(&pMonster->_mAi, tbuff); + CopyChar(&pMonster->_mint, tbuff); + CopyShort(&pMonster->falign_9A, tbuff); + + CopyInt(&pMonster->_mFlags, tbuff); + + CopyChar(&pMonster->_msquelch, tbuff); + tbuff += 3; + + CopyInt(&pMonster->falign_A4, tbuff); + CopyInt(&pMonster->_lastx, tbuff); + CopyInt(&pMonster->_lasty, tbuff); + CopyInt(&pMonster->_mRndSeed, tbuff); + CopyInt(&pMonster->_mAISeed, tbuff); + CopyInt(&pMonster->falign_B8, tbuff); + + CopyChar(&pMonster->_uniqtype, tbuff); + CopyChar(&pMonster->_uniqtrans, tbuff); + CopyChar(&pMonster->_udeadval, tbuff); + CopyChar(&pMonster->mWhoHit, tbuff); + + CopyChar(&pMonster->mLevel, tbuff); + CopyShort(&pMonster->mExp, tbuff); + tbuff += 1; + + CopyChar(&pMonster->mHit, tbuff); + CopyChar(&pMonster->mMinDamage, tbuff); + CopyChar(&pMonster->mMaxDamage, tbuff); + CopyChar(&pMonster->mHit2, tbuff); + + CopyChar(&pMonster->mMinDamage2, tbuff); + CopyChar(&pMonster->mMaxDamage2, tbuff); + CopyChar(&pMonster->mArmorClass, tbuff); + CopyChar(&pMonster->falign_CB, tbuff); + + CopyShort(&pMonster->mMagicRes, tbuff); + tbuff += 2; + + CopyInt(&pMonster->mtalkmsg, tbuff); + + CopyChar(&pMonster->leader, tbuff); + CopyChar(&pMonster->leaderflag, tbuff); + CopyChar(&pMonster->packsize, tbuff); + CopyChar(&pMonster->mlid, tbuff); +} + +void SaveMissile(int i) +{ + MissileStruct *pMissile = &missile[i]; + + CopyInt(&pMissile->_mitype, tbuff); + CopyInt(&pMissile->_mix, tbuff); + CopyInt(&pMissile->_miy, tbuff); + CopyInt(&pMissile->_mixoff, tbuff); + CopyInt(&pMissile->_miyoff, tbuff); + CopyInt(&pMissile->_mixvel, tbuff); + CopyInt(&pMissile->_miyvel, tbuff); + CopyInt(&pMissile->_misx, tbuff); + CopyInt(&pMissile->_misy, tbuff); + CopyInt(&pMissile->_mitxoff, tbuff); + CopyInt(&pMissile->_mityoff, tbuff); + CopyInt(&pMissile->_mimfnum, tbuff); + CopyInt(&pMissile->_mispllvl, tbuff); + CopyInt(&pMissile->_miDelFlag, tbuff); + CopyChar(&pMissile->_miAnimType, tbuff); + tbuff += 3; + + CopyInt(&pMissile->_miAnimFlags, tbuff); + tbuff += 4; + CopyInt(&pMissile->_miAnimDelay, tbuff); + CopyInt(&pMissile->_miAnimLen, tbuff); + CopyInt(&pMissile->_miAnimWidth, tbuff); + CopyInt(&pMissile->_miAnimWidth2, tbuff); + CopyInt(&pMissile->_miAnimCnt, tbuff); + CopyInt(&pMissile->_miAnimAdd, tbuff); + CopyInt(&pMissile->_miAnimFrame, tbuff); + CopyInt(&pMissile->_miDrawFlag, tbuff); + CopyInt(&pMissile->_miLightFlag, tbuff); + CopyInt(&pMissile->_miPreFlag, tbuff); + CopyInt(&pMissile->_miUniqTrans, tbuff); + CopyInt(&pMissile->_mirange, tbuff); + CopyInt(&pMissile->_misource, tbuff); + CopyInt(&pMissile->_micaster, tbuff); + CopyInt(&pMissile->_midam, tbuff); + CopyInt(&pMissile->_miHitFlag, tbuff); + CopyInt(&pMissile->_midist, tbuff); + CopyInt(&pMissile->_mlid, tbuff); + CopyInt(&pMissile->_mirnd, tbuff); + CopyInt(&pMissile->_miVar1, tbuff); + CopyInt(&pMissile->_miVar2, tbuff); + CopyInt(&pMissile->_miVar3, tbuff); + CopyInt(&pMissile->_miVar4, tbuff); + CopyInt(&pMissile->_miVar5, tbuff); + CopyInt(&pMissile->_miVar6, tbuff); + CopyInt(&pMissile->_miVar7, tbuff); + CopyInt(&pMissile->_miVar8, tbuff); +} + +void SaveObject(int i) +{ + ObjectStruct *pObject = &object[i]; + CopyInt(tbuff, &pObject->_otype); + CopyInt(&pObject->_ox, tbuff); + CopyInt(&pObject->_oy, tbuff); + CopyInt(&pObject->_oLight, tbuff); + CopyInt(&pObject->_oAnimFlag, tbuff); + tbuff += 4; + CopyInt(&pObject->_oAnimDelay, tbuff); + CopyInt(&pObject->_oAnimCnt, tbuff); + CopyInt(&pObject->_oAnimLen, tbuff); + CopyInt(&pObject->_oAnimFrame, tbuff); + CopyInt(&pObject->_oAnimWidth, tbuff); + CopyInt(&pObject->_oAnimWidth2, tbuff); + CopyInt(&pObject->_oDelFlag, tbuff); + + CopyChar(&pObject->_oBreak, tbuff); + tbuff += 3; + + CopyInt(&pObject->_oSolidFlag, tbuff); + CopyInt(&pObject->_oMissFlag, tbuff); + + CopyChar(&pObject->_oSelFlag, tbuff); + tbuff += 3; + + CopyInt(&pObject->_oPreFlag, tbuff); + CopyInt(&pObject->_oTrapFlag, tbuff); + CopyInt(&pObject->_oDoorFlag, tbuff); + CopyInt(&pObject->_olid, tbuff); + CopyInt(&pObject->_oRndSeed, tbuff); + CopyInt(&pObject->_oVar1, tbuff); + CopyInt(&pObject->_oVar2, tbuff); + CopyInt(&pObject->_oVar3, tbuff); + CopyInt(&pObject->_oVar4, tbuff); + CopyInt(&pObject->_oVar5, tbuff); + CopyInt(&pObject->_oVar6, tbuff); + CopyInt(&pObject->_oVar7, tbuff); + CopyInt(&pObject->_oVar8, tbuff); +} + +void SavePremium(int i) +{ + SaveItem(&item[i]); +} + +void SaveQuest(int i) +{ + memcpy(tbuff, &quests[i], sizeof(*quests)); + tbuff += sizeof(*quests); + WSave(ReturnLvlX); + WSave(ReturnLvlY); + WSave(ReturnLvl); + WSave(ReturnLvlT); + WSave(DoomQuestState); +} + +void SaveLighting(int i) +{ + memcpy(tbuff, &LightList[i], sizeof(*LightList)); + tbuff += sizeof(*LightList); +} + +void SaveVision(int i) +{ + memcpy(tbuff, &VisionList[i], sizeof(*VisionList)); + tbuff += sizeof(*VisionList); +} + +void SavePortal(int i) +{ + memcpy(tbuff, &portal[i], sizeof(*portal)); + tbuff += sizeof(*portal); +} + +void SaveLevel() +{ + int i, j; + char szName[MAX_PATH]; + int dwLen; + unsigned char *SaveBuff; + + if (!currlevel) + glSeedTbl[0] = GetRndSeed(); + + dwLen = codec_get_encoded_len(FILEBUFF); + SaveBuff = DiabloAllocPtr(dwLen); + tbuff = SaveBuff; + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dDead[i][j]); + } + } + + WSave(nummonsters); + WSave(numitems); + WSave(nobjects); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + WSave(monstactive[i]); + for (i = 0; i < nummonsters; i++) + SaveMonster(monstactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectavail[i]); + for (i = 0; i < nobjects; i++) + SaveObject(objectactive[i]); + } + + for (i = 0; i < MAXITEMS; i++) + BSave(itemactive[i]); + for (i = 0; i < MAXITEMS; i++) + BSave(itemavail[i]); + for (i = 0; i < numitems; i++) + SaveItem(&item[itemactive[i]]); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dItem[i][j]); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + WSave(dMonster[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dObject[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dLight[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dPreLight[i][j]); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + OSave(automapview[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dMissile[i][j]); + } + } + + GetTempLevelNames(szName); + dwLen = codec_get_encoded_len(tbuff - SaveBuff); + pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); + mem_free_dbg(SaveBuff); + + if (setlevel == 0) + plr[myplr]._pLvlVisited[currlevel] = 1; + else + plr[myplr]._pSLvlVisited[setlvlnum] = 1; +} + +void LoadLevel() +{ + int i, j; + DWORD dwLen; + char szName[MAX_PATH]; + BYTE *LoadBuff; + + GetPermLevelNames(szName); + LoadBuff = pfile_read(szName, &dwLen); + tbuff = LoadBuff; + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dDead[i][j] = BLoad(); + } + SetDead(); + } + + nummonsters = WLoad(); + numitems = WLoad(); + nobjects = WLoad(); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + monstactive[i] = WLoad(); + for (i = 0; i < nummonsters; i++) + LoadMonster(monstactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + objectactive[i] = BLoad(); + for (i = 0; i < MAXOBJECTS; i++) + objectavail[i] = BLoad(); + for (i = 0; i < nobjects; i++) + LoadObject(objectactive[i]); + for (i = 0; i < nobjects; i++) + SyncObjectAnim(objectactive[i]); + } + + for (i = 0; i < MAXITEMS; i++) + itemactive[i] = BLoad(); + for (i = 0; i < MAXITEMS; i++) + itemavail[i] = BLoad(); + for (i = 0; i < numitems; i++) + LoadItem(itemactive[i]); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dFlags[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dItem[i][j] = BLoad(); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dMonster[i][j] = WLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dObject[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dLight[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dPreLight[i][j] = BLoad(); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + automapview[i][j] = OLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dMissile[i][j] = 0; /// BUGFIX: supposed to load saved missiles with "BLoad()"? + } + } + + AutomapZoomReset(); + ResyncQuests(); + SyncPortals(); + dolighting = 1; + + for (i = 0; i < MAX_PLRS; i++) { + if (plr[i].plractive && currlevel == plr[i].plrlevel) + LightList[plr[i]._plid]._lunflag = 1; + } + + mem_free_dbg(LoadBuff); +} + +DEVILUTION_END_NAMESPACE diff --git a/structs.h b/structs.h index eb2cb92aea8..7d995dc2fc0 100644 --- a/structs.h +++ b/structs.h @@ -174,7 +174,7 @@ typedef struct ItemStruct { ////////////////////////////////////////////////// #pragma pack(push, 4) -typedef struct PlayerStruct { +typedef struct PlayerStruct { int _pmode; char walkpath[25]; uint8_t plractive; @@ -376,8 +376,8 @@ typedef struct TextDataStruct { typedef struct MissileData { unsigned char mName; - void(* mAddProc)(int, int, int, int, int, int, char, int, int); - void(* mProc)(int); + void (*mAddProc)(int, int, int, int, int, int, char, int, int); + void (*mProc)(int); BOOL mDraw; unsigned char mType; unsigned char mResist; @@ -1017,7 +1017,7 @@ typedef struct QuestData { typedef struct TMenuItem { DWORD dwFlags; char *pszStr; - void(* fnMenu)(BOOL); /* fix, should have one arg */ + void (*fnMenu)(BOOL); /* fix, should have one arg */ } TMenuItem; // TPDEF PTR FCN VOID TMenuUpdateFcn @@ -1331,21 +1331,21 @@ typedef struct _SNETUIDATA { int size; int uiflags; HWND parentwindow; - void(* artcallback)(); - void(* authcallback)(); - void(* createcallback)(); - void(* drawdesccallback)(); - void(* selectedcallback)(); - void(* messageboxcallback)(); - void(* soundcallback)(); - void(* statuscallback)(); - void(* getdatacallback)(); - void(* categorycallback)(); - void(* categorylistcallback)(); - void(* newaccountcallback)(); - void(* profilecallback)(); + void (*artcallback)(); + void (*authcallback)(); + void (*createcallback)(); + void (*drawdesccallback)(); + void (*selectedcallback)(); + void (*messageboxcallback)(); + void (*soundcallback)(); + void (*statuscallback)(); + void (*getdatacallback)(); + void (*categorycallback)(); + void (*categorylistcallback)(); + void (*newaccountcallback)(); + void (*profilecallback)(); int profilefields; - void(* profilebitmapcallback)(); + void (*profilebitmapcallback)(); int(__stdcall *selectnamecallback)( const struct _SNETPROGRAMDATA *, const struct _SNETPLAYERDATA *, @@ -1355,8 +1355,8 @@ typedef struct _SNETUIDATA { char *, DWORD, /* character name will be copied here */ char *, DWORD, /* character "description" will be copied here (used to advertise games) */ BOOL * /* new character? - unsure about this */ - ); - void(* changenamecallback)(); + ); + void (*changenamecallback)(); } _SNETUIDATA; typedef struct _SNETVERSIONDATA { From 48326cc6ff224e61420372c1c814a54e258ea3d5 Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 07:17:15 -0700 Subject: [PATCH 06/11] Use filthy Windows types --- Source/loadsave.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 1d2ddeb958f..42ba89f4a06 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -369,38 +369,38 @@ void LoadPlayer(int i) tbuff += 2; CopyInt(tbuff, &pPlayer->_pGFXLoad); - tbuff += sizeof(__uint32_t) * 8; + tbuff += sizeof(DWORD) * 8; CopyInt(tbuff, &pPlayer->_pNFrames); CopyInt(tbuff, &pPlayer->_pNWidth); - tbuff += sizeof(__uint32_t) * 8; + tbuff += sizeof(DWORD) * 8; CopyInt(tbuff, &pPlayer->_pWFrames); CopyInt(tbuff, &pPlayer->_pWWidth); - tbuff += sizeof(__uint32_t) * 8; + tbuff += sizeof(DWORD) * 8; CopyInt(tbuff, &pPlayer->_pAFrames); CopyInt(tbuff, &pPlayer->_pAWidth); CopyInt(tbuff, &pPlayer->_pAFNum); - tbuff += sizeof(__uint32_t) * 24; + tbuff += sizeof(DWORD) * 24; CopyInt(tbuff, &pPlayer->_pSFrames); CopyInt(tbuff, &pPlayer->_pSWidth); CopyInt(tbuff, &pPlayer->_pSFNum); - tbuff += sizeof(__uint32_t) * 8; + tbuff += sizeof(DWORD) * 8; CopyInt(tbuff, &pPlayer->_pHFrames); CopyInt(tbuff, &pPlayer->_pHWidth); - tbuff += sizeof(__uint32_t) * 8; + tbuff += sizeof(DWORD) * 8; CopyInt(tbuff, &pPlayer->_pDFrames); CopyInt(tbuff, &pPlayer->_pDWidth); - tbuff += sizeof(__uint32_t) * 8; + tbuff += sizeof(DWORD) * 8; CopyInt(tbuff, &pPlayer->_pBFrames); CopyInt(tbuff, &pPlayer->_pBWidth); @@ -572,38 +572,38 @@ void SavePlayer(int i) tbuff += 2; CopyInt(&pPlayer->_pGFXLoad, tbuff); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers CopyInt(&pPlayer->_pNFrames, tbuff); CopyInt(&pPlayer->_pNWidth, tbuff); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers CopyInt(&pPlayer->_pWFrames, tbuff); CopyInt(&pPlayer->_pWWidth, tbuff); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers CopyInt(&pPlayer->_pAFrames, tbuff); CopyInt(&pPlayer->_pAWidth, tbuff); CopyInt(&pPlayer->_pAFNum, tbuff); - tbuff += sizeof(__uint32_t) * 24; // Skip 24 pointers + tbuff += sizeof(DWORD) * 24; // Skip 24 pointers CopyInt(&pPlayer->_pSFrames, tbuff); CopyInt(&pPlayer->_pSWidth, tbuff); CopyInt(&pPlayer->_pSFNum, tbuff); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers CopyInt(&pPlayer->_pHFrames, tbuff); CopyInt(&pPlayer->_pHWidth, tbuff); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers CopyInt(&pPlayer->_pDFrames, tbuff); CopyInt(&pPlayer->_pDWidth, tbuff); - tbuff += sizeof(__uint32_t) * 8; // Skip 8 pointers + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers CopyInt(&pPlayer->_pBFrames, tbuff); CopyInt(&pPlayer->_pBWidth, tbuff); From 85b722461f6ae2db2eab2e6080eaf09914de24f6 Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 08:06:02 -0700 Subject: [PATCH 07/11] Fix line endings --- Source/loadsave.cpp | 3288 +++++++++++++++++++++---------------------- 1 file changed, 1644 insertions(+), 1644 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 42ba89f4a06..68dc56c5e52 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -1,1644 +1,1644 @@ -#include "diablo.h" - -DEVILUTION_BEGIN_NAMESPACE - -BYTE *tbuff; - -void LoadGame(BOOL firstflag) -{ - int i, j; - DWORD dwLen; - char szName[MAX_PATH]; - BYTE *LoadBuff; - int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects; - - FreeGameMem(); - pfile_remove_temp_files(); - pfile_get_game_name(szName); - LoadBuff = pfile_read(szName, &dwLen); - tbuff = LoadBuff; - - if (ILoad() != 'RETL') - app_fatal("Invalid save file"); - - setlevel = OLoad(); - setlvlnum = WLoad(); - currlevel = WLoad(); - leveltype = WLoad(); - _ViewX = WLoad(); - _ViewY = WLoad(); - invflag = OLoad(); - chrflag = OLoad(); - _nummonsters = WLoad(); - _numitems = WLoad(); - _nummissiles = WLoad(); - _nobjects = WLoad(); - - for (i = 0; i < NUMLEVELS; i++) { - glSeedTbl[i] = ILoad(); - gnLevelTypeTbl[i] = WLoad(); - } - - LoadPlayer(myplr); - - for (i = 0; i < MAXQUESTS; i++) - LoadQuest(i); - for (i = 0; i < MAXPORTAL; i++) - LoadPortal(i); - - LoadGameLevel(firstflag, 4); - SyncInitPlr(myplr); - SyncPlrAnim(myplr); - - ViewX = _ViewX; - ViewY = _ViewY; - nummonsters = _nummonsters; - numitems = _numitems; - nummissiles = _nummissiles; - nobjects = _nobjects; - - for (i = 0; i < MAXMONSTERS; i++) - monstkills[i] = ILoad(); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - monstactive[i] = WLoad(); - for (i = 0; i < nummonsters; i++) - LoadMonster(monstactive[i]); - for (i = 0; i < MAXMISSILES; i++) - missileactive[i] = BLoad(); - for (i = 0; i < MAXMISSILES; i++) - missileavail[i] = BLoad(); - for (i = 0; i < nummissiles; i++) - LoadMissile(missileactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - objectactive[i] = BLoad(); - for (i = 0; i < MAXOBJECTS; i++) - objectavail[i] = BLoad(); - for (i = 0; i < nobjects; i++) - LoadObject(objectactive[i]); - for (i = 0; i < nobjects; i++) - SyncObjectAnim(objectactive[i]); - - numlights = WLoad(); - - for (i = 0; i < MAXLIGHTS; i++) - lightactive[i] = BLoad(); - for (i = 0; i < numlights; i++) - LoadLighting(lightactive[i]); - - visionid = WLoad(); - numvision = WLoad(); - - for (i = 0; i < numvision; i++) - LoadVision(i); - } - - for (i = 0; i < MAXITEMS; i++) - itemactive[i] = BLoad(); - for (i = 0; i < MAXITEMS; i++) - itemavail[i] = BLoad(); - for (i = 0; i < numitems; i++) - LoadItem(itemactive[i]); - for (i = 0; i < 128; i++) - UniqueItemFlag[i] = OLoad(); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dFlags[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPlayer[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dItem[i][j] = BLoad(); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMonster[i][j] = WLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dDead[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dObject[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPreLight[i][j] = BLoad(); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - automapview[i][j] = OLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMissile[i][j] = BLoad(); - } - } - - numpremium = WLoad(); - premiumlevel = WLoad(); - - for (i = 0; i < 6; i++) - LoadPremium(i); - - automapflag = OLoad(); - AutoMapScale = WLoad(); - mem_free_dbg(LoadBuff); - AutomapZoomReset(); - ResyncQuests(); - - if (leveltype != DTYPE_TOWN) - ProcessLightList(); - - RedoPlayerVision(); - ProcessVisionList(); - missiles_process_charge(); - ResetPal(); - SetCursor_(CURSOR_HAND); - gbProcessPlayers = TRUE; -} - -char BLoad() -{ - return *tbuff++; -} - -int WLoad() -{ - int rv = *tbuff++ << 24; - rv |= *tbuff++ << 16; - rv |= *tbuff++ << 8; - rv |= *tbuff++; - - return rv; -} - -int ILoad() -{ - int rv = *tbuff++ << 24; - rv |= *tbuff++ << 16; - rv |= *tbuff++ << 8; - rv |= *tbuff++; - - return rv; -} - -BOOL OLoad() -{ - if (*tbuff++ == TRUE) - return TRUE; - else - return FALSE; -} - -void CopyInt(const void *src, void *dst) -{ - memcpy(dst, src, 4); - tbuff += 4; -} - -void CopyShort(const void *src, void *dst) -{ - memcpy(dst, src, 2); - tbuff += 2; -} - -void CopyShorts(const void *src, const int n, void *dst) -{ - memcpy(dst, src, 2 * n); - tbuff += 2 * n; -} - -void CopyInts(const void *src, const int n, void *dst) -{ - memcpy(dst, src, 4 * n); - tbuff += 4 * n; -} - -void CopyBytes(const void *src, const int n, void *dst) -{ - memcpy(dst, src, n); - tbuff += n; -} - -void CopyChar(const void *src, void *dst) -{ - memcpy(dst, src, 1); - tbuff += 1; -} - -void CopyInt64(const void *src, void *dst) -{ - memcpy(dst, src, 8); - tbuff += 8; -} - -void LoadPlayer(int i) -{ - PlayerStruct *pPlayer = &plr[i]; - - CopyInt(tbuff, &pPlayer->_pmode); - - CopyBytes(tbuff, 25, pPlayer->walkpath); - CopyBytes(tbuff, 1, &pPlayer->plractive); - tbuff += 2; - - CopyInt(tbuff, &pPlayer->destAction); - CopyInt(tbuff, &pPlayer->destParam1); - CopyInt(tbuff, &pPlayer->destParam2); - CopyInt(tbuff, &pPlayer->destParam3); - CopyInt(tbuff, &pPlayer->destParam4); - CopyInt(tbuff, &pPlayer->plrlevel); - CopyInt(tbuff, &pPlayer->WorldX); - CopyInt(tbuff, &pPlayer->WorldY); - CopyInt(tbuff, &pPlayer->_px); - CopyInt(tbuff, &pPlayer->_py); - CopyInt(tbuff, &pPlayer->_ptargx); - CopyInt(tbuff, &pPlayer->_ptargy); - CopyInt(tbuff, &pPlayer->_pownerx); - CopyInt(tbuff, &pPlayer->_pownery); - CopyInt(tbuff, &pPlayer->_poldx); - CopyInt(tbuff, &pPlayer->_poldy); - CopyInt(tbuff, &pPlayer->_pxoff); - CopyInt(tbuff, &pPlayer->_pyoff); - CopyInt(tbuff, &pPlayer->_pxvel); - CopyInt(tbuff, &pPlayer->_pyvel); - CopyInt(tbuff, &pPlayer->_pdir); - CopyInt(tbuff, &pPlayer->_nextdir); - CopyInt(tbuff, &pPlayer->_pgfxnum); - tbuff += 4; // Skip pointers - CopyInt(tbuff, &pPlayer->_pAnimDelay); - CopyInt(tbuff, &pPlayer->_pAnimCnt); - CopyInt(tbuff, &pPlayer->_pAnimLen); - CopyInt(tbuff, &pPlayer->_pAnimFrame); - CopyInt(tbuff, &pPlayer->_pAnimWidth); - CopyInt(tbuff, &pPlayer->_pAnimWidth2); - CopyInt(tbuff, &pPlayer->_peflag); - CopyInt(tbuff, &pPlayer->_plid); - CopyInt(tbuff, &pPlayer->_pvid); - - CopyInt(tbuff, &pPlayer->_pSpell); - CopyChar(tbuff, &pPlayer->_pSplType); - CopyChar(tbuff, &pPlayer->_pSplFrom); - tbuff += 2; - CopyInt(tbuff, &pPlayer->_pTSpell); - CopyChar(tbuff, &pPlayer->_pTSplType); - tbuff += 3; - CopyInt(tbuff, &pPlayer->_pRSpell); - CopyChar(tbuff, &pPlayer->_pRSplType); - tbuff += 3; - CopyInt(tbuff, &pPlayer->_pSBkSpell); - CopyChar(tbuff, &pPlayer->_pSBkSplType); - - CopyBytes(tbuff, 64, &pPlayer->_pSplLvl); - tbuff += 7; - CopyInt64(tbuff, &pPlayer->_pMemSpells); - CopyInt64(tbuff, &pPlayer->_pAblSpells); - CopyInt64(tbuff, &pPlayer->_pScrlSpells); - CopyChar(tbuff, &pPlayer->_pSpellFlags); - tbuff += 3; - CopyInts(tbuff, 4, &pPlayer->_pSplHotKey); - CopyBytes(tbuff, 4, &pPlayer->_pSplTHotKey); - CopyInt(tbuff, &pPlayer->_pwtype); - CopyChar(tbuff, &pPlayer->_pBlockFlag); - CopyChar(tbuff, &pPlayer->_pInvincible); - CopyChar(tbuff, &pPlayer->_pLightRad); - CopyChar(tbuff, &pPlayer->_pLvlChanging); - CopyBytes(tbuff, PLR_NAME_LEN, &pPlayer->_pName); - CopyChar(tbuff, &pPlayer->_pClass); - tbuff += 3; - CopyInt(tbuff, &pPlayer->_pStrength); - CopyInt(tbuff, &pPlayer->_pBaseStr); - CopyInt(tbuff, &pPlayer->_pMagic); - CopyInt(tbuff, &pPlayer->_pBaseMag); - CopyInt(tbuff, &pPlayer->_pDexterity); - CopyInt(tbuff, &pPlayer->_pBaseDex); - CopyInt(tbuff, &pPlayer->_pVitality); - CopyInt(tbuff, &pPlayer->_pBaseVit); - CopyInt(tbuff, &pPlayer->_pStatPts); - CopyInt(tbuff, &pPlayer->_pDamageMod); - CopyInt(tbuff, &pPlayer->_pBaseToBlk); - CopyInt(tbuff, &pPlayer->_pHPBase); - CopyInt(tbuff, &pPlayer->_pMaxHPBase); - CopyInt(tbuff, &pPlayer->_pHitPoints); - CopyInt(tbuff, &pPlayer->_pMaxHP); - CopyInt(tbuff, &pPlayer->_pHPPer); - CopyInt(tbuff, &pPlayer->_pManaBase); - CopyInt(tbuff, &pPlayer->_pMaxManaBase); - CopyInt(tbuff, &pPlayer->_pMana); - CopyInt(tbuff, &pPlayer->_pMaxMana); - CopyInt(tbuff, &pPlayer->_pManaPer); - CopyChar(tbuff, &pPlayer->_pLevel); - CopyChar(tbuff, &pPlayer->_pMaxLvl); - tbuff += 2; - CopyInt(tbuff, &pPlayer->_pExperience); - CopyInt(tbuff, &pPlayer->_pMaxExp); - CopyInt(tbuff, &pPlayer->_pNextExper); - CopyChar(tbuff, &pPlayer->_pArmorClass); - CopyChar(tbuff, &pPlayer->_pMagResist); - CopyChar(tbuff, &pPlayer->_pFireResist); - CopyChar(tbuff, &pPlayer->_pLghtResist); - CopyInt(tbuff, &pPlayer->_pGold); - CopyInt(tbuff, &pPlayer->_pInfraFlag); - CopyInt(tbuff, &pPlayer->_pVar1); - CopyInt(tbuff, &pPlayer->_pVar2); - CopyInt(tbuff, &pPlayer->_pVar3); - CopyInt(tbuff, &pPlayer->_pVar4); - CopyInt(tbuff, &pPlayer->_pVar5); - CopyInt(tbuff, &pPlayer->_pVar6); - CopyInt(tbuff, &pPlayer->_pVar7); - CopyInt(tbuff, &pPlayer->_pVar8); - CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pLvlVisited); - CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pSLvlVisited); - tbuff += 2; - CopyInt(tbuff, &pPlayer->_pGFXLoad); - - tbuff += sizeof(DWORD) * 8; - CopyInt(tbuff, &pPlayer->_pNFrames); - CopyInt(tbuff, &pPlayer->_pNWidth); - - tbuff += sizeof(DWORD) * 8; - - CopyInt(tbuff, &pPlayer->_pWFrames); - CopyInt(tbuff, &pPlayer->_pWWidth); - - tbuff += sizeof(DWORD) * 8; - - CopyInt(tbuff, &pPlayer->_pAFrames); - CopyInt(tbuff, &pPlayer->_pAWidth); - CopyInt(tbuff, &pPlayer->_pAFNum); - - tbuff += sizeof(DWORD) * 24; - - CopyInt(tbuff, &pPlayer->_pSFrames); - CopyInt(tbuff, &pPlayer->_pSWidth); - CopyInt(tbuff, &pPlayer->_pSFNum); - - tbuff += sizeof(DWORD) * 8; - - CopyInt(tbuff, &pPlayer->_pHFrames); - CopyInt(tbuff, &pPlayer->_pHWidth); - - tbuff += sizeof(DWORD) * 8; - - CopyInt(tbuff, &pPlayer->_pDFrames); - CopyInt(tbuff, &pPlayer->_pDWidth); - - tbuff += sizeof(DWORD) * 8; - - CopyInt(tbuff, &pPlayer->_pBFrames); - CopyInt(tbuff, &pPlayer->_pBWidth); - CopyItems(NUM_INVLOC, pPlayer->InvBody); - CopyItems(NUM_INV_GRID_ELEM, pPlayer->InvList); - CopyInt(tbuff, &pPlayer->_pNumInv); - CopyBytes(tbuff, NUM_INV_GRID_ELEM, pPlayer->InvGrid); - CopyItems(MAXBELTITEMS, pPlayer->SpdList); - CopyItem(&pPlayer->HoldItem); - CopyInt(tbuff, &pPlayer->_pIMinDam); - CopyInt(tbuff, &pPlayer->_pIMaxDam); - CopyInt(tbuff, &pPlayer->_pIAC); - CopyInt(tbuff, &pPlayer->_pIBonusDam); - CopyInt(tbuff, &pPlayer->_pIBonusToHit); - CopyInt(tbuff, &pPlayer->_pIBonusAC); - CopyInt(tbuff, &pPlayer->_pIBonusDamMod); - tbuff += 4; - CopyInt64(tbuff, &pPlayer->_pISpells); - CopyInt(tbuff, &pPlayer->_pIFlags); - CopyInt(tbuff, &pPlayer->_pIGetHit); - - CopyChar(tbuff, &pPlayer->_pISplLvlAdd); - CopyChar(tbuff, &pPlayer->_pISplCost); - tbuff += 2; - - CopyInt(tbuff, &pPlayer->_pISplDur); - CopyInt(tbuff, &pPlayer->_pIEnAc); - CopyInt(tbuff, &pPlayer->_pIFMinDam); - CopyInt(tbuff, &pPlayer->_pIFMaxDam); - CopyInt(tbuff, &pPlayer->_pILMinDam); - CopyInt(tbuff, &pPlayer->_pILMaxDam); - CopyInt(tbuff, &pPlayer->_pOilType); - - CopyChar(tbuff, &pPlayer->pTownWarps); - CopyChar(tbuff, &pPlayer->pDungMsgs); - CopyChar(tbuff, &pPlayer->pLvlLoad); - CopyChar(tbuff, &pPlayer->pBattleNet); - - CopyChar(tbuff, &pPlayer->pManaShield); - CopyBytes(tbuff, 3, &pPlayer->bReserved); - - CopyShorts(tbuff, 8, &pPlayer->wReserved); - - CopyInt(tbuff, &pPlayer->pDiabloKillLevel); - CopyInts(tbuff, 7, &pPlayer->dwReserved); - - // Omit 10 pointers -} - -void SavePlayer(int i) -{ - PlayerStruct *pPlayer = &plr[i]; - - CopyInt(&pPlayer->_pmode, tbuff); - - CopyBytes(&pPlayer->walkpath, 25, tbuff); - CopyBytes(&pPlayer->plractive, 1, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->destAction, tbuff); - CopyInt(&pPlayer->destParam1, tbuff); - CopyInt(&pPlayer->destParam2, tbuff); - CopyInt(&pPlayer->destParam3, tbuff); - CopyInt(&pPlayer->destParam4, tbuff); - CopyInt(&pPlayer->plrlevel, tbuff); - CopyInt(&pPlayer->WorldX, tbuff); - CopyInt(&pPlayer->WorldY, tbuff); - CopyInt(&pPlayer->_px, tbuff); - CopyInt(&pPlayer->_py, tbuff); - CopyInt(&pPlayer->_ptargx, tbuff); - CopyInt(&pPlayer->_ptargy, tbuff); - CopyInt(&pPlayer->_pownerx, tbuff); - CopyInt(&pPlayer->_pownery, tbuff); - CopyInt(&pPlayer->_poldx, tbuff); - CopyInt(&pPlayer->_poldy, tbuff); - CopyInt(&pPlayer->_pxoff, tbuff); - CopyInt(&pPlayer->_pyoff, tbuff); - CopyInt(&pPlayer->_pxvel, tbuff); - CopyInt(&pPlayer->_pyvel, tbuff); - CopyInt(&pPlayer->_pdir, tbuff); - CopyInt(&pPlayer->_nextdir, tbuff); - CopyInt(&pPlayer->_pgfxnum, tbuff); - tbuff += 4; // Skip pointers - CopyInt(&pPlayer->_pAnimDelay, tbuff); - CopyInt(&pPlayer->_pAnimCnt, tbuff); - CopyInt(&pPlayer->_pAnimLen, tbuff); - CopyInt(&pPlayer->_pAnimFrame, tbuff); - CopyInt(&pPlayer->_pAnimWidth, tbuff); - CopyInt(&pPlayer->_pAnimWidth2, tbuff); - CopyInt(&pPlayer->_peflag, tbuff); - CopyInt(&pPlayer->_plid, tbuff); - CopyInt(&pPlayer->_pvid, tbuff); - - CopyInt(&pPlayer->_pSpell, tbuff); - - CopyChar(&pPlayer->_pSplType, tbuff); - CopyChar(&pPlayer->_pSplFrom, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->_pTSpell, tbuff); - CopyChar(&pPlayer->_pTSplType, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pRSpell, tbuff); - CopyChar(&pPlayer->_pRSplType, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pSBkSpell, tbuff); - CopyChar(&pPlayer->_pSBkSplType, tbuff); - - CopyBytes(&pPlayer->_pSplLvl, 64, tbuff); - tbuff += 7; - CopyInt64(&pPlayer->_pMemSpells, tbuff); - CopyInt64(&pPlayer->_pAblSpells, tbuff); - CopyInt64(&pPlayer->_pScrlSpells, tbuff); - CopyChar(&pPlayer->_pSpellFlags, tbuff); - tbuff += 3; - CopyInts(&pPlayer->_pSplHotKey, 4, tbuff); - CopyBytes(&pPlayer->_pSplTHotKey, 4, tbuff); - CopyInt(&pPlayer->_pwtype, tbuff); - CopyChar(&pPlayer->_pBlockFlag, tbuff); - CopyChar(&pPlayer->_pInvincible, tbuff); - CopyChar(&pPlayer->_pLightRad, tbuff); - CopyChar(&pPlayer->_pLvlChanging, tbuff); - CopyBytes(&pPlayer->_pName, PLR_NAME_LEN, tbuff); - CopyChar(&pPlayer->_pClass, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pStrength, tbuff); - CopyInt(&pPlayer->_pBaseStr, tbuff); - CopyInt(&pPlayer->_pMagic, tbuff); - CopyInt(&pPlayer->_pBaseMag, tbuff); - CopyInt(&pPlayer->_pDexterity, tbuff); - CopyInt(&pPlayer->_pBaseDex, tbuff); - CopyInt(&pPlayer->_pVitality, tbuff); - CopyInt(&pPlayer->_pBaseVit, tbuff); - CopyInt(&pPlayer->_pStatPts, tbuff); - CopyInt(&pPlayer->_pDamageMod, tbuff); - CopyInt(&pPlayer->_pBaseToBlk, tbuff); - CopyInt(&pPlayer->_pHPBase, tbuff); - CopyInt(&pPlayer->_pMaxHPBase, tbuff); - CopyInt(&pPlayer->_pHitPoints, tbuff); - CopyInt(&pPlayer->_pMaxHP, tbuff); - CopyInt(&pPlayer->_pHPPer, tbuff); - CopyInt(&pPlayer->_pManaBase, tbuff); - CopyInt(&pPlayer->_pMaxManaBase, tbuff); - CopyInt(&pPlayer->_pMana, tbuff); - CopyInt(&pPlayer->_pMaxMana, tbuff); - CopyInt(&pPlayer->_pManaPer, tbuff); - CopyChar(&pPlayer->_pLevel, tbuff); - CopyChar(&pPlayer->_pMaxLvl, tbuff); - tbuff += 2; - CopyInt(&pPlayer->_pExperience, tbuff); - CopyInt(&pPlayer->_pMaxExp, tbuff); - CopyInt(&pPlayer->_pNextExper, tbuff); - CopyChar(&pPlayer->_pArmorClass, tbuff); - CopyChar(&pPlayer->_pMagResist, tbuff); - CopyChar(&pPlayer->_pFireResist, tbuff); - CopyChar(&pPlayer->_pLghtResist, tbuff); - CopyInt(&pPlayer->_pGold, tbuff); - CopyInt(&pPlayer->_pInfraFlag, tbuff); - CopyInt(&pPlayer->_pVar1, tbuff); - CopyInt(&pPlayer->_pVar2, tbuff); - CopyInt(&pPlayer->_pVar3, tbuff); - CopyInt(&pPlayer->_pVar4, tbuff); - CopyInt(&pPlayer->_pVar5, tbuff); - CopyInt(&pPlayer->_pVar6, tbuff); - CopyInt(&pPlayer->_pVar7, tbuff); - CopyInt(&pPlayer->_pVar8, tbuff); - CopyBytes(&pPlayer->_pLvlVisited, NUMLEVELS, tbuff); - CopyBytes(&pPlayer->_pSLvlVisited, NUMLEVELS, tbuff); // only 10 used - tbuff += 2; - CopyInt(&pPlayer->_pGFXLoad, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - CopyInt(&pPlayer->_pNFrames, tbuff); - CopyInt(&pPlayer->_pNWidth, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pWFrames, tbuff); - CopyInt(&pPlayer->_pWWidth, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pAFrames, tbuff); - CopyInt(&pPlayer->_pAWidth, tbuff); - CopyInt(&pPlayer->_pAFNum, tbuff); - - tbuff += sizeof(DWORD) * 24; // Skip 24 pointers - - CopyInt(&pPlayer->_pSFrames, tbuff); - CopyInt(&pPlayer->_pSWidth, tbuff); - CopyInt(&pPlayer->_pSFNum, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pHFrames, tbuff); - CopyInt(&pPlayer->_pHWidth, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pDFrames, tbuff); - CopyInt(&pPlayer->_pDWidth, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pBFrames, tbuff); - CopyInt(&pPlayer->_pBWidth, tbuff); - SaveItems(pPlayer->InvBody, NUM_INVLOC); - SaveItems(pPlayer->InvList, NUM_INV_GRID_ELEM); - CopyInt(&pPlayer->_pNumInv, tbuff); - CopyBytes(pPlayer->InvGrid, NUM_INV_GRID_ELEM, tbuff); - SaveItems(pPlayer->SpdList, MAXBELTITEMS); - SaveItem(&pPlayer->HoldItem); - CopyInt(&pPlayer->_pIMinDam, tbuff); - CopyInt(&pPlayer->_pIMaxDam, tbuff); - CopyInt(&pPlayer->_pIAC, tbuff); - CopyInt(&pPlayer->_pIBonusDam, tbuff); - CopyInt(&pPlayer->_pIBonusToHit, tbuff); - CopyInt(&pPlayer->_pIBonusAC, tbuff); - CopyInt(&pPlayer->_pIBonusDamMod, tbuff); - tbuff += 4; - CopyInt64(&pPlayer->_pISpells, tbuff); - CopyInt(&pPlayer->_pIFlags, tbuff); - CopyInt(&pPlayer->_pIGetHit, tbuff); - - CopyChar(&pPlayer->_pISplLvlAdd, tbuff); - CopyChar(&pPlayer->_pISplCost, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->_pISplDur, tbuff); - CopyInt(&pPlayer->_pIEnAc, tbuff); - CopyInt(&pPlayer->_pIFMinDam, tbuff); - CopyInt(&pPlayer->_pIFMaxDam, tbuff); - CopyInt(&pPlayer->_pILMinDam, tbuff); - CopyInt(&pPlayer->_pILMaxDam, tbuff); - CopyInt(&pPlayer->_pOilType, tbuff); - - CopyChar(&pPlayer->pTownWarps, tbuff); - CopyChar(&pPlayer->pDungMsgs, tbuff); - CopyChar(&pPlayer->pLvlLoad, tbuff); - CopyChar(&pPlayer->pBattleNet, tbuff); - - CopyChar(&pPlayer->pManaShield, tbuff); - CopyBytes(&pPlayer->bReserved, 3, tbuff); - - CopyShorts(&pPlayer->wReserved, 8, tbuff); - - CopyInt(&pPlayer->pDiabloKillLevel, tbuff); - CopyInts(&pPlayer->dwReserved, 7, tbuff); - - // Omit 10 pointers -} - -void LoadMonster(int i) -{ - MonsterStruct *pMonster = &monster[i]; - - CopyInt(tbuff, &pMonster->_mMTidx); - CopyInt(tbuff, &pMonster->_mmode); - - CopyChar(tbuff, &pMonster->_mgoal); - tbuff += 3; - - CopyInt(tbuff, &pMonster->_mgoalvar1); - CopyInt(tbuff, &pMonster->_mgoalvar2); - CopyInt(tbuff, &pMonster->_mgoalvar3); - CopyInt(tbuff, &pMonster->field_18); - - CopyChar(tbuff, &pMonster->_pathcount); - tbuff += 3; - - CopyInt(tbuff, &pMonster->_mx); - CopyInt(tbuff, &pMonster->_my); - CopyInt(tbuff, &pMonster->_mfutx); - CopyInt(tbuff, &pMonster->_mfuty); - CopyInt(tbuff, &pMonster->_moldx); - CopyInt(tbuff, &pMonster->_moldy); - CopyInt(tbuff, &pMonster->_mxoff); - CopyInt(tbuff, &pMonster->_myoff); - CopyInt(tbuff, &pMonster->_mxvel); - CopyInt(tbuff, &pMonster->_myvel); - CopyInt(tbuff, &pMonster->_mdir); - CopyInt(tbuff, &pMonster->_menemy); - - CopyChar(tbuff, &pMonster->_menemyx); - CopyChar(tbuff, &pMonster->_menemyy); - CopyShort(tbuff, &pMonster->falign_52); - - tbuff += 4; // Skip pointer - CopyInt(tbuff, &pMonster->_mAnimDelay); - CopyInt(tbuff, &pMonster->_mAnimCnt); - CopyInt(tbuff, &pMonster->_mAnimLen); - CopyInt(tbuff, &pMonster->_mAnimFrame); - CopyInt(tbuff, &pMonster->_meflag); - CopyInt(tbuff, &pMonster->_mDelFlag); - CopyInt(tbuff, &pMonster->_mVar1); - CopyInt(tbuff, &pMonster->_mVar2); - CopyInt(tbuff, &pMonster->_mVar3); - CopyInt(tbuff, &pMonster->_mVar4); - CopyInt(tbuff, &pMonster->_mVar5); - CopyInt(tbuff, &pMonster->_mVar6); - CopyInt(tbuff, &pMonster->_mVar7); - CopyInt(tbuff, &pMonster->_mVar8); - CopyInt(tbuff, &pMonster->_mmaxhp); - CopyInt(tbuff, &pMonster->_mhitpoints); - - CopyChar(tbuff, &pMonster->_mAi); - CopyChar(tbuff, &pMonster->_mint); - CopyShort(tbuff, &pMonster->falign_9A); - - CopyInt(tbuff, &pMonster->_mFlags); - - CopyChar(tbuff, &pMonster->_msquelch); - tbuff += 3; - - CopyInt(tbuff, &pMonster->falign_A4); - CopyInt(tbuff, &pMonster->_lastx); - CopyInt(tbuff, &pMonster->_lasty); - CopyInt(tbuff, &pMonster->_mRndSeed); - CopyInt(tbuff, &pMonster->_mAISeed); - CopyInt(tbuff, &pMonster->falign_B8); - - CopyChar(tbuff, &pMonster->_uniqtype); - CopyChar(tbuff, &pMonster->_uniqtrans); - CopyChar(tbuff, &pMonster->_udeadval); - CopyChar(tbuff, &pMonster->mWhoHit); - - CopyChar(tbuff, &pMonster->mLevel); - CopyShort(tbuff, &pMonster->mExp); - tbuff += 1; - - CopyChar(tbuff, &pMonster->mHit); - CopyChar(tbuff, &pMonster->mMinDamage); - CopyChar(tbuff, &pMonster->mMaxDamage); - CopyChar(tbuff, &pMonster->mHit2); - - CopyChar(tbuff, &pMonster->mMinDamage2); - CopyChar(tbuff, &pMonster->mMaxDamage2); - CopyChar(tbuff, &pMonster->mArmorClass); - CopyChar(tbuff, &pMonster->falign_CB); - - CopyShort(tbuff, &pMonster->mMagicRes); - tbuff += 2; - - CopyInt(tbuff, &pMonster->mtalkmsg); - - CopyChar(tbuff, &pMonster->leader); - CopyChar(tbuff, &pMonster->leaderflag); - CopyChar(tbuff, &pMonster->packsize); - CopyChar(tbuff, &pMonster->mlid); - - SyncMonsterAnim(i); -} - -void LoadMissile(int i) -{ - MissileStruct *pMissile = &missile[i]; - - CopyInt(tbuff, &pMissile->_mitype); - CopyInt(tbuff, &pMissile->_mix); - CopyInt(tbuff, &pMissile->_miy); - CopyInt(tbuff, &pMissile->_mixoff); - CopyInt(tbuff, &pMissile->_miyoff); - CopyInt(tbuff, &pMissile->_mixvel); - CopyInt(tbuff, &pMissile->_miyvel); - CopyInt(tbuff, &pMissile->_misx); - CopyInt(tbuff, &pMissile->_misy); - CopyInt(tbuff, &pMissile->_mitxoff); - CopyInt(tbuff, &pMissile->_mityoff); - CopyInt(tbuff, &pMissile->_mimfnum); - CopyInt(tbuff, &pMissile->_mispllvl); - CopyInt(tbuff, &pMissile->_miDelFlag); - CopyChar(tbuff, &pMissile->_miAnimType); - tbuff += 3; - - CopyInt(tbuff, &pMissile->_miAnimFlags); - tbuff += 4; - CopyInt(tbuff, &pMissile->_miAnimDelay); - CopyInt(tbuff, &pMissile->_miAnimLen); - CopyInt(tbuff, &pMissile->_miAnimWidth); - CopyInt(tbuff, &pMissile->_miAnimWidth2); - CopyInt(tbuff, &pMissile->_miAnimCnt); - CopyInt(tbuff, &pMissile->_miAnimAdd); - CopyInt(tbuff, &pMissile->_miAnimFrame); - CopyInt(tbuff, &pMissile->_miDrawFlag); - CopyInt(tbuff, &pMissile->_miLightFlag); - CopyInt(tbuff, &pMissile->_miPreFlag); - CopyInt(tbuff, &pMissile->_miUniqTrans); - CopyInt(tbuff, &pMissile->_mirange); - CopyInt(tbuff, &pMissile->_misource); - CopyInt(tbuff, &pMissile->_micaster); - CopyInt(tbuff, &pMissile->_midam); - CopyInt(tbuff, &pMissile->_miHitFlag); - CopyInt(tbuff, &pMissile->_midist); - CopyInt(tbuff, &pMissile->_mlid); - CopyInt(tbuff, &pMissile->_mirnd); - CopyInt(tbuff, &pMissile->_miVar1); - CopyInt(tbuff, &pMissile->_miVar2); - CopyInt(tbuff, &pMissile->_miVar3); - CopyInt(tbuff, &pMissile->_miVar4); - CopyInt(tbuff, &pMissile->_miVar5); - CopyInt(tbuff, &pMissile->_miVar6); - CopyInt(tbuff, &pMissile->_miVar7); - CopyInt(tbuff, &pMissile->_miVar8); -} - -void LoadObject(int i) -{ - ObjectStruct *pObject = &object[i]; - CopyInt(tbuff, &pObject->_otype); - CopyInt(tbuff, &pObject->_ox); - CopyInt(tbuff, &pObject->_oy); - CopyInt(tbuff, &pObject->_oLight); - CopyInt(tbuff, &pObject->_oAnimFlag); - tbuff += 4; - CopyInt(tbuff, &pObject->_oAnimDelay); - CopyInt(tbuff, &pObject->_oAnimCnt); - CopyInt(tbuff, &pObject->_oAnimLen); - CopyInt(tbuff, &pObject->_oAnimFrame); - CopyInt(tbuff, &pObject->_oAnimWidth); - CopyInt(tbuff, &pObject->_oAnimWidth2); - CopyInt(tbuff, &pObject->_oDelFlag); - - CopyChar(tbuff, &pObject->_oBreak); - tbuff += 3; - - CopyInt(tbuff, &pObject->_oSolidFlag); - CopyInt(tbuff, &pObject->_oMissFlag); - - CopyChar(tbuff, &pObject->_oSelFlag); - tbuff += 3; - - CopyInt(tbuff, &pObject->_oPreFlag); - CopyInt(tbuff, &pObject->_oTrapFlag); - CopyInt(tbuff, &pObject->_oDoorFlag); - CopyInt(tbuff, &pObject->_olid); - CopyInt(tbuff, &pObject->_oRndSeed); - CopyInt(tbuff, &pObject->_oVar1); - CopyInt(tbuff, &pObject->_oVar2); - CopyInt(tbuff, &pObject->_oVar3); - CopyInt(tbuff, &pObject->_oVar4); - CopyInt(tbuff, &pObject->_oVar5); - CopyInt(tbuff, &pObject->_oVar6); - CopyInt(tbuff, &pObject->_oVar7); - CopyInt(tbuff, &pObject->_oVar8); -} - -void LoadItem(int i) -{ - CopyItem(&item[i]); - GetItemFrm(i); -} - -void CopyItem(ItemStruct *pItem) -{ - CopyInt(tbuff, &pItem->_iSeed); - CopyShort(tbuff, &pItem->_iCreateInfo); - tbuff += 2; - CopyInt(tbuff, &pItem->_itype); - CopyInt(tbuff, &pItem->_ix); - CopyInt(tbuff, &pItem->_iy); - CopyInt(tbuff, &pItem->_iAnimFlag); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(tbuff, &pItem->_iAnimLen); - CopyInt(tbuff, &pItem->_iAnimFrame); - CopyInt(tbuff, &pItem->_iAnimWidth); - CopyInt(tbuff, &pItem->_iAnimWidth2); - CopyInt(tbuff, &pItem->_isin); - CopyChar(tbuff, &pItem->_iSelFlag); - tbuff += 3; - CopyInt(tbuff, &pItem->_iPostDraw); - CopyInt(tbuff, &pItem->_iIdentified); - CopyChar(tbuff, &pItem->_iMagical); - CopyBytes(tbuff, 64, &pItem->_iName); - CopyBytes(tbuff, 64, &pItem->_iIName); - CopyChar(tbuff, &pItem->_iLoc); - CopyChar(tbuff, &pItem->_iClass); - tbuff += 1; - CopyInt(tbuff, &pItem->_iCurs); - CopyInt(tbuff, &pItem->_ivalue); - CopyInt(tbuff, &pItem->_iIvalue); - CopyInt(tbuff, &pItem->_iMinDam); - CopyInt(tbuff, &pItem->_iMaxDam); - CopyInt(tbuff, &pItem->_iAC); - CopyInt(tbuff, &pItem->_iFlags); - CopyInt(tbuff, &pItem->_iMiscId); - CopyInt(tbuff, &pItem->_iSpell); - CopyInt(tbuff, &pItem->_iCharges); - CopyInt(tbuff, &pItem->_iMaxCharges); - CopyInt(tbuff, &pItem->_iDurability); - CopyInt(tbuff, &pItem->_iMaxDur); - CopyInt(tbuff, &pItem->_iPLDam); - CopyInt(tbuff, &pItem->_iPLToHit); - CopyInt(tbuff, &pItem->_iPLAC); - CopyInt(tbuff, &pItem->_iPLStr); - CopyInt(tbuff, &pItem->_iPLMag); - CopyInt(tbuff, &pItem->_iPLDex); - CopyInt(tbuff, &pItem->_iPLVit); - CopyInt(tbuff, &pItem->_iPLFR); - CopyInt(tbuff, &pItem->_iPLLR); - CopyInt(tbuff, &pItem->_iPLMR); - CopyInt(tbuff, &pItem->_iPLMana); - CopyInt(tbuff, &pItem->_iPLHP); - CopyInt(tbuff, &pItem->_iPLDamMod); - CopyInt(tbuff, &pItem->_iPLGetHit); - CopyInt(tbuff, &pItem->_iPLLight); - CopyChar(tbuff, &pItem->_iSplLvlAdd); - CopyChar(tbuff, &pItem->_iRequest); - tbuff += 2; - CopyInt(tbuff, &pItem->_iUid); - CopyInt(tbuff, &pItem->_iFMinDam); - CopyInt(tbuff, &pItem->_iFMaxDam); - CopyInt(tbuff, &pItem->_iLMinDam); - CopyInt(tbuff, &pItem->_iLMaxDam); - CopyInt(tbuff, &pItem->_iPLEnAc); - CopyChar(tbuff, &pItem->_iPrePower); - CopyChar(tbuff, &pItem->_iSufPower); - tbuff += 2; - CopyInt(tbuff, &pItem->_iVAdd1); - CopyInt(tbuff, &pItem->_iVMult1); - CopyInt(tbuff, &pItem->_iVAdd2); - CopyInt(tbuff, &pItem->_iVMult2); - CopyChar(tbuff, &pItem->_iMinStr); - CopyChar(tbuff, &pItem->_iMinMag); - CopyChar(tbuff, &pItem->_iMinDex); - tbuff += 1; - CopyInt(tbuff, &pItem->_iStatFlag); - CopyInt(tbuff, &pItem->IDidx); - CopyInt(tbuff, &pItem->offs016C); -} - -void CopyItems(const int n, ItemStruct *pItem) -{ - for (int i = 0; i < n; i++) { - CopyItem(&pItem[i]); - } -} - -void SaveItem(ItemStruct *pItem) -{ - CopyInt(&pItem->_iSeed, tbuff); - CopyShort(&pItem->_iCreateInfo, tbuff); - tbuff += 2; - CopyInt(&pItem->_itype, tbuff); - CopyInt(&pItem->_ix, tbuff); - CopyInt(&pItem->_iy, tbuff); - CopyInt(&pItem->_iAnimFlag, tbuff); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(&pItem->_iAnimLen, tbuff); - CopyInt(&pItem->_iAnimFrame, tbuff); - CopyInt(&pItem->_iAnimWidth, tbuff); - CopyInt(&pItem->_iAnimWidth2, tbuff); // width 2? - CopyInt(&pItem->_isin, tbuff); // set when item is flagged for deletion, deprecated in 1.02 - CopyChar(&pItem->_iSelFlag, tbuff); - tbuff += 3; - CopyInt(&pItem->_iPostDraw, tbuff); - CopyInt(&pItem->_iIdentified, tbuff); - CopyChar(&pItem->_iMagical, tbuff); - CopyBytes(&pItem->_iName, 64, tbuff); - CopyBytes(&pItem->_iIName, 64, tbuff); - CopyChar(&pItem->_iLoc, tbuff); - CopyChar(&pItem->_iClass, tbuff); - tbuff += 1; - CopyInt(&pItem->_iCurs, tbuff); - CopyInt(&pItem->_ivalue, tbuff); - CopyInt(&pItem->_iIvalue, tbuff); - CopyInt(&pItem->_iMinDam, tbuff); - CopyInt(&pItem->_iMaxDam, tbuff); - CopyInt(&pItem->_iAC, tbuff); - CopyInt(&pItem->_iFlags, tbuff); - CopyInt(&pItem->_iMiscId, tbuff); - CopyInt(&pItem->_iSpell, tbuff); - CopyInt(&pItem->_iCharges, tbuff); - CopyInt(&pItem->_iMaxCharges, tbuff); - CopyInt(&pItem->_iDurability, tbuff); - CopyInt(&pItem->_iMaxDur, tbuff); - CopyInt(&pItem->_iPLDam, tbuff); - CopyInt(&pItem->_iPLToHit, tbuff); - CopyInt(&pItem->_iPLAC, tbuff); - CopyInt(&pItem->_iPLStr, tbuff); - CopyInt(&pItem->_iPLMag, tbuff); - CopyInt(&pItem->_iPLDex, tbuff); - CopyInt(&pItem->_iPLVit, tbuff); - CopyInt(&pItem->_iPLFR, tbuff); - CopyInt(&pItem->_iPLLR, tbuff); - CopyInt(&pItem->_iPLMR, tbuff); - CopyInt(&pItem->_iPLMana, tbuff); - CopyInt(&pItem->_iPLHP, tbuff); - CopyInt(&pItem->_iPLDamMod, tbuff); - CopyInt(&pItem->_iPLGetHit, tbuff); - CopyInt(&pItem->_iPLLight, tbuff); - CopyChar(&pItem->_iSplLvlAdd, tbuff); - CopyChar(&pItem->_iRequest, tbuff); - tbuff += 2; - CopyInt(&pItem->_iUid, tbuff); - CopyInt(&pItem->_iFMinDam, tbuff); - CopyInt(&pItem->_iFMaxDam, tbuff); - CopyInt(&pItem->_iLMinDam, tbuff); - CopyInt(&pItem->_iLMaxDam, tbuff); - CopyInt(&pItem->_iPLEnAc, tbuff); - CopyChar(&pItem->_iPrePower, tbuff); - CopyChar(&pItem->_iSufPower, tbuff); - tbuff += 2; - CopyInt(&pItem->_iVAdd1, tbuff); - CopyInt(&pItem->_iVMult1, tbuff); - CopyInt(&pItem->_iVAdd2, tbuff); - CopyInt(&pItem->_iVMult2, tbuff); - CopyChar(&pItem->_iMinStr, tbuff); - CopyChar(&pItem->_iMinMag, tbuff); - CopyChar(&pItem->_iMinDex, tbuff); - tbuff += 1; - CopyInt(&pItem->_iStatFlag, tbuff); - CopyInt(&pItem->IDidx, tbuff); - CopyInt(&pItem->offs016C, tbuff); -} - -void SaveItems(ItemStruct *pItem, const int n) -{ - for (int i = 0; i < n; i++) { - SaveItem(&pItem[i]); - } -} - -void LoadPremium(int i) -{ - CopyItem(&item[i]); -} - -void LoadQuest(int i) -{ - memcpy(&quests[i], tbuff, sizeof(*quests)); - tbuff += sizeof(*quests); - ReturnLvlX = WLoad(); - ReturnLvlY = WLoad(); - ReturnLvl = WLoad(); - ReturnLvlT = WLoad(); - DoomQuestState = WLoad(); -} - -void LoadLighting(int i) -{ - memcpy(&LightList[i], tbuff, sizeof(*LightList)); - tbuff += sizeof(*LightList); -} - -void LoadVision(int i) -{ - memcpy(&VisionList[i], tbuff, sizeof(*VisionList)); - tbuff += sizeof(*VisionList); -} - -void LoadPortal(int i) -{ - memcpy(&portal[i], tbuff, sizeof(*portal)); - tbuff += sizeof(*portal); -} - -void SaveGame() -{ - int i, j; - char szName[MAX_PATH]; - - DWORD dwLen = codec_get_encoded_len(FILEBUFF); - BYTE *SaveBuff = DiabloAllocPtr(dwLen); - tbuff = SaveBuff; - - ISave('RETL'); - OSave((unsigned char)setlevel); - WSave(setlvlnum); - WSave(currlevel); - WSave((unsigned char)leveltype); - WSave(ViewX); - WSave(ViewY); - OSave(invflag); - OSave(chrflag); - WSave(nummonsters); - WSave(numitems); - WSave(nummissiles); - WSave(nobjects); - - for (i = 0; i < NUMLEVELS; i++) { - ISave(glSeedTbl[i]); - WSave(gnLevelTypeTbl[i]); - } - - SavePlayer(myplr); - - for (i = 0; i < MAXQUESTS; i++) - SaveQuest(i); - for (i = 0; i < MAXPORTAL; i++) - SavePortal(i); - for (i = 0; i < MAXMONSTERS; i++) - ISave(monstkills[i]); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - WSave(monstactive[i]); - for (i = 0; i < nummonsters; i++) - SaveMonster(monstactive[i]); - for (i = 0; i < MAXMISSILES; i++) - BSave(missileactive[i]); - for (i = 0; i < MAXMISSILES; i++) - BSave(missileavail[i]); - for (i = 0; i < nummissiles; i++) - SaveMissile(missileactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - BSave(objectactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - BSave(objectavail[i]); - for (i = 0; i < nobjects; i++) - SaveObject(objectactive[i]); - - WSave(numlights); - - for (i = 0; i < MAXLIGHTS; i++) - BSave(lightactive[i]); - for (i = 0; i < numlights; i++) - SaveLighting(lightactive[i]); - - WSave(visionid); - WSave(numvision); - - for (i = 0; i < numvision; i++) - SaveVision(i); - } - - for (i = 0; i < MAXITEMS; i++) - BSave(itemactive[i]); - for (i = 0; i < MAXITEMS; i++) - BSave(itemavail[i]); - for (i = 0; i < numitems; i++) - SaveItem(&item[itemactive[i]]); - for (i = 0; i < 128; i++) - OSave(UniqueItemFlag[i]); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dPlayer[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dItem[i][j]); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - WSave(dMonster[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dDead[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dObject[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dPreLight[i][j]); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - OSave(automapview[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dMissile[i][j]); - } - } - - WSave(numpremium); - WSave(premiumlevel); - - for (i = 0; i < 6; i++) - SavePremium(i); - - OSave(automapflag); - WSave(AutoMapScale); - pfile_get_game_name(szName); - dwLen = codec_get_encoded_len(tbuff - SaveBuff); - pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); - mem_free_dbg(SaveBuff); - gbValidSaveFile = TRUE; - pfile_rename_temp_to_perm(); - pfile_write_hero(); -} - -void BSave(char v) -{ - *tbuff++ = v; -} - -void WSave(int v) -{ - *tbuff++ = v >> 24; - *tbuff++ = v >> 16; - *tbuff++ = v >> 8; - *tbuff++ = v; -} - -void ISave(int v) -{ - *tbuff++ = v >> 24; - *tbuff++ = v >> 16; - *tbuff++ = v >> 8; - *tbuff++ = v; -} - -void OSave(BOOL v) -{ - if (v != FALSE) - *tbuff++ = TRUE; - else - *tbuff++ = FALSE; -} - -void SaveMonster(int i) -{ - MonsterStruct *pMonster = &monster[i]; - - CopyInt(&pMonster->_mMTidx, tbuff); - CopyInt(&pMonster->_mmode, tbuff); - - CopyChar(&pMonster->_mgoal, tbuff); - tbuff += 3; - - CopyInt(&pMonster->_mgoalvar1, tbuff); - CopyInt(&pMonster->_mgoalvar2, tbuff); - CopyInt(&pMonster->_mgoalvar3, tbuff); - CopyInt(&pMonster->field_18, tbuff); - - CopyChar(&pMonster->_pathcount, tbuff); - tbuff += 3; - - CopyInt(&pMonster->_mx, tbuff); - CopyInt(&pMonster->_my, tbuff); - CopyInt(&pMonster->_mfutx, tbuff); - CopyInt(&pMonster->_mfuty, tbuff); - CopyInt(&pMonster->_moldx, tbuff); - CopyInt(&pMonster->_moldy, tbuff); - CopyInt(&pMonster->_mxoff, tbuff); - CopyInt(&pMonster->_myoff, tbuff); - CopyInt(&pMonster->_mxvel, tbuff); - CopyInt(&pMonster->_myvel, tbuff); - CopyInt(&pMonster->_mdir, tbuff); - CopyInt(&pMonster->_menemy, tbuff); - - CopyChar(&pMonster->_menemyx, tbuff); - CopyChar(&pMonster->_menemyy, tbuff); - CopyShort(&pMonster->falign_52, tbuff); - - tbuff += 4; // Skip pointer - CopyInt(&pMonster->_mAnimDelay, tbuff); - CopyInt(&pMonster->_mAnimCnt, tbuff); - CopyInt(&pMonster->_mAnimLen, tbuff); - CopyInt(&pMonster->_mAnimFrame, tbuff); - CopyInt(&pMonster->_meflag, tbuff); - CopyInt(&pMonster->_mDelFlag, tbuff); - CopyInt(&pMonster->_mVar1, tbuff); - CopyInt(&pMonster->_mVar2, tbuff); - CopyInt(&pMonster->_mVar3, tbuff); - CopyInt(&pMonster->_mVar4, tbuff); - CopyInt(&pMonster->_mVar5, tbuff); - CopyInt(&pMonster->_mVar6, tbuff); - CopyInt(&pMonster->_mVar7, tbuff); - CopyInt(&pMonster->_mVar8, tbuff); - CopyInt(&pMonster->_mmaxhp, tbuff); - CopyInt(&pMonster->_mhitpoints, tbuff); - - CopyChar(&pMonster->_mAi, tbuff); - CopyChar(&pMonster->_mint, tbuff); - CopyShort(&pMonster->falign_9A, tbuff); - - CopyInt(&pMonster->_mFlags, tbuff); - - CopyChar(&pMonster->_msquelch, tbuff); - tbuff += 3; - - CopyInt(&pMonster->falign_A4, tbuff); - CopyInt(&pMonster->_lastx, tbuff); - CopyInt(&pMonster->_lasty, tbuff); - CopyInt(&pMonster->_mRndSeed, tbuff); - CopyInt(&pMonster->_mAISeed, tbuff); - CopyInt(&pMonster->falign_B8, tbuff); - - CopyChar(&pMonster->_uniqtype, tbuff); - CopyChar(&pMonster->_uniqtrans, tbuff); - CopyChar(&pMonster->_udeadval, tbuff); - CopyChar(&pMonster->mWhoHit, tbuff); - - CopyChar(&pMonster->mLevel, tbuff); - CopyShort(&pMonster->mExp, tbuff); - tbuff += 1; - - CopyChar(&pMonster->mHit, tbuff); - CopyChar(&pMonster->mMinDamage, tbuff); - CopyChar(&pMonster->mMaxDamage, tbuff); - CopyChar(&pMonster->mHit2, tbuff); - - CopyChar(&pMonster->mMinDamage2, tbuff); - CopyChar(&pMonster->mMaxDamage2, tbuff); - CopyChar(&pMonster->mArmorClass, tbuff); - CopyChar(&pMonster->falign_CB, tbuff); - - CopyShort(&pMonster->mMagicRes, tbuff); - tbuff += 2; - - CopyInt(&pMonster->mtalkmsg, tbuff); - - CopyChar(&pMonster->leader, tbuff); - CopyChar(&pMonster->leaderflag, tbuff); - CopyChar(&pMonster->packsize, tbuff); - CopyChar(&pMonster->mlid, tbuff); -} - -void SaveMissile(int i) -{ - MissileStruct *pMissile = &missile[i]; - - CopyInt(&pMissile->_mitype, tbuff); - CopyInt(&pMissile->_mix, tbuff); - CopyInt(&pMissile->_miy, tbuff); - CopyInt(&pMissile->_mixoff, tbuff); - CopyInt(&pMissile->_miyoff, tbuff); - CopyInt(&pMissile->_mixvel, tbuff); - CopyInt(&pMissile->_miyvel, tbuff); - CopyInt(&pMissile->_misx, tbuff); - CopyInt(&pMissile->_misy, tbuff); - CopyInt(&pMissile->_mitxoff, tbuff); - CopyInt(&pMissile->_mityoff, tbuff); - CopyInt(&pMissile->_mimfnum, tbuff); - CopyInt(&pMissile->_mispllvl, tbuff); - CopyInt(&pMissile->_miDelFlag, tbuff); - CopyChar(&pMissile->_miAnimType, tbuff); - tbuff += 3; - - CopyInt(&pMissile->_miAnimFlags, tbuff); - tbuff += 4; - CopyInt(&pMissile->_miAnimDelay, tbuff); - CopyInt(&pMissile->_miAnimLen, tbuff); - CopyInt(&pMissile->_miAnimWidth, tbuff); - CopyInt(&pMissile->_miAnimWidth2, tbuff); - CopyInt(&pMissile->_miAnimCnt, tbuff); - CopyInt(&pMissile->_miAnimAdd, tbuff); - CopyInt(&pMissile->_miAnimFrame, tbuff); - CopyInt(&pMissile->_miDrawFlag, tbuff); - CopyInt(&pMissile->_miLightFlag, tbuff); - CopyInt(&pMissile->_miPreFlag, tbuff); - CopyInt(&pMissile->_miUniqTrans, tbuff); - CopyInt(&pMissile->_mirange, tbuff); - CopyInt(&pMissile->_misource, tbuff); - CopyInt(&pMissile->_micaster, tbuff); - CopyInt(&pMissile->_midam, tbuff); - CopyInt(&pMissile->_miHitFlag, tbuff); - CopyInt(&pMissile->_midist, tbuff); - CopyInt(&pMissile->_mlid, tbuff); - CopyInt(&pMissile->_mirnd, tbuff); - CopyInt(&pMissile->_miVar1, tbuff); - CopyInt(&pMissile->_miVar2, tbuff); - CopyInt(&pMissile->_miVar3, tbuff); - CopyInt(&pMissile->_miVar4, tbuff); - CopyInt(&pMissile->_miVar5, tbuff); - CopyInt(&pMissile->_miVar6, tbuff); - CopyInt(&pMissile->_miVar7, tbuff); - CopyInt(&pMissile->_miVar8, tbuff); -} - -void SaveObject(int i) -{ - ObjectStruct *pObject = &object[i]; - CopyInt(tbuff, &pObject->_otype); - CopyInt(&pObject->_ox, tbuff); - CopyInt(&pObject->_oy, tbuff); - CopyInt(&pObject->_oLight, tbuff); - CopyInt(&pObject->_oAnimFlag, tbuff); - tbuff += 4; - CopyInt(&pObject->_oAnimDelay, tbuff); - CopyInt(&pObject->_oAnimCnt, tbuff); - CopyInt(&pObject->_oAnimLen, tbuff); - CopyInt(&pObject->_oAnimFrame, tbuff); - CopyInt(&pObject->_oAnimWidth, tbuff); - CopyInt(&pObject->_oAnimWidth2, tbuff); - CopyInt(&pObject->_oDelFlag, tbuff); - - CopyChar(&pObject->_oBreak, tbuff); - tbuff += 3; - - CopyInt(&pObject->_oSolidFlag, tbuff); - CopyInt(&pObject->_oMissFlag, tbuff); - - CopyChar(&pObject->_oSelFlag, tbuff); - tbuff += 3; - - CopyInt(&pObject->_oPreFlag, tbuff); - CopyInt(&pObject->_oTrapFlag, tbuff); - CopyInt(&pObject->_oDoorFlag, tbuff); - CopyInt(&pObject->_olid, tbuff); - CopyInt(&pObject->_oRndSeed, tbuff); - CopyInt(&pObject->_oVar1, tbuff); - CopyInt(&pObject->_oVar2, tbuff); - CopyInt(&pObject->_oVar3, tbuff); - CopyInt(&pObject->_oVar4, tbuff); - CopyInt(&pObject->_oVar5, tbuff); - CopyInt(&pObject->_oVar6, tbuff); - CopyInt(&pObject->_oVar7, tbuff); - CopyInt(&pObject->_oVar8, tbuff); -} - -void SavePremium(int i) -{ - SaveItem(&item[i]); -} - -void SaveQuest(int i) -{ - memcpy(tbuff, &quests[i], sizeof(*quests)); - tbuff += sizeof(*quests); - WSave(ReturnLvlX); - WSave(ReturnLvlY); - WSave(ReturnLvl); - WSave(ReturnLvlT); - WSave(DoomQuestState); -} - -void SaveLighting(int i) -{ - memcpy(tbuff, &LightList[i], sizeof(*LightList)); - tbuff += sizeof(*LightList); -} - -void SaveVision(int i) -{ - memcpy(tbuff, &VisionList[i], sizeof(*VisionList)); - tbuff += sizeof(*VisionList); -} - -void SavePortal(int i) -{ - memcpy(tbuff, &portal[i], sizeof(*portal)); - tbuff += sizeof(*portal); -} - -void SaveLevel() -{ - int i, j; - char szName[MAX_PATH]; - int dwLen; - unsigned char *SaveBuff; - - if (!currlevel) - glSeedTbl[0] = GetRndSeed(); - - dwLen = codec_get_encoded_len(FILEBUFF); - SaveBuff = DiabloAllocPtr(dwLen); - tbuff = SaveBuff; - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dDead[i][j]); - } - } - - WSave(nummonsters); - WSave(numitems); - WSave(nobjects); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - WSave(monstactive[i]); - for (i = 0; i < nummonsters; i++) - SaveMonster(monstactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - BSave(objectactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - BSave(objectavail[i]); - for (i = 0; i < nobjects; i++) - SaveObject(objectactive[i]); - } - - for (i = 0; i < MAXITEMS; i++) - BSave(itemactive[i]); - for (i = 0; i < MAXITEMS; i++) - BSave(itemavail[i]); - for (i = 0; i < numitems; i++) - SaveItem(&item[itemactive[i]]); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dItem[i][j]); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - WSave(dMonster[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dObject[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dPreLight[i][j]); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - OSave(automapview[i][j]); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dMissile[i][j]); - } - } - - GetTempLevelNames(szName); - dwLen = codec_get_encoded_len(tbuff - SaveBuff); - pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); - mem_free_dbg(SaveBuff); - - if (setlevel == 0) - plr[myplr]._pLvlVisited[currlevel] = 1; - else - plr[myplr]._pSLvlVisited[setlvlnum] = 1; -} - -void LoadLevel() -{ - int i, j; - DWORD dwLen; - char szName[MAX_PATH]; - BYTE *LoadBuff; - - GetPermLevelNames(szName); - LoadBuff = pfile_read(szName, &dwLen); - tbuff = LoadBuff; - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dDead[i][j] = BLoad(); - } - SetDead(); - } - - nummonsters = WLoad(); - numitems = WLoad(); - nobjects = WLoad(); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - monstactive[i] = WLoad(); - for (i = 0; i < nummonsters; i++) - LoadMonster(monstactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - objectactive[i] = BLoad(); - for (i = 0; i < MAXOBJECTS; i++) - objectavail[i] = BLoad(); - for (i = 0; i < nobjects; i++) - LoadObject(objectactive[i]); - for (i = 0; i < nobjects; i++) - SyncObjectAnim(objectactive[i]); - } - - for (i = 0; i < MAXITEMS; i++) - itemactive[i] = BLoad(); - for (i = 0; i < MAXITEMS; i++) - itemavail[i] = BLoad(); - for (i = 0; i < numitems; i++) - LoadItem(itemactive[i]); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dFlags[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dItem[i][j] = BLoad(); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMonster[i][j] = WLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dObject[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPreLight[i][j] = BLoad(); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - automapview[i][j] = OLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMissile[i][j] = 0; /// BUGFIX: supposed to load saved missiles with "BLoad()"? - } - } - - AutomapZoomReset(); - ResyncQuests(); - SyncPortals(); - dolighting = 1; - - for (i = 0; i < MAX_PLRS; i++) { - if (plr[i].plractive && currlevel == plr[i].plrlevel) - LightList[plr[i]._plid]._lunflag = 1; - } - - mem_free_dbg(LoadBuff); -} - -DEVILUTION_END_NAMESPACE +#include "diablo.h" + +DEVILUTION_BEGIN_NAMESPACE + +BYTE *tbuff; + +void LoadGame(BOOL firstflag) +{ + int i, j; + DWORD dwLen; + char szName[MAX_PATH]; + BYTE *LoadBuff; + int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects; + + FreeGameMem(); + pfile_remove_temp_files(); + pfile_get_game_name(szName); + LoadBuff = pfile_read(szName, &dwLen); + tbuff = LoadBuff; + + if (ILoad() != 'RETL') + app_fatal("Invalid save file"); + + setlevel = OLoad(); + setlvlnum = WLoad(); + currlevel = WLoad(); + leveltype = WLoad(); + _ViewX = WLoad(); + _ViewY = WLoad(); + invflag = OLoad(); + chrflag = OLoad(); + _nummonsters = WLoad(); + _numitems = WLoad(); + _nummissiles = WLoad(); + _nobjects = WLoad(); + + for (i = 0; i < NUMLEVELS; i++) { + glSeedTbl[i] = ILoad(); + gnLevelTypeTbl[i] = WLoad(); + } + + LoadPlayer(myplr); + + for (i = 0; i < MAXQUESTS; i++) + LoadQuest(i); + for (i = 0; i < MAXPORTAL; i++) + LoadPortal(i); + + LoadGameLevel(firstflag, 4); + SyncInitPlr(myplr); + SyncPlrAnim(myplr); + + ViewX = _ViewX; + ViewY = _ViewY; + nummonsters = _nummonsters; + numitems = _numitems; + nummissiles = _nummissiles; + nobjects = _nobjects; + + for (i = 0; i < MAXMONSTERS; i++) + monstkills[i] = ILoad(); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + monstactive[i] = WLoad(); + for (i = 0; i < nummonsters; i++) + LoadMonster(monstactive[i]); + for (i = 0; i < MAXMISSILES; i++) + missileactive[i] = BLoad(); + for (i = 0; i < MAXMISSILES; i++) + missileavail[i] = BLoad(); + for (i = 0; i < nummissiles; i++) + LoadMissile(missileactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + objectactive[i] = BLoad(); + for (i = 0; i < MAXOBJECTS; i++) + objectavail[i] = BLoad(); + for (i = 0; i < nobjects; i++) + LoadObject(objectactive[i]); + for (i = 0; i < nobjects; i++) + SyncObjectAnim(objectactive[i]); + + numlights = WLoad(); + + for (i = 0; i < MAXLIGHTS; i++) + lightactive[i] = BLoad(); + for (i = 0; i < numlights; i++) + LoadLighting(lightactive[i]); + + visionid = WLoad(); + numvision = WLoad(); + + for (i = 0; i < numvision; i++) + LoadVision(i); + } + + for (i = 0; i < MAXITEMS; i++) + itemactive[i] = BLoad(); + for (i = 0; i < MAXITEMS; i++) + itemavail[i] = BLoad(); + for (i = 0; i < numitems; i++) + LoadItem(itemactive[i]); + for (i = 0; i < 128; i++) + UniqueItemFlag[i] = OLoad(); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dLight[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dFlags[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dPlayer[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dItem[i][j] = BLoad(); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dMonster[i][j] = WLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dDead[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dObject[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dLight[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dPreLight[i][j] = BLoad(); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + automapview[i][j] = OLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dMissile[i][j] = BLoad(); + } + } + + numpremium = WLoad(); + premiumlevel = WLoad(); + + for (i = 0; i < 6; i++) + LoadPremium(i); + + automapflag = OLoad(); + AutoMapScale = WLoad(); + mem_free_dbg(LoadBuff); + AutomapZoomReset(); + ResyncQuests(); + + if (leveltype != DTYPE_TOWN) + ProcessLightList(); + + RedoPlayerVision(); + ProcessVisionList(); + missiles_process_charge(); + ResetPal(); + SetCursor_(CURSOR_HAND); + gbProcessPlayers = TRUE; +} + +char BLoad() +{ + return *tbuff++; +} + +int WLoad() +{ + int rv = *tbuff++ << 24; + rv |= *tbuff++ << 16; + rv |= *tbuff++ << 8; + rv |= *tbuff++; + + return rv; +} + +int ILoad() +{ + int rv = *tbuff++ << 24; + rv |= *tbuff++ << 16; + rv |= *tbuff++ << 8; + rv |= *tbuff++; + + return rv; +} + +BOOL OLoad() +{ + if (*tbuff++ == TRUE) + return TRUE; + else + return FALSE; +} + +void CopyInt(const void *src, void *dst) +{ + memcpy(dst, src, 4); + tbuff += 4; +} + +void CopyShort(const void *src, void *dst) +{ + memcpy(dst, src, 2); + tbuff += 2; +} + +void CopyShorts(const void *src, const int n, void *dst) +{ + memcpy(dst, src, 2 * n); + tbuff += 2 * n; +} + +void CopyInts(const void *src, const int n, void *dst) +{ + memcpy(dst, src, 4 * n); + tbuff += 4 * n; +} + +void CopyBytes(const void *src, const int n, void *dst) +{ + memcpy(dst, src, n); + tbuff += n; +} + +void CopyChar(const void *src, void *dst) +{ + memcpy(dst, src, 1); + tbuff += 1; +} + +void CopyInt64(const void *src, void *dst) +{ + memcpy(dst, src, 8); + tbuff += 8; +} + +void LoadPlayer(int i) +{ + PlayerStruct *pPlayer = &plr[i]; + + CopyInt(tbuff, &pPlayer->_pmode); + + CopyBytes(tbuff, 25, pPlayer->walkpath); + CopyBytes(tbuff, 1, &pPlayer->plractive); + tbuff += 2; + + CopyInt(tbuff, &pPlayer->destAction); + CopyInt(tbuff, &pPlayer->destParam1); + CopyInt(tbuff, &pPlayer->destParam2); + CopyInt(tbuff, &pPlayer->destParam3); + CopyInt(tbuff, &pPlayer->destParam4); + CopyInt(tbuff, &pPlayer->plrlevel); + CopyInt(tbuff, &pPlayer->WorldX); + CopyInt(tbuff, &pPlayer->WorldY); + CopyInt(tbuff, &pPlayer->_px); + CopyInt(tbuff, &pPlayer->_py); + CopyInt(tbuff, &pPlayer->_ptargx); + CopyInt(tbuff, &pPlayer->_ptargy); + CopyInt(tbuff, &pPlayer->_pownerx); + CopyInt(tbuff, &pPlayer->_pownery); + CopyInt(tbuff, &pPlayer->_poldx); + CopyInt(tbuff, &pPlayer->_poldy); + CopyInt(tbuff, &pPlayer->_pxoff); + CopyInt(tbuff, &pPlayer->_pyoff); + CopyInt(tbuff, &pPlayer->_pxvel); + CopyInt(tbuff, &pPlayer->_pyvel); + CopyInt(tbuff, &pPlayer->_pdir); + CopyInt(tbuff, &pPlayer->_nextdir); + CopyInt(tbuff, &pPlayer->_pgfxnum); + tbuff += 4; // Skip pointers + CopyInt(tbuff, &pPlayer->_pAnimDelay); + CopyInt(tbuff, &pPlayer->_pAnimCnt); + CopyInt(tbuff, &pPlayer->_pAnimLen); + CopyInt(tbuff, &pPlayer->_pAnimFrame); + CopyInt(tbuff, &pPlayer->_pAnimWidth); + CopyInt(tbuff, &pPlayer->_pAnimWidth2); + CopyInt(tbuff, &pPlayer->_peflag); + CopyInt(tbuff, &pPlayer->_plid); + CopyInt(tbuff, &pPlayer->_pvid); + + CopyInt(tbuff, &pPlayer->_pSpell); + CopyChar(tbuff, &pPlayer->_pSplType); + CopyChar(tbuff, &pPlayer->_pSplFrom); + tbuff += 2; + CopyInt(tbuff, &pPlayer->_pTSpell); + CopyChar(tbuff, &pPlayer->_pTSplType); + tbuff += 3; + CopyInt(tbuff, &pPlayer->_pRSpell); + CopyChar(tbuff, &pPlayer->_pRSplType); + tbuff += 3; + CopyInt(tbuff, &pPlayer->_pSBkSpell); + CopyChar(tbuff, &pPlayer->_pSBkSplType); + + CopyBytes(tbuff, 64, &pPlayer->_pSplLvl); + tbuff += 7; + CopyInt64(tbuff, &pPlayer->_pMemSpells); + CopyInt64(tbuff, &pPlayer->_pAblSpells); + CopyInt64(tbuff, &pPlayer->_pScrlSpells); + CopyChar(tbuff, &pPlayer->_pSpellFlags); + tbuff += 3; + CopyInts(tbuff, 4, &pPlayer->_pSplHotKey); + CopyBytes(tbuff, 4, &pPlayer->_pSplTHotKey); + CopyInt(tbuff, &pPlayer->_pwtype); + CopyChar(tbuff, &pPlayer->_pBlockFlag); + CopyChar(tbuff, &pPlayer->_pInvincible); + CopyChar(tbuff, &pPlayer->_pLightRad); + CopyChar(tbuff, &pPlayer->_pLvlChanging); + CopyBytes(tbuff, PLR_NAME_LEN, &pPlayer->_pName); + CopyChar(tbuff, &pPlayer->_pClass); + tbuff += 3; + CopyInt(tbuff, &pPlayer->_pStrength); + CopyInt(tbuff, &pPlayer->_pBaseStr); + CopyInt(tbuff, &pPlayer->_pMagic); + CopyInt(tbuff, &pPlayer->_pBaseMag); + CopyInt(tbuff, &pPlayer->_pDexterity); + CopyInt(tbuff, &pPlayer->_pBaseDex); + CopyInt(tbuff, &pPlayer->_pVitality); + CopyInt(tbuff, &pPlayer->_pBaseVit); + CopyInt(tbuff, &pPlayer->_pStatPts); + CopyInt(tbuff, &pPlayer->_pDamageMod); + CopyInt(tbuff, &pPlayer->_pBaseToBlk); + CopyInt(tbuff, &pPlayer->_pHPBase); + CopyInt(tbuff, &pPlayer->_pMaxHPBase); + CopyInt(tbuff, &pPlayer->_pHitPoints); + CopyInt(tbuff, &pPlayer->_pMaxHP); + CopyInt(tbuff, &pPlayer->_pHPPer); + CopyInt(tbuff, &pPlayer->_pManaBase); + CopyInt(tbuff, &pPlayer->_pMaxManaBase); + CopyInt(tbuff, &pPlayer->_pMana); + CopyInt(tbuff, &pPlayer->_pMaxMana); + CopyInt(tbuff, &pPlayer->_pManaPer); + CopyChar(tbuff, &pPlayer->_pLevel); + CopyChar(tbuff, &pPlayer->_pMaxLvl); + tbuff += 2; + CopyInt(tbuff, &pPlayer->_pExperience); + CopyInt(tbuff, &pPlayer->_pMaxExp); + CopyInt(tbuff, &pPlayer->_pNextExper); + CopyChar(tbuff, &pPlayer->_pArmorClass); + CopyChar(tbuff, &pPlayer->_pMagResist); + CopyChar(tbuff, &pPlayer->_pFireResist); + CopyChar(tbuff, &pPlayer->_pLghtResist); + CopyInt(tbuff, &pPlayer->_pGold); + CopyInt(tbuff, &pPlayer->_pInfraFlag); + CopyInt(tbuff, &pPlayer->_pVar1); + CopyInt(tbuff, &pPlayer->_pVar2); + CopyInt(tbuff, &pPlayer->_pVar3); + CopyInt(tbuff, &pPlayer->_pVar4); + CopyInt(tbuff, &pPlayer->_pVar5); + CopyInt(tbuff, &pPlayer->_pVar6); + CopyInt(tbuff, &pPlayer->_pVar7); + CopyInt(tbuff, &pPlayer->_pVar8); + CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pLvlVisited); + CopyBytes(tbuff, NUMLEVELS, &pPlayer->_pSLvlVisited); + tbuff += 2; + CopyInt(tbuff, &pPlayer->_pGFXLoad); + + tbuff += sizeof(DWORD) * 8; + CopyInt(tbuff, &pPlayer->_pNFrames); + CopyInt(tbuff, &pPlayer->_pNWidth); + + tbuff += sizeof(DWORD) * 8; + + CopyInt(tbuff, &pPlayer->_pWFrames); + CopyInt(tbuff, &pPlayer->_pWWidth); + + tbuff += sizeof(DWORD) * 8; + + CopyInt(tbuff, &pPlayer->_pAFrames); + CopyInt(tbuff, &pPlayer->_pAWidth); + CopyInt(tbuff, &pPlayer->_pAFNum); + + tbuff += sizeof(DWORD) * 24; + + CopyInt(tbuff, &pPlayer->_pSFrames); + CopyInt(tbuff, &pPlayer->_pSWidth); + CopyInt(tbuff, &pPlayer->_pSFNum); + + tbuff += sizeof(DWORD) * 8; + + CopyInt(tbuff, &pPlayer->_pHFrames); + CopyInt(tbuff, &pPlayer->_pHWidth); + + tbuff += sizeof(DWORD) * 8; + + CopyInt(tbuff, &pPlayer->_pDFrames); + CopyInt(tbuff, &pPlayer->_pDWidth); + + tbuff += sizeof(DWORD) * 8; + + CopyInt(tbuff, &pPlayer->_pBFrames); + CopyInt(tbuff, &pPlayer->_pBWidth); + CopyItems(NUM_INVLOC, pPlayer->InvBody); + CopyItems(NUM_INV_GRID_ELEM, pPlayer->InvList); + CopyInt(tbuff, &pPlayer->_pNumInv); + CopyBytes(tbuff, NUM_INV_GRID_ELEM, pPlayer->InvGrid); + CopyItems(MAXBELTITEMS, pPlayer->SpdList); + CopyItem(&pPlayer->HoldItem); + CopyInt(tbuff, &pPlayer->_pIMinDam); + CopyInt(tbuff, &pPlayer->_pIMaxDam); + CopyInt(tbuff, &pPlayer->_pIAC); + CopyInt(tbuff, &pPlayer->_pIBonusDam); + CopyInt(tbuff, &pPlayer->_pIBonusToHit); + CopyInt(tbuff, &pPlayer->_pIBonusAC); + CopyInt(tbuff, &pPlayer->_pIBonusDamMod); + tbuff += 4; + CopyInt64(tbuff, &pPlayer->_pISpells); + CopyInt(tbuff, &pPlayer->_pIFlags); + CopyInt(tbuff, &pPlayer->_pIGetHit); + + CopyChar(tbuff, &pPlayer->_pISplLvlAdd); + CopyChar(tbuff, &pPlayer->_pISplCost); + tbuff += 2; + + CopyInt(tbuff, &pPlayer->_pISplDur); + CopyInt(tbuff, &pPlayer->_pIEnAc); + CopyInt(tbuff, &pPlayer->_pIFMinDam); + CopyInt(tbuff, &pPlayer->_pIFMaxDam); + CopyInt(tbuff, &pPlayer->_pILMinDam); + CopyInt(tbuff, &pPlayer->_pILMaxDam); + CopyInt(tbuff, &pPlayer->_pOilType); + + CopyChar(tbuff, &pPlayer->pTownWarps); + CopyChar(tbuff, &pPlayer->pDungMsgs); + CopyChar(tbuff, &pPlayer->pLvlLoad); + CopyChar(tbuff, &pPlayer->pBattleNet); + + CopyChar(tbuff, &pPlayer->pManaShield); + CopyBytes(tbuff, 3, &pPlayer->bReserved); + + CopyShorts(tbuff, 8, &pPlayer->wReserved); + + CopyInt(tbuff, &pPlayer->pDiabloKillLevel); + CopyInts(tbuff, 7, &pPlayer->dwReserved); + + // Omit 10 pointers +} + +void SavePlayer(int i) +{ + PlayerStruct *pPlayer = &plr[i]; + + CopyInt(&pPlayer->_pmode, tbuff); + + CopyBytes(&pPlayer->walkpath, 25, tbuff); + CopyBytes(&pPlayer->plractive, 1, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->destAction, tbuff); + CopyInt(&pPlayer->destParam1, tbuff); + CopyInt(&pPlayer->destParam2, tbuff); + CopyInt(&pPlayer->destParam3, tbuff); + CopyInt(&pPlayer->destParam4, tbuff); + CopyInt(&pPlayer->plrlevel, tbuff); + CopyInt(&pPlayer->WorldX, tbuff); + CopyInt(&pPlayer->WorldY, tbuff); + CopyInt(&pPlayer->_px, tbuff); + CopyInt(&pPlayer->_py, tbuff); + CopyInt(&pPlayer->_ptargx, tbuff); + CopyInt(&pPlayer->_ptargy, tbuff); + CopyInt(&pPlayer->_pownerx, tbuff); + CopyInt(&pPlayer->_pownery, tbuff); + CopyInt(&pPlayer->_poldx, tbuff); + CopyInt(&pPlayer->_poldy, tbuff); + CopyInt(&pPlayer->_pxoff, tbuff); + CopyInt(&pPlayer->_pyoff, tbuff); + CopyInt(&pPlayer->_pxvel, tbuff); + CopyInt(&pPlayer->_pyvel, tbuff); + CopyInt(&pPlayer->_pdir, tbuff); + CopyInt(&pPlayer->_nextdir, tbuff); + CopyInt(&pPlayer->_pgfxnum, tbuff); + tbuff += 4; // Skip pointers + CopyInt(&pPlayer->_pAnimDelay, tbuff); + CopyInt(&pPlayer->_pAnimCnt, tbuff); + CopyInt(&pPlayer->_pAnimLen, tbuff); + CopyInt(&pPlayer->_pAnimFrame, tbuff); + CopyInt(&pPlayer->_pAnimWidth, tbuff); + CopyInt(&pPlayer->_pAnimWidth2, tbuff); + CopyInt(&pPlayer->_peflag, tbuff); + CopyInt(&pPlayer->_plid, tbuff); + CopyInt(&pPlayer->_pvid, tbuff); + + CopyInt(&pPlayer->_pSpell, tbuff); + + CopyChar(&pPlayer->_pSplType, tbuff); + CopyChar(&pPlayer->_pSplFrom, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->_pTSpell, tbuff); + CopyChar(&pPlayer->_pTSplType, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pRSpell, tbuff); + CopyChar(&pPlayer->_pRSplType, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pSBkSpell, tbuff); + CopyChar(&pPlayer->_pSBkSplType, tbuff); + + CopyBytes(&pPlayer->_pSplLvl, 64, tbuff); + tbuff += 7; + CopyInt64(&pPlayer->_pMemSpells, tbuff); + CopyInt64(&pPlayer->_pAblSpells, tbuff); + CopyInt64(&pPlayer->_pScrlSpells, tbuff); + CopyChar(&pPlayer->_pSpellFlags, tbuff); + tbuff += 3; + CopyInts(&pPlayer->_pSplHotKey, 4, tbuff); + CopyBytes(&pPlayer->_pSplTHotKey, 4, tbuff); + CopyInt(&pPlayer->_pwtype, tbuff); + CopyChar(&pPlayer->_pBlockFlag, tbuff); + CopyChar(&pPlayer->_pInvincible, tbuff); + CopyChar(&pPlayer->_pLightRad, tbuff); + CopyChar(&pPlayer->_pLvlChanging, tbuff); + CopyBytes(&pPlayer->_pName, PLR_NAME_LEN, tbuff); + CopyChar(&pPlayer->_pClass, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pStrength, tbuff); + CopyInt(&pPlayer->_pBaseStr, tbuff); + CopyInt(&pPlayer->_pMagic, tbuff); + CopyInt(&pPlayer->_pBaseMag, tbuff); + CopyInt(&pPlayer->_pDexterity, tbuff); + CopyInt(&pPlayer->_pBaseDex, tbuff); + CopyInt(&pPlayer->_pVitality, tbuff); + CopyInt(&pPlayer->_pBaseVit, tbuff); + CopyInt(&pPlayer->_pStatPts, tbuff); + CopyInt(&pPlayer->_pDamageMod, tbuff); + CopyInt(&pPlayer->_pBaseToBlk, tbuff); + CopyInt(&pPlayer->_pHPBase, tbuff); + CopyInt(&pPlayer->_pMaxHPBase, tbuff); + CopyInt(&pPlayer->_pHitPoints, tbuff); + CopyInt(&pPlayer->_pMaxHP, tbuff); + CopyInt(&pPlayer->_pHPPer, tbuff); + CopyInt(&pPlayer->_pManaBase, tbuff); + CopyInt(&pPlayer->_pMaxManaBase, tbuff); + CopyInt(&pPlayer->_pMana, tbuff); + CopyInt(&pPlayer->_pMaxMana, tbuff); + CopyInt(&pPlayer->_pManaPer, tbuff); + CopyChar(&pPlayer->_pLevel, tbuff); + CopyChar(&pPlayer->_pMaxLvl, tbuff); + tbuff += 2; + CopyInt(&pPlayer->_pExperience, tbuff); + CopyInt(&pPlayer->_pMaxExp, tbuff); + CopyInt(&pPlayer->_pNextExper, tbuff); + CopyChar(&pPlayer->_pArmorClass, tbuff); + CopyChar(&pPlayer->_pMagResist, tbuff); + CopyChar(&pPlayer->_pFireResist, tbuff); + CopyChar(&pPlayer->_pLghtResist, tbuff); + CopyInt(&pPlayer->_pGold, tbuff); + CopyInt(&pPlayer->_pInfraFlag, tbuff); + CopyInt(&pPlayer->_pVar1, tbuff); + CopyInt(&pPlayer->_pVar2, tbuff); + CopyInt(&pPlayer->_pVar3, tbuff); + CopyInt(&pPlayer->_pVar4, tbuff); + CopyInt(&pPlayer->_pVar5, tbuff); + CopyInt(&pPlayer->_pVar6, tbuff); + CopyInt(&pPlayer->_pVar7, tbuff); + CopyInt(&pPlayer->_pVar8, tbuff); + CopyBytes(&pPlayer->_pLvlVisited, NUMLEVELS, tbuff); + CopyBytes(&pPlayer->_pSLvlVisited, NUMLEVELS, tbuff); // only 10 used + tbuff += 2; + CopyInt(&pPlayer->_pGFXLoad, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + CopyInt(&pPlayer->_pNFrames, tbuff); + CopyInt(&pPlayer->_pNWidth, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pWFrames, tbuff); + CopyInt(&pPlayer->_pWWidth, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pAFrames, tbuff); + CopyInt(&pPlayer->_pAWidth, tbuff); + CopyInt(&pPlayer->_pAFNum, tbuff); + + tbuff += sizeof(DWORD) * 24; // Skip 24 pointers + + CopyInt(&pPlayer->_pSFrames, tbuff); + CopyInt(&pPlayer->_pSWidth, tbuff); + CopyInt(&pPlayer->_pSFNum, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pHFrames, tbuff); + CopyInt(&pPlayer->_pHWidth, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pDFrames, tbuff); + CopyInt(&pPlayer->_pDWidth, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pBFrames, tbuff); + CopyInt(&pPlayer->_pBWidth, tbuff); + SaveItems(pPlayer->InvBody, NUM_INVLOC); + SaveItems(pPlayer->InvList, NUM_INV_GRID_ELEM); + CopyInt(&pPlayer->_pNumInv, tbuff); + CopyBytes(pPlayer->InvGrid, NUM_INV_GRID_ELEM, tbuff); + SaveItems(pPlayer->SpdList, MAXBELTITEMS); + SaveItem(&pPlayer->HoldItem); + CopyInt(&pPlayer->_pIMinDam, tbuff); + CopyInt(&pPlayer->_pIMaxDam, tbuff); + CopyInt(&pPlayer->_pIAC, tbuff); + CopyInt(&pPlayer->_pIBonusDam, tbuff); + CopyInt(&pPlayer->_pIBonusToHit, tbuff); + CopyInt(&pPlayer->_pIBonusAC, tbuff); + CopyInt(&pPlayer->_pIBonusDamMod, tbuff); + tbuff += 4; + CopyInt64(&pPlayer->_pISpells, tbuff); + CopyInt(&pPlayer->_pIFlags, tbuff); + CopyInt(&pPlayer->_pIGetHit, tbuff); + + CopyChar(&pPlayer->_pISplLvlAdd, tbuff); + CopyChar(&pPlayer->_pISplCost, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->_pISplDur, tbuff); + CopyInt(&pPlayer->_pIEnAc, tbuff); + CopyInt(&pPlayer->_pIFMinDam, tbuff); + CopyInt(&pPlayer->_pIFMaxDam, tbuff); + CopyInt(&pPlayer->_pILMinDam, tbuff); + CopyInt(&pPlayer->_pILMaxDam, tbuff); + CopyInt(&pPlayer->_pOilType, tbuff); + + CopyChar(&pPlayer->pTownWarps, tbuff); + CopyChar(&pPlayer->pDungMsgs, tbuff); + CopyChar(&pPlayer->pLvlLoad, tbuff); + CopyChar(&pPlayer->pBattleNet, tbuff); + + CopyChar(&pPlayer->pManaShield, tbuff); + CopyBytes(&pPlayer->bReserved, 3, tbuff); + + CopyShorts(&pPlayer->wReserved, 8, tbuff); + + CopyInt(&pPlayer->pDiabloKillLevel, tbuff); + CopyInts(&pPlayer->dwReserved, 7, tbuff); + + // Omit 10 pointers +} + +void LoadMonster(int i) +{ + MonsterStruct *pMonster = &monster[i]; + + CopyInt(tbuff, &pMonster->_mMTidx); + CopyInt(tbuff, &pMonster->_mmode); + + CopyChar(tbuff, &pMonster->_mgoal); + tbuff += 3; + + CopyInt(tbuff, &pMonster->_mgoalvar1); + CopyInt(tbuff, &pMonster->_mgoalvar2); + CopyInt(tbuff, &pMonster->_mgoalvar3); + CopyInt(tbuff, &pMonster->field_18); + + CopyChar(tbuff, &pMonster->_pathcount); + tbuff += 3; + + CopyInt(tbuff, &pMonster->_mx); + CopyInt(tbuff, &pMonster->_my); + CopyInt(tbuff, &pMonster->_mfutx); + CopyInt(tbuff, &pMonster->_mfuty); + CopyInt(tbuff, &pMonster->_moldx); + CopyInt(tbuff, &pMonster->_moldy); + CopyInt(tbuff, &pMonster->_mxoff); + CopyInt(tbuff, &pMonster->_myoff); + CopyInt(tbuff, &pMonster->_mxvel); + CopyInt(tbuff, &pMonster->_myvel); + CopyInt(tbuff, &pMonster->_mdir); + CopyInt(tbuff, &pMonster->_menemy); + + CopyChar(tbuff, &pMonster->_menemyx); + CopyChar(tbuff, &pMonster->_menemyy); + CopyShort(tbuff, &pMonster->falign_52); + + tbuff += 4; // Skip pointer + CopyInt(tbuff, &pMonster->_mAnimDelay); + CopyInt(tbuff, &pMonster->_mAnimCnt); + CopyInt(tbuff, &pMonster->_mAnimLen); + CopyInt(tbuff, &pMonster->_mAnimFrame); + CopyInt(tbuff, &pMonster->_meflag); + CopyInt(tbuff, &pMonster->_mDelFlag); + CopyInt(tbuff, &pMonster->_mVar1); + CopyInt(tbuff, &pMonster->_mVar2); + CopyInt(tbuff, &pMonster->_mVar3); + CopyInt(tbuff, &pMonster->_mVar4); + CopyInt(tbuff, &pMonster->_mVar5); + CopyInt(tbuff, &pMonster->_mVar6); + CopyInt(tbuff, &pMonster->_mVar7); + CopyInt(tbuff, &pMonster->_mVar8); + CopyInt(tbuff, &pMonster->_mmaxhp); + CopyInt(tbuff, &pMonster->_mhitpoints); + + CopyChar(tbuff, &pMonster->_mAi); + CopyChar(tbuff, &pMonster->_mint); + CopyShort(tbuff, &pMonster->falign_9A); + + CopyInt(tbuff, &pMonster->_mFlags); + + CopyChar(tbuff, &pMonster->_msquelch); + tbuff += 3; + + CopyInt(tbuff, &pMonster->falign_A4); + CopyInt(tbuff, &pMonster->_lastx); + CopyInt(tbuff, &pMonster->_lasty); + CopyInt(tbuff, &pMonster->_mRndSeed); + CopyInt(tbuff, &pMonster->_mAISeed); + CopyInt(tbuff, &pMonster->falign_B8); + + CopyChar(tbuff, &pMonster->_uniqtype); + CopyChar(tbuff, &pMonster->_uniqtrans); + CopyChar(tbuff, &pMonster->_udeadval); + CopyChar(tbuff, &pMonster->mWhoHit); + + CopyChar(tbuff, &pMonster->mLevel); + CopyShort(tbuff, &pMonster->mExp); + tbuff += 1; + + CopyChar(tbuff, &pMonster->mHit); + CopyChar(tbuff, &pMonster->mMinDamage); + CopyChar(tbuff, &pMonster->mMaxDamage); + CopyChar(tbuff, &pMonster->mHit2); + + CopyChar(tbuff, &pMonster->mMinDamage2); + CopyChar(tbuff, &pMonster->mMaxDamage2); + CopyChar(tbuff, &pMonster->mArmorClass); + CopyChar(tbuff, &pMonster->falign_CB); + + CopyShort(tbuff, &pMonster->mMagicRes); + tbuff += 2; + + CopyInt(tbuff, &pMonster->mtalkmsg); + + CopyChar(tbuff, &pMonster->leader); + CopyChar(tbuff, &pMonster->leaderflag); + CopyChar(tbuff, &pMonster->packsize); + CopyChar(tbuff, &pMonster->mlid); + + SyncMonsterAnim(i); +} + +void LoadMissile(int i) +{ + MissileStruct *pMissile = &missile[i]; + + CopyInt(tbuff, &pMissile->_mitype); + CopyInt(tbuff, &pMissile->_mix); + CopyInt(tbuff, &pMissile->_miy); + CopyInt(tbuff, &pMissile->_mixoff); + CopyInt(tbuff, &pMissile->_miyoff); + CopyInt(tbuff, &pMissile->_mixvel); + CopyInt(tbuff, &pMissile->_miyvel); + CopyInt(tbuff, &pMissile->_misx); + CopyInt(tbuff, &pMissile->_misy); + CopyInt(tbuff, &pMissile->_mitxoff); + CopyInt(tbuff, &pMissile->_mityoff); + CopyInt(tbuff, &pMissile->_mimfnum); + CopyInt(tbuff, &pMissile->_mispllvl); + CopyInt(tbuff, &pMissile->_miDelFlag); + CopyChar(tbuff, &pMissile->_miAnimType); + tbuff += 3; + + CopyInt(tbuff, &pMissile->_miAnimFlags); + tbuff += 4; + CopyInt(tbuff, &pMissile->_miAnimDelay); + CopyInt(tbuff, &pMissile->_miAnimLen); + CopyInt(tbuff, &pMissile->_miAnimWidth); + CopyInt(tbuff, &pMissile->_miAnimWidth2); + CopyInt(tbuff, &pMissile->_miAnimCnt); + CopyInt(tbuff, &pMissile->_miAnimAdd); + CopyInt(tbuff, &pMissile->_miAnimFrame); + CopyInt(tbuff, &pMissile->_miDrawFlag); + CopyInt(tbuff, &pMissile->_miLightFlag); + CopyInt(tbuff, &pMissile->_miPreFlag); + CopyInt(tbuff, &pMissile->_miUniqTrans); + CopyInt(tbuff, &pMissile->_mirange); + CopyInt(tbuff, &pMissile->_misource); + CopyInt(tbuff, &pMissile->_micaster); + CopyInt(tbuff, &pMissile->_midam); + CopyInt(tbuff, &pMissile->_miHitFlag); + CopyInt(tbuff, &pMissile->_midist); + CopyInt(tbuff, &pMissile->_mlid); + CopyInt(tbuff, &pMissile->_mirnd); + CopyInt(tbuff, &pMissile->_miVar1); + CopyInt(tbuff, &pMissile->_miVar2); + CopyInt(tbuff, &pMissile->_miVar3); + CopyInt(tbuff, &pMissile->_miVar4); + CopyInt(tbuff, &pMissile->_miVar5); + CopyInt(tbuff, &pMissile->_miVar6); + CopyInt(tbuff, &pMissile->_miVar7); + CopyInt(tbuff, &pMissile->_miVar8); +} + +void LoadObject(int i) +{ + ObjectStruct *pObject = &object[i]; + CopyInt(tbuff, &pObject->_otype); + CopyInt(tbuff, &pObject->_ox); + CopyInt(tbuff, &pObject->_oy); + CopyInt(tbuff, &pObject->_oLight); + CopyInt(tbuff, &pObject->_oAnimFlag); + tbuff += 4; + CopyInt(tbuff, &pObject->_oAnimDelay); + CopyInt(tbuff, &pObject->_oAnimCnt); + CopyInt(tbuff, &pObject->_oAnimLen); + CopyInt(tbuff, &pObject->_oAnimFrame); + CopyInt(tbuff, &pObject->_oAnimWidth); + CopyInt(tbuff, &pObject->_oAnimWidth2); + CopyInt(tbuff, &pObject->_oDelFlag); + + CopyChar(tbuff, &pObject->_oBreak); + tbuff += 3; + + CopyInt(tbuff, &pObject->_oSolidFlag); + CopyInt(tbuff, &pObject->_oMissFlag); + + CopyChar(tbuff, &pObject->_oSelFlag); + tbuff += 3; + + CopyInt(tbuff, &pObject->_oPreFlag); + CopyInt(tbuff, &pObject->_oTrapFlag); + CopyInt(tbuff, &pObject->_oDoorFlag); + CopyInt(tbuff, &pObject->_olid); + CopyInt(tbuff, &pObject->_oRndSeed); + CopyInt(tbuff, &pObject->_oVar1); + CopyInt(tbuff, &pObject->_oVar2); + CopyInt(tbuff, &pObject->_oVar3); + CopyInt(tbuff, &pObject->_oVar4); + CopyInt(tbuff, &pObject->_oVar5); + CopyInt(tbuff, &pObject->_oVar6); + CopyInt(tbuff, &pObject->_oVar7); + CopyInt(tbuff, &pObject->_oVar8); +} + +void LoadItem(int i) +{ + CopyItem(&item[i]); + GetItemFrm(i); +} + +void CopyItem(ItemStruct *pItem) +{ + CopyInt(tbuff, &pItem->_iSeed); + CopyShort(tbuff, &pItem->_iCreateInfo); + tbuff += 2; + CopyInt(tbuff, &pItem->_itype); + CopyInt(tbuff, &pItem->_ix); + CopyInt(tbuff, &pItem->_iy); + CopyInt(tbuff, &pItem->_iAnimFlag); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(tbuff, &pItem->_iAnimLen); + CopyInt(tbuff, &pItem->_iAnimFrame); + CopyInt(tbuff, &pItem->_iAnimWidth); + CopyInt(tbuff, &pItem->_iAnimWidth2); + CopyInt(tbuff, &pItem->_isin); + CopyChar(tbuff, &pItem->_iSelFlag); + tbuff += 3; + CopyInt(tbuff, &pItem->_iPostDraw); + CopyInt(tbuff, &pItem->_iIdentified); + CopyChar(tbuff, &pItem->_iMagical); + CopyBytes(tbuff, 64, &pItem->_iName); + CopyBytes(tbuff, 64, &pItem->_iIName); + CopyChar(tbuff, &pItem->_iLoc); + CopyChar(tbuff, &pItem->_iClass); + tbuff += 1; + CopyInt(tbuff, &pItem->_iCurs); + CopyInt(tbuff, &pItem->_ivalue); + CopyInt(tbuff, &pItem->_iIvalue); + CopyInt(tbuff, &pItem->_iMinDam); + CopyInt(tbuff, &pItem->_iMaxDam); + CopyInt(tbuff, &pItem->_iAC); + CopyInt(tbuff, &pItem->_iFlags); + CopyInt(tbuff, &pItem->_iMiscId); + CopyInt(tbuff, &pItem->_iSpell); + CopyInt(tbuff, &pItem->_iCharges); + CopyInt(tbuff, &pItem->_iMaxCharges); + CopyInt(tbuff, &pItem->_iDurability); + CopyInt(tbuff, &pItem->_iMaxDur); + CopyInt(tbuff, &pItem->_iPLDam); + CopyInt(tbuff, &pItem->_iPLToHit); + CopyInt(tbuff, &pItem->_iPLAC); + CopyInt(tbuff, &pItem->_iPLStr); + CopyInt(tbuff, &pItem->_iPLMag); + CopyInt(tbuff, &pItem->_iPLDex); + CopyInt(tbuff, &pItem->_iPLVit); + CopyInt(tbuff, &pItem->_iPLFR); + CopyInt(tbuff, &pItem->_iPLLR); + CopyInt(tbuff, &pItem->_iPLMR); + CopyInt(tbuff, &pItem->_iPLMana); + CopyInt(tbuff, &pItem->_iPLHP); + CopyInt(tbuff, &pItem->_iPLDamMod); + CopyInt(tbuff, &pItem->_iPLGetHit); + CopyInt(tbuff, &pItem->_iPLLight); + CopyChar(tbuff, &pItem->_iSplLvlAdd); + CopyChar(tbuff, &pItem->_iRequest); + tbuff += 2; + CopyInt(tbuff, &pItem->_iUid); + CopyInt(tbuff, &pItem->_iFMinDam); + CopyInt(tbuff, &pItem->_iFMaxDam); + CopyInt(tbuff, &pItem->_iLMinDam); + CopyInt(tbuff, &pItem->_iLMaxDam); + CopyInt(tbuff, &pItem->_iPLEnAc); + CopyChar(tbuff, &pItem->_iPrePower); + CopyChar(tbuff, &pItem->_iSufPower); + tbuff += 2; + CopyInt(tbuff, &pItem->_iVAdd1); + CopyInt(tbuff, &pItem->_iVMult1); + CopyInt(tbuff, &pItem->_iVAdd2); + CopyInt(tbuff, &pItem->_iVMult2); + CopyChar(tbuff, &pItem->_iMinStr); + CopyChar(tbuff, &pItem->_iMinMag); + CopyChar(tbuff, &pItem->_iMinDex); + tbuff += 1; + CopyInt(tbuff, &pItem->_iStatFlag); + CopyInt(tbuff, &pItem->IDidx); + CopyInt(tbuff, &pItem->offs016C); +} + +void CopyItems(const int n, ItemStruct *pItem) +{ + for (int i = 0; i < n; i++) { + CopyItem(&pItem[i]); + } +} + +void SaveItem(ItemStruct *pItem) +{ + CopyInt(&pItem->_iSeed, tbuff); + CopyShort(&pItem->_iCreateInfo, tbuff); + tbuff += 2; + CopyInt(&pItem->_itype, tbuff); + CopyInt(&pItem->_ix, tbuff); + CopyInt(&pItem->_iy, tbuff); + CopyInt(&pItem->_iAnimFlag, tbuff); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(&pItem->_iAnimLen, tbuff); + CopyInt(&pItem->_iAnimFrame, tbuff); + CopyInt(&pItem->_iAnimWidth, tbuff); + CopyInt(&pItem->_iAnimWidth2, tbuff); // width 2? + CopyInt(&pItem->_isin, tbuff); // set when item is flagged for deletion, deprecated in 1.02 + CopyChar(&pItem->_iSelFlag, tbuff); + tbuff += 3; + CopyInt(&pItem->_iPostDraw, tbuff); + CopyInt(&pItem->_iIdentified, tbuff); + CopyChar(&pItem->_iMagical, tbuff); + CopyBytes(&pItem->_iName, 64, tbuff); + CopyBytes(&pItem->_iIName, 64, tbuff); + CopyChar(&pItem->_iLoc, tbuff); + CopyChar(&pItem->_iClass, tbuff); + tbuff += 1; + CopyInt(&pItem->_iCurs, tbuff); + CopyInt(&pItem->_ivalue, tbuff); + CopyInt(&pItem->_iIvalue, tbuff); + CopyInt(&pItem->_iMinDam, tbuff); + CopyInt(&pItem->_iMaxDam, tbuff); + CopyInt(&pItem->_iAC, tbuff); + CopyInt(&pItem->_iFlags, tbuff); + CopyInt(&pItem->_iMiscId, tbuff); + CopyInt(&pItem->_iSpell, tbuff); + CopyInt(&pItem->_iCharges, tbuff); + CopyInt(&pItem->_iMaxCharges, tbuff); + CopyInt(&pItem->_iDurability, tbuff); + CopyInt(&pItem->_iMaxDur, tbuff); + CopyInt(&pItem->_iPLDam, tbuff); + CopyInt(&pItem->_iPLToHit, tbuff); + CopyInt(&pItem->_iPLAC, tbuff); + CopyInt(&pItem->_iPLStr, tbuff); + CopyInt(&pItem->_iPLMag, tbuff); + CopyInt(&pItem->_iPLDex, tbuff); + CopyInt(&pItem->_iPLVit, tbuff); + CopyInt(&pItem->_iPLFR, tbuff); + CopyInt(&pItem->_iPLLR, tbuff); + CopyInt(&pItem->_iPLMR, tbuff); + CopyInt(&pItem->_iPLMana, tbuff); + CopyInt(&pItem->_iPLHP, tbuff); + CopyInt(&pItem->_iPLDamMod, tbuff); + CopyInt(&pItem->_iPLGetHit, tbuff); + CopyInt(&pItem->_iPLLight, tbuff); + CopyChar(&pItem->_iSplLvlAdd, tbuff); + CopyChar(&pItem->_iRequest, tbuff); + tbuff += 2; + CopyInt(&pItem->_iUid, tbuff); + CopyInt(&pItem->_iFMinDam, tbuff); + CopyInt(&pItem->_iFMaxDam, tbuff); + CopyInt(&pItem->_iLMinDam, tbuff); + CopyInt(&pItem->_iLMaxDam, tbuff); + CopyInt(&pItem->_iPLEnAc, tbuff); + CopyChar(&pItem->_iPrePower, tbuff); + CopyChar(&pItem->_iSufPower, tbuff); + tbuff += 2; + CopyInt(&pItem->_iVAdd1, tbuff); + CopyInt(&pItem->_iVMult1, tbuff); + CopyInt(&pItem->_iVAdd2, tbuff); + CopyInt(&pItem->_iVMult2, tbuff); + CopyChar(&pItem->_iMinStr, tbuff); + CopyChar(&pItem->_iMinMag, tbuff); + CopyChar(&pItem->_iMinDex, tbuff); + tbuff += 1; + CopyInt(&pItem->_iStatFlag, tbuff); + CopyInt(&pItem->IDidx, tbuff); + CopyInt(&pItem->offs016C, tbuff); +} + +void SaveItems(ItemStruct *pItem, const int n) +{ + for (int i = 0; i < n; i++) { + SaveItem(&pItem[i]); + } +} + +void LoadPremium(int i) +{ + CopyItem(&item[i]); +} + +void LoadQuest(int i) +{ + memcpy(&quests[i], tbuff, sizeof(*quests)); + tbuff += sizeof(*quests); + ReturnLvlX = WLoad(); + ReturnLvlY = WLoad(); + ReturnLvl = WLoad(); + ReturnLvlT = WLoad(); + DoomQuestState = WLoad(); +} + +void LoadLighting(int i) +{ + memcpy(&LightList[i], tbuff, sizeof(*LightList)); + tbuff += sizeof(*LightList); +} + +void LoadVision(int i) +{ + memcpy(&VisionList[i], tbuff, sizeof(*VisionList)); + tbuff += sizeof(*VisionList); +} + +void LoadPortal(int i) +{ + memcpy(&portal[i], tbuff, sizeof(*portal)); + tbuff += sizeof(*portal); +} + +void SaveGame() +{ + int i, j; + char szName[MAX_PATH]; + + DWORD dwLen = codec_get_encoded_len(FILEBUFF); + BYTE *SaveBuff = DiabloAllocPtr(dwLen); + tbuff = SaveBuff; + + ISave('RETL'); + OSave((unsigned char)setlevel); + WSave(setlvlnum); + WSave(currlevel); + WSave((unsigned char)leveltype); + WSave(ViewX); + WSave(ViewY); + OSave(invflag); + OSave(chrflag); + WSave(nummonsters); + WSave(numitems); + WSave(nummissiles); + WSave(nobjects); + + for (i = 0; i < NUMLEVELS; i++) { + ISave(glSeedTbl[i]); + WSave(gnLevelTypeTbl[i]); + } + + SavePlayer(myplr); + + for (i = 0; i < MAXQUESTS; i++) + SaveQuest(i); + for (i = 0; i < MAXPORTAL; i++) + SavePortal(i); + for (i = 0; i < MAXMONSTERS; i++) + ISave(monstkills[i]); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + WSave(monstactive[i]); + for (i = 0; i < nummonsters; i++) + SaveMonster(monstactive[i]); + for (i = 0; i < MAXMISSILES; i++) + BSave(missileactive[i]); + for (i = 0; i < MAXMISSILES; i++) + BSave(missileavail[i]); + for (i = 0; i < nummissiles; i++) + SaveMissile(missileactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectavail[i]); + for (i = 0; i < nobjects; i++) + SaveObject(objectactive[i]); + + WSave(numlights); + + for (i = 0; i < MAXLIGHTS; i++) + BSave(lightactive[i]); + for (i = 0; i < numlights; i++) + SaveLighting(lightactive[i]); + + WSave(visionid); + WSave(numvision); + + for (i = 0; i < numvision; i++) + SaveVision(i); + } + + for (i = 0; i < MAXITEMS; i++) + BSave(itemactive[i]); + for (i = 0; i < MAXITEMS; i++) + BSave(itemavail[i]); + for (i = 0; i < numitems; i++) + SaveItem(&item[itemactive[i]]); + for (i = 0; i < 128; i++) + OSave(UniqueItemFlag[i]); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dLight[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dPlayer[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dItem[i][j]); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + WSave(dMonster[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dDead[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dObject[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dLight[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dPreLight[i][j]); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + OSave(automapview[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dMissile[i][j]); + } + } + + WSave(numpremium); + WSave(premiumlevel); + + for (i = 0; i < 6; i++) + SavePremium(i); + + OSave(automapflag); + WSave(AutoMapScale); + pfile_get_game_name(szName); + dwLen = codec_get_encoded_len(tbuff - SaveBuff); + pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); + mem_free_dbg(SaveBuff); + gbValidSaveFile = TRUE; + pfile_rename_temp_to_perm(); + pfile_write_hero(); +} + +void BSave(char v) +{ + *tbuff++ = v; +} + +void WSave(int v) +{ + *tbuff++ = v >> 24; + *tbuff++ = v >> 16; + *tbuff++ = v >> 8; + *tbuff++ = v; +} + +void ISave(int v) +{ + *tbuff++ = v >> 24; + *tbuff++ = v >> 16; + *tbuff++ = v >> 8; + *tbuff++ = v; +} + +void OSave(BOOL v) +{ + if (v != FALSE) + *tbuff++ = TRUE; + else + *tbuff++ = FALSE; +} + +void SaveMonster(int i) +{ + MonsterStruct *pMonster = &monster[i]; + + CopyInt(&pMonster->_mMTidx, tbuff); + CopyInt(&pMonster->_mmode, tbuff); + + CopyChar(&pMonster->_mgoal, tbuff); + tbuff += 3; + + CopyInt(&pMonster->_mgoalvar1, tbuff); + CopyInt(&pMonster->_mgoalvar2, tbuff); + CopyInt(&pMonster->_mgoalvar3, tbuff); + CopyInt(&pMonster->field_18, tbuff); + + CopyChar(&pMonster->_pathcount, tbuff); + tbuff += 3; + + CopyInt(&pMonster->_mx, tbuff); + CopyInt(&pMonster->_my, tbuff); + CopyInt(&pMonster->_mfutx, tbuff); + CopyInt(&pMonster->_mfuty, tbuff); + CopyInt(&pMonster->_moldx, tbuff); + CopyInt(&pMonster->_moldy, tbuff); + CopyInt(&pMonster->_mxoff, tbuff); + CopyInt(&pMonster->_myoff, tbuff); + CopyInt(&pMonster->_mxvel, tbuff); + CopyInt(&pMonster->_myvel, tbuff); + CopyInt(&pMonster->_mdir, tbuff); + CopyInt(&pMonster->_menemy, tbuff); + + CopyChar(&pMonster->_menemyx, tbuff); + CopyChar(&pMonster->_menemyy, tbuff); + CopyShort(&pMonster->falign_52, tbuff); + + tbuff += 4; // Skip pointer + CopyInt(&pMonster->_mAnimDelay, tbuff); + CopyInt(&pMonster->_mAnimCnt, tbuff); + CopyInt(&pMonster->_mAnimLen, tbuff); + CopyInt(&pMonster->_mAnimFrame, tbuff); + CopyInt(&pMonster->_meflag, tbuff); + CopyInt(&pMonster->_mDelFlag, tbuff); + CopyInt(&pMonster->_mVar1, tbuff); + CopyInt(&pMonster->_mVar2, tbuff); + CopyInt(&pMonster->_mVar3, tbuff); + CopyInt(&pMonster->_mVar4, tbuff); + CopyInt(&pMonster->_mVar5, tbuff); + CopyInt(&pMonster->_mVar6, tbuff); + CopyInt(&pMonster->_mVar7, tbuff); + CopyInt(&pMonster->_mVar8, tbuff); + CopyInt(&pMonster->_mmaxhp, tbuff); + CopyInt(&pMonster->_mhitpoints, tbuff); + + CopyChar(&pMonster->_mAi, tbuff); + CopyChar(&pMonster->_mint, tbuff); + CopyShort(&pMonster->falign_9A, tbuff); + + CopyInt(&pMonster->_mFlags, tbuff); + + CopyChar(&pMonster->_msquelch, tbuff); + tbuff += 3; + + CopyInt(&pMonster->falign_A4, tbuff); + CopyInt(&pMonster->_lastx, tbuff); + CopyInt(&pMonster->_lasty, tbuff); + CopyInt(&pMonster->_mRndSeed, tbuff); + CopyInt(&pMonster->_mAISeed, tbuff); + CopyInt(&pMonster->falign_B8, tbuff); + + CopyChar(&pMonster->_uniqtype, tbuff); + CopyChar(&pMonster->_uniqtrans, tbuff); + CopyChar(&pMonster->_udeadval, tbuff); + CopyChar(&pMonster->mWhoHit, tbuff); + + CopyChar(&pMonster->mLevel, tbuff); + CopyShort(&pMonster->mExp, tbuff); + tbuff += 1; + + CopyChar(&pMonster->mHit, tbuff); + CopyChar(&pMonster->mMinDamage, tbuff); + CopyChar(&pMonster->mMaxDamage, tbuff); + CopyChar(&pMonster->mHit2, tbuff); + + CopyChar(&pMonster->mMinDamage2, tbuff); + CopyChar(&pMonster->mMaxDamage2, tbuff); + CopyChar(&pMonster->mArmorClass, tbuff); + CopyChar(&pMonster->falign_CB, tbuff); + + CopyShort(&pMonster->mMagicRes, tbuff); + tbuff += 2; + + CopyInt(&pMonster->mtalkmsg, tbuff); + + CopyChar(&pMonster->leader, tbuff); + CopyChar(&pMonster->leaderflag, tbuff); + CopyChar(&pMonster->packsize, tbuff); + CopyChar(&pMonster->mlid, tbuff); +} + +void SaveMissile(int i) +{ + MissileStruct *pMissile = &missile[i]; + + CopyInt(&pMissile->_mitype, tbuff); + CopyInt(&pMissile->_mix, tbuff); + CopyInt(&pMissile->_miy, tbuff); + CopyInt(&pMissile->_mixoff, tbuff); + CopyInt(&pMissile->_miyoff, tbuff); + CopyInt(&pMissile->_mixvel, tbuff); + CopyInt(&pMissile->_miyvel, tbuff); + CopyInt(&pMissile->_misx, tbuff); + CopyInt(&pMissile->_misy, tbuff); + CopyInt(&pMissile->_mitxoff, tbuff); + CopyInt(&pMissile->_mityoff, tbuff); + CopyInt(&pMissile->_mimfnum, tbuff); + CopyInt(&pMissile->_mispllvl, tbuff); + CopyInt(&pMissile->_miDelFlag, tbuff); + CopyChar(&pMissile->_miAnimType, tbuff); + tbuff += 3; + + CopyInt(&pMissile->_miAnimFlags, tbuff); + tbuff += 4; + CopyInt(&pMissile->_miAnimDelay, tbuff); + CopyInt(&pMissile->_miAnimLen, tbuff); + CopyInt(&pMissile->_miAnimWidth, tbuff); + CopyInt(&pMissile->_miAnimWidth2, tbuff); + CopyInt(&pMissile->_miAnimCnt, tbuff); + CopyInt(&pMissile->_miAnimAdd, tbuff); + CopyInt(&pMissile->_miAnimFrame, tbuff); + CopyInt(&pMissile->_miDrawFlag, tbuff); + CopyInt(&pMissile->_miLightFlag, tbuff); + CopyInt(&pMissile->_miPreFlag, tbuff); + CopyInt(&pMissile->_miUniqTrans, tbuff); + CopyInt(&pMissile->_mirange, tbuff); + CopyInt(&pMissile->_misource, tbuff); + CopyInt(&pMissile->_micaster, tbuff); + CopyInt(&pMissile->_midam, tbuff); + CopyInt(&pMissile->_miHitFlag, tbuff); + CopyInt(&pMissile->_midist, tbuff); + CopyInt(&pMissile->_mlid, tbuff); + CopyInt(&pMissile->_mirnd, tbuff); + CopyInt(&pMissile->_miVar1, tbuff); + CopyInt(&pMissile->_miVar2, tbuff); + CopyInt(&pMissile->_miVar3, tbuff); + CopyInt(&pMissile->_miVar4, tbuff); + CopyInt(&pMissile->_miVar5, tbuff); + CopyInt(&pMissile->_miVar6, tbuff); + CopyInt(&pMissile->_miVar7, tbuff); + CopyInt(&pMissile->_miVar8, tbuff); +} + +void SaveObject(int i) +{ + ObjectStruct *pObject = &object[i]; + CopyInt(tbuff, &pObject->_otype); + CopyInt(&pObject->_ox, tbuff); + CopyInt(&pObject->_oy, tbuff); + CopyInt(&pObject->_oLight, tbuff); + CopyInt(&pObject->_oAnimFlag, tbuff); + tbuff += 4; + CopyInt(&pObject->_oAnimDelay, tbuff); + CopyInt(&pObject->_oAnimCnt, tbuff); + CopyInt(&pObject->_oAnimLen, tbuff); + CopyInt(&pObject->_oAnimFrame, tbuff); + CopyInt(&pObject->_oAnimWidth, tbuff); + CopyInt(&pObject->_oAnimWidth2, tbuff); + CopyInt(&pObject->_oDelFlag, tbuff); + + CopyChar(&pObject->_oBreak, tbuff); + tbuff += 3; + + CopyInt(&pObject->_oSolidFlag, tbuff); + CopyInt(&pObject->_oMissFlag, tbuff); + + CopyChar(&pObject->_oSelFlag, tbuff); + tbuff += 3; + + CopyInt(&pObject->_oPreFlag, tbuff); + CopyInt(&pObject->_oTrapFlag, tbuff); + CopyInt(&pObject->_oDoorFlag, tbuff); + CopyInt(&pObject->_olid, tbuff); + CopyInt(&pObject->_oRndSeed, tbuff); + CopyInt(&pObject->_oVar1, tbuff); + CopyInt(&pObject->_oVar2, tbuff); + CopyInt(&pObject->_oVar3, tbuff); + CopyInt(&pObject->_oVar4, tbuff); + CopyInt(&pObject->_oVar5, tbuff); + CopyInt(&pObject->_oVar6, tbuff); + CopyInt(&pObject->_oVar7, tbuff); + CopyInt(&pObject->_oVar8, tbuff); +} + +void SavePremium(int i) +{ + SaveItem(&item[i]); +} + +void SaveQuest(int i) +{ + memcpy(tbuff, &quests[i], sizeof(*quests)); + tbuff += sizeof(*quests); + WSave(ReturnLvlX); + WSave(ReturnLvlY); + WSave(ReturnLvl); + WSave(ReturnLvlT); + WSave(DoomQuestState); +} + +void SaveLighting(int i) +{ + memcpy(tbuff, &LightList[i], sizeof(*LightList)); + tbuff += sizeof(*LightList); +} + +void SaveVision(int i) +{ + memcpy(tbuff, &VisionList[i], sizeof(*VisionList)); + tbuff += sizeof(*VisionList); +} + +void SavePortal(int i) +{ + memcpy(tbuff, &portal[i], sizeof(*portal)); + tbuff += sizeof(*portal); +} + +void SaveLevel() +{ + int i, j; + char szName[MAX_PATH]; + int dwLen; + unsigned char *SaveBuff; + + if (!currlevel) + glSeedTbl[0] = GetRndSeed(); + + dwLen = codec_get_encoded_len(FILEBUFF); + SaveBuff = DiabloAllocPtr(dwLen); + tbuff = SaveBuff; + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dDead[i][j]); + } + } + + WSave(nummonsters); + WSave(numitems); + WSave(nobjects); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + WSave(monstactive[i]); + for (i = 0; i < nummonsters; i++) + SaveMonster(monstactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectavail[i]); + for (i = 0; i < nobjects; i++) + SaveObject(objectactive[i]); + } + + for (i = 0; i < MAXITEMS; i++) + BSave(itemactive[i]); + for (i = 0; i < MAXITEMS; i++) + BSave(itemavail[i]); + for (i = 0; i < numitems; i++) + SaveItem(&item[itemactive[i]]); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dItem[i][j]); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + WSave(dMonster[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dObject[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dLight[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dPreLight[i][j]); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + OSave(automapview[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dMissile[i][j]); + } + } + + GetTempLevelNames(szName); + dwLen = codec_get_encoded_len(tbuff - SaveBuff); + pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); + mem_free_dbg(SaveBuff); + + if (setlevel == 0) + plr[myplr]._pLvlVisited[currlevel] = 1; + else + plr[myplr]._pSLvlVisited[setlvlnum] = 1; +} + +void LoadLevel() +{ + int i, j; + DWORD dwLen; + char szName[MAX_PATH]; + BYTE *LoadBuff; + + GetPermLevelNames(szName); + LoadBuff = pfile_read(szName, &dwLen); + tbuff = LoadBuff; + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dDead[i][j] = BLoad(); + } + SetDead(); + } + + nummonsters = WLoad(); + numitems = WLoad(); + nobjects = WLoad(); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + monstactive[i] = WLoad(); + for (i = 0; i < nummonsters; i++) + LoadMonster(monstactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + objectactive[i] = BLoad(); + for (i = 0; i < MAXOBJECTS; i++) + objectavail[i] = BLoad(); + for (i = 0; i < nobjects; i++) + LoadObject(objectactive[i]); + for (i = 0; i < nobjects; i++) + SyncObjectAnim(objectactive[i]); + } + + for (i = 0; i < MAXITEMS; i++) + itemactive[i] = BLoad(); + for (i = 0; i < MAXITEMS; i++) + itemavail[i] = BLoad(); + for (i = 0; i < numitems; i++) + LoadItem(itemactive[i]); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dFlags[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dItem[i][j] = BLoad(); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dMonster[i][j] = WLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dObject[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dLight[i][j] = BLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dPreLight[i][j] = BLoad(); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + automapview[i][j] = OLoad(); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + dMissile[i][j] = 0; /// BUGFIX: supposed to load saved missiles with "BLoad()"? + } + } + + AutomapZoomReset(); + ResyncQuests(); + SyncPortals(); + dolighting = 1; + + for (i = 0; i < MAX_PLRS; i++) { + if (plr[i].plractive && currlevel == plr[i].plrlevel) + LightList[plr[i]._plid]._lunflag = 1; + } + + mem_free_dbg(LoadBuff); +} + +DEVILUTION_END_NAMESPACE From e899b7b322106ba496c3e1423570729684903491 Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 08:35:08 -0700 Subject: [PATCH 08/11] Removed unused #pragma packs --- structs.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/structs.h b/structs.h index 7d995dc2fc0..b949f8487e8 100644 --- a/structs.h +++ b/structs.h @@ -92,7 +92,6 @@ typedef struct ItemGetRecordStruct { unsigned int dwTimestamp; } ItemGetRecordStruct; -#pragma pack(push, 4) typedef struct ItemStruct { int _iSeed; WORD _iCreateInfo; @@ -167,13 +166,11 @@ typedef struct ItemStruct { int IDidx; int offs016C; // _oldlight or _iInvalid } ItemStruct; -#pragma pack(pop) ////////////////////////////////////////////////// // player ////////////////////////////////////////////////// -#pragma pack(push, 4) typedef struct PlayerStruct { int _pmode; char walkpath[25]; @@ -354,7 +351,6 @@ typedef struct PlayerStruct { unsigned char *_pBData; void *pReserved; } PlayerStruct; -#pragma pack(pop) ////////////////////////////////////////////////// // textdat @@ -404,7 +400,6 @@ typedef struct ChainStruct { int _mirange; } ChainStruct; -#pragma pack(push, 4) typedef struct MissileStruct { int _mitype; int _mix; @@ -451,7 +446,6 @@ typedef struct MissileStruct { int _miVar7; int _miVar8; } MissileStruct; -#pragma pack(pop) ////////////////////////////////////////////////// // effects/sound @@ -545,7 +539,6 @@ typedef struct CMonster { BYTE *trans_file; } CMonster; -#pragma pack(push, 4) typedef struct MonsterStruct { // note: missing field _mAFNum int _mMTidx; int _mmode; /* MON_MODE */ @@ -622,7 +615,6 @@ typedef struct MonsterStruct { // note: missing field _mAFNum CMonster *MType; MonsterData *MData; } MonsterStruct; -#pragma pack(pop) typedef struct UniqMonstStruct { char mtype; @@ -1189,7 +1181,6 @@ typedef struct InvXY { // lighting ////////////////////////////////////////////////// -#pragma pack(push, 4) typedef struct LightListStruct { int _lx; int _ly; @@ -1205,7 +1196,6 @@ typedef struct LightListStruct { int _yoff; int _lflags; } LightListStruct; -#pragma pack(pop) ////////////////////////////////////////////////// // dead From b589c10bc08b74345b7521d784a4525fe18ea69d Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 08:41:37 -0700 Subject: [PATCH 09/11] Fix incorrect arg name in forward declarations --- Source/loadsave.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/loadsave.h b/Source/loadsave.h index 3d04e987670..fa03d7dbbea 100644 --- a/Source/loadsave.h +++ b/Source/loadsave.h @@ -18,8 +18,8 @@ void LoadPlayer(int i); void LoadMonster(int i); void LoadMissile(int i); void LoadObject(int i); -void LoadItem(int t); -void LoadPremium(int t); +void LoadItem(int i); +void LoadPremium(int i); void LoadQuest(int i); void LoadLighting(int i); void LoadVision(int i); From e754152784bba2c31d2b38b3fecc6901e0e0427f Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 08:51:18 -0700 Subject: [PATCH 10/11] Move SavePlayer and SaveItem down --- Source/loadsave.cpp | 580 ++++++++++++++++++++++---------------------- 1 file changed, 291 insertions(+), 289 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 68dc56c5e52..ea7aa3f715d 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -450,209 +450,6 @@ void LoadPlayer(int i) // Omit 10 pointers } -void SavePlayer(int i) -{ - PlayerStruct *pPlayer = &plr[i]; - - CopyInt(&pPlayer->_pmode, tbuff); - - CopyBytes(&pPlayer->walkpath, 25, tbuff); - CopyBytes(&pPlayer->plractive, 1, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->destAction, tbuff); - CopyInt(&pPlayer->destParam1, tbuff); - CopyInt(&pPlayer->destParam2, tbuff); - CopyInt(&pPlayer->destParam3, tbuff); - CopyInt(&pPlayer->destParam4, tbuff); - CopyInt(&pPlayer->plrlevel, tbuff); - CopyInt(&pPlayer->WorldX, tbuff); - CopyInt(&pPlayer->WorldY, tbuff); - CopyInt(&pPlayer->_px, tbuff); - CopyInt(&pPlayer->_py, tbuff); - CopyInt(&pPlayer->_ptargx, tbuff); - CopyInt(&pPlayer->_ptargy, tbuff); - CopyInt(&pPlayer->_pownerx, tbuff); - CopyInt(&pPlayer->_pownery, tbuff); - CopyInt(&pPlayer->_poldx, tbuff); - CopyInt(&pPlayer->_poldy, tbuff); - CopyInt(&pPlayer->_pxoff, tbuff); - CopyInt(&pPlayer->_pyoff, tbuff); - CopyInt(&pPlayer->_pxvel, tbuff); - CopyInt(&pPlayer->_pyvel, tbuff); - CopyInt(&pPlayer->_pdir, tbuff); - CopyInt(&pPlayer->_nextdir, tbuff); - CopyInt(&pPlayer->_pgfxnum, tbuff); - tbuff += 4; // Skip pointers - CopyInt(&pPlayer->_pAnimDelay, tbuff); - CopyInt(&pPlayer->_pAnimCnt, tbuff); - CopyInt(&pPlayer->_pAnimLen, tbuff); - CopyInt(&pPlayer->_pAnimFrame, tbuff); - CopyInt(&pPlayer->_pAnimWidth, tbuff); - CopyInt(&pPlayer->_pAnimWidth2, tbuff); - CopyInt(&pPlayer->_peflag, tbuff); - CopyInt(&pPlayer->_plid, tbuff); - CopyInt(&pPlayer->_pvid, tbuff); - - CopyInt(&pPlayer->_pSpell, tbuff); - - CopyChar(&pPlayer->_pSplType, tbuff); - CopyChar(&pPlayer->_pSplFrom, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->_pTSpell, tbuff); - CopyChar(&pPlayer->_pTSplType, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pRSpell, tbuff); - CopyChar(&pPlayer->_pRSplType, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pSBkSpell, tbuff); - CopyChar(&pPlayer->_pSBkSplType, tbuff); - - CopyBytes(&pPlayer->_pSplLvl, 64, tbuff); - tbuff += 7; - CopyInt64(&pPlayer->_pMemSpells, tbuff); - CopyInt64(&pPlayer->_pAblSpells, tbuff); - CopyInt64(&pPlayer->_pScrlSpells, tbuff); - CopyChar(&pPlayer->_pSpellFlags, tbuff); - tbuff += 3; - CopyInts(&pPlayer->_pSplHotKey, 4, tbuff); - CopyBytes(&pPlayer->_pSplTHotKey, 4, tbuff); - CopyInt(&pPlayer->_pwtype, tbuff); - CopyChar(&pPlayer->_pBlockFlag, tbuff); - CopyChar(&pPlayer->_pInvincible, tbuff); - CopyChar(&pPlayer->_pLightRad, tbuff); - CopyChar(&pPlayer->_pLvlChanging, tbuff); - CopyBytes(&pPlayer->_pName, PLR_NAME_LEN, tbuff); - CopyChar(&pPlayer->_pClass, tbuff); - tbuff += 3; - CopyInt(&pPlayer->_pStrength, tbuff); - CopyInt(&pPlayer->_pBaseStr, tbuff); - CopyInt(&pPlayer->_pMagic, tbuff); - CopyInt(&pPlayer->_pBaseMag, tbuff); - CopyInt(&pPlayer->_pDexterity, tbuff); - CopyInt(&pPlayer->_pBaseDex, tbuff); - CopyInt(&pPlayer->_pVitality, tbuff); - CopyInt(&pPlayer->_pBaseVit, tbuff); - CopyInt(&pPlayer->_pStatPts, tbuff); - CopyInt(&pPlayer->_pDamageMod, tbuff); - CopyInt(&pPlayer->_pBaseToBlk, tbuff); - CopyInt(&pPlayer->_pHPBase, tbuff); - CopyInt(&pPlayer->_pMaxHPBase, tbuff); - CopyInt(&pPlayer->_pHitPoints, tbuff); - CopyInt(&pPlayer->_pMaxHP, tbuff); - CopyInt(&pPlayer->_pHPPer, tbuff); - CopyInt(&pPlayer->_pManaBase, tbuff); - CopyInt(&pPlayer->_pMaxManaBase, tbuff); - CopyInt(&pPlayer->_pMana, tbuff); - CopyInt(&pPlayer->_pMaxMana, tbuff); - CopyInt(&pPlayer->_pManaPer, tbuff); - CopyChar(&pPlayer->_pLevel, tbuff); - CopyChar(&pPlayer->_pMaxLvl, tbuff); - tbuff += 2; - CopyInt(&pPlayer->_pExperience, tbuff); - CopyInt(&pPlayer->_pMaxExp, tbuff); - CopyInt(&pPlayer->_pNextExper, tbuff); - CopyChar(&pPlayer->_pArmorClass, tbuff); - CopyChar(&pPlayer->_pMagResist, tbuff); - CopyChar(&pPlayer->_pFireResist, tbuff); - CopyChar(&pPlayer->_pLghtResist, tbuff); - CopyInt(&pPlayer->_pGold, tbuff); - CopyInt(&pPlayer->_pInfraFlag, tbuff); - CopyInt(&pPlayer->_pVar1, tbuff); - CopyInt(&pPlayer->_pVar2, tbuff); - CopyInt(&pPlayer->_pVar3, tbuff); - CopyInt(&pPlayer->_pVar4, tbuff); - CopyInt(&pPlayer->_pVar5, tbuff); - CopyInt(&pPlayer->_pVar6, tbuff); - CopyInt(&pPlayer->_pVar7, tbuff); - CopyInt(&pPlayer->_pVar8, tbuff); - CopyBytes(&pPlayer->_pLvlVisited, NUMLEVELS, tbuff); - CopyBytes(&pPlayer->_pSLvlVisited, NUMLEVELS, tbuff); // only 10 used - tbuff += 2; - CopyInt(&pPlayer->_pGFXLoad, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - CopyInt(&pPlayer->_pNFrames, tbuff); - CopyInt(&pPlayer->_pNWidth, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pWFrames, tbuff); - CopyInt(&pPlayer->_pWWidth, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pAFrames, tbuff); - CopyInt(&pPlayer->_pAWidth, tbuff); - CopyInt(&pPlayer->_pAFNum, tbuff); - - tbuff += sizeof(DWORD) * 24; // Skip 24 pointers - - CopyInt(&pPlayer->_pSFrames, tbuff); - CopyInt(&pPlayer->_pSWidth, tbuff); - CopyInt(&pPlayer->_pSFNum, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pHFrames, tbuff); - CopyInt(&pPlayer->_pHWidth, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pDFrames, tbuff); - CopyInt(&pPlayer->_pDWidth, tbuff); - - tbuff += sizeof(DWORD) * 8; // Skip 8 pointers - - CopyInt(&pPlayer->_pBFrames, tbuff); - CopyInt(&pPlayer->_pBWidth, tbuff); - SaveItems(pPlayer->InvBody, NUM_INVLOC); - SaveItems(pPlayer->InvList, NUM_INV_GRID_ELEM); - CopyInt(&pPlayer->_pNumInv, tbuff); - CopyBytes(pPlayer->InvGrid, NUM_INV_GRID_ELEM, tbuff); - SaveItems(pPlayer->SpdList, MAXBELTITEMS); - SaveItem(&pPlayer->HoldItem); - CopyInt(&pPlayer->_pIMinDam, tbuff); - CopyInt(&pPlayer->_pIMaxDam, tbuff); - CopyInt(&pPlayer->_pIAC, tbuff); - CopyInt(&pPlayer->_pIBonusDam, tbuff); - CopyInt(&pPlayer->_pIBonusToHit, tbuff); - CopyInt(&pPlayer->_pIBonusAC, tbuff); - CopyInt(&pPlayer->_pIBonusDamMod, tbuff); - tbuff += 4; - CopyInt64(&pPlayer->_pISpells, tbuff); - CopyInt(&pPlayer->_pIFlags, tbuff); - CopyInt(&pPlayer->_pIGetHit, tbuff); - - CopyChar(&pPlayer->_pISplLvlAdd, tbuff); - CopyChar(&pPlayer->_pISplCost, tbuff); - tbuff += 2; - - CopyInt(&pPlayer->_pISplDur, tbuff); - CopyInt(&pPlayer->_pIEnAc, tbuff); - CopyInt(&pPlayer->_pIFMinDam, tbuff); - CopyInt(&pPlayer->_pIFMaxDam, tbuff); - CopyInt(&pPlayer->_pILMinDam, tbuff); - CopyInt(&pPlayer->_pILMaxDam, tbuff); - CopyInt(&pPlayer->_pOilType, tbuff); - - CopyChar(&pPlayer->pTownWarps, tbuff); - CopyChar(&pPlayer->pDungMsgs, tbuff); - CopyChar(&pPlayer->pLvlLoad, tbuff); - CopyChar(&pPlayer->pBattleNet, tbuff); - - CopyChar(&pPlayer->pManaShield, tbuff); - CopyBytes(&pPlayer->bReserved, 3, tbuff); - - CopyShorts(&pPlayer->wReserved, 8, tbuff); - - CopyInt(&pPlayer->pDiabloKillLevel, tbuff); - CopyInts(&pPlayer->dwReserved, 7, tbuff); - - // Omit 10 pointers -} - void LoadMonster(int i) { MonsterStruct *pMonster = &monster[i]; @@ -938,92 +735,7 @@ void CopyItems(const int n, ItemStruct *pItem) } } -void SaveItem(ItemStruct *pItem) -{ - CopyInt(&pItem->_iSeed, tbuff); - CopyShort(&pItem->_iCreateInfo, tbuff); - tbuff += 2; - CopyInt(&pItem->_itype, tbuff); - CopyInt(&pItem->_ix, tbuff); - CopyInt(&pItem->_iy, tbuff); - CopyInt(&pItem->_iAnimFlag, tbuff); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(&pItem->_iAnimLen, tbuff); - CopyInt(&pItem->_iAnimFrame, tbuff); - CopyInt(&pItem->_iAnimWidth, tbuff); - CopyInt(&pItem->_iAnimWidth2, tbuff); // width 2? - CopyInt(&pItem->_isin, tbuff); // set when item is flagged for deletion, deprecated in 1.02 - CopyChar(&pItem->_iSelFlag, tbuff); - tbuff += 3; - CopyInt(&pItem->_iPostDraw, tbuff); - CopyInt(&pItem->_iIdentified, tbuff); - CopyChar(&pItem->_iMagical, tbuff); - CopyBytes(&pItem->_iName, 64, tbuff); - CopyBytes(&pItem->_iIName, 64, tbuff); - CopyChar(&pItem->_iLoc, tbuff); - CopyChar(&pItem->_iClass, tbuff); - tbuff += 1; - CopyInt(&pItem->_iCurs, tbuff); - CopyInt(&pItem->_ivalue, tbuff); - CopyInt(&pItem->_iIvalue, tbuff); - CopyInt(&pItem->_iMinDam, tbuff); - CopyInt(&pItem->_iMaxDam, tbuff); - CopyInt(&pItem->_iAC, tbuff); - CopyInt(&pItem->_iFlags, tbuff); - CopyInt(&pItem->_iMiscId, tbuff); - CopyInt(&pItem->_iSpell, tbuff); - CopyInt(&pItem->_iCharges, tbuff); - CopyInt(&pItem->_iMaxCharges, tbuff); - CopyInt(&pItem->_iDurability, tbuff); - CopyInt(&pItem->_iMaxDur, tbuff); - CopyInt(&pItem->_iPLDam, tbuff); - CopyInt(&pItem->_iPLToHit, tbuff); - CopyInt(&pItem->_iPLAC, tbuff); - CopyInt(&pItem->_iPLStr, tbuff); - CopyInt(&pItem->_iPLMag, tbuff); - CopyInt(&pItem->_iPLDex, tbuff); - CopyInt(&pItem->_iPLVit, tbuff); - CopyInt(&pItem->_iPLFR, tbuff); - CopyInt(&pItem->_iPLLR, tbuff); - CopyInt(&pItem->_iPLMR, tbuff); - CopyInt(&pItem->_iPLMana, tbuff); - CopyInt(&pItem->_iPLHP, tbuff); - CopyInt(&pItem->_iPLDamMod, tbuff); - CopyInt(&pItem->_iPLGetHit, tbuff); - CopyInt(&pItem->_iPLLight, tbuff); - CopyChar(&pItem->_iSplLvlAdd, tbuff); - CopyChar(&pItem->_iRequest, tbuff); - tbuff += 2; - CopyInt(&pItem->_iUid, tbuff); - CopyInt(&pItem->_iFMinDam, tbuff); - CopyInt(&pItem->_iFMaxDam, tbuff); - CopyInt(&pItem->_iLMinDam, tbuff); - CopyInt(&pItem->_iLMaxDam, tbuff); - CopyInt(&pItem->_iPLEnAc, tbuff); - CopyChar(&pItem->_iPrePower, tbuff); - CopyChar(&pItem->_iSufPower, tbuff); - tbuff += 2; - CopyInt(&pItem->_iVAdd1, tbuff); - CopyInt(&pItem->_iVMult1, tbuff); - CopyInt(&pItem->_iVAdd2, tbuff); - CopyInt(&pItem->_iVMult2, tbuff); - CopyChar(&pItem->_iMinStr, tbuff); - CopyChar(&pItem->_iMinMag, tbuff); - CopyChar(&pItem->_iMinDex, tbuff); - tbuff += 1; - CopyInt(&pItem->_iStatFlag, tbuff); - CopyInt(&pItem->IDidx, tbuff); - CopyInt(&pItem->offs016C, tbuff); -} - -void SaveItems(ItemStruct *pItem, const int n) -{ - for (int i = 0; i < n; i++) { - SaveItem(&pItem[i]); - } -} - -void LoadPremium(int i) +void LoadPremium(int i) { CopyItem(&item[i]); } @@ -1229,6 +941,211 @@ void OSave(BOOL v) *tbuff++ = FALSE; } + + +void SavePlayer(int i) +{ + PlayerStruct *pPlayer = &plr[i]; + + CopyInt(&pPlayer->_pmode, tbuff); + + CopyBytes(&pPlayer->walkpath, 25, tbuff); + CopyBytes(&pPlayer->plractive, 1, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->destAction, tbuff); + CopyInt(&pPlayer->destParam1, tbuff); + CopyInt(&pPlayer->destParam2, tbuff); + CopyInt(&pPlayer->destParam3, tbuff); + CopyInt(&pPlayer->destParam4, tbuff); + CopyInt(&pPlayer->plrlevel, tbuff); + CopyInt(&pPlayer->WorldX, tbuff); + CopyInt(&pPlayer->WorldY, tbuff); + CopyInt(&pPlayer->_px, tbuff); + CopyInt(&pPlayer->_py, tbuff); + CopyInt(&pPlayer->_ptargx, tbuff); + CopyInt(&pPlayer->_ptargy, tbuff); + CopyInt(&pPlayer->_pownerx, tbuff); + CopyInt(&pPlayer->_pownery, tbuff); + CopyInt(&pPlayer->_poldx, tbuff); + CopyInt(&pPlayer->_poldy, tbuff); + CopyInt(&pPlayer->_pxoff, tbuff); + CopyInt(&pPlayer->_pyoff, tbuff); + CopyInt(&pPlayer->_pxvel, tbuff); + CopyInt(&pPlayer->_pyvel, tbuff); + CopyInt(&pPlayer->_pdir, tbuff); + CopyInt(&pPlayer->_nextdir, tbuff); + CopyInt(&pPlayer->_pgfxnum, tbuff); + tbuff += 4; // Skip pointers + CopyInt(&pPlayer->_pAnimDelay, tbuff); + CopyInt(&pPlayer->_pAnimCnt, tbuff); + CopyInt(&pPlayer->_pAnimLen, tbuff); + CopyInt(&pPlayer->_pAnimFrame, tbuff); + CopyInt(&pPlayer->_pAnimWidth, tbuff); + CopyInt(&pPlayer->_pAnimWidth2, tbuff); + CopyInt(&pPlayer->_peflag, tbuff); + CopyInt(&pPlayer->_plid, tbuff); + CopyInt(&pPlayer->_pvid, tbuff); + + CopyInt(&pPlayer->_pSpell, tbuff); + + CopyChar(&pPlayer->_pSplType, tbuff); + CopyChar(&pPlayer->_pSplFrom, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->_pTSpell, tbuff); + CopyChar(&pPlayer->_pTSplType, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pRSpell, tbuff); + CopyChar(&pPlayer->_pRSplType, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pSBkSpell, tbuff); + CopyChar(&pPlayer->_pSBkSplType, tbuff); + + CopyBytes(&pPlayer->_pSplLvl, 64, tbuff); + tbuff += 7; + CopyInt64(&pPlayer->_pMemSpells, tbuff); + CopyInt64(&pPlayer->_pAblSpells, tbuff); + CopyInt64(&pPlayer->_pScrlSpells, tbuff); + CopyChar(&pPlayer->_pSpellFlags, tbuff); + tbuff += 3; + CopyInts(&pPlayer->_pSplHotKey, 4, tbuff); + CopyBytes(&pPlayer->_pSplTHotKey, 4, tbuff); + CopyInt(&pPlayer->_pwtype, tbuff); + CopyChar(&pPlayer->_pBlockFlag, tbuff); + CopyChar(&pPlayer->_pInvincible, tbuff); + CopyChar(&pPlayer->_pLightRad, tbuff); + CopyChar(&pPlayer->_pLvlChanging, tbuff); + CopyBytes(&pPlayer->_pName, PLR_NAME_LEN, tbuff); + CopyChar(&pPlayer->_pClass, tbuff); + tbuff += 3; + CopyInt(&pPlayer->_pStrength, tbuff); + CopyInt(&pPlayer->_pBaseStr, tbuff); + CopyInt(&pPlayer->_pMagic, tbuff); + CopyInt(&pPlayer->_pBaseMag, tbuff); + CopyInt(&pPlayer->_pDexterity, tbuff); + CopyInt(&pPlayer->_pBaseDex, tbuff); + CopyInt(&pPlayer->_pVitality, tbuff); + CopyInt(&pPlayer->_pBaseVit, tbuff); + CopyInt(&pPlayer->_pStatPts, tbuff); + CopyInt(&pPlayer->_pDamageMod, tbuff); + CopyInt(&pPlayer->_pBaseToBlk, tbuff); + CopyInt(&pPlayer->_pHPBase, tbuff); + CopyInt(&pPlayer->_pMaxHPBase, tbuff); + CopyInt(&pPlayer->_pHitPoints, tbuff); + CopyInt(&pPlayer->_pMaxHP, tbuff); + CopyInt(&pPlayer->_pHPPer, tbuff); + CopyInt(&pPlayer->_pManaBase, tbuff); + CopyInt(&pPlayer->_pMaxManaBase, tbuff); + CopyInt(&pPlayer->_pMana, tbuff); + CopyInt(&pPlayer->_pMaxMana, tbuff); + CopyInt(&pPlayer->_pManaPer, tbuff); + CopyChar(&pPlayer->_pLevel, tbuff); + CopyChar(&pPlayer->_pMaxLvl, tbuff); + tbuff += 2; + CopyInt(&pPlayer->_pExperience, tbuff); + CopyInt(&pPlayer->_pMaxExp, tbuff); + CopyInt(&pPlayer->_pNextExper, tbuff); + CopyChar(&pPlayer->_pArmorClass, tbuff); + CopyChar(&pPlayer->_pMagResist, tbuff); + CopyChar(&pPlayer->_pFireResist, tbuff); + CopyChar(&pPlayer->_pLghtResist, tbuff); + CopyInt(&pPlayer->_pGold, tbuff); + CopyInt(&pPlayer->_pInfraFlag, tbuff); + CopyInt(&pPlayer->_pVar1, tbuff); + CopyInt(&pPlayer->_pVar2, tbuff); + CopyInt(&pPlayer->_pVar3, tbuff); + CopyInt(&pPlayer->_pVar4, tbuff); + CopyInt(&pPlayer->_pVar5, tbuff); + CopyInt(&pPlayer->_pVar6, tbuff); + CopyInt(&pPlayer->_pVar7, tbuff); + CopyInt(&pPlayer->_pVar8, tbuff); + CopyBytes(&pPlayer->_pLvlVisited, NUMLEVELS, tbuff); + CopyBytes(&pPlayer->_pSLvlVisited, NUMLEVELS, tbuff); // only 10 used + tbuff += 2; + CopyInt(&pPlayer->_pGFXLoad, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + CopyInt(&pPlayer->_pNFrames, tbuff); + CopyInt(&pPlayer->_pNWidth, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pWFrames, tbuff); + CopyInt(&pPlayer->_pWWidth, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pAFrames, tbuff); + CopyInt(&pPlayer->_pAWidth, tbuff); + CopyInt(&pPlayer->_pAFNum, tbuff); + + tbuff += sizeof(DWORD) * 24; // Skip 24 pointers + + CopyInt(&pPlayer->_pSFrames, tbuff); + CopyInt(&pPlayer->_pSWidth, tbuff); + CopyInt(&pPlayer->_pSFNum, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pHFrames, tbuff); + CopyInt(&pPlayer->_pHWidth, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pDFrames, tbuff); + CopyInt(&pPlayer->_pDWidth, tbuff); + + tbuff += sizeof(DWORD) * 8; // Skip 8 pointers + + CopyInt(&pPlayer->_pBFrames, tbuff); + CopyInt(&pPlayer->_pBWidth, tbuff); + SaveItems(pPlayer->InvBody, NUM_INVLOC); + SaveItems(pPlayer->InvList, NUM_INV_GRID_ELEM); + CopyInt(&pPlayer->_pNumInv, tbuff); + CopyBytes(pPlayer->InvGrid, NUM_INV_GRID_ELEM, tbuff); + SaveItems(pPlayer->SpdList, MAXBELTITEMS); + SaveItem(&pPlayer->HoldItem); + CopyInt(&pPlayer->_pIMinDam, tbuff); + CopyInt(&pPlayer->_pIMaxDam, tbuff); + CopyInt(&pPlayer->_pIAC, tbuff); + CopyInt(&pPlayer->_pIBonusDam, tbuff); + CopyInt(&pPlayer->_pIBonusToHit, tbuff); + CopyInt(&pPlayer->_pIBonusAC, tbuff); + CopyInt(&pPlayer->_pIBonusDamMod, tbuff); + tbuff += 4; + CopyInt64(&pPlayer->_pISpells, tbuff); + CopyInt(&pPlayer->_pIFlags, tbuff); + CopyInt(&pPlayer->_pIGetHit, tbuff); + + CopyChar(&pPlayer->_pISplLvlAdd, tbuff); + CopyChar(&pPlayer->_pISplCost, tbuff); + tbuff += 2; + + CopyInt(&pPlayer->_pISplDur, tbuff); + CopyInt(&pPlayer->_pIEnAc, tbuff); + CopyInt(&pPlayer->_pIFMinDam, tbuff); + CopyInt(&pPlayer->_pIFMaxDam, tbuff); + CopyInt(&pPlayer->_pILMinDam, tbuff); + CopyInt(&pPlayer->_pILMaxDam, tbuff); + CopyInt(&pPlayer->_pOilType, tbuff); + + CopyChar(&pPlayer->pTownWarps, tbuff); + CopyChar(&pPlayer->pDungMsgs, tbuff); + CopyChar(&pPlayer->pLvlLoad, tbuff); + CopyChar(&pPlayer->pBattleNet, tbuff); + + CopyChar(&pPlayer->pManaShield, tbuff); + CopyBytes(&pPlayer->bReserved, 3, tbuff); + + CopyShorts(&pPlayer->wReserved, 8, tbuff); + + CopyInt(&pPlayer->pDiabloKillLevel, tbuff); + CopyInts(&pPlayer->dwReserved, 7, tbuff); + + // Omit 10 pointers +} + void SaveMonster(int i) { MonsterStruct *pMonster = &monster[i]; @@ -1421,6 +1338,91 @@ void SaveObject(int i) CopyInt(&pObject->_oVar8, tbuff); } +void SaveItem(ItemStruct *pItem) +{ + CopyInt(&pItem->_iSeed, tbuff); + CopyShort(&pItem->_iCreateInfo, tbuff); + tbuff += 2; + CopyInt(&pItem->_itype, tbuff); + CopyInt(&pItem->_ix, tbuff); + CopyInt(&pItem->_iy, tbuff); + CopyInt(&pItem->_iAnimFlag, tbuff); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(&pItem->_iAnimLen, tbuff); + CopyInt(&pItem->_iAnimFrame, tbuff); + CopyInt(&pItem->_iAnimWidth, tbuff); + CopyInt(&pItem->_iAnimWidth2, tbuff); // width 2? + CopyInt(&pItem->_isin, tbuff); // set when item is flagged for deletion, deprecated in 1.02 + CopyChar(&pItem->_iSelFlag, tbuff); + tbuff += 3; + CopyInt(&pItem->_iPostDraw, tbuff); + CopyInt(&pItem->_iIdentified, tbuff); + CopyChar(&pItem->_iMagical, tbuff); + CopyBytes(&pItem->_iName, 64, tbuff); + CopyBytes(&pItem->_iIName, 64, tbuff); + CopyChar(&pItem->_iLoc, tbuff); + CopyChar(&pItem->_iClass, tbuff); + tbuff += 1; + CopyInt(&pItem->_iCurs, tbuff); + CopyInt(&pItem->_ivalue, tbuff); + CopyInt(&pItem->_iIvalue, tbuff); + CopyInt(&pItem->_iMinDam, tbuff); + CopyInt(&pItem->_iMaxDam, tbuff); + CopyInt(&pItem->_iAC, tbuff); + CopyInt(&pItem->_iFlags, tbuff); + CopyInt(&pItem->_iMiscId, tbuff); + CopyInt(&pItem->_iSpell, tbuff); + CopyInt(&pItem->_iCharges, tbuff); + CopyInt(&pItem->_iMaxCharges, tbuff); + CopyInt(&pItem->_iDurability, tbuff); + CopyInt(&pItem->_iMaxDur, tbuff); + CopyInt(&pItem->_iPLDam, tbuff); + CopyInt(&pItem->_iPLToHit, tbuff); + CopyInt(&pItem->_iPLAC, tbuff); + CopyInt(&pItem->_iPLStr, tbuff); + CopyInt(&pItem->_iPLMag, tbuff); + CopyInt(&pItem->_iPLDex, tbuff); + CopyInt(&pItem->_iPLVit, tbuff); + CopyInt(&pItem->_iPLFR, tbuff); + CopyInt(&pItem->_iPLLR, tbuff); + CopyInt(&pItem->_iPLMR, tbuff); + CopyInt(&pItem->_iPLMana, tbuff); + CopyInt(&pItem->_iPLHP, tbuff); + CopyInt(&pItem->_iPLDamMod, tbuff); + CopyInt(&pItem->_iPLGetHit, tbuff); + CopyInt(&pItem->_iPLLight, tbuff); + CopyChar(&pItem->_iSplLvlAdd, tbuff); + CopyChar(&pItem->_iRequest, tbuff); + tbuff += 2; + CopyInt(&pItem->_iUid, tbuff); + CopyInt(&pItem->_iFMinDam, tbuff); + CopyInt(&pItem->_iFMaxDam, tbuff); + CopyInt(&pItem->_iLMinDam, tbuff); + CopyInt(&pItem->_iLMaxDam, tbuff); + CopyInt(&pItem->_iPLEnAc, tbuff); + CopyChar(&pItem->_iPrePower, tbuff); + CopyChar(&pItem->_iSufPower, tbuff); + tbuff += 2; + CopyInt(&pItem->_iVAdd1, tbuff); + CopyInt(&pItem->_iVMult1, tbuff); + CopyInt(&pItem->_iVAdd2, tbuff); + CopyInt(&pItem->_iVMult2, tbuff); + CopyChar(&pItem->_iMinStr, tbuff); + CopyChar(&pItem->_iMinMag, tbuff); + CopyChar(&pItem->_iMinDex, tbuff); + tbuff += 1; + CopyInt(&pItem->_iStatFlag, tbuff); + CopyInt(&pItem->IDidx, tbuff); + CopyInt(&pItem->offs016C, tbuff); +} + +void SaveItems(ItemStruct *pItem, const int n) +{ + for (int i = 0; i < n; i++) { + SaveItem(&pItem[i]); + } +} + void SavePremium(int i) { SaveItem(&item[i]); From e2630377073b74d9e5b41f4f99920e8cad4f945d Mon Sep 17 00:00:00 2001 From: Alex Sweet Date: Mon, 8 Jul 2019 09:36:04 -0700 Subject: [PATCH 11/11] Undo style changes --- structs.h | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/structs.h b/structs.h index b949f8487e8..051fa76dbe1 100644 --- a/structs.h +++ b/structs.h @@ -1,5 +1,3 @@ -#pragma once - ////////////////////////////////////////////////// // control ////////////////////////////////////////////////// @@ -174,7 +172,7 @@ typedef struct ItemStruct { typedef struct PlayerStruct { int _pmode; char walkpath[25]; - uint8_t plractive; + BOOLEAN plractive; int destAction; int destParam1; int destParam2; @@ -372,8 +370,8 @@ typedef struct TextDataStruct { typedef struct MissileData { unsigned char mName; - void (*mAddProc)(int, int, int, int, int, int, char, int, int); - void (*mProc)(int); + void(* mAddProc)(int, int, int, int, int, int, char, int, int); + void(* mProc)(int); BOOL mDraw; unsigned char mType; unsigned char mResist; @@ -971,6 +969,7 @@ typedef struct TBuffer { ////////////////////////////////////////////////// // quests ////////////////////////////////////////////////// + #pragma pack(push, 4) typedef struct QuestStruct { unsigned char _qlevel; @@ -1009,7 +1008,7 @@ typedef struct QuestData { typedef struct TMenuItem { DWORD dwFlags; char *pszStr; - void (*fnMenu)(BOOL); /* fix, should have one arg */ + void(* fnMenu)(BOOL); /* fix, should have one arg */ } TMenuItem; // TPDEF PTR FCN VOID TMenuUpdateFcn @@ -1321,21 +1320,21 @@ typedef struct _SNETUIDATA { int size; int uiflags; HWND parentwindow; - void (*artcallback)(); - void (*authcallback)(); - void (*createcallback)(); - void (*drawdesccallback)(); - void (*selectedcallback)(); - void (*messageboxcallback)(); - void (*soundcallback)(); - void (*statuscallback)(); - void (*getdatacallback)(); - void (*categorycallback)(); - void (*categorylistcallback)(); - void (*newaccountcallback)(); - void (*profilecallback)(); + void(* artcallback)(); + void(* authcallback)(); + void(* createcallback)(); + void(* drawdesccallback)(); + void(* selectedcallback)(); + void(* messageboxcallback)(); + void(* soundcallback)(); + void(* statuscallback)(); + void(* getdatacallback)(); + void(* categorycallback)(); + void(* categorylistcallback)(); + void(* newaccountcallback)(); + void(* profilecallback)(); int profilefields; - void (*profilebitmapcallback)(); + void(* profilebitmapcallback)(); int(__stdcall *selectnamecallback)( const struct _SNETPROGRAMDATA *, const struct _SNETPLAYERDATA *, @@ -1345,8 +1344,8 @@ typedef struct _SNETUIDATA { char *, DWORD, /* character name will be copied here */ char *, DWORD, /* character "description" will be copied here (used to advertise games) */ BOOL * /* new character? - unsure about this */ - ); - void (*changenamecallback)(); + ); + void(* changenamecallback)(); } _SNETUIDATA; typedef struct _SNETVERSIONDATA {