CAreaCooker: Make use of unsigned stream helpers where applicable
Same behavior minus numerous implicit sign conversions.
This commit is contained in:
parent
cf0898792a
commit
4d4f1490b7
|
@ -87,38 +87,42 @@ void CAreaCooker::DetermineSectionNumbersCorruption()
|
||||||
// ************ HEADER ************
|
// ************ HEADER ************
|
||||||
void CAreaCooker::WritePrimeHeader(IOutputStream& rOut)
|
void CAreaCooker::WritePrimeHeader(IOutputStream& rOut)
|
||||||
{
|
{
|
||||||
rOut.WriteLong(0xDEADBEEF);
|
rOut.WriteULong(0xDEADBEEF);
|
||||||
rOut.WriteLong(GetMREAVersion(mVersion));
|
rOut.WriteULong(GetMREAVersion(mVersion));
|
||||||
mpArea->mTransform.Write(rOut);
|
mpArea->mTransform.Write(rOut);
|
||||||
rOut.WriteLong(mpArea->mOriginalWorldMeshCount);
|
rOut.WriteULong(mpArea->mOriginalWorldMeshCount);
|
||||||
if (mVersion >= EGame::Echoes) rOut.WriteLong(mpArea->mScriptLayers.size());
|
if (mVersion >= EGame::Echoes)
|
||||||
rOut.WriteLong(mpArea->mSectionDataBuffers.size());
|
rOut.WriteULong(static_cast<uint32>(mpArea->mScriptLayers.size()));
|
||||||
|
rOut.WriteULong(static_cast<uint32>(mpArea->mSectionDataBuffers.size()));
|
||||||
|
|
||||||
rOut.WriteLong(mGeometrySecNum);
|
rOut.WriteULong(mGeometrySecNum);
|
||||||
rOut.WriteLong(mSCLYSecNum);
|
rOut.WriteULong(mSCLYSecNum);
|
||||||
if (mVersion >= EGame::EchoesDemo) rOut.WriteLong(mSCGNSecNum);
|
if (mVersion >= EGame::EchoesDemo)
|
||||||
rOut.WriteLong(mCollisionSecNum);
|
rOut.WriteULong(mSCGNSecNum);
|
||||||
rOut.WriteLong(mUnknownSecNum);
|
rOut.WriteULong(mCollisionSecNum);
|
||||||
rOut.WriteLong(mLightsSecNum);
|
rOut.WriteULong(mUnknownSecNum);
|
||||||
rOut.WriteLong(mVISISecNum);
|
rOut.WriteULong(mLightsSecNum);
|
||||||
rOut.WriteLong(mPATHSecNum);
|
rOut.WriteULong(mVISISecNum);
|
||||||
if (mVersion <= EGame::Prime) rOut.WriteLong(mAROTSecNum);
|
rOut.WriteULong(mPATHSecNum);
|
||||||
|
if (mVersion <= EGame::Prime)
|
||||||
|
rOut.WriteULong(mAROTSecNum);
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rOut.WriteLong(mFFFFSecNum);
|
rOut.WriteULong(mFFFFSecNum);
|
||||||
rOut.WriteLong(mPTLASecNum);
|
rOut.WriteULong(mPTLASecNum);
|
||||||
rOut.WriteLong(mEGMCSecNum);
|
rOut.WriteULong(mEGMCSecNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mVersion >= EGame::EchoesDemo)
|
if (mVersion >= EGame::EchoesDemo)
|
||||||
{
|
{
|
||||||
if (mVersion >= EGame::Echoes) rOut.WriteLong(mCompressedBlocks.size());
|
if (mVersion >= EGame::Echoes)
|
||||||
|
rOut.WriteULong(static_cast<uint32>(mCompressedBlocks.size()));
|
||||||
rOut.WriteToBoundary(32, 0);
|
rOut.WriteToBoundary(32, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const uint32 size : mSectionSizes)
|
for (const uint32 size : mSectionSizes)
|
||||||
rOut.WriteLong(size);
|
rOut.WriteULong(size);
|
||||||
rOut.WriteToBoundary(32, 0);
|
rOut.WriteToBoundary(32, 0);
|
||||||
|
|
||||||
if (mVersion >= EGame::Echoes)
|
if (mVersion >= EGame::Echoes)
|
||||||
|
@ -127,18 +131,18 @@ void CAreaCooker::WritePrimeHeader(IOutputStream& rOut)
|
||||||
|
|
||||||
void CAreaCooker::WriteCorruptionHeader(IOutputStream& rOut)
|
void CAreaCooker::WriteCorruptionHeader(IOutputStream& rOut)
|
||||||
{
|
{
|
||||||
rOut.WriteLong(0xDEADBEEF);
|
rOut.WriteULong(0xDEADBEEF);
|
||||||
rOut.WriteLong(GetMREAVersion(mVersion));
|
rOut.WriteULong(GetMREAVersion(mVersion));
|
||||||
mpArea->mTransform.Write(rOut);
|
mpArea->mTransform.Write(rOut);
|
||||||
rOut.WriteLong(mpArea->mOriginalWorldMeshCount);
|
rOut.WriteULong(mpArea->mOriginalWorldMeshCount);
|
||||||
rOut.WriteLong(mpArea->mScriptLayers.size());
|
rOut.WriteULong(static_cast<uint32>(mpArea->mScriptLayers.size()));
|
||||||
rOut.WriteLong(mpArea->mSectionDataBuffers.size());
|
rOut.WriteULong(static_cast<uint32>(mpArea->mSectionDataBuffers.size()));
|
||||||
rOut.WriteLong(mCompressedBlocks.size());
|
rOut.WriteULong(static_cast<uint32>(mCompressedBlocks.size()));
|
||||||
rOut.WriteLong(mpArea->mSectionNumbers.size());
|
rOut.WriteULong(static_cast<uint32>(mpArea->mSectionNumbers.size()));
|
||||||
rOut.WriteToBoundary(32, 0);
|
rOut.WriteToBoundary(32, 0);
|
||||||
|
|
||||||
for (const uint32 size : mSectionSizes)
|
for (const uint32 size : mSectionSizes)
|
||||||
rOut.WriteLong(size);
|
rOut.WriteULong(size);
|
||||||
|
|
||||||
rOut.WriteToBoundary(32, 0);
|
rOut.WriteToBoundary(32, 0);
|
||||||
|
|
||||||
|
@ -146,8 +150,8 @@ void CAreaCooker::WriteCorruptionHeader(IOutputStream& rOut)
|
||||||
|
|
||||||
for (const auto& num : mpArea->mSectionNumbers)
|
for (const auto& num : mpArea->mSectionNumbers)
|
||||||
{
|
{
|
||||||
rOut.WriteLong(num.SectionID.ToLong());
|
rOut.WriteULong(num.SectionID.ToLong());
|
||||||
rOut.WriteLong(num.Index);
|
rOut.WriteULong(num.Index);
|
||||||
}
|
}
|
||||||
rOut.WriteToBoundary(32, 0);
|
rOut.WriteToBoundary(32, 0);
|
||||||
}
|
}
|
||||||
|
@ -158,10 +162,10 @@ void CAreaCooker::WriteCompressionHeader(IOutputStream& rOut)
|
||||||
{
|
{
|
||||||
const bool IsCompressed = block.CompressedSize != 0;
|
const bool IsCompressed = block.CompressedSize != 0;
|
||||||
|
|
||||||
rOut.WriteLong(IsCompressed ? block.DecompressedSize + 0x120 : block.DecompressedSize);
|
rOut.WriteULong(IsCompressed ? block.DecompressedSize + 0x120 : block.DecompressedSize);
|
||||||
rOut.WriteLong(block.DecompressedSize);
|
rOut.WriteULong(block.DecompressedSize);
|
||||||
rOut.WriteLong(block.CompressedSize);
|
rOut.WriteULong(block.CompressedSize);
|
||||||
rOut.WriteLong(block.NumSections);
|
rOut.WriteULong(block.NumSections);
|
||||||
}
|
}
|
||||||
|
|
||||||
rOut.WriteToBoundary(32, 0);
|
rOut.WriteToBoundary(32, 0);
|
||||||
|
@ -181,12 +185,12 @@ void CAreaCooker::WritePrimeSCLY(IOutputStream& rOut)
|
||||||
rOut.WriteFourCC( FOURCC('SCLY') );
|
rOut.WriteFourCC( FOURCC('SCLY') );
|
||||||
mVersion <= EGame::Prime ? rOut.WriteLong(1) : rOut.WriteByte(1);
|
mVersion <= EGame::Prime ? rOut.WriteLong(1) : rOut.WriteByte(1);
|
||||||
|
|
||||||
uint32 NumLayers = mpArea->mScriptLayers.size();
|
const auto NumLayers = static_cast<uint32>(mpArea->mScriptLayers.size());
|
||||||
rOut.WriteLong(NumLayers);
|
rOut.WriteULong(NumLayers);
|
||||||
|
|
||||||
uint32 LayerSizesStart = rOut.Tell();
|
const uint32 LayerSizesStart = rOut.Tell();
|
||||||
for (uint32 LayerIdx = 0; LayerIdx < NumLayers; LayerIdx++)
|
for (uint32 LayerIdx = 0; LayerIdx < NumLayers; LayerIdx++)
|
||||||
rOut.WriteLong(0);
|
rOut.WriteULong(0);
|
||||||
|
|
||||||
// SCLY
|
// SCLY
|
||||||
CScriptCooker ScriptCooker(mVersion, true);
|
CScriptCooker ScriptCooker(mVersion, true);
|
||||||
|
@ -194,13 +198,13 @@ void CAreaCooker::WritePrimeSCLY(IOutputStream& rOut)
|
||||||
|
|
||||||
for (uint32 LayerIdx = 0; LayerIdx < NumLayers; LayerIdx++)
|
for (uint32 LayerIdx = 0; LayerIdx < NumLayers; LayerIdx++)
|
||||||
{
|
{
|
||||||
uint32 LayerStart = rOut.Tell();
|
const uint32 LayerStart = rOut.Tell();
|
||||||
ScriptCooker.WriteLayer(rOut, mpArea->mScriptLayers[LayerIdx].get());
|
ScriptCooker.WriteLayer(rOut, mpArea->mScriptLayers[LayerIdx].get());
|
||||||
|
|
||||||
// Pad the layer to 32 bytes
|
// Pad the layer to 32 bytes
|
||||||
uint32 LayerSize = rOut.Tell() - LayerStart;
|
const uint32 LayerSize = rOut.Tell() - LayerStart;
|
||||||
uint32 PaddedSize = (LayerSize + 31) & ~31;
|
const uint32 PaddedSize = (LayerSize + 31) & ~31;
|
||||||
uint32 NumPadBytes = PaddedSize - LayerSize;
|
const uint32 NumPadBytes = PaddedSize - LayerSize;
|
||||||
|
|
||||||
for (uint32 Pad = 0; Pad < NumPadBytes; Pad++)
|
for (uint32 Pad = 0; Pad < NumPadBytes; Pad++)
|
||||||
rOut.WriteByte(0);
|
rOut.WriteByte(0);
|
||||||
|
@ -208,11 +212,11 @@ void CAreaCooker::WritePrimeSCLY(IOutputStream& rOut)
|
||||||
LayerSizes[LayerIdx] = PaddedSize;
|
LayerSizes[LayerIdx] = PaddedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 LayersEnd = rOut.Tell();
|
const uint32 LayersEnd = rOut.Tell();
|
||||||
rOut.Seek(LayerSizesStart, SEEK_SET);
|
rOut.Seek(LayerSizesStart, SEEK_SET);
|
||||||
|
|
||||||
for (uint32 LayerIdx = 0; LayerIdx < NumLayers; LayerIdx++)
|
for (uint32 LayerIdx = 0; LayerIdx < NumLayers; LayerIdx++)
|
||||||
rOut.WriteLong(LayerSizes[LayerIdx]);
|
rOut.WriteULong(LayerSizes[LayerIdx]);
|
||||||
|
|
||||||
rOut.Seek(LayersEnd, SEEK_SET);
|
rOut.Seek(LayersEnd, SEEK_SET);
|
||||||
FinishSection(false);
|
FinishSection(false);
|
||||||
|
@ -221,7 +225,7 @@ void CAreaCooker::WritePrimeSCLY(IOutputStream& rOut)
|
||||||
if (mVersion == EGame::EchoesDemo)
|
if (mVersion == EGame::EchoesDemo)
|
||||||
{
|
{
|
||||||
rOut.WriteFourCC(FOURCC('SCGN'));
|
rOut.WriteFourCC(FOURCC('SCGN'));
|
||||||
rOut.WriteByte(1);
|
rOut.WriteUByte(1);
|
||||||
ScriptCooker.WriteGeneratedLayer(rOut);
|
ScriptCooker.WriteGeneratedLayer(rOut);
|
||||||
FinishSection(false);
|
FinishSection(false);
|
||||||
}
|
}
|
||||||
|
@ -235,15 +239,15 @@ void CAreaCooker::WriteEchoesSCLY(IOutputStream& rOut)
|
||||||
for (uint32 LayerIdx = 0; LayerIdx < mpArea->mScriptLayers.size(); LayerIdx++)
|
for (uint32 LayerIdx = 0; LayerIdx < mpArea->mScriptLayers.size(); LayerIdx++)
|
||||||
{
|
{
|
||||||
rOut.WriteFourCC(FOURCC('SCLY'));
|
rOut.WriteFourCC(FOURCC('SCLY'));
|
||||||
rOut.WriteByte(1);
|
rOut.WriteUByte(1);
|
||||||
rOut.WriteLong(LayerIdx);
|
rOut.WriteULong(LayerIdx);
|
||||||
ScriptCooker.WriteLayer(rOut, mpArea->mScriptLayers[LayerIdx].get());
|
ScriptCooker.WriteLayer(rOut, mpArea->mScriptLayers[LayerIdx].get());
|
||||||
FinishSection(true);
|
FinishSection(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SCGN
|
// SCGN
|
||||||
rOut.WriteFourCC(FOURCC('SCGN'));
|
rOut.WriteFourCC(FOURCC('SCGN'));
|
||||||
rOut.WriteByte(1);
|
rOut.WriteUByte(1);
|
||||||
ScriptCooker.WriteGeneratedLayer(rOut);
|
ScriptCooker.WriteGeneratedLayer(rOut);
|
||||||
FinishSection(true);
|
FinishSection(true);
|
||||||
}
|
}
|
||||||
|
@ -258,7 +262,7 @@ void CAreaCooker::WriteDependencies(IOutputStream& rOut)
|
||||||
Builder.BuildDependencyList(Dependencies, LayerOffsets);
|
Builder.BuildDependencyList(Dependencies, LayerOffsets);
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
rOut.WriteLong(Dependencies.size());
|
rOut.WriteULong(static_cast<uint32>(Dependencies.size()));
|
||||||
|
|
||||||
for (const auto& dependency : Dependencies)
|
for (const auto& dependency : Dependencies)
|
||||||
{
|
{
|
||||||
|
@ -267,10 +271,10 @@ void CAreaCooker::WriteDependencies(IOutputStream& rOut)
|
||||||
pEntry->CookedExtension().Write(rOut);
|
pEntry->CookedExtension().Write(rOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
rOut.WriteLong(LayerOffsets.size());
|
rOut.WriteULong(static_cast<uint32>(LayerOffsets.size()));
|
||||||
|
|
||||||
for (const uint32 offset : LayerOffsets)
|
for (const uint32 offset : LayerOffsets)
|
||||||
rOut.WriteLong(offset);
|
rOut.WriteULong(offset);
|
||||||
|
|
||||||
FinishSection(false);
|
FinishSection(false);
|
||||||
}
|
}
|
||||||
|
@ -285,15 +289,15 @@ void CAreaCooker::WriteModules(IOutputStream& rOut)
|
||||||
pAreaDeps->GetModuleDependencies(mpArea->Game(), ModuleNames, LayerOffsets);
|
pAreaDeps->GetModuleDependencies(mpArea->Game(), ModuleNames, LayerOffsets);
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
rOut.WriteLong(ModuleNames.size());
|
rOut.WriteULong(static_cast<uint32>(ModuleNames.size()));
|
||||||
|
|
||||||
for (const auto& name : ModuleNames)
|
for (const auto& name : ModuleNames)
|
||||||
rOut.WriteString(name);
|
rOut.WriteString(name);
|
||||||
|
|
||||||
rOut.WriteLong(LayerOffsets.size());
|
rOut.WriteULong(static_cast<uint32>(LayerOffsets.size()));
|
||||||
|
|
||||||
for (const uint32 offset : LayerOffsets)
|
for (const uint32 offset : LayerOffsets)
|
||||||
rOut.WriteLong(offset);
|
rOut.WriteULong(offset);
|
||||||
|
|
||||||
FinishSection(false);
|
FinishSection(false);
|
||||||
}
|
}
|
||||||
|
@ -313,7 +317,7 @@ void CAreaCooker::FinishSection(bool SingleSectionBlock)
|
||||||
const uint32 kSizeThreshold = 0x20000;
|
const uint32 kSizeThreshold = 0x20000;
|
||||||
mSectionData.WriteToBoundary(32, 0);
|
mSectionData.WriteToBoundary(32, 0);
|
||||||
|
|
||||||
uint32 SecSize = mSectionData.Size();
|
const uint32 SecSize = mSectionData.Size();
|
||||||
mSectionSizes.push_back(SecSize);
|
mSectionSizes.push_back(SecSize);
|
||||||
|
|
||||||
// Only track compressed blocks for MP2+. Write everything to one block for MP1.
|
// Only track compressed blocks for MP2+. Write everything to one block for MP1.
|
||||||
|
@ -329,8 +333,10 @@ void CAreaCooker::FinishSection(bool SingleSectionBlock)
|
||||||
if (SingleSectionBlock)
|
if (SingleSectionBlock)
|
||||||
FinishBlock();
|
FinishBlock();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
else AddSectionToBlock();
|
{
|
||||||
|
AddSectionToBlock();
|
||||||
|
}
|
||||||
|
|
||||||
mSectionData.Clear();
|
mSectionData.Clear();
|
||||||
}
|
}
|
||||||
|
@ -340,17 +346,17 @@ void CAreaCooker::FinishBlock()
|
||||||
if (mCurBlock.NumSections == 0) return;
|
if (mCurBlock.NumSections == 0) return;
|
||||||
|
|
||||||
std::vector<uint8> CompressedBuf(mCompressedData.Size() * 2);
|
std::vector<uint8> CompressedBuf(mCompressedData.Size() * 2);
|
||||||
bool EnableCompression = (mVersion >= EGame::Echoes) && mpArea->mUsesCompression && !gkForceDisableCompression;
|
const bool EnableCompression = (mVersion >= EGame::Echoes) && mpArea->mUsesCompression && !gkForceDisableCompression;
|
||||||
bool UseZlib = (mVersion == EGame::DKCReturns);
|
const bool UseZlib = (mVersion == EGame::DKCReturns);
|
||||||
|
|
||||||
uint32 CompressedSize = 0;
|
uint32 CompressedSize = 0;
|
||||||
bool WriteCompressedData = false;
|
bool WriteCompressedData = false;
|
||||||
|
|
||||||
if (EnableCompression)
|
if (EnableCompression)
|
||||||
{
|
{
|
||||||
bool Success = CompressionUtil::CompressSegmentedData((uint8*) mCompressedData.Data(), mCompressedData.Size(), CompressedBuf.data(), CompressedSize, UseZlib, true);
|
const bool Success = CompressionUtil::CompressSegmentedData(static_cast<uint8*>(mCompressedData.Data()), mCompressedData.Size(), CompressedBuf.data(), CompressedSize, UseZlib, true);
|
||||||
uint32 PadBytes = (32 - (CompressedSize % 32)) & 0x1F;
|
const uint32 PadBytes = (32 - (CompressedSize % 32)) & 0x1F;
|
||||||
WriteCompressedData = Success && (CompressedSize + PadBytes < (uint32) mCompressedData.Size());
|
WriteCompressedData = Success && (CompressedSize + PadBytes < static_cast<uint32>(mCompressedData.Size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WriteCompressedData)
|
if (WriteCompressedData)
|
||||||
|
@ -359,7 +365,7 @@ void CAreaCooker::FinishBlock()
|
||||||
PadBytes &= 0x1F;
|
PadBytes &= 0x1F;
|
||||||
|
|
||||||
for (uint32 iPad = 0; iPad < PadBytes; iPad++)
|
for (uint32 iPad = 0; iPad < PadBytes; iPad++)
|
||||||
mAreaData.WriteByte(0);
|
mAreaData.WriteUByte(0);
|
||||||
|
|
||||||
mAreaData.WriteBytes(CompressedBuf.data(), CompressedSize);
|
mAreaData.WriteBytes(CompressedBuf.data(), CompressedSize);
|
||||||
mCurBlock.CompressedSize = CompressedSize;
|
mCurBlock.CompressedSize = CompressedSize;
|
||||||
|
@ -409,12 +415,13 @@ bool CAreaCooker::CookMREA(CGameArea *pArea, IOutputStream& rOut)
|
||||||
Cooker.WriteEchoesSCLY(Cooker.mSectionData);
|
Cooker.WriteEchoesSCLY(Cooker.mSectionData);
|
||||||
|
|
||||||
// Write post-SCLY data sections
|
// Write post-SCLY data sections
|
||||||
uint32 PostSCLY = (Cooker.mVersion <= EGame::Prime ? Cooker.mSCLYSecNum + 1 : Cooker.mSCGNSecNum + 1);
|
const uint32 PostSCLY = (Cooker.mVersion <= EGame::Prime ? Cooker.mSCLYSecNum + 1 : Cooker.mSCGNSecNum + 1);
|
||||||
for (uint32 iSec = PostSCLY; iSec < pArea->mSectionDataBuffers.size(); iSec++)
|
for (size_t iSec = PostSCLY; iSec < pArea->mSectionDataBuffers.size(); iSec++)
|
||||||
{
|
{
|
||||||
if (iSec == Cooker.mModulesSecNum)
|
if (iSec == Cooker.mModulesSecNum)
|
||||||
|
{
|
||||||
Cooker.WriteModules(Cooker.mSectionData);
|
Cooker.WriteModules(Cooker.mSectionData);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Cooker.mSectionData.WriteBytes(pArea->mSectionDataBuffers[iSec].data(), pArea->mSectionDataBuffers[iSec].size());
|
Cooker.mSectionData.WriteBytes(pArea->mSectionDataBuffers[iSec].data(), pArea->mSectionDataBuffers[iSec].size());
|
||||||
|
|
Loading…
Reference in New Issue