Browse Source

Remove more usage of miniwin types

pull/2417/head
Anders Jenbo 5 years ago
parent
commit
0889780923
  1. 4
      Source/DiabloUI/art.cpp
  2. 26
      Source/missiles.cpp
  3. 110
      Source/monster.cpp
  4. 7
      Source/mpqapi.cpp
  5. 10
      Source/msg.cpp
  6. 6
      Source/msg.h
  7. 5
      Source/multi.cpp
  8. 4
      Source/objects.cpp
  9. 2
      Source/player.cpp
  10. 4
      Source/plrmsg.cpp
  11. 9
      Source/scrollrt.cpp
  12. 10
      Source/sound.cpp
  13. 6
      Source/storm/storm.cpp
  14. 15
      Source/storm/storm.h
  15. 6
      Source/storm/storm_file_wrapper.cpp
  16. 6
      Source/storm/storm_net.cpp
  17. 8
      Source/storm/storm_sdl_rw.cpp
  18. 2
      Source/storm/storm_svid.cpp

4
Source/DiabloUI/art.cpp

@ -11,7 +11,7 @@
namespace devilution { namespace devilution {
namespace { namespace {
constexpr unsigned PcxHeaderSize = 128; constexpr size_t PcxHeaderSize = 128;
constexpr unsigned NumPaletteColors = 256; constexpr unsigned NumPaletteColors = 256;
constexpr unsigned PcxPaletteSize = 1 + NumPaletteColors * 3; 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); pixelDataSize -= PcxHeaderSize + (has256ColorPalette ? PcxPaletteSize : 0);
// We read 1 extra byte because it delimits the palette. // 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<BYTE[]> fileBuffer { new BYTE[readSize] }; std::unique_ptr<BYTE[]> fileBuffer { new BYTE[readSize] };
if (!SFileReadFileThreadSafe(handle, fileBuffer.get(), readSize)) { if (!SFileReadFileThreadSafe(handle, fileBuffer.get(), readSize)) {
return false; return false;

26
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*/) 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]._mirnd = GenerateRnd(15) + 1;
Missiles[mi]._midam = (micaster == 0) ? (GenerateRnd(Players[id]._pMagic / 4) + 1) : 15; 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 mx = Missiles[i].position.tile.x;
int my = Missiles[i].position.tile.y; int my = Missiles[i].position.tile.y;
assert((DWORD)mx < MAXDUNX); assert(mx >= 0 && mx < MAXDUNX);
assert((DWORD)my < MAXDUNY); assert(my >= 0 && my < MAXDUNY);
int pn = dPiece[mx][my]; int pn = dPiece[mx][my];
assert((DWORD)pn <= MAXTILES); assert(pn >= 0 && pn <= MAXTILES);
if (Missiles[i]._misource == -1) { if (Missiles[i]._misource == -1) {
if ((mx != Missiles[i].position.start.x || my != Missiles[i].position.start.y) && nMissileTable[pn]) { 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) void MI_Lightctrl(int i)
{ {
assert((DWORD)i < MAXMISSILES); assert(i >= 0 && i < MAXMISSILES);
Missiles[i]._mirange--; Missiles[i]._mirange--;
int dam; int dam;
@ -3810,10 +3810,10 @@ void MI_Lightctrl(int i)
int mx = Missiles[i].position.tile.x; int mx = Missiles[i].position.tile.x;
int my = Missiles[i].position.tile.y; int my = Missiles[i].position.tile.y;
assert((DWORD)mx < MAXDUNX); assert(mx >= 0 && mx < MAXDUNX);
assert((DWORD)my < MAXDUNY); assert(my >= 0 && my < MAXDUNY);
int pn = dPiece[mx][my]; 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 (id != -1 || Point { mx, my } != Missiles[i].position.start) {
if (nMissileTable[pn]) { if (nMissileTable[pn]) {
@ -4047,7 +4047,7 @@ void MI_Firemove(int i)
void MI_Guardian(int i) void MI_Guardian(int i)
{ {
assert((DWORD)i < MAXMISSILES); assert(i >= 0 && i < MAXMISSILES);
Missiles[i]._mirange--; Missiles[i]._mirange--;
@ -4427,7 +4427,7 @@ void MI_Wave(int i)
{ {
bool f1 = false; bool f1 = false;
bool f2 = false; bool f2 = false;
assert((DWORD)i < MAXMISSILES); assert(i >= 0 && i < MAXMISSILES);
int id = Missiles[i]._misource; int id = Missiles[i]._misource;
Point src = Missiles[i].position.tile; Point src = Missiles[i].position.tile;
@ -4436,7 +4436,7 @@ void MI_Wave(int i)
Direction dirb = right[right[sd]]; Direction dirb = right[right[sd]];
Point na = src + sd; Point na = src + sd;
int pn = dPiece[na.x][na.y]; int pn = dPiece[na.x][na.y];
assert((DWORD)pn <= MAXTILES); assert(pn >= 0 && pn <= MAXTILES);
if (!nMissileTable[pn]) { if (!nMissileTable[pn]) {
Direction pdir = Players[id]._pdir; Direction pdir = Players[id]._pdir;
AddMissile(na, na + sd, pdir, MIS_FIREMOVE, TARGET_MONSTERS, id, 0, Missiles[i]._mispllvl); 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; Point nb = src + sd + dirb;
for (int j = 0; j < (Missiles[i]._mispllvl / 2) + 2; j++) { 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 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)) { if (nMissileTable[pn] || f1 || !InDungeonBounds(na)) {
f1 = true; f1 = true;
} else { } else {
@ -4452,7 +4452,7 @@ void MI_Wave(int i)
na += dira; na += dira;
} }
pn = dPiece[nb.x][nb.y]; // BUGFIX: dPiece is accessed before check against dungeon size and 0 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)) { if (nMissileTable[pn] || f2 || !InDungeonBounds(nb)) {
f2 = true; f2 = true;
} else { } else {

110
Source/monster.cpp

@ -1136,7 +1136,7 @@ void SpawnLoot(MonsterStruct &monster, bool sendmsg)
void Teleport(int i) void Teleport(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode == MM_STONE) if (monster._mmode == MM_STONE)
@ -1175,7 +1175,7 @@ void Teleport(int i)
void MonsterHitMonster(int mid, int i, int dam) void MonsterHitMonster(int mid, int i, int dam)
{ {
assert((DWORD)mid < MAXMONSTERS); assert(mid >= 0 && mid < MAXMONSTERS);
auto &monster = Monsters[mid]; auto &monster = Monsters[mid];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
@ -1207,7 +1207,7 @@ void MonsterHitMonster(int mid, int i, int dam)
void StartMonsterDeath(int i, int pnum, bool sendmsg) void StartMonsterDeath(int i, int pnum, bool sendmsg)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
@ -1242,9 +1242,9 @@ void StartMonsterDeath(int i, int pnum, bool sendmsg)
void StartDeathFromMonster(int i, int mid) void StartDeathFromMonster(int i, int mid)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &killer = Monsters[i]; auto &killer = Monsters[i];
assert((DWORD)mid < MAXMONSTERS); assert(mid >= 0 && mid < MAXMONSTERS);
auto &monster = Monsters[mid]; auto &monster = Monsters[mid];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
@ -1353,7 +1353,7 @@ bool MonsterIdle(MonsterStruct &monster)
*/ */
bool MonsterWalk(int i, int variant) bool MonsterWalk(int i, int variant)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
assert(monster.MType != nullptr); 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) 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]; auto &monster = Monsters[mid];
assert(monster.MType != nullptr); 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) 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]; auto &monster = Monsters[i];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
@ -1579,7 +1579,7 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
bool MonsterAttack(int i) bool MonsterAttack(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
assert(monster.MData != nullptr); assert(monster.MData != nullptr);
@ -1609,7 +1609,7 @@ bool MonsterAttack(int i)
bool MonaterRangedAttack(int i) bool MonaterRangedAttack(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
assert(monster.MData != nullptr); assert(monster.MData != nullptr);
@ -1649,7 +1649,7 @@ bool MonaterRangedAttack(int i)
bool MonsterRangedSpecialAttack(int i) bool MonsterRangedSpecialAttack(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
assert(monster.MData != nullptr); assert(monster.MData != nullptr);
@ -1690,7 +1690,7 @@ bool MonsterRangedSpecialAttack(int i)
bool MonsterSpecialAttack(int i) bool MonsterSpecialAttack(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
assert(monster.MData != nullptr); assert(monster.MData != nullptr);
@ -1836,7 +1836,7 @@ bool MonsterGotHit(MonsterStruct &monster)
bool MonsterDeath(int i) bool MonsterDeath(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
assert(monster.MType != nullptr); assert(monster.MType != nullptr);
@ -1946,7 +1946,7 @@ bool IsLineNotSolid(Point startPoint, Point endPoint)
void GroupUnity(int i) void GroupUnity(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster.leaderflag == MonsterRelation::Individual) { if (monster.leaderflag == MonsterRelation::Individual) {
@ -2112,7 +2112,7 @@ bool AiPlanWalk(int i)
/** Maps from walking path step to facing direction. */ /** 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 }; 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]; auto &monster = Monsters[i];
if (FindPath([&monster](Point position) { return IsTileAccessible(monster, position); }, monster.position.tile, monster.enemyPosition, path) == 0) { 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) bool AiPlanPath(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster.MType->mtype != MT_GOLEM) { if (monster.MType->mtype != MT_GOLEM) {
@ -2203,7 +2203,7 @@ bool AiPlanPath(int i)
void AiAvoidance(int i, bool special) void AiAvoidance(int i, bool special)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { 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) void AiRanged(int i, missile_id missileType, bool special)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { 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) 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]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { 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) void ZombieAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { if (monster._mmode != MM_STAND) {
@ -2395,7 +2395,7 @@ void ZombieAi(int i)
void OverlordAi(int i) void OverlordAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { if (monster._mmode != MM_STAND || monster._msquelch == 0) {
@ -2425,7 +2425,7 @@ void OverlordAi(int i)
void SkeletonAi(int i) void SkeletonAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { if (monster._mmode != MM_STAND || monster._msquelch == 0) {
@ -2455,7 +2455,7 @@ void SkeletonAi(int i)
void SkeletonBowAi(int i) void SkeletonBowAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { if (monster._mmode != MM_STAND || monster._msquelch == 0) {
@ -2492,7 +2492,7 @@ void SkeletonBowAi(int i)
void ScavengerAi(int i) void ScavengerAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) if (monster._mmode != MM_STAND)
@ -2583,7 +2583,7 @@ void ScavengerAi(int i)
void RhinoAi(int i) void RhinoAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { if (monster._mmode != MM_STAND || monster._msquelch == 0) {
@ -2658,7 +2658,7 @@ void GoatBowAi(int i)
void FallenAi(int i) void FallenAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mgoal == MGOAL_ATTACK2) { if (monster._mgoal == MGOAL_ATTACK2) {
@ -2728,7 +2728,7 @@ void MagmaAi(int i)
void LeoricAi(int i) void LeoricAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { if (monster._mmode != MM_STAND || monster._msquelch == 0) {
@ -2790,7 +2790,7 @@ void LeoricAi(int i)
void BatAi(int i) void BatAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
int pnum = monster._menemy; int pnum = monster._menemy;
@ -2848,7 +2848,7 @@ void BatAi(int i)
void GargoyleAi(int i) void GargoyleAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
int dx = monster.position.tile.x - monster.position.last.x; int dx = monster.position.tile.x - monster.position.last.x;
@ -2884,7 +2884,7 @@ void GargoyleAi(int i)
void ButcherAi(int i) void ButcherAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { if (monster._mmode != MM_STAND || monster._msquelch == 0) {
@ -2914,7 +2914,7 @@ void SuccubusAi(int i)
void SneakAi(int i) void SneakAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { if (monster._mmode != MM_STAND) {
@ -2980,7 +2980,7 @@ void StormAi(int i)
void FiremanAi(int i) void FiremanAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) if (monster._mmode != MM_STAND || monster._msquelch == 0)
@ -3035,7 +3035,7 @@ void FiremanAi(int i)
void GharbadAi(int i) void GharbadAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { if (monster._mmode != MM_STAND) {
@ -3094,7 +3094,7 @@ void AcidAi(int i)
void SnotSpilAi(int i) void SnotSpilAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { if (monster._mmode != MM_STAND) {
@ -3137,7 +3137,7 @@ void SnotSpilAi(int i)
void SnakeAi(int i) void SnakeAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
char pattern[6] = { 1, 1, 0, -1, -1, 0 }; char pattern[6] = { 1, 1, 0, -1, -1, 0 };
@ -3198,7 +3198,7 @@ void SnakeAi(int i)
void CounselorAi(int i) void CounselorAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { if (monster._mmode != MM_STAND || monster._msquelch == 0) {
@ -3262,7 +3262,7 @@ void CounselorAi(int i)
void ZharAi(int i) void ZharAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { if (monster._mmode != MM_STAND) {
@ -3295,7 +3295,7 @@ void ZharAi(int i)
void MegaAi(int i) void MegaAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
int mx = monster.position.tile.x - monster.enemyPosition.x; int mx = monster.position.tile.x - monster.enemyPosition.x;
@ -3369,7 +3369,7 @@ void DiabloAi(int i)
void LazarusAi(int i) void LazarusAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { if (monster._mmode != MM_STAND) {
@ -3417,7 +3417,7 @@ void LazarusAi(int i)
void LazarusMinionAi(int i) void LazarusMinionAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) if (monster._mmode != MM_STAND)
@ -3446,7 +3446,7 @@ void LazarusMinionAi(int i)
void LachdananAi(int i) void LachdananAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { if (monster._mmode != MM_STAND) {
@ -3477,7 +3477,7 @@ void LachdananAi(int i)
void WarlordAi(int i) void WarlordAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND) { if (monster._mmode != MM_STAND) {
@ -3515,7 +3515,7 @@ void TorchantAi(int i)
void HorkDemonAi(int i) void HorkDemonAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mmode != MM_STAND || monster._msquelch == 0) { 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) void M_StartKill(int i, int pnum)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (MyPlayerId == pnum) { if (MyPlayerId == pnum) {
@ -4200,7 +4200,7 @@ void M_StartKill(int i, int pnum)
void M_SyncStartKill(int i, Point position, int pnum) void M_SyncStartKill(int i, Point position, int pnum)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
if (monster._mhitpoints > 0 || monster._mmode == MM_DEATH) { 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) void M_UpdateLeader(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
for (int j = 0; j < ActiveMonsterCount; j++) { for (int j = 0; j < ActiveMonsterCount; j++) {
@ -4306,7 +4306,7 @@ void PrepDoEnding()
void M_WalkDir(int i, Direction md) 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; int mwi = Monsters[i].MType->GetAnimData(MonsterGraphic::Walk).Frames - 1;
switch (md) { switch (md) {
@ -4341,7 +4341,7 @@ void M_WalkDir(int i, Direction md)
void GolumAi(int i) void GolumAi(int i)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &golem = Monsters[i]; auto &golem = Monsters[i];
if (golem.position.tile.x == 1 && golem.position.tile.y == 0) { if (golem.position.tile.x == 1 && golem.position.tile.y == 0) {
@ -4431,7 +4431,7 @@ void ProcessMonsters()
{ {
DeleteMonsterList(); DeleteMonsterList();
assert((DWORD)ActiveMonsterCount <= MAXMONSTERS); assert(ActiveMonsterCount >= 0 && ActiveMonsterCount <= MAXMONSTERS);
for (int i = 0; i < ActiveMonsterCount; i++) { for (int i = 0; i < ActiveMonsterCount; i++) {
int mi = ActiveMonsters[i]; int mi = ActiveMonsters[i];
auto &monster = Monsters[mi]; auto &monster = Monsters[mi];
@ -4470,11 +4470,11 @@ void ProcessMonsters()
} }
if ((monster._mFlags & MFLAG_TARGETS_MONSTER) != 0) { 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.position.last = Monsters[monster._menemy].position.future;
monster.enemyPosition = monster.position.last; monster.enemyPosition = monster.position.last;
} else { } else {
assert((DWORD)monster._menemy < MAX_PLRS); assert(monster._menemy >= 0 && monster._menemy < MAX_PLRS);
monster.enemyPosition = Players[monster._menemy].position.future; monster.enemyPosition = Players[monster._menemy].position.future;
if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) {
monster._msquelch = UINT8_MAX; monster._msquelch = UINT8_MAX;
@ -4567,7 +4567,7 @@ void FreeMonsters()
bool DirOK(int i, Direction mdir) bool DirOK(int i, Direction mdir)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
Point position = monster.position.tile; Point position = monster.position.tile;
Point futurePosition = position + mdir; Point futurePosition = position + mdir;
@ -4923,12 +4923,12 @@ void PlayEffect(MonsterStruct &monster, int mode)
void MissToMonst(int i, Point position) void MissToMonst(int i, Point position)
{ {
assert((DWORD)i < MAXMISSILES); assert(i >= 0 && i < MAXMISSILES);
MissileStruct *miss = &Missiles[i]; MissileStruct *miss = &Missiles[i];
int m = miss->_misource; int m = miss->_misource;
assert((DWORD)m < MAXMONSTERS); assert(m >= 0 && m < MAXMONSTERS);
auto &monster = Monsters[m]; auto &monster = Monsters[m];
Point oldPosition = miss->position.tile; Point oldPosition = miss->position.tile;
@ -5095,7 +5095,7 @@ void TalktoMonster(MonsterStruct &monster)
void SpawnGolum(int i, Point position, int mi) void SpawnGolum(int i, Point position, int mi)
{ {
assert((DWORD)i < MAXMONSTERS); assert(i >= 0 && i < MAXMONSTERS);
auto &monster = Monsters[i]; auto &monster = Monsters[i];
dMonster[position.x][position.y] = i + 1; dMonster[position.x][position.y] = i + 1;

7
Source/mpqapi.cpp

@ -406,7 +406,7 @@ int FindFreeBlock(uint32_t size, uint32_t *blockSize)
continue; continue;
if (pBlockTbl->sizefile != 0) if (pBlockTbl->sizefile != 0)
continue; continue;
if ((DWORD)pBlockTbl->sizealloc < size) if (pBlockTbl->sizealloc < size)
continue; continue;
result = pBlockTbl->offset; result = pBlockTbl->offset;
@ -625,7 +625,6 @@ bool mpqapi_has_file(const char *pszName)
bool OpenMPQ(const char *pszArchive) bool OpenMPQ(const char *pszArchive)
{ {
DWORD key;
_FILEHEADER fhdr; _FILEHEADER fhdr;
InitHash(); InitHash();
@ -644,7 +643,7 @@ bool OpenMPQ(const char *pszArchive)
if (fhdr.blockcount > 0) { if (fhdr.blockcount > 0) {
if (!cur_archive.stream.Read(reinterpret_cast<char *>(cur_archive.sgpBlockTbl), BlockEntrySize)) if (!cur_archive.stream.Read(reinterpret_cast<char *>(cur_archive.sgpBlockTbl), BlockEntrySize))
goto on_error; goto on_error;
key = Hash("(block table)", 3); uint32_t key = Hash("(block table)", 3);
Decrypt((DWORD *)cur_archive.sgpBlockTbl, BlockEntrySize, key); Decrypt((DWORD *)cur_archive.sgpBlockTbl, BlockEntrySize, key);
} }
cur_archive.sgpHashTbl = new _HASHENTRY[HashEntrySize / sizeof(_HASHENTRY)]; cur_archive.sgpHashTbl = new _HASHENTRY[HashEntrySize / sizeof(_HASHENTRY)];
@ -652,7 +651,7 @@ bool OpenMPQ(const char *pszArchive)
if (fhdr.hashcount > 0) { if (fhdr.hashcount > 0) {
if (!cur_archive.stream.Read(reinterpret_cast<char *>(cur_archive.sgpHashTbl), HashEntrySize)) if (!cur_archive.stream.Read(reinterpret_cast<char *>(cur_archive.sgpHashTbl), HashEntrySize))
goto on_error; goto on_error;
key = Hash("(hash table)", 3); uint32_t key = Hash("(hash table)", 3);
Decrypt((DWORD *)cur_archive.sgpHashTbl, HashEntrySize, key); Decrypt((DWORD *)cur_archive.sgpHashTbl, HashEntrySize, key);
} }

10
Source/msg.cpp

@ -41,8 +41,8 @@ namespace {
#define MAX_CHUNKS (NUMLEVELS + 4) #define MAX_CHUNKS (NUMLEVELS + 4)
DWORD sgdwOwnerWait; uint32_t sgdwOwnerWait;
DWORD sgdwRecvOffset; uint32_t sgdwRecvOffset;
int sgnCurrMegaPlayer; int sgnCurrMegaPlayer;
DLevel sgLevels[NUMLEVELS]; DLevel sgLevels[NUMLEVELS];
BYTE sbLastCmd; BYTE sbLastCmd;
@ -106,7 +106,7 @@ void PrePacket()
continue; continue;
} }
int pktSize = ParseCmd(playerId, (TCmd *)data); uint32_t pktSize = ParseCmd(playerId, (TCmd *)data);
data += pktSize; data += pktSize;
spaceLeft -= pktSize; spaceLeft -= pktSize;
} }
@ -2452,7 +2452,7 @@ void NetSendCmdDItem(bool bHiPri, int ii)
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); 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; TCmdDamage cmd;
@ -2465,7 +2465,7 @@ void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, DWORD dwDam)
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); 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; TCmdMonDamage cmd;

6
Source/msg.h

@ -443,10 +443,10 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position);
void NetSendCmdChItem(bool bHiPri, BYTE bLoc); void NetSendCmdChItem(bool bHiPri, BYTE bLoc);
void NetSendCmdDelItem(bool bHiPri, BYTE bLoc); void NetSendCmdDelItem(bool bHiPri, BYTE bLoc);
void NetSendCmdDItem(bool bHiPri, int ii); void NetSendCmdDItem(bool bHiPri, int ii);
void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, DWORD dwDam); void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam);
void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, DWORD dwDam); void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam);
void NetSendCmdString(uint32_t pmask, const char *pszStr); void NetSendCmdString(uint32_t pmask, const char *pszStr);
void delta_close_portal(int pnum); void delta_close_portal(int pnum);
DWORD ParseCmd(int pnum, TCmd *pCmd); uint32_t ParseCmd(int pnum, TCmd *pCmd);
} // namespace devilution } // namespace devilution

5
Source/multi.cpp

@ -35,7 +35,6 @@ uint16_t sgwPackPlrOffsetTbl[MAX_PLRS];
PkPlayerStruct netplr[MAX_PLRS]; PkPlayerStruct netplr[MAX_PLRS];
bool sgbPlayerTurnBitTbl[MAX_PLRS]; bool sgbPlayerTurnBitTbl[MAX_PLRS];
bool sgbPlayerLeftGameTbl[MAX_PLRS]; bool sgbPlayerLeftGameTbl[MAX_PLRS];
DWORD sgbSentThisCycle;
bool gbShouldValidatePackage; bool gbShouldValidatePackage;
BYTE gbActivePlayers; BYTE gbActivePlayers;
bool gbGameDestroyed; bool gbGameDestroyed;
@ -69,6 +68,8 @@ const event_type EventTypes[3] = {
namespace { namespace {
uint32_t sgbSentThisCycle;
void BufferInit(TBuffer *pBuf) void BufferInit(TBuffer *pBuf)
{ {
pBuf->dwNextWriteOffset = 0; pBuf->dwNextWriteOffset = 0;
@ -781,7 +782,7 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv)
if (MyPlayerId == pnum) { if (MyPlayerId == pnum) {
return; return;
} }
assert((DWORD)pnum < MAX_PLRS); assert(pnum >= 0 && pnum < MAX_PLRS);
auto &player = Players[pnum]; auto &player = Players[pnum];
if (sgwPackPlrOffsetTbl[pnum] != p->wOffset) { if (sgwPackPlrOffsetTbl[pnum] != p->wOffset) {

4
Source/objects.cpp

@ -3547,7 +3547,7 @@ bool OperateShrineThaumaturgic(int pnum)
{ {
for (int j = 0; j < ActiveObjectCount; j++) { for (int j = 0; j < ActiveObjectCount; j++) {
int v1 = ActiveObjects[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) { 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]._oRndSeed = AdvanceRndSeed();
Objects[v1]._oSelFlag = 1; Objects[v1]._oSelFlag = 1;
@ -4227,7 +4227,7 @@ void OperateShrine(int pnum, int i, _sfx_id sType)
dropGoldValue = 0; dropGoldValue = 0;
} }
assert((DWORD)i < MAXOBJECTS); assert(i >= 0 && i < MAXOBJECTS);
if (Objects[i]._oSelFlag == 0) if (Objects[i]._oSelFlag == 0)
return; return;

2
Source/player.cpp

@ -1221,7 +1221,7 @@ void InitPlayer(int pnum, bool firstTime)
player.position.tile = { ViewX, ViewY }; player.position.tile = { ViewX, ViewY };
} }
} else { } else {
DWORD i; unsigned i;
for (i = 0; i < 8 && !PosOkPlayer(pnum, player.position.tile + Displacement { plrxoff2[i], plryoff2[i] }); i++) for (i = 0; i < 8 && !PosOkPlayer(pnum, player.position.tile + Displacement { plrxoff2[i], plryoff2[i] }); i++)
; ;
player.position.tile.x += plrxoff2[i]; player.position.tile.x += plrxoff2[i];

4
Source/plrmsg.cpp

@ -24,7 +24,7 @@ const UiFlags TextColorFromPlayerId[MAX_PLRS + 1] = { UIS_SILVER, UIS_SILVER, UI
void plrmsg_delay(bool delay) void plrmsg_delay(bool delay)
{ {
static DWORD plrmsgTicks; static uint32_t plrmsgTicks;
if (delay) { if (delay) {
plrmsgTicks = -SDL_GetTicks(); plrmsgTicks = -SDL_GetTicks();
@ -76,7 +76,7 @@ void SendPlrMsg(int pnum, const char *pszStr)
void ClearPlrMsg() void ClearPlrMsg()
{ {
_plrmsg *pMsg = plr_msgs; _plrmsg *pMsg = plr_msgs;
DWORD tick = SDL_GetTicks(); uint32_t tick = SDL_GetTicks();
for (int i = 0; i < PMSG_COUNT; i++, pMsg++) { for (int i = 0; i < PMSG_COUNT; i++, pMsg++) {
if ((int)(tick - pMsg->time) > 10000) if ((int)(tick - pMsg->time) > 10000)

9
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) static void DrawDungeon(const Surface &out, int sx, int sy, int dx, int dy)
{ {
assert((DWORD)sx < MAXDUNX); assert(sx >= 0 && sx < MAXDUNX);
assert((DWORD)sy < MAXDUNY); assert(sy >= 0 && sy < MAXDUNY);
if (dRendered[sx][sy]) if (dRendered[sx][sy])
return; 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); DrawObject(out, sx, sy, dx, dy, true);
DrawItem(out, sx, sy, dx, dy, true); DrawItem(out, sx, sy, dx, dy, true);
if ((bFlag & BFLAG_PLAYERLR) != 0) { if ((bFlag & BFLAG_PLAYERLR) != 0) {
assert((DWORD)(sy - 1) < MAXDUNY); int syy = sy - 1;
DrawPlayerHelper(out, sx, sy - 1, dx, dy); assert(syy >= 0 && syy < MAXDUNY);
DrawPlayerHelper(out, sx, syy, dx, dy);
} }
if ((bFlag & BFLAG_MONSTLR) != 0 && negMon < 0) { if ((bFlag & BFLAG_MONSTLR) != 0 && negMon < 0) {
DrawMonsterHelper(out, sx, sy, -1, dx, dy); DrawMonsterHelper(out, sx, sy, -1, dx, dy);

10
Source/sound.cpp

@ -47,7 +47,7 @@ void LoadMusic(HANDLE handle)
#ifndef DISABLE_STREAMING_MUSIC #ifndef DISABLE_STREAMING_MUSIC
SDL_RWops *musicRw = SFileRw_FromStormHandle(handle); SDL_RWops *musicRw = SFileRw_FromStormHandle(handle);
#else #else
int bytestoread = SFileGetFileSize(handle); size_t bytestoread = SFileGetFileSize(handle);
musicBuffer = new char[bytestoread]; musicBuffer = new char[bytestoread];
SFileReadFileThreadSafe(handle, musicBuffer, bytestoread); SFileReadFileThreadSafe(handle, musicBuffer, bytestoread);
SFileCloseFileThreadSafe(handle); SFileCloseFileThreadSafe(handle);
@ -137,13 +137,11 @@ void ClearDuplicateSounds()
void snd_play_snd(TSnd *pSnd, int lVolume, int lPan) void snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
{ {
DWORD tc;
if (pSnd == nullptr || !gbSoundOn) { if (pSnd == nullptr || !gbSoundOn) {
return; return;
} }
tc = SDL_GetTicks(); uint32_t tc = SDL_GetTicks();
if (tc - pSnd->start_tc < 80) { if (tc - pSnd->start_tc < 80) {
return; return;
} }
@ -177,7 +175,7 @@ std::unique_ptr<TSnd> sound_file_load(const char *path, bool stream)
if (!SFileOpenFile(path, &file)) { if (!SFileOpenFile(path, &file)) {
ErrDlg("SFileOpenFile failed", path, __FILE__, __LINE__); ErrDlg("SFileOpenFile failed", path, __FILE__, __LINE__);
} }
DWORD dwBytes = SFileGetFileSize(file); size_t dwBytes = SFileGetFileSize(file);
auto waveFile = MakeArraySharedPtr<std::uint8_t>(dwBytes); auto waveFile = MakeArraySharedPtr<std::uint8_t>(dwBytes);
SFileReadFileThreadSafe(file, waveFile.get(), dwBytes); SFileReadFileThreadSafe(file, waveFile.get(), dwBytes);
int error = snd->DSB.SetChunk(waveFile, dwBytes); int error = snd->DSB.SetChunk(waveFile, dwBytes);
@ -243,7 +241,7 @@ void music_start(uint8_t nTrack)
bool success; bool success;
const char *trackPath; const char *trackPath;
assert((DWORD)nTrack < NUM_MUSIC); assert(nTrack < NUM_MUSIC);
music_stop(); music_stop();
if (gbMusicOn) { if (gbMusicOn) {
if (spawn_mpq != nullptr) if (spawn_mpq != nullptr)

6
Source/storm/storm.cpp

@ -36,7 +36,7 @@ SdlMutex Mutex;
} // namespace } // 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<SdlMutex> lock(Mutex); const std::lock_guard<SdlMutex> lock(Mutex);
return SFileReadFile(hFile, buffer, nNumberOfBytesToRead, read, lpDistanceToMoveHigh); return SFileReadFile(hFile, buffer, nNumberOfBytesToRead, read, lpDistanceToMoveHigh);
@ -138,12 +138,12 @@ bool SFileOpenFile(const char *filename, HANDLE *phFile)
return result; return result;
} }
DWORD SErrGetLastError() uint32_t SErrGetLastError()
{ {
return ::GetLastError(); return ::GetLastError();
} }
void SErrSetLastError(DWORD dwErrCode) void SErrSetLastError(uint32_t dwErrCode)
{ {
::SetLastError(dwErrCode); ::SetLastError(dwErrCode);
} }

15
Source/storm/storm.h

@ -132,7 +132,7 @@ bool SNetDestroy();
* *
* Returns true if the function was called successfully and false otherwise. * 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 /* 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. * Returns true if the function was called successfully and false otherwise.
*/ */
bool SNetGetTurnsInTransit( bool SNetGetTurnsInTransit(uint32_t *turns);
DWORD *turns);
bool SNetJoinGame(char *gameName, char *gamePassword, int *playerid); bool SNetJoinGame(char *gameName, char *gamePassword, int *playerid);
@ -225,7 +224,7 @@ bool WINAPI SFileOpenArchive(const char *szMpqName, DWORD dwPriority, DWORD dwFl
#endif #endif
bool WINAPI SFileCloseArchive(HANDLE hArchive); bool WINAPI SFileCloseArchive(HANDLE hArchive);
bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char *szFileName, DWORD dwSearchScope, HANDLE *phFile); 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 SFileGetFileSize(HANDLE hFile, uint32_t *lpFileSizeHigh = nullptr);
DWORD WINAPI SFileSetFilePointer(HANDLE, int, int *, int); DWORD WINAPI SFileSetFilePointer(HANDLE, int, int *, int);
bool WINAPI SFileCloseFile(HANDLE hFile); bool WINAPI SFileCloseFile(HANDLE hFile);
@ -248,7 +247,7 @@ bool WINAPI SFileCloseFile(HANDLE hFile);
* *
* Returns the last error set within the Storm library. * Returns the last error set within the Storm library.
*/ */
DWORD SErrGetLastError(); uint32_t SErrGetLastError();
/* SErrSetLastError @ 465 /* SErrSetLastError @ 465
* *
@ -256,7 +255,7 @@ DWORD SErrGetLastError();
* *
* dwErrCode: The error code that will be set. * dwErrCode: The error code that will be set.
*/ */
void SErrSetLastError(DWORD dwErrCode); void SErrSetLastError(uint32_t dwErrCode);
// Values for dwErrCode // Values for dwErrCode
#define STORM_ERROR_GAME_TERMINATED 0x85100069 #define STORM_ERROR_GAME_TERMINATED 0x85100069
@ -277,7 +276,7 @@ void SErrSetLastError(DWORD dwErrCode);
void SStrCopy(char *dest, const char *src, int max_length); void SStrCopy(char *dest, const char *src, int max_length);
bool SFileSetBasePath(const char *); bool SFileSetBasePath(const char *);
bool SNetGetOwnerTurnsWaiting(DWORD *); bool SNetGetOwnerTurnsWaiting(uint32_t *);
bool SNetUnregisterEventHandler(event_type); bool SNetUnregisterEventHandler(event_type);
bool SNetRegisterEventHandler(event_type, SEVTHANDLER); bool SNetRegisterEventHandler(event_type, SEVTHANDLER);
bool SNetSetBasePlayer(int); bool SNetSetBasePlayer(int);
@ -296,7 +295,7 @@ bool SFileOpenArchive(const char *szMpqName, DWORD dwPriority, DWORD dwFlags, HA
// Locks ReadFile and CloseFile under a mutex. // Locks ReadFile and CloseFile under a mutex.
// See https://github.com/ladislav-zezula/StormLib/issues/175 // 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); bool SFileCloseFileThreadSafe(HANDLE hFile);
// Sets the file's 64-bit seek position. // Sets the file's 64-bit seek position.

6
Source/storm/storm_file_wrapper.cpp

@ -12,9 +12,9 @@ extern "C" {
ssize_t SFileCookieRead(void *cookie, char *buf, size_t nbytes) ssize_t SFileCookieRead(void *cookie, char *buf, size_t nbytes)
{ {
DWORD numRead = 0; size_t numRead = 0;
if (!SFileReadFileThreadSafe(static_cast<HANDLE>(cookie), buf, nbytes, &numRead)) { if (!SFileReadFileThreadSafe(static_cast<HANDLE>(cookie), buf, nbytes, &numRead)) {
const DWORD errCode = SErrGetLastError(); const auto errCode = SErrGetLastError();
if (errCode != STORM_ERROR_HANDLE_EOF) { if (errCode != STORM_ERROR_HANDLE_EOF) {
Log("SFileRwRead error: {} ERROR CODE {}", (unsigned int)nbytes, (unsigned int)errCode); 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<HANDLE>(cookie), *pos, swhence); const std::uint64_t spos = SFileSetFilePointer(static_cast<HANDLE>(cookie), *pos, swhence);
if (spos == static_cast<std::uint64_t>(-1)) { if (spos == static_cast<std::uint64_t>(-1)) {
Log("SFileRwSeek error: {}", (unsigned int)SErrGetLastError()); Log("SFileRwSeek error: {}", SErrGetLastError());
return -1; return -1;
} }
*pos = static_cast<off64_t>(spos); *pos = static_cast<off64_t>(spos);

6
Source/storm/storm_net.cpp

@ -96,7 +96,7 @@ bool SNetDestroy()
return true; return true;
} }
bool SNetDropPlayer(int playerid, DWORD flags) bool SNetDropPlayer(int playerid, uint32_t flags)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<SdlMutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
@ -186,7 +186,7 @@ bool SNetJoinGame(char *pszGameName, char *pszGamePassword, int *playerID)
/** /**
* @brief Is this the mirror image of SNetGetTurnsInTransit? * @brief Is this the mirror image of SNetGetTurnsInTransit?
*/ */
bool SNetGetOwnerTurnsWaiting(DWORD *turns) bool SNetGetOwnerTurnsWaiting(uint32_t *turns)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<SdlMutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
@ -194,7 +194,7 @@ bool SNetGetOwnerTurnsWaiting(DWORD *turns)
return dvlnet_inst->SNetGetOwnerTurnsWaiting(turns); return dvlnet_inst->SNetGetOwnerTurnsWaiting(turns);
} }
bool SNetGetTurnsInTransit(DWORD *turns) bool SNetGetTurnsInTransit(uint32_t *turns)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<SdlMutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);

8
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); const std::uint64_t pos = SFileSetFilePointer(SFileRwGetHandle(context), offset, swhence);
if (pos == static_cast<std::uint64_t>(-1)) { if (pos == static_cast<std::uint64_t>(-1)) {
Log("SFileRwSeek error: {}", (unsigned int)SErrGetLastError()); Log("SFileRwSeek error: {}", SErrGetLastError());
} }
return pos; 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) static int SFileRwRead(struct SDL_RWops *context, void *ptr, int size, int maxnum)
#endif #endif
{ {
DWORD numRead = 0; size_t numRead = 0;
if (!SFileReadFileThreadSafe(SFileRwGetHandle(context), ptr, maxnum * size, &numRead)) { if (!SFileReadFileThreadSafe(SFileRwGetHandle(context), ptr, maxnum * size, &numRead)) {
const DWORD errCode = SErrGetLastError(); const auto errCode = SErrGetLastError();
if (errCode != STORM_ERROR_HANDLE_EOF) { 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; return numRead / size;

2
Source/storm/storm_svid.cpp

@ -156,7 +156,7 @@ bool SVidPlayBegin(const char *filename, int flags)
FILE *file = FILE_FromStormHandle(videoStream); FILE *file = FILE_FromStormHandle(videoStream);
SVidSMK = smk_open_filepointer(file, SMK_MODE_DISK); SVidSMK = smk_open_filepointer(file, SMK_MODE_DISK);
#else #else
int bytestoread = SFileGetFileSize(videoStream); size_t bytestoread = SFileGetFileSize(videoStream);
SVidBuffer = std::unique_ptr<uint8_t[]> { new uint8_t[bytestoread] }; SVidBuffer = std::unique_ptr<uint8_t[]> { new uint8_t[bytestoread] };
SFileReadFileThreadSafe(videoStream, SVidBuffer.get(), bytestoread); SFileReadFileThreadSafe(videoStream, SVidBuffer.get(), bytestoread);
SFileCloseFileThreadSafe(videoStream); SFileCloseFileThreadSafe(videoStream);

Loading…
Cancel
Save