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

Function DetectFileType

src/openrct2/sawyer_coding/SawyerCoding.cpp:385–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383#pragma endregion
384
385 int32_t DetectFileType(const uint8_t* src, size_t length)
386 {
387 if (length < 4)
388 {
389 throw std::length_error("Stream is (nearly) empty!");
390 }
391
392 // Currently can't detect TD4, as the checksum is the same as SC4 (need alternative method)
393
394 uint32_t checksum = *(reinterpret_cast<const uint32_t*>(&src[length - 4]));
395 uint32_t actualChecksum = 0;
396 for (size_t i = 0; i < length - 4; i++)
397 {
398 actualChecksum = (actualChecksum & 0xFFFFFF00) | (((actualChecksum & 0xFF) + static_cast<uint8_t>(src[i])) & 0xFF);
399 actualChecksum = Numerics::rol32(actualChecksum, 3);
400 }
401
402 return DetectRCT1Version(checksum - actualChecksum);
403 }
404
405 int32_t DetectRCT1Version(int32_t gameVersion)
406 {

Callers 2

TryClassifyAsS4Function · 0.85
ReadAndDecodeS4Method · 0.85

Calls 1

DetectRCT1VersionFunction · 0.85

Tested by

no test coverage detected