From e8ec55df9173c588a774f50e71cfd2be77271166 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Fri, 2 Feb 2024 22:09:41 +0100 Subject: Restored support for setting monster ID offset on monsters tag Apparently this was supported before, but support for that was lost in bd1fdd87eed48ba3ffcc413936d6a6a60a429a97. Fixes #46 --- src/resources/monsterdb.cpp | 8 ++++++-- src/resources/monsterdb.h | 2 ++ src/resources/settingsmanager.cpp | 8 ++++++++ src/utils/xml.cpp | 5 +++++ src/utils/xml.h | 9 +++++++-- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 5fd74c24..c4abeecf 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -53,11 +53,15 @@ void MonsterDB::init() if (mLoaded) unload(); - // This used to be read from offset attribute of monsters root tag, however - // I couldn't find any place it was used, so for now the default values are set + // This can be overridden by an 'offset' attribute on a 'monsters' root tag. mMonsterIdOffset = Net::getNetworkType() == ServerInfo::TMWATHENA ? OLD_TMWATHENA_OFFSET : 0; } +void MonsterDB::setMonsterIdOffset(int offset) +{ + mMonsterIdOffset = offset; +} + /** * Read node from settings. */ diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h index 5b2f3c2d..dc8b50cb 100644 --- a/src/resources/monsterdb.h +++ b/src/resources/monsterdb.h @@ -33,6 +33,8 @@ namespace MonsterDB { void init(); + void setMonsterIdOffset(int offset); + void readMonsterNode(xmlNodePtr node, const std::string &filename); void checkStatus(); diff --git a/src/resources/settingsmanager.cpp b/src/resources/settingsmanager.cpp index b307d565..f4a40577 100644 --- a/src/resources/settingsmanager.cpp +++ b/src/resources/settingsmanager.cpp @@ -121,6 +121,14 @@ namespace SettingsManager return false; } + if (xmlStrEqual(node->name, BAD_CAST "monsters")) + { + if (XML::hasProperty(node, "offset")) + { + MonsterDB::setMonsterIdOffset(XML::getProperty(node, "offset", 0)); + } + } + // go through every node for_each_xml_child_node(childNode, node) { diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index d0f51230..2fb9d66b 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -92,6 +92,11 @@ namespace XML return mDoc ? xmlDocGetRootElement(mDoc) : nullptr; } + bool hasProperty(xmlNodePtr node, const char *name) + { + return xmlHasProp(node, BAD_CAST name) != nullptr; + } + int getProperty(xmlNodePtr node, const char* name, int def) { int &ret = def; diff --git a/src/utils/xml.h b/src/utils/xml.h index 60355aa6..df8dd1bd 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -60,15 +60,20 @@ namespace XML }; /** - * Gets an floating point property from an xmlNodePtr. + * Returns whether a certain property is present. */ - double getFloatProperty(xmlNodePtr node, const char *name, double def); + bool hasProperty(xmlNodePtr node, const char *name); /** * Gets an integer property from an xmlNodePtr. */ int getProperty(xmlNodePtr node, const char *name, int def); + /** + * Gets an floating point property from an xmlNodePtr. + */ + double getFloatProperty(xmlNodePtr node, const char *name, double def); + /** * Gets a string property from an xmlNodePtr. */ -- cgit v1.2.3-70-g09d2