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)
{
// 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" },
{ 0x264A4972, "TweakPlayer" },
{ 0x33B3323A, "TweakGunRes" },
@ -21,7 +20,7 @@ std::unique_ptr<CTweakData> CTweakLoader::LoadCTWK(IInputStream& CTWK, CResource
{ 0xC9954E56, "TweakGuiColors", },
{ 0xE66A4F86, "TweakAutoMapper", },
{ 0xED2E48A9, "TweakGui", },
{ 0xF1ED8FD7, "TweakPlayerControls", }
{ 0xF1ED8FD7, "TweakPlayerControls", },
};
auto Find = skIdToTemplateName.find(pEntry->ID().ToLong());
@ -53,15 +52,16 @@ void CTweakLoader::LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakDa
{
// 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.
uint Magic = NTWK.ReadLong();
uint8 LayerVersion = NTWK.ReadByte();
const uint32 Magic = NTWK.ReadULong();
const uint8 LayerVersion = NTWK.ReadUByte();
if (Magic != FOURCC('NTWK'))
{
errorf("Unrecognized NTWK magic: 0x%08X", Magic);
return;
}
else if (LayerVersion != 1)
if (LayerVersion != 1)
{
errorf("Unrecognized layer version in NTWK: %d", LayerVersion);
return;
@ -71,13 +71,12 @@ void CTweakLoader::LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakDa
ASSERT(pGameTemplate != nullptr);
// 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.
static const std::unordered_map<uint, const char*> skIdToTemplateName =
{
static const std::unordered_map<uint32, const char*> skIdToTemplateName{
{ FOURCC('TWAC'), "TweakAdvancedControls" },
{ FOURCC('TWAM'), "TweakAutoMapper" },
{ FOURCC('TWBL'), "TweakBall" },
@ -102,13 +101,13 @@ void CTweakLoader::LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakDa
{ FOURCC('TWTG'), "TweakTargeting" },
};
uint TweakID = NTWK.ReadLong();
uint16 TweakSize = NTWK.ReadShort();
uint NextTweak = NTWK.Tell() + TweakSize;
const uint32 TweakID = NTWK.ReadULong();
const uint16 TweakSize = NTWK.ReadUShort();
const uint32 NextTweak = NTWK.Tell() + TweakSize;
auto Find = skIdToTemplateName.find(TweakID);
if (Find == skIdToTemplateName.end())
if (Find == skIdToTemplateName.cend())
{
errorf("Unrecognized tweak ID: %s (0x%08X)", *CFourCC(TweakID).ToString(), TweakID);
NTWK.GoTo(NextTweak);
@ -120,7 +119,7 @@ void CTweakLoader::LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakDa
// Load tweak data
NTWK.Skip(0xC);
CTweakData* pTweakData = new CTweakData(pTweakTemplate, TweakID);
auto* pTweakData = new CTweakData(pTweakTemplate, TweakID);
CScriptLoader::LoadStructData(NTWK, pTweakData->TweakData());
OutTweaks.push_back(pTweakData);