MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / CreateObjectFromLegacyFile

Function CreateObjectFromLegacyFile

src/openrct2/object/ObjectFactory.cpp:279–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277 }
278
279 std::unique_ptr<Object> CreateObjectFromLegacyFile(const utf8* path, bool loadImages)
280 {
281 LOG_VERBOSE("CreateObjectFromLegacyFile(..., \"%s\")", path);
282
283 std::unique_ptr<Object> result;
284 try
285 {
286 auto fs = FileStream(path, FileMode::open);
287 auto chunkReader = SawyerChunkReader(&fs);
288
289 RCTObjectEntry entry = fs.ReadValue<RCTObjectEntry>();
290
291 if (entry.GetType() != ObjectType::scenarioMeta)
292 {
293 result = CreateObject(entry.GetType());
294 result->SetDescriptor(ObjectEntryDescriptor(entry));
295 result->SetFileName(Path::GetFileNameWithoutExtension(path));
296
297 utf8 objectName[kDatNameLength + 1] = { 0 };
298 ObjectEntryGetNameFixed(objectName, sizeof(objectName), &entry);
299 LOG_VERBOSE(" entry: { 0x%08X, \"%s\", 0x%08X }", entry.flags, objectName, entry.checksum);
300
301 auto chunk = chunkReader.ReadChunk();
302 LOG_VERBOSE(" size: %zu", chunk->GetLength());
303
304 auto chunkStream = MemoryStream(chunk->GetData(), chunk->GetLength());
305 auto readContext = ReadObjectContext(objectName, loadImages, nullptr);
306 ReadObjectLegacy(*result, &readContext, &chunkStream);
307 if (readContext.WasError())
308 {
309 throw std::runtime_error("Object has errors");
310 }
311 result->SetSourceGames({ entry.GetSourceGame() });
312 }
313 }
314 catch (const std::exception& e)
315 {
316 LOG_ERROR("Error: %s when processing object %s", e.what(), path);
317 }
318 return result;
319 }
320
321 std::unique_ptr<Object> CreateObjectFromLegacyData(const RCTObjectEntry* entry, const void* data, size_t dataSize)
322 {

Callers 2

CreateObjectFromFileFunction · 0.85
LoadObjectImagesMethod · 0.85

Calls 15

FileStreamClass · 0.85
SawyerChunkReaderClass · 0.85
CreateObjectFunction · 0.85
ObjectEntryGetNameFixedFunction · 0.85
MemoryStreamClass · 0.85
ReadObjectContextClass · 0.85
ReadObjectLegacyFunction · 0.85
SetDescriptorMethod · 0.80
SetFileNameMethod · 0.80
ReadChunkMethod · 0.80
WasErrorMethod · 0.80

Tested by

no test coverage detected