MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / tryInstallObject

Function tryInstallObject

src/OpenLoco/src/Objects/ObjectManager.cpp:764–808  ·  view source on GitHub ↗

0x00472687 based on

Source from the content-addressed store, hash-verified

762
763 // 0x00472687 based on
764 bool tryInstallObject(const ObjectHeader& objectHeader, std::span<const std::byte> data)
765 {
766 unloadAll();
767 if (!computeObjectChecksum(objectHeader, data))
768 {
769 return false;
770 }
771 // Copy the object into Loco freeable memory (required for when partialLoad loads the object)
772 std::byte* objectData = static_cast<std::byte*>(malloc(data.size()));
773 if (objectData == nullptr)
774 {
775 return false;
776 }
777 std::copy(std::begin(data), std::end(data), objectData);
778
779 auto* obj = reinterpret_cast<Object*>(objectData);
780 if (!callObjectValidate(objectHeader.getType(), *obj))
781 {
782 return false;
783 }
784
785 if (getTotalNumImages() >= Gfx::G1ExpectedCount::kObjects + Gfx::G1ExpectedCount::kTemporaryObjects + Gfx::G1ExpectedCount::kDisc)
786 {
787 // Free objectData?
788 return false;
789 }
790
791 // Warning this saves a copy of the objectData pointer and must be unloaded prior to exiting this function
792 if (!partialLoad(objectHeader, std::span(objectData, data.size())))
793 {
794 return false;
795 }
796
797 // Object already installed so no need to install it
798 if (isObjectInstalled(objectHeader))
799 {
800 unloadAll();
801 return false;
802 }
803
804 bool result = installObject(objectHeader);
805
806 unloadAll();
807 return result;
808 }
809
810 static constexpr SawyerEncoding getBestEncodingForObjectType(ObjectType type)
811 {

Callers 1

importSaveToGameStateFunction · 0.85

Calls 11

unloadAllFunction · 0.85
computeObjectChecksumFunction · 0.85
beginFunction · 0.85
endFunction · 0.85
callObjectValidateFunction · 0.85
getTotalNumImagesFunction · 0.85
partialLoadFunction · 0.85
isObjectInstalledFunction · 0.85
installObjectFunction · 0.85
sizeMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected