[clipMap_t] importer bugfxies plus some new structs

This commit is contained in:
TheApadayo 2016-12-29 14:14:55 -05:00
parent 72a7f8c226
commit e95bf591cf
4 changed files with 125 additions and 64 deletions

View File

@ -856,8 +856,8 @@ namespace Assets
SaveLogEnter("GfxDrawSurf"); SaveLogEnter("GfxDrawSurf");
buffer->align(Utils::Stream::ALIGN_128); buffer->align(Utils::Stream::ALIGN_128);
buffer->save(asset->surfaceCastsSunShadow, 4, asset->sunShadowCount); buffer->save(asset->surfaceCastsSunShadow, 4, asset->surfaceVisDataCount);
Utils::Stream::ClearPointer(&dest->surfaceCastsSunShadow); Utils::Stream::ClearPointer(&dest->surfaceMaterials);
SaveLogExit(); SaveLogExit();
} }

View File

@ -4,14 +4,11 @@ namespace Assets
{ {
void IMapEnts::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) void IMapEnts::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{ {
std::string basename(name); Utils::String::Replace(name, "maps/", "");
Utils::String::Replace(name, "mp/", "");
basename.erase(0, 8); Utils::String::Replace(name, ".d3dbsp", "");
basename.erase(basename.end() - 7, basename.end());
Components::Logger::Print("Using basename %s for mapents %s\n", basename.c_str(), name.c_str()); Components::FileSystem::File ents(Utils::String::VA("mapents/%s.ents", name.c_str()));
Components::FileSystem::File ents(Utils::String::VA("mapents/%s.ents", basename.c_str()));
if (ents.exists()) if (ents.exists())
{ {
Game::MapEnts* entites = builder->getAllocator()->allocate<Game::MapEnts>(); Game::MapEnts* entites = builder->getAllocator()->allocate<Game::MapEnts>();

View File

@ -359,11 +359,11 @@ namespace Assets
Game::cbrush_t* destBrush = &destBrushes[i]; Game::cbrush_t* destBrush = &destBrushes[i];
Game::cbrush_t* brush = &asset->cBrushes[i]; Game::cbrush_t* brush = &asset->cBrushes[i];
if (brush->brushSide) if (brush->sides)
{ {
if (builder->hasPointer(brush->brushSide)) if (builder->hasPointer(brush->sides))
{ {
destBrush->brushSide = builder->getPointer(brush->brushSide); destBrush->sides = builder->getPointer(brush->sides);
} }
else else
{ {
@ -372,41 +372,41 @@ namespace Assets
MessageBoxA(0, "BrushSide shouldn't be written in cBrush!", "WARNING", MB_ICONEXCLAMATION); MessageBoxA(0, "BrushSide shouldn't be written in cBrush!", "WARNING", MB_ICONEXCLAMATION);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(brush->brushSide); builder->storePointer(brush->sides);
Game::cbrushside_t* side = buffer->dest<Game::cbrushside_t>(); Game::cbrushside_t* side = buffer->dest<Game::cbrushside_t>();
buffer->save(brush->brushSide); buffer->save(brush->sides);
if (brush->brushSide->side) if (brush->sides->side)
{ {
if (builder->hasPointer(brush->brushSide->side)) if (builder->hasPointer(brush->sides->side))
{ {
side->side = builder->getPointer(brush->brushSide->side); side->side = builder->getPointer(brush->sides->side);
} }
else else
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(brush->brushSide->side); builder->storePointer(brush->sides->side);
buffer->save(brush->brushSide->side); buffer->save(brush->sides->side);
Utils::Stream::ClearPointer(&side->side); Utils::Stream::ClearPointer(&side->side);
} }
} }
Utils::Stream::ClearPointer(&destBrush->brushSide); Utils::Stream::ClearPointer(&destBrush->sides);
} }
} }
if (brush->brushEdge) if (brush->baseAdjacentSide)
{ {
if (builder->hasPointer(brush->brushEdge)) if (builder->hasPointer(brush->baseAdjacentSide))
{ {
destBrush->brushEdge = builder->getPointer(brush->brushEdge); destBrush->baseAdjacentSide = builder->getPointer(brush->baseAdjacentSide);
} }
else else
{ {
builder->storePointer(brush->brushEdge); builder->storePointer(brush->baseAdjacentSide);
buffer->save(brush->brushEdge); buffer->save(brush->baseAdjacentSide);
Utils::Stream::ClearPointer(&destBrush->brushEdge); Utils::Stream::ClearPointer(&destBrush->baseAdjacentSide);
} }
} }
} }
@ -566,18 +566,16 @@ namespace Assets
builder->loadAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset); builder->loadAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset);
} }
void IclipMap_t::load(Game::XAssetHeader* /*header*/, std::string name, Components::ZoneBuilder::Zone* builder) void IclipMap_t::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{ {
Game::clipMap_t* map = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_CLIPMAP_PVS, name.data()).clipMap; Utils::String::Replace(name, "maps/mp/", "");
if (map) return; Utils::String::Replace(name, ".d3dbsp", "");
std::string basename(name); Components::FileSystem::File clipFile(fmt::sprintf("clipmap/%s.iw4xClipMap", name.data()));
if (!clipFile.exists())
basename.erase(0, 8); {
basename.erase(basename.end() - 7, basename.end()); return;
}
Components::FileSystem::File clipFile(fmt::sprintf("clipmap/%s.iw4xClipMap", basename.data()));
if (!clipFile.exists()) return;
Game::clipMap_t* clipMap = builder->getAllocator()->allocate<Game::clipMap_t>(); Game::clipMap_t* clipMap = builder->getAllocator()->allocate<Game::clipMap_t>();
if (!clipMap) if (!clipMap)
@ -628,17 +626,27 @@ namespace Assets
if (clipMap->numStaticModels) if (clipMap->numStaticModels)
{ {
clipMap->staticModelList = reader.readArray<Game::cStaticModel_t>(clipMap->numStaticModels); clipMap->staticModelList = builder->getAllocator()->allocateArray<Game::cStaticModel_t>(clipMap->numStaticModels);
for (int i = 0; i < clipMap->numStaticModels; ++i)
{
std::string modelName = reader.readString();
if (modelName != "NONE"s)
{
clipMap->staticModelList[i].xmodel = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, modelName, builder).model;
}
float* buf = reader.readArray<float>(18);
memcpy(&clipMap->staticModelList[i].origin, buf, sizeof(float) * 18);
}
} }
if (clipMap->numMaterials) if (clipMap->numMaterials)
{ {
clipMap->materials = builder->getAllocator()->allocateArray<Game::ClipMaterial>(clipMap->numMaterials); clipMap->materials = builder->getAllocator()->allocateArray<Game::ClipMaterial>(clipMap->numMaterials);
for (int i = 0; i < clipMap->numMaterials; ++i) for (int j = 0; j < clipMap->numMaterials; ++j)
{ {
clipMap->materials[i].name = reader.readArray<char>(64); clipMap->materials[j].name = reader.readArray<char>(64);
clipMap->materials[i].unk = reader.read<int>(); clipMap->materials[j].unk = reader.read<int>();
clipMap->materials[i].unk2 = reader.read<int>(); clipMap->materials[j].unk2 = reader.read<int>();
} }
} }
@ -648,7 +656,14 @@ namespace Assets
for (int i = 0; i < clipMap->numCBrushSides; ++i) for (int i = 0; i < clipMap->numCBrushSides; ++i)
{ {
int planeIndex = reader.read<int>(); int planeIndex = reader.read<int>();
if (planeIndex < 0 || planeIndex > clipMap->numCBrushSides) {
Components::Logger::Error("invalid plane index");
return;
}
clipMap->cBrushSides[i].side = &clipMap->cPlanes[planeIndex]; clipMap->cBrushSides[i].side = &clipMap->cPlanes[planeIndex];
reader.read<int>(); // materialNum
reader.read<short>(); // firstAdjacentSide
reader.read<char>(); // edgeCount
// not sure how to fill out texInfo and dispInfo // not sure how to fill out texInfo and dispInfo
// just leave zero for now // just leave zero for now
} }
@ -665,6 +680,11 @@ namespace Assets
for (int i = 0; i < clipMap->numCNodes; ++i) for (int i = 0; i < clipMap->numCNodes; ++i)
{ {
int planeIndex = reader.read<int>(); int planeIndex = reader.read<int>();
if (planeIndex < 0 || planeIndex > clipMap->numCPlanes)
{
Components::Logger::Error("invalid plane index\n");
return;
}
clipMap->cNodes[i].plane = &clipMap->cPlanes[planeIndex]; clipMap->cNodes[i].plane = &clipMap->cPlanes[planeIndex];
clipMap->cNodes[i].children[0] = reader.read<short>(); clipMap->cNodes[i].children[0] = reader.read<short>();
clipMap->cNodes[i].children[1] = reader.read<short>(); clipMap->cNodes[i].children[1] = reader.read<short>();
@ -729,6 +749,11 @@ namespace Assets
if (clipMap->collisionPartitions[i].borderCount > 0) if (clipMap->collisionPartitions[i].borderCount > 0)
{ {
int index = reader.read<int>(); int index = reader.read<int>();
if (index < 0 || index > clipMap->numCollisionBorders)
{
Components::Logger::Error("invalid border index\n");
return;
}
clipMap->collisionPartitions[i].borders = &clipMap->collisionBorders[index]; clipMap->collisionPartitions[i].borders = &clipMap->collisionBorders[index];
} }
} }
@ -747,21 +772,51 @@ namespace Assets
if (clipMap->numCBrushes) if (clipMap->numCBrushes)
{ {
clipMap->cBrushes = builder->getAllocator()->allocateArray<Game::cbrush_t>(clipMap->numCBrushes); clipMap->cBrushes = builder->getAllocator()->allocateArray<Game::cbrush_t>(clipMap->numCBrushes);
memset(clipMap->cBrushes, 0, sizeof(Game::cbrush_t) * clipMap->numCBrushes);
for (int i = 0; i < clipMap->numCBrushes; ++i) for (int i = 0; i < clipMap->numCBrushes; ++i)
{ {
clipMap->cBrushes[i].count = reader.read<int>(); if (i == 134)
if (clipMap->cBrushes[i].count > 0) {
__debugbreak();
}
clipMap->cBrushes[i].numsides = reader.read<unsigned int>() & 0xFFFF; // todo: check for overflow here
if (clipMap->cBrushes[i].numsides > 0)
{ {
int index = reader.read<int>(); int index = reader.read<int>();
clipMap->cBrushes[i].brushSide = &clipMap->cBrushSides[index]; if (index < 0 || index > clipMap->numCBrushSides)
{
Components::Logger::Error("invalid side index\n");
return;
}
clipMap->cBrushes[i].sides = &clipMap->cBrushSides[index];
}
else
{
clipMap->cBrushes[i].sides = nullptr;
} }
int index = reader.read<int>(); int index = reader.read<int>();
clipMap->cBrushes[i].brushEdge = &clipMap->cBrushEdges[index]; if (index > clipMap->numCBrushEdges)
{
Components::Logger::Error("invalid edge index\n");
return;
}
clipMap->cBrushes[i].baseAdjacentSide = &clipMap->cBrushEdges[index];
reader.readArray<short>(6); // don't know where these go char* tmp = reader.readArray<char>(12);
reader.readArray<short>(6); memcpy(&clipMap->cBrushes[i].axialMaterialNum, tmp, 12);
reader.readArray<char>(6);
//todo check for overflow
for (int r = 0; r < 2; ++r)
{
for (int c = 0; c < 3; ++c)
{
clipMap->cBrushes[i].firstAdjacentSideOffsets[r][c] = reader.read<short>() & 0xFF;
}
}
tmp = reader.readArray<char>(6);
memcpy(&clipMap->cBrushes[i].edgeCount, tmp, 6);
} }
clipMap->cBrushBounds = reader.readArray<Game::Bounds>(clipMap->numCBrushes); clipMap->cBrushBounds = reader.readArray<Game::Bounds>(clipMap->numCBrushes);
@ -780,7 +835,7 @@ namespace Assets
std::string tempName = reader.readString(); std::string tempName = reader.readString();
if (tempName != "NONE"s) if (tempName != "NONE"s)
{ {
clipMap->dynEntDefList[x][i].xModel = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, name, builder).model; clipMap->dynEntDefList[x][i].xModel = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, tempName, builder).model;
} }
clipMap->dynEntDefList[x][i].brushModel = reader.read<short>(); clipMap->dynEntDefList[x][i].brushModel = reader.read<short>();
@ -789,13 +844,13 @@ namespace Assets
tempName = reader.readString(); tempName = reader.readString();
if (tempName != "NONE"s) if (tempName != "NONE"s)
{ {
clipMap->dynEntDefList[x][i].destroyFx = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, name, builder).fx; clipMap->dynEntDefList[x][i].destroyFx = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, tempName, builder).fx;
} }
tempName = reader.readString(); tempName = reader.readString();
if (tempName != "NONE"s) if (tempName != "NONE"s)
{ {
clipMap->dynEntDefList[x][i].physPreset = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_PHYSPRESET, name, builder).physPreset; clipMap->dynEntDefList[x][i].physPreset = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_PHYSPRESET, tempName, builder).physPreset;
} }
clipMap->dynEntDefList[x][i].health = reader.read<int>(); clipMap->dynEntDefList[x][i].health = reader.read<int>();
@ -807,6 +862,8 @@ namespace Assets
clipMap->checksum = reader.read<int>(); clipMap->checksum = reader.read<int>();
clipMap->mapEnts = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MAP_ENTS, basename.c_str(), builder).mapEnts; clipMap->mapEnts = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MAP_ENTS, Utils::String::VA("maps/mp/%s.d3dbsp", name.c_str()), builder).mapEnts;
header->clipMap = clipMap;
} }
} }

