mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 20:43:04 +01:00
add better object read error logging
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "../core/IStream.hpp"
|
||||
#include "../core/Memory.hpp"
|
||||
#include "ImageTable.h"
|
||||
#include "Object.h"
|
||||
|
||||
ImageTable::~ImageTable()
|
||||
{
|
||||
@@ -26,44 +27,51 @@ ImageTable::~ImageTable()
|
||||
_dataSize = 0;
|
||||
}
|
||||
|
||||
void ImageTable::Read(IStream * stream)
|
||||
void ImageTable::Read(IReadObjectContext * context, IStream * stream)
|
||||
{
|
||||
uint32 numImages = stream->ReadValue<uint32>();
|
||||
uint32 imageDataSize = stream->ReadValue<uint32>();
|
||||
|
||||
_dataSize = imageDataSize;
|
||||
_data = Memory::Reallocate(_data, _dataSize);
|
||||
|
||||
// Read g1 element headers
|
||||
uintptr_t imageDataBase = (uintptr_t)_data;
|
||||
for (uint32 i = 0; i < numImages; i++)
|
||||
try
|
||||
{
|
||||
rct_g1_element g1Element;
|
||||
uint32 numImages = stream->ReadValue<uint32>();
|
||||
uint32 imageDataSize = stream->ReadValue<uint32>();
|
||||
|
||||
uintptr_t imageDataOffset = (uintptr_t)stream->ReadValue<uint32>();
|
||||
g1Element.offset = (uint8*)(imageDataBase + imageDataOffset);
|
||||
_dataSize = imageDataSize;
|
||||
_data = Memory::Reallocate(_data, _dataSize);
|
||||
|
||||
g1Element.width = stream->ReadValue<sint16>();
|
||||
g1Element.height = stream->ReadValue<sint16>();
|
||||
g1Element.x_offset = stream->ReadValue<sint16>();
|
||||
g1Element.y_offset = stream->ReadValue<sint16>();
|
||||
g1Element.flags = stream->ReadValue<uint16>();
|
||||
g1Element.zoomed_offset = stream->ReadValue<uint16>();
|
||||
// Read g1 element headers
|
||||
uintptr_t imageDataBase = (uintptr_t)_data;
|
||||
for (uint32 i = 0; i < numImages; i++)
|
||||
{
|
||||
rct_g1_element g1Element;
|
||||
|
||||
_entries.push_back(g1Element);
|
||||
uintptr_t imageDataOffset = (uintptr_t)stream->ReadValue<uint32>();
|
||||
g1Element.offset = (uint8*)(imageDataBase + imageDataOffset);
|
||||
|
||||
g1Element.width = stream->ReadValue<sint16>();
|
||||
g1Element.height = stream->ReadValue<sint16>();
|
||||
g1Element.x_offset = stream->ReadValue<sint16>();
|
||||
g1Element.y_offset = stream->ReadValue<sint16>();
|
||||
g1Element.flags = stream->ReadValue<uint16>();
|
||||
g1Element.zoomed_offset = stream->ReadValue<uint16>();
|
||||
|
||||
_entries.push_back(g1Element);
|
||||
}
|
||||
|
||||
// Read g1 element data
|
||||
size_t readBytes = (size_t)stream->TryRead(_data, _dataSize);
|
||||
|
||||
// If data is shorter than expected (some custom objects are unfortunately like that)
|
||||
size_t unreadBytes = _dataSize - readBytes;
|
||||
if (unreadBytes > 0)
|
||||
{
|
||||
void * ptr = (void*)(((uintptr_t)_data) + readBytes);
|
||||
Memory::Set(ptr, 0, unreadBytes);
|
||||
|
||||
context->LogWarning(OBJECT_ERROR_BAD_IMAGE_TABLE, "Image table size shorter than expected.");
|
||||
}
|
||||
}
|
||||
|
||||
// Read g1 element data
|
||||
size_t readBytes = (size_t)stream->TryRead(_data, _dataSize);
|
||||
|
||||
// If data is shorter than expected (some custom objects are unfortunately like that)
|
||||
size_t unreadBytes = _dataSize - readBytes;
|
||||
if (unreadBytes > 0)
|
||||
catch (Exception ex)
|
||||
{
|
||||
void * ptr = (void*)(((uintptr_t)_data) + readBytes);
|
||||
Memory::Set(ptr, 0, unreadBytes);
|
||||
|
||||
Console::Error::WriteFormat("Warning: Image table size shorter than expected.");
|
||||
Console::Error::WriteLine();
|
||||
context->LogError(OBJECT_ERROR_BAD_IMAGE_TABLE, "Bad image table.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user