diff --git a/CMakeVariables.txt b/CMakeVariables.txt index 7a8d6b71..39eff425 100644 --- a/CMakeVariables.txt +++ b/CMakeVariables.txt @@ -15,6 +15,6 @@ __dynamic=1 # __include_backtrace__=1 # Set __include_backtrace__ to 1 to includes the backtrace library for better crashlogs. # __compile_backtrace__=1 -# Set __compile_backtrace__ to 1 to compile the backtrace library instead of using system libraries. -__maria_db_connector_compile_jobs__=1 +# Set __compile_backtrace__ to 1 to compile the backtrace library instead of using system libraries. +__maria_db_connector_compile_jobs__= # Set to the number of jobs (make -j equivalent) to compile the mariadbconn files with. diff --git a/dCommon/BrickByBrickFix.cpp b/dCommon/BrickByBrickFix.cpp index c006ab0d..1d33eb20 100644 --- a/dCommon/BrickByBrickFix.cpp +++ b/dCommon/BrickByBrickFix.cpp @@ -6,15 +6,26 @@ #include "dLogger.h" #include "Game.h" +#include "tinyxml2.h" + //! Forward declarations std::unique_ptr GetModelsFromDatabase(); -void WriteSd0Magic(char* input); +void WriteSd0Magic(char* input, uint32_t chunkSize); uint32_t BrickByBrickFix::TruncateBrokenBrickByBrickXml() { auto modelsToTruncate = GetModelsFromDatabase(); - if (modelsToTruncate->next()) { - // Decompress with zlib and attempt to convert to xml. If that fails this model is broken. + while (modelsToTruncate->next()) { + auto modelAsSd0 = modelsToTruncate->getBlob(2); + // Check that header is sd0 by checking for the sd0 magic. + if ( + modelAsSd0->get() == 's' && modelAsSd0->get() == 'd' && modelAsSd0->get() == '0' && + modelAsSd0->get() == 0x01 && modelAsSd0->get() == 0xFF && modelAsSd0->good()) { + + } + else { + Game::logger->Log("BrickByBrickFix", "Please update models to use sd0 through UpdateOldModels."); + } } return 0; } @@ -28,8 +39,9 @@ uint32_t BrickByBrickFix::UpdateBrickByBrickModelsToSd0() { while (modelsToUpdate->next()) { uint32_t modelId = modelsToUpdate->getInt(1); auto oldLxfml = modelsToUpdate->getBlob(2); - // Check if the stored blob starts with zlib magic (0x78). If it does, convert it to sd0. - if (oldLxfml->get() == 0x78) { + // Check if the stored blob starts with zlib magic (0x78 0xDA - best compression of zlib) + // If it does, convert it to sd0. + if (oldLxfml->get() == 0x78 && oldLxfml->get() == 0xDA) { Game::logger->Log("BrickByBrickFix", "Updating model %i", modelId); // Get and save size of zlib compressed chunk. @@ -39,14 +51,9 @@ uint32_t BrickByBrickFix::UpdateBrickByBrickModelsToSd0() { // Allocate 9 extra bytes. 5 for sd0 magic, 4 for the only zlib compressed size. uint32_t oldLxfmlSizeWithHeader = oldLxfmlSize + 9; - char* sd0ConvertedModel = static_cast(std::malloc(oldLxfmlSizeWithHeader)); + char* sd0ConvertedModel = static_cast(malloc(oldLxfmlSizeWithHeader)); - WriteSd0Magic(sd0ConvertedModel); - // zlib compressed chunk size - sd0ConvertedModel[5] = static_cast(oldLxfmlSize); - sd0ConvertedModel[6] = static_cast(oldLxfmlSize >> 8U); - sd0ConvertedModel[7] = static_cast(oldLxfmlSize >> 16U); - sd0ConvertedModel[8] = static_cast(oldLxfmlSize >> 24U); + WriteSd0Magic(sd0ConvertedModel, oldLxfmlSize); for (uint32_t i = 9; i < oldLxfmlSizeWithHeader; i++) { sd0ConvertedModel[i] = oldLxfml->get(); } @@ -79,10 +86,12 @@ std::unique_ptr GetModelsFromDatabase() { return std::unique_ptr(modelsRawDataQuery->executeQuery()); } -void WriteSd0Magic(char* input) { +void WriteSd0Magic(char* input, uint32_t chunkSize) { input[0] = 's'; input[1] = 'd'; input[2] = '0'; input[3] = 0x01; input[4] = 0xFF; + // Write the integer to the character array + *reinterpret_cast(input + 5) = chunkSize; } diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index e34b7fe7..b1ee804c 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -2401,7 +2401,6 @@ void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* e } void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { - //First, we have Wincent's clean methods of reading in the data received from the client. LWOOBJID localId; inStream->Read(localId);