Documentation

EoReader
in package

A class for reading EO data from a sequence of bytes.

EoReader features a chunked reading mode, which is important for accurate emulation of the official game client.

See documentation for chunked reading: https://github.com/Cirras/eo-protocol/blob/master/docs/chunks.md

Table of Contents

Properties

$chunkedReadingMode  : bool
$chunkStart  : int
$data  : array<string|int, int>
$nextBreak  : int
$position  : int

Methods

__construct()  : mixed
Creates a new EoReader instance for the specified data.
getByte()  : int
Reads a raw byte from the input data.
getBytes()  : array<string|int, int>
Reads an array of raw bytes from the input data.
getChar()  : int
Reads an encoded 1-byte integer from the input data.
getEncodedString()  : string
Reads an encoded string from the input data.
getFixedEncodedString()  : string
Reads an encoded string with a fixed length from the input data.
getFixedString()  : string
Reads a string with a fixed length from the input data.
getInt()  : int
Reads an encoded 4-byte integer from the input data.
getPosition()  : int
Gets the current position of the reader in the input data.
getRemaining()  : int
Gets the number of bytes remaining in the current chunk or in the input data.
getShort()  : int
Reads an encoded 2-byte integer from the input data.
getString()  : string
Reads a string from the input data by reading until the end.
getThree()  : int
Reads an encoded 3-byte integer from the input data.
isChunkedReadingMode()  : bool
Gets the value of the chunked reading mode.
nextChunk()  : void
Moves the reader position to the start of the next chunk in the input data.
setChunkedReadingMode()  : void
Sets the chunked reading mode.
slice()  : EoReader
Creates a new EoReader whose input data is a shared subsequence of this reader's data.
decodeAnsi()  : string
Decodes windows-1252 bytes to a string.
decodeAnsiString()  : string
Decodes a windows-1252 string to UTF-8.
findNextBreakIndex()  : void
Finds the index of the next break byte (0xFF) in the input data.
readByte()  : int
Internal method to read a raw byte from the input data.
readBytes()  : array<string|int, int>
Internal method to read an array of raw bytes from the input data.
removePadding()  : array<string|int, int>
Removes padding (trailing 0xFF or 0x00 bytes) from a sequence of bytes.

Properties

$chunkedReadingMode

private bool $chunkedReadingMode = false

$data

private array<string|int, int> $data

Methods

__construct()

Creates a new EoReader instance for the specified data.

public __construct(array<string|int, int> $data) : mixed
Parameters
$data : array<string|int, int>

The byte string containing the input data.

getByte()

Reads a raw byte from the input data.

public getByte() : int
Return values
int

A raw byte.

getBytes()

Reads an array of raw bytes from the input data.

public getBytes(int $length) : array<string|int, int>
Parameters
$length : int

The number of bytes to read.

Return values
array<string|int, int>

An array of raw bytes.

getChar()

Reads an encoded 1-byte integer from the input data.

public getChar() : int
Return values
int

A decoded 1-byte integer.

getEncodedString()

Reads an encoded string from the input data.

public getEncodedString() : string
Return values
string

A decoded string.

getFixedEncodedString()

Reads an encoded string with a fixed length from the input data.

public getFixedEncodedString(int $length[, bool $padded = false ]) : string
Parameters
$length : int

The length of the string.

$padded : bool = false

True if the string is padded with trailing 0xFF bytes.

Tags
throws
ValueError

If the length is negative.

Return values
string

A decoded string.

getFixedString()

Reads a string with a fixed length from the input data.

public getFixedString(int $length[, bool $padded = false ]) : string
Parameters
$length : int

The length of the string.

$padded : bool = false

True if the string is padded with trailing 0xFF bytes.

Tags
throws
ValueError

If the length is negative.

Return values
string

A decoded string.

getInt()

Reads an encoded 4-byte integer from the input data.

public getInt() : int
Return values
int

A decoded 4-byte integer.

getPosition()

Gets the current position of the reader in the input data.

public getPosition() : int
Return values
int

The current position.

getRemaining()

Gets the number of bytes remaining in the current chunk or in the input data.

public getRemaining() : int
Return values
int

The number of bytes remaining.

getShort()

Reads an encoded 2-byte integer from the input data.

public getShort() : int
Return values
int

A decoded 2-byte integer.

getString()

Reads a string from the input data by reading until the end.

public getString() : string
Return values
string

A decoded string.

getThree()

Reads an encoded 3-byte integer from the input data.

public getThree() : int
Return values
int

A decoded 3-byte integer.

isChunkedReadingMode()

Gets the value of the chunked reading mode.

public isChunkedReadingMode() : bool
Return values
bool

True if in chunked reading mode, false otherwise.

nextChunk()

Moves the reader position to the start of the next chunk in the input data.

public nextChunk() : void
Tags
throws
RuntimeException

If not in chunked reading mode.

setChunkedReadingMode()

Sets the chunked reading mode.

public setChunkedReadingMode(bool $value) : void
Parameters
$value : bool

True to enable chunked reading mode, false to disable it.

slice()

Creates a new EoReader whose input data is a shared subsequence of this reader's data.

public slice([int|null $index = null ][, int|null $length = null ]) : EoReader

The input data of the new reader will start at position index in this reader and contain up to length bytes. The two readers' positions and chunked reading modes will be independent. The new reader's position will be zero, and its chunked reading mode will be false.

Parameters
$index : int|null = null

The position in this reader at which the data of the new reader will start. Defaults to the current reader position.

$length : int|null = null

The length of the shared subsequence of data to supply to the new reader. Defaults to the length of the remaining data starting from index.

Tags
throws
ValueError

If index or length is negative.

Return values
EoReader

The new reader.

decodeAnsi()

Decodes windows-1252 bytes to a string.

private decodeAnsi(array<string|int, int> $bytes) : string
Parameters
$bytes : array<string|int, int>

The sequence of bytes to decode.

Return values
string

The decoded string.

decodeAnsiString()

Decodes a windows-1252 string to UTF-8.

private decodeAnsiString(string $string) : string
Parameters
$string : string

The string to decode.

Return values
string

The decoded string.

findNextBreakIndex()

Finds the index of the next break byte (0xFF) in the input data.

private findNextBreakIndex() : void

readByte()

Internal method to read a raw byte from the input data.

private readByte() : int
Return values
int

A raw byte.

readBytes()

Internal method to read an array of raw bytes from the input data.

private readBytes(int $length) : array<string|int, int>
Parameters
$length : int

The number of bytes to read.

Return values
array<string|int, int>

An array of raw bytes.

removePadding()

Removes padding (trailing 0xFF or 0x00 bytes) from a sequence of bytes.

private removePadding(array<string|int, int> $bytes) : array<string|int, int>
Parameters
$bytes : array<string|int, int>

The sequence of bytes.

Return values
array<string|int, int>

The bytes without padding.


        
On this page

Search results