CTweakLoader: Make use of unsigned stream helpers

This commit is contained in:
Lioncash 2020-06-20 03:33:03 -04:00
parent 39fd1f8c75
commit f1e115a717
1 changed files with 18 additions and 19 deletions

View File

@ -5,8 +5,7 @@
std::unique_ptr<CTweakData> CTweakLoader::LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry) std::unique_ptr<CTweakData> CTweakLoader::LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry)
{ {
// Find the correct template based on the asset ID. // Find the correct template based on the asset ID.
static const std::unordered_map<uint, const char*> skIdToTemplateName = static const std::unordered_map<uint32, const char*> skIdToTemplateName{
{
{ 0x1D180D7C, "TweakParticle" }, { 0x1D180D7C, "TweakParticle" },
{ 0x264A4972, "TweakPlayer" }, { 0x264A4972, "TweakPlayer" },
{ 0x33B3323A, "TweakGunRes" }, { 0x33B3323A, "TweakGunRes" },
@ -21,7 +20,7 @@ std::unique_ptr<CTweakData> CTweakLoader::LoadCTWK(IInputStream& CTWK, CResource
{ 0xC9954E56, "TweakGuiColors", }, { 0xC9954E56, "TweakGuiColors", },
{ 0xE66A4F86, "TweakAutoMapper", }, { 0xE66A4F86, "TweakAutoMapper", },
{ 0xED2E48A9, "TweakGui", }, { 0xED2E48A9, "TweakGui", },
{ 0xF1ED8FD7, "TweakPlayerControls", } { 0xF1ED8FD7, "TweakPlayerControls", },
}; };
auto Find = skIdToTemplateName.find(pEntry->ID().ToLong()); auto Find = skIdToTemplateName.find(pEntry->ID().ToLong());
@ -53,31 +52,31 @@ void CTweakLoader::LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakDa
{ {
// Validate file. NTWK basically embeds a bunch of tweak objects using the script layers // Validate file. NTWK basically embeds a bunch of tweak objects using the script layers
// format, so it has the same version byte that script layers have. // format, so it has the same version byte that script layers have.
uint Magic = NTWK.ReadLong(); const uint32 Magic = NTWK.ReadULong();
uint8 LayerVersion = NTWK.ReadByte(); const uint8 LayerVersion = NTWK.ReadUByte();
if (Magic != FOURCC('NTWK')) if (Magic != FOURCC('NTWK'))
{ {
errorf("Unrecognized NTWK magic: 0x%08X", Magic); errorf("Unrecognized NTWK magic: 0x%08X", Magic);
return; return;
} }
else if (LayerVersion != 1)
if (LayerVersion != 1)
{ {
errorf("Unrecognized layer version in NTWK: %d", LayerVersion); errorf("Unrecognized layer version in NTWK: %d", LayerVersion);
return; return;
} }
CGameTemplate* pGameTemplate = NGameList::GetGameTemplate( Game ); CGameTemplate* pGameTemplate = NGameList::GetGameTemplate( Game );
ASSERT( pGameTemplate != nullptr ); ASSERT(pGameTemplate != nullptr);
// Start reading tweaks // Start reading tweaks
uint NumTweaks = NTWK.ReadLong(); const uint32 NumTweaks = NTWK.ReadULong();
for (uint TweakIdx = 0; TweakIdx < NumTweaks; TweakIdx++) for (uint32 TweakIdx = 0; TweakIdx < NumTweaks; TweakIdx++)
{ {
// Find the correct template based on the tweak ID. // Find the correct template based on the tweak ID.
static const std::unordered_map<uint, const char*> skIdToTemplateName = static const std::unordered_map<uint32, const char*> skIdToTemplateName{
{
{ FOURCC('TWAC'), "TweakAdvancedControls" }, { FOURCC('TWAC'), "TweakAdvancedControls" },
{ FOURCC('TWAM'), "TweakAutoMapper" }, { FOURCC('TWAM'), "TweakAutoMapper" },
{ FOURCC('TWBL'), "TweakBall" }, { FOURCC('TWBL'), "TweakBall" },
@ -102,26 +101,26 @@ void CTweakLoader::LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakDa
{ FOURCC('TWTG'), "TweakTargeting" }, { FOURCC('TWTG'), "TweakTargeting" },
}; };
uint TweakID = NTWK.ReadLong(); const uint32 TweakID = NTWK.ReadULong();
uint16 TweakSize = NTWK.ReadShort(); const uint16 TweakSize = NTWK.ReadUShort();
uint NextTweak = NTWK.Tell() + TweakSize; const uint32 NextTweak = NTWK.Tell() + TweakSize;
auto Find = skIdToTemplateName.find(TweakID); auto Find = skIdToTemplateName.find(TweakID);
if (Find == skIdToTemplateName.end()) if (Find == skIdToTemplateName.cend())
{ {
errorf("Unrecognized tweak ID: %s (0x%08X)", *CFourCC(TweakID).ToString(), TweakID); errorf("Unrecognized tweak ID: %s (0x%08X)", *CFourCC(TweakID).ToString(), TweakID);
NTWK.GoTo(NextTweak); NTWK.GoTo(NextTweak);
continue; continue;
} }
CScriptTemplate* pTweakTemplate = pGameTemplate->FindMiscTemplate( Find->second ); CScriptTemplate* pTweakTemplate = pGameTemplate->FindMiscTemplate(Find->second);
ASSERT( pTweakTemplate != nullptr ); ASSERT(pTweakTemplate != nullptr);
// Load tweak data // Load tweak data
NTWK.Skip(0xC); NTWK.Skip(0xC);
CTweakData* pTweakData = new CTweakData(pTweakTemplate, TweakID); auto* pTweakData = new CTweakData(pTweakTemplate, TweakID);
CScriptLoader::LoadStructData( NTWK, pTweakData->TweakData() ); CScriptLoader::LoadStructData(NTWK, pTweakData->TweakData());
OutTweaks.push_back(pTweakData); OutTweaks.push_back(pTweakData);
NTWK.GoTo(NextTweak); NTWK.GoTo(NextTweak);