From 80267f8874e83e704963d5f4f23ef98d52f9d405 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 10 Jun 2016 13:52:55 +0200 Subject: [PATCH] Optimize pointer clearing for zonebuilding --- .../Modules/AssetInterfaces/IGfxImage.cpp | 4 +-- .../AssetInterfaces/ILocalizedEntry.cpp | 4 +-- .../Modules/AssetInterfaces/IMapEnts.cpp | 21 +++++++++----- .../Modules/AssetInterfaces/IMaterial.cpp | 16 +++++------ .../AssetInterfaces/IMaterialPixelShader.cpp | 4 +-- .../AssetInterfaces/IMaterialTechniqueSet.cpp | 10 +++---- .../IMaterialVertexDeclaration.cpp | 2 +- .../AssetInterfaces/IMaterialVertexShader.cpp | 4 +-- .../Modules/AssetInterfaces/IPhysCollmap.cpp | 14 +++++----- .../Modules/AssetInterfaces/IPhysPreset.cpp | 4 +-- .../Modules/AssetInterfaces/IRawFile.cpp | 4 +-- .../AssetInterfaces/IStructuredDataDefSet.cpp | 20 ++++++------- .../Modules/AssetInterfaces/IXAnimParts.cpp | 28 +++++++++---------- .../Modules/AssetInterfaces/IXModel.cpp | 25 +++++++++-------- .../Modules/AssetInterfaces/IXModelSurfs.cpp | 18 ++++++------ src/Components/Modules/IPCPipe.cpp | 2 +- src/Components/Modules/QuickPatch.cpp | 3 ++ src/Components/Modules/ZoneBuilder.cpp | 21 +++++++------- src/Utils/Stream.hpp | 8 ++++++ 19 files changed, 115 insertions(+), 97 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IGfxImage.cpp b/src/Components/Modules/AssetInterfaces/IGfxImage.cpp index cce65803..227e20e3 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxImage.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxImage.cpp @@ -100,7 +100,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } buffer->PushBlock(Game::XFILE_BLOCK_TEMP); @@ -115,7 +115,7 @@ namespace Assets // Zero the size! destTexture->dataSize = 0; - dest->texture = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->texture); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/ILocalizedEntry.cpp b/src/Components/Modules/AssetInterfaces/ILocalizedEntry.cpp index c839b0da..7bd89075 100644 --- a/src/Components/Modules/AssetInterfaces/ILocalizedEntry.cpp +++ b/src/Components/Modules/AssetInterfaces/ILocalizedEntry.cpp @@ -16,13 +16,13 @@ namespace Assets if (asset->value) { buffer->SaveString(asset->value); - dest->value = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->value); } if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IMapEnts.cpp b/src/Components/Modules/AssetInterfaces/IMapEnts.cpp index bf1f46fa..1663de4a 100644 --- a/src/Components/Modules/AssetInterfaces/IMapEnts.cpp +++ b/src/Components/Modules/AssetInterfaces/IMapEnts.cpp @@ -40,37 +40,43 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->entityString) { buffer->Save(asset->entityString, asset->numEntityChars); - dest->entityString = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->entityString); } if (asset->trigger.models) { Assert_Size(Game::TriggerModel, 8); buffer->Align(Utils::Stream::ALIGN_4); + buffer->SaveArray(asset->trigger.models, asset->trigger.modelCount); - dest->trigger.models = reinterpret_cast(-1); + + Utils::Stream::ClearPointer(&dest->trigger.models); } if (asset->trigger.hulls) { Assert_Size(Game::TriggerHull, 32); buffer->Align(Utils::Stream::ALIGN_4); + buffer->SaveArray(asset->trigger.hulls, asset->trigger.hullCount); - dest->trigger.hulls = reinterpret_cast(-1); + + Utils::Stream::ClearPointer(&dest->trigger.hulls); } if (asset->trigger.slabs) { Assert_Size(Game::TriggerSlab, 20); buffer->Align(Utils::Stream::ALIGN_4); + buffer->SaveArray(asset->trigger.slabs, asset->trigger.slabCount); - dest->trigger.slabs = reinterpret_cast(-1); + + Utils::Stream::ClearPointer(&dest->trigger.slabs); } if (asset->stages) @@ -88,10 +94,11 @@ namespace Assets Game::Stage* stage = &asset->stages[i]; buffer->SaveString(stage->stageName); - destStage->stageName = reinterpret_cast(-1); + + Utils::Stream::ClearPointer(&destStage->stageName); } - dest->stages = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->stages); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index aaa016d1..8b504a90 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -207,7 +207,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->techniqueSet) @@ -247,22 +247,22 @@ namespace Assets if (water) { buffer->Align(Utils::Stream::ALIGN_4); - buffer->Save(water, sizeof(Game::water_t)); - destTextureDef->info.water = reinterpret_cast(-1); + buffer->Save(water); + Utils::Stream::ClearPointer(&destTextureDef->info.water); // Save_water_t if (water->H0X) { buffer->Align(Utils::Stream::ALIGN_4); buffer->Save(water->H0X, 8, water->M * water->N); - destWater->H0X = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destWater->H0X); } if (water->H0Y) { buffer->Align(Utils::Stream::ALIGN_4); buffer->Save(water->H0Y, 4, water->M * water->N); - destWater->H0Y = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destWater->H0Y); } if (water->image) @@ -277,7 +277,7 @@ namespace Assets } } - dest->textureTable = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->textureTable); } } @@ -295,7 +295,7 @@ namespace Assets builder->StorePointer(asset->constantTable); buffer->SaveArray(asset->constantTable, asset->constantCount); - dest->constantTable = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->constantTable); } } @@ -311,7 +311,7 @@ namespace Assets builder->StorePointer(asset->stateBitTable); buffer->Save(asset->stateBitTable, 8, asset->stateBitsCount); - dest->stateBitTable = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->stateBitTable); } } diff --git a/src/Components/Modules/AssetInterfaces/IMaterialPixelShader.cpp b/src/Components/Modules/AssetInterfaces/IMaterialPixelShader.cpp index a8855118..4db8a4ef 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterialPixelShader.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterialPixelShader.cpp @@ -16,14 +16,14 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->loadDef.physicalPart) { buffer->Align(Utils::Stream::ALIGN_4); buffer->Save(asset->loadDef.physicalPart, 4, asset->loadDef.cachedPartSize & 0xFFFF); - dest->loadDef.physicalPart = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->loadDef.physicalPart); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IMaterialTechniqueSet.cpp b/src/Components/Modules/AssetInterfaces/IMaterialTechniqueSet.cpp index 9bcad7c1..108fe9d3 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterialTechniqueSet.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterialTechniqueSet.cpp @@ -48,7 +48,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } // Save_MaterialTechniquePtrArray @@ -80,7 +80,7 @@ namespace Assets Game::MaterialPass* destPass = buffer->Dest(); Game::MaterialPass* pass = &technique->passes[j]; - buffer->Save(pass, sizeof(Game::MaterialPass)); + buffer->Save(pass); if (pass->vertexDecl) { @@ -101,17 +101,17 @@ namespace Assets { buffer->Align(Utils::Stream::ALIGN_4); buffer->SaveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3); - destPass->argumentDef = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destPass->argumentDef); } } if (technique->name) { buffer->SaveString(technique->name); - destTechnique->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destTechnique->name); } - dest->techniques[i] = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->techniques[i]); } } } diff --git a/src/Components/Modules/AssetInterfaces/IMaterialVertexDeclaration.cpp b/src/Components/Modules/AssetInterfaces/IMaterialVertexDeclaration.cpp index eb8c4b01..0079741e 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterialVertexDeclaration.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterialVertexDeclaration.cpp @@ -16,7 +16,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IMaterialVertexShader.cpp b/src/Components/Modules/AssetInterfaces/IMaterialVertexShader.cpp index 6b47aa58..1bde0268 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterialVertexShader.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterialVertexShader.cpp @@ -16,14 +16,14 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->loadDef.physicalPart) { buffer->Align(Utils::Stream::ALIGN_4); buffer->Save(asset->loadDef.physicalPart, 4, asset->loadDef.cachedPartSize & 0xFFFF); - dest->loadDef.physicalPart = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->loadDef.physicalPart); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IPhysCollmap.cpp b/src/Components/Modules/AssetInterfaces/IPhysCollmap.cpp index 3d6164b4..20bed818 100644 --- a/src/Components/Modules/AssetInterfaces/IPhysCollmap.cpp +++ b/src/Components/Modules/AssetInterfaces/IPhysCollmap.cpp @@ -42,18 +42,18 @@ namespace Assets builder->StorePointer(side->side); buffer->Save(side->side, sizeof(Game::cplane_t)); - destSide->side = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destSide->side); } } } - destBrush->brush.brushSide = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destBrush->brush.brushSide); } if (brush->brush.brushEdge) { buffer->Save(brush->brush.brushEdge, brush->totalEdgeCount); - destBrush->brush.brushEdge = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destBrush->brush.brushEdge); } } @@ -71,7 +71,7 @@ namespace Assets builder->StorePointer(brush->planes); buffer->Save(brush->planes, sizeof(Game::cplane_t)); - destBrush->planes = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destBrush->planes); } } } @@ -95,7 +95,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); IPhysCollmap::Save_BrushWrapper(builder, geom->brush); - destGeom->brush = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destGeom->brush); } } } @@ -114,7 +114,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->geoms) @@ -122,7 +122,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); IPhysCollmap::Save_PhysGeomInfoArray(builder, asset->geoms, asset->count); - dest->geoms = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->geoms); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IPhysPreset.cpp b/src/Components/Modules/AssetInterfaces/IPhysPreset.cpp index 3483af6a..0c16e6f7 100644 --- a/src/Components/Modules/AssetInterfaces/IPhysPreset.cpp +++ b/src/Components/Modules/AssetInterfaces/IPhysPreset.cpp @@ -18,13 +18,13 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->sndAliasPrefix) { buffer->SaveString(asset->sndAliasPrefix); - dest->sndAliasPrefix = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->sndAliasPrefix); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IRawFile.cpp b/src/Components/Modules/AssetInterfaces/IRawFile.cpp index 38c54c1d..863ab2c6 100644 --- a/src/Components/Modules/AssetInterfaces/IRawFile.cpp +++ b/src/Components/Modules/AssetInterfaces/IRawFile.cpp @@ -38,7 +38,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->compressedData) @@ -52,7 +52,7 @@ namespace Assets buffer->Save(asset->compressedData, asset->sizeUnCompressed + 1); } - dest->compressedData = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->compressedData); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.cpp b/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.cpp index 809c2483..a658bfc5 100644 --- a/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.cpp +++ b/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.cpp @@ -30,11 +30,11 @@ namespace Assets if (index->key) { buffer->SaveString(index->key); - destIndex->key = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destIndex->key); } } - destEnum->indices = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destEnum->indices); } } } @@ -67,11 +67,11 @@ namespace Assets if (property->name) { buffer->SaveString(property->name); - destProperty->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destProperty->name); } } - destStruct->property = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destStruct->property); } } } @@ -90,7 +90,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->data) @@ -112,7 +112,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); IStructuredDataDefSet::Save_StructuredDataEnumArray(data->enums, data->numEnums, builder); - destData->enums = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destData->enums); } if (data->structs) @@ -121,7 +121,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); IStructuredDataDefSet::Save_StructuredDataStructArray(data->structs, data->numStructs, builder); - destData->structs = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destData->structs); } if (data->indexedArrays) @@ -130,7 +130,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); buffer->SaveArray(data->indexedArrays, data->numIndexedArrays); - destData->indexedArrays = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destData->indexedArrays); } if (data->enumArrays) @@ -139,11 +139,11 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); buffer->SaveArray(data->enumArrays, data->numEnumArrays); - destData->enumArrays = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destData->enumArrays); } } - dest->data = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->data); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp b/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp index 7c02f919..54e1042a 100644 --- a/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp +++ b/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp @@ -155,7 +155,7 @@ namespace Assets buffer->Save(delta->trans->u.frame0, 12); } - destDelta->trans = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destDelta->trans); } if (delta->quat2) @@ -187,7 +187,7 @@ namespace Assets buffer->Save(delta->quat2->u.frame0, 4); } - destDelta->quat2 = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destDelta->quat2); } if (delta->quat) @@ -219,7 +219,7 @@ namespace Assets buffer->Save(delta->quat->u.frame0, 4); } - destDelta->quat = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destDelta->quat); } } @@ -237,7 +237,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->tagnames) @@ -252,7 +252,7 @@ namespace Assets builder->MapScriptString(&destTagnames[i]); } - dest->tagnames = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->tagnames); } if (asset->notetracks) @@ -268,7 +268,7 @@ namespace Assets builder->MapScriptString(&destNotetracks[i].name); } - dest->notetracks = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->notetracks); } if (asset->delta) @@ -278,47 +278,47 @@ namespace Assets IXAnimParts::Save_XAnimDeltaPart(asset->delta, asset->framecount, builder); - dest->delta = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->delta); } if (asset->dataByte) { buffer->SaveArray(asset->dataByte, asset->dataByteCount); - dest->dataByte = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->delta); } if (asset->dataShort) { buffer->Align(Utils::Stream::ALIGN_2); buffer->SaveArray(asset->dataShort, asset->dataShortCount); - dest->dataShort = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->dataShort); } if (asset->dataInt) { buffer->Align(Utils::Stream::ALIGN_4); buffer->SaveArray(asset->dataInt, asset->dataIntCount); - dest->dataInt = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->dataInt); } if (asset->randomDataShort) { buffer->Align(Utils::Stream::ALIGN_2); buffer->SaveArray(asset->randomDataShort, asset->randomDataShortCount); - dest->randomDataShort = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->randomDataShort); } if (asset->randomDataByte) { buffer->SaveArray(asset->randomDataByte, asset->randomDataByteCount); - dest->randomDataByte = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->randomDataByte); } if (asset->randomDataInt) { buffer->Align(Utils::Stream::ALIGN_4); buffer->SaveArray(asset->randomDataInt, asset->randomDataIntCount); - dest->randomDataInt = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->randomDataInt); } if (asset->indices.data) @@ -333,7 +333,7 @@ namespace Assets buffer->SaveArray(asset->indices._1, asset->indexcount); } - dest->indices.data = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->indices.data); } buffer->PopBlock(); diff --git a/src/Components/Modules/AssetInterfaces/IXModel.cpp b/src/Components/Modules/AssetInterfaces/IXModel.cpp index 28e23702..101146fc 100644 --- a/src/Components/Modules/AssetInterfaces/IXModel.cpp +++ b/src/Components/Modules/AssetInterfaces/IXModel.cpp @@ -205,7 +205,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->boneNames) @@ -220,13 +220,13 @@ namespace Assets builder->MapScriptString(&destBoneNames[i]); } - dest->boneNames = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->boneNames); } if (asset->parentList) { buffer->Save(asset->parentList, asset->numBones - asset->numRootBones); - dest->parentList = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->parentList); } if (asset->tagAngles) @@ -235,7 +235,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_2); buffer->SaveArray(asset->tagAngles, asset->numBones - asset->numRootBones); - dest->tagAngles = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->tagAngles); } if (asset->tagPositions) @@ -244,13 +244,13 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); buffer->SaveArray(asset->tagPositions, asset->numBones - asset->numRootBones); - dest->tagPositions = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->tagPositions); } if (asset->partClassification) { buffer->Save(asset->partClassification, asset->numBones); - dest->partClassification = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->partClassification); } if (asset->animMatrix) @@ -259,7 +259,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); buffer->SaveArray(asset->animMatrix, asset->numBones); - dest->animMatrix = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->animMatrix); } if (asset->materials) @@ -277,7 +277,7 @@ namespace Assets } } - dest->materials = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->materials); } // Save_XModelLodInfoArray @@ -295,7 +295,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); IXModelSurfs().Save({ asset->lods[i].surfaces }, builder); - dest->lods[i].surfaces = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->lods[i].surfaces); buffer->PopBlock(); } @@ -320,12 +320,13 @@ namespace Assets if (colSurf->tris) { buffer->Align(Utils::Stream::ALIGN_4); + buffer->Save(colSurf->tris, 48, colSurf->count); - destColSurf->tris = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destColSurf->tris); } } - dest->colSurf = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->colSurf); } if (asset->boneInfo) @@ -335,7 +336,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_4); buffer->SaveArray(asset->boneInfo, asset->numBones); - dest->boneInfo = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->boneInfo); } if (asset->physPreset) diff --git a/src/Components/Modules/AssetInterfaces/IXModelSurfs.cpp b/src/Components/Modules/AssetInterfaces/IXModelSurfs.cpp index e04b8f7b..ca6759c8 100644 --- a/src/Components/Modules/AssetInterfaces/IXModelSurfs.cpp +++ b/src/Components/Modules/AssetInterfaces/IXModelSurfs.cpp @@ -15,14 +15,14 @@ namespace Assets { buffer->Align(Utils::Stream::ALIGN_16); buffer->Save(entry->node, 16, entry->numNode); - destEntry->node = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destEntry->node); } if (entry->leaf) { buffer->Align(Utils::Stream::ALIGN_2); buffer->SaveArray(entry->leaf, entry->numLeaf); - destEntry->leaf = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destEntry->leaf); } } @@ -34,7 +34,7 @@ namespace Assets { buffer->Align(Utils::Stream::ALIGN_2); buffer->Save(surf->blendInfo, sizeof(short), surf->blendNum1 + (surf->blendNum2 * 3) + (surf->blendNum3 * 5) + (surf->blendNum4 * 7)); - destSurf->blendInfo = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destSurf->blendInfo); } // Access vertex block @@ -45,7 +45,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_16); buffer->SaveArray(surf->vertexBuffer, surf->numVertices); - destSurf->vertexBuffer = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destSurf->vertexBuffer); } buffer->PopBlock(); @@ -68,11 +68,11 @@ namespace Assets { buffer->Align(Utils::Stream::ALIGN_4); IXModelSurfs::Save_XSurfaceCollisionTree(rigidVertList->entry, builder); - destRigidVertList->entry = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destRigidVertList->entry); } } - destSurf->ct = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destSurf->ct); } // Access index block @@ -83,7 +83,7 @@ namespace Assets buffer->Align(Utils::Stream::ALIGN_16); buffer->SaveArray(surf->indexBuffer, surf->numPrimitives); - destSurf->indexBuffer = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&destSurf->indexBuffer); } buffer->PopBlock(); } @@ -102,7 +102,7 @@ namespace Assets if (asset->name) { buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); - dest->name = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->name); } if (asset->surfaces) @@ -119,7 +119,7 @@ namespace Assets IXModelSurfs::Save_XSurface(&asset->surfaces[i], &destSurfaces[i], builder); } - dest->surfaces = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&dest->surfaces); } buffer->PopBlock(); diff --git a/src/Components/Modules/IPCPipe.cpp b/src/Components/Modules/IPCPipe.cpp index 1215e8c2..eabfcde7 100644 --- a/src/Components/Modules/IPCPipe.cpp +++ b/src/Components/Modules/IPCPipe.cpp @@ -132,7 +132,7 @@ namespace Components memset(this->PipeName, 0, sizeof(this->PipeName)); memset(this->PipeFile, 0, sizeof(this->PipeFile)); - strncpy_s(this->PipeName, name.c_str(), sizeof(this->PipeName)); + strncpy_s(this->PipeName, name.data(), sizeof(this->PipeName)); sprintf_s(this->PipeFile, sizeof(this->PipeFile), "\\\\.\\Pipe\\%s", this->PipeName); } diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index ee8c01f8..3c8b8ed1 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -324,6 +324,9 @@ namespace Components // developer_Script 1 Utils::Hook::Set(0x60AE2B, true); + // Disable cheat protection for dvars + Utils::Hook::Set(0x647682, 0xEB); + // Constantly draw the mini console Utils::Hook::Set(0x412A45, 0xEB); Renderer::OnFrame([] () diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index 2aa84ad9..0ea441a3 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -69,7 +69,7 @@ namespace Components { std::string fastfile = DataMap.GetElementAt(i, 1); - if (!Game::DB_IsZoneLoaded(fastfile.c_str())) + if (!Game::DB_IsZoneLoaded(fastfile.data())) { Game::XZoneInfo info; info.name = fastfile.data(); @@ -80,7 +80,7 @@ namespace Components } else { - Logger::Print("Zone '%s' already loaded\n", fastfile.c_str()); + Logger::Print("Zone '%s' already loaded\n", fastfile.data()); } } } @@ -193,7 +193,7 @@ namespace Components Game::XAssetHeader ZoneBuilder::Zone::RequireAsset(Game::XAssetType type, const char* name) { Game::XAssetHeader header; - header.data = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&header.data); int assetIndex = ZoneBuilder::Zone::FindAsset(type, name); @@ -227,7 +227,7 @@ namespace Components Utils::WriteFile(outFile, outBuffer); Logger::Print("done.\n"); - Logger::Print("Zone '%s' written with %d assets\n", outFile.c_str(), ZoneBuilder::Zone::LoadedAssets.size()); + Logger::Print("Zone '%s' written with %d assets\n", outFile.data(), ZoneBuilder::Zone::LoadedAssets.size()); } void ZoneBuilder::Zone::SaveData() @@ -235,13 +235,13 @@ namespace Components // Add header Game::ZoneHeader zoneHeader = { 0 }; zoneHeader.assetList.assetCount = ZoneBuilder::Zone::LoadedAssets.size(); - zoneHeader.assetList.assets = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&zoneHeader.assetList.assets); // Increment ScriptStrings count (for empty script string) if available if (!ZoneBuilder::Zone::ScriptStrings.empty()) { zoneHeader.assetList.stringList.count = ZoneBuilder::Zone::ScriptStrings.size() + 1; - zoneHeader.assetList.stringList.strings = reinterpret_cast(-1); + Utils::Stream::ClearPointer(&zoneHeader.assetList.stringList.strings); } // Write header @@ -267,7 +267,7 @@ namespace Components // Write ScriptStrings for (auto ScriptString : ZoneBuilder::Zone::ScriptStrings) { - ZoneBuilder::Zone::Buffer.SaveString(ScriptString.c_str()); + ZoneBuilder::Zone::Buffer.SaveString(ScriptString.data()); } } @@ -278,11 +278,10 @@ namespace Components // AssetTable for (auto asset : ZoneBuilder::Zone::LoadedAssets) { - Game::XAsset entry; - entry.type = asset.type; - entry.header.data = reinterpret_cast(-1); + Game::XAsset entry = { entry.type, 0 }; + Utils::Stream::ClearPointer(&entry.header.data); - ZoneBuilder::Zone::Buffer.Save(&entry, sizeof(Game::XAsset)); + ZoneBuilder::Zone::Buffer.Save(&entry); } // Assets diff --git a/src/Utils/Stream.hpp b/src/Utils/Stream.hpp index be9fe557..d3a6e7c3 100644 --- a/src/Utils/Stream.hpp +++ b/src/Utils/Stream.hpp @@ -70,6 +70,10 @@ namespace Utils char* Save(const void * _str, size_t size, size_t count = 1); char* Save(Game::XFILE_BLOCK_TYPES stream, const void * _str, size_t size, size_t count); char* Save(Game::XFILE_BLOCK_TYPES stream, int value, size_t count); + template char* Save(T* object) + { + return SaveArray(object, 1); + } template char* SaveArray(T* array, size_t count) { return Save(array, sizeof(T), count); @@ -101,6 +105,10 @@ namespace Utils { return reinterpret_cast(this->At()); } + template static inline void ClearPointer(T** object) + { + *object = reinterpret_cast(-1); + } void ToBuffer(std::string& outBuffer); std::string ToBuffer();