diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index 83d792e0..3b1c1309 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -31,25 +31,6 @@ namespace Assets } } - /* - std::sort(surfs.begin(), surfs.end(), [](Game::GfxSurface* a, Game::GfxSurface* b) - { - if (a->material->name == nullptr && b->material->name == nullptr) return false; - if (a->material->name == nullptr && b->material->name != nullptr) return true; - if (a->material->name != nullptr && b->material->name == nullptr) return false; - return strcmp(a->material->name, b->material->name) == 0; - }); - - Game::GfxSurface* tmpBuffer = builder->getAllocator()->allocateArray(world->surfaceCount); - - for (unsigned int i = 0; i < world->surfaceCount; ++i) - { - std::memcpy(&tmpBuffer[i], surfs[i], sizeof(Game::GfxSurface)); - } - - asset->surfaces = tmpBuffer; - */ - if (asset->surfacesBounds) { asset->surfacesBounds = reader->readArray(world->surfaceCount); @@ -66,7 +47,6 @@ namespace Assets if (model->model) { model->model = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, reader->readString().data(), builder).model; - //reader->readString(); model->model = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_XMODEL, "void").model; // Use red-fx for now } } } @@ -997,6 +977,8 @@ namespace Assets Utils::Stream::ClearPointer(&dest->baseName); } + //buffer->setPointerAssertion(true); + if (asset->skies) { AssertSize(Game::GfxSky, 16); @@ -1364,6 +1346,7 @@ namespace Assets Utils::Stream::ClearPointer(&dest->heroOnlyLights); } + //buffer->setPointerAssertion(false); buffer->popBlock(); SaveLogExit(); } diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 93a9a37c..81ea8202 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -1,5 +1,4 @@ #include "STDInclude.hpp" -#include namespace Components { diff --git a/src/Utils/Stream.cpp b/src/Utils/Stream.cpp index 0810ffeb..85140bcb 100644 --- a/src/Utils/Stream.cpp +++ b/src/Utils/Stream.cpp @@ -87,7 +87,7 @@ namespace Utils return this->pointerMap.find(pointer) != this->pointerMap.end(); } - Stream::Stream() : criticalSectionState(0) + Stream::Stream() : ptrAssertion(false), criticalSectionState(0) { memset(this->blockSize, 0, sizeof(this->blockSize)); @@ -122,6 +122,25 @@ namespace Utils return this->buffer.capacity(); } + void Stream::assertPointer(const void* pointer, size_t length) + { + if (!this->ptrAssertion) return; + + for (auto& entry : this->ptrList) + { + unsigned int ePtr = reinterpret_cast(entry.first); + unsigned int tPtr = reinterpret_cast(pointer); + + if(Utils::HasIntercection(ePtr, entry.second, tPtr, length)) + { + MessageBoxA(nullptr, "Duplicate data written!", "ERROR", MB_ICONERROR); + __debugbreak(); + } + } + + this->ptrList.push_back({ pointer, length }); + } + char* Stream::save(const void* _str, size_t size, size_t count) { return this->save(this->getCurrentBlock(), _str, size, count); @@ -155,6 +174,7 @@ namespace Utils } this->increaseBlockSize(stream, size * count); + this->assertPointer(_str, size * count); return this->at() - (size * count); } diff --git a/src/Utils/Stream.hpp b/src/Utils/Stream.hpp index 9b5bf558..8b860f4f 100644 --- a/src/Utils/Stream.hpp +++ b/src/Utils/Stream.hpp @@ -15,6 +15,9 @@ namespace Utils class Stream { private: + bool ptrAssertion; + std::vector> ptrList; + int criticalSectionState; unsigned int blockSize[Game::MAX_XFILE_COUNT]; std::vector streamStack; @@ -133,6 +136,12 @@ namespace Utils *object = reinterpret_cast(-1); } + void setPointerAssertion(bool value) + { + this->ptrAssertion = value; + } + void assertPointer(const void* pointer, size_t length); + void toBuffer(std::string& outBuffer); std::string toBuffer(); diff --git a/src/Utils/Utils.cpp b/src/Utils/Utils.cpp index 179295b9..c0cf82e3 100644 --- a/src/Utils/Utils.cpp +++ b/src/Utils/Utils.cpp @@ -81,6 +81,6 @@ namespace Utils bool HasIntercection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2) { - return !((base1 + len1) < base2 || (base2 + len2) < base1); + return !(base1 + len1 <= base2 || base2 + len2 <= base1); } }