This commit is contained in:
TheApadayo 2016-12-21 20:59:37 -05:00
commit f8a50eda81
11 changed files with 127 additions and 83 deletions

View File

@ -399,7 +399,7 @@ namespace Components
dwSize += GetLengthSid(psidArray[0]);
dwSize += sizeof(ACCESS_DENIED_ACE) - sizeof(DWORD);
for (UINT i = 1; i < _countof(psidArray); i++)
for (UINT i = 1; i < _countof(psidArray); ++i)
{
// DWORD is the SidStart field, which is not used for absolute format
dwSize += GetLengthSid(psidArray[i]);

View File

@ -134,15 +134,15 @@ namespace Components
// Fix shader const stuff
if (type == Game::XAssetType::ASSET_TYPE_TECHSET && Zones::Version() >= 359)
{
for (int i = 0; i < 48; i++)
for (int i = 0; i < 48; ++i)
{
if (asset.techniqueSet->techniques[i])
{
for (int j = 0; j < asset.techniqueSet->techniques[i]->numPasses; j++)
for (int j = 0; j < asset.techniqueSet->techniques[i]->numPasses; ++j)
{
Game::MaterialPass* pass = &asset.techniqueSet->techniques[i]->passes[j];
for (int k = 0; k < (pass->argCount1 + pass->argCount2 + pass->argCount3); k++)
for (int k = 0; k < (pass->argCount1 + pass->argCount2 + pass->argCount3); ++k)
{
if (pass->argumentDef[k].type == D3DSHADER_PARAM_REGISTER_TYPE::D3DSPR_CONSTINT)
{
@ -240,7 +240,6 @@ namespace Components
void AssetHandler::OffsetToAlias(Utils::Stream::Offset* offset)
{
// Same here, reinterpret the value, as we're operating inside the game's environment
void* pointer = (*Game::g_streamBlocks)[offset->getUnpackedBlock()].data + offset->getUnpackedOffset();
if (AssetHandler::Relocations.find(pointer) != AssetHandler::Relocations.end())
@ -249,10 +248,6 @@ namespace Components
}
offset->pointer = *reinterpret_cast<void**>(pointer);
#ifdef DEBUG
Game::XAssetHeader zob{ offset->pointer };
#endif
}
void AssetHandler::ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder)

View File

@ -40,7 +40,7 @@ namespace Assets
const Game::GfxImageFileHeader* iwiHeader = reinterpret_cast<const Game::GfxImageFileHeader*>(iwiBuffer.data());
image->mapType = 3;
image->mapType = Game::MAPTYPE_2D;
image->dataLen1 = iwiHeader->fileSizeForPicmip[0] - 32;
image->dataLen2 = iwiHeader->fileSizeForPicmip[0] - 32;
@ -52,7 +52,7 @@ namespace Assets
std::memcpy(image->loadDef->dimensions, iwiHeader->dimensions, 6);
image->loadDef->flags = 0;
image->loadDef->mipLevels = 0;
image->loadDef->levelCount = 0;
switch (iwiHeader->format)
{
@ -93,6 +93,7 @@ namespace Assets
void IGfxImage::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
AssertSize(Game::GfxImage, 32);
AssertSize(Game::MapType, 1);
Utils::Stream* buffer = builder->getBuffer();
Game::GfxImage* asset = header.image;
@ -109,21 +110,18 @@ namespace Assets
buffer->pushBlock(Game::XFILE_BLOCK_TEMP);
if (asset->texture)
if (asset->loadDef)
{
buffer->align(Utils::Stream::ALIGN_4);
Game::GfxImageLoadDef* destTexture = buffer->dest<Game::GfxImageLoadDef>();
buffer->save(asset->loadDef, 16);
buffer->save(asset->loadDef, 16, 1);
builder->incrementExternalSize(asset->loadDef->dataSize);
builder->incrementExternalSize(asset->loadDef->resourceSize);
// Zero the size!
destTexture->dataSize = 0;
if (destTexture->dataSize > 0)
if (destTexture->resourceSize > 0)
{
buffer->save(asset->loadDef->data, asset->loadDef->dataSize);
buffer->save(asset->loadDef->data, asset->loadDef->resourceSize);
}
Utils::Stream::ClearPointer(&dest->loadDef);

View File

@ -85,8 +85,6 @@ namespace Assets
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->unknownImage->name);
}
if (asset->dpvs.surfaces)
{
for (int i = 0; i < asset->dpvsSurfaceCount; ++i)
@ -147,7 +145,7 @@ namespace Assets
if (asset->sceneEntCellBits)
{
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->sceneEntCellBits, 2048, asset->cellCount);
buffer->save(asset->sceneEntCellBits, 1, asset->cellCount << 11);
Utils::Stream::ClearPointer(&dest->sceneEntCellBits);
}
@ -169,12 +167,12 @@ namespace Assets
Game::GfxImage** imageDest = buffer->dest<Game::GfxImage*>();
buffer->saveArray(asset->reflectionImages, asset->reflectionProbeCount);
for (unsigned int i = 0; i < asset->reflectionProbeCount; i++)
for (unsigned int i = 0; i < asset->reflectionProbeCount; ++i)
{
imageDest[i] = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->reflectionImages[i]->name).image;
}
Utils::Stream::ClearPointer(asset->reflectionImages);
Utils::Stream::ClearPointer(&dest->reflectionImages);
}
if (asset->reflectionProbes)
@ -208,7 +206,7 @@ namespace Assets
Game::GfxLightmapArray* lightmapArrayDestTable = buffer->dest<Game::GfxLightmapArray>();
buffer->saveArray(asset->lightmaps, asset->lightmapCount);
for (int i = 0; i < asset->lightmapCount; i++)
for (int i = 0; i < asset->lightmapCount; ++i)
{
Game::GfxLightmapArray* lightmapArrayDest = &lightmapArrayDestTable[i];
Game::GfxLightmapArray* lightmapArray = &asset->lightmaps[i];
@ -224,7 +222,7 @@ namespace Assets
}
}
Utils::Stream::ClearPointer(asset->reflectionImages);
Utils::Stream::ClearPointer(&dest->lightmaps);
}
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
@ -259,26 +257,22 @@ namespace Assets
{
if (asset->vd.vertices)
{
AssertSize(Game::GfxWorldVertex, 44);
buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->vd.vertices, asset->vertexCount);
Utils::Stream::ClearPointer(&dest->vd.vertices);
}
// this one has no if statement on purpouse
buffer->save(&asset->vd.worldVb, 1, 4);
}
// saveGfxWorldVertexLayerData
{
if (asset->vld.data)
{
// no align for char
buffer->saveArray(asset->vld.data, asset->vertexLayerDataSize);
Utils::Stream::ClearPointer(&dest->vld.data);
}
buffer->save(&asset->vld.layerVb, 1, 4);
}
if (asset->indices)
@ -301,7 +295,7 @@ namespace Assets
if (asset->rowDataStart)
{
buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(asset->rowDataStart, (asset->maxs[asset->rowAxis] - asset->mins[asset->rowAxis]) + 2);
buffer->saveArray(asset->rowDataStart, (asset->maxs[asset->rowAxis] - asset->mins[asset->rowAxis]) + 1);
Utils::Stream::ClearPointer(&dest->rowDataStart);
}
@ -404,7 +398,7 @@ namespace Assets
Game::GfxSurface* destSurfaceTable = buffer->dest<Game::GfxSurface>();
buffer->saveArray(asset->surfaces, world->dpvsSurfaceCount);
for (int i = 0; i < world->dpvsSurfaceCount; i++)
for (int i = 0; i < world->dpvsSurfaceCount; ++i)
{
Game::GfxSurface* surface = &asset->surfaces[i];
Game::GfxSurface* destSurface = &destSurfaceTable[i];
@ -435,7 +429,7 @@ namespace Assets
Game::GfxStaticModelDrawInst* destModelTable = buffer->dest<Game::GfxStaticModelDrawInst>();
buffer->saveArray(asset->smodelDrawInsts, asset->smodelCount);
for (unsigned int i = 0; i < asset->smodelCount; i++)
for (unsigned int i = 0; i < asset->smodelCount; ++i)
{
Game::GfxStaticModelDrawInst* model = &asset->smodelDrawInsts[i];
Game::GfxStaticModelDrawInst* destModel = &destModelTable[i];
@ -497,9 +491,9 @@ namespace Assets
}
// this covers [0][0], [1][0], [0][1], [1][1], [0][2], [1][2]
for (char i = 0; i < 3; i++)
for (char i = 0; i < 3; ++i)
{
for (char j = 0; j < 2; j++)
for (char j = 0; j < 2; ++j)
{
if (asset->dynEntVisData[j][i])
{
@ -516,7 +510,7 @@ namespace Assets
void IGfxWorld::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
AssertSize(Game::GfxWorld, 0x274);
AssertSize(Game::GfxWorld, 628);
Utils::Stream* buffer = builder->getBuffer();
SAVE_LOG_ENTER("GfxWorld");
@ -569,7 +563,7 @@ namespace Assets
this->saveGfxWorldDpvsPlanes(asset, &asset->dpvsPlanes, &dest->dpvsPlanes, builder);
uint32_t cellCount = asset->dpvsPlanes.cellCount;
int cellCount = asset->dpvsPlanes.cellCount;
if (asset->aabbTreeCounts)
{
@ -588,7 +582,7 @@ namespace Assets
Game::GfxCellTree* destCellTreeTable = buffer->dest<Game::GfxCellTree>();
buffer->saveArray(asset->aabbTrees, cellCount);
for (unsigned int i = 0; i < cellCount; ++i)
for (int i = 0; i < cellCount; ++i)
{
Game::GfxCellTree* destCellTree = &destCellTreeTable[i];
Game::GfxCellTree* cellTree = &asset->aabbTrees[i];
@ -630,7 +624,6 @@ namespace Assets
Utils::Stream::ClearPointer(&destCellTree->aabbTree);
}
}
Utils::Stream::ClearPointer(&dest->aabbTrees);
@ -644,7 +637,7 @@ namespace Assets
Game::GfxCell* destCellTable = buffer->dest<Game::GfxCell>();
buffer->saveArray(asset->cells, cellCount);
for (unsigned int i = 0; i < cellCount; ++i)
for (int i = 0; i < cellCount; ++i)
{
Game::GfxCell* destCell = &destCellTable[i];
Game::GfxCell* cell = &asset->cells[i];

View File

@ -29,9 +29,9 @@ namespace Assets
}
else
{
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(asset->cPlanes);
buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->cPlanes, asset->numCPlanes);
Utils::Stream::ClearPointer(&dest->cPlanes);
}
@ -93,9 +93,9 @@ namespace Assets
}
else
{
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(sides[i].side);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(sides[i].side);
Utils::Stream::ClearPointer(&sides[i].side);
}
@ -130,9 +130,9 @@ namespace Assets
}
else
{
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(nodes[i].plane);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(nodes[i].plane);
Utils::Stream::ClearPointer(&nodes[i].plane);
}
@ -178,9 +178,9 @@ namespace Assets
}
else
{
buffer->align(Utils::Stream::ALIGN_2);
builder->storePointer(node[i].data.brushes);
buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(node[i].data.brushes, node[i].leafBrushCount);
Utils::Stream::ClearPointer(&node[i].data.brushes);
}
@ -254,9 +254,9 @@ namespace Assets
}
else
{
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(border[i].borders);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(border[i].borders);
Utils::Stream::ClearPointer(&border[i].borders);
}
@ -302,11 +302,11 @@ namespace Assets
}
else
{
builder->storePointer(brushes[i].brushSide);
AssertSize(Game::cbrushside_t, 8);
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(brushes[i].brushSide);
Game::cbrushside_t* side = buffer->dest<Game::cbrushside_t>();
buffer->save(brushes[i].brushSide);
@ -318,9 +318,9 @@ namespace Assets
}
else
{
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(brushes[i].brushSide->side);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(brushes[i].brushSide->side);
Utils::Stream::ClearPointer(&side->side);
}
@ -416,7 +416,7 @@ namespace Assets
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
for (int i = 0; i < 2; i++)
for (int i = 0; i < 2; ++i)
{
if (asset->dynEntPoseList[i])
{
@ -429,7 +429,7 @@ namespace Assets
}
}
for (int i = 0; i < 2; i++)
for (int i = 0; i < 2; ++i)
{
if (asset->dynEntClientList[i])
{
@ -441,7 +441,7 @@ namespace Assets
}
}
for (int i = 0; i < 2; i++)
for (int i = 0; i < 2; ++i)
{
if (asset->dynEntCollList[i])
{
@ -466,7 +466,7 @@ namespace Assets
builder->loadAsset(Game::XAssetType::ASSET_TYPE_XMODEL, m->name);
}
for (int j = 0; j < 2; j++)
for (int j = 0; j < 2; ++j)
{
Game::DynEntityDef* def = asset->dynEntDefList[j];

View File

@ -306,7 +306,7 @@ namespace Components
map.append(fmt::sprintf("mtllib %s.mtl\n\n", world->baseName));
Logger::Print("Writing vertices...\n");
for (unsigned int i = 0; i < world->worldDraw.vertexCount; i++)
for (unsigned int i = 0; i < world->worldDraw.vertexCount; ++i)
{
float x = world->worldDraw.vd.vertices[i].xyz[1];
float y = world->worldDraw.vd.vertices[i].xyz[2];
@ -318,7 +318,7 @@ namespace Components
map.append("\n");
Logger::Print("Writing texture coordinates...\n");
for (unsigned int i = 0; i < world->worldDraw.vertexCount; i++)
for (unsigned int i = 0; i < world->worldDraw.vertexCount; ++i)
{
map.append(fmt::sprintf("vt %.6f %.6f\n", world->worldDraw.vd.vertices[i].texCoord[0], -world->worldDraw.vd.vertices[i].texCoord[1]));
}
@ -327,11 +327,11 @@ namespace Components
int materialCount = 0;
Game::Material** materials = allocator.allocateArray<Game::Material*>(world->dpvs.staticSurfaceCount);
for (unsigned int i = 0; i < world->dpvs.staticSurfaceCount; i++)
for (unsigned int i = 0; i < world->dpvs.staticSurfaceCount; ++i)
{
bool isNewMat = true;
for (int j = 0; j < materialCount; j++)
for (int j = 0; j < materialCount; ++j)
{
if (world->dpvs.surfaces[i].material == materials[j])
{
@ -350,7 +350,7 @@ namespace Components
mtl.append(fmt::sprintf("# Material Count: %d\n", materialCount));
Logger::Print("Exporting materials and faces...\n");
for (int m = 0; m < materialCount; m++)
for (int m = 0; m < materialCount; ++m)
{
std::string name = materials[m]->name;
@ -377,7 +377,7 @@ namespace Components
}
std::string _name = fmt::sprintf("raw/mapdump/%s/textures/%s.png", world->baseName, image->name);
D3DXSaveTextureToFile(std::wstring(_name.begin(), _name.end()).data(), D3DXIFF_PNG, image->texture, NULL);
D3DXSaveTextureToFile(std::wstring(_name.begin(), _name.end()).data(), D3DXIFF_PNG, image->map, NULL);
mtl.append(fmt::sprintf("\nnewmtl %s\n", name.data()));
mtl.append("Ka 1.0000 1.0000 1.0000\n");
@ -386,14 +386,14 @@ namespace Components
mtl.append(fmt::sprintf("map_Ka textures/%s.png\n", image->name));
mtl.append(fmt::sprintf("map_Kd textures/%s.png\n", image->name));
for (unsigned int i = 0; i < world->dpvs.staticSurfaceCount; i++)
for (unsigned int i = 0; i < world->dpvs.staticSurfaceCount; ++i)
{
if (world->dpvs.surfaces[i].material != materials[m])
continue;
int vertOffset = world->dpvs.surfaces[i].tris.firstVertex + 1;//+1 cus obj starts at 1
int indexOffset = world->dpvs.surfaces[i].tris.baseIndex;
for (unsigned short j = 0; j < world->dpvs.surfaces[i].tris.triCount; j++)
for (unsigned short j = 0; j < world->dpvs.surfaces[i].tris.triCount; ++j)
{
int a = world->worldDraw.indices[indexOffset + j * 3 + 0] + vertOffset;
int b = world->worldDraw.indices[indexOffset + j * 3 + 1] + vertOffset;

View File

@ -2,6 +2,8 @@
namespace Components
{
Utils::Memory::Allocator ZoneBuilder::MemAllocator;
std::string ZoneBuilder::TraceZone;
std::vector<std::pair<Game::XAssetType, std::string>> ZoneBuilder::TraceAssets;
@ -316,7 +318,7 @@ namespace Components
this->buffer.enterCriticalSection();
Game::XFile* header = reinterpret_cast<Game::XFile*>(this->buffer.data());
header->size = this->buffer.length() - sizeof(Game::XFile); // Write correct data size
header->externalSize = 0;//this->externalSize; // This actually stores how much external data has to be loaded. It's used to calculate the loadscreen progress
header->externalSize = this->externalSize; // This actually stores how much external data has to be loaded. It's used to calculate the loadscreen progress
// Write stream sizes
for (int i = 0; i < Game::MAX_XFILE_COUNT; ++i)
@ -486,6 +488,25 @@ namespace Components
return AssetTrace;
}
int ZoneBuilder::StoreTexture(Game::GfxImageLoadDef **loadDef, Game::GfxImage *image)
{
size_t size = 16 + (*loadDef)->resourceSize;
void* data = ZoneBuilder::MemAllocator.allocate(size);
std::memcpy(data, *loadDef, size);
image->loadDef = reinterpret_cast<Game::GfxImageLoadDef *>(data);
return 0;
}
void ZoneBuilder::ReleaseTexture(Game::XAssetHeader header)
{
if (header.image && header.image->loadDef)
{
ZoneBuilder::MemAllocator.free(header.image->loadDef);
}
}
ZoneBuilder::ZoneBuilder()
{
AssertSize(Game::XFileHeader, 21);
@ -497,7 +518,13 @@ namespace Components
if (ZoneBuilder::IsEnabled())
{
// Prevent loading textures (preserves loaddef)
Utils::Hook::Set<BYTE>(0x51F4E0, 0xC3);
//Utils::Hook::Set<BYTE>(Game::Load_Texture, 0xC3);
// Store the loaddef
Utils::Hook(Game::Load_Texture, StoreTexture, HOOK_JUMP).install()->quick();
// Release the loaddef
Game::DB_ReleaseXAssetHandlers[Game::XAssetType::ASSET_TYPE_IMAGE] = ZoneBuilder::ReleaseTexture;
//r_loadForrenderer = 0
Utils::Hook::Set<BYTE>(0x519DDF, 0);
@ -620,4 +647,9 @@ namespace Components
});
}
}
ZoneBuilder::~ZoneBuilder()
{
assert(ZoneBuilder::MemAllocator.empty());
}
}

View File

@ -75,6 +75,7 @@ namespace Components
};
ZoneBuilder();
~ZoneBuilder();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* getName() { return "ZoneBuilder"; };
@ -87,5 +88,10 @@ namespace Components
static void BeginAssetTrace(std::string zone);
static std::vector<std::pair<Game::XAssetType, std::string>> EndAssetTrace();
private:
static Utils::Memory::Allocator MemAllocator;
static int StoreTexture(Game::GfxImageLoadDef **loadDef, Game::GfxImage *image);
static void ReleaseTexture(Game::XAssetHeader header);
};
}

View File

@ -1167,7 +1167,7 @@ namespace Components
struct
{
Game::GfxImageLoadDef* texture;
char mapType;
Game::MapType mapType;
char semantic;
char category;
char flags;

View File

@ -285,27 +285,41 @@ namespace Game
int fileSizeForPicmip[4];
};
struct GfxImageLoadDef // actually a IDirect3DTexture* but this is easier
struct __declspec(align(4)) GfxImageLoadDef
{
char mipLevels;
char levelCount;
char flags;
short dimensions[3];
int format; // usually the compression Magic
int dataSize; // set to zero to load from IWD
__int16 dimensions[3];
int format;
int resourceSize;
char data[1];
};
enum MapType : char
{
MAPTYPE_NONE = 0x0,
MAPTYPE_INVALID1 = 0x1,
MAPTYPE_INVALID2 = 0x2,
MAPTYPE_2D = 0x3,
MAPTYPE_3D = 0x4,
MAPTYPE_CUBE = 0x5,
MAPTYPE_COUNT = 0x6,
};
struct GfxImage
{
union
{
GfxImageLoadDef* loadDef;
#ifdef __cplusplus
IDirect3DTexture9* texture;
IDirect3DBaseTexture9 *basemap;
IDirect3DTexture9 *map;
IDirect3DVolumeTexture9 *volmap;
IDirect3DCubeTexture9 *cubemap;
#endif
};
char mapType; // 5 is cube, 4 is 3d, 3 is 2d
MapType mapType;
char semantic;
char category;
char flags;
@ -2948,7 +2962,7 @@ namespace Game
{
GfxPortalWritable writable;
DpvsPlane plane;
float(*vertices)[3];
vec3_t* vertices;
char unknown[2];
char vertexCount;
float hullAxis[2][3];

View File

@ -111,9 +111,15 @@ namespace Utils
char* Stream::save(Game::XFILE_BLOCK_TYPES stream, const void * _str, size_t size, size_t count)
{
//if (stream == XFILE_BLOCK_TEMP || stream == XFILE_BLOCK_VIRTUAL || stream == XFILE_BLOCK_PHYSICAL) // Only those seem to actually write data.
// As I'm not sure though, I'll still write the data
// Use IncreaseBlockSize to fill virtual streams
// Only those seem to actually write data.
// As I'm not sure though, I'll still write the data
// Use IncreaseBlockSize to fill virtual streams
if (stream != Game::XFILE_BLOCK_TEMP && stream != Game::XFILE_BLOCK_VIRTUAL && stream != Game::XFILE_BLOCK_PHYSICAL)
{
this->increaseBlockSize(stream, size * count);
return this->at();
}
auto data = this->data();
if (this->isCriticalSection() && this->length() + (size * count) > this->capacity())