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

Function ObjectCalculateChecksum

src/openrct2/object/ObjectRepository.cpp:671–701  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

669 }
670
671 int32_t ObjectCalculateChecksum(const RCTObjectEntry* entry, const void* data, size_t dataLength)
672 {
673 const uint8_t* entryBytePtr = reinterpret_cast<const uint8_t*>(entry);
674
675 uint32_t checksum = 0xF369A75B;
676 checksum ^= entryBytePtr[0];
677 checksum = Numerics::rol32(checksum, 11);
678 for (int32_t i = 4; i < 12; i++)
679 {
680 checksum ^= entryBytePtr[i];
681 checksum = Numerics::rol32(checksum, 11);
682 }
683
684 const uint8_t* dataBytes = reinterpret_cast<const uint8_t*>(data);
685 const size_t dataLength32 = dataLength - (dataLength & 31);
686 for (size_t i = 0; i < 32; i++)
687 {
688 for (size_t j = i; j < dataLength32; j += 32)
689 {
690 checksum ^= dataBytes[j];
691 }
692 checksum = Numerics::rol32(checksum, 11);
693 }
694 for (size_t i = dataLength32; i < dataLength; i++)
695 {
696 checksum ^= dataBytes[i];
697 checksum = Numerics::rol32(checksum, 11);
698 }
699
700 return static_cast<int32_t>(checksum);
701 }
702} // namespace OpenRCT2

Callers 1

SaveObjectMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected