1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 06:23:04 +01:00

Fix #5169: Parks containing packed objects fail to open

Regression from 3b02b05dc6. Forgot to implement reading packed objects with IStream.
This commit is contained in:
Ted John
2017-02-04 00:34:14 +00:00
parent 3b02b05dc6
commit afc8943e34
6 changed files with 81 additions and 39 deletions

View File

@@ -31,6 +31,7 @@
#include "../core/Stopwatch.hpp"
#include "../core/String.hpp"
#include "../PlatformEnvironment.h"
#include "../rct12/SawyerEncoding.h"
#include "../scenario/ScenarioRepository.h"
#include "Object.h"
#include "ObjectFactory.h"
@@ -223,6 +224,31 @@ public:
}
}
bool TryExportPackedObject(IStream * stream) override
{
// Check if we already have this object
rct_object_entry entry = stream->ReadValue<rct_object_entry>();
if (FindObject(&entry) != nullptr)
{
SawyerEncoding::SkipChunk(stream);
}
else
{
// Read object and save to new file
size_t chunkSize;
void * chunk = SawyerEncoding::ReadChunk(stream, &chunkSize);
if (chunk == nullptr)
{
log_error("Failed to reallocate buffer for packed object.");
return false;
}
AddObject(&entry, chunk, chunkSize);
Memory::Free(chunk);
}
return true;
}
private:
void ClearItems()
{
@@ -735,43 +761,6 @@ extern "C"
}
}
sint32 object_load_packed(SDL_RWops * rw)
{
IObjectRepository * objRepo = GetObjectRepository();
rct_object_entry entry;
SDL_RWread(rw, &entry, 16, 1);
// Check if we already have this object
if (objRepo->FindObject(&entry) != nullptr)
{
sawyercoding_skip_chunk(rw);
}
else
{
// Read object and save to new file
uint8 * chunk = Memory::Allocate<uint8>(0x600000);
if (chunk == nullptr)
{
log_error("Failed to allocate buffer for packed object.");
return 0;
}
size_t chunkSize = sawyercoding_read_chunk_with_size(rw, chunk, 0x600000);
chunk = Memory::Reallocate(chunk, chunkSize);
if (chunk == nullptr)
{
log_error("Failed to reallocate buffer for packed object.");
return 0;
}
objRepo->AddObject(&entry, chunk, chunkSize);
Memory::Free(chunk);
}
return 1;
}
bool object_saved_packed(SDL_RWops * rw, const rct_object_entry * entry)
{
IObjectRepository * objectRepository = GetObjectRepository();