View File

@ -2381,12 +2381,16 @@ namespace Game
struct cbrush_t struct cbrush_t
{ {
int count; unsigned __int16 numsides;
cbrushside_t * brushSide; unsigned __int16 glassPieceIndex;
char * brushEdge; cbrushside_t *sides;
char pad[24]; char *baseAdjacentSide;
__int16 axialMaterialNum[2][3];
char firstAdjacentSideOffsets[2][3];
char edgeCount[2][3];
}; };
struct cLeaf_t struct cLeaf_t
{ {
unsigned __int16 firstCollAabbIndex; unsigned __int16 firstCollAabbIndex;
@ -2504,9 +2508,12 @@ namespace Game
struct SModelAabbNode struct SModelAabbNode
{ {
char pad[28]; Bounds bounds;
unsigned __int16 firstChild;
unsigned __int16 childCount;
}; };
struct clipMap_t struct clipMap_t
{ {
const char* name; const char* name;
@ -2981,22 +2988,21 @@ namespace Game
struct GfxStaticModelDrawInst; struct GfxStaticModelDrawInst;
struct GfxWorldDpvsStatic struct GfxWorldDpvsStatic
{ {
unsigned int smodelCount; unsigned int smodelCount;
unsigned int staticSurfaceCount; unsigned int staticSurfaceCount;
unsigned int staticSurfaceCountNoDecal; unsigned int staticSurfaceCountNoDecal;
unsigned int litSurfsBegin; unsigned int litOpaqueSurfsBegin;
unsigned int litSurfsEnd; unsigned int litOpaqueSurfsEnd;
unsigned int decalSurfsBegin; unsigned int litTransSurfsBegin;
unsigned int decalSurfsEnd; unsigned int litTransSurfsEnd;
unsigned int shadowCasterSurfsBegin;
unsigned int shadowCasterSurfsEnd;
unsigned int emissiveSurfsBegin; unsigned int emissiveSurfsBegin;
unsigned int emissiveSurfsEnd; unsigned int emissiveSurfsEnd;
unsigned int smodelVisDataCount; unsigned int smodelVisDataCount;
unsigned int surfaceVisDataCount; unsigned int surfaceVisDataCount;
int surfStuff;
int sunShadowCount;
char *smodelVisData[3]; char *smodelVisData[3];
char *surfaceVisData[3]; char *surfaceVisData[3];
unsigned __int16 *sortedSurfIndex; unsigned __int16 *sortedSurfIndex;
@ -3009,6 +3015,7 @@ namespace Game
volatile int usageCount; volatile int usageCount;
}; };
#pragma pack(push, 4) #pragma pack(push, 4)
struct GfxPackedPlacement struct GfxPackedPlacement
{ {