dat

package
v0.0.7 Latest Latest
Warning

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

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

Documentation

Overview

Package dat implements a parser for Tibia dataset files (Tibia.dat), describing items, creatures, etc.

Index

Constants

View Source
const (
	CLIENT_VERSION_UNKNOWN = iota
	CLIENT_VERSION_854
)

Enumeration of versions that are 'actively' supported.

(Values may change between versions of the package and have no meaning.)

View Source
const (
	OptByte780Ground                = OptByte780(0x00) // 0, Proto name: bank
	OptByte780OnTop                 = OptByte780(0x01) // 1, Proto name: clip
	OptByte780WalkthroughItem       = OptByte780(0x02) // 2, Proto name: bottom
	OptByte780HigherWalkthroughItem = OptByte780(0x03) // 3, Proto name: top
	OptByte780Container             = OptByte780(0x04) // 4, Proto name: container
	OptByte780Stackable             = OptByte780(0x05) // 5, Proto name: cumulative
	OptByte780AlwaysUsed            = OptByte780(0x06) // 6, Proto name: usable
	OptByte780Usable                = OptByte780(0x07) // 7, Proto name: forceuse
	OptByte780Rune                  = OptByte780(0x08) // 8, Proto name: multiuse
	OptByte780RW                    = OptByte780(0x09) // 9, Proto name: write
	OptByte780RO                    = OptByte780(0x0A) // 10, Proto name: write_once
	OptByte780FluidContainer        = OptByte780(0x0B) // 11, Proto name: liquidpool
	OptByte780Splash                = OptByte780(0x0C) // 12, Proto name: unpass
	OptByte780BlockingPlayer        = OptByte780(0x0D) // 13, Proto name: unmove
	OptByte780ImmobileItem          = OptByte780(0x0E) // 14, Proto name: unsight
	OptByte780BlockingMissiles      = OptByte780(0x0F) // 15, Proto name: avoid
	OptByte780BlockingMonsters      = OptByte780(0x10) // 16, Proto name: no_movement_animation
	OptByte780Equipable             = OptByte780(0x11) // 16, Proto name: take
	OptByte780Hangable              = OptByte780(0x12) // 17, Proto name: liquidcontainer
	OptByte780HorizontalItem        = OptByte780(0x13) // 18, Proto name: hang
	OptByte780VerticalItem          = OptByte780(0x14) // 19, Proto name: hook
	OptByte780RotatableItem         = OptByte780(0x15) // 20, Proto name: rotate
	OptByte780Lightcaster           = OptByte780(0x16) // 21, Proto name: light
	OptByte780FloorChangingItem     = OptByte780(0x17) // 22, Proto name: dont_hide
	OptByte780Unknown0x18           = OptByte780(0x18) // 23, Proto name: translucent
	OptByte780HasOffset             = OptByte780(0x19) // 24, Proto name: shift
	OptByte780PlayerOffset          = OptByte780(0x1A) // 25, Proto name: height
	OptByte780HeightOffsetAllParts  = OptByte780(0x1B) // 26, Proto name: lying_object
	OptByte780IdleAnim              = OptByte780(0x1C) // 27, Proto name: animate_always
	OptByte780MapColor              = OptByte780(0x1D) // 28, Proto name: automap
	OptByte780LineSpot              = OptByte780(0x1E) // 29, Proto name: lenshelp
	OptByte780Unknown0x1F           = OptByte780(0x1F) // 30, Proto name: fullbank
	OptByte780LookThrough           = OptByte780(0x20) // 31, Proto name: ignore_look
	OptByte780Max                   = iota
)

Note: proto field number mappings are temporary, and generally just 'i+1'. They need to be closely examined before they can be used and guaranteed a semantic match.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dataset

type Dataset struct {
	Header
	// contains filtered or unexported fields
}

Dataset represents a set of items, outfits, effects and distance effects read from a Tibia dataset file ('things' or 'dataset entries').

func NewDataset

func NewDataset(r io.Reader) (*Dataset, error)

NewDataset reads the dataset file from the passed io.Reader and returns the Dataset object.

func (Dataset) ClientVersion

func (d Dataset) ClientVersion() int

ClientVersion returns which version of the game this data file comes from.

Currently supported is only 8.54.

func (*Dataset) Item

func (d *Dataset) Item(clientID uint16) *Item

func (*Dataset) Outfit

func (d *Dataset) Outfit(clientID uint16) *Outfit

type DatasetColor added in v0.0.3

type DatasetColor uint16

DatasetColor fulfills the color.Color interface on top of the stored uint16 value.

Usable for light color and map color.

func (DatasetColor) RGBA added in v0.0.3

func (col DatasetColor) RGBA() (r, g, b, a uint32)

type DatasetEntry

type DatasetEntry interface {
	GetGraphics() *Graphics
}

DatasetEntry interface represents an entry in the dataset.

It exposes a method to get a description of graphics for a particular 'thing', but is primarily intended to make it easier to abstract representing 'any entry' in the type system.

All dataset entries have graphics attached to them.

type DistanceEffect

type DistanceEffect struct {
	DatasetEntry
	Graphics

	Id int
	LightInfo

	// Raw bytes read from 7.80+ datafile.
	OptBytes780 []OptByte780
}

DistanceEffect represents an in-game effect which moves from one tile to another over a period of time, then diappears.

func (*DistanceEffect) GetGraphics

func (d *DistanceEffect) GetGraphics() *Graphics

GetGraphics returns sprites associated with this distance effect.

func (DistanceEffect) String

func (d DistanceEffect) String() string

String returns a string representation for a distance effect.

type Effect

