[IXModel] Correct more structs

This commit is contained in:
momo5502 2017-01-03 20:09:38 +01:00
parent 7d9c588e0e
commit b28df707b4
5 changed files with 109 additions and 94 deletions

View File

@ -41,7 +41,7 @@ namespace Assets
// Read bone names // Read bone names
model->boneNames = builder->getAllocator()->allocateArray<unsigned short>(model->numBones); model->boneNames = builder->getAllocator()->allocateArray<unsigned short>(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); model->boneNames[i] = Game::SL_GetString(reader.readCString(), 0);
} }
@ -86,9 +86,9 @@ namespace Assets
std::memcpy(surface, baseSurface, sizeof(Game::XSurface)); std::memcpy(surface, baseSurface, sizeof(Game::XSurface));
surface->tileMode = reader.read<char>(); surface->tileMode = reader.read<char>();
surface->deformed = reader.read<char>(); surface->deformed = reader.read<bool>();
surface->streamHandle = reader.read<unsigned char>(); surface->zoneHandle = reader.read<char>();
surface->partBits[0] = reader.read<int>(); surface->partBits[0] = reader.read<int>();
surface->partBits[1] = reader.read<int>(); surface->partBits[1] = reader.read<int>();
surface->partBits[2] = reader.read<int>(); surface->partBits[2] = reader.read<int>();
@ -99,37 +99,37 @@ namespace Assets
surface->baseTriIndex = reader.read<unsigned __int16>(); surface->baseTriIndex = reader.read<unsigned __int16>();
surface->baseVertIndex = reader.read<unsigned __int16>(); surface->baseVertIndex = reader.read<unsigned __int16>();
surface->numVertices = reader.read<unsigned short>(); surface->vertCount = reader.read<unsigned short>();
surface->numPrimitives = reader.read<unsigned short>(); surface->triCount = reader.read<unsigned short>();
surface->numCT = reader.read<int>(); surface->vertListCount = reader.read<unsigned int>();
surface->blendNum1 = reader.read<short>(); surface->vertInfo.vertCount[0] = reader.read<short>();
surface->blendNum2 = reader.read<short>(); surface->vertInfo.vertCount[1] = reader.read<short>();
surface->blendNum3 = reader.read<short>(); surface->vertInfo.vertCount[2] = reader.read<short>();
surface->blendNum4 = reader.read<short>(); surface->vertInfo.vertCount[3] = reader.read<short>();
surface->blendInfo = reinterpret_cast<char*>(reader.read(2, surface->blendNum1 + (3 * surface->blendNum2) + (5 * surface->blendNum3) + (7 * surface->blendNum4))); surface->vertInfo.vertsBlend = reader.readArray<unsigned short>(surface->vertInfo.vertCount[0] + (3 * surface->vertInfo.vertCount[1]) + (5 * surface->vertInfo.vertCount[2]) + (7 * surface->vertInfo.vertCount[3]));
surface->vertexBuffer = reader.readArray<Game::GfxPackedVertex>(surface->numVertices); surface->verts0 = reader.readArray<Game::GfxPackedVertex>(surface->vertCount);
surface->indexBuffer = reader.readArray<Game::Face>(surface->numPrimitives); surface->triIndices = reader.readArray<unsigned __int16>(3 * surface->triCount);
// Read vert list // Read vert list
if (reader.readByte()) if (reader.readByte())
{ {
surface->ct = reader.readArray<Game::XRigidVertList>(surface->numCT); surface->vertList = reader.readArray<Game::XRigidVertList>(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<Game::XSurfaceCollisionTree>(); vertList->collisionTree = reader.readArray<Game::XSurfaceCollisionTree>();
vertList->entry->node = reinterpret_cast<char*>(reader.read(16, vertList->entry->numNode)); vertList->collisionTree->nodes = reader.readArray<Game::XSurfaceCollisionNode>(vertList->collisionTree->nodeCount);
vertList->entry->leaf = reader.readArray<short>(vertList->entry->numLeaf); vertList->collisionTree->leafs = reader.readArray<Game::XSurfaceCollisionLeaf>(vertList->collisionTree->leafCount);
} }
} }
else else
{ {
surface->ct = nullptr; surface->vertList = nullptr;
} }
} }
@ -212,7 +212,7 @@ namespace Assets
if (asset->materialHandles) if (asset->materialHandles)
{ {
for (unsigned char i = 0; i < asset->numsurfs; ++i) for (char i = 0; i < asset->numsurfs; ++i)
{ {
if (asset->materialHandles[i]) if (asset->materialHandles[i])
{ {
@ -314,7 +314,7 @@ namespace Assets
Game::Material** destMaterials = buffer->dest<Game::Material*>(); Game::Material** destMaterials = buffer->dest<Game::Material*>();
buffer->saveArray(asset->materialHandles, asset->numsurfs); 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]) if (asset->materialHandles[i])
{ {

View File

@ -11,18 +11,22 @@ namespace Assets
Game::XSurfaceCollisionTree* destEntry = buffer->dest<Game::XSurfaceCollisionTree>(); Game::XSurfaceCollisionTree* destEntry = buffer->dest<Game::XSurfaceCollisionTree>();
buffer->save(entry); buffer->save(entry);
if (entry->node) if (entry->nodes)
{ {
AssertSize(Game::XSurfaceCollisionNode, 16);
buffer->align(Utils::Stream::ALIGN_16); buffer->align(Utils::Stream::ALIGN_16);
buffer->save(entry->node, 16, entry->numNode); buffer->saveArray(entry->nodes, entry->nodeCount);
Utils::Stream::ClearPointer(&destEntry->node); Utils::Stream::ClearPointer(&destEntry->nodes);
} }
if (entry->leaf) if (entry->leafs)
{ {
AssertSize(Game::XSurfaceCollisionLeaf, 2);
buffer->align(Utils::Stream::ALIGN_2); buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(entry->leaf, entry->numLeaf); buffer->saveArray(entry->leafs, entry->leafCount);
Utils::Stream::ClearPointer(&destEntry->leaf); Utils::Stream::ClearPointer(&destEntry->leafs);
} }
} }
@ -30,60 +34,58 @@ namespace Assets
{ {
Utils::Stream* buffer = builder->getBuffer(); Utils::Stream* buffer = builder->getBuffer();
if (surf->blendInfo) if (surf->vertInfo.vertsBlend)
{ {
buffer->align(Utils::Stream::ALIGN_2); buffer->align(Utils::Stream::ALIGN_2);
buffer->save(surf->blendInfo, sizeof(short), surf->blendNum1 + (surf->blendNum2 * 3) + (surf->blendNum3 * 5) + (surf->blendNum4 * 7)); 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->blendInfo); Utils::Stream::ClearPointer(&destSurf->vertInfo.vertsBlend);
} }
// Access vertex block // Access vertex block
buffer->pushBlock(Game::XFILE_BLOCK_VERTEX); buffer->pushBlock(Game::XFILE_BLOCK_VERTEX);
if (surf->vertexBuffer) if (surf->verts0)
{ {
AssertSize(Game::GfxPackedVertex, 32); AssertSize(Game::GfxPackedVertex, 32);
buffer->align(Utils::Stream::ALIGN_16); buffer->align(Utils::Stream::ALIGN_16);
buffer->saveArray(surf->vertexBuffer, surf->numVertices); buffer->saveArray(surf->verts0, surf->vertCount);
Utils::Stream::ClearPointer(&destSurf->vertexBuffer); Utils::Stream::ClearPointer(&destSurf->verts0);
} }
buffer->popBlock(); buffer->popBlock();
// Save_XRigidVertListArray // Save_XRigidVertListArray
if (surf->ct) if (surf->vertList)
{ {
AssertSize(Game::XRigidVertList, 12); AssertSize(Game::XRigidVertList, 12);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::XRigidVertList* destCt = buffer->dest<Game::XRigidVertList>(); Game::XRigidVertList* destCt = buffer->dest<Game::XRigidVertList>();
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* 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); buffer->align(Utils::Stream::ALIGN_4);
this->saveXSurfaceCollisionTree(rigidVertList->entry, builder); this->saveXSurfaceCollisionTree(rigidVertList->collisionTree, builder);
Utils::Stream::ClearPointer(&destRigidVertList->entry); Utils::Stream::ClearPointer(&destRigidVertList->collisionTree);
} }
} }
Utils::Stream::ClearPointer(&destSurf->ct); Utils::Stream::ClearPointer(&destSurf->vertList);
} }
// Access index block // Access index block
buffer->pushBlock(Game::XFILE_BLOCK_INDEX); buffer->pushBlock(Game::XFILE_BLOCK_INDEX);
if (surf->indexBuffer) if (surf->triIndices)
{ {
AssertSize(Game::Face, 6);
buffer->align(Utils::Stream::ALIGN_16); buffer->align(Utils::Stream::ALIGN_16);
buffer->saveArray(surf->indexBuffer, surf->numPrimitives); buffer->saveArray(surf->triIndices, surf->triCount * 3);
Utils::Stream::ClearPointer(&destSurf->indexBuffer); Utils::Stream::ClearPointer(&destSurf->triIndices);
} }
buffer->popBlock(); buffer->popBlock();
} }

