From 0889780923262ee8fecfe2d07c33272c58ab5bc1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 18 Jul 2021 00:25:55 +0200 Subject: [PATCH] Remove more usage of miniwin types --- Source/DiabloUI/art.cpp | 4 +- Source/missiles.cpp | 26 +++---- Source/monster.cpp | 110 ++++++++++++++-------------- Source/mpqapi.cpp | 7 +- Source/msg.cpp | 10 +-- Source/msg.h | 6 +- Source/multi.cpp | 5 +- Source/objects.cpp | 4 +- Source/player.cpp | 2 +- Source/plrmsg.cpp | 4 +- Source/scrollrt.cpp | 9 ++- Source/sound.cpp | 10 +-- Source/storm/storm.cpp | 6 +- Source/storm/storm.h | 15 ++-- Source/storm/storm_file_wrapper.cpp | 6 +- Source/storm/storm_net.cpp | 6 +- Source/storm/storm_sdl_rw.cpp | 8 +- Source/storm/storm_svid.cpp | 2 +- 18 files changed, 119 insertions(+), 121 deletions(-) diff --git a/Source/DiabloUI/art.cpp b/Source/DiabloUI/art.cpp index 375c0d7d4..5a5232fb8 100644 --- a/Source/DiabloUI/art.cpp +++ b/Source/DiabloUI/art.cpp @@ -11,7 +11,7 @@ namespace devilution { namespace { -constexpr unsigned PcxHeaderSize = 128; +constexpr size_t PcxHeaderSize = 128; constexpr unsigned NumPaletteColors = 256; constexpr unsigned PcxPaletteSize = 1 + NumPaletteColors * 3; @@ -38,7 +38,7 @@ bool LoadPcxPixelsAndPalette(HANDLE handle, int width, int height, std::uint8_t pixelDataSize -= PcxHeaderSize + (has256ColorPalette ? PcxPaletteSize : 0); // We read 1 extra byte because it delimits the palette. - const unsigned readSize = pixelDataSize + (has256ColorPalette ? PcxPaletteSize : 0); + const size_t readSize = pixelDataSize + (has256ColorPalette ? PcxPaletteSize : 0); std::unique_ptr fileBuffer { new BYTE[readSize] }; if (!SFileReadFileThreadSafe(handle, fileBuffer.get(), readSize)) { return false; diff --git a/Source/missiles.cpp b/Source/missiles.cpp index ea74c7506..681eb2d1b 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2977,7 +2977,7 @@ void AddFlamec(int mi, Point src, Point dst, int midir, int8_t mienemy, int id, void AddCbolt(int mi, Point src, Point dst, int midir, int8_t micaster, int id, int /*dam*/) { - assert((DWORD)mi < MAXMISSILES); + assert(mi >= 0 && mi < MAXMISSILES); Missiles[mi]._mirnd = GenerateRnd(15) + 1; Missiles[mi]._midam = (micaster == 0) ? (GenerateRnd(Players[id]._pMagic / 4) + 1) : 15; @@ -3592,10 +3592,10 @@ void MI_LightningArrow(int i) int mx = Missiles[i].position.tile.x; int my = Missiles[i].position.tile.y; - assert((DWORD)mx < MAXDUNX); - assert((DWORD)my < MAXDUNY); + assert(mx >= 0 && mx < MAXDUNX); + assert(my >= 0 && my < MAXDUNY); int pn = dPiece[mx][my]; - assert((DWORD)pn <= MAXTILES); + assert(pn >= 0 && pn <= MAXTILES); if (Missiles[i]._misource == -1) { if ((mx != Missiles[i].position.start.x || my != Missiles[i].position.start.y) && nMissileTable[pn]) { @@ -3789,7 +3789,7 @@ void MI_SpecArrow(int i) void MI_Lightctrl(int i) { - assert((DWORD)i < MAXMISSILES); + assert(i >= 0 && i < MAXMISSILES); Missiles[i]._mirange--; int dam; @@ -3810,10 +3810,10 @@ void MI_Lightctrl(int i) int mx = Missiles[i].position.tile.x; int my = Missiles[i].position.tile.y; - assert((DWORD)mx < MAXDUNX); - assert((DWORD)my < MAXDUNY); + assert(mx >= 0 && mx < MAXDUNX); + assert(my >= 0 && my < MAXDUNY); int pn = dPiece[mx][my]; - assert((DWORD)pn <= MAXTILES); + assert(pn >= 0 && pn <= MAXTILES); if (id != -1 || Point { mx, my } != Missiles[i].position.start) { if (nMissileTable[pn]) { @@ -4047,7 +4047,7 @@ void MI_Firemove(int i) void MI_Guardian(int i) { - assert((DWORD)i < MAXMISSILES); + assert(i >= 0 && i < MAXMISSILES); Missiles[i]._mirange--; @@ -4427,7 +4427,7 @@ void MI_Wave(int i) { bool f1 = false; bool f2 = false; - assert((DWORD)i < MAXMISSILES); + assert(i >= 0 && i < MAXMISSILES); int id = Missiles[i]._misource; Point src = Missiles[i].position.tile; @@ -4436,7 +4436,7 @@ void MI_Wave(int i) Direction dirb = right[right[sd]]; Point na = src + sd; int pn = dPiece[na.x][na.y]; - assert((DWORD)pn <= MAXTILES); + assert(pn >= 0 && pn <= MAXTILES); if (!nMissileTable[pn]) { Direction pdir = Players[id]._pdir; AddMissile(na, na + sd, pdir, MIS_FIREMOVE, TARGET_MONSTERS, id, 0, Missiles[i]._mispllvl); @@ -4444,7 +4444,7 @@ void MI_Wave(int i) Point nb = src + sd + dirb; for (int j = 0; j < (Missiles[i]._mispllvl / 2) + 2; j++) { pn = dPiece[na.x][na.y]; // BUGFIX: dPiece is accessed before check against dungeon size and 0 - assert((DWORD)pn <= MAXTILES); + assert(pn >= 0 && pn <= MAXTILES); if (nMissileTable[pn] || f1 || !InDungeonBounds(na)) { f1 = true; } else { @@ -4452,7 +4452,7 @@ void MI_Wave(int i) na += dira; } pn = dPiece[nb.x][nb.y]; // BUGFIX: dPiece is accessed before check against dungeon size and 0 - assert((DWORD)pn <= MAXTILES); + assert(pn >= 0 && pn <= MAXTILES); if (nMissileTable[pn] || f2 || !InDungeonBounds(nb)) { f2 = true; } else { diff --git a/Source/monster.cpp b/Source/monster.cpp index a045d9c9e..a418e9579 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -1136,7 +1136,7 @@ void SpawnLoot(MonsterStruct &monster, bool sendmsg) void Teleport(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode == MM_STONE) @@ -1175,7 +1175,7 @@ void Teleport(int i) void MonsterHitMonster(int mid, int i, int dam) { - assert((DWORD)mid < MAXMONSTERS); + assert(mid >= 0 && mid < MAXMONSTERS); auto &monster = Monsters[mid]; assert(monster.MType != nullptr); @@ -1207,7 +1207,7 @@ void MonsterHitMonster(int mid, int i, int dam) void StartMonsterDeath(int i, int pnum, bool sendmsg) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; assert(monster.MType != nullptr); @@ -1242,9 +1242,9 @@ void StartMonsterDeath(int i, int pnum, bool sendmsg) void StartDeathFromMonster(int i, int mid) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &killer = Monsters[i]; - assert((DWORD)mid < MAXMONSTERS); + assert(mid >= 0 && mid < MAXMONSTERS); auto &monster = Monsters[mid]; assert(monster.MType != nullptr); @@ -1353,7 +1353,7 @@ bool MonsterIdle(MonsterStruct &monster) */ bool MonsterWalk(int i, int variant) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; assert(monster.MType != nullptr); @@ -1398,7 +1398,7 @@ bool MonsterWalk(int i, int variant) void MonsterAttackMonster(int i, int mid, int hper, int mind, int maxd) { - assert((DWORD)mid < MAXMONSTERS); + assert(mid >= 0 && mid < MAXMONSTERS); auto &monster = Monsters[mid]; assert(monster.MType != nullptr); @@ -1431,7 +1431,7 @@ void MonsterAttackMonster(int i, int mid, int hper, int mind, int maxd) void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; assert(monster.MType != nullptr); @@ -1579,7 +1579,7 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam) bool MonsterAttack(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; assert(monster.MType != nullptr); assert(monster.MData != nullptr); @@ -1609,7 +1609,7 @@ bool MonsterAttack(int i) bool MonaterRangedAttack(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; assert(monster.MType != nullptr); assert(monster.MData != nullptr); @@ -1649,7 +1649,7 @@ bool MonaterRangedAttack(int i) bool MonsterRangedSpecialAttack(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; assert(monster.MType != nullptr); assert(monster.MData != nullptr); @@ -1690,7 +1690,7 @@ bool MonsterRangedSpecialAttack(int i) bool MonsterSpecialAttack(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; assert(monster.MType != nullptr); assert(monster.MData != nullptr); @@ -1836,7 +1836,7 @@ bool MonsterGotHit(MonsterStruct &monster) bool MonsterDeath(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; assert(monster.MType != nullptr); @@ -1946,7 +1946,7 @@ bool IsLineNotSolid(Point startPoint, Point endPoint) void GroupUnity(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster.leaderflag == MonsterRelation::Individual) { @@ -2112,7 +2112,7 @@ bool AiPlanWalk(int i) /** Maps from walking path step to facing direction. */ const Direction plr2monst[9] = { DIR_S, DIR_NE, DIR_NW, DIR_SE, DIR_SW, DIR_N, DIR_E, DIR_S, DIR_W }; - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (FindPath([&monster](Point position) { return IsTileAccessible(monster, position); }, monster.position.tile, monster.enemyPosition, path) == 0) { @@ -2167,7 +2167,7 @@ bool RoundWalk(int i, Direction direction, int *dir) bool AiPlanPath(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster.MType->mtype != MT_GOLEM) { @@ -2203,7 +2203,7 @@ bool AiPlanPath(int i) void AiAvoidance(int i, bool special) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -2257,7 +2257,7 @@ void AiAvoidance(int i, bool special) void AiRanged(int i, missile_id missileType, bool special) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -2302,7 +2302,7 @@ void AiRanged(int i, missile_id missileType, bool special) void AiRangedAvoidance(int i, missile_id missileType, bool checkdoors, int dam, int lessmissiles) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -2360,7 +2360,7 @@ void AiRangedAvoidance(int i, missile_id missileType, bool checkdoors, int dam, void ZombieAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -2395,7 +2395,7 @@ void ZombieAi(int i) void OverlordAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -2425,7 +2425,7 @@ void OverlordAi(int i) void SkeletonAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -2455,7 +2455,7 @@ void SkeletonAi(int i) void SkeletonBowAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -2492,7 +2492,7 @@ void SkeletonBowAi(int i) void ScavengerAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) @@ -2583,7 +2583,7 @@ void ScavengerAi(int i) void RhinoAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -2658,7 +2658,7 @@ void GoatBowAi(int i) void FallenAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mgoal == MGOAL_ATTACK2) { @@ -2728,7 +2728,7 @@ void MagmaAi(int i) void LeoricAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -2790,7 +2790,7 @@ void LeoricAi(int i) void BatAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; int pnum = monster._menemy; @@ -2848,7 +2848,7 @@ void BatAi(int i) void GargoyleAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; int dx = monster.position.tile.x - monster.position.last.x; @@ -2884,7 +2884,7 @@ void GargoyleAi(int i) void ButcherAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -2914,7 +2914,7 @@ void SuccubusAi(int i) void SneakAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -2980,7 +2980,7 @@ void StormAi(int i) void FiremanAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) @@ -3035,7 +3035,7 @@ void FiremanAi(int i) void GharbadAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -3094,7 +3094,7 @@ void AcidAi(int i) void SnotSpilAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -3137,7 +3137,7 @@ void SnotSpilAi(int i) void SnakeAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; char pattern[6] = { 1, 1, 0, -1, -1, 0 }; @@ -3198,7 +3198,7 @@ void SnakeAi(int i) void CounselorAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -3262,7 +3262,7 @@ void CounselorAi(int i) void ZharAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -3295,7 +3295,7 @@ void ZharAi(int i) void MegaAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; int mx = monster.position.tile.x - monster.enemyPosition.x; @@ -3369,7 +3369,7 @@ void DiabloAi(int i) void LazarusAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -3417,7 +3417,7 @@ void LazarusAi(int i) void LazarusMinionAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) @@ -3446,7 +3446,7 @@ void LazarusMinionAi(int i) void LachdananAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -3477,7 +3477,7 @@ void LachdananAi(int i) void WarlordAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND) { @@ -3515,7 +3515,7 @@ void TorchantAi(int i) void HorkDemonAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mmode != MM_STAND || monster._msquelch == 0) { @@ -4183,7 +4183,7 @@ void M_StartHit(int i, int pnum, int dam) void M_StartKill(int i, int pnum) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (MyPlayerId == pnum) { @@ -4200,7 +4200,7 @@ void M_StartKill(int i, int pnum) void M_SyncStartKill(int i, Point position, int pnum) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; if (monster._mhitpoints > 0 || monster._mmode == MM_DEATH) { @@ -4223,7 +4223,7 @@ void M_SyncStartKill(int i, Point position, int pnum) void M_UpdateLeader(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; for (int j = 0; j < ActiveMonsterCount; j++) { @@ -4306,7 +4306,7 @@ void PrepDoEnding() void M_WalkDir(int i, Direction md) { - assert((DWORD)i < MAXMONSTERSassert); + assert(i >= 0 && i < MAXMONSTERS); int mwi = Monsters[i].MType->GetAnimData(MonsterGraphic::Walk).Frames - 1; switch (md) { @@ -4341,7 +4341,7 @@ void M_WalkDir(int i, Direction md) void GolumAi(int i) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &golem = Monsters[i]; if (golem.position.tile.x == 1 && golem.position.tile.y == 0) { @@ -4431,7 +4431,7 @@ void ProcessMonsters() { DeleteMonsterList(); - assert((DWORD)ActiveMonsterCount <= MAXMONSTERS); + assert(ActiveMonsterCount >= 0 && ActiveMonsterCount <= MAXMONSTERS); for (int i = 0; i < ActiveMonsterCount; i++) { int mi = ActiveMonsters[i]; auto &monster = Monsters[mi]; @@ -4470,11 +4470,11 @@ void ProcessMonsters() } if ((monster._mFlags & MFLAG_TARGETS_MONSTER) != 0) { - assert((DWORD)monster._menemy < MAXMONSTERS); + assert(monster._menemy >= 0 && monster._menemy < MAXMONSTERS); monster.position.last = Monsters[monster._menemy].position.future; monster.enemyPosition = monster.position.last; } else { - assert((DWORD)monster._menemy < MAX_PLRS); + assert(monster._menemy >= 0 && monster._menemy < MAX_PLRS); monster.enemyPosition = Players[monster._menemy].position.future; if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { monster._msquelch = UINT8_MAX; @@ -4567,7 +4567,7 @@ void FreeMonsters() bool DirOK(int i, Direction mdir) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; Point position = monster.position.tile; Point futurePosition = position + mdir; @@ -4923,12 +4923,12 @@ void PlayEffect(MonsterStruct &monster, int mode) void MissToMonst(int i, Point position) { - assert((DWORD)i < MAXMISSILES); + assert(i >= 0 && i < MAXMISSILES); MissileStruct *miss = &Missiles[i]; int m = miss->_misource; - assert((DWORD)m < MAXMONSTERS); + assert(m >= 0 && m < MAXMONSTERS); auto &monster = Monsters[m]; Point oldPosition = miss->position.tile; @@ -5095,7 +5095,7 @@ void TalktoMonster(MonsterStruct &monster) void SpawnGolum(int i, Point position, int mi) { - assert((DWORD)i < MAXMONSTERS); + assert(i >= 0 && i < MAXMONSTERS); auto &monster = Monsters[i]; dMonster[position.x][position.y] = i + 1; diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 63767bda1..4a7b22d0c 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -406,7 +406,7 @@ int FindFreeBlock(uint32_t size, uint32_t *blockSize) continue; if (pBlockTbl->sizefile != 0) continue; - if ((DWORD)pBlockTbl->sizealloc < size) + if (pBlockTbl->sizealloc < size) continue; result = pBlockTbl->offset; @@ -625,7 +625,6 @@ bool mpqapi_has_file(const char *pszName) bool OpenMPQ(const char *pszArchive) { - DWORD key; _FILEHEADER fhdr; InitHash(); @@ -644,7 +643,7 @@ bool OpenMPQ(const char *pszArchive) if (fhdr.blockcount > 0) { if (!cur_archive.stream.Read(reinterpret_cast(cur_archive.sgpBlockTbl), BlockEntrySize)) goto on_error; - key = Hash("(block table)", 3); + uint32_t key = Hash("(block table)", 3); Decrypt((DWORD *)cur_archive.sgpBlockTbl, BlockEntrySize, key); } cur_archive.sgpHashTbl = new _HASHENTRY[HashEntrySize / sizeof(_HASHENTRY)]; @@ -652,7 +651,7 @@ bool OpenMPQ(const char *pszArchive) if (fhdr.hashcount > 0) { if (!cur_archive.stream.Read(reinterpret_cast(cur_archive.sgpHashTbl), HashEntrySize)) goto on_error; - key = Hash("(hash table)", 3); + uint32_t key = Hash("(hash table)", 3); Decrypt((DWORD *)cur_archive.sgpHashTbl, HashEntrySize, key); } diff --git a/Source/msg.cpp b/Source/msg.cpp index 54821dfbd..09cc20192 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -41,8 +41,8 @@ namespace { #define MAX_CHUNKS (NUMLEVELS + 4) -DWORD sgdwOwnerWait; -DWORD sgdwRecvOffset; +uint32_t sgdwOwnerWait; +uint32_t sgdwRecvOffset; int sgnCurrMegaPlayer; DLevel sgLevels[NUMLEVELS]; BYTE sbLastCmd; @@ -106,7 +106,7 @@ void PrePacket() continue; } - int pktSize = ParseCmd(playerId, (TCmd *)data); + uint32_t pktSize = ParseCmd(playerId, (TCmd *)data); data += pktSize; spaceLeft -= pktSize; } @@ -2452,7 +2452,7 @@ void NetSendCmdDItem(bool bHiPri, int ii) NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); } -void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, DWORD dwDam) +void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam) { TCmdDamage cmd; @@ -2465,7 +2465,7 @@ void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, DWORD dwDam) NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); } -void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, DWORD dwDam) +void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam) { TCmdMonDamage cmd; diff --git a/Source/msg.h b/Source/msg.h index 879a235ea..e4ac53e17 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -443,10 +443,10 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position); void NetSendCmdChItem(bool bHiPri, BYTE bLoc); void NetSendCmdDelItem(bool bHiPri, BYTE bLoc); void NetSendCmdDItem(bool bHiPri, int ii); -void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, DWORD dwDam); -void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, DWORD dwDam); +void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam); +void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam); void NetSendCmdString(uint32_t pmask, const char *pszStr); void delta_close_portal(int pnum); -DWORD ParseCmd(int pnum, TCmd *pCmd); +uint32_t ParseCmd(int pnum, TCmd *pCmd); } // namespace devilution diff --git a/Source/multi.cpp b/Source/multi.cpp index 4241e9494..1ee83c543 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -35,7 +35,6 @@ uint16_t sgwPackPlrOffsetTbl[MAX_PLRS]; PkPlayerStruct netplr[MAX_PLRS]; bool sgbPlayerTurnBitTbl[MAX_PLRS]; bool sgbPlayerLeftGameTbl[MAX_PLRS]; -DWORD sgbSentThisCycle; bool gbShouldValidatePackage; BYTE gbActivePlayers; bool gbGameDestroyed; @@ -69,6 +68,8 @@ const event_type EventTypes[3] = { namespace { +uint32_t sgbSentThisCycle; + void BufferInit(TBuffer *pBuf) { pBuf->dwNextWriteOffset = 0; @@ -781,7 +782,7 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv) if (MyPlayerId == pnum) { return; } - assert((DWORD)pnum < MAX_PLRS); + assert(pnum >= 0 && pnum < MAX_PLRS); auto &player = Players[pnum]; if (sgwPackPlrOffsetTbl[pnum] != p->wOffset) { diff --git a/Source/objects.cpp b/Source/objects.cpp index 0cd1deec8..d51aed80a 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3547,7 +3547,7 @@ bool OperateShrineThaumaturgic(int pnum) { for (int j = 0; j < ActiveObjectCount; j++) { int v1 = ActiveObjects[j]; - assert((DWORD)v1 < MAXOBJECTS); + assert(v1 >= 0 && v1 < MAXOBJECTS); if (IsAnyOf(Objects[v1]._otype, OBJ_CHEST1, OBJ_CHEST2, OBJ_CHEST3, OBJ_TCHEST1, OBJ_TCHEST2, OBJ_TCHEST3) && Objects[v1]._oSelFlag == 0) { Objects[v1]._oRndSeed = AdvanceRndSeed(); Objects[v1]._oSelFlag = 1; @@ -4227,7 +4227,7 @@ void OperateShrine(int pnum, int i, _sfx_id sType) dropGoldValue = 0; } - assert((DWORD)i < MAXOBJECTS); + assert(i >= 0 && i < MAXOBJECTS); if (Objects[i]._oSelFlag == 0) return; diff --git a/Source/player.cpp b/Source/player.cpp index ad23a76c6..8bb531f4d 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1221,7 +1221,7 @@ void InitPlayer(int pnum, bool firstTime) player.position.tile = { ViewX, ViewY }; } } else { - DWORD i; + unsigned i; for (i = 0; i < 8 && !PosOkPlayer(pnum, player.position.tile + Displacement { plrxoff2[i], plryoff2[i] }); i++) ; player.position.tile.x += plrxoff2[i]; diff --git a/Source/plrmsg.cpp b/Source/plrmsg.cpp index 44c1a65cb..0e4ee03ba 100644 --- a/Source/plrmsg.cpp +++ b/Source/plrmsg.cpp @@ -24,7 +24,7 @@ const UiFlags TextColorFromPlayerId[MAX_PLRS + 1] = { UIS_SILVER, UIS_SILVER, UI void plrmsg_delay(bool delay) { - static DWORD plrmsgTicks; + static uint32_t plrmsgTicks; if (delay) { plrmsgTicks = -SDL_GetTicks(); @@ -76,7 +76,7 @@ void SendPlrMsg(int pnum, const char *pszStr) void ClearPlrMsg() { _plrmsg *pMsg = plr_msgs; - DWORD tick = SDL_GetTicks(); + uint32_t tick = SDL_GetTicks(); for (int i = 0; i < PMSG_COUNT; i++, pMsg++) { if ((int)(tick - pMsg->time) > 10000) diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 98f5463df..77662af0c 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -840,8 +840,8 @@ static void DrawPlayerHelper(const Surface &out, int x, int y, int sx, int sy) */ static void DrawDungeon(const Surface &out, int sx, int sy, int dx, int dy) { - assert((DWORD)sx < MAXDUNX); - assert((DWORD)sy < MAXDUNY); + assert(sx >= 0 && sx < MAXDUNX); + assert(sy >= 0 && sy < MAXDUNY); if (dRendered[sx][sy]) return; @@ -893,8 +893,9 @@ static void DrawDungeon(const Surface &out, int sx, int sy, int dx, int dy) DrawObject(out, sx, sy, dx, dy, true); DrawItem(out, sx, sy, dx, dy, true); if ((bFlag & BFLAG_PLAYERLR) != 0) { - assert((DWORD)(sy - 1) < MAXDUNY); - DrawPlayerHelper(out, sx, sy - 1, dx, dy); + int syy = sy - 1; + assert(syy >= 0 && syy < MAXDUNY); + DrawPlayerHelper(out, sx, syy, dx, dy); } if ((bFlag & BFLAG_MONSTLR) != 0 && negMon < 0) { DrawMonsterHelper(out, sx, sy, -1, dx, dy); diff --git a/Source/sound.cpp b/Source/sound.cpp index 3fd3e5c02..c5c09ede8 100644 --- a/Source/sound.cpp +++ b/Source/sound.cpp @@ -47,7 +47,7 @@ void LoadMusic(HANDLE handle) #ifndef DISABLE_STREAMING_MUSIC SDL_RWops *musicRw = SFileRw_FromStormHandle(handle); #else - int bytestoread = SFileGetFileSize(handle); + size_t bytestoread = SFileGetFileSize(handle); musicBuffer = new char[bytestoread]; SFileReadFileThreadSafe(handle, musicBuffer, bytestoread); SFileCloseFileThreadSafe(handle); @@ -137,13 +137,11 @@ void ClearDuplicateSounds() void snd_play_snd(TSnd *pSnd, int lVolume, int lPan) { - DWORD tc; - if (pSnd == nullptr || !gbSoundOn) { return; } - tc = SDL_GetTicks(); + uint32_t tc = SDL_GetTicks(); if (tc - pSnd->start_tc < 80) { return; } @@ -177,7 +175,7 @@ std::unique_ptr sound_file_load(const char *path, bool stream) if (!SFileOpenFile(path, &file)) { ErrDlg("SFileOpenFile failed", path, __FILE__, __LINE__); } - DWORD dwBytes = SFileGetFileSize(file); + size_t dwBytes = SFileGetFileSize(file); auto waveFile = MakeArraySharedPtr(dwBytes); SFileReadFileThreadSafe(file, waveFile.get(), dwBytes); int error = snd->DSB.SetChunk(waveFile, dwBytes); @@ -243,7 +241,7 @@ void music_start(uint8_t nTrack) bool success; const char *trackPath; - assert((DWORD)nTrack < NUM_MUSIC); + assert(nTrack < NUM_MUSIC); music_stop(); if (gbMusicOn) { if (spawn_mpq != nullptr) diff --git a/Source/storm/storm.cpp b/Source/storm/storm.cpp index 389062c18..00ad21f55 100644 --- a/Source/storm/storm.cpp +++ b/Source/storm/storm.cpp @@ -36,7 +36,7 @@ SdlMutex Mutex; } // namespace -bool SFileReadFileThreadSafe(HANDLE hFile, void *buffer, DWORD nNumberOfBytesToRead, DWORD *read, int *lpDistanceToMoveHigh) +bool SFileReadFileThreadSafe(HANDLE hFile, void *buffer, size_t nNumberOfBytesToRead, size_t *read, int *lpDistanceToMoveHigh) { const std::lock_guard lock(Mutex); return SFileReadFile(hFile, buffer, nNumberOfBytesToRead, read, lpDistanceToMoveHigh); @@ -138,12 +138,12 @@ bool SFileOpenFile(const char *filename, HANDLE *phFile) return result; } -DWORD SErrGetLastError() +uint32_t SErrGetLastError() { return ::GetLastError(); } -void SErrSetLastError(DWORD dwErrCode) +void SErrSetLastError(uint32_t dwErrCode) { ::SetLastError(dwErrCode); } diff --git a/Source/storm/storm.h b/Source/storm/storm.h index a9b4eaeab..18670a201 100644 --- a/Source/storm/storm.h +++ b/Source/storm/storm.h @@ -132,7 +132,7 @@ bool SNetDestroy(); * * Returns true if the function was called successfully and false otherwise. */ -bool SNetDropPlayer(int playerid, DWORD flags); +bool SNetDropPlayer(int playerid, uint32_t flags); /* SNetGetGameInfo @ 107 * @@ -156,8 +156,7 @@ bool SNetGetGameInfo(game_info type, void *dst, unsigned int length); * * Returns true if the function was called successfully and false otherwise. */ -bool SNetGetTurnsInTransit( - DWORD *turns); +bool SNetGetTurnsInTransit(uint32_t *turns); bool SNetJoinGame(char *gameName, char *gamePassword, int *playerid); @@ -225,7 +224,7 @@ bool WINAPI SFileOpenArchive(const char *szMpqName, DWORD dwPriority, DWORD dwFl #endif bool WINAPI SFileCloseArchive(HANDLE hArchive); bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char *szFileName, DWORD dwSearchScope, HANDLE *phFile); -bool WINAPI SFileReadFile(HANDLE hFile, void *buffer, DWORD nNumberOfBytesToRead, DWORD *read, int *lpDistanceToMoveHigh); +bool WINAPI SFileReadFile(HANDLE hFile, void *buffer, size_t nNumberOfBytesToRead, size_t *read, int *lpDistanceToMoveHigh); DWORD WINAPI SFileGetFileSize(HANDLE hFile, uint32_t *lpFileSizeHigh = nullptr); DWORD WINAPI SFileSetFilePointer(HANDLE, int, int *, int); bool WINAPI SFileCloseFile(HANDLE hFile); @@ -248,7 +247,7 @@ bool WINAPI SFileCloseFile(HANDLE hFile); * * Returns the last error set within the Storm library. */ -DWORD SErrGetLastError(); +uint32_t SErrGetLastError(); /* SErrSetLastError @ 465 * @@ -256,7 +255,7 @@ DWORD SErrGetLastError(); * * dwErrCode: The error code that will be set. */ -void SErrSetLastError(DWORD dwErrCode); +void SErrSetLastError(uint32_t dwErrCode); // Values for dwErrCode #define STORM_ERROR_GAME_TERMINATED 0x85100069 @@ -277,7 +276,7 @@ void SErrSetLastError(DWORD dwErrCode); void SStrCopy(char *dest, const char *src, int max_length); bool SFileSetBasePath(const char *); -bool SNetGetOwnerTurnsWaiting(DWORD *); +bool SNetGetOwnerTurnsWaiting(uint32_t *); bool SNetUnregisterEventHandler(event_type); bool SNetRegisterEventHandler(event_type, SEVTHANDLER); bool SNetSetBasePlayer(int); @@ -296,7 +295,7 @@ bool SFileOpenArchive(const char *szMpqName, DWORD dwPriority, DWORD dwFlags, HA // Locks ReadFile and CloseFile under a mutex. // See https://github.com/ladislav-zezula/StormLib/issues/175 -bool SFileReadFileThreadSafe(HANDLE hFile, void *buffer, DWORD nNumberOfBytesToRead, DWORD *read = nullptr, int *lpDistanceToMoveHigh = nullptr); +bool SFileReadFileThreadSafe(HANDLE hFile, void *buffer, size_t nNumberOfBytesToRead, size_t *read = nullptr, int *lpDistanceToMoveHigh = nullptr); bool SFileCloseFileThreadSafe(HANDLE hFile); // Sets the file's 64-bit seek position. diff --git a/Source/storm/storm_file_wrapper.cpp b/Source/storm/storm_file_wrapper.cpp index e2f124671..c1befa51f 100644 --- a/Source/storm/storm_file_wrapper.cpp +++ b/Source/storm/storm_file_wrapper.cpp @@ -12,9 +12,9 @@ extern "C" { ssize_t SFileCookieRead(void *cookie, char *buf, size_t nbytes) { - DWORD numRead = 0; + size_t numRead = 0; if (!SFileReadFileThreadSafe(static_cast(cookie), buf, nbytes, &numRead)) { - const DWORD errCode = SErrGetLastError(); + const auto errCode = SErrGetLastError(); if (errCode != STORM_ERROR_HANDLE_EOF) { Log("SFileRwRead error: {} ERROR CODE {}", (unsigned int)nbytes, (unsigned int)errCode); } @@ -40,7 +40,7 @@ int SFileCookieSeek(void *cookie, off64_t *pos, int whence) } const std::uint64_t spos = SFileSetFilePointer(static_cast(cookie), *pos, swhence); if (spos == static_cast(-1)) { - Log("SFileRwSeek error: {}", (unsigned int)SErrGetLastError()); + Log("SFileRwSeek error: {}", SErrGetLastError()); return -1; } *pos = static_cast(spos); diff --git a/Source/storm/storm_net.cpp b/Source/storm/storm_net.cpp index 285e238e4..5e5973209 100644 --- a/Source/storm/storm_net.cpp +++ b/Source/storm/storm_net.cpp @@ -96,7 +96,7 @@ bool SNetDestroy() return true; } -bool SNetDropPlayer(int playerid, DWORD flags) +bool SNetDropPlayer(int playerid, uint32_t flags) { #ifndef NONET std::lock_guard lg(storm_net_mutex); @@ -186,7 +186,7 @@ bool SNetJoinGame(char *pszGameName, char *pszGamePassword, int *playerID) /** * @brief Is this the mirror image of SNetGetTurnsInTransit? */ -bool SNetGetOwnerTurnsWaiting(DWORD *turns) +bool SNetGetOwnerTurnsWaiting(uint32_t *turns) { #ifndef NONET std::lock_guard lg(storm_net_mutex); @@ -194,7 +194,7 @@ bool SNetGetOwnerTurnsWaiting(DWORD *turns) return dvlnet_inst->SNetGetOwnerTurnsWaiting(turns); } -bool SNetGetTurnsInTransit(DWORD *turns) +bool SNetGetTurnsInTransit(uint32_t *turns) { #ifndef NONET std::lock_guard lg(storm_net_mutex); diff --git a/Source/storm/storm_sdl_rw.cpp b/Source/storm/storm_sdl_rw.cpp index e522902ad..678624ce7 100644 --- a/Source/storm/storm_sdl_rw.cpp +++ b/Source/storm/storm_sdl_rw.cpp @@ -48,7 +48,7 @@ static int SFileRwSeek(struct SDL_RWops *context, int offset, int whence) } const std::uint64_t pos = SFileSetFilePointer(SFileRwGetHandle(context), offset, swhence); if (pos == static_cast(-1)) { - Log("SFileRwSeek error: {}", (unsigned int)SErrGetLastError()); + Log("SFileRwSeek error: {}", SErrGetLastError()); } return pos; } @@ -59,11 +59,11 @@ static size_t SFileRwRead(struct SDL_RWops *context, void *ptr, size_t size, siz static int SFileRwRead(struct SDL_RWops *context, void *ptr, int size, int maxnum) #endif { - DWORD numRead = 0; + size_t numRead = 0; if (!SFileReadFileThreadSafe(SFileRwGetHandle(context), ptr, maxnum * size, &numRead)) { - const DWORD errCode = SErrGetLastError(); + const auto errCode = SErrGetLastError(); if (errCode != STORM_ERROR_HANDLE_EOF) { - Log("SFileRwRead error: {} {} ERROR CODE {}", (unsigned int)size, (unsigned int)maxnum, (unsigned int)errCode); + Log("SFileRwRead error: {} {} ERROR CODE {}", size, maxnum, errCode); } } return numRead / size; diff --git a/Source/storm/storm_svid.cpp b/Source/storm/storm_svid.cpp index 3c7227c40..ac8a6a05d 100644 --- a/Source/storm/storm_svid.cpp +++ b/Source/storm/storm_svid.cpp @@ -156,7 +156,7 @@ bool SVidPlayBegin(const char *filename, int flags) FILE *file = FILE_FromStormHandle(videoStream); SVidSMK = smk_open_filepointer(file, SMK_MODE_DISK); #else - int bytestoread = SFileGetFileSize(videoStream); + size_t bytestoread = SFileGetFileSize(videoStream); SVidBuffer = std::unique_ptr { new uint8_t[bytestoread] }; SFileReadFileThreadSafe(videoStream, SVidBuffer.get(), bytestoread); SFileCloseFileThreadSafe(videoStream);