From b7b8fdfd0cb520ff1891cde9434c095689b189a0 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Thu, 13 Feb 2014 00:41:53 -0200 Subject: [PATCH] Fix BinaryTree skip, small otb changes --- src/client/itemtype.h | 6 ++++-- src/client/thingtypemanager.cpp | 16 +++++++++++----- src/framework/core/binarytree.cpp | 6 ++++++ src/framework/core/binarytree.h | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/client/itemtype.h b/src/client/itemtype.h index 4ed67837..0ea4b440 100644 --- a/src/client/itemtype.h +++ b/src/client/itemtype.h @@ -43,7 +43,8 @@ enum ItemCategory : uint8 { ItemCategorySplash = 11, ItemCategoryFluid = 12, ItemCategoryDoor = 13, - ItemCategoryLast = 14 + ItemCategoryDeprecated = 14, + ItemCategoryLast = 15 }; enum ItemTypeAttr : uint8 { @@ -76,7 +77,8 @@ enum ItemTypeAttr : uint8 { ItemTypeAttrLight2 = 42, ItemTypeAttrTopOrder = 43, ItemTypeAttrWrtiable3 = 44, // deprecated - ItemTypeAttrLast = 45 + ItemTypeAttrWareId = 45, + ItemTypeAttrLast = 46 }; enum ClientVersion diff --git a/src/client/thingtypemanager.cpp b/src/client/thingtypemanager.cpp index 15ab59f0..53286d20 100644 --- a/src/client/thingtypemanager.cpp +++ b/src/client/thingtypemanager.cpp @@ -178,17 +178,23 @@ void ThingTypeManager::loadOtb(const std::string& file) stdext::throw_exception("invalid otb file"); BinaryTreePtr root = fin->getBinaryTree(); + root->skip(1); // otb first byte is always 0 signature = root->getU32(); if(signature != 0) stdext::throw_exception("invalid otb file"); - root->skip(4); + uint8 rootAttr = root->getU8(); + if(rootAttr == 0x01) { // OTB_ROOT_ATTR_VERSION + uint16 size = root->getU16(); + if(size != 4 + 4 + 4 + 128) + stdext::throw_exception("invalid otb root attr version size"); - m_otbMajorVersion = root->getU32(); - m_otbMinorVersion = root->getU32(); - root->skip(4); - root->skip(128); // description + m_otbMajorVersion = root->getU32(); + m_otbMinorVersion = root->getU32(); + root->skip(4); // buildNumber + root->skip(128); // description + } m_reverseItemTypes.clear(); m_itemTypes.resize(root->getChildren().size() + 1, m_nullItemType); diff --git a/src/framework/core/binarytree.cpp b/src/framework/core/binarytree.cpp index 2ed9b719..2006f82b 100644 --- a/src/framework/core/binarytree.cpp +++ b/src/framework/core/binarytree.cpp @@ -111,6 +111,12 @@ void BinaryTree::seek(uint pos) m_pos = pos; } +void BinaryTree::skip(uint len) +{ + unserialize(); + seek(tell() + len); +} + uint8 BinaryTree::getU8() { unserialize(); diff --git a/src/framework/core/binarytree.h b/src/framework/core/binarytree.h index 9951a4e7..b7576548 100644 --- a/src/framework/core/binarytree.h +++ b/src/framework/core/binarytree.h @@ -39,7 +39,7 @@ public: ~BinaryTree(); void seek(uint pos); - void skip(uint len) { seek(tell() + len); } + void skip(uint len); uint tell() { return m_pos; } uint size() { unserialize(); return m_buffer.size(); }