View File

@ -21,16 +21,16 @@ namespace Components
for (int i = 0; i < surfs->numSurfaces; ++i) for (int i = 0; i < surfs->numSurfaces; ++i)
{ {
Game::XSurface* surface = &surfs->surfaces[i]; Game::XSurface* surface = &surfs->surfaces[i];
if (surface->streamHandle == 0xFF) if (surface->zoneHandle == -1)
{ {
IDirect3DVertexBuffer9* vertexBuffer; IDirect3DVertexBuffer9* vertexBuffer;
IDirect3DIndexBuffer9* indexBuffer; IDirect3DIndexBuffer9* indexBuffer;
Game::Load_VertexBuffer(surface->vertexBuffer, &vertexBuffer, surface->numVertices * 32); Game::Load_VertexBuffer(surface->verts0, &vertexBuffer, surface->vertCount * 32);
Game::Load_IndexBuffer(surface->indexBuffer, &indexBuffer, surface->numPrimitives * 3); Game::Load_IndexBuffer(surface->triIndices, &indexBuffer, surface->triCount * 3);
ModelSurfs::BufferMap[surface->vertexBuffer] = vertexBuffer; ModelSurfs::BufferMap[surface->verts0] = vertexBuffer;
ModelSurfs::BufferMap[surface->indexBuffer] = indexBuffer; ModelSurfs::BufferMap[surface->triIndices] = indexBuffer;
} }
} }
} }
@ -130,10 +130,10 @@ namespace Components
char* source = &surfaceData[i * 84]; char* source = &surfaceData[i * 84];
std::memcpy(&tempSurfaces[i], source, 12); std::memcpy(&tempSurfaces[i], source, 12);
std::memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); std::memcpy(&tempSurfaces[i].triIndices, source + 16, 20);
std::memcpy(&tempSurfaces[i].numCT, source + 40, 8); std::memcpy(&tempSurfaces[i].vertListCount, source + 40, 8);
std::memcpy(&tempSurfaces[i].partBits, source + 52, 24); 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); std::memcpy(surfaceData, tempSurfaces, 64 * modelSurfs->numSurfaces);
@ -185,18 +185,18 @@ namespace Components
{ {
Game::XSurface* surface = &header.surfaces->surfaces[i]; Game::XSurface* surface = &header.surfaces->surfaces[i];
if (surface->streamHandle == 0xFF) if (surface->zoneHandle == -1)
{ {
hasCustomSurface = true; hasCustomSurface = true;
auto buffer = ModelSurfs::BufferMap.find(surface->indexBuffer); auto buffer = ModelSurfs::BufferMap.find(surface->triIndices);
if (buffer != ModelSurfs::BufferMap.end()) if (buffer != ModelSurfs::BufferMap.end())
{ {
buffer->second->Release(); buffer->second->Release();
ModelSurfs::BufferMap.erase(buffer); ModelSurfs::BufferMap.erase(buffer);
} }
buffer = ModelSurfs::BufferMap.find(surface->vertexBuffer); buffer = ModelSurfs::BufferMap.find(surface->verts0);
if (buffer != ModelSurfs::BufferMap.end()) if (buffer != ModelSurfs::BufferMap.end())
{ {
buffer->second->Release(); buffer->second->Release();

View File

@ -165,8 +165,8 @@ namespace Components
char* source = &buffer[i * 84]; char* source = &buffer[i * 84];
std::memcpy(&tempSurfaces[i], source, 12); std::memcpy(&tempSurfaces[i], source, 12);
std::memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); std::memcpy(&tempSurfaces[i].triIndices, source + 16, 20);
std::memcpy(&tempSurfaces[i].numCT, source + 40, 8); std::memcpy(&tempSurfaces[i].vertListCount, source + 40, 8);
std::memcpy(&tempSurfaces[i].partBits, source + 52, 24); std::memcpy(&tempSurfaces[i].partBits, source + 52, 24);
if (Zones::ZoneVersion >= 332) if (Zones::ZoneVersion >= 332)
@ -175,9 +175,9 @@ namespace Components
{ {
short pad; // +0 short pad; // +0
char flag; // +2 char flag; // +2
unsigned char streamHandle; // +3 char zoneHandle; // +3
unsigned short numVertices; // +4 unsigned short vertCount; // +4
unsigned short numPrimitives; // +6 unsigned short triCount; // +6
// [...] // [...]
} surface332; } surface332;
@ -191,9 +191,9 @@ namespace Components
} }
// Copy the correct data back to our surface // Copy the correct data back to our surface
tempSurfaces[i].streamHandle = surface332.streamHandle; tempSurfaces[i].zoneHandle = surface332.zoneHandle;
tempSurfaces[i].numVertices = surface332.numVertices; tempSurfaces[i].vertCount = surface332.vertCount;
tempSurfaces[i].numPrimitives = surface332.numPrimitives; tempSurfaces[i].triCount = surface332.triCount;
//std::memmove(&tempSurfaces[i].numVertices, &tempSurfaces[i].numPrimitives, 6); //std::memmove(&tempSurfaces[i].numVertices, &tempSurfaces[i].numPrimitives, 6);
} }

View File

@ -1517,23 +1517,41 @@ namespace Game
int error; int error;
} structuredDataFindState_t; } 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 struct XSurfaceCollisionTree
{ {
float trans[3]; float trans[3];
float scale[3]; float scale[3];
int numNode; unsigned int nodeCount;
char* node; // el size 16 XSurfaceCollisionNode *nodes;
int numLeaf; unsigned int leafCount;
short* leaf; XSurfaceCollisionLeaf *leafs;
}; };
struct XRigidVertList struct XRigidVertList
{ {
unsigned short boneOffset; unsigned __int16 boneOffset;
unsigned short vertCount; unsigned __int16 vertCount;
unsigned short triOffset; unsigned __int16 triOffset;
unsigned short triCount; unsigned __int16 triCount;
XSurfaceCollisionTree* entry; XSurfaceCollisionTree *collisionTree;
}; };
struct GfxPackedVertex struct GfxPackedVertex
@ -1546,31 +1564,26 @@ namespace Game
float normal[3]; float normal[3];
}; };
struct Face struct XSurfaceVertexInfo
{ {
unsigned short v1; __int16 vertCount[4];
unsigned short v2; unsigned __int16 *vertsBlend;
unsigned short v3;
}; };
struct XSurface struct XSurface
{ {
char tileMode; char tileMode;
char deformed; bool deformed;
unsigned short numVertices; // +2 unsigned __int16 vertCount;
unsigned short numPrimitives; // +4 unsigned __int16 triCount;
unsigned char streamHandle; // something to do with buffers, +6 char zoneHandle;
unsigned __int16 baseTriIndex; unsigned __int16 baseTriIndex;
unsigned __int16 baseVertIndex; unsigned __int16 baseVertIndex;
Face* indexBuffer; // +12 unsigned __int16 *triIndices;
short blendNum1; // +16 XSurfaceVertexInfo vertInfo;
short blendNum2; // +18 GfxPackedVertex *verts0;
short blendNum3; // +20 unsigned int vertListCount;
short blendNum4; // +22 XRigidVertList *vertList;
char* blendInfo; // +24
GfxPackedVertex* vertexBuffer; // +28
int numCT; // +32
XRigidVertList* ct; // +36
int partBits[6]; int partBits[6];
}; };