mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
refactor: only use sizeof with parenthesis
This commit is contained in:
parent
4f0ee35740
commit
1b13f1f1b4
@ -46,8 +46,8 @@ class IPak::Impl : public ObjContainerReferenceable
|
|||||||
|
|
||||||
for (unsigned itemIndex = 0; itemIndex < m_index_section->itemCount; itemIndex++)
|
for (unsigned itemIndex = 0; itemIndex < m_index_section->itemCount; itemIndex++)
|
||||||
{
|
{
|
||||||
m_stream->read(reinterpret_cast<char*>(&indexEntry), sizeof indexEntry);
|
m_stream->read(reinterpret_cast<char*>(&indexEntry), sizeof(indexEntry));
|
||||||
if (m_stream->gcount() != sizeof indexEntry)
|
if (m_stream->gcount() != sizeof(indexEntry))
|
||||||
{
|
{
|
||||||
printf("Unexpected eof when trying to load index entry %u.\n", itemIndex);
|
printf("Unexpected eof when trying to load index entry %u.\n", itemIndex);
|
||||||
return false;
|
return false;
|
||||||
@ -99,7 +99,7 @@ class IPak::Impl : public ObjContainerReferenceable
|
|||||||
IPakHeader header{};
|
IPakHeader header{};
|
||||||
|
|
||||||
m_stream->read(reinterpret_cast<char*>(&header), sizeof(header));
|
m_stream->read(reinterpret_cast<char*>(&header), sizeof(header));
|
||||||
if (m_stream->gcount() != sizeof header)
|
if (m_stream->gcount() != sizeof(header))
|
||||||
{
|
{
|
||||||
printf("Unexpected eof when trying to load header.\n");
|
printf("Unexpected eof when trying to load header.\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -126,7 +126,7 @@ protected:
|
|||||||
while (skipAmount > 0)
|
while (skipAmount > 0)
|
||||||
{
|
{
|
||||||
char temp[1024];
|
char temp[1024];
|
||||||
const auto toRead = skipAmount > sizeof temp ? sizeof temp : static_cast<size_t>(skipAmount);
|
const auto toRead = skipAmount > sizeof(temp) ? sizeof(temp) : static_cast<size_t>(skipAmount);
|
||||||
unzReadCurrentFile(m_container, temp, toRead);
|
unzReadCurrentFile(m_container, temp, toRead);
|
||||||
skipAmount -= toRead;
|
skipAmount -= toRead;
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ public:
|
|||||||
{
|
{
|
||||||
unz_file_info64 info;
|
unz_file_info64 info;
|
||||||
char fileNameBuffer[256];
|
char fileNameBuffer[256];
|
||||||
unzGetCurrentFileInfo64(m_unz_file, &info, fileNameBuffer, sizeof fileNameBuffer, nullptr, 0, nullptr, 0);
|
unzGetCurrentFileInfo64(m_unz_file, &info, fileNameBuffer, sizeof(fileNameBuffer), nullptr, 0, nullptr, 0);
|
||||||
|
|
||||||
std::string fileName(fileNameBuffer);
|
std::string fileName(fileNameBuffer);
|
||||||
std::filesystem::path path(fileName);
|
std::filesystem::path path(fileName);
|
||||||
|
@ -44,7 +44,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
|
|||||||
while (zs.avail_in > 0)
|
while (zs.avail_in > 0)
|
||||||
{
|
{
|
||||||
zs.next_out = buffer;
|
zs.next_out = buffer;
|
||||||
zs.avail_out = sizeof buffer;
|
zs.avail_out = sizeof(buffer);
|
||||||
ret = inflate(&zs, Z_SYNC_FLUSH);
|
ret = inflate(&zs, Z_SYNC_FLUSH);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -54,7 +54,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.write(reinterpret_cast<char*>(buffer), sizeof buffer - zs.avail_out);
|
stream.write(reinterpret_cast<char*>(buffer), sizeof(buffer) - zs.avail_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
inflateEnd(&zs);
|
inflateEnd(&zs);
|
||||||
|
@ -44,7 +44,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
|
|||||||
while (zs.avail_in > 0)
|
while (zs.avail_in > 0)
|
||||||
{
|
{
|
||||||
zs.next_out = buffer;
|
zs.next_out = buffer;
|
||||||
zs.avail_out = sizeof buffer;
|
zs.avail_out = sizeof(buffer);
|
||||||
ret = inflate(&zs, Z_SYNC_FLUSH);
|
ret = inflate(&zs, Z_SYNC_FLUSH);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -54,7 +54,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.write(reinterpret_cast<char*>(buffer), sizeof buffer - zs.avail_out);
|
stream.write(reinterpret_cast<char*>(buffer), sizeof(buffer) - zs.avail_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
inflateEnd(&zs);
|
inflateEnd(&zs);
|
||||||
|
@ -59,7 +59,7 @@ void AssetDumperRawFile::DumpGsc(AssetDumpingContext& context, XAssetInfo<RawFil
|
|||||||
while (zs.avail_in > 0)
|
while (zs.avail_in > 0)
|
||||||
{
|
{
|
||||||
zs.next_out = buffer;
|
zs.next_out = buffer;
|
||||||
zs.avail_out = sizeof buffer;
|
zs.avail_out = sizeof(buffer);
|
||||||
ret = inflate(&zs, Z_SYNC_FLUSH);
|
ret = inflate(&zs, Z_SYNC_FLUSH);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -69,7 +69,7 @@ void AssetDumperRawFile::DumpGsc(AssetDumpingContext& context, XAssetInfo<RawFil
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto inflateOutSize = sizeof buffer - zs.avail_out;
|
const auto inflateOutSize = sizeof(buffer) - zs.avail_out;
|
||||||
|
|
||||||
if (writtenSize + inflateOutSize >= outLen)
|
if (writtenSize + inflateOutSize >= outLen)
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,7 @@ void AssetDumperRawFile::DumpAnimtree(AssetDumpingContext& context, XAssetInfo<R
|
|||||||
while (zs.avail_in > 0)
|
while (zs.avail_in > 0)
|
||||||
{
|
{
|
||||||
zs.next_out = buffer;
|
zs.next_out = buffer;
|
||||||
zs.avail_out = sizeof buffer;
|
zs.avail_out = sizeof(buffer);
|
||||||
ret = inflate(&zs, Z_SYNC_FLUSH);
|
ret = inflate(&zs, Z_SYNC_FLUSH);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -65,7 +65,7 @@ void AssetDumperRawFile::DumpAnimtree(AssetDumpingContext& context, XAssetInfo<R
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto inflateOutSize = sizeof buffer - zs.avail_out;
|
const auto inflateOutSize = sizeof(buffer) - zs.avail_out;
|
||||||
|
|
||||||
stream.write(reinterpret_cast<char*>(buffer), inflateOutSize);
|
stream.write(reinterpret_cast<char*>(buffer), inflateOutSize);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ class DdsWriterInternal
|
|||||||
|
|
||||||
void PopulateDdsHeader(DDS_HEADER& header)
|
void PopulateDdsHeader(DDS_HEADER& header)
|
||||||
{
|
{
|
||||||
header.dwSize = sizeof header;
|
header.dwSize = sizeof(header);
|
||||||
header.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
|
header.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
|
||||||
|
|
||||||
if (m_texture->HasMipMaps())
|
if (m_texture->HasMipMaps())
|
||||||
@ -201,14 +201,14 @@ public:
|
|||||||
|
|
||||||
constexpr auto magic = MakeFourCc('D', 'D', 'S', ' ');
|
constexpr auto magic = MakeFourCc('D', 'D', 'S', ' ');
|
||||||
|
|
||||||
m_stream.write(reinterpret_cast<const char*>(&magic), sizeof magic);
|
m_stream.write(reinterpret_cast<const char*>(&magic), sizeof(magic));
|
||||||
m_stream.write(reinterpret_cast<const char*>(&header), sizeof header);
|
m_stream.write(reinterpret_cast<const char*>(&header), sizeof(header));
|
||||||
|
|
||||||
if (m_use_dx10_extension)
|
if (m_use_dx10_extension)
|
||||||
{
|
{
|
||||||
DDS_HEADER_DXT10 dxt10{};
|
DDS_HEADER_DXT10 dxt10{};
|
||||||
PopulateDxt10Header(dxt10);
|
PopulateDxt10Header(dxt10);
|
||||||
m_stream.write(reinterpret_cast<const char*>(&dxt10), sizeof dxt10);
|
m_stream.write(reinterpret_cast<const char*>(&dxt10), sizeof(dxt10));
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto mipCount = m_texture->HasMipMaps() ? m_texture->GetMipMapCount() : 1;
|
const auto mipCount = m_texture->HasMipMaps() ? m_texture->GetMipMapCount() : 1;
|
||||||
|
@ -146,7 +146,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
|||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
XAssetList assetList{};
|
XAssetList assetList{};
|
||||||
m_stream->LoadDataRaw(&assetList, sizeof assetList);
|
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
|
||||||
|
|
||||||
varScriptStringList = &assetList.stringList;
|
varScriptStringList = &assetList.stringList;
|
||||||
LoadScriptStringList(false);
|
LoadScriptStringList(false);
|
||||||
|
@ -166,7 +166,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
|||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
XAssetList assetList{};
|
XAssetList assetList{};
|
||||||
m_stream->LoadDataRaw(&assetList, sizeof assetList);
|
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
|
||||||
|
|
||||||
varScriptStringList = &assetList.stringList;
|
varScriptStringList = &assetList.stringList;
|
||||||
LoadScriptStringList(false);
|
LoadScriptStringList(false);
|
||||||
|
@ -130,11 +130,11 @@ class ZoneLoaderFactory::Impl
|
|||||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||||
|
|
||||||
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, 1);
|
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1);
|
||||||
auto* subHeaderHashPtr = subHeaderHash.get();
|
auto* subHeaderHashPtr = subHeaderHash.get();
|
||||||
zoneLoader->AddLoadingStep(std::move(subHeaderHash));
|
zoneLoader->AddLoadingStep(std::move(subHeaderHash));
|
||||||
|
|
||||||
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof DB_AuthSignature::bytes);
|
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes));
|
||||||
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
||||||
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature));
|
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature));
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class ZoneLoaderFactory::Impl
|
|||||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||||
|
|
||||||
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
|
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
|
||||||
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||||
zoneLoader->AddLoadingStep(std::move(masterBlockHashes));
|
zoneLoader->AddLoadingStep(std::move(masterBlockHashes));
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
|||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
XAssetList assetList{};
|
XAssetList assetList{};
|
||||||
m_stream->LoadDataRaw(&assetList, sizeof assetList);
|
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
|
||||||
|
|
||||||
varScriptStringList = &assetList.stringList;
|
varScriptStringList = &assetList.stringList;
|
||||||
LoadScriptStringList(false);
|
LoadScriptStringList(false);
|
||||||
|
@ -114,11 +114,11 @@ class ZoneLoaderFactory::Impl
|
|||||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||||
|
|
||||||
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, 1);
|
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1);
|
||||||
auto* subHeaderHashPtr = subHeaderHash.get();
|
auto* subHeaderHashPtr = subHeaderHash.get();
|
||||||
zoneLoader->AddLoadingStep(std::move(subHeaderHash));
|
zoneLoader->AddLoadingStep(std::move(subHeaderHash));
|
||||||
|
|
||||||
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof DB_AuthSignature::bytes);
|
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes));
|
||||||
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
||||||
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature));
|
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature));
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ class ZoneLoaderFactory::Impl
|
|||||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||||
|
|
||||||
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
|
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
|
||||||
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||||
zoneLoader->AddLoadingStep(std::move(masterBlockHashes));
|
zoneLoader->AddLoadingStep(std::move(masterBlockHashes));
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
|||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
XAssetList assetList{};
|
XAssetList assetList{};
|
||||||
m_stream->LoadDataRaw(&assetList, sizeof assetList);
|
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
|
||||||
|
|
||||||
varScriptStringList = &assetList.stringList;
|
varScriptStringList = &assetList.stringList;
|
||||||
LoadScriptStringList(false);
|
LoadScriptStringList(false);
|
||||||
|
@ -188,7 +188,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
|||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
XAssetList assetList{};
|
XAssetList assetList{};
|
||||||
m_stream->LoadDataRaw(&assetList, sizeof assetList);
|
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
|
||||||
|
|
||||||
varScriptStringList = &assetList.stringList;
|
varScriptStringList = &assetList.stringList;
|
||||||
LoadScriptStringList(false);
|
LoadScriptStringList(false);
|
||||||
|
@ -150,16 +150,16 @@ class ProcessorXChunks::ProcessorXChunksImpl
|
|||||||
xchunk_size_t chunkSize;
|
xchunk_size_t chunkSize;
|
||||||
if (m_vanilla_buffer_size > 0)
|
if (m_vanilla_buffer_size > 0)
|
||||||
{
|
{
|
||||||
if (m_vanilla_buffer_offset + sizeof chunkSize > m_vanilla_buffer_size)
|
if (m_vanilla_buffer_offset + sizeof(chunkSize) > m_vanilla_buffer_size)
|
||||||
{
|
{
|
||||||
m_base->m_base_stream->Load(&chunkSize, m_vanilla_buffer_size - m_vanilla_buffer_offset);
|
m_base->m_base_stream->Load(&chunkSize, m_vanilla_buffer_size - m_vanilla_buffer_offset);
|
||||||
m_vanilla_buffer_offset = 0;
|
m_vanilla_buffer_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vanilla_buffer_offset = (m_vanilla_buffer_offset + sizeof chunkSize) % m_vanilla_buffer_size;
|
m_vanilla_buffer_offset = (m_vanilla_buffer_offset + sizeof(chunkSize)) % m_vanilla_buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t readSize = m_base->m_base_stream->Load(&chunkSize, sizeof chunkSize);
|
const size_t readSize = m_base->m_base_stream->Load(&chunkSize, sizeof(chunkSize));
|
||||||
|
|
||||||
if (readSize == 0)
|
if (readSize == 0)
|
||||||
{
|
{
|
||||||
|
@ -33,8 +33,8 @@ std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ZoneHeader header{};
|
ZoneHeader header{};
|
||||||
file.read(reinterpret_cast<char*>(&header), sizeof header);
|
file.read(reinterpret_cast<char*>(&header), sizeof(header));
|
||||||
if (file.gcount() != sizeof header)
|
if (file.gcount() != sizeof(header))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to read zone header from file '" << path << "'.\n";
|
std::cout << "Failed to read zone header from file '" << path << "'.\n";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user