otb

package
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2024 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package otb reads in the 'OpenTibia Binary' format.

This format is used in items.otb specifying item attributes, as well as a mapping from a client ID to a persistent server ID.

It is also used in the OpenTibia Binary Map with extension .otbm.

Index

Constants

View Source
const (
	ESCAPE_CHAR = 0xFD // Following character should be read verbatim, even if it otherwise has a special meaning.
	NODE_START  = 0xFE // From this character onwards, this is a new OTB node. If preceded by NODE_END, this is the next sibling node. Otherwise, it's a child node.
	NODE_END    = 0xFF // This character marks the end of the latest OTB node. If immediately followed by a NODE_START, that will be the next sibling node.
)

Various special-meaning characters that might be encountered while parsing a node.

Variables

This section is empty.

Functions

This section is empty.

Types

type OTB

type OTB struct {
	// contains filtered or unexported fields
}

OTB reads in the file format as implemented in OpenTibia Server's fileloader.cpp.

The implementation currently vaguely mirrors what's in fileloader.cpp. It's somewhat suboptimal in the way it processes children, stores 'props' (non-node blobs attached to a node) and such. It avoids some deficiencies in the reference implementation, but is very suboptimal when it comes to parsing this file format.

It could be supplanted by a smarter, more Go-like file format reader.

func NewOTB

func NewOTB(r io.ReadSeeker) (*OTB, error)

NewOTB reads an OTB file from the given `io.ReadSeeker`, and constructs a tree of nodes.

No meaning is assigned to nodes; this is the task of readers for an individual format.

func (*OTB) ChildNode

func (otb *OTB) ChildNode(parent *OTBNode) *OTBNode

ChildNode returns whichever is the first child node of a given node. If nil is passed, root node is assumed.

To obtain further children, use child's NextNode to obtain the first sibling, then use that child's NextNode to obtain the next sibling, etc.

TODO(ivucica): Refactor this. These calls should be made on OTBNode.

type OTBNode

type OTBNode struct {
	// contains filtered or unexported fields
}

OTBNode represents a single node in an OTB-formatted file.

Each node has a type, some data, and may have a sibling and a child attached to it.

Further meaning depends on the file; for example, root node in items.otb does not use type, but uses data array to store the version of the file and a free form descriptor. Its child is the first item in the file; item's sibling is the second item; second item's sibling is the third item; et cetera.

func (*OTBNode) ChildNode

func (n *OTBNode) ChildNode() *OTBNode

ChildNode returns the first child of the node, or null if there are no children.

func (*OTBNode) NextNode

func (n *OTBNode) NextNode() *OTBNode

NextNode returns the next sibling of the node, or null if there are no more siblings.

func (*OTBNode) NodeType

func (n *OTBNode) NodeType() uint8

NodeType returns the type of the node.

For example, in item nodes in items.otb, this means which item group the item belongs to (item groups being used in editors to group items into sections such as ground, walls, etc).

func (*OTBNode) PropsBuffer

func (n *OTBNode) PropsBuffer() *bytes.Buffer

Returns a new (i.e. reset to start) buffer for reading properties.

Directories

Path Synopsis
Package itemsotb reads in an items.otb file.
Package itemsotb reads in an items.otb file.
Package otbm implements an OTBM map file format reader and a gameworld map data source.
Package otbm implements an OTBM map file format reader and a gameworld map data source.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL