From ee42172389c0aebfbc0c2d5bbabab4ec858bc8cd Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Sat, 23 Jan 2021 14:23:51 -0500 Subject: WIP F3DEX Support, Bug Fixes, Game definable in XML (#75) * WIP F3DEX support * Additional work on F3DEX support, fixed bug with actorlist * Fixed crash bug * Adds ZFile attribute "Game" to be able to change the game mode for ZAPD. * Additional changes to support F3DEX * Fixed bug with cullDL and with dlist type selection * F3DEX Opcode fix * Fixed up a few bugs * Cleaned up some code and fixed bug with directory creation. * ZAPD now supports correct bitpacking for gsSPSetOtherMode on F3DEX * Fixes syntax error in ZDisplayList.h * Updates Actor and Object Lists * Updated actor and object list * G_MTX updated for F3DEX * Fixed bug with transition actor list * Updated G_Texture for F3DEX * SW97 maps: Removes actor 0x22, and shifts actors 0x23 and above down by one to match retail enum. * Fixes issue in reuse of actorCount variable in SetActorList::GetActorListArraySize. Co-authored-by: Kenix3 --- ZAPD/ZFile.cpp | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'ZAPD/ZFile.cpp') diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index aaee5b6..55a5066 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -70,6 +70,24 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b int segment = -1; + // TODO: This should be a variable on the ZFile, but it is a large change in order to force all ZResource types to have a parent ZFile. + const char* gameStr = reader->Attribute("Game"); + if (reader->Attribute("Game") != nullptr) + { + if (string(gameStr) == "MM") + { + Globals::Instance->game = ZGame::MM_RETAIL; + } + else if (string(gameStr) == "SW97" || string(gameStr) == "OOTSW97") + { + Globals::Instance->game = ZGame::OOT_SW97; + } + else + { + // TODO: Error here. + } + } + if (reader->Attribute("BaseAddress") != NULL) baseAddress = (uint32_t)strtoul(StringHelper::Split(reader->Attribute("BaseAddress"), "0x")[1].c_str(), NULL, 16); @@ -144,7 +162,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b ZResource* dList = nullptr; if (mode == ZFileMode::Extract) - dList = ZDisplayList::ExtractFromXML(child, rawData, rawDataIndex, ZDisplayList::GetDListLength(rawData, rawDataIndex), folderName); + dList = ZDisplayList::ExtractFromXML(child, rawData, rawDataIndex, ZDisplayList::GetDListLength(rawData, rawDataIndex, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX), folderName); //else //dList = ZDisplayList::BuildFromXML(child, folderName, mode == ZFileMode::Build); else @@ -1014,6 +1032,9 @@ void ZFile::ProcessDeclarationText(Declaration* decl) if (c == '@' && c2 == 'r') { + if (refIndex >= decl->references.size()) + break; + Declaration* refDecl = GetDeclarationRanged(decl->references[refIndex]); uint32_t refDeclAddr = GetDeclarationRangedAddress(decl->references[refIndex]); @@ -1021,10 +1042,17 @@ void ZFile::ProcessDeclarationText(Declaration* decl) { if (refDecl->isArray) { - int itemSize = refDecl->size / refDecl->arrayItemCnt; - int itemIndex = (decl->references[refIndex] - refDeclAddr) / itemSize; - - decl->text.replace(i, 2, StringHelper::Sprintf("&%s[%i]", refDecl->varName.c_str(), itemIndex)); + if (refDecl->arrayItemCnt != 0) + { + int itemSize = refDecl->size / refDecl->arrayItemCnt; + int itemIndex = (decl->references[refIndex] - refDeclAddr) / itemSize; + + decl->text.replace(i, 2, StringHelper::Sprintf("&%s[%i]", refDecl->varName.c_str(), itemIndex)); + } + else + { + decl->text.replace(i, 2, StringHelper::Sprintf("ERROR ARRAYITEMCNT = 0")); + } } else { -- cgit v1.2.3