type Effect struct {
	DatasetEntry
	Graphics

	Id int
	LightInfo

	// Raw bytes read from 7.80+ datafile.
	OptBytes780 []OptByte780
}

Effect represents a temporarily-appearing in-game effect, such as a poof of smoke, then disappears.

func (*Effect) GetGraphics

func (e *Effect) GetGraphics() *Graphics

GetGraphics returns sprites associated with this effect.

func (Effect) String

func (e Effect) String() string

String returns a string representation for an effect.

type Graphics

type Graphics struct {
	// WxH. Separated into a struct for easier reading.
	GraphicsDimensions
	// How many pixels should each sprite's tile take on screen? Usually 32.
	RenderSize uint8
	// Details on how to render each of the WxH sprite blocks (animations, variations, etc.)
	// Separated into a struct for easier reading.
	GraphicsDetails

	// Which sprites are used when rendering.
	Sprites []uint16
}

Graphics describes sprites associated with a particular thing, and how they should be drawn.

type GraphicsDetails

type GraphicsDetails struct {
	// How many WxH blocks will be drawn one on top of the other.
	BlendFrames uint8
	// How many variations does this sprite have based on its position on the map.
	XDiv, YDiv, ZDiv uint8
	// How many blocks of WxHxBlendFramesxXdivxYdivxZdiv does this sprite use as animation frames.
	AnimCount uint8
}

GraphicsDetails represents various points detailing how many individual sprites compose a thing, and how should they be drawn.

This includes number of animation frames, number of sprites that should be layered one on top of the other, etc.

type GraphicsDimensions

type GraphicsDimensions struct {
	// How many on-screen tiles will this sprite take, when drawn.
	Width, Height uint8
}

GraphicsDimensions represents size of an item expressed in tiles.

It's extracted as a type so it can more easily be read from the binary file.

type Header struct {
	Signature                                                uint32
	ItemCount, OutfitCount, EffectCount, DistanceEffectCount uint16 // TODO(ivucica): rename to 'max id'
}

type Item

type Item struct {
	DatasetEntry
	Graphics

	Id int

	GroundSpeed uint16
	SortOrder   uint16
	Container   bool
	Stackable   bool
	AlwaysUsed  bool
	Usable      bool
	Rune        bool

	Readable bool
	Writable bool
	MaxRWLen uint16

	FluidContainer bool
	Splash         bool

	BlockingPlayer   bool
	Immobile         bool
	BlockingMissiles bool
	BlockingMonsters bool

	Equipable      bool
	Hangable       bool
	HorizontalItem bool
	VerticalItem   bool
	RotatableItem  bool

	LightInfo
	OffsetInfo
	PlayerOffset uint16
	LargeOffset  bool
	IdleAnim     bool
	MapColor     DatasetColor
	MapColorOK   bool
	LookThrough  bool

	// Raw bytes read from 7.80+ datafile.
	OptBytes780 []OptByte780
}

Item represents a dataset entry describing an in-game item.

Items range from ground tiles, through wall tiles, to inventory items such as apples or swords.

func (*Item) GetGraphics

func (i *Item) GetGraphics() *Graphics

GetGraphics returns sprites associated with this item.

func (Item) IsGround

func (i Item) IsGround() bool

IsGround returns information whether an item is a ground item.

Currently this is based on existence of an item's ground speed.

func (Item) String

func (i Item) String() string

String returns a string representation for an item.

type LightInfo

type LightInfo struct {
	Strength uint16
	Color    DatasetColor
}

LightInfo represents a recurring structure in the binary format of the data file concerning the strength and color of the light emitted client-side.

type OffsetInfo

type OffsetInfo struct {
	X, Y uint16
}

OffsetInfo represents how far the object should be drawn offset to its usual drawing location.

type OptByte780 added in v0.0.5

type OptByte780 byte

func (OptByte780) ConstName added in v0.0.5

func (b OptByte780) ConstName() string

ConstName returns the name used for the constant in the source code.

func (OptByte780) OTStyleDescription added in v0.0.5

func (b OptByte780) OTStyleDescription() string

OTStyleDescription returns a human readable description consisting of hex and dec representation of a byte, and a sentence-formatted short description of the byte.

func (OptByte780) ProtoFieldID added in v0.0.5

func (b OptByte780) ProtoFieldID() int

ProtoFieldID returns 12.x's equivalent proto field number, or 0 if not mappable.

Note: proto field number mappings are temporary, and generally just 'i+1'. They need to be closely examined before they can be used and guaranteed a semantic match.

func (OptByte780) ProtoFieldName added in v0.0.5

func (b OptByte780) ProtoFieldName() string

ProtoFieldID returns 12.x's equivalent proto field name, or empty if not mappable.

Note: proto field number mappings are temporary, and generally just 'i+1'. They need to be closely examined before they can be used and guaranteed a semantic match.

func (OptByte780) String added in v0.0.5

func (b OptByte780) String() string

String returns a human-readable string detailing the information known about this byte: its hex and dec numbers, a short description, in-code enum const name, equivalent proto field id (if any) and the name (if any)

type Outfit

type Outfit struct {
	DatasetEntry
	Graphics

	Id int
	OffsetInfo
	IdleAnim bool
	LightInfo

	// Raw bytes read from 7.80+ datafile.
	OptBytes780 []OptByte780
}

Outfit represents a dataset entry describing a possible appearance for an in-game character, whether NPC or player.

func (*Outfit) GetGraphics

func (o *Outfit) GetGraphics() *Graphics

GetGraphics returns sprites associated with this outfit.

func (Outfit) String

func (o Outfit) String() string

String returns a string representation for an outfit.

Jump to

Keyboard shortcuts

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