diff --git a/Source/inv.cpp b/Source/inv.cpp index 5567a4097..27381f944 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1867,7 +1867,7 @@ void CleanupItems(int ii) if (currlevel == 21 & item[ii]._ix == CornerStone.x && item[ii]._iy == CornerStone.y) { CornerStone.item.IDidx = -1; CornerStone.item._itype = ITYPE_MISC; - CornerStone.item._iSelFlag = FALSE; + CornerStone.item._iSelFlag = 0; CornerStone.item._ix = 0; CornerStone.item._iy = 0; CornerStone.item._iAnimFlag = FALSE; diff --git a/Source/items.h b/Source/items.h index d345d6a6a..058f61f08 100644 --- a/Source/items.h +++ b/Source/items.h @@ -66,7 +66,7 @@ typedef struct ItemStruct { Sint32 _iAnimWidth; Sint32 _iAnimWidth2; // width 2? bool _iDelFlag; // set when item is flagged for deletion, deprecated in 1.02 - Sint8 _iSelFlag; + Uint8 _iSelFlag; bool _iPostDraw; bool _iIdentified; Sint8 _iMagical; diff --git a/Source/lighting.h b/Source/lighting.h index 67b7c97a0..d53256041 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -17,15 +17,14 @@ typedef struct LightListStruct { int _ly; int _lradius; int _lid; - int _ldel; - int _lunflag; - int field_18; + bool _ldel; + bool _lunflag; int _lunx; int _luny; int _lunr; int _xoff; int _yoff; - int _lflags; + bool _lflags; } LightListStruct; extern LightListStruct VisionList[MAXVISION]; diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index b7af3521e..fbf2d2bab 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -7,51 +7,108 @@ DEVILUTION_BEGIN_NAMESPACE -BYTE *tbuff; - bool gbIsHellfireSaveGame; int giNumberOfLevels; int giNumberQuests; int giNumberOfSmithPremiumItems; +namespace { + +template +T SwapLE(T in) +{ + switch (sizeof(T)) { + case 2: + return SDL_SwapLE16(in); + case 4: + return SDL_SwapLE32(in); + case 8: + return SDL_SwapLE64(in); + default: + return in; + } +} + +template +T SwapBE(T in) +{ + switch (sizeof(T)) { + case 2: + return SDL_SwapBE16(in); + case 4: + return SDL_SwapBE32(in); + case 8: + return SDL_SwapBE64(in); + default: + return in; + } +} + class LoadHelper { Uint8 *m_buffer; Uint32 m_bufferPtr = 0; Uint32 m_bufferLen; + template + T next() + { + const auto size = sizeof(T); + if (!isValid(size)) + return 0; + + T value; + memcpy(&value, &m_buffer[m_bufferPtr], size); + m_bufferPtr += size; + + return value; + } + public: LoadHelper(const char *szFileName) { m_buffer = pfile_read(szFileName, &m_bufferLen); } - bool isValid(Uint32 len = 1) + bool isValid(Uint32 size = 1) { return m_buffer != nullptr - && m_bufferLen >= (m_bufferPtr + len); + && m_bufferLen >= (m_bufferPtr + size); } - Uint8 nextByte() + void skip(Uint32 size) { - if (!this->isValid(1)) - return 0; + m_bufferPtr += size; + } - Uint8 value = m_buffer[m_bufferPtr]; - m_bufferPtr++; + void nextBytes(void *bytes, size_t size) + { + if (!isValid(size)) + return; - return value; + memcpy(bytes, &m_buffer[m_bufferPtr], size); + m_bufferPtr += size; } - Uint32 nextLE32() + template + T nextLE() { - if (!this->isValid(4)) - return 0; + return SwapLE(next()); + } + + template + T nextBE() + { + return SwapBE(next()); + } - Uint32 value; - memcpy(&value, &m_buffer[m_bufferPtr], 4); - m_bufferPtr += 4; + bool nextBool8() + { + return next() != 0; + } - return SDL_SwapLE32(value); + bool nextBool32() + { + return next() != 0; } ~LoadHelper() @@ -80,216 +137,133 @@ public: && m_bufferLen >= (m_bufferPtr + len); } - void writeByte(Uint8 value) + void skip(Uint32 len) { - if (!this->isValid(1)) - return; - - m_buffer[m_bufferPtr] = SDL_SwapLE32(value); - m_bufferPtr++; + m_bufferPtr += len; } - void writeLE32(Uint32 value) + void writeBytes(const void *bytes, size_t len) { - if (!this->isValid(4)) + if (!isValid(len)) return; - Uint32 temp = SDL_SwapLE32(value); - memcpy(&m_buffer[m_bufferPtr], &temp, 4); - m_bufferPtr += 4; + memcpy(&m_buffer[m_bufferPtr], bytes, len); + m_bufferPtr += len; } - ~SaveHelper() + template + void writeLE(T value) { - pfile_write_save_file(m_szFileName, m_buffer, m_bufferPtr, codec_get_encoded_len(m_bufferPtr)); - mem_free_dbg(m_buffer); + value = SwapLE(value); + writeBytes(&value, sizeof(value)); } -}; - -static char BLoad() -{ - return *tbuff++; -} - -#define WLoad ILoad - -static int ILoad() -{ - int rv = *tbuff++ << 24; - rv |= *tbuff++ << 16; - rv |= *tbuff++ << 8; - rv |= *tbuff++; - - return rv; -} - -static Uint32 LoadUint32LE() -{ - Uint32 buf; - memcpy(&buf, tbuff, 4); - tbuff += 4; - - return SwapLE32(buf); -} -static bool LoadBool8() -{ - if (*tbuff++ == TRUE) - return TRUE; - else - return FALSE; -} - -static bool LoadBool32() -{ - Uint32 buf; - memcpy(&buf, tbuff, 4); - tbuff += 4; - return buf != 0; -} - -static void CopyBytes(const void *src, const int n, void *dst) -{ - memcpy(dst, src, n); - tbuff += n; -} - -static void CopyChar(const void *src, void *dst) -{ - *(char *)dst = *(char *)src; - tbuff += 1; -} + template + void writeBE(T value) + { + value = SwapBE(value); + writeBytes(&value, sizeof(value)); + } -static void CopyShort(const void *src, void *dst) -{ - unsigned short buf; - memcpy(&buf, src, 2); - buf = SwapLE16(buf); - memcpy(dst, &buf, 2); - tbuff += 2; -} + void flush() + { + if (m_buffer == nullptr) + return; -static void CopyShorts(const void *src, const int n, void *dst) -{ - const unsigned short *s = reinterpret_cast(src); - unsigned short *d = reinterpret_cast(dst); - for (int i = 0; i < n; i++) { - CopyShort(s, d); - ++d; - ++s; + pfile_write_save_file(m_szFileName, m_buffer, m_bufferPtr, codec_get_encoded_len(m_bufferPtr)); + mem_free_dbg(m_buffer); + m_buffer = nullptr; } -} -static void CopyInt(const void *src, void *dst) -{ - unsigned int buf; - memcpy(&buf, src, 4); - buf = SwapLE32(buf); - memcpy(dst, &buf, 4); - tbuff += 4; -} - -static void CopyInts(const void *src, const int n, void *dst) -{ - const unsigned int *s = reinterpret_cast(src); - const unsigned int *d = reinterpret_cast(dst); - for (int i = 0; i < n; i++) { - CopyInt(s, (void *)d); - ++d; - ++s; + ~SaveHelper() + { + flush(); } -} +}; -static void CopyInt64(const void *src, void *dst) -{ - unsigned long long buf; - memcpy(&buf, src, 8); - buf = SDL_SwapLE64(buf); - memcpy(dst, &buf, 8); - tbuff += 8; } -static void LoadItemData(ItemStruct *pItem) +static void LoadItemData(LoadHelper *file, ItemStruct *pItem) { - CopyInt(tbuff, &pItem->_iSeed); - CopyShort(tbuff, &pItem->_iCreateInfo); - tbuff += 2; // Alignment - pItem->_itype = (item_type)LoadUint32LE(); - CopyInt(tbuff, &pItem->_ix); - CopyInt(tbuff, &pItem->_iy); - pItem->_iAnimFlag = LoadBool32(); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(tbuff, &pItem->_iAnimLen); - CopyInt(tbuff, &pItem->_iAnimFrame); - CopyInt(tbuff, &pItem->_iAnimWidth); - CopyInt(tbuff, &pItem->_iAnimWidth2); - tbuff += 4; // Unused since 1.02 - CopyChar(tbuff, &pItem->_iSelFlag); - tbuff += 3; // Alignment - pItem->_iPostDraw = LoadBool32(); - pItem->_iIdentified = LoadBool32(); - CopyChar(tbuff, &pItem->_iMagical); - CopyBytes(tbuff, 64, &pItem->_iName); - CopyBytes(tbuff, 64, &pItem->_iIName); - pItem->_iLoc = (item_equip_type)BLoad(); - pItem->_iClass = (item_class)BLoad(); - tbuff += 1; // Alignment - 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); - pItem->_iMiscId = (item_misc_id)LoadUint32LE(); - pItem->_iSpell = (spell_id)LoadUint32LE(); - 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; // Alignment - CopyInt(tbuff, &pItem->_iUid); - CopyInt(tbuff, &pItem->_iFMinDam); - CopyInt(tbuff, &pItem->_iFMaxDam); - CopyInt(tbuff, &pItem->_iLMinDam); - CopyInt(tbuff, &pItem->_iLMaxDam); - CopyInt(tbuff, &pItem->_iPLEnAc); - pItem->_iPrePower = (item_effect_type)BLoad(); - pItem->_iSufPower = (item_effect_type)BLoad(); - tbuff += 2; // Alignment - 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; // Alignment - pItem->_iStatFlag = LoadBool32(); - CopyInt(tbuff, &pItem->IDidx); + pItem->_iSeed = file->nextLE(); + pItem->_iCreateInfo = file->nextLE(); + file->skip(2); // Alignment + pItem->_itype = (item_type)file->nextLE(); + pItem->_ix = file->nextLE(); + pItem->_iy = file->nextLE(); + pItem->_iAnimFlag = file->nextBool32(); + file->skip(4); // Skip pointer _iAnimData + pItem->_iAnimLen = file->nextLE(); + pItem->_iAnimFrame = file->nextLE(); + pItem->_iAnimWidth = file->nextLE(); + pItem->_iAnimWidth2 = file->nextLE(); + file->skip(4); // Unused since 1.02 + pItem->_iSelFlag = file->nextLE(); + file->skip(3); // Alignment + pItem->_iPostDraw = file->nextBool32(); + pItem->_iIdentified = file->nextBool32(); + pItem->_iMagical = file->nextLE(); + file->nextBytes(pItem->_iName, 64); + file->nextBytes(pItem->_iIName, 64); + pItem->_iLoc = (item_equip_type)file->nextLE(); + pItem->_iClass = (item_class)file->nextLE(); + file->skip(1); // Alignment + pItem->_iCurs = file->nextLE(); + pItem->_ivalue = file->nextLE(); + pItem->_iIvalue = file->nextLE(); + pItem->_iMinDam = file->nextLE(); + pItem->_iMaxDam = file->nextLE(); + pItem->_iAC = file->nextLE(); + pItem->_iFlags = file->nextLE(); + pItem->_iMiscId = (item_misc_id)file->nextLE(); + pItem->_iSpell = (spell_id)file->nextLE(); + pItem->_iCharges = file->nextLE(); + pItem->_iMaxCharges = file->nextLE(); + pItem->_iDurability = file->nextLE(); + pItem->_iMaxDur = file->nextLE(); + pItem->_iPLDam = file->nextLE(); + pItem->_iPLToHit = file->nextLE(); + pItem->_iPLAC = file->nextLE(); + pItem->_iPLStr = file->nextLE(); + pItem->_iPLMag = file->nextLE(); + pItem->_iPLDex = file->nextLE(); + pItem->_iPLVit = file->nextLE(); + pItem->_iPLFR = file->nextLE(); + pItem->_iPLLR = file->nextLE(); + pItem->_iPLMR = file->nextLE(); + pItem->_iPLMana = file->nextLE(); + pItem->_iPLHP = file->nextLE(); + pItem->_iPLDamMod = file->nextLE(); + pItem->_iPLGetHit = file->nextLE(); + pItem->_iPLLight = file->nextLE(); + pItem->_iSplLvlAdd = file->nextLE(); + pItem->_iRequest = file->nextLE(); + file->skip(2); // Alignment + pItem->_iUid = file->nextLE(); + pItem->_iFMinDam = file->nextLE(); + pItem->_iFMaxDam = file->nextLE(); + pItem->_iLMinDam = file->nextLE(); + pItem->_iLMaxDam = file->nextLE(); + pItem->_iPLEnAc = file->nextLE(); + pItem->_iPrePower = (item_effect_type)file->nextLE(); + pItem->_iSufPower = (item_effect_type)file->nextLE(); + file->skip(2); // Alignment + pItem->_iVAdd1 = file->nextLE(); + pItem->_iVMult1 = file->nextLE(); + pItem->_iVAdd2 = file->nextLE(); + pItem->_iVMult2 = file->nextLE(); + pItem->_iMinStr = file->nextLE(); + pItem->_iMinMag = file->nextLE(); + pItem->_iMinDex = file->nextLE(); + file->skip(1); // Alignment + pItem->_iStatFlag = file->nextBool32(); + pItem->IDidx = file->nextLE(); if (!gbIsHellfireSaveGame) { pItem->IDidx = RemapItemIdxFromDiablo(pItem->IDidx); } - tbuff += 4; // Unused + file->skip(4); // Unused if (gbIsHellfireSaveGame) - CopyInt(tbuff, &pItem->_iDamAcFlags); + pItem->_iDamAcFlags = file->nextLE(); else pItem->_iDamAcFlags = 0; @@ -299,218 +273,227 @@ static void LoadItemData(ItemStruct *pItem) } } -static void LoadItems(const int n, ItemStruct *pItem) +static void LoadItems(LoadHelper *file, const int n, ItemStruct *pItem) { for (int i = 0; i < n; i++) { - LoadItemData(&pItem[i]); + LoadItemData(file, &pItem[i]); } } -static void LoadPlayer(int i) +static void LoadPlayer(LoadHelper *file, int p) { - PlayerStruct *pPlayer = &plr[i]; - - CopyInt(tbuff, &pPlayer->_pmode); - CopyBytes(tbuff, MAX_PATH_LENGTH, pPlayer->walkpath); - CopyBytes(tbuff, 1, &pPlayer->plractive); - tbuff += 2; // Alignment - 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->_px); - CopyInt(tbuff, &pPlayer->_py); - CopyInt(tbuff, &pPlayer->_pfutx); - CopyInt(tbuff, &pPlayer->_pfuty); - 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 pointer _pAnimData - CopyInt(tbuff, &pPlayer->_pAnimDelay); - CopyInt(tbuff, &pPlayer->_pAnimCnt); - CopyInt(tbuff, &pPlayer->_pAnimLen); - CopyInt(tbuff, &pPlayer->_pAnimFrame); - CopyInt(tbuff, &pPlayer->_pAnimWidth); - CopyInt(tbuff, &pPlayer->_pAnimWidth2); - tbuff += 4; // Skip _peflag - CopyInt(tbuff, &pPlayer->_plid); - CopyInt(tbuff, &pPlayer->_pvid); - - CopyInt(tbuff, &pPlayer->_pSpell); - CopyChar(tbuff, &pPlayer->_pSplType); - CopyChar(tbuff, &pPlayer->_pSplFrom); - tbuff += 2; // Alignment - CopyInt(tbuff, &pPlayer->_pTSpell); - CopyChar(tbuff, &pPlayer->_pTSplType); - tbuff += 3; // Alignment - CopyInt(tbuff, &pPlayer->_pRSpell); - CopyChar(tbuff, &pPlayer->_pRSplType); - tbuff += 3; // Alignment - CopyInt(tbuff, &pPlayer->_pSBkSpell); - CopyChar(tbuff, &pPlayer->_pSBkSplType); - CopyBytes(tbuff, 64, &pPlayer->_pSplLvl); - tbuff += 7; // Alignment - CopyInt64(tbuff, &pPlayer->_pMemSpells); - CopyInt64(tbuff, &pPlayer->_pAblSpells); - CopyInt64(tbuff, &pPlayer->_pScrlSpells); - CopyChar(tbuff, &pPlayer->_pSpellFlags); - tbuff += 3; // Alignment - 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; // Alignment - 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); - if (pPlayer->_pBaseToBlk == 0) { + PlayerStruct *pPlayer = &plr[p]; + + pPlayer->_pmode = file->nextLE(); + + for (int i = 0; i < MAX_PATH_LENGTH; i++) { + pPlayer->walkpath[i] = file->nextLE(); + } + pPlayer->plractive = file->nextBool8(); + file->skip(2); // Alignment + pPlayer->destAction = file->nextLE(); + pPlayer->destParam1 = file->nextLE(); + pPlayer->destParam2 = file->nextLE(); + pPlayer->destParam3 = file->nextLE(); + pPlayer->destParam4 = file->nextLE(); + pPlayer->plrlevel = file->nextLE(); + pPlayer->_px = file->nextLE(); + pPlayer->_py = file->nextLE(); + pPlayer->_pfutx = file->nextLE(); + pPlayer->_pfuty = file->nextLE(); + pPlayer->_ptargx = file->nextLE(); + pPlayer->_ptargy = file->nextLE(); + pPlayer->_pownerx = file->nextLE(); + pPlayer->_pownery = file->nextLE(); + pPlayer->_poldx = file->nextLE(); + pPlayer->_poldy = file->nextLE(); + pPlayer->_pxoff = file->nextLE(); + pPlayer->_pyoff = file->nextLE(); + pPlayer->_pxvel = file->nextLE(); + pPlayer->_pyvel = file->nextLE(); + pPlayer->_pdir = file->nextLE(); + file->skip(4); // Unused + pPlayer->_pgfxnum = file->nextLE(); + file->skip(4); // Skip pointer _pAnimData + pPlayer->_pAnimDelay = file->nextLE(); + pPlayer->_pAnimCnt = file->nextLE(); + pPlayer->_pAnimLen = file->nextLE(); + pPlayer->_pAnimFrame = file->nextLE(); + pPlayer->_pAnimWidth = file->nextLE(); + pPlayer->_pAnimWidth2 = file->nextLE(); + file->skip(4); // Skip _peflag + pPlayer->_plid = file->nextLE(); + pPlayer->_pvid = file->nextLE(); + + pPlayer->_pSpell = file->nextLE(); + pPlayer->_pSplType = file->nextLE(); + pPlayer->_pSplFrom = file->nextLE(); + file->skip(2); // Alignment + pPlayer->_pTSpell = file->nextLE(); + pPlayer->_pTSplType = file->nextLE(); + file->skip(3); // Alignment + pPlayer->_pRSpell = file->nextLE(); + pPlayer->_pRSplType = file->nextLE(); + file->skip(3); // Alignment + pPlayer->_pSBkSpell = file->nextLE(); + pPlayer->_pSBkSplType = file->nextLE(); + for (int i = 0; i < 64; i++) + pPlayer->_pSplLvl[i] = file->nextLE(); + file->skip(7); // Alignment + pPlayer->_pMemSpells = file->nextLE(); + pPlayer->_pAblSpells = file->nextLE(); + pPlayer->_pScrlSpells = file->nextLE(); + pPlayer->_pSpellFlags = file->nextLE(); + file->skip(3); // Alignment + for (int i = 0; i < 4; i++) + pPlayer->_pSplHotKey[i] = file->nextLE(); + for (int i = 0; i < 4; i++) + pPlayer->_pSplTHotKey[i] = file->nextLE(); + + pPlayer->_pwtype = file->nextLE(); + pPlayer->_pBlockFlag = file->nextBool8(); + pPlayer->_pInvincible = file->nextBool8(); + pPlayer->_pLightRad = file->nextLE(); + pPlayer->_pLvlChanging = file->nextBool8(); + + file->nextBytes(pPlayer->_pName, PLR_NAME_LEN); + pPlayer->_pClass = file->nextLE(); + file->skip(3); // Alignment + pPlayer->_pStrength = file->nextLE(); + pPlayer->_pBaseStr = file->nextLE(); + pPlayer->_pMagic = file->nextLE(); + pPlayer->_pBaseMag = file->nextLE(); + pPlayer->_pDexterity = file->nextLE(); + pPlayer->_pBaseDex = file->nextLE(); + pPlayer->_pVitality = file->nextLE(); + pPlayer->_pBaseVit = file->nextLE(); + pPlayer->_pStatPts = file->nextLE(); + pPlayer->_pDamageMod = file->nextLE(); + pPlayer->_pBaseToBlk = file->nextLE(); + if (pPlayer->_pBaseToBlk == 0) pPlayer->_pBaseToBlk = ToBlkTbl[pPlayer->_pClass]; - } - 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; // Alignment - 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, giNumberOfLevels, &pPlayer->_pLvlVisited); - CopyBytes(tbuff, giNumberOfLevels, &pPlayer->_pSLvlVisited); - tbuff += 2; // Alignment - - CopyInt(tbuff, &pPlayer->_pGFXLoad); - tbuff += 4 * 8; // Skip pointers _pNAnim - CopyInt(tbuff, &pPlayer->_pNFrames); - CopyInt(tbuff, &pPlayer->_pNWidth); - tbuff += 4 * 8; // Skip pointers _pWAnim - CopyInt(tbuff, &pPlayer->_pWFrames); - CopyInt(tbuff, &pPlayer->_pWWidth); - tbuff += 4 * 8; // Skip pointers _pAAnim - CopyInt(tbuff, &pPlayer->_pAFrames); - CopyInt(tbuff, &pPlayer->_pAWidth); - CopyInt(tbuff, &pPlayer->_pAFNum); - tbuff += 4 * 8; // Skip pointers _pLAnim - tbuff += 4 * 8; // Skip pointers _pFAnim - tbuff += 4 * 8; // Skip pointers _pTAnim - CopyInt(tbuff, &pPlayer->_pSFrames); - CopyInt(tbuff, &pPlayer->_pSWidth); - CopyInt(tbuff, &pPlayer->_pSFNum); - tbuff += 4 * 8; // Skip pointers _pHAnim - CopyInt(tbuff, &pPlayer->_pHFrames); - CopyInt(tbuff, &pPlayer->_pHWidth); - tbuff += 4 * 8; // Skip pointers _pDAnim - CopyInt(tbuff, &pPlayer->_pDFrames); - CopyInt(tbuff, &pPlayer->_pDWidth); - tbuff += 4 * 8; // Skip pointers _pBAnim - CopyInt(tbuff, &pPlayer->_pBFrames); - CopyInt(tbuff, &pPlayer->_pBWidth); - - LoadItems(NUM_INVLOC, pPlayer->InvBody); - LoadItems(NUM_INV_GRID_ELEM, pPlayer->InvList); - CopyInt(tbuff, &pPlayer->_pNumInv); - CopyBytes(tbuff, NUM_INV_GRID_ELEM, pPlayer->InvGrid); - LoadItems(MAXBELTITEMS, pPlayer->SpdList); - LoadItemData(&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; // Alignment - - CopyInt64(tbuff, &pPlayer->_pISpells); - CopyInt(tbuff, &pPlayer->_pIFlags); - CopyInt(tbuff, &pPlayer->_pIGetHit); - CopyChar(tbuff, &pPlayer->_pISplLvlAdd); - CopyChar(tbuff, &pPlayer->_pISplCost); - tbuff += 2; // Alignment - 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); + pPlayer->_pHPBase = file->nextLE(); + pPlayer->_pMaxHPBase = file->nextLE(); + pPlayer->_pHitPoints = file->nextLE(); + pPlayer->_pMaxHP = file->nextLE(); + pPlayer->_pHPPer = file->nextLE(); + pPlayer->_pManaBase = file->nextLE(); + pPlayer->_pMaxManaBase = file->nextLE(); + pPlayer->_pMana = file->nextLE(); + pPlayer->_pMaxMana = file->nextLE(); + pPlayer->_pManaPer = file->nextLE(); + pPlayer->_pLevel = file->nextLE(); + pPlayer->_pMaxLvl = file->nextLE(); + file->skip(2); // Alignment + pPlayer->_pExperience = file->nextLE(); + pPlayer->_pMaxExp = file->nextLE(); + pPlayer->_pNextExper = file->nextLE(); + pPlayer->_pArmorClass = file->nextLE(); + pPlayer->_pMagResist = file->nextLE(); + pPlayer->_pFireResist = file->nextLE(); + pPlayer->_pLghtResist = file->nextLE(); + pPlayer->_pGold = file->nextLE(); + + pPlayer->_pInfraFlag = file->nextBool32(); + pPlayer->_pVar1 = file->nextLE(); + pPlayer->_pVar2 = file->nextLE(); + pPlayer->_pVar3 = file->nextLE(); + pPlayer->_pVar4 = file->nextLE(); + pPlayer->_pVar5 = file->nextLE(); + pPlayer->_pVar6 = file->nextLE(); + pPlayer->_pVar7 = file->nextLE(); + pPlayer->_pVar8 = file->nextLE(); + for (int i = 0; i < giNumberOfLevels; i++) + pPlayer->_pLvlVisited[i] = file->nextBool8(); + for (int i = 0; i < giNumberOfLevels; i++) + pPlayer->_pSLvlVisited[i] = file->nextBool8(); + + file->skip(2); // Alignment + + pPlayer->_pGFXLoad = file->nextLE(); + file->skip(4 * 8); // Skip pointers _pNAnim + pPlayer->_pNFrames = file->nextLE(); + pPlayer->_pNWidth = file->nextLE(); + file->skip(4 * 8); // Skip pointers _pWAnim + pPlayer->_pWFrames = file->nextLE(); + pPlayer->_pWWidth = file->nextLE(); + file->skip(4 * 8); // Skip pointers _pAAnim + pPlayer->_pAFrames = file->nextLE(); + pPlayer->_pAWidth = file->nextLE(); + pPlayer->_pAFNum = file->nextLE(); + file->skip(4 * 8); // Skip pointers _pLAnim + file->skip(4 * 8); // Skip pointers _pFAnim + file->skip(4 * 8); // Skip pointers _pTAnim + pPlayer->_pSFrames = file->nextLE(); + pPlayer->_pSWidth = file->nextLE(); + pPlayer->_pSFNum = file->nextLE(); + file->skip(4 * 8); // Skip pointers _pHAnim + pPlayer->_pHFrames = file->nextLE(); + pPlayer->_pHWidth = file->nextLE(); + file->skip(4 * 8); // Skip pointers _pDAnim + pPlayer->_pDFrames = file->nextLE(); + pPlayer->_pDWidth = file->nextLE(); + file->skip(4 * 8); // Skip pointers _pBAnim + pPlayer->_pBFrames = file->nextLE(); + pPlayer->_pBWidth = file->nextLE(); + + LoadItems(file, NUM_INVLOC, pPlayer->InvBody); + LoadItems(file, NUM_INV_GRID_ELEM, pPlayer->InvList); + pPlayer->_pNumInv = file->nextLE(); + for (int i = 0; i < NUM_INV_GRID_ELEM; i++) + pPlayer->InvGrid[i] = file->nextLE(); + LoadItems(file, MAXBELTITEMS, pPlayer->SpdList); + LoadItemData(file, &pPlayer->HoldItem); + + pPlayer->_pIMinDam = file->nextLE(); + pPlayer->_pIMaxDam = file->nextLE(); + pPlayer->_pIAC = file->nextLE(); + pPlayer->_pIBonusDam = file->nextLE(); + pPlayer->_pIBonusToHit = file->nextLE(); + pPlayer->_pIBonusAC = file->nextLE(); + pPlayer->_pIBonusDamMod = file->nextLE(); + file->skip(4); // Alignment + + pPlayer->_pISpells = file->nextLE(); + pPlayer->_pIFlags = file->nextLE(); + pPlayer->_pIGetHit = file->nextLE(); + pPlayer->_pISplLvlAdd = file->nextLE(); + pPlayer->_pISplCost = file->nextLE(); + file->skip(2); // Alignment + pPlayer->_pISplDur = file->nextLE(); + pPlayer->_pIEnAc = file->nextLE(); + pPlayer->_pIFMinDam = file->nextLE(); + pPlayer->_pIFMaxDam = file->nextLE(); + pPlayer->_pILMinDam = file->nextLE(); + pPlayer->_pILMaxDam = file->nextLE(); + pPlayer->_pOilType = file->nextLE(); + pPlayer->pTownWarps = file->nextLE(); + pPlayer->pDungMsgs = file->nextLE(); + pPlayer->pLvlLoad = file->nextLE(); if (gbIsHellfireSaveGame) { - CopyChar(tbuff, &pPlayer->pDungMsgs2); + pPlayer->pDungMsgs2 = file->nextLE(); pPlayer->pBattleNet = false; } else { pPlayer->pDungMsgs2 = 0; - CopyChar(tbuff, &pPlayer->pBattleNet); + pPlayer->pBattleNet = file->nextBool8(); } - CopyChar(tbuff, &pPlayer->pManaShield); + pPlayer->pManaShield = file->nextBool8(); if (gbIsHellfireSaveGame) { - CopyChar(tbuff, &pPlayer->pOriginalCathedral); + pPlayer->pOriginalCathedral = file->nextBool8(); } else { - tbuff += 1; + file->skip(1); pPlayer->pOriginalCathedral = true; } - tbuff += 2; // Available bytes - CopyShort(tbuff, &pPlayer->wReflections); - tbuff += 14; // Available bytes + file->skip(2); // Available bytes + pPlayer->wReflections = file->nextLE(); + file->skip(14); // Available bytes - CopyInt(tbuff, &pPlayer->pDiabloKillLevel); - CopyInt(tbuff, &pPlayer->pDifficulty); - CopyInt(tbuff, &pPlayer->pDamAcFlags); - tbuff += 20; // Available bytes - CalcPlrItemVals(i, FALSE); + pPlayer->pDiabloKillLevel = file->nextLE(); + pPlayer->pDifficulty = file->nextLE(); + pPlayer->pDamAcFlags = file->nextLE(); + file->skip(20); // Available bytes + CalcPlrItemVals(p, FALSE); // Omit pointer _pNData // Omit pointer _pWData @@ -526,92 +509,92 @@ static void LoadPlayer(int i) bool gbSkipSync = false; -static void LoadMonster(int i) +static void LoadMonster(LoadHelper *file, int i) { MonsterStruct *pMonster = &monster[i]; - CopyInt(tbuff, &pMonster->_mMTidx); - CopyInt(tbuff, &pMonster->_mmode); - CopyChar(tbuff, &pMonster->_mgoal); - tbuff += 3; // Alignment - CopyInt(tbuff, &pMonster->_mgoalvar1); - CopyInt(tbuff, &pMonster->_mgoalvar2); - CopyInt(tbuff, &pMonster->_mgoalvar3); - CopyInt(tbuff, &pMonster->field_18); - CopyChar(tbuff, &pMonster->_pathcount); - tbuff += 3; // Alignment - 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 _mAnimData - CopyInt(tbuff, &pMonster->_mAnimDelay); - CopyInt(tbuff, &pMonster->_mAnimCnt); - CopyInt(tbuff, &pMonster->_mAnimLen); - CopyInt(tbuff, &pMonster->_mAnimFrame); - tbuff += 4; // Skip _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; // Alignment - 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); - tbuff += 1; // Alignment - CopyShort(tbuff, &pMonster->mExp); - - tbuff += 1; // Skip mHit as it's already initialized - CopyChar(tbuff, &pMonster->mMinDamage); - CopyChar(tbuff, &pMonster->mMaxDamage); - tbuff += 1; // Skip mHit2 as it's already initialized - CopyChar(tbuff, &pMonster->mMinDamage2); - CopyChar(tbuff, &pMonster->mMaxDamage2); - CopyChar(tbuff, &pMonster->mArmorClass); - CopyChar(tbuff, &pMonster->falign_CB); - CopyShort(tbuff, &pMonster->mMagicRes); - tbuff += 2; // Alignment - - CopyInt(tbuff, &pMonster->mtalkmsg); - CopyChar(tbuff, &pMonster->leader); - CopyChar(tbuff, &pMonster->leaderflag); - CopyChar(tbuff, &pMonster->packsize); - CopyChar(tbuff, &pMonster->mlid); + pMonster->_mMTidx = file->nextLE(); + pMonster->_mmode = file->nextLE(); + pMonster->_mgoal = file->nextLE(); + file->skip(3); // Alignment + pMonster->_mgoalvar1 = file->nextLE(); + pMonster->_mgoalvar2 = file->nextLE(); + pMonster->_mgoalvar3 = file->nextLE(); + file->skip(4); // Unused + pMonster->_pathcount = file->nextLE(); + file->skip(3); // Alignment + pMonster->_mx = file->nextLE(); + pMonster->_my = file->nextLE(); + pMonster->_mfutx = file->nextLE(); + pMonster->_mfuty = file->nextLE(); + pMonster->_moldx = file->nextLE(); + pMonster->_moldy = file->nextLE(); + pMonster->_mxoff = file->nextLE(); + pMonster->_myoff = file->nextLE(); + pMonster->_mxvel = file->nextLE(); + pMonster->_myvel = file->nextLE(); + pMonster->_mdir = file->nextLE(); + pMonster->_menemy = file->nextLE(); + pMonster->_menemyx = file->nextLE(); + pMonster->_menemyy = file->nextLE(); + file->skip(2); // Unused + + file->skip(4); // Skip pointer _mAnimData + pMonster->_mAnimDelay = file->nextLE(); + pMonster->_mAnimCnt = file->nextLE(); + pMonster->_mAnimLen = file->nextLE(); + pMonster->_mAnimFrame = file->nextLE(); + file->skip(4); // Skip _meflag + pMonster->_mDelFlag = file->nextBool32(); + pMonster->_mVar1 = file->nextLE(); + pMonster->_mVar2 = file->nextLE(); + pMonster->_mVar3 = file->nextLE(); + pMonster->_mVar4 = file->nextLE(); + pMonster->_mVar5 = file->nextLE(); + pMonster->_mVar6 = file->nextLE(); + pMonster->_mVar7 = file->nextLE(); + pMonster->_mVar8 = file->nextLE(); + pMonster->_mmaxhp = file->nextLE(); + pMonster->_mhitpoints = file->nextLE(); + + pMonster->_mAi = file->nextLE(); + pMonster->_mint = file->nextLE(); + file->skip(2); // Alignment + pMonster->_mFlags = file->nextLE(); + pMonster->_msquelch = file->nextLE(); + file->skip(3); // Alignment + file->skip(4); // Unused + pMonster->_lastx = file->nextLE(); + pMonster->_lasty = file->nextLE(); + pMonster->_mRndSeed = file->nextLE(); + pMonster->_mAISeed = file->nextLE(); + file->skip(4); // Unused + + pMonster->_uniqtype = file->nextLE(); + pMonster->_uniqtrans = file->nextLE(); + pMonster->_udeadval = file->nextLE(); + + pMonster->mWhoHit = file->nextLE(); + pMonster->mLevel = file->nextLE(); + file->skip(1); // Alignment + pMonster->mExp = file->nextLE(); + + file->skip(1); // Skip mHit as it's already initialized + pMonster->mMinDamage = file->nextLE(); + pMonster->mMaxDamage = file->nextLE(); + file->skip(1); // Skip mHit2 as it's already initialized + pMonster->mMinDamage2 = file->nextLE(); + pMonster->mMaxDamage2 = file->nextLE(); + pMonster->mArmorClass = file->nextLE(); + file->skip(1); // Alignment + pMonster->mMagicRes = file->nextLE(); + file->skip(2); // Alignment + + pMonster->mtalkmsg = file->nextLE(); + pMonster->leader = file->nextLE(); + pMonster->leaderflag = file->nextLE(); + pMonster->packsize = file->nextLE(); + pMonster->mlid = file->nextLE(); if (pMonster->mlid == plr[myplr]._plid) pMonster->mlid = NO_LIGHT; // Correct incorect values in old saves @@ -625,189 +608,166 @@ static void LoadMonster(int i) SyncMonsterAnim(i); } -static void LoadMissile(int i) +static void LoadMissile(LoadHelper *file, 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); - pMissile->_miDelFlag = LoadBool32(); - CopyChar(tbuff, &pMissile->_miAnimType); - tbuff += 3; // Alignment - CopyInt(tbuff, &pMissile->_miAnimFlags); - tbuff += 4; // Skip pointer _miAnimData - 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); - pMissile->_miDrawFlag = LoadBool32(); - pMissile->_miLightFlag = LoadBool32(); - pMissile->_miPreFlag = LoadBool32(); - CopyInt(tbuff, &pMissile->_miUniqTrans); - CopyInt(tbuff, &pMissile->_mirange); - CopyInt(tbuff, &pMissile->_misource); - CopyInt(tbuff, &pMissile->_micaster); - CopyInt(tbuff, &pMissile->_midam); - pMissile->_miHitFlag = LoadBool32(); - 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); + pMissile->_mitype = file->nextLE(); + pMissile->_mix = file->nextLE(); + pMissile->_miy = file->nextLE(); + pMissile->_mixoff = file->nextLE(); + pMissile->_miyoff = file->nextLE(); + pMissile->_mixvel = file->nextLE(); + pMissile->_miyvel = file->nextLE(); + pMissile->_misx = file->nextLE(); + pMissile->_misy = file->nextLE(); + pMissile->_mitxoff = file->nextLE(); + pMissile->_mityoff = file->nextLE(); + pMissile->_mimfnum = file->nextLE(); + pMissile->_mispllvl = file->nextLE(); + pMissile->_miDelFlag = file->nextBool32(); + pMissile->_miAnimType = file->nextLE(); + file->skip(3); // Alignment + pMissile->_miAnimFlags = file->nextLE(); + file->skip(4); // Skip pointer _miAnimData + pMissile->_miAnimDelay = file->nextLE(); + pMissile->_miAnimLen = file->nextLE(); + pMissile->_miAnimWidth = file->nextLE(); + pMissile->_miAnimWidth2 = file->nextLE(); + pMissile->_miAnimCnt = file->nextLE(); + pMissile->_miAnimAdd = file->nextLE(); + pMissile->_miAnimFrame = file->nextLE(); + pMissile->_miDrawFlag = file->nextBool32(); + pMissile->_miLightFlag = file->nextBool32(); + pMissile->_miPreFlag = file->nextBool32(); + pMissile->_miUniqTrans = file->nextLE(); + pMissile->_mirange = file->nextLE(); + pMissile->_misource = file->nextLE(); + pMissile->_micaster = file->nextLE(); + pMissile->_midam = file->nextLE(); + pMissile->_miHitFlag = file->nextBool32(); + pMissile->_midist = file->nextLE(); + pMissile->_mlid = file->nextLE(); + pMissile->_mirnd = file->nextLE(); + pMissile->_miVar1 = file->nextLE(); + pMissile->_miVar2 = file->nextLE(); + pMissile->_miVar3 = file->nextLE(); + pMissile->_miVar4 = file->nextLE(); + pMissile->_miVar5 = file->nextLE(); + pMissile->_miVar6 = file->nextLE(); + pMissile->_miVar7 = file->nextLE(); + pMissile->_miVar8 = file->nextLE(); } -static void LoadObject(int i) +static void LoadObject(LoadHelper *file, 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; // Skip pointer _oAnimData - 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; // Alignment - CopyInt(tbuff, &pObject->_oSolidFlag); - CopyInt(tbuff, &pObject->_oMissFlag); - - CopyChar(tbuff, &pObject->_oSelFlag); - tbuff += 3; // Alignment - 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); + pObject->_otype = file->nextLE(); + pObject->_ox = file->nextLE(); + pObject->_oy = file->nextLE(); + pObject->_oLight = file->nextBool32(); + pObject->_oAnimFlag = file->nextLE(); + file->skip(4); // Skip pointer _oAnimData + pObject->_oAnimDelay = file->nextLE(); + pObject->_oAnimCnt = file->nextLE(); + pObject->_oAnimLen = file->nextLE(); + pObject->_oAnimFrame = file->nextLE(); + pObject->_oAnimWidth = file->nextLE(); + pObject->_oAnimWidth2 = file->nextLE(); + pObject->_oDelFlag = file->nextBool32(); + pObject->_oBreak = file->nextLE(); + file->skip(3); // Alignment + pObject->_oSolidFlag = file->nextBool32(); + pObject->_oMissFlag = file->nextBool32(); + + pObject->_oSelFlag = file->nextLE(); + file->skip(3); // Alignment + pObject->_oPreFlag = file->nextBool32(); + pObject->_oTrapFlag = file->nextBool32(); + pObject->_oDoorFlag = file->nextBool32(); + pObject->_olid = file->nextLE(); + pObject->_oRndSeed = file->nextLE(); + pObject->_oVar1 = file->nextLE(); + pObject->_oVar2 = file->nextLE(); + pObject->_oVar3 = file->nextLE(); + pObject->_oVar4 = file->nextLE(); + pObject->_oVar5 = file->nextLE(); + pObject->_oVar6 = file->nextLE(); + pObject->_oVar7 = file->nextLE(); + pObject->_oVar8 = file->nextLE(); } -static void LoadItem(int i) +static void LoadItem(LoadHelper *file, int i) { - LoadItemData(&item[i]); + LoadItemData(file, &item[i]); GetItemFrm(i); } -static void LoadPremium(int i) +static void LoadPremium(LoadHelper *file, int i) { - LoadItemData(&premiumitem[i]); + LoadItemData(file, &premiumitem[i]); } -static void LoadQuest(int i) +static void LoadQuest(LoadHelper *file, int i) { QuestStruct *pQuest = &quests[i]; - CopyChar(tbuff, &pQuest->_qlevel); - CopyChar(tbuff, &pQuest->_qtype); - CopyChar(tbuff, &pQuest->_qactive); - CopyChar(tbuff, &pQuest->_qlvltype); - CopyInt(tbuff, &pQuest->_qtx); - CopyInt(tbuff, &pQuest->_qty); - CopyChar(tbuff, &pQuest->_qslvl); - CopyChar(tbuff, &pQuest->_qidx); + pQuest->_qlevel = file->nextLE(); + pQuest->_qtype = file->nextLE(); + pQuest->_qactive = file->nextLE(); + pQuest->_qlvltype = file->nextLE(); + pQuest->_qtx = file->nextLE(); + pQuest->_qty = file->nextLE(); + pQuest->_qslvl = file->nextLE(); + pQuest->_qidx = file->nextLE(); if (gbIsHellfireSaveGame) { - tbuff += 2; // Alignment - CopyInt(tbuff, &pQuest->_qmsg); + file->skip(2); // Alignment + pQuest->_qmsg = file->nextLE(); } else { - Uint8 tmp; - CopyChar(tbuff, &tmp); - pQuest->_qmsg = tmp; + pQuest->_qmsg = file->nextLE(); } - CopyChar(tbuff, &pQuest->_qvar1); - CopyChar(tbuff, &pQuest->_qvar2); - tbuff += 2; // Alignment + pQuest->_qvar1 = file->nextLE(); + pQuest->_qvar2 = file->nextLE(); + file->skip(2); // Alignment if (!gbIsHellfireSaveGame) - tbuff += 1; // Alignment - pQuest->_qlog = LoadBool32(); - - ReturnLvlX = WLoad(); - ReturnLvlY = WLoad(); - ReturnLvl = WLoad(); - ReturnLvlT = WLoad(); - DoomQuestState = WLoad(); -} - -static void LoadLighting(int i) -{ - LightListStruct *pLight = &LightList[i]; - - CopyInt(tbuff, &pLight->_lx); - CopyInt(tbuff, &pLight->_ly); - CopyInt(tbuff, &pLight->_lradius); - CopyInt(tbuff, &pLight->_lid); - CopyInt(tbuff, &pLight->_ldel); - CopyInt(tbuff, &pLight->_lunflag); - CopyInt(tbuff, &pLight->field_18); - CopyInt(tbuff, &pLight->_lunx); - CopyInt(tbuff, &pLight->_luny); - CopyInt(tbuff, &pLight->_lunr); - CopyInt(tbuff, &pLight->_xoff); - CopyInt(tbuff, &pLight->_yoff); - CopyInt(tbuff, &pLight->_lflags); + file->skip(1); // Alignment + pQuest->_qlog = file->nextBool32(); + + ReturnLvlX = file->nextBE(); + ReturnLvlY = file->nextBE(); + ReturnLvl = file->nextBE(); + ReturnLvlT = file->nextBE(); + DoomQuestState = file->nextBE(); } -static void LoadVision(int i) +static void LoadLighting(LoadHelper *file, LightListStruct *pLight) { - LightListStruct *pVision = &VisionList[i]; - - CopyInt(tbuff, &pVision->_lx); - CopyInt(tbuff, &pVision->_ly); - CopyInt(tbuff, &pVision->_lradius); - CopyInt(tbuff, &pVision->_lid); - CopyInt(tbuff, &pVision->_ldel); - CopyInt(tbuff, &pVision->_lunflag); - CopyInt(tbuff, &pVision->field_18); - CopyInt(tbuff, &pVision->_lunx); - CopyInt(tbuff, &pVision->_luny); - CopyInt(tbuff, &pVision->_lunr); - CopyInt(tbuff, &pVision->_xoff); - CopyInt(tbuff, &pVision->_yoff); - CopyInt(tbuff, &pVision->_lflags); + pLight->_lx = file->nextLE(); + pLight->_ly = file->nextLE(); + pLight->_lradius = file->nextLE(); + pLight->_lid = file->nextLE(); + pLight->_ldel = file->nextBool32(); + pLight->_lunflag = file->nextBool32(); + file->skip(4); // Unused + pLight->_lunx = file->nextLE(); + pLight->_luny = file->nextLE(); + pLight->_lunr = file->nextLE(); + pLight->_xoff = file->nextLE(); + pLight->_yoff = file->nextLE(); + pLight->_lflags = file->nextBool32(); } -static void LoadPortal(int i) +static void LoadPortal(LoadHelper *file, int i) { PortalStruct *pPortal = &portal[i]; - CopyInt(tbuff, &pPortal->open); - CopyInt(tbuff, &pPortal->x); - CopyInt(tbuff, &pPortal->y); - CopyInt(tbuff, &pPortal->level); - CopyInt(tbuff, &pPortal->ltype); - CopyInt(tbuff, &pPortal->setlvl); + pPortal->open = file->nextBool32(); + pPortal->x = file->nextLE(); + pPortal->y = file->nextLE(); + pPortal->level = file->nextLE(); + pPortal->ltype = file->nextLE(); + pPortal->setlvl = file->nextBool32(); } int RemapItemIdxFromDiablo(int i) @@ -846,17 +806,17 @@ int RemapItemIdxToDiablo(int i) return i; } -bool IsHeaderValid(int magicNumber) +bool IsHeaderValid(Uint32 magicNumber) { gbIsHellfireSaveGame = false; - if (magicNumber == LOAD_BE32("SHAR")) { + if (magicNumber == LOAD_LE32("SHAR")) { return true; - } else if (magicNumber == LOAD_BE32("SHLF")) { + } else if (magicNumber == LOAD_LE32("SHLF")) { gbIsHellfireSaveGame = true; return true; - } else if (!gbIsSpawn && magicNumber == LOAD_BE32("RETL")) { + } else if (!gbIsSpawn && magicNumber == LOAD_LE32("RETL")) { return true; - } else if (!gbIsSpawn && magicNumber == LOAD_BE32("HELF")) { + } else if (!gbIsSpawn && magicNumber == LOAD_LE32("HELF")) { gbIsHellfireSaveGame = true; return true; } @@ -871,7 +831,6 @@ void ConvertLevels() int _setlvlnum = setlvlnum; int _currlevel = currlevel; int _leveltype = leveltype; - BYTE *_tbuff = tbuff; gbSkipSync = true; @@ -913,7 +872,6 @@ void ConvertLevels() setlvlnum = _setlvlnum; currlevel = _currlevel; leveltype = _leveltype; - tbuff = _tbuff; } void LoadHotkeys() @@ -926,13 +884,13 @@ void LoadHotkeys() const size_t nHotkeySpells = sizeof(plr[myplr]._pSplTHotKey) / sizeof(plr[myplr]._pSplTHotKey[0]); for (size_t i = 0; i < nHotkeyTypes; i++) { - plr[myplr]._pSplHotKey[i] = file.nextLE32(); + plr[myplr]._pSplHotKey[i] = file.nextLE(); } for (size_t i = 0; i < nHotkeySpells; i++) { - plr[myplr]._pSplTHotKey[i] = file.nextByte(); + plr[myplr]._pSplTHotKey[i] = file.nextLE(); } - plr[myplr]._pRSpell = file.nextLE32(); - plr[myplr]._pRSplType = file.nextByte(); + plr[myplr]._pRSpell = file.nextLE(); + plr[myplr]._pRSplType = file.nextLE(); } void SaveHotkeys() @@ -943,13 +901,13 @@ void SaveHotkeys() SaveHelper file("hotkeys", (nHotkeyTypes * 4) + nHotkeySpells + 4 + 1); for (size_t i = 0; i < nHotkeyTypes; i++) { - file.writeLE32(plr[myplr]._pSplHotKey[i]); + file.writeLE(plr[myplr]._pSplHotKey[i]); } for (size_t i = 0; i < nHotkeySpells; i++) { - file.writeByte(plr[myplr]._pSplTHotKey[i]); + file.writeLE(plr[myplr]._pSplTHotKey[i]); } - file.writeLE32(plr[myplr]._pRSpell); - file.writeByte(plr[myplr]._pRSplType); + file.writeLE(plr[myplr]._pRSpell); + file.writeLE(plr[myplr]._pRSplType); } /** @@ -958,20 +916,14 @@ void SaveHotkeys() */ void LoadGame(BOOL firstflag) { - int i, j; - DWORD dwLen; - BYTE *LoadBuff; - int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects; - FreeGameMem(); pfile_remove_temp_files(); - LoadBuff = pfile_read("game", &dwLen); - if (LoadBuff == NULL) - app_fatal("Unable to open save file archive"); - tbuff = LoadBuff; + LoadHelper file("game"); + if (!file.isValid()) + app_fatal("Unable to open save file archive"); - if (!IsHeaderValid(ILoad())) + if (!IsHeaderValid(file.nextLE())) app_fatal("Invalid save file"); if (gbIsHellfireSaveGame) { @@ -985,39 +937,39 @@ void LoadGame(BOOL firstflag) giNumberOfSmithPremiumItems = 6; } - setlevel = LoadBool8(); - setlvlnum = WLoad(); - currlevel = WLoad(); - leveltype = WLoad(); + setlevel = file.nextBool8(); + setlvlnum = file.nextBE(); + currlevel = file.nextBE(); + leveltype = file.nextBE(); if (!setlevel) leveltype = gnLevelTypeTbl[currlevel]; - _ViewX = WLoad(); - _ViewY = WLoad(); - invflag = LoadBool8(); - chrflag = LoadBool8(); - _nummonsters = WLoad(); - _numitems = WLoad(); - _nummissiles = WLoad(); - _nobjects = WLoad(); + int _ViewX = file.nextBE(); + int _ViewY = file.nextBE(); + invflag = file.nextBool8(); + chrflag = file.nextBool8(); + int _nummonsters = file.nextBE(); + int _numitems = file.nextBE(); + int _nummissiles = file.nextBE(); + int _nobjects = file.nextBE(); if (!gbIsHellfire && currlevel > 17) app_fatal("Player is on a Hellfire only level"); - for (i = 0; i < giNumberOfLevels; i++) { - glSeedTbl[i] = ILoad(); - tbuff += 4; // Skip loading gnLevelTypeTbl + for (int i = 0; i < giNumberOfLevels; i++) { + glSeedTbl[i] = file.nextBE(); + file.skip(4); // Skip loading gnLevelTypeTbl } - LoadPlayer(myplr); + LoadPlayer(&file, myplr); gnDifficulty = plr[myplr].pDifficulty; if (gnDifficulty < DIFF_NORMAL || gnDifficulty > DIFF_HELL) gnDifficulty = DIFF_NORMAL; - for (i = 0; i < giNumberQuests; i++) - LoadQuest(i); - for (i = 0; i < MAXPORTAL; i++) - LoadPortal(i); + for (int i = 0; i < giNumberQuests; i++) + LoadQuest(&file, i); + for (int i = 0; i < MAXPORTAL; i++) + LoadPortal(&file, i); if (gbIsHellfireSaveGame != gbIsHellfire) ConvertLevels(); @@ -1033,111 +985,110 @@ void LoadGame(BOOL firstflag) nummissiles = _nummissiles; nobjects = _nobjects; - for (i = 0; i < MAXMONSTERS; i++) - monstkills[i] = ILoad(); + for (int i = 0; i < MAXMONSTERS; i++) + monstkills[i] = file.nextBE(); 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++) + for (int i = 0; i < MAXMONSTERS; i++) + monstactive[i] = file.nextBE(); + for (int i = 0; i < nummonsters; i++) + LoadMonster(&file, monstactive[i]); + for (int i = 0; i < MAXMISSILES; i++) + missileactive[i] = file.nextLE(); + for (int i = 0; i < MAXMISSILES; i++) + missileavail[i] = file.nextLE(); + for (int i = 0; i < nummissiles; i++) + LoadMissile(&file, missileactive[i]); + for (int i = 0; i < MAXOBJECTS; i++) + objectactive[i] = file.nextLE(); + for (int i = 0; i < MAXOBJECTS; i++) + objectavail[i] = file.nextLE(); + for (int i = 0; i < nobjects; i++) + LoadObject(&file, objectactive[i]); + for (int i = 0; i < nobjects; i++) SyncObjectAnim(objectactive[i]); - numlights = WLoad(); + numlights = file.nextBE(); - for (i = 0; i < MAXLIGHTS; i++) - lightactive[i] = BLoad(); - for (i = 0; i < numlights; i++) - LoadLighting(lightactive[i]); + for (int i = 0; i < MAXLIGHTS; i++) + lightactive[i] = file.nextLE(); + for (int i = 0; i < numlights; i++) + LoadLighting(&file, &LightList[lightactive[i]]); - visionid = WLoad(); - numvision = WLoad(); + visionid = file.nextBE(); + numvision = file.nextBE(); - for (i = 0; i < numvision; i++) - LoadVision(i); + for (int i = 0; i < numvision; i++) + LoadLighting(&file, &VisionList[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] = LoadBool8(); + for (int i = 0; i < MAXITEMS; i++) + itemactive[i] = file.nextLE(); + for (int i = 0; i < MAXITEMS; i++) + itemavail[i] = file.nextLE(); + for (int i = 0; i < numitems; i++) + LoadItem(&file, itemactive[i]); + for (int i = 0; i < 128; i++) + UniqueItemFlag[i] = file.nextBool8(); - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dLight[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dFlags[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dFlags[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPlayer[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dPlayer[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dItem[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dItem[i][j] = file.nextLE(); } if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMonster[i][j] = WLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dMonster[i][j] = file.nextBE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dDead[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dDead[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dObject[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dObject[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dLight[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPreLight[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dPreLight[i][j] = file.nextLE(); } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - automapview[i][j] = LoadBool8(); + for (int j = 0; j < DMAXY; j++) { + for (int i = 0; i < DMAXX; i++) + automapview[i][j] = file.nextBool8(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMissile[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dMissile[i][j] = file.nextLE(); } } - numpremium = WLoad(); - premiumlevel = WLoad(); + numpremium = file.nextBE(); + premiumlevel = file.nextBE(); - for (i = 0; i < giNumberOfSmithPremiumItems; i++) - LoadPremium(i); + for (int i = 0; i < giNumberOfSmithPremiumItems; i++) + LoadPremium(&file, i); if (gbIsHellfire && !gbIsHellfireSaveGame) SpawnPremium(myplr); - automapflag = LoadBool8(); - AutoMapScale = WLoad(); - mem_free_dbg(LoadBuff); + automapflag = file.nextBool8(); + AutoMapScale = file.nextBE(); AutomapZoomReset(); ResyncQuests(); @@ -1157,51 +1108,7 @@ void LoadGame(BOOL firstflag) gbIsHellfireSaveGame = gbIsHellfire; } -static void BSave(char v) -{ - *tbuff++ = v; -} - -static void WSave(int v) -{ - *tbuff++ = v >> 24; - *tbuff++ = v >> 16; - *tbuff++ = v >> 8; - *tbuff++ = v; -} - -static void ISave(int v) -{ - *tbuff++ = v >> 24; - *tbuff++ = v >> 16; - *tbuff++ = v >> 8; - *tbuff++ = v; -} - -static void SaveUint32LE(Uint32 v) -{ - Uint32 buf = SwapLE32(v); - memcpy(tbuff, &buf, 4); - tbuff += 4; -} - -static void SaveBool8(bool v) -{ - if (v != false) - *tbuff++ = 1; - else - *tbuff++ = 0; -} - -static void SaveBool32(bool value) -{ - Uint32 buf = value ? 1 : 0; - buf = SwapLE32(buf); - memcpy(tbuff, &buf, 4); - tbuff += 4; -} - -static void SaveItem(ItemStruct *pItem) +static void SaveItem(SaveHelper *file, ItemStruct *pItem) { int idx = pItem->IDidx; if (!gbIsHellfire) @@ -1212,284 +1119,293 @@ static void SaveItem(ItemStruct *pItem) iType = ITYPE_NONE; } - CopyInt(&pItem->_iSeed, tbuff); - CopyShort(&pItem->_iCreateInfo, tbuff); - tbuff += 2; // Alignment - CopyInt(&iType, tbuff); - CopyInt(&pItem->_ix, tbuff); - CopyInt(&pItem->_iy, tbuff); - SaveBool32(pItem->_iAnimFlag); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(&pItem->_iAnimLen, tbuff); - CopyInt(&pItem->_iAnimFrame, tbuff); - CopyInt(&pItem->_iAnimWidth, tbuff); - CopyInt(&pItem->_iAnimWidth2, tbuff); - tbuff += 4; // Unused since 1.02 - CopyChar(&pItem->_iSelFlag, tbuff); - tbuff += 3; // Alignment - SaveBool32(pItem->_iPostDraw); - SaveBool32(pItem->_iIdentified); - CopyChar(&pItem->_iMagical, tbuff); - CopyBytes(&pItem->_iName, 64, tbuff); - CopyBytes(&pItem->_iIName, 64, tbuff); - BSave(pItem->_iLoc); - BSave(pItem->_iClass); - tbuff += 1; // Alignment - 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); - SaveUint32LE(pItem->_iMiscId); - SaveUint32LE(pItem->_iSpell); - 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; // Alignment - CopyInt(&pItem->_iUid, tbuff); - CopyInt(&pItem->_iFMinDam, tbuff); - CopyInt(&pItem->_iFMaxDam, tbuff); - CopyInt(&pItem->_iLMinDam, tbuff); - CopyInt(&pItem->_iLMaxDam, tbuff); - CopyInt(&pItem->_iPLEnAc, tbuff); - BSave(pItem->_iPrePower); - BSave(pItem->_iSufPower); - tbuff += 2; // Alignment - 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; // Alignment - SaveBool32(pItem->_iStatFlag); - CopyInt(&idx, tbuff); - tbuff += 4; // Unused + file->writeLE(pItem->_iSeed); + file->writeLE(pItem->_iCreateInfo); + file->skip(2); // Alignment + file->writeLE(iType); + file->writeLE(pItem->_ix); + file->writeLE(pItem->_iy); + file->writeLE(pItem->_iAnimFlag); + file->skip(4); // Skip pointer _iAnimData + file->writeLE(pItem->_iAnimLen); + file->writeLE(pItem->_iAnimFrame); + file->writeLE(pItem->_iAnimWidth); + file->writeLE(pItem->_iAnimWidth2); + file->skip(4); // Unused since 1.02 + file->writeLE(pItem->_iSelFlag); + file->skip(3); // Alignment + file->writeLE(pItem->_iPostDraw); + file->writeLE(pItem->_iIdentified); + file->writeLE(pItem->_iMagical); + file->writeBytes(pItem->_iName, 64); + file->writeBytes(pItem->_iIName, 64); + file->writeLE(pItem->_iLoc); + file->writeLE(pItem->_iClass); + file->skip(1); // Alignment + file->writeLE(pItem->_iCurs); + file->writeLE(pItem->_ivalue); + file->writeLE(pItem->_iIvalue); + file->writeLE(pItem->_iMinDam); + file->writeLE(pItem->_iMaxDam); + file->writeLE(pItem->_iAC); + file->writeLE(pItem->_iFlags); + file->writeLE(pItem->_iMiscId); + file->writeLE(pItem->_iSpell); + file->writeLE(pItem->_iCharges); + file->writeLE(pItem->_iMaxCharges); + file->writeLE(pItem->_iDurability); + file->writeLE(pItem->_iMaxDur); + file->writeLE(pItem->_iPLDam); + file->writeLE(pItem->_iPLToHit); + file->writeLE(pItem->_iPLAC); + file->writeLE(pItem->_iPLStr); + file->writeLE(pItem->_iPLMag); + file->writeLE(pItem->_iPLDex); + file->writeLE(pItem->_iPLVit); + file->writeLE(pItem->_iPLFR); + file->writeLE(pItem->_iPLLR); + file->writeLE(pItem->_iPLMR); + file->writeLE(pItem->_iPLMana); + file->writeLE(pItem->_iPLHP); + file->writeLE(pItem->_iPLDamMod); + file->writeLE(pItem->_iPLGetHit); + file->writeLE(pItem->_iPLLight); + file->writeLE(pItem->_iSplLvlAdd); + file->writeLE(pItem->_iRequest); + file->skip(2); // Alignment + file->writeLE(pItem->_iUid); + file->writeLE(pItem->_iFMinDam); + file->writeLE(pItem->_iFMaxDam); + file->writeLE(pItem->_iLMinDam); + file->writeLE(pItem->_iLMaxDam); + file->writeLE(pItem->_iPLEnAc); + file->writeLE(pItem->_iPrePower); + file->writeLE(pItem->_iSufPower); + file->skip(2); // Alignment + file->writeLE(pItem->_iVAdd1); + file->writeLE(pItem->_iVMult1); + file->writeLE(pItem->_iVAdd2); + file->writeLE(pItem->_iVMult2); + file->writeLE(pItem->_iMinStr); + file->writeLE(pItem->_iMinMag); + file->writeLE(pItem->_iMinDex); + file->skip(1); // Alignment + file->writeLE(pItem->_iStatFlag); + file->writeLE(idx); + file->skip(4); // Unused if (gbIsHellfire) - CopyInt(&pItem->_iDamAcFlags, tbuff); + file->writeLE(pItem->_iDamAcFlags); } -static void SaveItems(ItemStruct *pItem, const int n) +static void SaveItems(SaveHelper *file, ItemStruct *pItem, const int n) { for (int i = 0; i < n; i++) { - SaveItem(&pItem[i]); + SaveItem(file, &pItem[i]); } } -static void SavePlayer(int i) +static void SavePlayer(SaveHelper *file, int p) { - PlayerStruct *pPlayer = &plr[i]; - - CopyInt(&pPlayer->_pmode, tbuff); - CopyBytes(&pPlayer->walkpath, MAX_PATH_LENGTH, tbuff); - CopyBytes(&pPlayer->plractive, 1, tbuff); - tbuff += 2; // Alignment - 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->_px, tbuff); - CopyInt(&pPlayer->_py, tbuff); - CopyInt(&pPlayer->_pfutx, tbuff); - CopyInt(&pPlayer->_pfuty, 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 pointer _pAnimData - CopyInt(&pPlayer->_pAnimDelay, tbuff); - CopyInt(&pPlayer->_pAnimCnt, tbuff); - CopyInt(&pPlayer->_pAnimLen, tbuff); - CopyInt(&pPlayer->_pAnimFrame, tbuff); - CopyInt(&pPlayer->_pAnimWidth, tbuff); - CopyInt(&pPlayer->_pAnimWidth2, tbuff); - tbuff += 4; // Skip _peflag - CopyInt(&pPlayer->_plid, tbuff); - CopyInt(&pPlayer->_pvid, tbuff); - - CopyInt(&pPlayer->_pSpell, tbuff); - CopyChar(&pPlayer->_pSplType, tbuff); - CopyChar(&pPlayer->_pSplFrom, tbuff); - tbuff += 2; // Alignment - CopyInt(&pPlayer->_pTSpell, tbuff); - CopyChar(&pPlayer->_pTSplType, tbuff); - tbuff += 3; // Alignment - CopyInt(&pPlayer->_pRSpell, tbuff); - CopyChar(&pPlayer->_pRSplType, tbuff); - tbuff += 3; // Alignment - CopyInt(&pPlayer->_pSBkSpell, tbuff); - CopyChar(&pPlayer->_pSBkSplType, tbuff); - CopyBytes(&pPlayer->_pSplLvl, 64, tbuff); - tbuff += 7; // Alignment - CopyInt64(&pPlayer->_pMemSpells, tbuff); - CopyInt64(&pPlayer->_pAblSpells, tbuff); - CopyInt64(&pPlayer->_pScrlSpells, tbuff); - CopyChar(&pPlayer->_pSpellFlags, tbuff); - tbuff += 3; // Alignment - 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; // Alignment - 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; // Alignment - 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, giNumberOfLevels, tbuff); - CopyBytes(&pPlayer->_pSLvlVisited, giNumberOfLevels, tbuff); // only 10 used - tbuff += 2; // Alignment - - CopyInt(&pPlayer->_pGFXLoad, tbuff); - tbuff += 4 * 8; // Skip pointers _pNAnim - CopyInt(&pPlayer->_pNFrames, tbuff); - CopyInt(&pPlayer->_pNWidth, tbuff); - tbuff += 4 * 8; // Skip pointers _pWAnim - CopyInt(&pPlayer->_pWFrames, tbuff); - CopyInt(&pPlayer->_pWWidth, tbuff); - tbuff += 4 * 8; // Skip pointers _pAAnim - CopyInt(&pPlayer->_pAFrames, tbuff); - CopyInt(&pPlayer->_pAWidth, tbuff); - CopyInt(&pPlayer->_pAFNum, tbuff); - tbuff += 4 * 8; // Skip pointers _pLAnim - tbuff += 4 * 8; // Skip pointers _pFAnim - tbuff += 4 * 8; // Skip pointers _pTAnim - CopyInt(&pPlayer->_pSFrames, tbuff); - CopyInt(&pPlayer->_pSWidth, tbuff); - CopyInt(&pPlayer->_pSFNum, tbuff); - tbuff += 4 * 8; // Skip pointers _pHAnim - CopyInt(&pPlayer->_pHFrames, tbuff); - CopyInt(&pPlayer->_pHWidth, tbuff); - tbuff += 4 * 8; // Skip pointers _pDAnim - CopyInt(&pPlayer->_pDFrames, tbuff); - CopyInt(&pPlayer->_pDWidth, tbuff); - tbuff += 4 * 8; // Skip pointers _pBAnim - 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; // Alignment - - CopyInt64(&pPlayer->_pISpells, tbuff); - CopyInt(&pPlayer->_pIFlags, tbuff); - CopyInt(&pPlayer->_pIGetHit, tbuff); - - CopyChar(&pPlayer->_pISplLvlAdd, tbuff); - CopyChar(&pPlayer->_pISplCost, tbuff); - tbuff += 2; // Alignment - 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); + PlayerStruct *pPlayer = &plr[p]; + + file->writeLE(pPlayer->_pmode); + for (int i = 0; i < MAX_PATH_LENGTH; i++) + file->writeLE(pPlayer->walkpath[i]); + file->writeLE(pPlayer->plractive); + file->skip(2); // Alignment + file->writeLE(pPlayer->destAction); + file->writeLE(pPlayer->destParam1); + file->writeLE(pPlayer->destParam2); + file->writeLE(pPlayer->destParam3); + file->writeLE(pPlayer->destParam4); + file->writeLE(pPlayer->plrlevel); + file->writeLE(pPlayer->_px); + file->writeLE(pPlayer->_py); + file->writeLE(pPlayer->_pfutx); + file->writeLE(pPlayer->_pfuty); + file->writeLE(pPlayer->_ptargx); + file->writeLE(pPlayer->_ptargy); + file->writeLE(pPlayer->_pownerx); + file->writeLE(pPlayer->_pownery); + file->writeLE(pPlayer->_poldx); + file->writeLE(pPlayer->_poldy); + file->writeLE(pPlayer->_pxoff); + file->writeLE(pPlayer->_pyoff); + file->writeLE(pPlayer->_pxvel); + file->writeLE(pPlayer->_pyvel); + file->writeLE(pPlayer->_pdir); + file->skip(4); // Unused + file->writeLE(pPlayer->_pgfxnum); + file->skip(4); // Skip pointer _pAnimData + file->writeLE(pPlayer->_pAnimDelay); + file->writeLE(pPlayer->_pAnimCnt); + file->writeLE(pPlayer->_pAnimLen); + file->writeLE(pPlayer->_pAnimFrame); + file->writeLE(pPlayer->_pAnimWidth); + file->writeLE(pPlayer->_pAnimWidth2); + file->skip(4); // Skip _peflag + file->writeLE(pPlayer->_plid); + file->writeLE(pPlayer->_pvid); + + file->writeLE(pPlayer->_pSpell); + file->writeLE(pPlayer->_pSplType); + file->writeLE(pPlayer->_pSplFrom); + file->skip(2); // Alignment + file->writeLE(pPlayer->_pTSpell); + file->writeLE(pPlayer->_pTSplType); + file->skip(3); // Alignment + file->writeLE(pPlayer->_pRSpell); + file->writeLE(pPlayer->_pRSplType); + file->skip(3); // Alignment + file->writeLE(pPlayer->_pSBkSpell); + file->writeLE(pPlayer->_pSBkSplType); + for (int i = 0; i < 64; i++) + file->writeLE(pPlayer->_pSplLvl[i]); + file->skip(7); // Alignment + file->writeLE(pPlayer->_pMemSpells); + file->writeLE(pPlayer->_pAblSpells); + file->writeLE(pPlayer->_pScrlSpells); + file->writeLE(pPlayer->_pSpellFlags); + file->skip(3); // Alignment + for (int i = 0; i < 4; i++) + file->writeLE(pPlayer->_pSplHotKey[i]); + for (int i = 0; i < 4; i++) + file->writeLE(pPlayer->_pSplTHotKey[i]); + + file->writeLE(pPlayer->_pwtype); + file->writeLE(pPlayer->_pBlockFlag); + file->writeLE(pPlayer->_pInvincible); + file->writeLE(pPlayer->_pLightRad); + file->writeLE(pPlayer->_pLvlChanging); + + file->writeBytes(pPlayer->_pName, PLR_NAME_LEN); + file->writeLE(pPlayer->_pClass); + file->skip(3); // Alignment + file->writeLE(pPlayer->_pStrength); + file->writeLE(pPlayer->_pBaseStr); + file->writeLE(pPlayer->_pMagic); + file->writeLE(pPlayer->_pBaseMag); + file->writeLE(pPlayer->_pDexterity); + file->writeLE(pPlayer->_pBaseDex); + file->writeLE(pPlayer->_pVitality); + file->writeLE(pPlayer->_pBaseVit); + file->writeLE(pPlayer->_pStatPts); + file->writeLE(pPlayer->_pDamageMod); + + file->writeLE(pPlayer->_pBaseToBlk); + file->writeLE(pPlayer->_pHPBase); + file->writeLE(pPlayer->_pMaxHPBase); + file->writeLE(pPlayer->_pHitPoints); + file->writeLE(pPlayer->_pMaxHP); + file->writeLE(pPlayer->_pHPPer); + file->writeLE(pPlayer->_pManaBase); + file->writeLE(pPlayer->_pMaxManaBase); + file->writeLE(pPlayer->_pMana); + file->writeLE(pPlayer->_pMaxMana); + file->writeLE(pPlayer->_pManaPer); + file->writeLE(pPlayer->_pLevel); + file->writeLE(pPlayer->_pMaxLvl); + file->skip(2); // Alignment + file->writeLE(pPlayer->_pExperience); + file->writeLE(pPlayer->_pMaxExp); + file->writeLE(pPlayer->_pNextExper); + file->writeLE(pPlayer->_pArmorClass); + file->writeLE(pPlayer->_pMagResist); + file->writeLE(pPlayer->_pFireResist); + file->writeLE(pPlayer->_pLghtResist); + file->writeLE(pPlayer->_pGold); + + file->writeLE(pPlayer->_pInfraFlag); + file->writeLE(pPlayer->_pVar1); + file->writeLE(pPlayer->_pVar2); + file->writeLE(pPlayer->_pVar3); + file->writeLE(pPlayer->_pVar4); + file->writeLE(pPlayer->_pVar5); + file->writeLE(pPlayer->_pVar6); + file->writeLE(pPlayer->_pVar7); + file->writeLE(pPlayer->_pVar8); + for (int i = 0; i < giNumberOfLevels; i++) + file->writeLE(pPlayer->_pLvlVisited[i]); + for (int i = 0; i < giNumberOfLevels; i++) + file->writeLE(pPlayer->_pSLvlVisited[i]); // only 10 used + + file->skip(2); // Alignment + + file->writeLE(pPlayer->_pGFXLoad); + file->skip(4 * 8); // Skip pointers _pNAnim + file->writeLE(pPlayer->_pNFrames); + file->writeLE(pPlayer->_pNWidth); + file->skip(4 * 8); // Skip pointers _pWAnim + file->writeLE(pPlayer->_pWFrames); + file->writeLE(pPlayer->_pWWidth); + file->skip(4 * 8); // Skip pointers _pAAnim + file->writeLE(pPlayer->_pAFrames); + file->writeLE(pPlayer->_pAWidth); + file->writeLE(pPlayer->_pAFNum); + file->skip(4 * 8); // Skip pointers _pLAnim + file->skip(4 * 8); // Skip pointers _pFAnim + file->skip(4 * 8); // Skip pointers _pTAnim + file->writeLE(pPlayer->_pSFrames); + file->writeLE(pPlayer->_pSWidth); + file->writeLE(pPlayer->_pSFNum); + file->skip(4 * 8); // Skip pointers _pHAnim + file->writeLE(pPlayer->_pHFrames); + file->writeLE(pPlayer->_pHWidth); + file->skip(4 * 8); // Skip pointers _pDAnim + file->writeLE(pPlayer->_pDFrames); + file->writeLE(pPlayer->_pDWidth); + file->skip(4 * 8); // Skip pointers _pBAnim + file->writeLE(pPlayer->_pBFrames); + file->writeLE(pPlayer->_pBWidth); + + SaveItems(file, pPlayer->InvBody, NUM_INVLOC); + SaveItems(file, pPlayer->InvList, NUM_INV_GRID_ELEM); + file->writeLE(pPlayer->_pNumInv); + for (int i = 0; i < NUM_INV_GRID_ELEM; i++) + file->writeLE(pPlayer->InvGrid[i]); + SaveItems(file, pPlayer->SpdList, MAXBELTITEMS); + SaveItem(file, &pPlayer->HoldItem); + + file->writeLE(pPlayer->_pIMinDam); + file->writeLE(pPlayer->_pIMaxDam); + file->writeLE(pPlayer->_pIAC); + file->writeLE(pPlayer->_pIBonusDam); + file->writeLE(pPlayer->_pIBonusToHit); + file->writeLE(pPlayer->_pIBonusAC); + file->writeLE(pPlayer->_pIBonusDamMod); + file->skip(4); // Alignment + + file->writeLE(pPlayer->_pISpells); + file->writeLE(pPlayer->_pIFlags); + file->writeLE(pPlayer->_pIGetHit); + + file->writeLE(pPlayer->_pISplLvlAdd); + file->writeLE(pPlayer->_pISplCost); + file->skip(2); // Alignment + file->writeLE(pPlayer->_pISplDur); + file->writeLE(pPlayer->_pIEnAc); + file->writeLE(pPlayer->_pIFMinDam); + file->writeLE(pPlayer->_pIFMaxDam); + file->writeLE(pPlayer->_pILMinDam); + file->writeLE(pPlayer->_pILMaxDam); + file->writeLE(pPlayer->_pOilType); + file->writeLE(pPlayer->pTownWarps); + file->writeLE(pPlayer->pDungMsgs); + file->writeLE(pPlayer->pLvlLoad); if (gbIsHellfire) - CopyChar(&pPlayer->pDungMsgs2, tbuff); + file->writeLE(pPlayer->pDungMsgs2); else - CopyChar(&pPlayer->pBattleNet, tbuff); - CopyChar(&pPlayer->pManaShield, tbuff); - CopyChar(&pPlayer->pOriginalCathedral, tbuff); - tbuff += 2; // Available bytes - CopyShort(&pPlayer->wReflections, tbuff); - tbuff += 14; // Available bytes - - CopyInt(&pPlayer->pDiabloKillLevel, tbuff); - CopyInt(&pPlayer->pDifficulty, tbuff); - CopyInt(&pPlayer->pDamAcFlags, tbuff); - tbuff += 20; // Available bytes + file->writeLE(pPlayer->pBattleNet); + file->writeLE(pPlayer->pManaShield); + file->writeLE(pPlayer->pOriginalCathedral); + file->skip(2); // Available bytes + file->writeLE(pPlayer->wReflections); + file->skip(14); // Available bytes + + file->writeLE(pPlayer->pDiabloKillLevel); + file->writeLE(pPlayer->pDifficulty); + file->writeLE(pPlayer->pDamAcFlags); + file->skip(20); // Available bytes // Omit pointer _pNData // Omit pointer _pWData @@ -1503,296 +1419,266 @@ static void SavePlayer(int i) // Omit pointer pReserved } -static void SaveMonster(int i) +static void SaveMonster(SaveHelper *file, int i) { MonsterStruct *pMonster = &monster[i]; - CopyInt(&pMonster->_mMTidx, tbuff); - CopyInt(&pMonster->_mmode, tbuff); - CopyChar(&pMonster->_mgoal, tbuff); - tbuff += 3; // Alignment - CopyInt(&pMonster->_mgoalvar1, tbuff); - CopyInt(&pMonster->_mgoalvar2, tbuff); - CopyInt(&pMonster->_mgoalvar3, tbuff); - CopyInt(&pMonster->field_18, tbuff); - CopyChar(&pMonster->_pathcount, tbuff); - tbuff += 3; // Alignment - 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 _mAnimData - CopyInt(&pMonster->_mAnimDelay, tbuff); - CopyInt(&pMonster->_mAnimCnt, tbuff); - CopyInt(&pMonster->_mAnimLen, tbuff); - CopyInt(&pMonster->_mAnimFrame, tbuff); - tbuff += 4; // Skip _meflag - 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; // Alignment - 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); - tbuff += 1; // Alignment - CopyShort(&pMonster->mExp, tbuff); - - // Write mHit for backwards compatibility - Sint8 mHit = pMonster->mHit < SCHAR_MAX ? pMonster->mHit : SCHAR_MAX; - CopyChar(&mHit, tbuff); - CopyChar(&pMonster->mMinDamage, tbuff); - CopyChar(&pMonster->mMaxDamage, tbuff); - // Write mHit2 for backwards compatibility - Sint8 mHit2 = pMonster->mHit2 < SCHAR_MAX ? pMonster->mHit2 : SCHAR_MAX; - CopyChar(&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; // Alignment - - CopyInt(&pMonster->mtalkmsg, tbuff); - CopyChar(&pMonster->leader, tbuff); - CopyChar(&pMonster->leaderflag, tbuff); - CopyChar(&pMonster->packsize, tbuff); - CopyChar(&pMonster->mlid, tbuff); + file->writeLE(pMonster->_mMTidx); + file->writeLE(pMonster->_mmode); + file->writeLE(pMonster->_mgoal); + file->skip(3); // Alignment + file->writeLE(pMonster->_mgoalvar1); + file->writeLE(pMonster->_mgoalvar2); + file->writeLE(pMonster->_mgoalvar3); + file->skip(4); // Unused + file->writeLE(pMonster->_pathcount); + file->skip(3); // Alignment + file->writeLE(pMonster->_mx); + file->writeLE(pMonster->_my); + file->writeLE(pMonster->_mfutx); + file->writeLE(pMonster->_mfuty); + file->writeLE(pMonster->_moldx); + file->writeLE(pMonster->_moldy); + file->writeLE(pMonster->_mxoff); + file->writeLE(pMonster->_myoff); + file->writeLE(pMonster->_mxvel); + file->writeLE(pMonster->_myvel); + file->writeLE(pMonster->_mdir); + file->writeLE(pMonster->_menemy); + file->writeLE(pMonster->_menemyx); + file->writeLE(pMonster->_menemyy); + file->skip(2); // Unused + + file->skip(4); // Skip pointer _mAnimData + file->writeLE(pMonster->_mAnimDelay); + file->writeLE(pMonster->_mAnimCnt); + file->writeLE(pMonster->_mAnimLen); + file->writeLE(pMonster->_mAnimFrame); + file->skip(4); // Skip _meflag + file->writeLE(pMonster->_mDelFlag); + file->writeLE(pMonster->_mVar1); + file->writeLE(pMonster->_mVar2); + file->writeLE(pMonster->_mVar3); + file->writeLE(pMonster->_mVar4); + file->writeLE(pMonster->_mVar5); + file->writeLE(pMonster->_mVar6); + file->writeLE(pMonster->_mVar7); + file->writeLE(pMonster->_mVar8); + file->writeLE(pMonster->_mmaxhp); + file->writeLE(pMonster->_mhitpoints); + + file->writeLE(pMonster->_mAi); + file->writeLE(pMonster->_mint); + file->skip(2); // Alignment + file->writeLE(pMonster->_mFlags); + file->writeLE(pMonster->_msquelch); + file->skip(3); // Alignment + file->skip(4); // Unused + file->writeLE(pMonster->_lastx); + file->writeLE(pMonster->_lasty); + file->writeLE(pMonster->_mRndSeed); + file->writeLE(pMonster->_mAISeed); + file->skip(4); // Unused + + file->writeLE(pMonster->_uniqtype); + file->writeLE(pMonster->_uniqtrans); + file->writeLE(pMonster->_udeadval); + + file->writeLE(pMonster->mWhoHit); + file->writeLE(pMonster->mLevel); + file->skip(1); // Alignment + file->writeLE(pMonster->mExp); + + file->writeLE(pMonster->mHit < SCHAR_MAX ? pMonster->mHit : SCHAR_MAX); // For backwards compatibility + file->writeLE(pMonster->mMinDamage); + file->writeLE(pMonster->mMaxDamage); + file->writeLE(pMonster->mHit2 < SCHAR_MAX ? pMonster->mHit2 : SCHAR_MAX); // For backwards compatibility + file->writeLE(pMonster->mMinDamage2); + file->writeLE(pMonster->mMaxDamage2); + file->writeLE(pMonster->mArmorClass); + file->skip(1); // Alignment + file->writeLE(pMonster->mMagicRes); + file->skip(2); // Alignment + + file->writeLE(pMonster->mtalkmsg); + file->writeLE(pMonster->leader); + file->writeLE(pMonster->leaderflag); + file->writeLE(pMonster->packsize); + file->writeLE(pMonster->mlid); // Omit pointer mName; // Omit pointer MType; // Omit pointer MData; } -static void SaveMissile(int i) +static void SaveMissile(SaveHelper *file, 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); - SaveBool32(pMissile->_miDelFlag); - CopyChar(&pMissile->_miAnimType, tbuff); - tbuff += 3; // Alignment - CopyInt(&pMissile->_miAnimFlags, tbuff); - tbuff += 4; // Skip pointer _miAnimData - 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); - SaveBool32(pMissile->_miDrawFlag); - SaveBool32(pMissile->_miLightFlag); - SaveBool32(pMissile->_miPreFlag); - CopyInt(&pMissile->_miUniqTrans, tbuff); - CopyInt(&pMissile->_mirange, tbuff); - CopyInt(&pMissile->_misource, tbuff); - CopyInt(&pMissile->_micaster, tbuff); - CopyInt(&pMissile->_midam, tbuff); - SaveBool32(pMissile->_miHitFlag); - 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); + file->writeLE(pMissile->_mitype); + file->writeLE(pMissile->_mix); + file->writeLE(pMissile->_miy); + file->writeLE(pMissile->_mixoff); + file->writeLE(pMissile->_miyoff); + file->writeLE(pMissile->_mixvel); + file->writeLE(pMissile->_miyvel); + file->writeLE(pMissile->_misx); + file->writeLE(pMissile->_misy); + file->writeLE(pMissile->_mitxoff); + file->writeLE(pMissile->_mityoff); + file->writeLE(pMissile->_mimfnum); + file->writeLE(pMissile->_mispllvl); + file->writeLE(pMissile->_miDelFlag); + file->writeLE(pMissile->_miAnimType); + file->skip(3); // Alignment + file->writeLE(pMissile->_miAnimFlags); + file->skip(4); // Skip pointer _miAnimData + file->writeLE(pMissile->_miAnimDelay); + file->writeLE(pMissile->_miAnimLen); + file->writeLE(pMissile->_miAnimWidth); + file->writeLE(pMissile->_miAnimWidth2); + file->writeLE(pMissile->_miAnimCnt); + file->writeLE(pMissile->_miAnimAdd); + file->writeLE(pMissile->_miAnimFrame); + file->writeLE(pMissile->_miDrawFlag); + file->writeLE(pMissile->_miLightFlag); + file->writeLE(pMissile->_miPreFlag); + file->writeLE(pMissile->_miUniqTrans); + file->writeLE(pMissile->_mirange); + file->writeLE(pMissile->_misource); + file->writeLE(pMissile->_micaster); + file->writeLE(pMissile->_midam); + file->writeLE(pMissile->_miHitFlag); + file->writeLE(pMissile->_midist); + file->writeLE(pMissile->_mlid); + file->writeLE(pMissile->_mirnd); + file->writeLE(pMissile->_miVar1); + file->writeLE(pMissile->_miVar2); + file->writeLE(pMissile->_miVar3); + file->writeLE(pMissile->_miVar4); + file->writeLE(pMissile->_miVar5); + file->writeLE(pMissile->_miVar6); + file->writeLE(pMissile->_miVar7); + file->writeLE(pMissile->_miVar8); } -static void SaveObject(int i) +static void SaveObject(SaveHelper *file, int i) { ObjectStruct *pObject = &object[i]; - CopyInt(&pObject->_otype, tbuff); - CopyInt(&pObject->_ox, tbuff); - CopyInt(&pObject->_oy, tbuff); - CopyInt(&pObject->_oLight, tbuff); - CopyInt(&pObject->_oAnimFlag, tbuff); - tbuff += 4; // Skip pointer _oAnimData - 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; // Alignment - CopyInt(&pObject->_oSolidFlag, tbuff); - CopyInt(&pObject->_oMissFlag, tbuff); - - CopyChar(&pObject->_oSelFlag, tbuff); - tbuff += 3; // Alignment - 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); + file->writeLE(pObject->_otype); + file->writeLE(pObject->_ox); + file->writeLE(pObject->_oy); + file->writeLE(pObject->_oLight); + file->writeLE(pObject->_oAnimFlag); + file->skip(4); // Skip pointer _oAnimData + file->writeLE(pObject->_oAnimDelay); + file->writeLE(pObject->_oAnimCnt); + file->writeLE(pObject->_oAnimLen); + file->writeLE(pObject->_oAnimFrame); + file->writeLE(pObject->_oAnimWidth); + file->writeLE(pObject->_oAnimWidth2); + file->writeLE(pObject->_oDelFlag); + file->writeLE(pObject->_oBreak); + file->skip(3); // Alignment + file->writeLE(pObject->_oSolidFlag); + file->writeLE(pObject->_oMissFlag); + + file->writeLE(pObject->_oSelFlag); + file->skip(3); // Alignment + file->writeLE(pObject->_oPreFlag); + file->writeLE(pObject->_oTrapFlag); + file->writeLE(pObject->_oDoorFlag); + file->writeLE(pObject->_olid); + file->writeLE(pObject->_oRndSeed); + file->writeLE(pObject->_oVar1); + file->writeLE(pObject->_oVar2); + file->writeLE(pObject->_oVar3); + file->writeLE(pObject->_oVar4); + file->writeLE(pObject->_oVar5); + file->writeLE(pObject->_oVar6); + file->writeLE(pObject->_oVar7); + file->writeLE(pObject->_oVar8); } -static void SavePremium(int i) +static void SavePremium(SaveHelper *file, int i) { - SaveItem(&premiumitem[i]); + SaveItem(file, &premiumitem[i]); } -static void SaveQuest(int i) +static void SaveQuest(SaveHelper *file, int i) { QuestStruct *pQuest = &quests[i]; - CopyChar(&pQuest->_qlevel, tbuff); - CopyChar(&pQuest->_qtype, tbuff); - CopyChar(&pQuest->_qactive, tbuff); - CopyChar(&pQuest->_qlvltype, tbuff); - CopyInt(&pQuest->_qtx, tbuff); - CopyInt(&pQuest->_qty, tbuff); - CopyChar(&pQuest->_qslvl, tbuff); - CopyChar(&pQuest->_qidx, tbuff); + file->writeLE(pQuest->_qlevel); + file->writeLE(pQuest->_qtype); + file->writeLE(pQuest->_qactive); + file->writeLE(pQuest->_qlvltype); + file->writeLE(pQuest->_qtx); + file->writeLE(pQuest->_qty); + file->writeLE(pQuest->_qslvl); + file->writeLE(pQuest->_qidx); if (gbIsHellfire) { - tbuff += 2; // Alignment - CopyInt(&pQuest->_qmsg, tbuff); + file->skip(2); // Alignment + file->writeLE(pQuest->_qmsg); } else { - Uint8 tmp = pQuest->_qmsg; - CopyChar(&tmp, tbuff); + file->writeLE(pQuest->_qmsg); } - CopyChar(&pQuest->_qvar1, tbuff); - CopyChar(&pQuest->_qvar2, tbuff); - tbuff += 2; // Alignment + file->writeLE(pQuest->_qvar1); + file->writeLE(pQuest->_qvar2); + file->skip(2); // Alignment if (!gbIsHellfire) - tbuff += 1; // Alignment - SaveBool32(pQuest->_qlog); - - WSave(ReturnLvlX); - WSave(ReturnLvlY); - WSave(ReturnLvl); - WSave(ReturnLvlT); - WSave(DoomQuestState); -} - -static void SaveLighting(int i) -{ - LightListStruct *pLight = &LightList[i]; - - CopyInt(&pLight->_lx, tbuff); - CopyInt(&pLight->_ly, tbuff); - CopyInt(&pLight->_lradius, tbuff); - CopyInt(&pLight->_lid, tbuff); - CopyInt(&pLight->_ldel, tbuff); - CopyInt(&pLight->_lunflag, tbuff); - CopyInt(&pLight->field_18, tbuff); - CopyInt(&pLight->_lunx, tbuff); - CopyInt(&pLight->_luny, tbuff); - CopyInt(&pLight->_lunr, tbuff); - CopyInt(&pLight->_xoff, tbuff); - CopyInt(&pLight->_yoff, tbuff); - CopyInt(&pLight->_lflags, tbuff); + file->skip(1); // Alignment + file->writeLE(pQuest->_qlog); + + file->writeBE(ReturnLvlX); + file->writeBE(ReturnLvlY); + file->writeBE(ReturnLvl); + file->writeBE(ReturnLvlT); + file->writeBE(DoomQuestState); } -static void SaveVision(int i) +static void SaveLighting(SaveHelper *file, LightListStruct *pLight) { - LightListStruct *pVision = &VisionList[i]; - - CopyInt(&pVision->_lx, tbuff); - CopyInt(&pVision->_ly, tbuff); - CopyInt(&pVision->_lradius, tbuff); - CopyInt(&pVision->_lid, tbuff); - CopyInt(&pVision->_ldel, tbuff); - CopyInt(&pVision->_lunflag, tbuff); - CopyInt(&pVision->field_18, tbuff); - CopyInt(&pVision->_lunx, tbuff); - CopyInt(&pVision->_luny, tbuff); - CopyInt(&pVision->_lunr, tbuff); - CopyInt(&pVision->_xoff, tbuff); - CopyInt(&pVision->_yoff, tbuff); - CopyInt(&pVision->_lflags, tbuff); + file->writeLE(pLight->_lx); + file->writeLE(pLight->_ly); + file->writeLE(pLight->_lradius); + file->writeLE(pLight->_lid); + file->writeLE(pLight->_ldel); + file->writeLE(pLight->_lunflag); + file->skip(4); // Unused + file->writeLE(pLight->_lunx); + file->writeLE(pLight->_luny); + file->writeLE(pLight->_lunr); + file->writeLE(pLight->_xoff); + file->writeLE(pLight->_yoff); + file->writeLE(pLight->_lflags); } -static void SavePortal(int i) +static void SavePortal(SaveHelper *file, int i) { PortalStruct *pPortal = &portal[i]; - CopyInt(&pPortal->open, tbuff); - CopyInt(&pPortal->x, tbuff); - CopyInt(&pPortal->y, tbuff); - CopyInt(&pPortal->level, tbuff); - CopyInt(&pPortal->ltype, tbuff); - CopyInt(&pPortal->setlvl, tbuff); + file->writeLE(pPortal->open); + file->writeLE(pPortal->x); + file->writeLE(pPortal->y); + file->writeLE(pPortal->level); + file->writeLE(pPortal->ltype); + file->writeLE(pPortal->setlvl); } void SaveGame() { - int i, j; - - DWORD dwLen = codec_get_encoded_len(FILEBUFF); - BYTE *SaveBuff = DiabloAllocPtr(dwLen); - tbuff = SaveBuff; + SaveHelper file("game", FILEBUFF); if (gbIsSpawn && !gbIsHellfire) - ISave(LOAD_BE32("SHAR")); + file.writeLE(LOAD_LE32("SHAR")); else if (gbIsSpawn && gbIsHellfire) - ISave(LOAD_BE32("SHLF")); + file.writeLE(LOAD_LE32("SHLF")); else if (!gbIsSpawn && gbIsHellfire) - ISave(LOAD_BE32("HELF")); + file.writeLE(LOAD_LE32("HELF")); else if (!gbIsSpawn && !gbIsHellfire) - ISave(LOAD_BE32("RETL")); + file.writeLE(LOAD_LE32("RETL")); else app_fatal("Invalid game state"); @@ -1806,134 +1692,134 @@ void SaveGame() giNumberOfSmithPremiumItems = 6; } - SaveBool8(setlevel); - WSave(setlvlnum); - WSave(currlevel); - WSave(leveltype); - WSave(ViewX); - WSave(ViewY); - SaveBool8(invflag); - SaveBool8(chrflag); - WSave(nummonsters); - WSave(numitems); - WSave(nummissiles); - WSave(nobjects); + file.writeLE(setlevel); + file.writeBE(setlvlnum); + file.writeBE(currlevel); + file.writeBE(leveltype); + file.writeBE(ViewX); + file.writeBE(ViewY); + file.writeLE(invflag); + file.writeLE(chrflag); + file.writeBE(nummonsters); + file.writeBE(numitems); + file.writeBE(nummissiles); + file.writeBE(nobjects); - for (i = 0; i < giNumberOfLevels; i++) { - ISave(glSeedTbl[i]); - WSave(gnLevelTypeTbl[i]); + for (int i = 0; i < giNumberOfLevels; i++) { + file.writeBE(glSeedTbl[i]); + file.writeBE(gnLevelTypeTbl[i]); } plr[myplr].pDifficulty = gnDifficulty; - SavePlayer(myplr); + SavePlayer(&file, myplr); - for (i = 0; i < giNumberQuests; i++) - SaveQuest(i); - for (i = 0; i < MAXPORTAL; i++) - SavePortal(i); - for (i = 0; i < MAXMONSTERS; i++) - ISave(monstkills[i]); + for (int i = 0; i < giNumberQuests; i++) + SaveQuest(&file, i); + for (int i = 0; i < MAXPORTAL; i++) + SavePortal(&file, i); + for (int i = 0; i < MAXMONSTERS; i++) + file.writeBE(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++) - SaveBool8(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]); + for (int i = 0; i < MAXMONSTERS; i++) + file.writeBE(monstactive[i]); + for (int i = 0; i < nummonsters; i++) + SaveMonster(&file, monstactive[i]); + for (int i = 0; i < MAXMISSILES; i++) + file.writeLE(missileactive[i]); + for (int i = 0; i < MAXMISSILES; i++) + file.writeLE(missileavail[i]); + for (int i = 0; i < nummissiles; i++) + SaveMissile(&file, missileactive[i]); + for (int i = 0; i < MAXOBJECTS; i++) + file.writeLE(objectactive[i]); + for (int i = 0; i < MAXOBJECTS; i++) + file.writeLE(objectavail[i]); + for (int i = 0; i < nobjects; i++) + SaveObject(&file, objectactive[i]); + + file.writeBE(numlights); + + for (int i = 0; i < MAXLIGHTS; i++) + file.writeLE(lightactive[i]); + for (int i = 0; i < numlights; i++) + SaveLighting(&file, &LightList[lightactive[i]]); + + file.writeBE(visionid); + file.writeBE(numvision); + + for (int i = 0; i < numvision; i++) + SaveLighting(&file, &VisionList[i]); + } + + for (int i = 0; i < MAXITEMS; i++) + file.writeLE(itemactive[i]); + for (int i = 0; i < MAXITEMS; i++) + file.writeLE(itemavail[i]); + for (int i = 0; i < numitems; i++) + SaveItem(&file, &item[itemactive[i]]); + for (int i = 0; i < 128; i++) + file.writeLE(UniqueItemFlag[i]); + + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dLight[i][j]); + } + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); + } + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dPlayer[i][j]); + } + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dItem[i][j]); } if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - WSave(dMonster[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeBE(dMonster[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dDead[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dDead[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dObject[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dObject[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dLight[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dPreLight[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dPreLight[i][j]); } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - SaveBool8(automapview[i][j]); + for (int j = 0; j < DMAXY; j++) { + for (int i = 0; i < DMAXX; i++) + file.writeLE(automapview[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dMissile[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dMissile[i][j]); } } - WSave(numpremium); - WSave(premiumlevel); + file.writeBE(numpremium); + file.writeBE(premiumlevel); - for (i = 0; i < giNumberOfSmithPremiumItems; i++) - SavePremium(i); + for (int i = 0; i < giNumberOfSmithPremiumItems; i++) + SavePremium(&file, i); + + file.writeLE(automapflag); + file.writeBE(AutoMapScale); + + file.flush(); - SaveBool8(automapflag); - WSave(AutoMapScale); - dwLen = codec_get_encoded_len(tbuff - SaveBuff); - pfile_write_save_file("game", SaveBuff, tbuff - SaveBuff, dwLen); - mem_free_dbg(SaveBuff); gbValidSaveFile = TRUE; pfile_rename_temp_to_perm(); pfile_write_hero(); @@ -1941,92 +1827,83 @@ void SaveGame() void SaveLevel() { - int i, j; - char szName[MAX_PATH]; - int dwLen; - BYTE *SaveBuff; - DoUnVision(plr[myplr]._px, plr[myplr]._py, plr[myplr]._pLightRad); // fix for vision staying on the level if (currlevel == 0) glSeedTbl[0] = AdvanceRndSeed(); - dwLen = codec_get_encoded_len(FILEBUFF); - SaveBuff = DiabloAllocPtr(dwLen); - tbuff = SaveBuff; + char szName[MAX_PATH]; + GetTempLevelNames(szName); + SaveHelper file(szName, FILEBUFF); if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dDead[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dDead[i][j]); } } - WSave(nummonsters); - WSave(numitems); - WSave(nobjects); + file.writeBE(nummonsters); + file.writeBE(numitems); + file.writeBE(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]); + for (int i = 0; i < MAXMONSTERS; i++) + file.writeBE(monstactive[i]); + for (int i = 0; i < nummonsters; i++) + SaveMonster(&file, monstactive[i]); + for (int i = 0; i < MAXOBJECTS; i++) + file.writeLE(objectactive[i]); + for (int i = 0; i < MAXOBJECTS; i++) + file.writeLE(objectavail[i]); + for (int i = 0; i < nobjects; i++) + SaveObject(&file, objectactive[i]); + } + + for (int i = 0; i < MAXITEMS; i++) + file.writeLE(itemactive[i]); + for (int i = 0; i < MAXITEMS; i++) + file.writeLE(itemavail[i]); + + for (int i = 0; i < numitems; i++) + SaveItem(&file, &item[itemactive[i]]); + + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); + } + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dItem[i][j]); } if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - WSave(dMonster[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeBE(dMonster[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dObject[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dObject[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dLight[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dPreLight[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(dPreLight[i][j]); } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - SaveBool8(automapview[i][j]); + for (int j = 0; j < DMAXY; j++) { + for (int i = 0; i < DMAXX; i++) + file.writeLE(automapview[i][j]); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - BSave(dMissile[i][j]); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + file.writeLE(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) plr[myplr]._pLvlVisited[currlevel] = TRUE; else @@ -2035,86 +1912,81 @@ void SaveLevel() void LoadLevel() { - int i, j; - DWORD dwLen; char szName[MAX_PATH]; - BYTE *LoadBuff; - GetPermLevelNames(szName); - LoadBuff = pfile_read(szName, &dwLen); - if (LoadBuff == NULL) + LoadHelper file(szName); + if (!file.isValid()) app_fatal("Unable to open save file archive"); - tbuff = LoadBuff; if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dDead[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dDead[i][j] = file.nextLE(); } SetDead(); } - nummonsters = WLoad(); - numitems = WLoad(); - nobjects = WLoad(); + nummonsters = file.nextBE(); + numitems = file.nextBE(); + nobjects = file.nextBE(); 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 (int i = 0; i < MAXMONSTERS; i++) + monstactive[i] = file.nextBE(); + for (int i = 0; i < nummonsters; i++) + LoadMonster(&file, monstactive[i]); + for (int i = 0; i < MAXOBJECTS; i++) + objectactive[i] = file.nextLE(); + for (int i = 0; i < MAXOBJECTS; i++) + objectavail[i] = file.nextLE(); + for (int i = 0; i < nobjects; i++) + LoadObject(&file, objectactive[i]); if (!gbSkipSync) { - for (i = 0; i < nobjects; i++) + for (int 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 (int i = 0; i < MAXITEMS; i++) + itemactive[i] = file.nextLE(); + for (int i = 0; i < MAXITEMS; i++) + itemavail[i] = file.nextLE(); + for (int i = 0; i < numitems; i++) + LoadItem(&file, itemactive[i]); - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dFlags[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dFlags[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dItem[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dItem[i][j] = file.nextLE(); } if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMonster[i][j] = WLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dMonster[i][j] = file.nextBE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dObject[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dObject[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dLight[i][j] = file.nextLE(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPreLight[i][j] = BLoad(); + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dPreLight[i][j] = file.nextLE(); } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - automapview[i][j] = LoadBool8(); + for (int j = 0; j < DMAXY; j++) { + for (int i = 0; i < DMAXX; i++) + automapview[i][j] = file.nextBool8(); } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMissile[i][j] = 0; /// BUGFIX: supposed to load saved missiles with "BLoad()"? + for (int j = 0; j < MAXDUNY; j++) { + for (int i = 0; i < MAXDUNX; i++) + dMissile[i][j] = 0; /// BUGFIX: supposed to load saved missiles with "file.nextLE()"? } } @@ -2125,12 +1997,10 @@ void LoadLevel() dolighting = TRUE; } - for (i = 0; i < MAX_PLRS; i++) { + for (int i = 0; i < MAX_PLRS; i++) { if (plr[i].plractive && currlevel == plr[i].plrlevel) LightList[plr[i]._plid]._lunflag = TRUE; } - - mem_free_dbg(LoadBuff); } DEVILUTION_END_NAMESPACE diff --git a/Source/loadsave.h b/Source/loadsave.h index c4fb373ff..68573967b 100644 --- a/Source/loadsave.h +++ b/Source/loadsave.h @@ -17,7 +17,7 @@ extern int giNumberOfLevels; int RemapItemIdxFromDiablo(int i); int RemapItemIdxToDiablo(int i); -bool IsHeaderValid(int magicNumber); +bool IsHeaderValid(Uint32 magicNumber); void LoadHotkeys(); void LoadGame(BOOL firstflag); void SaveHotkeys(); diff --git a/Source/missiles.h b/Source/missiles.h index 240fc53f6..694604e4f 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -70,7 +70,7 @@ typedef struct MissileStruct { bool _miDrawFlag; bool _miLightFlag; bool _miPreFlag; - Sint32 _miUniqTrans; + Uint32 _miUniqTrans; Sint32 _mirange; // Time to live for the missile in game ticks, oncs 0 the missile will be marked for deletion via _miDelFlag Sint32 _misource; Sint32 _micaster; diff --git a/Source/monster.cpp b/Source/monster.cpp index f062e847f..ff154ed21 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -495,7 +495,6 @@ void InitMonster(int i, int rd, int mtype, int x, int y) monster[i]._mgoalvar1 = 0; monster[i]._mgoalvar2 = 0; monster[i]._mgoalvar3 = 0; - monster[i].field_18 = 0; monster[i]._pathcount = 0; monster[i]._mDelFlag = FALSE; monster[i]._uniqtype = 0; diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 33c1ab422..1f25a0441 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -262,7 +262,7 @@ private: _FILEHEADER fhdr; memset(&fhdr, 0, sizeof(fhdr)); - fhdr.signature = LOAD_LE32("MPQ\x1A"); + fhdr.signature = SDL_SwapLE32(LOAD_LE32("MPQ\x1A")); fhdr.headersize = SDL_SwapLE32(32); fhdr.filesize = SDL_SwapLE32(static_cast(size)); fhdr.version = SDL_SwapLE16(0); diff --git a/Source/pack.h b/Source/pack.h index 49d9b4f42..8b2715886 100644 --- a/Source/pack.h +++ b/Source/pack.h @@ -61,7 +61,7 @@ typedef struct PkPlayerStruct { Sint8 pTownWarps; Sint8 pDungMsgs; Sint8 pLvlLoad; - Sint8 pBattleNet; + Uint8 pBattleNet; Uint8 pManaShield; Uint8 pDungMsgs2; Sint8 bIsHellfire; @@ -71,7 +71,7 @@ typedef struct PkPlayerStruct { Sint8 pSplLvl2[10]; // Hellfire spells Sint16 wReserved8; // For future use Uint32 pDiabloKillLevel; - Sint32 pDifficulty; + Uint32 pDifficulty; Sint32 pDamAcFlags; Sint32 dwReserved[5]; // For future use } PkPlayerStruct; diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 110dabd3b..5fb208cd4 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -299,7 +299,7 @@ BOOL pfile_archive_contains_game(HANDLE hsArchive, DWORD save_num) if (gameData == NULL) return FALSE; - int hdr = (gameData[0] << 24) | (gameData[1] << 16) | (gameData[2] << 8) | gameData[3]; + Uint32 hdr = LOAD_LE32(gameData); mem_free_dbg(gameData); return IsHeaderValid(hdr); diff --git a/Source/player.h b/Source/player.h index 1b4c740a2..44e789315 100644 --- a/Source/player.h +++ b/Source/player.h @@ -33,7 +33,6 @@ typedef struct PlayerStruct { int _pxvel; // Pixel X-velocity while walking. Indirectly applied to _pxoff via _pvar6 int _pyvel; // Pixel Y-velocity while walking. Indirectly applied to _pyoff via _pvar7 int _pdir; // Direction faced by player (direction enum) - int _nextdir; // Unused int _pgfxnum; // Bitmask indicating what variant of the sprite the player is using. Lower byte define weapon (anim_weapon_id) and higher values define armour (starting with anim_armor_id) unsigned char *_pAnimData; int _pAnimDelay; // Tick length of each frame in the current animation @@ -171,14 +170,14 @@ typedef struct PlayerStruct { unsigned char pTownWarps; unsigned char pDungMsgs; unsigned char pLvlLoad; - unsigned char pBattleNet; + bool pBattleNet; BOOLEAN pManaShield; unsigned char pDungMsgs2; BOOLEAN pOriginalCathedral; WORD wReflections; DWORD pDiabloKillLevel; - int pDifficulty; - int pDamAcFlags; + Uint32 pDifficulty; + Uint32 pDamAcFlags; unsigned char *_pNData; unsigned char *_pWData; unsigned char *_pAData; diff --git a/structs.h b/structs.h index 6c3d82ab6..3f56a79a2 100644 --- a/structs.h +++ b/structs.h @@ -107,7 +107,6 @@ typedef struct MonsterStruct { // note: missing field _mAFNum int _mgoalvar1; int _mgoalvar2; int _mgoalvar3; - int field_18; unsigned char _pathcount; int _mx; // Tile X-position of monster int _my; // Tile Y-position of monster @@ -123,13 +122,11 @@ typedef struct MonsterStruct { // note: missing field _mAFNum int _menemy; // The current target of the mosnter. An index in to either the plr or monster array based on the _meflag value. unsigned char _menemyx; // X-coordinate of enemy (usually correspond's to the enemy's futx value) unsigned char _menemyy; // Y-coordinate of enemy (usually correspond's to the enemy's futy value) - short falign_52; // probably _mAFNum (unused) unsigned char *_mAnimData; int _mAnimDelay; // Tick length of each frame in the current animation int _mAnimCnt; // Increases by one each game tick, counting how close we are to _pAnimDelay int _mAnimLen; // Number of frames in current animation int _mAnimFrame; // Current frame of animation. - BOOL _meflag; BOOL _mDelFlag; int _mVar1; int _mVar2; @@ -143,15 +140,12 @@ typedef struct MonsterStruct { // note: missing field _mAFNum int _mhitpoints; unsigned char _mAi; unsigned char _mint; - short falign_9A; - int _mFlags; + Uint32 _mFlags; BYTE _msquelch; - int falign_A4; int _lastx; int _lasty; int _mRndSeed; int _mAISeed; - int falign_B8; unsigned char _uniqtype; unsigned char _uniqtrans; char _udeadval; @@ -165,7 +159,6 @@ typedef struct MonsterStruct { // note: missing field _mAFNum unsigned char mMinDamage2; unsigned char mMaxDamage2; unsigned char mArmorClass; - char falign_CB; unsigned short mMagicRes; int mtalkmsg; unsigned char leader; @@ -222,8 +215,8 @@ typedef struct ObjectStruct { int _otype; int _ox; int _oy; - int _oLight; - int _oAnimFlag; + bool _oLight; + Uint32 _oAnimFlag; unsigned char *_oAnimData; int _oAnimDelay; // Tick length of each frame in the current animation int _oAnimCnt; // Increases by one each game tick, counting how close we are to _pAnimDelay