Browse Source

Remove utils/stdcompat/cstddef.hpp

pull/6464/head
Gleb Mazovetskiy 3 years ago
parent
commit
74755c8be7
  1. 4
      CMakeLists.txt
  2. 25
      Source/codec.cpp
  3. 6
      Source/codec.h
  4. 8
      Source/encrypt.cpp
  5. 11
      Source/encrypt.h
  6. 2
      Source/engine.h
  7. 9
      Source/engine/load_file.hpp
  8. 2
      Source/levels/gendung.cpp
  9. 2
      Source/levels/gendung.h
  10. 6
      Source/loadsave.cpp
  11. 2
      Source/misdat.h
  12. 2
      Source/monster.cpp
  13. 2
      Source/monster.h
  14. 6
      Source/mpq/mpq_reader.cpp
  15. 3
      Source/mpq/mpq_reader.hpp
  16. 6
      Source/mpq/mpq_writer.cpp
  17. 6
      Source/mpq/mpq_writer.hpp
  18. 152
      Source/msg.cpp
  19. 4
      Source/msg.h
  20. 36
      Source/multi.cpp
  21. 8
      Source/multi.h
  22. 18
      Source/pfile.cpp
  23. 8
      Source/pfile.h
  24. 3
      Source/sha.h
  25. 2
      Source/sync.cpp
  26. 5
      Source/sync.h
  27. 10
      Source/tmsg.cpp
  28. 7
      Source/tmsg.h
  29. 4
      Source/towners.h
  30. 8
      Source/utils/language.cpp
  31. 2
      Source/utils/pcx_to_clx.cpp
  32. 4
      Source/utils/static_vector.hpp
  33. 7
      Source/utils/stdcompat/cstddef.hpp

4
CMakeLists.txt

@ -294,8 +294,8 @@ if(GPERF)
endif() endif()
# Despite setting C++ standard to 20, features from this version are not being used. # Despite setting C++ standard to 20, features from this version are not being used.
# The oldest compiler used is GCC 6.5 - and that defines our C++ feature set (meaning most of C++17). # DevilutionX is compatible with C++ 17.
# It's present only to take advantage of fmt::format build time errors. # Here we set it to 20 only to take advantage of the fmt::format build time errors.
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED OFF) set(CMAKE_CXX_STANDARD_REQUIRED OFF)

25
Source/codec.cpp

