diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index ad11c460..17a11e90 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -126,9 +126,13 @@ namespace Assets AssertSize(Game::cplane_t, 20); buffer->align(Utils::Stream::ALIGN_4); - builder->storePointer(asset->planes); - buffer->saveArray(asset->planes, world->planeCount); + for (int i = 0; i < world->planeCount; ++i) + { + builder->storePointer(&asset->planes[i]); + buffer->save(&asset->planes[i]); + } + Utils::Stream::ClearPointer(&dest->planes); } } @@ -615,9 +619,13 @@ namespace Assets else { buffer->align(Utils::Stream::ALIGN_2); - builder->storePointer(aabbTree->smodelIndexes); - buffer->saveArray(aabbTree->smodelIndexes, aabbTree->smodelIndexCount); + for (unsigned short k = 0; k < aabbTree->smodelIndexCount; ++k) + { + builder->storePointer(&aabbTree->smodelIndexes[k]); + buffer->save(&aabbTree->smodelIndexes[k]); + } + Utils::Stream::ClearPointer(&destAabbTree->smodelIndexes); } } diff --git a/src/Components/Modules/AssetInterfaces/IPhysCollmap.cpp b/src/Components/Modules/AssetInterfaces/IPhysCollmap.cpp index 2816050f..a3009a0f 100644 --- a/src/Components/Modules/AssetInterfaces/IPhysCollmap.cpp +++ b/src/Components/Modules/AssetInterfaces/IPhysCollmap.cpp @@ -40,8 +40,7 @@ namespace Assets { buffer->align(Utils::Stream::ALIGN_4); builder->storePointer(side->side); - - buffer->save(side->side, sizeof(Game::cplane_t)); + buffer->save(side->side); Utils::Stream::ClearPointer(&destSide->side); } } @@ -68,9 +67,13 @@ namespace Assets else { buffer->align(Utils::Stream::ALIGN_4); - builder->storePointer(brush->planes); - buffer->save(brush->planes, sizeof(Game::cplane_t)); + for (short i = 0; i < brush->brush.count; ++i) + { + builder->storePointer(&brush->planes[i]); + buffer->save(&brush->planes[i]); + } + Utils::Stream::ClearPointer(&destBrush->planes); } } diff --git a/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp b/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp index 5e857645..8662f326 100644 --- a/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp +++ b/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp @@ -32,9 +32,13 @@ namespace Assets else { buffer->align(Utils::Stream::ALIGN_4); - builder->storePointer(asset->cPlanes); - buffer->saveArray(asset->cPlanes, asset->numCPlanes); + for (int i = 0; i < asset->numCPlanes; ++i) + { + builder->storePointer(&asset->cPlanes[i]); + buffer->save(&asset->cPlanes[i]); + } + Utils::Stream::ClearPointer(&dest->cPlanes); } @@ -47,8 +51,9 @@ namespace Assets AssertSize(Game::cStaticModel_t, 76); SaveLogEnter("cStaticModel_t"); - // xmodel is already stored buffer->align(Utils::Stream::ALIGN_4); + + Utils::Stream::Offset mark = buffer->getOffset(); Game::cStaticModel_t* destStaticModelList = buffer->dest(); buffer->saveArray(asset->staticModelList, asset->numStaticModels); @@ -204,9 +209,13 @@ namespace Assets else { buffer->align(Utils::Stream::ALIGN_2); - builder->storePointer(node[i].data.brushes); - buffer->saveArray(node[i].data.brushes, node[i].leafBrushCount); + for (short j = 0; j < node[i].leafBrushCount; ++j) + { + builder->storePointer(&node[i].data.brushes[j]); + buffer->save(&node[i].data.brushes[j]); + } + Utils::Stream::ClearPointer(&node[i].data.brushes); } } @@ -427,7 +436,7 @@ namespace Assets if (asset->mapEnts) { - dest->mapEnts = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset->name).mapEnts; + dest->mapEnts = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset->mapEnts->name).mapEnts; } for (int i = 0; i < 2; ++i) diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index f62912b9..2c7be0c3 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -374,9 +374,14 @@ namespace Components return NULL; } + void ZoneBuilder::Zone::storePointer(const void* pointer, Utils::Stream::Offset offset) + { + this->pointerMap[pointer] = offset.getPackedOffset(); + } + void ZoneBuilder::Zone::storePointer(const void* pointer) { - this->pointerMap[pointer] = this->buffer.getPackedOffset(); + this->storePointer(pointer, this->buffer.getOffset()); } int ZoneBuilder::Zone::addScriptString(std::string str) diff --git a/src/Components/Modules/ZoneBuilder.hpp b/src/Components/Modules/ZoneBuilder.hpp index 3f5b5b90..bed43ef2 100644 --- a/src/Components/Modules/ZoneBuilder.hpp +++ b/src/Components/Modules/ZoneBuilder.hpp @@ -20,6 +20,7 @@ namespace Components bool hasPointer(const void* pointer); void storePointer(const void* pointer); + void storePointer(const void* pointer, Utils::Stream::Offset offset); template inline T* getPointer(const T* pointer) { return reinterpret_cast(this->safeGetPointer(pointer)); } diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 50ca762f..e7812a4a 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -1542,9 +1542,10 @@ namespace Game struct cbrushWrapper_t { short count; + short pad; cbrushside_t* brushSide; char * brushEdge; - char pad[24]; + char pad2[24]; }; #pragma pack(push, 4) diff --git a/src/Utils/Stream.cpp b/src/Utils/Stream.cpp index 3dbce286..79b08816 100644 --- a/src/Utils/Stream.cpp +++ b/src/Utils/Stream.cpp @@ -277,14 +277,20 @@ namespace Utils return 0; } - DWORD Stream::getPackedOffset() + Stream::Offset Stream::getOffset() { Game::XFILE_BLOCK_TYPES block = this->getCurrentBlock(); Stream::Offset offset; offset.block = block; offset.offset = this->getBlockSize(block); - return offset.getPackedOffset(); + + return offset; + } + + DWORD Stream::getPackedOffset() + { + return this->getOffset().getPackedOffset(); } void Stream::toBuffer(std::string& outBuffer) diff --git a/src/Utils/Stream.hpp b/src/Utils/Stream.hpp index 5e82686a..b3449a5c 100644 --- a/src/Utils/Stream.hpp +++ b/src/Utils/Stream.hpp @@ -177,5 +177,7 @@ namespace Utils return lOffset.block; }; }; + + Offset getOffset(); }; }