From b28df707b4f624a47e2223e24d5ae19ed6f77f25 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 3 Jan 2017 20:09:38 +0100 Subject: [PATCH] [IXModel] Correct more structs --- .../Modules/AssetInterfaces/IXModel.cpp | 44 ++++++------- .../Modules/AssetInterfaces/IXModelSurfs.cpp | 52 ++++++++------- src/Components/Modules/ModelSurfs.cpp | 22 +++---- src/Components/Modules/Zones.cpp | 20 +++--- src/Game/Structs.hpp | 65 +++++++++++-------- 5 files changed, 109 insertions(+), 94 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IXModel.cpp b/src/Components/Modules/AssetInterfaces/IXModel.cpp index 28a1f13b..b7746e07 100644 --- a/src/Components/Modules/AssetInterfaces/IXModel.cpp +++ b/src/Components/Modules/AssetInterfaces/IXModel.cpp @@ -41,7 +41,7 @@ namespace Assets // Read bone names model->boneNames = builder->getAllocator()->allocateArray(model->numBones); - for (int i = 0; i < model->numBones; ++i) + for (char i = 0; i < model->numBones; ++i) { model->boneNames[i] = Game::SL_GetString(reader.readCString(), 0); } @@ -86,9 +86,9 @@ namespace Assets std::memcpy(surface, baseSurface, sizeof(Game::XSurface)); surface->tileMode = reader.read(); - surface->deformed = reader.read(); + surface->deformed = reader.read(); - surface->streamHandle = reader.read(); + surface->zoneHandle = reader.read(); surface->partBits[0] = reader.read(); surface->partBits[1] = reader.read(); surface->partBits[2] = reader.read(); @@ -99,37 +99,37 @@ namespace Assets surface->baseTriIndex = reader.read(); surface->baseVertIndex = reader.read(); - surface->numVertices = reader.read(); - surface->numPrimitives = reader.read(); - surface->numCT = reader.read(); + surface->vertCount = reader.read(); + surface->triCount = reader.read(); + surface->vertListCount = reader.read(); - surface->blendNum1 = reader.read(); - surface->blendNum2 = reader.read(); - surface->blendNum3 = reader.read(); - surface->blendNum4 = reader.read(); + surface->vertInfo.vertCount[0] = reader.read(); + surface->vertInfo.vertCount[1] = reader.read(); + surface->vertInfo.vertCount[2] = reader.read(); + surface->vertInfo.vertCount[3] = reader.read(); - surface->blendInfo = reinterpret_cast(reader.read(2, surface->blendNum1 + (3 * surface->blendNum2) + (5 * surface->blendNum3) + (7 * surface->blendNum4))); + surface->vertInfo.vertsBlend = reader.readArray(surface->vertInfo.vertCount[0] + (3 * surface->vertInfo.vertCount[1]) + (5 * surface->vertInfo.vertCount[2]) + (7 * surface->vertInfo.vertCount[3])); - surface->vertexBuffer = reader.readArray(surface->numVertices); - surface->indexBuffer = reader.readArray(surface->numPrimitives); + surface->verts0 = reader.readArray(surface->vertCount); + surface->triIndices = reader.readArray(3 * surface->triCount); // Read vert list if (reader.readByte()) { - surface->ct = reader.readArray(surface->numCT); + surface->vertList = reader.readArray(surface->vertListCount); - for (int j = 0; j < surface->numCT; ++j) + for (unsigned int j = 0; j < surface->vertListCount; ++j) { - Game::XRigidVertList* vertList = &surface->ct[j]; + Game::XRigidVertList* vertList = &surface->vertList[j]; - vertList->entry = reader.readArray(); - vertList->entry->node = reinterpret_cast(reader.read(16, vertList->entry->numNode)); - vertList->entry->leaf = reader.readArray(vertList->entry->numLeaf); + vertList->collisionTree = reader.readArray(); + vertList->collisionTree->nodes = reader.readArray(vertList->collisionTree->nodeCount); + vertList->collisionTree->leafs = reader.readArray(vertList->collisionTree->leafCount); } } else { - surface->ct = nullptr; + surface->vertList = nullptr; } } @@ -212,7 +212,7 @@ namespace Assets if (asset->materialHandles) { - for (unsigned char i = 0; i < asset->numsurfs; ++i) + for (char i = 0; i < asset->numsurfs; ++i) { if (asset->materialHandles[i]) { @@ -314,7 +314,7 @@ namespace Assets Game::Material** destMaterials = buffer->dest(); buffer->saveArray(asset->materialHandles, asset->numsurfs); - for (unsigned char i = 0; i < asset->numsurfs; ++i) + for (char i = 0; i < asset->numsurfs; ++i) { if (asset->materialHandles[i]) { diff --git a/src/Components/Modules/AssetInterfaces/IXModelSurfs.cpp b/src/Components/Modules/AssetInterfaces/IXModelSurfs.cpp index 4bf01cde..e7285a83 100644 --- a/src/Components/Modules/AssetInterfaces/IXModelSurfs.cpp +++ b/src/Components/Modules/AssetInterfaces/IXModelSurfs.cpp @@ -11,18 +11,22 @@ namespace Assets Game::XSurfaceCollisionTree* destEntry = buffer->dest(); buffer->save(entry); - if (entry->node) + if (entry->nodes) { + AssertSize(Game::XSurfaceCollisionNode, 16); + buffer->align(Utils::Stream::ALIGN_16); - buffer->save(entry->node, 16, entry->numNode); - Utils::Stream::ClearPointer(&destEntry->node); + buffer->saveArray(entry->nodes, entry->nodeCount); + Utils::Stream::ClearPointer(&destEntry->nodes); } - if (entry->leaf) + if (entry->leafs) { + AssertSize(Game::XSurfaceCollisionLeaf, 2); + buffer->align(Utils::Stream::ALIGN_2); - buffer->saveArray(entry->leaf, entry->numLeaf); - Utils::Stream::ClearPointer(&destEntry->leaf); + buffer->saveArray(entry->leafs, entry->leafCount); + Utils::Stream::ClearPointer(&destEntry->leafs); } } @@ -30,60 +34,58 @@ namespace Assets { Utils::Stream* buffer = builder->getBuffer(); - if (surf->blendInfo) + if (surf->vertInfo.vertsBlend) { buffer->align(Utils::Stream::ALIGN_2); - buffer->save(surf->blendInfo, sizeof(short), surf->blendNum1 + (surf->blendNum2 * 3) + (surf->blendNum3 * 5) + (surf->blendNum4 * 7)); - Utils::Stream::ClearPointer(&destSurf->blendInfo); + buffer->saveArray(surf->vertInfo.vertsBlend, surf->vertInfo.vertCount[0] + (surf->vertInfo.vertCount[1] * 3) + (surf->vertInfo.vertCount[2] * 5) + (surf->vertInfo.vertCount[3] * 7)); + Utils::Stream::ClearPointer(&destSurf->vertInfo.vertsBlend); } // Access vertex block buffer->pushBlock(Game::XFILE_BLOCK_VERTEX); - if (surf->vertexBuffer) + if (surf->verts0) { AssertSize(Game::GfxPackedVertex, 32); buffer->align(Utils::Stream::ALIGN_16); - buffer->saveArray(surf->vertexBuffer, surf->numVertices); - Utils::Stream::ClearPointer(&destSurf->vertexBuffer); + buffer->saveArray(surf->verts0, surf->vertCount); + Utils::Stream::ClearPointer(&destSurf->verts0); } buffer->popBlock(); // Save_XRigidVertListArray - if (surf->ct) + if (surf->vertList) { AssertSize(Game::XRigidVertList, 12); buffer->align(Utils::Stream::ALIGN_4); Game::XRigidVertList* destCt = buffer->dest(); - buffer->saveArray(surf->ct, surf->numCT); + buffer->saveArray(surf->vertList, surf->vertListCount); - for (int i = 0; i < surf->numCT; ++i) + for (unsigned int i = 0; i < surf->vertListCount; ++i) { Game::XRigidVertList* destRigidVertList = &destCt[i]; - Game::XRigidVertList* rigidVertList = &surf->ct[i]; + Game::XRigidVertList* rigidVertList = &surf->vertList[i]; - if (rigidVertList->entry) + if (rigidVertList->collisionTree) { buffer->align(Utils::Stream::ALIGN_4); - this->saveXSurfaceCollisionTree(rigidVertList->entry, builder); - Utils::Stream::ClearPointer(&destRigidVertList->entry); + this->saveXSurfaceCollisionTree(rigidVertList->collisionTree, builder); + Utils::Stream::ClearPointer(&destRigidVertList->collisionTree); } } - Utils::Stream::ClearPointer(&destSurf->ct); + Utils::Stream::ClearPointer(&destSurf->vertList); } // Access index block buffer->pushBlock(Game::XFILE_BLOCK_INDEX); - if (surf->indexBuffer) + if (surf->triIndices) { - AssertSize(Game::Face, 6); - buffer->align(Utils::Stream::ALIGN_16); - buffer->saveArray(surf->indexBuffer, surf->numPrimitives); - Utils::Stream::ClearPointer(&destSurf->indexBuffer); + buffer->saveArray(surf->triIndices, surf->triCount * 3); + Utils::Stream::ClearPointer(&destSurf->triIndices); } buffer->popBlock(); } diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 9bf84eb6..785a1c5f 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -21,16 +21,16 @@ namespace Components for (int i = 0; i < surfs->numSurfaces; ++i) { Game::XSurface* surface = &surfs->surfaces[i]; - if (surface->streamHandle == 0xFF) + if (surface->zoneHandle == -1) { IDirect3DVertexBuffer9* vertexBuffer; IDirect3DIndexBuffer9* indexBuffer; - Game::Load_VertexBuffer(surface->vertexBuffer, &vertexBuffer, surface->numVertices * 32); - Game::Load_IndexBuffer(surface->indexBuffer, &indexBuffer, surface->numPrimitives * 3); + Game::Load_VertexBuffer(surface->verts0, &vertexBuffer, surface->vertCount * 32); + Game::Load_IndexBuffer(surface->triIndices, &indexBuffer, surface->triCount * 3); - ModelSurfs::BufferMap[surface->vertexBuffer] = vertexBuffer; - ModelSurfs::BufferMap[surface->indexBuffer] = indexBuffer; + ModelSurfs::BufferMap[surface->verts0] = vertexBuffer; + ModelSurfs::BufferMap[surface->triIndices] = indexBuffer; } } } @@ -130,10 +130,10 @@ namespace Components char* source = &surfaceData[i * 84]; std::memcpy(&tempSurfaces[i], source, 12); - std::memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); - std::memcpy(&tempSurfaces[i].numCT, source + 40, 8); + std::memcpy(&tempSurfaces[i].triIndices, source + 16, 20); + std::memcpy(&tempSurfaces[i].vertListCount, source + 40, 8); std::memcpy(&tempSurfaces[i].partBits, source + 52, 24); - tempSurfaces[i].streamHandle = 0xFF; // Fake handle for buffer interception + tempSurfaces[i].zoneHandle = -1; // Fake handle for buffer interception } std::memcpy(surfaceData, tempSurfaces, 64 * modelSurfs->numSurfaces); @@ -185,18 +185,18 @@ namespace Components { Game::XSurface* surface = &header.surfaces->surfaces[i]; - if (surface->streamHandle == 0xFF) + if (surface->zoneHandle == -1) { hasCustomSurface = true; - auto buffer = ModelSurfs::BufferMap.find(surface->indexBuffer); + auto buffer = ModelSurfs::BufferMap.find(surface->triIndices); if (buffer != ModelSurfs::BufferMap.end()) { buffer->second->Release(); ModelSurfs::BufferMap.erase(buffer); } - buffer = ModelSurfs::BufferMap.find(surface->vertexBuffer); + buffer = ModelSurfs::BufferMap.find(surface->verts0); if (buffer != ModelSurfs::BufferMap.end()) { buffer->second->Release(); diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index d294a8f4..5a9f6235 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -165,19 +165,19 @@ namespace Components char* source = &buffer[i * 84]; std::memcpy(&tempSurfaces[i], source, 12); - std::memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); - std::memcpy(&tempSurfaces[i].numCT, source + 40, 8); + std::memcpy(&tempSurfaces[i].triIndices, source + 16, 20); + std::memcpy(&tempSurfaces[i].vertListCount, source + 40, 8); std::memcpy(&tempSurfaces[i].partBits, source + 52, 24); if (Zones::ZoneVersion >= 332) { struct { - short pad; // +0 - char flag; // +2 - unsigned char streamHandle; // +3 - unsigned short numVertices; // +4 - unsigned short numPrimitives; // +6 + short pad; // +0 + char flag; // +2 + char zoneHandle; // +3 + unsigned short vertCount; // +4 + unsigned short triCount; // +6 // [...] } surface332; @@ -191,9 +191,9 @@ namespace Components } // Copy the correct data back to our surface - tempSurfaces[i].streamHandle = surface332.streamHandle; - tempSurfaces[i].numVertices = surface332.numVertices; - tempSurfaces[i].numPrimitives = surface332.numPrimitives; + tempSurfaces[i].zoneHandle = surface332.zoneHandle; + tempSurfaces[i].vertCount = surface332.vertCount; + tempSurfaces[i].triCount = surface332.triCount; //std::memmove(&tempSurfaces[i].numVertices, &tempSurfaces[i].numPrimitives, 6); } diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 9764911d..2f6b4fa4 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -1517,23 +1517,41 @@ namespace Game int error; } structuredDataFindState_t; + struct XSurfaceCollisionLeaf + { + unsigned __int16 triangleBeginIndex; + }; + + struct XSurfaceCollisionAabb + { + unsigned __int16 mins[3]; + unsigned __int16 maxs[3]; + }; + + struct XSurfaceCollisionNode + { + XSurfaceCollisionAabb aabb; + unsigned __int16 childBeginIndex; + unsigned __int16 childCount; + }; + struct XSurfaceCollisionTree { float trans[3]; float scale[3]; - int numNode; - char* node; // el size 16 - int numLeaf; - short* leaf; + unsigned int nodeCount; + XSurfaceCollisionNode *nodes; + unsigned int leafCount; + XSurfaceCollisionLeaf *leafs; }; struct XRigidVertList { - unsigned short boneOffset; - unsigned short vertCount; - unsigned short triOffset; - unsigned short triCount; - XSurfaceCollisionTree* entry; + unsigned __int16 boneOffset; + unsigned __int16 vertCount; + unsigned __int16 triOffset; + unsigned __int16 triCount; + XSurfaceCollisionTree *collisionTree; }; struct GfxPackedVertex @@ -1546,31 +1564,26 @@ namespace Game float normal[3]; }; - struct Face + struct XSurfaceVertexInfo { - unsigned short v1; - unsigned short v2; - unsigned short v3; + __int16 vertCount[4]; + unsigned __int16 *vertsBlend; }; struct XSurface { char tileMode; - char deformed; - unsigned short numVertices; // +2 - unsigned short numPrimitives; // +4 - unsigned char streamHandle; // something to do with buffers, +6 + bool deformed; + unsigned __int16 vertCount; + unsigned __int16 triCount; + char zoneHandle; unsigned __int16 baseTriIndex; unsigned __int16 baseVertIndex; - Face* indexBuffer; // +12 - short blendNum1; // +16 - short blendNum2; // +18 - short blendNum3; // +20 - short blendNum4; // +22 - char* blendInfo; // +24 - GfxPackedVertex* vertexBuffer; // +28 - int numCT; // +32 - XRigidVertList* ct; // +36 + unsigned __int16 *triIndices; + XSurfaceVertexInfo vertInfo; + GfxPackedVertex *verts0; + unsigned int vertListCount; + XRigidVertList *vertList; int partBits[6]; };