@ -7,7 +7,6 @@
#include "sha.h" #include "sha.h"
#include "utils/endian.hpp" #include "utils/endian.hpp"
#include "utils/log.hpp" #include "utils/log.hpp"
#include "utils/stdcompat/cstddef.hpp"
namespace devilution { namespace devilution {
namespace { namespace {
@ -53,7 +52,7 @@ SHA1Context CodecInitKey(const char *pszPassword)
return context; return context;
} }
CodecSignature GetCodecSignature(byte *src) CodecSignature GetCodecSignature(std::byte *src)
{ {
CodecSignature result; CodecSignature result;
result.checksum = LoadLE32(src); result.checksum = LoadLE32(src);
@ -63,16 +62,16 @@ CodecSignature GetCodecSignature(byte *src)
return result; return result;
} }
void SetCodecSignature(byte *dst, CodecSignature sig) void SetCodecSignature(std::byte *dst, CodecSignature sig)
{ {
*dst++ = static_cast<byte>(sig.checksum); *dst++ = static_cast<std::byte>(sig.checksum);
*dst++ = static_cast<byte>(sig.checksum >> 8); *dst++ = static_cast<std::byte>(sig.checksum >> 8);
*dst++ = static_cast<byte>(sig.checksum >> 16); *dst++ = static_cast<std::byte>(sig.checksum >> 16);
*dst++ = static_cast<byte>(sig.checksum >> 24); *dst++ = static_cast<std::byte>(sig.checksum >> 24);
*dst++ = static_cast<byte>(sig.error); *dst++ = static_cast<std::byte>(sig.error);
*dst++ = static_cast<byte>(sig.lastChunkSize); *dst++ = static_cast<std::byte>(sig.lastChunkSize);
*dst++ = static_cast<byte>(0); *dst++ = static_cast<std::byte>(0);
*dst++ = static_cast<byte>(0); *dst++ = static_cast<std::byte>(0);
} }
void ByteSwapBlock(uint32_t *data) void ByteSwapBlock(uint32_t *data)
@ -89,7 +88,7 @@ void XorBlock(const uint32_t *shaResult, uint32_t *out)
} // namespace } // namespace
std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPassword) std::size_t codec_decode(std::byte *pbSrcDst, std::size_t size, const char *pszPassword)
{ {
uint32_t buf[BlockSize]; uint32_t buf[BlockSize];
uint32_t dst[SHA1HashSize]; uint32_t dst[SHA1HashSize];
@ -134,7 +133,7 @@ std::size_t codec_get_encoded_len(std::size_t dwSrcBytes)
return dwSrcBytes + SignatureSize; return dwSrcBytes + SignatureSize;
} }
void codec_encode(byte *pbSrcDst, std::size_t size, std::size_t size64, const char *pszPassword) void codec_encode(std::byte *pbSrcDst, std::size_t size, std::size_t size64, const char *pszPassword)
{ {
uint32_t buf[BlockSize]; uint32_t buf[BlockSize];
uint32_t tmp[SHA1HashSize]; uint32_t tmp[SHA1HashSize];

6
Source/codec.h

@ -5,12 +5,12 @@
*/ */
#pragma once #pragma once
#include "utils/stdcompat/cstddef.hpp" #include <cstddef>
namespace devilution { namespace devilution {
std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPassword); std::size_t codec_decode(std::byte *pbSrcDst, std::size_t size, const char *pszPassword);
std::size_t codec_get_encoded_len(std::size_t dwSrcBytes); std::size_t codec_get_encoded_len(std::size_t dwSrcBytes);
void codec_encode(byte *pbSrcDst, std::size_t size, std::size_t size_64, const char *pszPassword); void codec_encode(std::byte *pbSrcDst, std::size_t size, std::size_t size_64, const char *pszPassword);
} // namespace devilution } // namespace devilution

8
Source/encrypt.cpp

@ -102,7 +102,7 @@ uint32_t Hash(const char *s, int type)
return seed1; return seed1;
} }
uint32_t PkwareCompress(byte *srcData, uint32_t size) uint32_t PkwareCompress(std::byte *srcData, uint32_t size)
{ {
std::unique_ptr<char[]> ptr = std::make_unique<char[]>(CMP_BUFFER_SIZE); std::unique_ptr<char[]> ptr = std::make_unique<char[]>(CMP_BUFFER_SIZE);
@ -110,7 +110,7 @@ uint32_t PkwareCompress(byte *srcData, uint32_t size)
if (destSize < 2 * 4096) if (destSize < 2 * 4096)
destSize = 2 * 4096; destSize = 2 * 4096;
std::unique_ptr<byte[]> destData { new byte[destSize] }; std::unique_ptr<std::byte[]> destData { new std::byte[destSize] };
TDataInfo param; TDataInfo param;
param.srcData = srcData; param.srcData = srcData;
@ -131,10 +131,10 @@ uint32_t PkwareCompress(byte *srcData, uint32_t size)
return size; return size;
} }
void PkwareDecompress(byte *inBuff, uint32_t recvSize, int maxBytes) void PkwareDecompress(std::byte *inBuff, uint32_t recvSize, int maxBytes)
{ {
std::unique_ptr<char[]> ptr = std::make_unique<char[]>(CMP_BUFFER_SIZE); std::unique_ptr<char[]> ptr = std::make_unique<char[]>(CMP_BUFFER_SIZE);
std::unique_ptr<byte[]> outBuff { new byte[maxBytes] }; std::unique_ptr<std::byte[]> outBuff { new std::byte[maxBytes] };
TDataInfo info; TDataInfo info;
info.srcData = inBuff; info.srcData = inBuff;

11
Source/encrypt.h

@ -5,16 +5,15 @@
*/ */
#pragma once #pragma once
#include <cstddef>
#include <cstdint> #include <cstdint>
#include "utils/stdcompat/cstddef.hpp"
namespace devilution { namespace devilution {
struct TDataInfo { struct TDataInfo {
byte *srcData; std::byte *srcData;
uint32_t srcOffset; uint32_t srcOffset;
byte *destData; std::byte *destData;
uint32_t destOffset; uint32_t destOffset;
uint32_t size; uint32_t size;
}; };
@ -22,7 +21,7 @@ struct TDataInfo {
void Decrypt(uint32_t *castBlock, uint32_t size, uint32_t key); void Decrypt(uint32_t *castBlock, uint32_t size, uint32_t key);
void Encrypt(uint32_t *castBlock, uint32_t size, uint32_t key); void Encrypt(uint32_t *castBlock, uint32_t size, uint32_t key);
uint32_t Hash(const char *s, int type); uint32_t Hash(const char *s, int type);
uint32_t PkwareCompress(byte *srcData, uint32_t size); uint32_t PkwareCompress(std::byte *srcData, uint32_t size);
void PkwareDecompress(byte *inBuff, uint32_t recvSize, int maxBytes); void PkwareDecompress(std::byte *inBuff, uint32_t recvSize, int maxBytes);
} // namespace devilution } // namespace devilution

2
Source/engine.h

@ -25,6 +25,7 @@
// defines for `PRIuMAX` et al. SDL transitively includes `inttypes.h`. // defines for `PRIuMAX` et al. SDL transitively includes `inttypes.h`.
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97044 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97044
#include <cinttypes> #include <cinttypes>
#include <cstddef>
#include <SDL.h> #include <SDL.h>
@ -36,7 +37,6 @@
#include "engine/point.hpp" #include "engine/point.hpp"
#include "engine/size.hpp" #include "engine/size.hpp"
#include "engine/surface.hpp" #include "engine/surface.hpp"
#include "utils/stdcompat/cstddef.hpp"
#define TILE_WIDTH 64 #define TILE_WIDTH 64
#define TILE_HEIGHT 32 #define TILE_HEIGHT 32

9
Source/engine/load_file.hpp

@ -13,7 +13,6 @@
#include "engine/assets.hpp" #include "engine/assets.hpp"
#include "mpq/mpq_common.hpp" #include "mpq/mpq_common.hpp"
#include "utils/static_vector.hpp" #include "utils/static_vector.hpp"
#include "utils/stdcompat/cstddef.hpp"
#include "utils/str_cat.hpp" #include "utils/str_cat.hpp"
namespace devilution { namespace devilution {
@ -58,7 +57,7 @@ void LoadFileInMem(const char *path, std::array<T, N> &data)
* @param numRead Number of T elements read * @param numRead Number of T elements read
* @return Buffer with content of file * @return Buffer with content of file
*/ */
template <typename T = byte> template <typename T = std::byte>
std::unique_ptr<T[]> LoadFileInMem(const char *path, std::size_t *numRead = nullptr) std::unique_ptr<T[]> LoadFileInMem(const char *path, std::size_t *numRead = nullptr)
{ {
size_t size; size_t size;
@ -95,10 +94,10 @@ struct MultiFileLoader {
* @param pathFn a function that returns the path for the given index * @param pathFn a function that returns the path for the given index
* @param outOffsets a buffer index for the start of each file will be written here, then the total file size at the end. * @param outOffsets a buffer index for the start of each file will be written here, then the total file size at the end.
* @param filterFn a function that returns whether to load a file for the given index * @param filterFn a function that returns whether to load a file for the given index
* @return std::unique_ptr<byte[]> the buffer with all the files * @return std::unique_ptr<std::byte[]> the buffer with all the files
*/ */
template <typename PathFn, typename FilterFn = DefaultFilterFn> template <typename PathFn, typename FilterFn = DefaultFilterFn>
[[nodiscard]] std::unique_ptr<byte[]> operator()(size_t numFiles, PathFn &&pathFn, uint32_t *outOffsets, [[nodiscard]] std::unique_ptr<std::byte[]> operator()(size_t numFiles, PathFn &&pathFn, uint32_t *outOffsets,
FilterFn filterFn = DefaultFilterFn {}) FilterFn filterFn = DefaultFilterFn {})
{ {
StaticVector<std::array<char, MaxMpqPathSize>, MaxFiles> paths; StaticVector<std::array<char, MaxMpqPathSize>, MaxFiles> paths;
@ -125,7 +124,7 @@ struct MultiFileLoader {
++j; ++j;
} }
outOffsets[files.size()] = totalSize; outOffsets[files.size()] = totalSize;
std::unique_ptr<byte[]> buf { new byte[totalSize] }; std::unique_ptr<std::byte[]> buf { new std::byte[totalSize] };
for (size_t i = 0, j = 0; i < numFiles; ++i) { for (size_t i = 0, j = 0; i < numFiles; ++i) {
if (!filterFn(i)) if (!filterFn(i))
continue; continue;

2
Source/levels/gendung.cpp

@ -25,7 +25,7 @@ WorldTileRectangle SetPiece;
std::unique_ptr<uint16_t[]> pSetPiece; std::unique_ptr<uint16_t[]> pSetPiece;
OptionalOwnedClxSpriteList pSpecialCels; OptionalOwnedClxSpriteList pSpecialCels;
std::unique_ptr<MegaTile[]> pMegaTiles; std::unique_ptr<MegaTile[]> pMegaTiles;
std::unique_ptr<byte[]> pDungeonCels; std::unique_ptr<std::byte[]> pDungeonCels;
std::array<TileProperties, MAXTILES> SOLData; std::array<TileProperties, MAXTILES> SOLData;
WorldTilePosition dminPosition; WorldTilePosition dminPosition;
WorldTilePosition dmaxPosition; WorldTilePosition dmaxPosition;

2
Source/levels/gendung.h

@ -163,7 +163,7 @@ extern std::unique_ptr<uint16_t[]> pSetPiece;
extern OptionalOwnedClxSpriteList pSpecialCels; extern OptionalOwnedClxSpriteList pSpecialCels;
/** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */ /** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */
extern DVL_API_FOR_TEST std::unique_ptr<MegaTile[]> pMegaTiles; extern DVL_API_FOR_TEST std::unique_ptr<MegaTile[]> pMegaTiles;
extern std::unique_ptr<byte[]> pDungeonCels; extern std::unique_ptr<std::byte[]> pDungeonCels;
/** /**
* List tile properties * List tile properties
*/ */

6
Source/loadsave.cpp

@ -81,7 +81,7 @@ T SwapBE(T in)
} }
class LoadHelper { class LoadHelper {
std::unique_ptr<byte[]> m_buffer_; std::unique_ptr<std::byte[]> m_buffer_;
size_t m_cur_ = 0; size_t m_cur_ = 0;
size_t m_size_; size_t m_size_;
@ -168,7 +168,7 @@ public:
class SaveHelper { class SaveHelper {
SaveWriter &m_mpqWriter; SaveWriter &m_mpqWriter;
const char *m_szFileName_; const char *m_szFileName_;
std::unique_ptr<byte[]> m_buffer_; std::unique_ptr<std::byte[]> m_buffer_;
size_t m_cur_ = 0; size_t m_cur_ = 0;
size_t m_capacity_; size_t m_capacity_;
@ -176,7 +176,7 @@ public:
SaveHelper(SaveWriter &mpqWriter, const char *szFileName, size_t bufferLen) SaveHelper(SaveWriter &mpqWriter, const char *szFileName, size_t bufferLen)
: m_mpqWriter(mpqWriter) : m_mpqWriter(mpqWriter)
, m_szFileName_(szFileName) , m_szFileName_(szFileName)
, m_buffer_(new byte[codec_get_encoded_len(bufferLen)]) , m_buffer_(new std::byte[codec_get_encoded_len(bufferLen)])
, m_capacity_(bufferLen) , m_capacity_(bufferLen)
{ {
} }

2
Source/misdat.h

@ -5,6 +5,7 @@
*/ */
#pragma once #pragma once
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
@ -14,7 +15,6 @@
#include "engine/clx_sprite.hpp" #include "engine/clx_sprite.hpp"
#include "spelldat.h" #include "spelldat.h"
#include "utils/enum_traits.h" #include "utils/enum_traits.h"
#include "utils/stdcompat/cstddef.hpp"
#include "utils/stdcompat/string_view.hpp" #include "utils/stdcompat/string_view.hpp"
namespace devilution { namespace devilution {

2
Source/monster.cpp

@ -3372,7 +3372,7 @@ void InitMonsterGFX(CMonster &monsterType)
} }
animOffsets[clxData.size()] = accumulatedSize; animOffsets[clxData.size()] = accumulatedSize;
monsterType.animData = nullptr; monsterType.animData = nullptr;
monsterType.animData = std::unique_ptr<byte[]>(new byte[accumulatedSize]); monsterType.animData = std::unique_ptr<std::byte[]>(new std::byte[accumulatedSize]);
for (size_t i = 0; i < clxData.size(); ++i) { for (size_t i = 0; i < clxData.size(); ++i) {
memcpy(&monsterType.animData[animOffsets[i]], clxData[i].data(), clxData[i].size()); memcpy(&monsterType.animData[animOffsets[i]], clxData[i].data(), clxData[i].size());
} }

2
Source/monster.h

@ -176,7 +176,7 @@ enum class MonsterSound : uint8_t {
}; };
struct CMonster { struct CMonster {
std::unique_ptr<byte[]> animData; std::unique_ptr<std::byte[]> animData;
AnimStruct anims[6]; AnimStruct anims[6];
std::unique_ptr<TSnd> sounds[4][2]; std::unique_ptr<TSnd> sounds[4][2];
const MonsterData *data; const MonsterData *data;

6
Source/mpq/mpq_reader.cpp

@ -62,9 +62,9 @@ bool MpqArchive::GetFileNumber(MpqArchive::FileHash fileHash, uint32_t &fileNumb
return libmpq__file_number_from_hash(archive_, fileHash[0], fileHash[1], fileHash[2], &fileNumber) == 0; return libmpq__file_number_from_hash(archive_, fileHash[0], fileHash[1], fileHash[2], &fileNumber) == 0;
} }
std::unique_ptr<byte[]> MpqArchive::ReadFile(const char *filename, std::size_t &fileSize, int32_t &error) std::unique_ptr<std::byte[]> MpqArchive::ReadFile(const char *filename, std::size_t &fileSize, int32_t &error)
{ {
std::unique_ptr<byte[]> result; std::unique_ptr<std::byte[]> result;
std::uint32_t fileNumber; std::uint32_t fileNumber;
error = libmpq__file_number(archive_, filename, &fileNumber); error = libmpq__file_number(archive_, filename, &fileNumber);
if (error != 0) if (error != 0)
@ -79,7 +79,7 @@ std::unique_ptr<byte[]> MpqArchive::ReadFile(const char *filename, std::size_t &
if (error != 0) if (error != 0)
return result; return result;
result = std::make_unique<byte[]>(unpackedSize); result = std::make_unique<std::byte[]>(unpackedSize);
const std::size_t blockSize = GetBlockSize(fileNumber, 0, error); const std::size_t blockSize = GetBlockSize(fileNumber, 0, error);
if (error != 0) if (error != 0)

3
Source/mpq/mpq_reader.hpp

@ -7,7 +7,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "utils/stdcompat/cstddef.hpp"
#include "utils/stdcompat/optional.hpp" #include "utils/stdcompat/optional.hpp"
// Forward-declare so that we can avoid exposing libmpq. // Forward-declare so that we can avoid exposing libmpq.
@ -43,7 +42,7 @@ public:
// Returns false if the file does not exit. // Returns false if the file does not exit.
bool GetFileNumber(FileHash fileHash, uint32_t &fileNumber); bool GetFileNumber(FileHash fileHash, uint32_t &fileNumber);
std::unique_ptr<byte[]> ReadFile(const char *filename, std::size_t &fileSize, int32_t &error); std::unique_ptr<std::byte[]> ReadFile(const char *filename, std::size_t &fileSize, int32_t &error);
// Returns error code. // Returns error code.
int32_t ReadBlock(uint32_t fileNumber, uint32_t blockNumber, uint8_t *out, uint32_t outSize); int32_t ReadBlock(uint32_t fileNumber, uint32_t blockNumber, uint8_t *out, uint32_t outSize);

6
Source/mpq/mpq_writer.cpp

@ -362,7 +362,7 @@ MpqBlockEntry *MpqWriter::AddFile(const char *filename, MpqBlockEntry *block, ui
return block; return block;
} }
bool MpqWriter::WriteFileContents(const char *filename, const byte *fileData, size_t fileSize, MpqBlockEntry *block) bool MpqWriter::WriteFileContents(const char *filename, const std::byte *fileData, size_t fileSize, MpqBlockEntry *block)
{ {
const char *tmp; const char *tmp;
while ((tmp = strchr(filename, ':')) != nullptr) while ((tmp = strchr(filename, ':')) != nullptr)
@ -408,7 +408,7 @@ bool MpqWriter::WriteFileContents(const char *filename, const byte *fileData, si
#endif #endif
uint32_t destSize = offsetTableByteSize; uint32_t destSize = offsetTableByteSize;
byte mpqBuf[BlockSize]; std::byte mpqBuf[BlockSize];
size_t curSector = 0; size_t curSector = 0;
while (true) { while (true) {
uint32_t len = std::min<uint32_t>(fileSize, BlockSize); uint32_t len = std::min<uint32_t>(fileSize, BlockSize);
@ -504,7 +504,7 @@ void MpqWriter::RemoveHashEntries(bool (*fnGetName)(uint8_t, char *))
} }
} }
bool MpqWriter::WriteFile(const char *filename, const byte *data, size_t size) bool MpqWriter::WriteFile(const char *filename, const std::byte *data, size_t size)
{ {
MpqBlockEntry *blockEntry; MpqBlockEntry *blockEntry;

6
Source/mpq/mpq_writer.hpp

@ -5,11 +5,11 @@
*/ */
#pragma once #pragma once
#include <cstddef>
#include <cstdint> #include <cstdint>
#include "mpq/mpq_common.hpp" #include "mpq/mpq_common.hpp"
#include "utils/logged_fstream.hpp" #include "utils/logged_fstream.hpp"
#include "utils/stdcompat/cstddef.hpp"
namespace devilution { namespace devilution {
class MpqWriter { class MpqWriter {
@ -27,7 +27,7 @@ public:
void RemoveHashEntry(const char *filename); void RemoveHashEntry(const char *filename);
void RemoveHashEntries(bool (*fnGetName)(uint8_t, char *)); void RemoveHashEntries(bool (*fnGetName)(uint8_t, char *));
bool WriteFile(const char *filename, const byte *data, size_t size); bool WriteFile(const char *filename, const std::byte *data, size_t size);
void RenameFile(const char *name, const char *newName); void RenameFile(const char *name, const char *newName);
private: private:
@ -37,7 +37,7 @@ private:
bool ReadMPQHeader(MpqFileHeader *hdr); bool ReadMPQHeader(MpqFileHeader *hdr);
MpqBlockEntry *AddFile(const char *filename, MpqBlockEntry *block, uint32_t blockIndex); MpqBlockEntry *AddFile(const char *filename, MpqBlockEntry *block, uint32_t blockIndex);
bool WriteFileContents(const char *filename, const byte *fileData, size_t fileSize, MpqBlockEntry *block); bool WriteFileContents(const char *filename, const std::byte *fileData, size_t fileSize, MpqBlockEntry *block);
// Returns an unused entry in the block entry table. // Returns an unused entry in the block entry table.
MpqBlockEntry *NewBlock(uint32_t *blockIndex = nullptr); MpqBlockEntry *NewBlock(uint32_t *blockIndex = nullptr);

152
Source/msg.cpp

@ -150,7 +150,7 @@ string_view CmdIdString(_cmd_id cmd)
struct TMegaPkt { struct TMegaPkt {
uint32_t spaceLeft; uint32_t spaceLeft;
byte data[32000]; std::byte data[32000];
TMegaPkt() TMegaPkt()
: spaceLeft(sizeof(data)) : spaceLeft(sizeof(data))
@ -220,7 +220,7 @@ uint8_t sbLastCmd;
/** /**
* @brief buffer used to receive level deltas, size is the worst expected case assuming every object on a level was touched * @brief buffer used to receive level deltas, size is the worst expected case assuming every object on a level was touched
*/ */
byte sgRecvBuf[1U + sizeof(DLevel::item) + sizeof(uint8_t) + (sizeof(WorldTilePosition) + sizeof(_cmd_id)) * MAXOBJECTS + sizeof(DLevel::monster)]; std::byte sgRecvBuf[1U + sizeof(DLevel::item) + sizeof(uint8_t) + (sizeof(WorldTilePosition) + sizeof(_cmd_id)) * MAXOBJECTS + sizeof(DLevel::monster)];
_cmd_id sgbRecvCmd; _cmd_id sgbRecvCmd;
std::unordered_map<uint8_t, LocalLevel> LocalLevels; std::unordered_map<uint8_t, LocalLevel> LocalLevels;
DJunk sgJunk; DJunk sgJunk;
@ -338,7 +338,7 @@ void PrePacket()
{ {
uint8_t playerId = std::numeric_limits<uint8_t>::max(); uint8_t playerId = std::numeric_limits<uint8_t>::max();
for (TMegaPkt &pkt : MegaPktList) { for (TMegaPkt &pkt : MegaPktList) {
byte *data = pkt.data; std::byte *data = pkt.data;
size_t spaceLeft = sizeof(pkt.data); size_t spaceLeft = sizeof(pkt.data);
while (spaceLeft != pkt.spaceLeft) { while (spaceLeft != pkt.spaceLeft) {
auto cmdId = static_cast<_cmd_id>(*data); auto cmdId = static_cast<_cmd_id>(*data);
@ -426,11 +426,11 @@ int WaitForTurns()
return 100 * sgbDeltaChunks / MAX_CHUNKS; return 100 * sgbDeltaChunks / MAX_CHUNKS;
} }
byte *DeltaExportItem(byte *dst, const TCmdPItem *src) std::byte *DeltaExportItem(std::byte *dst, const TCmdPItem *src)
{ {
for (int i = 0; i < MAXITEMS; i++, src++) { for (int i = 0; i < MAXITEMS; i++, src++) {
if (src->bCmd == CMD_INVALID) { if (src->bCmd == CMD_INVALID) {
*dst++ = byte { 0xFF }; *dst++ = std::byte { 0xFF };
} else { } else {
memcpy(dst, src, sizeof(TCmdPItem)); memcpy(dst, src, sizeof(TCmdPItem));
dst += sizeof(TCmdPItem); dst += sizeof(TCmdPItem);
@ -440,11 +440,11 @@ byte *DeltaExportItem(byte *dst, const TCmdPItem *src)
return dst; return dst;
} }
size_t DeltaImportItem(const byte *src, TCmdPItem *dst) size_t DeltaImportItem(const std::byte *src, TCmdPItem *dst)
{ {
size_t size = 0; size_t size = 0;
for (int i = 0; i < MAXITEMS; i++, dst++) { for (int i = 0; i < MAXITEMS; i++, dst++) {
if (src[size] == byte { 0xFF }) { if (src[size] == std::byte { 0xFF }) {
memset(dst, 0xFF, sizeof(TCmdPItem)); memset(dst, 0xFF, sizeof(TCmdPItem));
size++; size++;
} else { } else {
@ -456,19 +456,19 @@ size_t DeltaImportItem(const byte *src, TCmdPItem *dst)
return size; return size;
} }
byte *DeltaExportObject(byte *dst, const std::unordered_map<WorldTilePosition, DObjectStr> &src) std::byte *DeltaExportObject(std::byte *dst, const std::unordered_map<WorldTilePosition, DObjectStr> &src)
{ {
*dst++ = static_cast<byte>(src.size()); *dst++ = static_cast<std::byte>(src.size());
for (auto &pair : src) { for (auto &pair : src) {
*dst++ = static_cast<byte>(pair.first.x); *dst++ = static_cast<std::byte>(pair.first.x);
*dst++ = static_cast<byte>(pair.first.y); *dst++ = static_cast<std::byte>(pair.first.y);
*dst++ = static_cast<byte>(pair.second.bCmd); *dst++ = static_cast<std::byte>(pair.second.bCmd);
} }
return dst; return dst;
} }
const byte *DeltaImportObjects(const byte *src, std::unordered_map<WorldTilePosition, DObjectStr> &dst) const std::byte *DeltaImportObjects(const std::byte *src, std::unordered_map<WorldTilePosition, DObjectStr> &dst)
{ {
dst.clear(); dst.clear();
@ -484,11 +484,11 @@ const byte *DeltaImportObjects(const byte *src, std::unordered_map<WorldTilePosi
return src; return src;
} }
byte *DeltaExportMonster(byte *dst, const DMonsterStr *src) std::byte *DeltaExportMonster(std::byte *dst, const DMonsterStr *src)
{ {
for (size_t i = 0; i < MaxMonsters; i++, src++) { for (size_t i = 0; i < MaxMonsters; i++, src++) {
if (src->position.x == 0xFF) { if (src->position.x == 0xFF) {
*dst++ = byte { 0xFF }; *dst++ = std::byte { 0xFF };
} else { } else {
memcpy(dst, src, sizeof(DMonsterStr)); memcpy(dst, src, sizeof(DMonsterStr));
dst += sizeof(DMonsterStr); dst += sizeof(DMonsterStr);
@ -498,11 +498,11 @@ byte *DeltaExportMonster(byte *dst, const DMonsterStr *src)
return dst; return dst;
} }
void DeltaImportMonster(const byte *src, DMonsterStr *dst) void DeltaImportMonster(const std::byte *src, DMonsterStr *dst)
{ {
size_t size = 0; size_t size = 0;
for (size_t i = 0; i < MaxMonsters; i++, dst++) { for (size_t i = 0; i < MaxMonsters; i++, dst++) {
if (src[size] == byte { 0xFF }) { if (src[size] == std::byte { 0xFF }) {
memset(dst, 0xFF, sizeof(DMonsterStr)); memset(dst, 0xFF, sizeof(DMonsterStr));
size++; size++;
} else { } else {
@ -512,11 +512,11 @@ void DeltaImportMonster(const byte *src, DMonsterStr *dst)
} }
} }
byte *DeltaExportJunk(byte *dst) std::byte *DeltaExportJunk(std::byte *dst)
{ {
for (auto &portal : sgJunk.portal) { for (auto &portal : sgJunk.portal) {
if (portal.x == 0xFF) { if (portal.x == 0xFF) {
*dst++ = byte { 0xFF }; *dst++ = std::byte { 0xFF };
} else { } else {
memcpy(dst, &portal, sizeof(DPortal)); memcpy(dst, &portal, sizeof(DPortal));
dst += sizeof(DPortal); dst += sizeof(DPortal);
@ -541,10 +541,10 @@ byte *DeltaExportJunk(byte *dst)
return dst; return dst;
} }
void DeltaImportJunk(const byte *src) void DeltaImportJunk(const std::byte *src)
{ {
for (int i = 0; i < MAXPORTAL; i++) { for (int i = 0; i < MAXPORTAL; i++) {
if (*src == byte { 0xFF }) { if (*src == std::byte { 0xFF }) {
memset(&sgJunk.portal[i], 0xFF, sizeof(DPortal)); memset(&sgJunk.portal[i], 0xFF, sizeof(DPortal));
src++; src++;
} else { } else {
@ -564,17 +564,17 @@ void DeltaImportJunk(const byte *src)
} }
} }
uint32_t CompressData(byte *buffer, byte *end) uint32_t CompressData(std::byte *buffer, std::byte *end)
{ {
#ifdef USE_PKWARE #ifdef USE_PKWARE
const auto size = static_cast<uint32_t>(end - buffer - 1); const auto size = static_cast<uint32_t>(end - buffer - 1);
const uint32_t pkSize = PkwareCompress(buffer + 1, size); const uint32_t pkSize = PkwareCompress(buffer + 1, size);
*buffer = size != pkSize ? byte { 1 } : byte { 0 }; *buffer = size != pkSize ? std::byte { 1 } : std::byte { 0 };
return pkSize + 1; return pkSize + 1;
#else #else
*buffer = byte { 0 }; *buffer = std::byte { 0 };
return end - buffer; return end - buffer;
#endif #endif
} }
@ -582,11 +582,11 @@ uint32_t CompressData(byte *buffer, byte *end)
void DeltaImportData(_cmd_id cmd, uint32_t recvOffset) void DeltaImportData(_cmd_id cmd, uint32_t recvOffset)
{ {
#ifdef USE_PKWARE #ifdef USE_PKWARE
if (sgRecvBuf[0] != byte { 0 }) if (sgRecvBuf[0] != std::byte { 0 })
PkwareDecompress(&sgRecvBuf[1], recvOffset, sizeof(sgRecvBuf) - 1); PkwareDecompress(&sgRecvBuf[1], recvOffset, sizeof(sgRecvBuf) - 1);
#endif #endif
const byte *src = &sgRecvBuf[1]; const std::byte *src = &sgRecvBuf[1];
if (cmd == CMD_DLEVEL_JUNK) { if (cmd == CMD_DLEVEL_JUNK) {
DeltaImportJunk(src); DeltaImportJunk(src);
} else if (cmd == CMD_DLEVEL) { } else if (cmd == CMD_DLEVEL) {
@ -823,7 +823,7 @@ void NetSendCmdGItem2(bool usonly, _cmd_id bCmd, uint8_t mast, uint8_t pnum, con
if (!usonly) { if (!usonly) {
cmd.dwTime = 0; cmd.dwTime = 0;
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
return; return;
} }
@ -834,7 +834,7 @@ void NetSendCmdGItem2(bool usonly, _cmd_id bCmd, uint8_t mast, uint8_t pnum, con
return; return;
} }
tmsg_add((byte *)&cmd, sizeof(cmd)); tmsg_add((std::byte *)&cmd, sizeof(cmd));
} }
bool NetSendCmdReq2(_cmd_id bCmd, uint8_t mast, uint8_t pnum, const TCmdGItem &item) bool NetSendCmdReq2(_cmd_id bCmd, uint8_t mast, uint8_t pnum, const TCmdGItem &item)
@ -852,7 +852,7 @@ bool NetSendCmdReq2(_cmd_id bCmd, uint8_t mast, uint8_t pnum, const TCmdGItem &i
else if (ticks - SDL_SwapLE32(cmd.dwTime) > 5000) else if (ticks - SDL_SwapLE32(cmd.dwTime) > 5000)
return false; return false;
tmsg_add((byte *)&cmd, sizeof(cmd)); tmsg_add((std::byte *)&cmd, sizeof(cmd));
return true; return true;
} }
@ -864,7 +864,7 @@ void NetSendCmdExtra(const TCmdGItem &item)
memcpy(&cmd, &item, sizeof(cmd)); memcpy(&cmd, &item, sizeof(cmd));
cmd.dwTime = 0; cmd.dwTime = 0;
cmd.bCmd = CMD_ITEMEXTRA; cmd.bCmd = CMD_ITEMEXTRA;
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
size_t OnWalk(const TCmd *pCmd, Player &player) size_t OnWalk(const TCmd *pCmd, Player &player)
@ -2428,10 +2428,10 @@ void DeltaExportData(int pnum)
+ sizeof(uint8_t) /* count of object interactions which caused a state change since dungeon generation */ + sizeof(uint8_t) /* count of object interactions which caused a state change since dungeon generation */
+ (sizeof(WorldTilePosition) + sizeof(DObjectStr)) * deltaLevel.object.size() /* location/action pairs for the object interactions */ + (sizeof(WorldTilePosition) + sizeof(DObjectStr)) * deltaLevel.object.size() /* location/action pairs for the object interactions */
+ sizeof(deltaLevel.monster); /* latest monster state */ + sizeof(deltaLevel.monster); /* latest monster state */
std::unique_ptr<byte[]> dst { new byte[bufferSize] }; std::unique_ptr<std::byte[]> dst { new std::byte[bufferSize] };
byte *dstEnd = &dst.get()[1]; std::byte *dstEnd = &dst.get()[1];
*dstEnd = static_cast<byte>(it.first); *dstEnd = static_cast<std::byte>(it.first);
dstEnd += sizeof(uint8_t); dstEnd += sizeof(uint8_t);
dstEnd = DeltaExportItem(dstEnd, deltaLevel.item); dstEnd = DeltaExportItem(dstEnd, deltaLevel.item);
dstEnd = DeltaExportObject(dstEnd, deltaLevel.object); dstEnd = DeltaExportObject(dstEnd, deltaLevel.object);
@ -2440,13 +2440,13 @@ void DeltaExportData(int pnum)
multi_send_zero_packet(pnum, CMD_DLEVEL, dst.get(), size); multi_send_zero_packet(pnum, CMD_DLEVEL, dst.get(), size);
} }
byte dst[sizeof(DJunk) + 1]; std::byte dst[sizeof(DJunk) + 1];
byte *dstEnd = &dst[1]; std::byte *dstEnd = &dst[1];
dstEnd = DeltaExportJunk(dstEnd); dstEnd = DeltaExportJunk(dstEnd);
uint32_t size = CompressData(dst, dstEnd); uint32_t size = CompressData(dst, dstEnd);
multi_send_zero_packet(pnum, CMD_DLEVEL_JUNK, dst, size); multi_send_zero_packet(pnum, CMD_DLEVEL_JUNK, dst, size);
byte src[1] = { static_cast<byte>(0) }; std::byte src[1] = { static_cast<std::byte>(0) };
multi_send_zero_packet(pnum, CMD_DLEVEL_END, src, 1); multi_send_zero_packet(pnum, CMD_DLEVEL_END, src, 1);
} }
@ -2730,9 +2730,9 @@ void NetSendCmd(bool bHiPri, _cmd_id bCmd)
cmd.bCmd = bCmd; cmd.bCmd = bCmd;
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdGolem(uint8_t mx, uint8_t my, Direction dir, uint8_t menemy, int hp, uint8_t cl) void NetSendCmdGolem(uint8_t mx, uint8_t my, Direction dir, uint8_t menemy, int hp, uint8_t cl)
@ -2746,7 +2746,7 @@ void NetSendCmdGolem(uint8_t mx, uint8_t my, Direction dir, uint8_t menemy, int
cmd._menemy = menemy; cmd._menemy = menemy;
cmd._mhitpoints = hp; cmd._mhitpoints = hp;
cmd._currlevel = cl; cmd._currlevel = cl;
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdLoc(size_t playerId, bool bHiPri, _cmd_id bCmd, Point position) void NetSendCmdLoc(size_t playerId, bool bHiPri, _cmd_id bCmd, Point position)
@ -2760,9 +2760,9 @@ void NetSendCmdLoc(size_t playerId, bool bHiPri, _cmd_id bCmd, Point position)
cmd.x = position.x; cmd.x = position.x;
cmd.y = position.y; cmd.y = position.y;
if (bHiPri) if (bHiPri)
NetSendHiPri(playerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(playerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(playerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(playerId, (std::byte *)&cmd, sizeof(cmd));
MyPlayer->UpdatePreviewCelSprite(bCmd, position, 0, 0); MyPlayer->UpdatePreviewCelSprite(bCmd, position, 0, 0);
} }
@ -2779,9 +2779,9 @@ void NetSendCmdLocParam1(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
cmd.y = position.y; cmd.y = position.y;
cmd.wParam1 = SDL_SwapLE16(wParam1); cmd.wParam1 = SDL_SwapLE16(wParam1);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, 0); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, 0);
} }
@ -2799,9 +2799,9 @@ void NetSendCmdLocParam2(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
cmd.wParam1 = SDL_SwapLE16(wParam1); cmd.wParam1 = SDL_SwapLE16(wParam1);
cmd.wParam2 = SDL_SwapLE16(wParam2); cmd.wParam2 = SDL_SwapLE16(wParam2);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2);
} }
@ -2820,9 +2820,9 @@ void NetSendCmdLocParam3(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
cmd.wParam2 = SDL_SwapLE16(wParam2); cmd.wParam2 = SDL_SwapLE16(wParam2);
cmd.wParam3 = SDL_SwapLE16(wParam3); cmd.wParam3 = SDL_SwapLE16(wParam3);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2);
} }
@ -2842,9 +2842,9 @@ void NetSendCmdLocParam4(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
cmd.wParam3 = SDL_SwapLE16(wParam3); cmd.wParam3 = SDL_SwapLE16(wParam3);
cmd.wParam4 = SDL_SwapLE16(wParam4); cmd.wParam4 = SDL_SwapLE16(wParam4);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3);
} }
@ -2865,9 +2865,9 @@ void NetSendCmdLocParam5(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
cmd.wParam4 = SDL_SwapLE16(wParam4); cmd.wParam4 = SDL_SwapLE16(wParam4);
cmd.wParam5 = SDL_SwapLE16(wParam5); cmd.wParam5 = SDL_SwapLE16(wParam5);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3);
} }
@ -2882,9 +2882,9 @@ void NetSendCmdParam1(bool bHiPri, _cmd_id bCmd, uint16_t wParam1)
cmd.bCmd = bCmd; cmd.bCmd = bCmd;
cmd.wParam1 = SDL_SwapLE16(wParam1); cmd.wParam1 = SDL_SwapLE16(wParam1);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, 0); MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, 0);
} }
@ -2897,9 +2897,9 @@ void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar
cmd.wParam1 = SDL_SwapLE16(wParam1); cmd.wParam1 = SDL_SwapLE16(wParam1);
cmd.wParam2 = SDL_SwapLE16(wParam2); cmd.wParam2 = SDL_SwapLE16(wParam2);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdParam5(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4, uint16_t wParam5) void NetSendCmdParam5(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4, uint16_t wParam5)
@ -2916,9 +2916,9 @@ void NetSendCmdParam5(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar
cmd.wParam4 = SDL_SwapLE16(wParam4); cmd.wParam4 = SDL_SwapLE16(wParam4);
cmd.wParam5 = SDL_SwapLE16(wParam5); cmd.wParam5 = SDL_SwapLE16(wParam5);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, wParam2); MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, wParam2);
} }
@ -2935,9 +2935,9 @@ void NetSendCmdQuest(bool bHiPri, const Quest &quest)
cmd.qmsg = quest._qmsg; cmd.qmsg = quest._qmsg;
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t pnum, uint8_t ii) void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t pnum, uint8_t ii)
@ -2955,9 +2955,9 @@ void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t pnum, uint8_t ii)
PrepareItemForNetwork(Items[ii], cmd); PrepareItemForNetwork(Items[ii], cmd);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item) void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item)
@ -2972,9 +2972,9 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item
ItemLimbo = item; ItemLimbo = item;
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdChItem(bool bHiPri, uint8_t bLoc, bool forceSpellChange) void NetSendCmdChItem(bool bHiPri, uint8_t bLoc, bool forceSpellChange)
@ -2989,9 +2989,9 @@ void NetSendCmdChItem(bool bHiPri, uint8_t bLoc, bool forceSpellChange)
PrepareItemForNetwork(item, cmd); PrepareItemForNetwork(item, cmd);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc) void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc)
@ -3001,9 +3001,9 @@ void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc)
cmd.bLoc = bLoc; cmd.bLoc = bLoc;
cmd.bCmd = CMD_DELPLRITEMS; cmd.bCmd = CMD_DELPLRITEMS;
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSyncInvItem(const Player &player, int invListIndex) void NetSyncInvItem(const Player &player, int invListIndex)
@ -3031,9 +3031,9 @@ void NetSendCmdChInvItem(bool bHiPri, int invGridIndex)
PrepareItemForNetwork(item, cmd); PrepareItemForNetwork(item, cmd);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdChBeltItem(bool bHiPri, int beltIndex) void NetSendCmdChBeltItem(bool bHiPri, int beltIndex)
@ -3047,9 +3047,9 @@ void NetSendCmdChBeltItem(bool bHiPri, int beltIndex)
PrepareItemForNetwork(item, cmd); PrepareItemForNetwork(item, cmd);
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam, DamageType damageType) void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam, DamageType damageType)
@ -3061,9 +3061,9 @@ void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam, DamageType dama
cmd.dwDam = dwDam; cmd.dwDam = dwDam;
cmd.damageType = damageType; cmd.damageType = damageType;
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam) void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam)
@ -3074,9 +3074,9 @@ void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam)
cmd.wMon = wMon; cmd.wMon = wMon;
cmd.dwDam = dwDam; cmd.dwDam = dwDam;
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
else else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
} }
void NetSendCmdString(uint32_t pmask, const char *pszStr) void NetSendCmdString(uint32_t pmask, const char *pszStr)
@ -3085,7 +3085,7 @@ void NetSendCmdString(uint32_t pmask, const char *pszStr)
cmd.bCmd = CMD_STRING; cmd.bCmd = CMD_STRING;
CopyUtf8(cmd.str, pszStr, sizeof(cmd.str)); CopyUtf8(cmd.str, pszStr, sizeof(cmd.str));
multi_send_msg_packet(pmask, (byte *)&cmd, strlen(cmd.str) + 2); multi_send_msg_packet(pmask, (std::byte *)&cmd, strlen(cmd.str) + 2);
} }
void delta_close_portal(int pnum) void delta_close_portal(int pnum)

4
Source/msg.h

@ -708,13 +708,13 @@ struct TPktHdr {
struct TPkt { struct TPkt {
TPktHdr hdr; TPktHdr hdr;
byte body[493]; std::byte body[493];
}; };
#pragma pack(pop) #pragma pack(pop)
struct TBuffer { struct TBuffer {
uint32_t dwNextWriteOffset; uint32_t dwNextWriteOffset;
byte bData[4096]; std::byte bData[4096];
}; };
extern uint8_t gbBufferMsgs; extern uint8_t gbBufferMsgs;

36
Source/multi.cpp

@ -4,6 +4,7 @@
* Implementation of functions for keeping multiplaye games in sync. * Implementation of functions for keeping multiplaye games in sync.
*/ */
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <ctime> #include <ctime>
@ -28,7 +29,6 @@
#include "tmsg.h" #include "tmsg.h"
#include "utils/endian.hpp" #include "utils/endian.hpp"
#include "utils/language.h" #include "utils/language.h"
#include "utils/stdcompat/cstddef.hpp"
#include "utils/stdcompat/string_view.hpp" #include "utils/stdcompat/string_view.hpp"
#include "utils/str_cat.hpp" #include "utils/str_cat.hpp"
@ -88,27 +88,27 @@ uint32_t sgbSentThisCycle;
void BufferInit(TBuffer *pBuf) void BufferInit(TBuffer *pBuf)
{ {
pBuf->dwNextWriteOffset = 0; pBuf->dwNextWriteOffset = 0;
pBuf->bData[0] = byte { 0 }; pBuf->bData[0] = std::byte { 0 };
} }
void CopyPacket(TBuffer *buf, const byte *packet, size_t size) void CopyPacket(TBuffer *buf, const std::byte *packet, size_t size)
{ {
if (buf->dwNextWriteOffset + size + 2 > 0x1000) { if (buf->dwNextWriteOffset + size + 2 > 0x1000) {
return; return;
} }
byte *p = &buf->bData[buf->dwNextWriteOffset]; std::byte *p = &buf->bData[buf->dwNextWriteOffset];
buf->dwNextWriteOffset += size + 1; buf->dwNextWriteOffset += size + 1;
*p = static_cast<byte>(size); *p = static_cast<std::byte>(size);
p++; p++;
memcpy(p, packet, size); memcpy(p, packet, size);
p[size] = byte { 0 }; p[size] = std::byte { 0 };
} }
byte *CopyBufferedPackets(byte *destination, TBuffer *source, size_t *size) std::byte *CopyBufferedPackets(std::byte *destination, TBuffer *source, size_t *size)
{ {
if (source->dwNextWriteOffset != 0) { if (source->dwNextWriteOffset != 0) {
byte *srcPtr = source->bData; std::byte *srcPtr = source->bData;
while (true) { while (true) {
auto chunkSize = static_cast<uint8_t>(*srcPtr); auto chunkSize = static_cast<uint8_t>(*srcPtr);
if (chunkSize == 0) if (chunkSize == 0)
@ -192,7 +192,7 @@ void CheckPlayerInfoTimeouts()
} }
} }
void SendPacket(int playerId, const byte *packet, size_t size) void SendPacket(int playerId, const std::byte *packet, size_t size)
{ {
TPkt pkt; TPkt pkt;
@ -324,7 +324,7 @@ void BeginTimeout()
CheckDropPlayer(); CheckDropPlayer();
} }
void HandleAllPackets(size_t pnum, const byte *data, size_t size) void HandleAllPackets(size_t pnum, const std::byte *data, size_t size)
{ {
for (unsigned offset = 0; offset < size;) { for (unsigned offset = 0; offset < size;) {
size_t messageSize = ParseCmd(pnum, reinterpret_cast<const TCmd *>(&data[offset])); size_t messageSize = ParseCmd(pnum, reinterpret_cast<const TCmd *>(&data[offset]));
@ -338,7 +338,7 @@ void HandleAllPackets(size_t pnum, const byte *data, size_t size)
void ProcessTmsgs() void ProcessTmsgs()
{ {
while (true) { while (true) {
std::unique_ptr<byte[]> msg; std::unique_ptr<std::byte[]> msg;
uint8_t size = tmsg_get(&msg); uint8_t size = tmsg_get(&msg);
if (size == 0) if (size == 0)
break; break;
@ -352,7 +352,7 @@ void SendPlayerInfo(int pnum, _cmd_id cmd)
PlayerNetPack packed; PlayerNetPack packed;
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
PackNetPlayer(packed, myPlayer); PackNetPlayer(packed, myPlayer);
multi_send_zero_packet(pnum, cmd, reinterpret_cast<byte *>(&packed), sizeof(PlayerNetPack)); multi_send_zero_packet(pnum, cmd, reinterpret_cast<std::byte *>(&packed), sizeof(PlayerNetPack));
} }
void SetupLocalPositions() void SetupLocalPositions()
@ -495,7 +495,7 @@ void InitGameInfo()
sgGameInitInfo.fullQuests = (!gbIsMultiplayer || *sgOptions.Gameplay.multiplayerFullQuests) ? 1 : 0; sgGameInitInfo.fullQuests = (!gbIsMultiplayer || *sgOptions.Gameplay.multiplayerFullQuests) ? 1 : 0;
} }
void NetSendLoPri(int playerId, const byte *data, size_t size) void NetSendLoPri(int playerId, const std::byte *data, size_t size)
{ {
if (data != nullptr && size != 0) { if (data != nullptr && size != 0) {
CopyPacket(&lowPriorityBuffer, data, size); CopyPacket(&lowPriorityBuffer, data, size);
@ -503,7 +503,7 @@ void NetSendLoPri(int playerId, const byte *data, size_t size)
} }
} }
void NetSendHiPri(int playerId, const byte *data, size_t size) void NetSendHiPri(int playerId, const std::byte *data, size_t size)
{ {
if (data != nullptr && size != 0) { if (data != nullptr && size != 0) {
CopyPacket(&highPriorityBuffer, data, size); CopyPacket(&highPriorityBuffer, data, size);
@ -513,7 +513,7 @@ void NetSendHiPri(int playerId, const byte *data, size_t size)
shareNextHighPriorityMessage = false; shareNextHighPriorityMessage = false;
TPkt pkt; TPkt pkt;
NetReceivePlayerData(&pkt); NetReceivePlayerData(&pkt);
byte *destination = pkt.body; std::byte *destination = pkt.body;
size_t remainingSpace = gdwNormalMsgSize - sizeof(TPktHdr); size_t remainingSpace = gdwNormalMsgSize - sizeof(TPktHdr);
destination = CopyBufferedPackets(destination, &highPriorityBuffer, &remainingSpace); destination = CopyBufferedPackets(destination, &highPriorityBuffer, &remainingSpace);
destination = CopyBufferedPackets(destination, &lowPriorityBuffer, &remainingSpace); destination = CopyBufferedPackets(destination, &lowPriorityBuffer, &remainingSpace);
@ -525,7 +525,7 @@ void NetSendHiPri(int playerId, const byte *data, size_t size)
} }
} }
void multi_send_msg_packet(uint32_t pmask, const byte *data, size_t size) void multi_send_msg_packet(uint32_t pmask, const std::byte *data, size_t size)
{ {
TPkt pkt; TPkt pkt;
NetReceivePlayerData(&pkt); NetReceivePlayerData(&pkt);
@ -676,14 +676,14 @@ void multi_process_network_packets()
} }
} }
} }
HandleAllPackets(playerId, (const byte *)(pkt + 1), dwMsgSize - sizeof(TPktHdr)); HandleAllPackets(playerId, (const std::byte *)(pkt + 1), dwMsgSize - sizeof(TPktHdr));
} }
if (SErrGetLastError() != STORM_ERROR_NO_MESSAGES_WAITING) if (SErrGetLastError() != STORM_ERROR_NO_MESSAGES_WAITING)
nthread_terminate_game("SNetReceiveMsg"); nthread_terminate_game("SNetReceiveMsg");
CheckPlayerInfoTimeouts(); CheckPlayerInfoTimeouts();
} }
void multi_send_zero_packet(size_t pnum, _cmd_id bCmd, const byte *data, size_t size) void multi_send_zero_packet(size_t pnum, _cmd_id bCmd, const std::byte *data, size_t size)
{ {
assert(pnum != MyPlayerId); assert(pnum != MyPlayerId);
assert(data != nullptr); assert(data != nullptr);

8
Source/multi.h

@ -56,9 +56,9 @@ extern uint32_t player_state[MAX_PLRS];
extern bool IsLoopback; extern bool IsLoopback;
void InitGameInfo(); void InitGameInfo();
void NetSendLoPri(int playerId, const byte *data, size_t size); void NetSendLoPri(int playerId, const std::byte *data, size_t size);
void NetSendHiPri(int playerId, const byte *data, size_t size); void NetSendHiPri(int playerId, const std::byte *data, size_t size);
void multi_send_msg_packet(uint32_t pmask, const byte *data, size_t size); void multi_send_msg_packet(uint32_t pmask, const std::byte *data, size_t size);
void multi_msg_countdown(); void multi_msg_countdown();
void multi_player_left(int pnum, int reason); void multi_player_left(int pnum, int reason);
void multi_net_ping(); void multi_net_ping();
@ -68,7 +68,7 @@ void multi_net_ping();
*/ */
bool multi_handle_delta(); bool multi_handle_delta();
void multi_process_network_packets(); void multi_process_network_packets();
void multi_send_zero_packet(size_t pnum, _cmd_id bCmd, const byte *data, size_t size); void multi_send_zero_packet(size_t pnum, _cmd_id bCmd, const std::byte *data, size_t size);
void NetClose(); void NetClose();
bool NetInit(bool bSinglePlayer); bool NetInit(bool bSinglePlayer);
void recv_plrinfo(int pnum, const TCmdPlrInfoHdr &header, bool recv); void recv_plrinfo(int pnum, const TCmdPlrInfoHdr &header, bool recv);

18
Source/pfile.cpp

@ -144,7 +144,7 @@ bool ReadHero(SaveReader &archive, PlayerPack *pPack)
void EncodeHero(SaveWriter &saveWriter, const PlayerPack *pack) void EncodeHero(SaveWriter &saveWriter, const PlayerPack *pack)
{ {
size_t packedLen = codec_get_encoded_len(sizeof(*pack)); size_t packedLen = codec_get_encoded_len(sizeof(*pack));
std::unique_ptr<byte[]> packed { new byte[packedLen] }; std::unique_ptr<std::byte[]> packed { new std::byte[packedLen] };
memcpy(packed.get(), pack, sizeof(*pack)); memcpy(packed.get(), pack, sizeof(*pack));
codec_encode(packed.get(), sizeof(*pack), packedLen, pfile_get_password()); codec_encode(packed.get(), sizeof(*pack), packedLen, pfile_get_password());
@ -233,7 +233,7 @@ std::optional<SaveReader> CreateSaveReader(std::string &&path)
#ifndef DISABLE_DEMOMODE #ifndef DISABLE_DEMOMODE
struct CompareInfo { struct CompareInfo {
std::unique_ptr<byte[]> &data; std::unique_ptr<std::byte[]> &data;
size_t currentPosition; size_t currentPosition;
size_t size; size_t size;
bool isTownLevel; bool isTownLevel;
@ -275,7 +275,7 @@ void CreateDetailDiffs(string_view prefix, string_view memoryMapFile, CompareInf
} }
size_t readBytes = SDL_RWsize(handle); size_t readBytes = SDL_RWsize(handle);
std::unique_ptr<byte[]> memoryMapFileData { new byte[readBytes] }; std::unique_ptr<std::byte[]> memoryMapFileData { new std::byte[readBytes] };
SDL_RWread(handle, memoryMapFileData.get(), readBytes, 1); SDL_RWread(handle, memoryMapFileData.get(), readBytes, 1);
const string_view buffer(reinterpret_cast<const char *>(memoryMapFileData.get()), readBytes); const string_view buffer(reinterpret_cast<const char *>(memoryMapFileData.get()), readBytes);
@ -502,9 +502,9 @@ void pfile_write_hero(SaveWriter &saveWriter, bool writeGameData)
} // namespace } // namespace
#ifdef UNPACKED_SAVES #ifdef UNPACKED_SAVES
std::unique_ptr<byte[]> SaveReader::ReadFile(const char *filename, std::size_t &fileSize, int32_t &error) std::unique_ptr<std::byte[]> SaveReader::ReadFile(const char *filename, std::size_t &fileSize, int32_t &error)
{ {
std::unique_ptr<byte[]> result; std::unique_ptr<std::byte[]> result;
error = 0; error = 0;
const std::string path = dir_ + filename; const std::string path = dir_ + filename;
uintmax_t size; uintmax_t size;
@ -518,7 +518,7 @@ std::unique_ptr<byte[]> SaveReader::ReadFile(const char *filename, std::size_t &
error = 1; error = 1;
return nullptr; return nullptr;
} }
result.reset(new byte[size]); result.reset(new std::byte[size]);
if (std::fread(result.get(), size, 1, file) != 1) { if (std::fread(result.get(), size, 1, file) != 1) {
std::fclose(file); std::fclose(file);
error = 1; error = 1;
@ -528,7 +528,7 @@ std::unique_ptr<byte[]> SaveReader::ReadFile(const char *filename, std::size_t &
return result; return result;
} }
bool SaveWriter::WriteFile(const char *filename, const byte *data, size_t size) bool SaveWriter::WriteFile(const char *filename, const std::byte *data, size_t size)
{ {
const std::string path = dir_ + filename; const std::string path = dir_ + filename;
FILE *file = OpenFile(path.c_str(), "wb"); FILE *file = OpenFile(path.c_str(), "wb");
@ -563,12 +563,12 @@ std::optional<SaveReader> OpenStashArchive()
return CreateSaveReader(GetStashSavePath()); return CreateSaveReader(GetStashSavePath());
} }
std::unique_ptr<byte[]> ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen) std::unique_ptr<std::byte[]> ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen)
{ {
int32_t error; int32_t error;
std::size_t length; std::size_t length;
std::unique_ptr<byte[]> result = archive.ReadFile(pszName, length, error); std::unique_ptr<std::byte[]> result = archive.ReadFile(pszName, length, error);
if (error != 0) if (error != 0)
return nullptr; return nullptr;

8
Source/pfile.h

@ -35,7 +35,7 @@ struct SaveReader {
return dir_; return dir_;
} }
std::unique_ptr<byte[]> ReadFile(const char *filename, std::size_t &fileSize, int32_t &error); std::unique_ptr<std::byte[]> ReadFile(const char *filename, std::size_t &fileSize, int32_t &error);
bool HasFile(const char *path) bool HasFile(const char *path)
{ {
@ -52,7 +52,7 @@ struct SaveWriter {
{ {
} }
bool WriteFile(const char *filename, const byte *data, size_t size); bool WriteFile(const char *filename, const std::byte *data, size_t size);
bool HasFile(const char *path) bool HasFile(const char *path)
{ {
@ -96,7 +96,7 @@ struct HeroCompareResult {
std::optional<SaveReader> OpenSaveArchive(uint32_t saveNum); std::optional<SaveReader> OpenSaveArchive(uint32_t saveNum);
std::optional<SaveReader> OpenStashArchive(); std::optional<SaveReader> OpenStashArchive();
const char *pfile_get_password(); const char *pfile_get_password();
std::unique_ptr<byte[]> ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen = nullptr); std::unique_ptr<std::byte[]> ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen = nullptr);
void pfile_write_hero(bool writeGameData = false); void pfile_write_hero(bool writeGameData = false);
#ifndef DISABLE_DEMOMODE #ifndef DISABLE_DEMOMODE
@ -124,7 +124,7 @@ void pfile_read_player_from_save(uint32_t saveNum, Player &player);
void pfile_save_level(); void pfile_save_level();
void pfile_convert_levels(); void pfile_convert_levels();
void pfile_remove_temp_files(); void pfile_remove_temp_files();
std::unique_ptr<byte[]> pfile_read(const char *pszName, size_t *pdwLen); std::unique_ptr<std::byte[]> pfile_read(const char *pszName, size_t *pdwLen);
void pfile_update(bool forceSave); void pfile_update(bool forceSave);
} // namespace devilution } // namespace devilution

3
Source/sha.h

@ -5,10 +5,9 @@
*/ */
#pragma once #pragma once
#include <cstddef>
#include <cstdint> #include <cstdint>
#include "utils/stdcompat/cstddef.hpp"
namespace devilution { namespace devilution {
constexpr size_t BlockSize = 16; constexpr size_t BlockSize = 16;

2
Source/sync.cpp

@ -250,7 +250,7 @@ bool IsTSyncMonsterValidate(const TSyncMonster &monsterSync)
} // namespace } // namespace
uint32_t sync_all_monsters(byte *pbBuf, uint32_t dwMaxLen) uint32_t sync_all_monsters(std::byte *pbBuf, uint32_t dwMaxLen)
{ {
if (ActiveMonsterCount < 1) { if (ActiveMonsterCount < 1) {
return dwMaxLen; return dwMaxLen;

5
Source/sync.h

@ -5,13 +5,12 @@
*/ */
#pragma once #pragma once
#include <cstddef>
#include <cstdint> #include <cstdint>
#include "utils/stdcompat/cstddef.hpp"
namespace devilution { namespace devilution {
uint32_t sync_all_monsters(byte *pbBuf, uint32_t dwMaxLen); uint32_t sync_all_monsters(std::byte *pbBuf, uint32_t dwMaxLen);
uint32_t OnSyncData(const TCmd *pCmd, size_t pnum); uint32_t OnSyncData(const TCmd *pCmd, size_t pnum);
void sync_init(); void sync_init();

10
Source/tmsg.cpp

@ -16,12 +16,12 @@ namespace {
struct TMsg { struct TMsg {
uint32_t time; uint32_t time;
std::unique_ptr<byte[]> body; std::unique_ptr<std::byte[]> body;
uint8_t len; uint8_t len;
TMsg(uint32_t time, const byte *data, uint8_t len) TMsg(uint32_t time, const std::byte *data, uint8_t len)
: time(time) : time(time)
, body(new byte[len]) , body(new std::byte[len])
, len(len) , len(len)
{ {
memcpy(body.get(), data, len); memcpy(body.get(), data, len);
@ -32,7 +32,7 @@ std::list<TMsg> TimedMsgList;
} // namespace } // namespace
uint8_t tmsg_get(std::unique_ptr<byte[]> *msg) uint8_t tmsg_get(std::unique_ptr<std::byte[]> *msg)
{ {
if (TimedMsgList.empty()) if (TimedMsgList.empty())
return 0; return 0;
@ -47,7 +47,7 @@ uint8_t tmsg_get(std::unique_ptr<byte[]> *msg)
return len; return len;
} }
void tmsg_add(const byte *msg, uint8_t len) void tmsg_add(const std::byte *msg, uint8_t len)
{ {
uint32_t time = SDL_GetTicks() + gnTickDelay * 10; uint32_t time = SDL_GetTicks() + gnTickDelay * 10;
TimedMsgList.emplace_back(time, msg, len); TimedMsgList.emplace_back(time, msg, len);

7
Source/tmsg.h

@ -5,15 +5,14 @@
*/ */
#pragma once #pragma once
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include "utils/stdcompat/cstddef.hpp"
namespace devilution { namespace devilution {
uint8_t tmsg_get(std::unique_ptr<byte[]> *msg); uint8_t tmsg_get(std::unique_ptr<std::byte[]> *msg);
void tmsg_add(const byte *msg, uint8_t bLen); void tmsg_add(const std::byte *msg, uint8_t bLen);
void tmsg_start(); void tmsg_start();
void tmsg_cleanup(); void tmsg_cleanup();

4
Source/towners.h

@ -5,14 +5,14 @@
*/ */
#pragma once #pragma once
#include "utils/stdcompat/string_view.hpp" #include <cstddef>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include "items.h" #include "items.h"
#include "player.h" #include "player.h"
#include "quests.h" #include "quests.h"
#include "utils/stdcompat/cstddef.hpp" #include "utils/stdcompat/string_view.hpp"
namespace devilution { namespace devilution {

8
Source/utils/language.cpp

@ -272,7 +272,7 @@ bool ReadEntry(AssetHandle &handle, const MoEntry &e, char *result)
return handle.read(result, e.length); return handle.read(result, e.length);
} }
bool CopyData(void *dst, const byte *data, size_t dataSize, size_t offset, size_t length) bool CopyData(void *dst, const std::byte *data, size_t dataSize, size_t offset, size_t length)
{ {
if (offset + length > dataSize) if (offset + length > dataSize)
return false; return false;
@ -280,7 +280,7 @@ bool CopyData(void *dst, const byte *data, size_t dataSize, size_t offset, size_
return true; return true;
} }
bool ReadEntry(const byte *data, size_t dataSize, const MoEntry &e, char *result) bool ReadEntry(const std::byte *data, size_t dataSize, const MoEntry &e, char *result)
{ {
if (!CopyData(result, data, dataSize, e.offset, e.length)) if (!CopyData(result, data, dataSize, e.offset, e.length))
return false; return false;
@ -410,9 +410,9 @@ void LanguageInitialize()
const bool readWholeFile = handle.handle->type == SDL_RWOPS_UNKNOWN; const bool readWholeFile = handle.handle->type == SDL_RWOPS_UNKNOWN;
#endif #endif
std::unique_ptr<byte[]> data; std::unique_ptr<std::byte[]> data;
if (readWholeFile) { if (readWholeFile) {
data.reset(new byte[fileSize]); data.reset(new std::byte[fileSize]);
if (!handle.read(data.get(), fileSize)) if (!handle.read(data.get(), fileSize))
return; return;
handle = {}; handle = {};

2
Source/utils/pcx_to_clx.cpp

@ -1,5 +1,6 @@
#include "utils/pcx_to_clx.hpp" #include "utils/pcx_to_clx.hpp"
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
@ -13,7 +14,6 @@
#include "utils/clx_encode.hpp" #include "utils/clx_encode.hpp"
#include "utils/endian.hpp" #include "utils/endian.hpp"
#include "utils/pcx.hpp" #include "utils/pcx.hpp"
#include "utils/stdcompat/cstddef.hpp"
#ifdef DEBUG_PCX_TO_CL2_SIZE #ifdef DEBUG_PCX_TO_CL2_SIZE
#include <iomanip> #include <iomanip>

4
Source/utils/static_vector.hpp

@ -1,11 +1,11 @@
#pragma once #pragma once
#include <cstddef>
#include <initializer_list> #include <initializer_list>
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "appfat.h" #include "appfat.h"
#include "utils/stdcompat/cstddef.hpp"
namespace devilution { namespace devilution {
@ -79,7 +79,7 @@ public:
private: private:
struct AlignedStorage { struct AlignedStorage {
alignas(alignof(T)) byte data[sizeof(T)]; alignas(alignof(T)) std::byte data[sizeof(T)];
const T *ptr() const const T *ptr() const
{ {

7
Source/utils/stdcompat/cstddef.hpp

@ -1,7 +0,0 @@
#pragma once
#include <cstddef> // IWYU pragma: export
namespace devilution {
using ::std::byte;
}
Loading…
Cancel
Save