fix: address review comments

This commit is contained in:
6arelyFuture 2023-12-09 22:49:32 +01:00
parent 9306210227
commit 0ad1964864
Signed by: Future
GPG Key ID: FA77F074E98D98A5
2 changed files with 6 additions and 6 deletions

View File

@ -53,10 +53,13 @@ bool AssetLoaderScriptFile::LoadFromRaw(
memcpy(&scriptFile->bytecodeLen, fileBuffer.get() + offset, sizeof(scriptFile->bytecodeLen));
offset += sizeof(scriptFile->bytecodeLen);
// Get the file size
auto fileSize = file.m_length;
if (scriptFile->compressedLen <= 0 || scriptFile->bytecodeLen <= 0)
{
std::cerr << "Error: Invalid length of the buffers in " << assetName << " specified" << std::endl;
return false;
}
if (offset + scriptFile->compressedLen > fileSize || offset + scriptFile->bytecodeLen > fileSize)
if (offset + (scriptFile->compressedLen + scriptFile->bytecodeLen) > file.m_length)
{
std::cerr << "Error: Specified length in " << assetName << " GSC BIN structure exceeds the actual file size" << std::endl;
return false;
@ -68,7 +71,6 @@ bool AssetLoaderScriptFile::LoadFromRaw(
scriptFile->bytecode = static_cast<unsigned char*>(memory->Alloc(scriptFile->bytecodeLen));
memcpy(scriptFile->bytecode, fileBuffer.get() + offset, scriptFile->bytecodeLen);
offset += scriptFile->bytecodeLen;
manager->AddAsset(ASSET_TYPE_SCRIPTFILE, assetName, scriptFile);

View File

@ -8,8 +8,6 @@ namespace IW5
{
class AssetLoaderScriptFile final : public BasicAssetLoader<ASSET_TYPE_SCRIPTFILE, ScriptFile>
{
static constexpr size_t COMPRESSED_BUFFER_SIZE_PADDING = 64;
public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
_NODISCARD bool CanLoadFromRaw() const override;