mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 12:34:55 +02:00
Fix OTBM saving
This commit is contained in:
@@ -181,3 +181,70 @@ Point BinaryTree::getPoint()
|
||||
ret.y = getU8();
|
||||
return ret;
|
||||
}
|
||||
|
||||
OutputBinaryTree::OutputBinaryTree(const FileStreamPtr& fin)
|
||||
: m_fin(fin)
|
||||
{
|
||||
startNode(0);
|
||||
}
|
||||
|
||||
void OutputBinaryTree::addU8(uint8 v)
|
||||
{
|
||||
write(&v, 1);
|
||||
}
|
||||
|
||||
void OutputBinaryTree::addU16(uint16 v)
|
||||
{
|
||||
uint8 data[2];
|
||||
stdext::writeLE16(data, v);
|
||||
write(data, 2);
|
||||
}
|
||||
|
||||
void OutputBinaryTree::addU32(uint32 v)
|
||||
{
|
||||
uint8 data[4];
|
||||
stdext::writeLE32(data, v);
|
||||
write(data, 4);
|
||||
}
|
||||
|
||||
void OutputBinaryTree::addString(const std::string& v)
|
||||
{
|
||||
if(v.size() > 0xFFFF)
|
||||
stdext::throw_exception("too long string");
|
||||
|
||||
addU16(v.length());
|
||||
write((const uint8*)v.c_str(), v.length());
|
||||
}
|
||||
|
||||
void OutputBinaryTree::addPos(const Position& pos)
|
||||
{
|
||||
addU16(pos.x);
|
||||
addU16(pos.y);
|
||||
addU8(pos.z);
|
||||
}
|
||||
|
||||
void OutputBinaryTree::addPoint(const Point& point)
|
||||
{
|
||||
addU8(point.x);
|
||||
addU8(point.y);
|
||||
}
|
||||
|
||||
void OutputBinaryTree::startNode(uint8 node)
|
||||
{
|
||||
m_fin->addU8(BINARYTREE_NODE_START);
|
||||
addU8(node);
|
||||
}
|
||||
|
||||
void OutputBinaryTree::endNode()
|
||||
{
|
||||
m_fin->addU8(BINARYTREE_NODE_END);
|
||||
}
|
||||
|
||||
void OutputBinaryTree::write(const uint8 *data, int size)
|
||||
{
|
||||
for(int i=0;i<size;++i) {
|
||||
if(data[i]==BINARYTREE_NODE_START || data[i]==BINARYTREE_NODE_END||data[i]==BINARYTREE_ESCAPE_CHAR)
|
||||
m_fin->addU8(BINARYTREE_ESCAPE_CHAR);
|
||||
m_fin->addU8(data[i]);
|
||||
}
|
||||
}
|
||||
|
@@ -66,4 +66,27 @@ private:
|
||||
uint m_startPos;
|
||||
};
|
||||
|
||||
class OutputBinaryTree : public stdext::shared_object
|
||||
{
|
||||
public:
|
||||
OutputBinaryTree(const FileStreamPtr& finish);
|
||||
|
||||
void addU8(uint8 v);
|
||||
void addU16(uint16 v);
|
||||
void addU32(uint32 v);
|
||||
void addString(const std::string& v);
|
||||
void addPos(const Position& pos);
|
||||
void addPoint(const Point& point);
|
||||
|
||||
void startNode(uint8 node);
|
||||
void endNode();
|
||||
|
||||
private:
|
||||
FileStreamPtr m_fin;
|
||||
|
||||
protected:
|
||||
void write(const uint8* data, int size);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -32,14 +32,14 @@ class Event;
|
||||
class ScheduledEvent;
|
||||
class FileStream;
|
||||
class BinaryTree;
|
||||
class BinaryWriteTree;
|
||||
class OutputBinaryTree;
|
||||
|
||||
typedef stdext::shared_object_ptr<Module> ModulePtr;
|
||||
typedef stdext::shared_object_ptr<Event> EventPtr;
|
||||
typedef stdext::shared_object_ptr<ScheduledEvent> ScheduledEventPtr;
|
||||
typedef stdext::shared_object_ptr<FileStream> FileStreamPtr;
|
||||
typedef stdext::shared_object_ptr<BinaryTree> BinaryTreePtr;
|
||||
typedef stdext::shared_object_ptr<BinaryWriteTree> BinaryWriteTreePtr;
|
||||
typedef stdext::shared_object_ptr<OutputBinaryTree> OutputBinaryTreePtr;
|
||||
|
||||
typedef std::vector<BinaryTreePtr> BinaryTreeVec;
|
||||
|
||||
|
Reference in New Issue
Block a user