summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouist103 <35883445+louist103@users.noreply.github.com>2022-12-05 23:19:25 -0500
committerGitHub <noreply@github.com>2022-12-05 23:19:25 -0500
commita80f36ca0f003a3901fc781505f707ca2ef4c63a (patch)
tree2b9cec4c873c194ada5449f276a18bf0090483be
parent645444f209bfeca025b3862548a59d31ef9bca08 (diff)
Read from an external file for entrance lists (#271)
* Read from entrance list file * Remove switch. * Add check for special entrances. * Ignore warning for GCC in specific spot. * u
-rw-r--r--ZAPD/CrashHandler.cpp33
-rw-r--r--ZAPD/GameConfig.cpp24
-rw-r--r--ZAPD/GameConfig.h4
-rw-r--r--ZAPD/ZFile.cpp6
-rw-r--r--ZAPD/ZRoom/Commands/SetActorList.h3
-rw-r--r--ZAPD/ZRoom/Commands/SetExitList.cpp4
-rw-r--r--ZAPD/ZRoom/Commands/SetRoomList.cpp5
-rw-r--r--ZAPD/ZRoom/ZNames.h25
-rw-r--r--ZAPDUtils/Utils/File.h2
-rw-r--r--ZAPDUtils/Utils/StringHelper.h2
10 files changed, 76 insertions, 32 deletions
diff --git a/ZAPD/CrashHandler.cpp b/ZAPD/CrashHandler.cpp
index b1b4a47..3568665 100644
--- a/ZAPD/CrashHandler.cpp
+++ b/ZAPD/CrashHandler.cpp
@@ -27,28 +27,27 @@
#pragma comment(lib, "Dbghelp.lib")
#endif
-
// Feel free to add more crash messages.
static std::array<const char* const, 14> crashEasterEgg = {
"\tYou've met with a terrible fate, haven't you?",
"\tSEA BEARS FOAM. SLEEP BEARS DREAMS. \n\tBOTH END IN THE SAME WAY: CRASSSH!",
"\tZAPD has fallen and cannot get up.",
"\tIT'S A SECRET TO EVERYBODY. \n\tBut it shouldn't be, you'd better ask about it!",
- "\tI AM ERROR.",
- "\tGRUMBLE,GRUMBLE...",
- "\tDODONGO DISLIKES SMOKE \n\tAnd ZAPD dislikes whatever you fed it.",
- "\tMay the way of the Hero lead \n\tto the debugger.",
- "\tTHE WIND FISH SLUMBERS LONG... \n\tTHE HERO'S LIFE GONE... ",
- "\tSEA BEARS FOAM, SLEEP BEARS DREAMS. \n\tBOTH END IN THE SAME WAY CRASSSH!",
- "\tYou've met with a terrible fate, haven't you?",
- "\tMaster, I calculate a 100% probability that ZAPD has crashed. \n\tAdditionally, the "
- "batteries in your Wii Remote are nearly depleted.",
- "\t CONGRATURATIONS! \n"
- "\tAll Pages are displayed.\n"
- "\t THANK YOU! \n"
- "\t You are great debugger!",
- "\tRCP is HUNG UP!!\n"
- "\tOh! MY GOD!!",
+ "\tI AM ERROR.",
+ "\tGRUMBLE,GRUMBLE...",
+ "\tDODONGO DISLIKES SMOKE \n\tAnd ZAPD dislikes whatever you fed it.",
+ "\tMay the way of the Hero lead \n\tto the debugger.",
+ "\tTHE WIND FISH SLUMBERS LONG... \n\tTHE HERO'S LIFE GONE... ",
+ "\tSEA BEARS FOAM, SLEEP BEARS DREAMS. \n\tBOTH END IN THE SAME WAY CRASSSH!",
+ "\tYou've met with a terrible fate, haven't you?",
+ "\tMaster, I calculate a 100% probability that ZAPD has crashed. \n\tAdditionally, the "
+ "batteries in your Wii Remote are nearly depleted.",
+ "\t CONGRATURATIONS! \n"
+ "\tAll Pages are displayed.\n"
+ "\t THANK YOU! \n"
+ "\t You are great debugger!",
+ "\tRCP is HUNG UP!!\n"
+ "\tOh! MY GOD!!",
};
#if HAS_POSIX == 1
@@ -204,5 +203,3 @@ void CrashHandler_Init()
"tried to set error handler, but this ZAPD build lacks support for one", "");
#endif
}
-
-
diff --git a/ZAPD/GameConfig.cpp b/ZAPD/GameConfig.cpp
index ae29ba2..777cf9d 100644
--- a/ZAPD/GameConfig.cpp
+++ b/ZAPD/GameConfig.cpp
@@ -94,6 +94,26 @@ void GameConfig::ConfigFunc_ObjectList(const tinyxml2::XMLElement& element)
objectList.emplace_back(std::move(line));
}
+void GameConfig::ConfigFunc_EntranceList(const tinyxml2::XMLElement& element)
+{
+ std::string fileName = element.Attribute("File");
+ std::vector<std::string> lines =
+ File::ReadAllLines(Path::GetDirectoryName(configFilePath) / fileName);
+
+ for (auto& line : lines)
+ entranceList.emplace_back(std::move(line));
+}
+
+void GameConfig::ConfigFunc_specialEntranceList(const tinyxml2::XMLElement& element)
+{
+ std::string fileName = element.Attribute("File");
+ std::vector<std::string> lines =
+ File::ReadAllLines(Path::GetDirectoryName(configFilePath) / fileName);
+
+ for (auto& line : lines)
+ specialEntranceList.emplace_back(std::move(line));
+}
+
void GameConfig::ConfigFunc_TexturePool(const tinyxml2::XMLElement& element)
{
std::string fileName = element.Attribute("File");
@@ -145,10 +165,12 @@ void GameConfig::ConfigFunc_ExternalFile(const tinyxml2::XMLElement& element)
void GameConfig::ReadConfigFile(const fs::path& argConfigFilePath)
{
- static const std::map<std::string, ConfigFunc> ConfigFuncDictionary = {
+ static const std::unordered_map<std::string, ConfigFunc> ConfigFuncDictionary = {
{"SymbolMap", &GameConfig::ConfigFunc_SymbolMap},
{"ActorList", &GameConfig::ConfigFunc_ActorList},
{"ObjectList", &GameConfig::ConfigFunc_ObjectList},
+ {"EntranceList", &GameConfig::ConfigFunc_EntranceList},
+ {"SpecialEntranceList", &GameConfig::ConfigFunc_specialEntranceList},
{"TexturePool", &GameConfig::ConfigFunc_TexturePool},
{"BGConfig", &GameConfig::ConfigFunc_BGConfig},
{"ExternalXMLFolder", &GameConfig::ConfigFunc_ExternalXMLFolder},
diff --git a/ZAPD/GameConfig.h b/ZAPD/GameConfig.h
index c478d16..2a783d1 100644
--- a/ZAPD/GameConfig.h
+++ b/ZAPD/GameConfig.h
@@ -31,6 +31,8 @@ public:
std::map<uint32_t, std::string> symbolMap;
std::vector<std::string> actorList;
std::vector<std::string> objectList;
+ std::vector<std::string> entranceList;
+ std::vector<std::string> specialEntranceList;
std::map<uint32_t, TexturePoolEntry> texturePool; // Key = CRC
// ZBackground
@@ -49,6 +51,8 @@ public:
void ConfigFunc_SymbolMap(const tinyxml2::XMLElement& element);
void ConfigFunc_ActorList(const tinyxml2::XMLElement& element);
void ConfigFunc_ObjectList(const tinyxml2::XMLElement& element);
+ void ConfigFunc_EntranceList(const tinyxml2::XMLElement& element);
+ void ConfigFunc_specialEntranceList(const tinyxml2::XMLElement& element);
void ConfigFunc_TexturePool(const tinyxml2::XMLElement& element);
void ConfigFunc_BGConfig(const tinyxml2::XMLElement& element);
void ConfigFunc_ExternalXMLFolder(const tinyxml2::XMLElement& element);
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp
index 60382f6..0977650 100644
--- a/ZAPD/ZFile.cpp
+++ b/ZAPD/ZFile.cpp
@@ -216,7 +216,9 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename)
std::string offsetStr = StringHelper::Split(offsetXml, "0x")[1];
if (!StringHelper::HasOnlyHexDigits(offsetStr))
{
- HANDLE_ERROR(WarningType::InvalidXML, StringHelper::Sprintf("Invalid offset %s entered", offsetStr.c_str()), "");
+ HANDLE_ERROR(WarningType::InvalidXML,
+ StringHelper::Sprintf("Invalid offset %s entered", offsetStr.c_str()),
+ "");
}
rawDataIndex = strtol(offsetStr.c_str(), NULL, 16);
@@ -426,7 +428,7 @@ std::vector<ZResource*> ZFile::GetResourcesOfType(ZResourceType resType)
{
std::vector<ZResource*> resList;
resList.reserve(resources.size());
-
+
for (ZResource* res : resources)
{
if (res->GetResourceType() == resType)
diff --git a/ZAPD/ZRoom/Commands/SetActorList.h b/ZAPD/ZRoom/Commands/SetActorList.h
index 4d21616..9122c15 100644
--- a/ZAPD/ZRoom/Commands/SetActorList.h
+++ b/ZAPD/ZRoom/Commands/SetActorList.h
@@ -1,7 +1,7 @@
#pragma once
-#include "ZRoom/ZRoomCommand.h"
#include "ZActorList.h"
+#include "ZRoom/ZRoomCommand.h"
class SetActorList : public ZRoomCommand
{
@@ -14,7 +14,6 @@ public:
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
-
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
diff --git a/ZAPD/ZRoom/Commands/SetExitList.cpp b/ZAPD/ZRoom/Commands/SetExitList.cpp
index f94ef21..80ccc6b 100644
--- a/ZAPD/ZRoom/Commands/SetExitList.cpp
+++ b/ZAPD/ZRoom/Commands/SetExitList.cpp
@@ -4,6 +4,7 @@
#include "Utils/BitConverter.h"
#include "Utils/StringHelper.h"
#include "ZFile.h"
+#include "ZRoom/ZNames.h"
#include "ZRoom/ZRoom.h"
SetExitList::SetExitList(ZFile* nParent) : ZRoomCommand(nParent)
@@ -44,7 +45,8 @@ void SetExitList::DeclareReferencesLate([[maybe_unused]] const std::string& pref
for (size_t i = 0; i < exits.size(); i++)
{
- declaration += StringHelper::Sprintf(" 0x%04X,", exits.at(i));
+ declaration +=
+ StringHelper::Sprintf(" %s,", ZNames::GetEntranceName(exits[i]).c_str());
if (i + 1 < exits.size())
declaration += "\n";
}
diff --git a/ZAPD/ZRoom/Commands/SetRoomList.cpp b/ZAPD/ZRoom/Commands/SetRoomList.cpp
index 3e68202..24969a1 100644
--- a/ZAPD/ZRoom/Commands/SetRoomList.cpp
+++ b/ZAPD/ZRoom/Commands/SetRoomList.cpp
@@ -105,8 +105,9 @@ std::string RomFile::GetBodySourceCode() const
if (!isFirst)
declaration += "\n";
- declaration += StringHelper::Sprintf("\t{ (uintptr_t)_%sSegmentRomStart, (uintptr_t)_%sSegmentRomEnd },",
- roomName.c_str(), roomName.c_str());
+ declaration += StringHelper::Sprintf(
+ "\t{ (uintptr_t)_%sSegmentRomStart, (uintptr_t)_%sSegmentRomEnd },",
+ roomName.c_str(), roomName.c_str());
isFirst = false;
}
}
diff --git a/ZAPD/ZRoom/ZNames.h b/ZAPD/ZRoom/ZNames.h
index 94e08de..667407c 100644
--- a/ZAPD/ZRoom/ZNames.h
+++ b/ZAPD/ZRoom/ZNames.h
@@ -12,17 +12,17 @@ public:
{
if (id >= Globals::Instance->cfg.objectList.size())
return StringHelper::Sprintf("0x%04X", id);
- return Globals::Instance->cfg.objectList.at(id);
+ return Globals::Instance->cfg.objectList[id];
}
- static std::string GetActorName(int32_t id)
+ static std::string GetActorName(uint16_t id)
{
switch (Globals::Instance->game)
{
case ZGame::OOT_RETAIL:
case ZGame::OOT_SW97:
if (id < ZNames::GetNumActors())
- return Globals::Instance->cfg.actorList.at(id);
+ return Globals::Instance->cfg.actorList[id];
else
return StringHelper::Sprintf("0x%04X", id);
case ZGame::MM_RETAIL:
@@ -31,7 +31,7 @@ public:
id &= 0xFFF;
std::string name;
if (id < ZNames::GetNumActors())
- name = Globals::Instance->cfg.actorList.at(id);
+ name = Globals::Instance->cfg.actorList[id];
else
name = StringHelper::Sprintf("0x%04X", id);
@@ -45,5 +45,20 @@ public:
return "";
}
- static int32_t GetNumActors() { return Globals::Instance->cfg.actorList.size(); }
+ static std::string GetEntranceName(uint16_t id)
+ {
+ if (ZNames::GetNumEntrances() == 0 || ZNames::GetNumSpecialEntrances() == 0)
+ return StringHelper::Sprintf("0x%04X", id);
+
+ if (id < ZNames::GetNumEntrances())
+ return Globals::Instance->cfg.entranceList[id];
+ else if ((id >= 0x7FF9 && id <= 0x7FFF) && !((id - 0x7FF9U) > GetNumSpecialEntrances())) // Special entrances
+ return Globals::Instance->cfg.specialEntranceList[id - 0x7FF9];
+ else
+ return StringHelper::Sprintf("0x%04X", id);
+ }
+
+ static size_t GetNumActors() { return Globals::Instance->cfg.actorList.size(); }
+ static size_t GetNumEntrances() { return Globals::Instance->cfg.entranceList.size(); }
+ static size_t GetNumSpecialEntrances() { return Globals::Instance->cfg.specialEntranceList.size(); }
};
diff --git a/ZAPDUtils/Utils/File.h b/ZAPDUtils/Utils/File.h
index 084152f..7bc5d29 100644
--- a/ZAPDUtils/Utils/File.h
+++ b/ZAPDUtils/Utils/File.h
@@ -33,6 +33,8 @@ public:
static std::string ReadAllText(const fs::path& filePath)
{
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
+ if (!file.is_open())
+ return "";
int32_t fileSize = (int32_t)file.tellg();
file.seekg(0);
char* data = new char[fileSize + 1];
diff --git a/ZAPDUtils/Utils/StringHelper.h b/ZAPDUtils/Utils/StringHelper.h
index 693813c..8560d6b 100644
--- a/ZAPDUtils/Utils/StringHelper.h
+++ b/ZAPDUtils/Utils/StringHelper.h
@@ -105,7 +105,7 @@ public:
{
return std::all_of(str.begin(), str.end(), ::isdigit);
}
-
+
static bool HasOnlyHexDigits(const std::string& str)
{
return std::all_of(str.begin(), str.end(), ::isxdigit);